import { name, version } from '../data.mjs' import { sample, paperless, buildStylesheet } from './css.mjs' const grid = { metric: ` `, imperial: ` `, } export const plugin = { name, version, hooks: { preRender: function (svg, data = {}) { const current = svg.attributes.get('class') if (!current || current.indexOf('freesewing') !== -1) { svg.attributes.set('class', 'freesewing') svg.style += sample svg.style += paperless svg.style += buildStylesheet(svg.pattern.settings.scale, data.stripped) if (svg.pattern.settings.paperless) { svg.pattern.settings.units === 'imperial' ? (svg.defs += grid.imperial) : (svg.defs += grid.metric) for (const key in svg.pattern.parts) { const part = svg.pattern.parts[key] if (!part.hidden && svg.pattern.needs(key)) { let anchor = new svg.pattern.Point(0, 0) if (typeof part.points.gridAnchor !== 'undefined') anchor = part.points.gridAnchor else if (typeof part.points.anchor !== 'undefined') anchor = part.points.anchor svg.defs += `` svg.defs += '' part.paths[part.getId()] = new svg.pattern.Path() .move(part.topLeft) .line(new svg.pattern.Point(part.topLeft.x, part.bottomRight.y)) .line(part.bottomRight) .line(new svg.pattern.Point(part.bottomRight.x, part.topLeft.y)) .close() .attr('class', 'grid') .attr('style', `fill: url(#grid_${key})`) } } } } }, }, } // More specifically named exports export const themePlugin = plugin export const pluginTheme = plugin