@overtone-art/canvas-editor-core 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chunk-ORZZ6MGQ.mjs +228 -0
- package/dist/chunk-ORZZ6MGQ.mjs.map +1 -0
- package/dist/index.d.mts +297 -225
- package/dist/index.d.ts +297 -225
- package/dist/index.global.js +506 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1719 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1501 -94
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +86 -0
- package/dist/node.d.ts +86 -0
- package/dist/node.js +814 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +675 -0
- package/dist/node.mjs.map +1 -0
- package/dist/types-D60CfxL9.d.mts +461 -0
- package/dist/types-D60CfxL9.d.ts +461 -0
- package/package.json +49 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node.ts","../src/print.ts"],"sourcesContent":["import { FabricImage, Rect, StaticCanvas, util } from 'fabric/node';\nimport type { FabricObject, ImageFormat } from 'fabric/node';\nimport { computeCoverPlacement, computePrintAreaClip } from './export';\nimport { displaceRgba } from './displacement';\nimport type { EditorState, MockupBlendMode, MockupConfig, MockupDisplacement } from './types';\n\nexport { renderPrintPdf } from './print';\nexport type { PrintPdfOptions, PrintPdfResult } from './print';\n\nexport interface NodeRenderOptions {\n format?: 'png' | 'jpeg' | 'webp' | 'svg';\n multiplier?: number;\n quality?: number;\n /**\n * Gate every image URL referenced by the state before it is loaded. States\n * are authored in the browser and therefore untrusted on a server; the\n * default policy allows only `http:`, `https:` and `data:`. Supply a\n * narrower predicate (e.g. an origin allowlist) to also stop requests to\n * internal hosts.\n */\n allowImageUrl?: (url: string) => boolean;\n}\n\nexport interface NodeRenderResult {\n format: 'png' | 'jpeg' | 'webp' | 'svg';\n mimeType: string;\n data: Uint8Array | string;\n width: number;\n height: number;\n}\n\n// `fabric/node` resolves bare paths and `file:` URLs against the local disk, so\n// an unrestricted state is a local-file-read and SSRF primitive on a server.\nconst ALLOWED_PROTOCOLS = new Set(['http:', 'https:', 'data:']);\n\n/** Keys whose string values are fetched as images during a render. */\nconst URL_KEYS = new Set(['src', 'image']);\n\nfunction defaultAllowImageUrl(url: string): boolean {\n const scheme = /^([a-z][a-z\\d+.-]*):/i.exec(url.trim());\n return scheme !== null && ALLOWED_PROTOCOLS.has(`${scheme[1].toLowerCase()}:`);\n}\n\nfunction assertImageUrlsAllowed(value: unknown, allow: (url: string) => boolean): void {\n if (Array.isArray(value)) {\n for (const item of value) assertImageUrlsAllowed(item, allow);\n return;\n }\n if (!value || typeof value !== 'object') return;\n for (const [key, entry] of Object.entries(value)) {\n if (typeof entry === 'string') {\n if (URL_KEYS.has(key) && !allow(entry)) {\n throw new Error(`Blocked disallowed image URL: ${entry.slice(0, 120)}`);\n }\n } else {\n assertImageUrlsAllowed(entry, allow);\n }\n }\n}\n\nfunction validateState(state: EditorState): void {\n if (\n !state?.canvas ||\n !Array.isArray(state.layers) ||\n !Number.isFinite(state.canvas.width) ||\n !Number.isFinite(state.canvas.height) ||\n state.canvas.width <= 0 ||\n state.canvas.height <= 0\n ) {\n throw new Error('Invalid editor state');\n }\n const major = Number.parseInt(state.version?.split('.')[0] ?? '1', 10);\n if (!Number.isFinite(major) || major > 2) {\n throw new Error(`Unsupported editor state version: ${state.version}`);\n }\n}\n\nfunction dataUrlBytes(dataUrl: string): Uint8Array {\n const encoded = dataUrl.slice(dataUrl.indexOf(',') + 1);\n const binary = atob(encoded);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);\n return bytes;\n}\n\nfunction validateOptions(options: NodeRenderOptions): Required<NodeRenderOptions> {\n const format = options.format ?? 'png';\n const multiplier = options.multiplier ?? 1;\n const quality = options.quality ?? 1;\n const allowImageUrl = options.allowImageUrl ?? defaultAllowImageUrl;\n if (!Number.isFinite(multiplier) || multiplier <= 0) {\n throw new Error('Render multiplier must be positive');\n }\n if (!Number.isFinite(quality) || quality < 0 || quality > 1) {\n throw new Error('Render quality must be between 0 and 1');\n }\n return { format, multiplier, quality, allowImageUrl };\n}\n\nasync function createStateCanvas(state: EditorState, transparent = false): Promise<StaticCanvas> {\n const canvas = new StaticCanvas(undefined, {\n width: state.canvas.width,\n height: state.canvas.height,\n backgroundColor: transparent ? '' : (state.background ?? ''),\n preserveObjectStacking: true,\n });\n try {\n if (!transparent && state.backgroundImage) {\n canvas.backgroundImage = (\n await util.enlivenObjects([state.backgroundImage])\n )[0] as FabricObject;\n }\n const objects = (await util.enlivenObjects(\n state.layers.map((layer) => layer.fabricObject),\n )) as FabricObject[];\n objects.forEach((object, index) => {\n const layer = state.layers[index];\n object.set({ visible: layer.visible, opacity: layer.opacity });\n canvas.add(object);\n });\n canvas.renderAll();\n return canvas;\n } catch (error) {\n canvas.dispose();\n throw error;\n }\n}\n\nfunction encodeCanvas(\n canvas: StaticCanvas,\n options: Required<NodeRenderOptions>,\n): NodeRenderResult {\n const { format, multiplier, quality } = options;\n const width = Math.round(canvas.getWidth() * multiplier);\n const height = Math.round(canvas.getHeight() * multiplier);\n if (format === 'svg') {\n return { format, mimeType: 'image/svg+xml', data: canvas.toSVG(), width, height };\n }\n const dataUrl = canvas.toDataURL({ format: format as ImageFormat, multiplier, quality });\n return {\n format,\n mimeType: format === 'jpeg' ? 'image/jpeg' : `image/${format}`,\n data: dataUrlBytes(dataUrl),\n width,\n height,\n };\n}\n\nfunction compositeOperation(mode?: MockupBlendMode): GlobalCompositeOperation {\n return !mode || mode === 'normal' ? 'source-over' : mode;\n}\n\nfunction clampOpacity(value = 1): number {\n return Math.max(0, Math.min(1, value));\n}\n\nasync function coverImage(url: string, width: number, height: number): Promise<FabricImage> {\n let image: FabricImage;\n try {\n image = await FabricImage.fromURL(url);\n } catch (error) {\n throw new Error(`Failed to load mockup image: ${url}`, { cause: error });\n }\n const sourceWidth = image.width;\n const sourceHeight = image.height;\n const placement = computeCoverPlacement(sourceWidth, sourceHeight, width, height);\n image.set({\n originX: 'left',\n originY: 'top',\n left: placement.left,\n top: placement.top,\n scaleX: placement.width / sourceWidth,\n scaleY: placement.height / sourceHeight,\n selectable: false,\n evented: false,\n });\n return image;\n}\n\nasync function displacedDesignUrl(\n designCanvas: StaticCanvas,\n displacement: MockupDisplacement,\n width: number,\n height: number,\n): Promise<string> {\n const mapCanvas = new StaticCanvas(undefined, { width, height });\n const warpedCanvas = new StaticCanvas(undefined, { width, height });\n try {\n mapCanvas.add(await coverImage(displacement.image, width, height));\n mapCanvas.renderAll();\n const pixels = displaceRgba(\n designCanvas.getContext().getImageData(0, 0, width, height).data,\n mapCanvas.getContext().getImageData(0, 0, width, height).data,\n width,\n height,\n displacement,\n );\n const imageData = warpedCanvas.getContext().createImageData(width, height);\n imageData.data.set(pixels);\n warpedCanvas.getContext().putImageData(imageData, 0, 0);\n return warpedCanvas.toDataURL({ format: 'png', multiplier: 1 });\n } catch (error) {\n throw new Error('Failed to apply mockup displacement map', { cause: error });\n } finally {\n mapCanvas.dispose();\n warpedCanvas.dispose();\n }\n}\n\n/** Render browser-authored EditorState without a DOM or live editor instance. */\nexport async function renderEditorState(\n state: EditorState,\n options: NodeRenderOptions = {},\n): Promise<NodeRenderResult> {\n validateState(state);\n const resolved = validateOptions(options);\n assertImageUrlsAllowed(state, resolved.allowImageUrl);\n const canvas = await createStateCanvas(state);\n try {\n return encodeCanvas(canvas, resolved);\n } finally {\n canvas.dispose();\n }\n}\n\n/** Render a saved product mockup with the transparent design composited above it. */\nexport async function renderMockupState(\n state: EditorState,\n options: NodeRenderOptions = {},\n): Promise<NodeRenderResult> {\n validateState(state);\n const resolved = validateOptions(options);\n assertImageUrlsAllowed(state, resolved.allowImageUrl);\n if (resolved.format === 'svg') {\n throw new Error('Mockup rendering supports PNG, JPEG, and WebP output');\n }\n const mockup: MockupConfig | null | undefined = state.mockup;\n if (!mockup?.image) throw new Error('No mockup is configured');\n\n const designCanvas = await createStateCanvas(state, true);\n const output = new StaticCanvas(undefined, {\n width: state.canvas.width,\n height: state.canvas.height,\n preserveObjectStacking: true,\n });\n try {\n output.add(await coverImage(mockup.image, state.canvas.width, state.canvas.height));\n\n const designUrl = mockup.displacement\n ? await displacedDesignUrl(\n designCanvas,\n mockup.displacement,\n state.canvas.width,\n state.canvas.height,\n )\n : designCanvas.toDataURL({ format: 'png', multiplier: 1 });\n const design = await FabricImage.fromURL(designUrl);\n design.set({\n originX: 'left',\n originY: 'top',\n left: 0,\n top: 0,\n opacity: clampOpacity(mockup.designOpacity),\n globalCompositeOperation: compositeOperation(mockup.designBlendMode),\n selectable: false,\n evented: false,\n });\n if (mockup.printArea && mockup.clipToPrintArea !== false) {\n const clip = computePrintAreaClip(\n mockup.printArea,\n 1,\n 1,\n state.canvas.width,\n state.canvas.height,\n );\n design.clipPath = new Rect({\n originX: 'left',\n originY: 'top',\n left: clip.left,\n top: clip.top,\n width: clip.width,\n height: clip.height,\n absolutePositioned: true,\n });\n }\n output.add(design);\n\n if (mockup.overlay) {\n const overlay = await coverImage(\n mockup.overlay.image,\n state.canvas.width,\n state.canvas.height,\n );\n overlay.set({\n opacity: clampOpacity(mockup.overlay.opacity),\n globalCompositeOperation: compositeOperation(mockup.overlay.blendMode ?? 'multiply'),\n });\n output.add(overlay);\n }\n output.renderAll();\n return encodeCanvas(output, resolved);\n } finally {\n designCanvas.dispose();\n output.dispose();\n }\n}\n\nasync function renderBatch(\n states: EditorState[],\n options: NodeRenderOptions & { concurrency?: number },\n renderer: (state: EditorState, options: NodeRenderOptions) => Promise<NodeRenderResult>,\n): Promise<NodeRenderResult[]> {\n const concurrency = Math.max(1, Math.floor(options.concurrency ?? 2));\n const results = new Array<NodeRenderResult>(states.length);\n let nextIndex = 0;\n await Promise.all(\n Array.from({ length: Math.min(concurrency, states.length) }, async () => {\n while (nextIndex < states.length) {\n const index = nextIndex++;\n results[index] = await renderer(states[index], options);\n }\n }),\n );\n return results;\n}\n\n/** Render multiple states with bounded concurrency for fulfillment jobs. */\nexport async function renderEditorStateBatch(\n states: EditorState[],\n options: NodeRenderOptions & { concurrency?: number } = {},\n): Promise<NodeRenderResult[]> {\n return renderBatch(states, options, renderEditorState);\n}\n\n/** Render multiple mockup states with bounded concurrency for fulfillment jobs. */\nexport async function renderMockupStateBatch(\n states: EditorState[],\n options: NodeRenderOptions & { concurrency?: number } = {},\n): Promise<NodeRenderResult[]> {\n return renderBatch(states, options, renderMockupState);\n}\n","import type { EditorState } from './types';\nimport type { NodeRenderOptions } from './node';\n\nexport interface PrintPdfOptions {\n /** Rasterization density. Defaults to the document DPI, or 300. */\n dpi?: number;\n /** Bleed on every edge, in inches. Defaults to 0.125in. */\n bleed?: number;\n /** Space outside bleed reserved for printer marks, in inches. Defaults to 0.25in. */\n marksMargin?: number;\n trimMarks?: boolean;\n registrationMarks?: boolean;\n /** Optional safe-area inset in inches for preflight warnings. */\n safeArea?: number;\n /** Sharp built-in `cmyk` profile or an absolute path to a custom ICC profile. */\n iccProfile?: string;\n /** Ceiling on the rasterized bleed image, in pixels. Defaults to 250 megapixels. */\n maxPixels?: number;\n outputConditionIdentifier?: string;\n title?: string;\n allowImageUrl?: NodeRenderOptions['allowImageUrl'];\n /** Preserve SVG shapes/text over a CMYK bleed raster. Defaults to `vector`. */\n rendering?: 'vector' | 'raster';\n /** PDFKit font registrations keyed by the exact SVG font-family name. */\n fontFiles?: Record<string, string | Uint8Array>;\n /** Convert text backed by `fontFiles` into glyph paths. Defaults to true. */\n outlineFonts?: boolean;\n}\n\nexport interface PrintPdfResult {\n format: 'pdf';\n mimeType: 'application/pdf';\n data: Uint8Array;\n standard: 'PDF/X-4';\n colourSpace: 'CMYK';\n rendering: 'vector' | 'raster';\n outlinedFonts: string[];\n unoutlinedFonts: string[];\n dpi: number;\n trimWidthPoints: number;\n trimHeightPoints: number;\n bleedPoints: number;\n warnings: string[];\n}\n\nfunction svgAttributes(source: string): Record<string, string> {\n return Object.fromEntries(\n [...source.matchAll(/([\\w:-]+)=(?:\"([^\"]*)\"|'([^']*)')/g)].map((match) => [\n match[1],\n match[2] ?? match[3] ?? '',\n ]),\n );\n}\n\nfunction decodeXmlText(source: string): string {\n return source\n .replace(/<[^>]+>/g, '')\n .replace(/&#x([\\da-f]+);/gi, (_, value: string) =>\n String.fromCodePoint(Number.parseInt(value, 16)),\n )\n .replace(/&#(\\d+);/g, (_, value: string) => String.fromCodePoint(Number(value)))\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/&/g, '&');\n}\n\nfunction escapeXmlAttribute(value: string): string {\n return value.replace(/[<>&\"']/g, (character) => `&#${character.charCodeAt(0)};`);\n}\n\nfunction fontSource(\n files: Record<string, string | Uint8Array>,\n family: string,\n bold: boolean,\n italic: boolean,\n): string | Uint8Array | undefined {\n const suffix = bold && italic ? '-BoldItalic' : bold ? '-Bold' : italic ? '-Italic' : '';\n // `family` comes from the untrusted SVG, so plain indexing would resolve\n // `__proto__`/`constructor` to inherited members and hand a non-font to fontkit.\n const own = (key: string) =>\n Object.hasOwn(files, key) ? (files[key] as string | Uint8Array) : undefined;\n return own(`${family}${suffix}`) ?? own(family);\n}\n\nasync function outlineSvgText(\n svg: string,\n files: Record<string, string | Uint8Array>,\n outlined: Set<string>,\n): Promise<string> {\n const fontkit = await import('fontkit');\n let output = '';\n let cursor = 0;\n for (const textMatch of svg.matchAll(/<text\\b([^>]*)>([\\s\\S]*?)<\\/text>/gi)) {\n const index = textMatch.index ?? 0;\n output += svg.slice(cursor, index);\n cursor = index + textMatch[0].length;\n const textAttributes = svgAttributes(textMatch[1]);\n const spans = [...textMatch[2].matchAll(/<tspan\\b([^>]*)>([\\s\\S]*?)<\\/tspan>/gi)];\n const lines = spans.length\n ? spans.map((span) => ({ attributes: svgAttributes(span[1]), text: decodeXmlText(span[2]) }))\n : [{ attributes: textAttributes, text: decodeXmlText(textMatch[2]) }];\n const resolved = lines.map((line) => {\n const attributes = { ...textAttributes, ...line.attributes };\n const family = attributes['font-family'] ?? 'sans-serif';\n const bold = /bold|[6-9]00/i.test(attributes['font-weight'] ?? '');\n const italic = /italic|oblique/i.test(attributes['font-style'] ?? '');\n return { ...line, attributes, family, source: fontSource(files, family, bold, italic) };\n });\n if (resolved.some((line) => !line.source)) {\n output += textMatch[0];\n continue;\n }\n const paths: string[] = [];\n for (const line of resolved) {\n const source = line.source!;\n const opened =\n typeof source === 'string'\n ? fontkit.openSync(source)\n : fontkit.create(Buffer.from(source.buffer, source.byteOffset, source.byteLength));\n if (!('layout' in opened)) {\n throw new Error(`Font collection requires a named face: ${line.family}`);\n }\n const size = Number.parseFloat(line.attributes['font-size'] ?? '16');\n const scale = size / opened.unitsPerEm;\n const style = line.attributes.style ?? '';\n const run = opened.layout(line.text);\n let penX = Number.parseFloat(line.attributes.x ?? '0');\n const baseline = Number.parseFloat(line.attributes.y ?? '0');\n run.glyphs.forEach((glyph, glyphIndex) => {\n const position = run.positions[glyphIndex];\n const x = penX + position.xOffset * scale;\n const y = baseline - position.yOffset * scale;\n paths.push(\n `<path d=\"${glyph.path.toSVG()}\" transform=\"translate(${x} ${y}) scale(${scale} ${-scale})\" style=\"${escapeXmlAttribute(style)}\"/>`,\n );\n penX += position.xAdvance * scale;\n });\n outlined.add(line.family);\n }\n output += `<g data-outlined-font=\"${escapeXmlAttribute([...new Set(resolved.map((line) => line.family))].join(','))}\">${paths.join('')}</g>`;\n }\n return output + svg.slice(cursor);\n}\n\nfunction rgbToCmyk([redByte, greenByte, blueByte]: [number, number, number]): [\n number,\n number,\n number,\n number,\n] {\n const red = redByte / 255;\n const green = greenByte / 255;\n const blue = blueByte / 255;\n const black = 1 - Math.max(red, green, blue);\n if (black >= 1) return [0, 0, 0, 100];\n return [\n ((1 - red - black) / (1 - black)) * 100,\n ((1 - green - black) / (1 - black)) * 100,\n ((1 - blue - black) / (1 - black)) * 100,\n black * 100,\n ];\n}\n\nasync function imageSourceBytes(\n source: string,\n allow?: (url: string) => boolean,\n): Promise<Uint8Array> {\n if (source.startsWith('data:')) {\n const response = await fetch(source);\n if (!response.ok) throw new Error('Failed to decode an embedded SVG image');\n return new Uint8Array(await response.arrayBuffer());\n }\n const permitted = allow\n ? allow(source)\n : (() => {\n try {\n return ['http:', 'https:'].includes(new URL(source).protocol);\n } catch {\n return false;\n }\n })();\n if (!permitted) throw new Error(`Blocked disallowed vector image URL: ${source}`);\n const response = await fetch(source);\n if (!response.ok) throw new Error(`Failed to load vector image: ${source}`);\n return new Uint8Array(await response.arrayBuffer());\n}\n\nasync function convertSvgImagesToCmyk(\n svg: string,\n sharp: (typeof import('sharp'))['default'],\n profile: string,\n allow?: (url: string) => boolean,\n): Promise<string> {\n const sources = new Set<string>();\n for (const image of svg.matchAll(/<image\\b[^>]*(?:xlink:href|href)=\"([^\"]+)\"[^>]*>/gi)) {\n if (image[1]) sources.add(image[1]);\n }\n let converted = svg;\n for (const source of sources) {\n const bytes = await imageSourceBytes(source, allow);\n const jpeg = await sharp(bytes)\n .flatten({ background: '#ffffff' })\n .toColourspace('cmyk')\n .withIccProfile(profile)\n .jpeg({ quality: 100, chromaSubsampling: '4:4:4' })\n .toBuffer();\n const dataUrl = `data:image/jpeg;base64,${jpeg.toString('base64')}`;\n converted = converted.split(source).join(dataUrl);\n }\n return converted;\n}\n\nasync function renderVectorOverlay(\n state: EditorState,\n options: PrintPdfOptions,\n width: number,\n height: number,\n sharp: (typeof import('sharp'))['default'],\n warnings: string[],\n outlinedFonts: Set<string>,\n unoutlinedFonts: Set<string>,\n): Promise<Uint8Array> {\n const [{ default: PDFKit }, { default: SVGtoPDF }, { renderEditorState }] = await Promise.all([\n import('pdfkit'),\n import('svg-to-pdfkit'),\n import('./node'),\n ]);\n // The bleed image is already flattened onto white. Render the trim overlay\n // against the same opaque print substrate so semi-transparent artwork does\n // not blend a second time with the raster copy beneath it.\n const rendered = await renderEditorState(\n { ...state, background: '#ffffff' },\n {\n format: 'svg',\n allowImageUrl: options.allowImageUrl,\n },\n );\n if (typeof rendered.data !== 'string') throw new Error('Vector rendering returned raster data');\n const fontFiles = options.fontFiles ?? {};\n const outlinedSvg =\n options.outlineFonts === false\n ? rendered.data\n : await outlineSvgText(rendered.data, fontFiles, outlinedFonts);\n const svg = await convertSvgImagesToCmyk(\n outlinedSvg,\n sharp,\n options.iccProfile ?? 'cmyk',\n options.allowImageUrl,\n );\n const remainingText = [...svg.matchAll(/<text\\b([^>]*)>/gi)].map((match) =>\n svgAttributes(match[1]),\n );\n for (const attributes of remainingText) {\n const family = attributes['font-family'] ?? 'sans-serif';\n unoutlinedFonts.add(family);\n const bold = /bold|[6-9]00/i.test(attributes['font-weight'] ?? '');\n const italic = /italic|oblique/i.test(attributes['font-style'] ?? '');\n if (!fontSource(fontFiles, family, bold, italic)) {\n warnings.push(\n `Font \"${family}\" used a PDF standard fallback; supply fontFiles for exact embedding`,\n );\n }\n }\n\n const document = new PDFKit({ autoFirstPage: false, compress: false, pdfVersion: '1.7' });\n for (const [name, path] of Object.entries(fontFiles)) {\n document.registerFont(name, typeof path === 'string' ? path : Buffer.from(path));\n }\n document.addPage({ size: [width, height], margin: 0 });\n SVGtoPDF(document, svg, 0, 0, {\n width,\n height,\n preserveAspectRatio: 'none',\n colorCallback: (color) => {\n const [rgb, opacity] = color;\n return [rgbToCmyk(rgb), opacity] as unknown as typeof color;\n },\n warningCallback: (warning) => warnings.push(`Vector render: ${warning}`),\n });\n\n return new Promise<Uint8Array>((resolve, reject) => {\n const chunks: Uint8Array[] = [];\n document.on('data', (chunk: Uint8Array) => chunks.push(chunk));\n document.on('error', reject);\n document.on('end', () => resolve(new Uint8Array(Buffer.concat(chunks))));\n document.end();\n });\n}\n\n/** Beyond this no printer is served, and larger values only buy an OOM. */\nconst MAX_DPI = 2400;\n/** ~24×36in at 600dpi. Bounds the raster a hostile state can ask a server for. */\nconst DEFAULT_MAX_PIXELS = 250_000_000;\n\nfunction positive(value: number, label: string): number {\n if (!Number.isFinite(value) || value <= 0) throw new Error(`${label} must be positive`);\n return value;\n}\n\n/**\n * States are browser-authored and untrusted on a server. `documentDpi` divides\n * the render multiplier, so an unvalidated fractional value (0.001) inflates the\n * rasterization by six orders of magnitude before any size check runs.\n */\nfunction boundedDpi(value: number, label: string): number {\n const dpi = positive(value, label);\n if (dpi > MAX_DPI) throw new Error(`${label} must not exceed ${MAX_DPI}`);\n if (dpi < 1) throw new Error(`${label} must be at least 1`);\n return dpi;\n}\n\nfunction nonNegative(value: number, label: string): number {\n if (!Number.isFinite(value) || value < 0) throw new Error(`${label} cannot be negative`);\n return value;\n}\n\nfunction preflightSafeArea(state: EditorState, safePixels: number): string[] {\n if (safePixels <= 0) return [];\n const right = state.canvas.width - safePixels;\n const bottom = state.canvas.height - safePixels;\n const warnings: string[] = [];\n for (const layer of state.layers) {\n if (!layer.visible) continue;\n const object = layer.fabricObject;\n const left = Number(object.left ?? 0);\n const top = Number(object.top ?? 0);\n const width = Number(object.width ?? 0) * Math.abs(Number(object.scaleX ?? 1));\n const height = Number(object.height ?? 0) * Math.abs(Number(object.scaleY ?? 1));\n if (left < safePixels || top < safePixels || left + width > right || top + height > bottom) {\n warnings.push(`Layer \"${layer.name}\" extends outside the configured safe area`);\n }\n }\n return warnings;\n}\n\n/**\n * Render an EditorState into a print-production PDF/X-4 file.\n *\n * The design is rasterized at the requested density, converted through Sharp's\n * CMYK ICC pipeline, edge-extended into bleed, and embedded with output intent,\n * trim/bleed boxes, XMP identification, and optional printer marks.\n */\nexport async function renderPrintPdf(\n state: EditorState,\n options: PrintPdfOptions = {},\n): Promise<PrintPdfResult> {\n const dpi = boundedDpi(options.dpi ?? state.canvas.dpi ?? 300, 'Print DPI');\n const documentDpi = boundedDpi(state.canvas.dpi ?? 72, 'Document DPI');\n const maxPixels = positive(options.maxPixels ?? DEFAULT_MAX_PIXELS, 'Max pixels');\n const bleedInches = nonNegative(options.bleed ?? 0.125, 'Bleed');\n const marksMarginInches = nonNegative(options.marksMargin ?? 0.25, 'Marks margin');\n const safeAreaInches = nonNegative(options.safeArea ?? 0, 'Safe area');\n const rendering = options.rendering ?? 'vector';\n const bleedPixels = Math.round(bleedInches * dpi);\n const trimWidthPoints = (state.canvas.width / documentDpi) * 72;\n const trimHeightPoints = (state.canvas.height / documentDpi) * 72;\n const bleedPoints = bleedInches * 72;\n const marksMarginPoints = marksMarginInches * 72;\n\n const scale = dpi / documentDpi;\n const outputPixels =\n Math.round(state.canvas.width * scale + bleedPixels * 2) *\n Math.round(state.canvas.height * scale + bleedPixels * 2);\n if (!Number.isFinite(outputPixels) || outputPixels > maxPixels) {\n throw new Error(\n `Print raster of ${outputPixels} pixels exceeds the ${maxPixels} pixel budget; lower the DPI or raise maxPixels`,\n );\n }\n\n const [{ default: sharp }, pdfLib] = await Promise.all([import('sharp'), import('pdf-lib')]);\n // Keep the optional print entry free of a static cycle with `node.ts`, which\n // re-exports this function as part of the Node-only public surface.\n const { renderEditorState } = await import('./node');\n const rendered = await renderEditorState(state, {\n format: 'png',\n multiplier: scale,\n allowImageUrl: options.allowImageUrl,\n });\n if (typeof rendered.data === 'string') throw new Error('Print rasterization returned SVG data');\n\n let pipeline = sharp(rendered.data).flatten({ background: '#ffffff' });\n if (bleedPixels > 0) {\n pipeline = pipeline.extend({\n top: bleedPixels,\n right: bleedPixels,\n bottom: bleedPixels,\n left: bleedPixels,\n extendWith: 'copy',\n });\n }\n const { data: cmykJpeg, info } = await pipeline\n .toColourspace('cmyk')\n .withIccProfile(options.iccProfile ?? 'cmyk')\n .withDensity(dpi)\n .jpeg({ quality: 100, chromaSubsampling: '4:4:4' })\n .toBuffer({ resolveWithObject: true });\n const metadata = await sharp(cmykJpeg).metadata();\n if (info.channels !== 4 || metadata.space !== 'cmyk' || !metadata.icc) {\n throw new Error('CMYK conversion did not produce a four-channel image with an ICC profile');\n }\n\n const { PDFDocument, PDFDict, PDFName, PDFString, cmyk } = pdfLib;\n const document = await PDFDocument.create();\n const title = options.title ?? 'Overtone Canvas Editor print export';\n document.setTitle(title);\n document.setCreator('@overtone-art/canvas-editor-core');\n document.setProducer('@overtone-art/canvas-editor-core');\n const pageWidth = trimWidthPoints + bleedPoints * 2 + marksMarginPoints * 2;\n const pageHeight = trimHeightPoints + bleedPoints * 2 + marksMarginPoints * 2;\n const page = document.addPage([pageWidth, pageHeight]);\n const image = await document.embedJpg(cmykJpeg);\n page.drawImage(image, {\n x: marksMarginPoints,\n y: marksMarginPoints,\n width: trimWidthPoints + bleedPoints * 2,\n height: trimHeightPoints + bleedPoints * 2,\n });\n\n const trimLeft = marksMarginPoints + bleedPoints;\n const trimBottom = marksMarginPoints + bleedPoints;\n const trimRight = trimLeft + trimWidthPoints;\n const trimTop = trimBottom + trimHeightPoints;\n const warnings = preflightSafeArea(state, safeAreaInches * documentDpi);\n const outlinedFonts = new Set<string>();\n const unoutlinedFonts = new Set<string>();\n if (rendering === 'vector') {\n const vectorPdf = await renderVectorOverlay(\n state,\n options,\n trimWidthPoints,\n trimHeightPoints,\n sharp,\n warnings,\n outlinedFonts,\n unoutlinedFonts,\n );\n const [vectorPage] = await document.embedPdf(vectorPdf);\n page.drawPage(vectorPage, {\n x: trimLeft,\n y: trimBottom,\n width: trimWidthPoints,\n height: trimHeightPoints,\n });\n }\n const bleedLeft = marksMarginPoints;\n const bleedBottom = marksMarginPoints;\n const bleedRight = pageWidth - marksMarginPoints;\n const bleedTop = pageHeight - marksMarginPoints;\n const context = document.context;\n page.node.set(PDFName.of('TrimBox'), context.obj([trimLeft, trimBottom, trimRight, trimTop]));\n page.node.set(\n PDFName.of('BleedBox'),\n context.obj([bleedLeft, bleedBottom, bleedRight, bleedTop]),\n );\n page.node.set(PDFName.of('ArtBox'), context.obj([trimLeft, trimBottom, trimRight, trimTop]));\n\n const markColour = cmyk(0, 0, 0, 1);\n if (options.trimMarks !== false) {\n const offset = Math.max(3, bleedPoints / 2);\n const length = Math.max(9, marksMarginPoints - 3);\n for (const x of [trimLeft, trimRight]) {\n page.drawLine({\n start: { x, y: trimBottom - offset },\n end: { x, y: trimBottom - offset - length },\n thickness: 0.5,\n color: markColour,\n });\n page.drawLine({\n start: { x, y: trimTop + offset },\n end: { x, y: trimTop + offset + length },\n thickness: 0.5,\n color: markColour,\n });\n }\n for (const y of [trimBottom, trimTop]) {\n page.drawLine({\n start: { x: trimLeft - offset, y },\n end: { x: trimLeft - offset - length, y },\n thickness: 0.5,\n color: markColour,\n });\n page.drawLine({\n start: { x: trimRight + offset, y },\n end: { x: trimRight + offset + length, y },\n thickness: 0.5,\n color: markColour,\n });\n }\n }\n if (options.registrationMarks !== false) {\n for (const [x, y] of [\n [pageWidth / 2, marksMarginPoints / 2],\n [pageWidth / 2, pageHeight - marksMarginPoints / 2],\n [marksMarginPoints / 2, pageHeight / 2],\n [pageWidth - marksMarginPoints / 2, pageHeight / 2],\n ] as Array<[number, number]>) {\n page.drawCircle({ x, y, size: 4, borderWidth: 0.5, borderColor: markColour });\n page.drawLine({\n start: { x: x - 6, y },\n end: { x: x + 6, y },\n thickness: 0.5,\n color: markColour,\n });\n page.drawLine({\n start: { x, y: y - 6 },\n end: { x, y: y + 6 },\n thickness: 0.5,\n color: markColour,\n });\n }\n }\n\n const profileStream = context.flateStream(metadata.icc, {\n N: 4,\n Alternate: PDFName.of('DeviceCMYK'),\n });\n const profileRef = context.register(profileStream);\n const outputIntent = context.obj({\n Type: PDFName.of('OutputIntent'),\n S: PDFName.of('GTS_PDFX'),\n OutputConditionIdentifier: PDFString.of(options.outputConditionIdentifier ?? 'CMYK'),\n RegistryName: PDFString.of('https://www.color.org'),\n Info: PDFString.of(options.outputConditionIdentifier ?? 'CMYK print condition'),\n DestOutputProfile: profileRef,\n });\n document.catalog.set(PDFName.of('OutputIntents'), context.obj([context.register(outputIntent)]));\n\n const now = new Date().toISOString();\n const xmp = `<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n<rdf:Description rdf:about=\"\" xmlns:pdfxid=\"http://www.npes.org/pdfx/ns/id/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\" pdfxid:GTS_PDFXVersion=\"PDF/X-4\" xmp:CreateDate=\"${now}\"><dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">${title.replace(/[<>&]/g, '')}</rdf:li></rdf:Alt></dc:title></rdf:Description>\n</rdf:RDF></x:xmpmeta><?xpacket end=\"w\"?>`;\n const metadataStream = context.flateStream(new TextEncoder().encode(xmp), {\n Type: PDFName.of('Metadata'),\n Subtype: PDFName.of('XML'),\n });\n document.catalog.set(PDFName.of('Metadata'), context.register(metadataStream));\n const infoRef = context.trailerInfo.Info;\n if (infoRef) {\n const infoDict = context.lookup(infoRef, PDFDict);\n infoDict.set(PDFName.of('GTS_PDFXVersion'), PDFString.of('PDF/X-4'));\n infoDict.set(PDFName.of('Trapped'), PDFName.of('False'));\n }\n\n return {\n format: 'pdf',\n mimeType: 'application/pdf',\n data: await document.save({ useObjectStreams: false }),\n standard: 'PDF/X-4',\n colourSpace: 'CMYK',\n rendering,\n outlinedFonts: [...outlinedFonts].sort(),\n unoutlinedFonts: [...unoutlinedFonts].sort(),\n dpi,\n trimWidthPoints,\n trimHeightPoints,\n bleedPoints,\n warnings,\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAS,aAAa,MAAM,cAAc,YAAY;;;AC6CtD,SAAS,cAAc,QAAwC;AAC7D,SAAO,OAAO;AAAA,IACZ,CAAC,GAAG,OAAO,SAAS,oCAAoC,CAAC,EAAE,IAAI,CAAC,UAAU;AAAA,MACxE,MAAM,CAAC;AAAA,MACP,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK;AAAA,IAC1B,CAAC;AAAA,EACH;AACF;AAEA,SAAS,cAAc,QAAwB;AAC7C,SAA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U;AAAA,MACrF,CAAC;AACD,aAAO,IAAI,OAAO;AAAA,IACpB;AACA,WAAO,UAAU;AACjB,WAAO,aAAa,QAAQ,QAAQ;AAAA,EACtC,UAAE;AACA,iBAAa,QAAQ;AACrB,WAAO,QAAQ;AAAA,EACjB;AACF;AAEA,eAAe,YACb,QACA,SACA,UAC6B;AAC7B,QAAM,cAAc,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,eAAe,CAAC,CAAC;AACpE,QAAM,UAAU,IAAI,MAAwB,OAAO,MAAM;AACzD,MAAI,YAAY;AAChB,QAAM,QAAQ;AAAA,IACZ,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,aAAa,OAAO,MAAM,EAAE,GAAG,YAAY;AACvE,aAAO,YAAY,OAAO,QAAQ;AAChC,cAAM,QAAQ;AACd,gBAAQ,KAAK,IAAI,MAAM,SAAS,OAAO,KAAK,GAAG,OAAO;AAAA,MACxD;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAGA,eAAsB,uBACpB,QACA,UAAwD,CAAC,GAC5B;AAC7B,SAAO,YAAY,QAAQ,SAAS,iBAAiB;AACvD;AAGA,eAAsB,uBACpB,QACA,UAAwD,CAAC,GAC5B;AAC7B,SAAO,YAAY,QAAQ,SAAS,iBAAiB;AACvD;","names":["response","renderEditorState"]}
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { FabricObject } from 'fabric';
|
|
2
|
+
|
|
3
|
+
type Unit = 'px' | 'mm' | 'in';
|
|
4
|
+
type LayerType = 'image' | 'mask' | 'text' | 'shape' | 'template' | 'group';
|
|
5
|
+
interface LayerData {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LayerType;
|
|
8
|
+
name: string;
|
|
9
|
+
visible: boolean;
|
|
10
|
+
locked: boolean;
|
|
11
|
+
opacity: number;
|
|
12
|
+
/** Non-fabric metadata persisted with the layer (pattern config, etc). */
|
|
13
|
+
meta?: LayerMeta;
|
|
14
|
+
}
|
|
15
|
+
interface LayerMeta {
|
|
16
|
+
pattern?: PatternState;
|
|
17
|
+
mask?: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
revision: number;
|
|
21
|
+
};
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface SerializedLayer extends LayerData {
|
|
25
|
+
fabricObject: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface EditorState {
|
|
28
|
+
version: string;
|
|
29
|
+
canvas: {
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
unit?: Unit;
|
|
33
|
+
dpi?: number;
|
|
34
|
+
};
|
|
35
|
+
layers: SerializedLayer[];
|
|
36
|
+
background?: string;
|
|
37
|
+
backgroundImage?: Record<string, unknown> | null;
|
|
38
|
+
backgroundImageOptions?: SerializedBackgroundImageOptions | null;
|
|
39
|
+
mockup?: MockupConfig | null;
|
|
40
|
+
}
|
|
41
|
+
interface EditorConfig {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
backgroundColor?: string;
|
|
45
|
+
fileAdapter?: FileAdapter;
|
|
46
|
+
imageProvider?: ImageProvider;
|
|
47
|
+
preserveObjectStacking?: boolean;
|
|
48
|
+
unit?: Unit;
|
|
49
|
+
dpi?: number;
|
|
50
|
+
/** Resolve a non-CORS image through a trusted proxy or same-origin store for pattern rendering. */
|
|
51
|
+
patternSourceResolver?: PatternSourceResolver;
|
|
52
|
+
fonts?: FontDefinition[];
|
|
53
|
+
license?: LicenseConfig;
|
|
54
|
+
}
|
|
55
|
+
type ExportFormat = 'png' | 'jpeg' | 'webp' | 'svg' | 'json';
|
|
56
|
+
interface ResizeOptions {
|
|
57
|
+
/** Scale layer positions and dimensions with the canvas. Defaults to true. */
|
|
58
|
+
scaleContent?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface BackgroundImageOptions {
|
|
61
|
+
fit?: 'cover' | 'contain' | 'stretch';
|
|
62
|
+
opacity?: number;
|
|
63
|
+
/** Fabric/HTML image loading mode for remote assets. */
|
|
64
|
+
crossOrigin?: '' | 'anonymous' | 'use-credentials' | null;
|
|
65
|
+
/** Cancels the current load; never serialized. */
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
}
|
|
68
|
+
type SerializedBackgroundImageOptions = Omit<BackgroundImageOptions, 'signal'>;
|
|
69
|
+
interface SemanticExportOptions extends PngLikeExportOptions {
|
|
70
|
+
/** Document keeps full-canvas coordinates; source returns native image pixels. */
|
|
71
|
+
resolution?: 'document' | 'source';
|
|
72
|
+
}
|
|
73
|
+
interface MaskPoint {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
}
|
|
77
|
+
interface MaskBrushOptions {
|
|
78
|
+
mode: 'add' | 'subtract';
|
|
79
|
+
size: number;
|
|
80
|
+
/** Soft-edge inner radius ratio, from 0 (soft) to 1 (hard). */
|
|
81
|
+
hardness: number;
|
|
82
|
+
}
|
|
83
|
+
type MaskRefinementPrompt = {
|
|
84
|
+
type: 'point';
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
label: 'foreground' | 'background';
|
|
88
|
+
} | {
|
|
89
|
+
type: 'rectangle';
|
|
90
|
+
left: number;
|
|
91
|
+
top: number;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'text';
|
|
96
|
+
value: string;
|
|
97
|
+
};
|
|
98
|
+
interface MaskRefinementRequest {
|
|
99
|
+
mask: string;
|
|
100
|
+
width: number;
|
|
101
|
+
height: number;
|
|
102
|
+
prompts: MaskRefinementPrompt[];
|
|
103
|
+
}
|
|
104
|
+
interface MaskRefinementResult {
|
|
105
|
+
dataUrl: string;
|
|
106
|
+
width?: number;
|
|
107
|
+
height?: number;
|
|
108
|
+
metadata?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
interface MaskRefinementProvider {
|
|
111
|
+
refine(request: MaskRefinementRequest, options?: {
|
|
112
|
+
signal?: AbortSignal;
|
|
113
|
+
onProgress?: (progress: number) => void;
|
|
114
|
+
}): Promise<MaskRefinementResult>;
|
|
115
|
+
}
|
|
116
|
+
/** Kept structural to avoid coupling the public types module to export.ts. */
|
|
117
|
+
interface PngLikeExportOptions {
|
|
118
|
+
multiplier?: number;
|
|
119
|
+
quality?: number;
|
|
120
|
+
}
|
|
121
|
+
interface DpiIssue {
|
|
122
|
+
layerId: string;
|
|
123
|
+
layerName: string;
|
|
124
|
+
effectiveDpi: number;
|
|
125
|
+
minimumDpi: number;
|
|
126
|
+
}
|
|
127
|
+
interface ImageAdjustments {
|
|
128
|
+
/** Range -1 to 1. */
|
|
129
|
+
brightness?: number;
|
|
130
|
+
/** Range -1 to 1. */
|
|
131
|
+
contrast?: number;
|
|
132
|
+
/** Range -1 to 1. */
|
|
133
|
+
saturation?: number;
|
|
134
|
+
/** Range 0 to 1. */
|
|
135
|
+
blur?: number;
|
|
136
|
+
}
|
|
137
|
+
type PatternSourceResolver = (source: string) => Promise<string>;
|
|
138
|
+
interface FontDefinition {
|
|
139
|
+
family: string;
|
|
140
|
+
/** URL, data URL, or a complete CSS FontFace source such as `local(...)`. */
|
|
141
|
+
source: string;
|
|
142
|
+
weight?: string;
|
|
143
|
+
style?: string;
|
|
144
|
+
display?: FontDisplay;
|
|
145
|
+
}
|
|
146
|
+
interface SvgExportOptions {
|
|
147
|
+
/** Embed registered URL/data fonts into the SVG. Defaults to true. */
|
|
148
|
+
embedFonts?: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface LicensePayload {
|
|
151
|
+
id: string;
|
|
152
|
+
domains: string[];
|
|
153
|
+
expiresAt?: string;
|
|
154
|
+
features?: string[];
|
|
155
|
+
}
|
|
156
|
+
type LicenseStatus = {
|
|
157
|
+
state: 'community' | 'exempt' | 'checking';
|
|
158
|
+
payload: null;
|
|
159
|
+
} | {
|
|
160
|
+
state: 'valid';
|
|
161
|
+
payload: LicensePayload;
|
|
162
|
+
} | {
|
|
163
|
+
state: 'invalid' | 'expired' | 'domain-mismatch';
|
|
164
|
+
payload: LicensePayload | null;
|
|
165
|
+
};
|
|
166
|
+
interface LicenseConfig {
|
|
167
|
+
key?: string;
|
|
168
|
+
/** Offline signature decoder/verifier supplied by the commercial distribution. */
|
|
169
|
+
verifyOffline?: (key: string) => Promise<LicensePayload | null> | LicensePayload | null;
|
|
170
|
+
hostname?: string;
|
|
171
|
+
environment?: 'development' | 'test' | 'production';
|
|
172
|
+
onUsage?: (event: {
|
|
173
|
+
name: string;
|
|
174
|
+
at: string;
|
|
175
|
+
licenseId?: string;
|
|
176
|
+
}) => void;
|
|
177
|
+
}
|
|
178
|
+
interface CanvasSizePreset {
|
|
179
|
+
id: string;
|
|
180
|
+
name: string;
|
|
181
|
+
width: number;
|
|
182
|
+
height: number;
|
|
183
|
+
unit: Unit;
|
|
184
|
+
dpi: number;
|
|
185
|
+
}
|
|
186
|
+
interface FileAdapter {
|
|
187
|
+
save(data: Blob | string, filename: string, format: ExportFormat): Promise<string>;
|
|
188
|
+
}
|
|
189
|
+
interface ImageProviderResult {
|
|
190
|
+
id?: string;
|
|
191
|
+
url: string;
|
|
192
|
+
width: number;
|
|
193
|
+
height: number;
|
|
194
|
+
previewUrl?: string;
|
|
195
|
+
thumbnailUrl?: string;
|
|
196
|
+
alt?: string;
|
|
197
|
+
sourceUrl?: string;
|
|
198
|
+
attribution?: ImageAttribution;
|
|
199
|
+
/** Provider event endpoint retained for use tracking; never render this as an image. */
|
|
200
|
+
trackingUrl?: string;
|
|
201
|
+
}
|
|
202
|
+
interface ImageAttribution {
|
|
203
|
+
name: string;
|
|
204
|
+
url: string;
|
|
205
|
+
provider?: string;
|
|
206
|
+
}
|
|
207
|
+
interface ImageSearchOptions {
|
|
208
|
+
page?: number;
|
|
209
|
+
perPage?: number;
|
|
210
|
+
orientation?: 'landscape' | 'portrait' | 'squarish';
|
|
211
|
+
orderBy?: 'relevant' | 'latest';
|
|
212
|
+
contentFilter?: 'low' | 'high';
|
|
213
|
+
}
|
|
214
|
+
interface ImageSearchResult {
|
|
215
|
+
items: ImageProviderResult[];
|
|
216
|
+
page: number;
|
|
217
|
+
total: number;
|
|
218
|
+
totalPages: number;
|
|
219
|
+
}
|
|
220
|
+
interface ImageProvider {
|
|
221
|
+
upload?(file: File): Promise<ImageProviderResult>;
|
|
222
|
+
browse?(): Promise<ImageProviderResult | null>;
|
|
223
|
+
search?(query: string, options?: ImageSearchOptions): Promise<ImageSearchResult>;
|
|
224
|
+
/** Called immediately before a provider asset is inserted into the design. */
|
|
225
|
+
trackUse?(image: ImageProviderResult): Promise<void>;
|
|
226
|
+
}
|
|
227
|
+
interface ShapePlugin {
|
|
228
|
+
name: string;
|
|
229
|
+
icon: string;
|
|
230
|
+
category?: string;
|
|
231
|
+
create(options?: Record<string, unknown>): FabricObject;
|
|
232
|
+
}
|
|
233
|
+
interface TemplateParameter {
|
|
234
|
+
key: string;
|
|
235
|
+
label: string;
|
|
236
|
+
type: 'text' | 'color' | 'number' | 'font';
|
|
237
|
+
default?: string | number;
|
|
238
|
+
}
|
|
239
|
+
interface TemplateDefinition {
|
|
240
|
+
id: string;
|
|
241
|
+
name: string;
|
|
242
|
+
category: string;
|
|
243
|
+
svg: string;
|
|
244
|
+
parameters: TemplateParameter[];
|
|
245
|
+
preview?: string;
|
|
246
|
+
}
|
|
247
|
+
interface PrintifyPositioning {
|
|
248
|
+
x: number;
|
|
249
|
+
y: number;
|
|
250
|
+
scale: number;
|
|
251
|
+
angle: number;
|
|
252
|
+
}
|
|
253
|
+
interface NormalizedLayerPosition {
|
|
254
|
+
layerId: string;
|
|
255
|
+
name: string;
|
|
256
|
+
type: LayerType;
|
|
257
|
+
centerX: number;
|
|
258
|
+
centerY: number;
|
|
259
|
+
width: number;
|
|
260
|
+
height: number;
|
|
261
|
+
scaleX: number;
|
|
262
|
+
scaleY: number;
|
|
263
|
+
angle: number;
|
|
264
|
+
}
|
|
265
|
+
interface PositioningAdapter<T> {
|
|
266
|
+
readonly provider: string;
|
|
267
|
+
map(positions: NormalizedLayerPosition[], canvas: {
|
|
268
|
+
width: number;
|
|
269
|
+
height: number;
|
|
270
|
+
}): T;
|
|
271
|
+
}
|
|
272
|
+
interface ProjectPage {
|
|
273
|
+
id: string;
|
|
274
|
+
name: string;
|
|
275
|
+
state: EditorState;
|
|
276
|
+
}
|
|
277
|
+
interface ProjectState {
|
|
278
|
+
version: '1.0.0';
|
|
279
|
+
activePageId: string;
|
|
280
|
+
pages: ProjectPage[];
|
|
281
|
+
}
|
|
282
|
+
type TileMode = 'grid' | 'brick-horizontal' | 'brick-vertical';
|
|
283
|
+
interface PatternConfig {
|
|
284
|
+
mode: TileMode;
|
|
285
|
+
/**
|
|
286
|
+
* Tile size as a % of the source image's on-canvas size (100 = natural).
|
|
287
|
+
* Smaller values pack more repeats across the print area; larger values make
|
|
288
|
+
* fewer, bigger tiles. Independent of how the source layer was placed.
|
|
289
|
+
*/
|
|
290
|
+
scale: number;
|
|
291
|
+
/** Extra horizontal gap between tiles, as % of tile width. */
|
|
292
|
+
horizontalSpacing: number;
|
|
293
|
+
/** Extra vertical gap between tiles, as % of tile height. */
|
|
294
|
+
verticalSpacing: number;
|
|
295
|
+
/** Rotation of the whole pattern, in degrees. */
|
|
296
|
+
angle: number;
|
|
297
|
+
/** Brick row/column shift, as % of tile size. */
|
|
298
|
+
horizontalOffset: number;
|
|
299
|
+
/**
|
|
300
|
+
* Phase shift of the whole tile grid inside the print area, as % of tile
|
|
301
|
+
* width. The pattern object itself is pinned to the print area (it can't be
|
|
302
|
+
* dragged — that would expose bare edges), so this is how the tiling is
|
|
303
|
+
* nudged into alignment. Clamped to ±100% so coverage is never broken.
|
|
304
|
+
*/
|
|
305
|
+
offsetX: number;
|
|
306
|
+
/** Phase shift of the tile grid, as % of tile height. See {@link offsetX}. */
|
|
307
|
+
offsetY: number;
|
|
308
|
+
/** Added rotation per horizontal step, in degrees. */
|
|
309
|
+
rotationStepH: number;
|
|
310
|
+
/** Added rotation per vertical step, in degrees. */
|
|
311
|
+
rotationStepV: number;
|
|
312
|
+
}
|
|
313
|
+
/** Fabric interaction flags frozen while a layer is rendered as a pattern. */
|
|
314
|
+
interface PatternLocks {
|
|
315
|
+
lockMovementX: boolean;
|
|
316
|
+
lockMovementY: boolean;
|
|
317
|
+
lockScalingX: boolean;
|
|
318
|
+
lockScalingY: boolean;
|
|
319
|
+
lockRotation: boolean;
|
|
320
|
+
hasControls: boolean;
|
|
321
|
+
}
|
|
322
|
+
/** Persisted on a layer's meta while it is rendered as a repeating pattern. */
|
|
323
|
+
interface PatternState {
|
|
324
|
+
config: PatternConfig;
|
|
325
|
+
/** Original (pre-pattern) image source, as a durable data URL when possible. */
|
|
326
|
+
originalSrc: string;
|
|
327
|
+
/**
|
|
328
|
+
* Serialized `clipPath` the image carried before it became a pattern, or null
|
|
329
|
+
* if it had none. A pattern must fill the whole print area, so any pre-pattern
|
|
330
|
+
* clip (e.g. a template crop sized to the original box) is stripped while the
|
|
331
|
+
* pattern is on and re-applied when it is turned off. Persisted so it survives
|
|
332
|
+
* serialization / reload / undo.
|
|
333
|
+
*/
|
|
334
|
+
originalClip?: Record<string, unknown> | null;
|
|
335
|
+
/**
|
|
336
|
+
* Interaction flags the object carried before it became a pattern. A pattern
|
|
337
|
+
* fills the whole print area, so while it is on the object is locked in place
|
|
338
|
+
* (a drag/resize would slide the tiled bitmap off the area and leave a bare
|
|
339
|
+
* band); the captured flags are restored when the pattern is turned off.
|
|
340
|
+
*/
|
|
341
|
+
originalLocks?: PatternLocks;
|
|
342
|
+
/** Original fabric transform, restored when the pattern is turned off. */
|
|
343
|
+
original: {
|
|
344
|
+
left: number;
|
|
345
|
+
top: number;
|
|
346
|
+
scaleX: number;
|
|
347
|
+
scaleY: number;
|
|
348
|
+
width: number;
|
|
349
|
+
height: number;
|
|
350
|
+
angle: number;
|
|
351
|
+
cropX: number;
|
|
352
|
+
cropY: number;
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
declare const DEFAULT_PATTERN_CONFIG: PatternConfig;
|
|
356
|
+
interface MockupPrintArea {
|
|
357
|
+
left: number;
|
|
358
|
+
top: number;
|
|
359
|
+
width: number;
|
|
360
|
+
height: number;
|
|
361
|
+
}
|
|
362
|
+
type MockupBlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'soft-light' | 'hard-light';
|
|
363
|
+
interface MockupOverlay {
|
|
364
|
+
/** Lighting, texture, or shadow image drawn above the design. */
|
|
365
|
+
image: string;
|
|
366
|
+
blendMode?: MockupBlendMode;
|
|
367
|
+
opacity?: number;
|
|
368
|
+
}
|
|
369
|
+
type MockupDisplacementChannel = 'red' | 'green' | 'blue' | 'alpha';
|
|
370
|
+
interface MockupDisplacement {
|
|
371
|
+
/** Channel-map image cover-fitted to the mockup canvas. A value of 128 is neutral. */
|
|
372
|
+
image: string;
|
|
373
|
+
/** Maximum horizontal displacement in document pixels. Defaults to 10. */
|
|
374
|
+
scaleX?: number;
|
|
375
|
+
/** Maximum vertical displacement in document pixels. Defaults to 10. */
|
|
376
|
+
scaleY?: number;
|
|
377
|
+
/** Map channel controlling horizontal displacement. Defaults to red. */
|
|
378
|
+
channelX?: MockupDisplacementChannel;
|
|
379
|
+
/** Map channel controlling vertical displacement. Defaults to green. */
|
|
380
|
+
channelY?: MockupDisplacementChannel;
|
|
381
|
+
}
|
|
382
|
+
interface MockupConfig {
|
|
383
|
+
/** Garment/product image rendered behind the design. */
|
|
384
|
+
image: string;
|
|
385
|
+
/** Print-area rectangle, in canvas pixels. Drawn as a guide. */
|
|
386
|
+
printArea?: MockupPrintArea;
|
|
387
|
+
/** Clip the design to printArea. Defaults to true when printArea exists. */
|
|
388
|
+
clipToPrintArea?: boolean;
|
|
389
|
+
designBlendMode?: MockupBlendMode;
|
|
390
|
+
designOpacity?: number;
|
|
391
|
+
/** Optional channel-map warp applied to the design before compositing. */
|
|
392
|
+
displacement?: MockupDisplacement;
|
|
393
|
+
/** Optional product lighting/shadow pass rendered after the design. */
|
|
394
|
+
overlay?: MockupOverlay;
|
|
395
|
+
}
|
|
396
|
+
interface EditorEvents {
|
|
397
|
+
'layer:added': {
|
|
398
|
+
layer: LayerData;
|
|
399
|
+
};
|
|
400
|
+
'layer:removed': {
|
|
401
|
+
layerId: string;
|
|
402
|
+
};
|
|
403
|
+
'layer:selected': {
|
|
404
|
+
layerId: string | null;
|
|
405
|
+
};
|
|
406
|
+
'layer:modified': {
|
|
407
|
+
layerId: string;
|
|
408
|
+
};
|
|
409
|
+
'layer:reordered': {
|
|
410
|
+
layerIds: string[];
|
|
411
|
+
};
|
|
412
|
+
'layers:changed': {
|
|
413
|
+
layers: LayerData[];
|
|
414
|
+
};
|
|
415
|
+
'selection:changed': {
|
|
416
|
+
selected: string[];
|
|
417
|
+
};
|
|
418
|
+
'history:changed': {
|
|
419
|
+
canUndo: boolean;
|
|
420
|
+
canRedo: boolean;
|
|
421
|
+
};
|
|
422
|
+
'history:snapshot': {
|
|
423
|
+
bytes: number;
|
|
424
|
+
totalBytes: number;
|
|
425
|
+
entries: number;
|
|
426
|
+
};
|
|
427
|
+
'zoom:changed': {
|
|
428
|
+
zoom: number;
|
|
429
|
+
};
|
|
430
|
+
'snap:changed': {
|
|
431
|
+
enabled: boolean;
|
|
432
|
+
};
|
|
433
|
+
'crop:changed': {
|
|
434
|
+
active: boolean;
|
|
435
|
+
layerId: string | null;
|
|
436
|
+
};
|
|
437
|
+
'mockup:changed': {
|
|
438
|
+
mockup: MockupConfig | null;
|
|
439
|
+
};
|
|
440
|
+
'canvas:modified': Record<string, never>;
|
|
441
|
+
'project:changed': {
|
|
442
|
+
activePageId: string;
|
|
443
|
+
pages: Array<{
|
|
444
|
+
id: string;
|
|
445
|
+
name: string;
|
|
446
|
+
}>;
|
|
447
|
+
};
|
|
448
|
+
'export:start': {
|
|
449
|
+
format: string;
|
|
450
|
+
};
|
|
451
|
+
'export:complete': {
|
|
452
|
+
format: string;
|
|
453
|
+
url?: string;
|
|
454
|
+
};
|
|
455
|
+
error: {
|
|
456
|
+
message: string;
|
|
457
|
+
error?: unknown;
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export { type PatternLocks as A, type BackgroundImageOptions as B, type CanvasSizePreset as C, DEFAULT_PATTERN_CONFIG as D, type EditorConfig as E, type FileAdapter as F, type PatternSourceResolver as G, type PatternState as H, type ImageAdjustments as I, type PositioningAdapter as J, type PrintifyPositioning as K, type LayerData as L, type MaskBrushOptions as M, type NormalizedLayerPosition as N, type ProjectPage as O, type PatternConfig as P, type ProjectState as Q, type ResizeOptions as R, type SemanticExportOptions as S, type SerializedBackgroundImageOptions as T, type SerializedLayer as U, type ShapePlugin as V, type SvgExportOptions as W, type TemplateDefinition as X, type TemplateParameter as Y, type TileMode as Z, type Unit as _, type DpiIssue as a, type EditorEvents as b, type EditorState as c, type ExportFormat as d, type FontDefinition as e, type ImageAttribution as f, type ImageProvider as g, type ImageProviderResult as h, type ImageSearchOptions as i, type ImageSearchResult as j, type LayerMeta as k, type LayerType as l, type LicenseConfig as m, type LicensePayload as n, type LicenseStatus as o, type MaskPoint as p, type MaskRefinementPrompt as q, type MaskRefinementProvider as r, type MaskRefinementRequest as s, type MaskRefinementResult as t, type MockupBlendMode as u, type MockupConfig as v, type MockupDisplacement as w, type MockupDisplacementChannel as x, type MockupOverlay as y, type MockupPrintArea as z };
|