@varianta/sdk 0.1.4 → 0.1.5
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/dist/react.cjs.js +2 -0
- package/dist/react.cjs.js.map +1 -0
- package/dist/react.esm.js +291 -0
- package/dist/react.esm.js.map +1 -0
- package/package.json +6 -1
- package/dist/index.umd.js +0 -10
- package/dist/index.umd.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),r=require("react"),V=require("./index.cjs.js"),D=r.forwardRef((I,v)=>{const{templateId:f,productId:y,apiUrl:t,theme:s="light",mode:m="edit",debug:S=!1,className:b,style:T,initialDesign:g,onReady:z,onChange:w,onLayerSelect:l,onLayerAdd:d,onLayerRemove:E,onLayerUpdate:h,onError:c,onFinalize:L,onViewChange:C}=I,R=r.useRef(null),e=r.useRef(null),u=r.useRef({onReady:z,onChange:w,onLayerSelect:l,onLayerAdd:d,onLayerRemove:E,onLayerUpdate:h,onError:c,onFinalize:L,onViewChange:C});return r.useEffect(()=>{u.current={onReady:z,onChange:w,onLayerSelect:l,onLayerAdd:d,onLayerRemove:E,onLayerUpdate:h,onError:c,onFinalize:L,onViewChange:C}},[z,w,l,d,E,h,c,L,C]),r.useEffect(()=>{if(!R.current)return;const i={templateId:f,productId:y,apiUrl:t,theme:s,mode:m,debug:S,initialDesign:g,onReady:()=>u.current.onReady?.(),onChange:n=>u.current.onChange?.(n),onLayerSelect:n=>u.current.onLayerSelect?.(n),onLayerAdd:n=>u.current.onLayerAdd?.(n),onLayerRemove:n=>u.current.onLayerRemove?.(n),onLayerUpdate:n=>u.current.onLayerUpdate?.(n),onError:n=>u.current.onError?.(n),onFinalize:n=>u.current.onFinalize?.(n),onViewChange:n=>u.current.onViewChange?.(n)};try{const n=V.initCustomizer(R.current,i);e.current=n}catch(n){console.error("[Customizer React] Failed to initialize:",n),u.current.onError?.({code:"INIT_ERROR",message:n instanceof Error?n.message:"Unknown error",details:n})}return()=>{e.current&&(e.current.destroy(),e.current=null)}},[f,y,t,S,g]),r.useEffect(()=>{e.current&&e.current.setTheme(s)},[s]),r.useEffect(()=>{e.current&&e.current.setMode(m)},[m]),r.useImperativeHandle(v,()=>({getDesign:()=>{if(!e.current)throw new Error("Editor not initialized");return e.current.getDesign()},setDesign:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.setDesign(i)},undo:()=>{if(!e.current)throw new Error("Editor not initialized");e.current.undo()},redo:()=>{if(!e.current)throw new Error("Editor not initialized");e.current.redo()},canUndo:()=>e.current?e.current.canUndo():!1,canRedo:()=>e.current?e.current.canRedo():!1,finalize:async()=>{if(!e.current)throw new Error("Editor not initialized");return e.current.finalize()},addTextLayer:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.addTextLayer(i)},addImageLayer:async i=>{if(!e.current)throw new Error("Editor not initialized");return e.current.addImageLayer(i)},removeLayer:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.removeLayer(i)},selectLayer:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.selectLayer(i)},getSelectedLayerId:()=>e.current?e.current.getSelectedLayerId():null,getActiveView:()=>e.current?e.current.getActiveView():null,getViews:()=>e.current?e.current.getViews():[],setActiveView:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.setActiveView(i)},setTheme:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.setTheme(i)},setMode:i=>{if(!e.current)throw new Error("Editor not initialized");e.current.setMode(i)},destroy:()=>{e.current&&(e.current.destroy(),e.current=null)},getElement:()=>{if(!e.current)throw new Error("Editor not initialized");return e.current.getElement()}}),[]),p.jsx("div",{ref:R,className:b,style:{width:"100%",height:"100%",...T}})});D.displayName="Customizer";function x(I={}){const{autoSave:v=!1,autoSaveKey:f="customizer-design",autoSaveDebounce:y=1e3}=I,t=r.useRef(null),[s,m]=r.useState(null),[S,b]=r.useState(!1),[T,g]=r.useState(!1),[z,w]=r.useState(null),[l,d]=r.useState(!1),[E,h]=r.useState(null),c=r.useRef(void 0);r.useEffect(()=>{if(!(!v||!s))return c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{try{localStorage.setItem(f,JSON.stringify(s))}catch(o){console.error("[useCustomizer] Auto-save failed:",o)}},y),()=>{c.current&&clearTimeout(c.current)}},[s,v,f,y]);const L=r.useCallback(()=>{if(!t.current)return null;try{return t.current.getDesign()}catch(o){return console.error("[useCustomizer] getDesign failed:",o),null}},[]),C=r.useCallback(o=>{if(t.current)try{t.current.setDesign(o),m(o)}catch(a){console.error("[useCustomizer] setDesign failed:",a)}},[]),R=r.useCallback(()=>{if(t.current)try{t.current.undo(),b(t.current.canUndo()),g(t.current.canRedo())}catch(o){console.error("[useCustomizer] undo failed:",o)}},[]),e=r.useCallback(()=>{if(t.current)try{t.current.redo(),b(t.current.canUndo()),g(t.current.canRedo())}catch(o){console.error("[useCustomizer] redo failed:",o)}},[]),u=r.useCallback(async()=>{if(!t.current||l)return null;d(!0);try{const o=await t.current.finalize();return h(o),o}catch(o){return console.error("[useCustomizer] finalize failed:",o),null}finally{d(!1)}},[l]),i=r.useCallback(o=>{if(t.current)try{t.current.addTextLayer(o)}catch(a){console.error("[useCustomizer] addTextLayer failed:",a)}},[]),n=r.useCallback(async o=>{if(t.current)try{await t.current.addImageLayer(o)}catch(a){console.error("[useCustomizer] addImageLayer failed:",a)}},[]),k=r.useCallback(o=>{if(t.current)try{t.current.removeLayer(o)}catch(a){console.error("[useCustomizer] removeLayer failed:",a)}},[]),U=r.useCallback(o=>{if(t.current)try{t.current.selectLayer(o),w(o)}catch(a){console.error("[useCustomizer] selectLayer failed:",a)}},[]);return{customizerRef:t,design:s,canUndo:S,canRedo:T,selectedLayerId:z,isFinalizing:l,finalizeResult:E,getDesign:L,setDesign:C,undo:R,redo:e,finalize:u,addTextLayer:i,addImageLayer:n,removeLayer:k,selectLayer:U}}exports.Customizer=D;exports.useCustomizer=x;
|
|
2
|
+
//# sourceMappingURL=react.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.cjs.js","sources":["../src/react/Customizer.tsx","../src/react/useCustomizer.ts"],"sourcesContent":["/**\n * React wrapper for Customizer Editor\n * @packageDocumentation\n */\n\nimport {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n type CSSProperties,\n} from 'react';\nimport { initCustomizer } from '../vanilla';\nimport type {\n CustomizerOptions,\n CustomizerInstance,\n DesignJSON,\n FinalizeResult,\n CustomizerError,\n} from '../types';\n\n/**\n * Props for the Customizer React component\n */\nexport interface CustomizerProps {\n /**\n * Template ID to load. Required unless productId is provided.\n */\n templateId?: string;\n\n /**\n * Product ID to load (fetches all views/templates for the product).\n * Alternative to templateId. Exactly one of templateId or productId must be provided.\n */\n productId?: string;\n\n /**\n * API base URL for fetching templates and finalizing designs\n * @default 'https://api.varianta.io'\n */\n apiUrl?: string;\n\n /**\n * Visual theme\n * @default 'light'\n */\n theme?: 'light' | 'dark';\n\n /**\n * Editor mode\n * @default 'edit'\n */\n mode?: 'edit' | 'preview';\n\n /**\n * Enable debug mode with additional logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Custom CSS class name\n */\n className?: string;\n\n /**\n * Custom inline styles\n */\n style?: CSSProperties;\n\n /**\n * Initial design data to load\n */\n initialDesign?: DesignJSON;\n\n /**\n * Called when the editor is ready\n */\n onReady?: () => void;\n\n /**\n * Called when the design changes\n */\n onChange?: (design: DesignJSON) => void;\n\n /**\n * Called when a layer is selected\n */\n onLayerSelect?: (layerId: string | null) => void;\n\n /**\n * Called when a layer is added\n */\n onLayerAdd?: (layerId: string) => void;\n\n /**\n * Called when a layer is removed\n */\n onLayerRemove?: (layerId: string) => void;\n\n /**\n * Called when a layer is updated\n */\n onLayerUpdate?: (layerId: string) => void;\n\n /**\n * Called when an error occurs\n */\n onError?: (error: CustomizerError) => void;\n\n /**\n * Called when finalization is complete\n */\n onFinalize?: (result: FinalizeResult) => void;\n\n /**\n * Called when the active view changes (only relevant when using productId)\n */\n onViewChange?: (viewName: string) => void;\n}\n\n/**\n * Handle type exposed via ref\n */\nexport interface CustomizerHandle extends CustomizerInstance {}\n\n/**\n * Customizer React Component\n *\n * @example\n * ```tsx\n * import { Customizer, CustomizerHandle } from '@varianta/sdk/react';\n * import { useRef } from 'react';\n *\n * function App() {\n * const customizerRef = useRef<CustomizerHandle>(null);\n *\n * const handleFinalize = async () => {\n * if (customizerRef.current) {\n * const result = await customizerRef.current.finalize();\n * console.log('Finalized:', result);\n * }\n * };\n *\n * return (\n * <div style={{ width: '100vw', height: '100vh' }}>\n * <Customizer\n * ref={customizerRef}\n * templateId=\"tshirt-001\"\n * theme=\"light\"\n * onChange={(design) => console.log('Design changed:', design)}\n * onReady={() => console.log('Editor ready!')}\n * />\n * <button onClick={handleFinalize}>Finalize Design</button>\n * </div>\n * );\n * }\n * ```\n */\nexport const Customizer = forwardRef<CustomizerHandle, CustomizerProps>(\n (props, ref) => {\n const {\n templateId,\n productId,\n apiUrl,\n theme = 'light',\n mode = 'edit',\n debug = false,\n className,\n style,\n initialDesign,\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<CustomizerInstance | null>(null);\n\n // Store latest callbacks in a ref to avoid stale closures\n const callbacksRef = useRef({\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n });\n\n // Update callbacks ref whenever they change\n useEffect(() => {\n callbacksRef.current = {\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n };\n }, [onReady, onChange, onLayerSelect, onLayerAdd, onLayerRemove, onLayerUpdate, onError, onFinalize, onViewChange]);\n\n // Initialize the editor\n useEffect(() => {\n if (!containerRef.current) return;\n\n const options: CustomizerOptions = {\n templateId,\n productId,\n apiUrl,\n theme,\n mode,\n debug,\n initialDesign,\n // Use callback refs to always get latest callbacks\n onReady: () => callbacksRef.current.onReady?.(),\n onChange: (design) => callbacksRef.current.onChange?.(design),\n onLayerSelect: (layerId) => callbacksRef.current.onLayerSelect?.(layerId),\n onLayerAdd: (layerId) => callbacksRef.current.onLayerAdd?.(layerId),\n onLayerRemove: (layerId) => callbacksRef.current.onLayerRemove?.(layerId),\n onLayerUpdate: (layerId) => callbacksRef.current.onLayerUpdate?.(layerId),\n onError: (error) => callbacksRef.current.onError?.(error),\n onFinalize: (result) => callbacksRef.current.onFinalize?.(result),\n onViewChange: (viewName) => callbacksRef.current.onViewChange?.(viewName),\n };\n\n try {\n const instance = initCustomizer(containerRef.current, options);\n instanceRef.current = instance;\n } catch (error) {\n console.error('[Customizer React] Failed to initialize:', error);\n callbacksRef.current.onError?.({\n code: 'INIT_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error,\n });\n }\n\n // Cleanup\n return () => {\n if (instanceRef.current) {\n instanceRef.current.destroy();\n instanceRef.current = null;\n }\n };\n }, [templateId, productId, apiUrl, debug, initialDesign]); // Only re-initialize on structural changes\n\n // Update theme when it changes\n useEffect(() => {\n if (instanceRef.current) {\n instanceRef.current.setTheme(theme);\n }\n }, [theme]);\n\n // Update mode when it changes\n useEffect(() => {\n if (instanceRef.current) {\n instanceRef.current.setMode(mode);\n }\n }, [mode]);\n\n // Expose methods via ref\n useImperativeHandle(\n ref,\n () => {\n // Return API that always uses current instanceRef\n return {\n getDesign: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.getDesign();\n },\n setDesign: (design: DesignJSON) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setDesign(design);\n },\n undo: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.undo();\n },\n redo: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.redo();\n },\n canUndo: () => {\n if (!instanceRef.current) return false;\n return instanceRef.current.canUndo();\n },\n canRedo: () => {\n if (!instanceRef.current) return false;\n return instanceRef.current.canRedo();\n },\n finalize: async () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.finalize();\n },\n addTextLayer: (text?: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.addTextLayer(text);\n },\n addImageLayer: async (url: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.addImageLayer(url);\n },\n removeLayer: (layerId: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.removeLayer(layerId);\n },\n selectLayer: (layerId: string | null) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.selectLayer(layerId);\n },\n getSelectedLayerId: () => {\n if (!instanceRef.current) return null;\n return instanceRef.current.getSelectedLayerId();\n },\n getActiveView: () => {\n if (!instanceRef.current) return null;\n return instanceRef.current.getActiveView();\n },\n getViews: () => {\n if (!instanceRef.current) return [];\n return instanceRef.current.getViews();\n },\n setActiveView: (viewName: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setActiveView(viewName);\n },\n setTheme: (newTheme: 'light' | 'dark') => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setTheme(newTheme);\n },\n setMode: (newMode: 'edit' | 'preview') => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setMode(newMode);\n },\n destroy: () => {\n if (!instanceRef.current) return;\n instanceRef.current.destroy();\n instanceRef.current = null;\n },\n getElement: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.getElement();\n },\n };\n },\n [] // Empty deps is OK - we always read from instanceRef.current\n );\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n />\n );\n }\n);\n\nCustomizer.displayName = 'Customizer';\n","/**\n * React hook for controlling the customizer editor\n * @packageDocumentation\n */\n\nimport { useRef, useCallback, useState, useEffect } from 'react';\nimport type { CustomizerHandle } from './Customizer';\nimport type { DesignJSON, FinalizeResult } from '../types';\n\n/**\n * Options for the useCustomizer hook\n */\nexport interface UseCustomizerOptions {\n /**\n * Auto-save design to localStorage\n */\n autoSave?: boolean;\n\n /**\n * localStorage key for auto-save\n * @default 'customizer-design'\n */\n autoSaveKey?: string;\n\n /**\n * Debounce time for auto-save in ms\n * @default 1000\n */\n autoSaveDebounce?: number;\n}\n\n/**\n * Return type for useCustomizer hook\n */\nexport interface UseCustomizerReturn {\n /**\n * Ref to attach to the Customizer component\n */\n customizerRef: React.RefObject<CustomizerHandle | null>;\n\n /**\n * Current design state\n */\n design: DesignJSON | null;\n\n /**\n * Whether undo is available\n */\n canUndo: boolean;\n\n /**\n * Whether redo is available\n */\n canRedo: boolean;\n\n /**\n * Selected layer ID\n */\n selectedLayerId: string | null;\n\n /**\n * Whether finalization is in progress\n */\n isFinalizing: boolean;\n\n /**\n * Finalization result\n */\n finalizeResult: FinalizeResult | null;\n\n /**\n * Get the current design\n */\n getDesign: () => DesignJSON | null;\n\n /**\n * Set a new design\n */\n setDesign: (design: DesignJSON) => void;\n\n /**\n * Undo the last action\n */\n undo: () => void;\n\n /**\n * Redo the last undone action\n */\n redo: () => void;\n\n /**\n * Finalize the design\n */\n finalize: () => Promise<FinalizeResult | null>;\n\n /**\n * Add a text layer\n */\n addTextLayer: (text?: string) => void;\n\n /**\n * Add an image layer\n */\n addImageLayer: (url: string) => Promise<void>;\n\n /**\n * Remove a layer\n */\n removeLayer: (layerId: string) => void;\n\n /**\n * Select a layer\n */\n selectLayer: (layerId: string | null) => void;\n}\n\n/**\n * React hook for controlling the customizer editor\n *\n * @example\n * ```tsx\n * import { Customizer } from '@varianta/sdk/react';\n * import { useCustomizer } from '@varianta/sdk/react';\n *\n * function App() {\n * const {\n * customizerRef,\n * design,\n * canUndo,\n * canRedo,\n * undo,\n * redo,\n * finalize,\n * isFinalizing,\n * } = useCustomizer({ autoSave: true });\n *\n * return (\n * <>\n * <Customizer\n * ref={customizerRef}\n * templateId=\"tshirt-001\"\n * onChange={(d) => console.log('Changed:', d)}\n * />\n * <button onClick={undo} disabled={!canUndo}>Undo</button>\n * <button onClick={redo} disabled={!canRedo}>Redo</button>\n * <button onClick={finalize} disabled={isFinalizing}>\n * {isFinalizing ? 'Finalizing...' : 'Finalize'}\n * </button>\n * </>\n * );\n * }\n * ```\n */\nexport function useCustomizer(\n options: UseCustomizerOptions = {}\n): UseCustomizerReturn {\n const {\n autoSave = false,\n autoSaveKey = 'customizer-design',\n autoSaveDebounce = 1000,\n } = options;\n\n const customizerRef = useRef<CustomizerHandle>(null);\n const [design, setDesign] = useState<DesignJSON | null>(null);\n const [canUndo, setCanUndo] = useState(false);\n const [canRedo, setCanRedo] = useState(false);\n const [selectedLayerId, setSelectedLayerId] = useState<string | null>(null);\n const [isFinalizing, setIsFinalizing] = useState(false);\n const [finalizeResult, setFinalizeResult] = useState<FinalizeResult | null>(\n null\n );\n\n const autoSaveTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n // Auto-save to localStorage\n useEffect(() => {\n if (!autoSave || !design) return;\n\n // Clear existing timeout\n if (autoSaveTimeoutRef.current) {\n clearTimeout(autoSaveTimeoutRef.current);\n }\n\n // Set new timeout\n autoSaveTimeoutRef.current = setTimeout(() => {\n try {\n localStorage.setItem(autoSaveKey, JSON.stringify(design));\n } catch (error) {\n console.error('[useCustomizer] Auto-save failed:', error);\n }\n }, autoSaveDebounce);\n\n return () => {\n if (autoSaveTimeoutRef.current) {\n clearTimeout(autoSaveTimeoutRef.current);\n }\n };\n }, [design, autoSave, autoSaveKey, autoSaveDebounce]);\n\n const getDesign = useCallback(() => {\n if (!customizerRef.current) return null;\n try {\n return customizerRef.current.getDesign();\n } catch (error) {\n console.error('[useCustomizer] getDesign failed:', error);\n return null;\n }\n }, []);\n\n const setDesignCallback = useCallback((newDesign: DesignJSON) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.setDesign(newDesign);\n setDesign(newDesign);\n } catch (error) {\n console.error('[useCustomizer] setDesign failed:', error);\n }\n }, []);\n\n const undo = useCallback(() => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.undo();\n setCanUndo(customizerRef.current.canUndo());\n setCanRedo(customizerRef.current.canRedo());\n } catch (error) {\n console.error('[useCustomizer] undo failed:', error);\n }\n }, []);\n\n const redo = useCallback(() => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.redo();\n setCanUndo(customizerRef.current.canUndo());\n setCanRedo(customizerRef.current.canRedo());\n } catch (error) {\n console.error('[useCustomizer] redo failed:', error);\n }\n }, []);\n\n const finalize = useCallback(async () => {\n if (!customizerRef.current || isFinalizing) return null;\n\n setIsFinalizing(true);\n try {\n const result = await customizerRef.current.finalize();\n setFinalizeResult(result);\n return result;\n } catch (error) {\n console.error('[useCustomizer] finalize failed:', error);\n return null;\n } finally {\n setIsFinalizing(false);\n }\n }, [isFinalizing]);\n\n const addTextLayer = useCallback((text?: string) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.addTextLayer(text);\n } catch (error) {\n console.error('[useCustomizer] addTextLayer failed:', error);\n }\n }, []);\n\n const addImageLayer = useCallback(async (url: string) => {\n if (!customizerRef.current) return;\n try {\n await customizerRef.current.addImageLayer(url);\n } catch (error) {\n console.error('[useCustomizer] addImageLayer failed:', error);\n }\n }, []);\n\n const removeLayer = useCallback((layerId: string) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.removeLayer(layerId);\n } catch (error) {\n console.error('[useCustomizer] removeLayer failed:', error);\n }\n }, []);\n\n const selectLayer = useCallback((layerId: string | null) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.selectLayer(layerId);\n setSelectedLayerId(layerId);\n } catch (error) {\n console.error('[useCustomizer] selectLayer failed:', error);\n }\n }, []);\n\n return {\n customizerRef,\n design,\n canUndo,\n canRedo,\n selectedLayerId,\n isFinalizing,\n finalizeResult,\n getDesign,\n setDesign: setDesignCallback,\n undo,\n redo,\n finalize,\n addTextLayer,\n addImageLayer,\n removeLayer,\n selectLayer,\n };\n}\n"],"names":["Customizer","forwardRef","props","ref","templateId","productId","apiUrl","theme","mode","debug","className","style","initialDesign","onReady","onChange","onLayerSelect","onLayerAdd","onLayerRemove","onLayerUpdate","onError","onFinalize","onViewChange","containerRef","useRef","instanceRef","callbacksRef","useEffect","options","design","layerId","error","result","viewName","instance","initCustomizer","useImperativeHandle","text","url","newTheme","newMode","jsx","useCustomizer","autoSave","autoSaveKey","autoSaveDebounce","customizerRef","setDesign","useState","canUndo","setCanUndo","canRedo","setCanRedo","selectedLayerId","setSelectedLayerId","isFinalizing","setIsFinalizing","finalizeResult","setFinalizeResult","autoSaveTimeoutRef","getDesign","useCallback","setDesignCallback","newDesign","undo","redo","finalize","addTextLayer","addImageLayer","removeLayer","selectLayer"],"mappings":"oKA+JaA,EAAaC,EAAAA,WACxB,CAACC,EAAOC,IAAQ,CACd,KAAM,CACJ,WAAAC,EACA,UAAAC,EACA,OAAAC,EACA,MAAAC,EAAQ,QACR,KAAAC,EAAO,OACP,MAAAC,EAAQ,GACR,UAAAC,EACA,MAAAC,EACA,cAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,EACA,WAAAC,EACA,cAAAC,EACA,cAAAC,EACA,QAAAC,EACA,WAAAC,EACA,aAAAC,CAAA,EACEnB,EAEEoB,EAAeC,EAAAA,OAAuB,IAAI,EAC1CC,EAAcD,EAAAA,OAAkC,IAAI,EAGpDE,EAAeF,EAAAA,OAAO,CAC1B,QAAAV,EACA,SAAAC,EACA,cAAAC,EACA,WAAAC,EACA,cAAAC,EACA,cAAAC,EACA,QAAAC,EACA,WAAAC,EACA,aAAAC,CAAA,CACD,EAGDK,OAA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CACF,EAAG,CAAA,CAAE,EAECuC,EAAcT,cAAa/B,GAA2B,CAC1D,GAAKgB,EAAc,QACnB,GAAI,CACFA,EAAc,QAAQ,YAAYhB,CAAO,EACzCwB,EAAmBxB,CAAO,CAC5B,OAASC,EAAO,CACd,QAAQ,MAAM,sCAAuCA,CAAK,CAC5D,CACF,EAAG,CAAA,CAAE,EAEL,MAAO,CACL,cAAAe,EACA,OAAAjB,EACA,QAAAoB,EACA,QAAAE,EACA,gBAAAE,EACA,aAAAE,EACA,eAAAE,EACA,UAAAG,EACA,UAAWE,EACX,KAAAE,EACA,KAAAC,EACA,SAAAC,EACA,aAAAC,EACA,cAAAC,EACA,YAAAC,EACA,YAAAC,CAAA,CAEJ"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as b, useRef as p, useEffect as I, useImperativeHandle as k, useState as f, useCallback as a } from "react";
|
|
3
|
+
import { initCustomizer as N } from "./index.esm.js";
|
|
4
|
+
const M = b(
|
|
5
|
+
(U, D) => {
|
|
6
|
+
const {
|
|
7
|
+
templateId: y,
|
|
8
|
+
productId: m,
|
|
9
|
+
apiUrl: r,
|
|
10
|
+
theme: s = "light",
|
|
11
|
+
mode: g = "edit",
|
|
12
|
+
debug: S = !1,
|
|
13
|
+
className: T,
|
|
14
|
+
style: V,
|
|
15
|
+
initialDesign: z,
|
|
16
|
+
onReady: w,
|
|
17
|
+
onChange: h,
|
|
18
|
+
onLayerSelect: l,
|
|
19
|
+
onLayerAdd: d,
|
|
20
|
+
onLayerRemove: L,
|
|
21
|
+
onLayerUpdate: E,
|
|
22
|
+
onError: c,
|
|
23
|
+
onFinalize: C,
|
|
24
|
+
onViewChange: R
|
|
25
|
+
} = U, v = p(null), e = p(null), i = p({
|
|
26
|
+
onReady: w,
|
|
27
|
+
onChange: h,
|
|
28
|
+
onLayerSelect: l,
|
|
29
|
+
onLayerAdd: d,
|
|
30
|
+
onLayerRemove: L,
|
|
31
|
+
onLayerUpdate: E,
|
|
32
|
+
onError: c,
|
|
33
|
+
onFinalize: C,
|
|
34
|
+
onViewChange: R
|
|
35
|
+
});
|
|
36
|
+
return I(() => {
|
|
37
|
+
i.current = {
|
|
38
|
+
onReady: w,
|
|
39
|
+
onChange: h,
|
|
40
|
+
onLayerSelect: l,
|
|
41
|
+
onLayerAdd: d,
|
|
42
|
+
onLayerRemove: L,
|
|
43
|
+
onLayerUpdate: E,
|
|
44
|
+
onError: c,
|
|
45
|
+
onFinalize: C,
|
|
46
|
+
onViewChange: R
|
|
47
|
+
};
|
|
48
|
+
}, [w, h, l, d, L, E, c, C, R]), I(() => {
|
|
49
|
+
if (!v.current) return;
|
|
50
|
+
const o = {
|
|
51
|
+
templateId: y,
|
|
52
|
+
productId: m,
|
|
53
|
+
apiUrl: r,
|
|
54
|
+
theme: s,
|
|
55
|
+
mode: g,
|
|
56
|
+
debug: S,
|
|
57
|
+
initialDesign: z,
|
|
58
|
+
// Use callback refs to always get latest callbacks
|
|
59
|
+
onReady: () => i.current.onReady?.(),
|
|
60
|
+
onChange: (t) => i.current.onChange?.(t),
|
|
61
|
+
onLayerSelect: (t) => i.current.onLayerSelect?.(t),
|
|
62
|
+
onLayerAdd: (t) => i.current.onLayerAdd?.(t),
|
|
63
|
+
onLayerRemove: (t) => i.current.onLayerRemove?.(t),
|
|
64
|
+
onLayerUpdate: (t) => i.current.onLayerUpdate?.(t),
|
|
65
|
+
onError: (t) => i.current.onError?.(t),
|
|
66
|
+
onFinalize: (t) => i.current.onFinalize?.(t),
|
|
67
|
+
onViewChange: (t) => i.current.onViewChange?.(t)
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const t = N(v.current, o);
|
|
71
|
+
e.current = t;
|
|
72
|
+
} catch (t) {
|
|
73
|
+
console.error("[Customizer React] Failed to initialize:", t), i.current.onError?.({
|
|
74
|
+
code: "INIT_ERROR",
|
|
75
|
+
message: t instanceof Error ? t.message : "Unknown error",
|
|
76
|
+
details: t
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
e.current && (e.current.destroy(), e.current = null);
|
|
81
|
+
};
|
|
82
|
+
}, [y, m, r, S, z]), I(() => {
|
|
83
|
+
e.current && e.current.setTheme(s);
|
|
84
|
+
}, [s]), I(() => {
|
|
85
|
+
e.current && e.current.setMode(g);
|
|
86
|
+
}, [g]), k(
|
|
87
|
+
D,
|
|
88
|
+
() => ({
|
|
89
|
+
getDesign: () => {
|
|
90
|
+
if (!e.current)
|
|
91
|
+
throw new Error("Editor not initialized");
|
|
92
|
+
return e.current.getDesign();
|
|
93
|
+
},
|
|
94
|
+
setDesign: (o) => {
|
|
95
|
+
if (!e.current)
|
|
96
|
+
throw new Error("Editor not initialized");
|
|
97
|
+
e.current.setDesign(o);
|
|
98
|
+
},
|
|
99
|
+
undo: () => {
|
|
100
|
+
if (!e.current)
|
|
101
|
+
throw new Error("Editor not initialized");
|
|
102
|
+
e.current.undo();
|
|
103
|
+
},
|
|
104
|
+
redo: () => {
|
|
105
|
+
if (!e.current)
|
|
106
|
+
throw new Error("Editor not initialized");
|
|
107
|
+
e.current.redo();
|
|
108
|
+
},
|
|
109
|
+
canUndo: () => e.current ? e.current.canUndo() : !1,
|
|
110
|
+
canRedo: () => e.current ? e.current.canRedo() : !1,
|
|
111
|
+
finalize: async () => {
|
|
112
|
+
if (!e.current)
|
|
113
|
+
throw new Error("Editor not initialized");
|
|
114
|
+
return e.current.finalize();
|
|
115
|
+
},
|
|
116
|
+
addTextLayer: (o) => {
|
|
117
|
+
if (!e.current)
|
|
118
|
+
throw new Error("Editor not initialized");
|
|
119
|
+
e.current.addTextLayer(o);
|
|
120
|
+
},
|
|
121
|
+
addImageLayer: async (o) => {
|
|
122
|
+
if (!e.current)
|
|
123
|
+
throw new Error("Editor not initialized");
|
|
124
|
+
return e.current.addImageLayer(o);
|
|
125
|
+
},
|
|
126
|
+
removeLayer: (o) => {
|
|
127
|
+
if (!e.current)
|
|
128
|
+
throw new Error("Editor not initialized");
|
|
129
|
+
e.current.removeLayer(o);
|
|
130
|
+
},
|
|
131
|
+
selectLayer: (o) => {
|
|
132
|
+
if (!e.current)
|
|
133
|
+
throw new Error("Editor not initialized");
|
|
134
|
+
e.current.selectLayer(o);
|
|
135
|
+
},
|
|
136
|
+
getSelectedLayerId: () => e.current ? e.current.getSelectedLayerId() : null,
|
|
137
|
+
getActiveView: () => e.current ? e.current.getActiveView() : null,
|
|
138
|
+
getViews: () => e.current ? e.current.getViews() : [],
|
|
139
|
+
setActiveView: (o) => {
|
|
140
|
+
if (!e.current)
|
|
141
|
+
throw new Error("Editor not initialized");
|
|
142
|
+
e.current.setActiveView(o);
|
|
143
|
+
},
|
|
144
|
+
setTheme: (o) => {
|
|
145
|
+
if (!e.current)
|
|
146
|
+
throw new Error("Editor not initialized");
|
|
147
|
+
e.current.setTheme(o);
|
|
148
|
+
},
|
|
149
|
+
setMode: (o) => {
|
|
150
|
+
if (!e.current)
|
|
151
|
+
throw new Error("Editor not initialized");
|
|
152
|
+
e.current.setMode(o);
|
|
153
|
+
},
|
|
154
|
+
destroy: () => {
|
|
155
|
+
e.current && (e.current.destroy(), e.current = null);
|
|
156
|
+
},
|
|
157
|
+
getElement: () => {
|
|
158
|
+
if (!e.current)
|
|
159
|
+
throw new Error("Editor not initialized");
|
|
160
|
+
return e.current.getElement();
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
[]
|
|
164
|
+
// Empty deps is OK - we always read from instanceRef.current
|
|
165
|
+
), /* @__PURE__ */ F(
|
|
166
|
+
"div",
|
|
167
|
+
{
|
|
168
|
+
ref: v,
|
|
169
|
+
className: T,
|
|
170
|
+
style: {
|
|
171
|
+
width: "100%",
|
|
172
|
+
height: "100%",
|
|
173
|
+
...V
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
M.displayName = "Customizer";
|
|
180
|
+
function J(U = {}) {
|
|
181
|
+
const {
|
|
182
|
+
autoSave: D = !1,
|
|
183
|
+
autoSaveKey: y = "customizer-design",
|
|
184
|
+
autoSaveDebounce: m = 1e3
|
|
185
|
+
} = U, r = p(null), [s, g] = f(null), [S, T] = f(!1), [V, z] = f(!1), [w, h] = f(null), [l, d] = f(!1), [L, E] = f(
|
|
186
|
+
null
|
|
187
|
+
), c = p(void 0);
|
|
188
|
+
I(() => {
|
|
189
|
+
if (!(!D || !s))
|
|
190
|
+
return c.current && clearTimeout(c.current), c.current = setTimeout(() => {
|
|
191
|
+
try {
|
|
192
|
+
localStorage.setItem(y, JSON.stringify(s));
|
|
193
|
+
} catch (n) {
|
|
194
|
+
console.error("[useCustomizer] Auto-save failed:", n);
|
|
195
|
+
}
|
|
196
|
+
}, m), () => {
|
|
197
|
+
c.current && clearTimeout(c.current);
|
|
198
|
+
};
|
|
199
|
+
}, [s, D, y, m]);
|
|
200
|
+
const C = a(() => {
|
|
201
|
+
if (!r.current) return null;
|
|
202
|
+
try {
|
|
203
|
+
return r.current.getDesign();
|
|
204
|
+
} catch (n) {
|
|
205
|
+
return console.error("[useCustomizer] getDesign failed:", n), null;
|
|
206
|
+
}
|
|
207
|
+
}, []), R = a((n) => {
|
|
208
|
+
if (r.current)
|
|
209
|
+
try {
|
|
210
|
+
r.current.setDesign(n), g(n);
|
|
211
|
+
} catch (u) {
|
|
212
|
+
console.error("[useCustomizer] setDesign failed:", u);
|
|
213
|
+
}
|
|
214
|
+
}, []), v = a(() => {
|
|
215
|
+
if (r.current)
|
|
216
|
+
try {
|
|
217
|
+
r.current.undo(), T(r.current.canUndo()), z(r.current.canRedo());
|
|
218
|
+
} catch (n) {
|
|
219
|
+
console.error("[useCustomizer] undo failed:", n);
|
|
220
|
+
}
|
|
221
|
+
}, []), e = a(() => {
|
|
222
|
+
if (r.current)
|
|
223
|
+
try {
|
|
224
|
+
r.current.redo(), T(r.current.canUndo()), z(r.current.canRedo());
|
|
225
|
+
} catch (n) {
|
|
226
|
+
console.error("[useCustomizer] redo failed:", n);
|
|
227
|
+
}
|
|
228
|
+
}, []), i = a(async () => {
|
|
229
|
+
if (!r.current || l) return null;
|
|
230
|
+
d(!0);
|
|
231
|
+
try {
|
|
232
|
+
const n = await r.current.finalize();
|
|
233
|
+
return E(n), n;
|
|
234
|
+
} catch (n) {
|
|
235
|
+
return console.error("[useCustomizer] finalize failed:", n), null;
|
|
236
|
+
} finally {
|
|
237
|
+
d(!1);
|
|
238
|
+
}
|
|
239
|
+
}, [l]), o = a((n) => {
|
|
240
|
+
if (r.current)
|
|
241
|
+
try {
|
|
242
|
+
r.current.addTextLayer(n);
|
|
243
|
+
} catch (u) {
|
|
244
|
+
console.error("[useCustomizer] addTextLayer failed:", u);
|
|
245
|
+
}
|
|
246
|
+
}, []), t = a(async (n) => {
|
|
247
|
+
if (r.current)
|
|
248
|
+
try {
|
|
249
|
+
await r.current.addImageLayer(n);
|
|
250
|
+
} catch (u) {
|
|
251
|
+
console.error("[useCustomizer] addImageLayer failed:", u);
|
|
252
|
+
}
|
|
253
|
+
}, []), A = a((n) => {
|
|
254
|
+
if (r.current)
|
|
255
|
+
try {
|
|
256
|
+
r.current.removeLayer(n);
|
|
257
|
+
} catch (u) {
|
|
258
|
+
console.error("[useCustomizer] removeLayer failed:", u);
|
|
259
|
+
}
|
|
260
|
+
}, []), x = a((n) => {
|
|
261
|
+
if (r.current)
|
|
262
|
+
try {
|
|
263
|
+
r.current.selectLayer(n), h(n);
|
|
264
|
+
} catch (u) {
|
|
265
|
+
console.error("[useCustomizer] selectLayer failed:", u);
|
|
266
|
+
}
|
|
267
|
+
}, []);
|
|
268
|
+
return {
|
|
269
|
+
customizerRef: r,
|
|
270
|
+
design: s,
|
|
271
|
+
canUndo: S,
|
|
272
|
+
canRedo: V,
|
|
273
|
+
selectedLayerId: w,
|
|
274
|
+
isFinalizing: l,
|
|
275
|
+
finalizeResult: L,
|
|
276
|
+
getDesign: C,
|
|
277
|
+
setDesign: R,
|
|
278
|
+
undo: v,
|
|
279
|
+
redo: e,
|
|
280
|
+
finalize: i,
|
|
281
|
+
addTextLayer: o,
|
|
282
|
+
addImageLayer: t,
|
|
283
|
+
removeLayer: A,
|
|
284
|
+
selectLayer: x
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
M as Customizer,
|
|
289
|
+
J as useCustomizer
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=react.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.esm.js","sources":["../src/react/Customizer.tsx","../src/react/useCustomizer.ts"],"sourcesContent":["/**\n * React wrapper for Customizer Editor\n * @packageDocumentation\n */\n\nimport {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n type CSSProperties,\n} from 'react';\nimport { initCustomizer } from '../vanilla';\nimport type {\n CustomizerOptions,\n CustomizerInstance,\n DesignJSON,\n FinalizeResult,\n CustomizerError,\n} from '../types';\n\n/**\n * Props for the Customizer React component\n */\nexport interface CustomizerProps {\n /**\n * Template ID to load. Required unless productId is provided.\n */\n templateId?: string;\n\n /**\n * Product ID to load (fetches all views/templates for the product).\n * Alternative to templateId. Exactly one of templateId or productId must be provided.\n */\n productId?: string;\n\n /**\n * API base URL for fetching templates and finalizing designs\n * @default 'https://api.varianta.io'\n */\n apiUrl?: string;\n\n /**\n * Visual theme\n * @default 'light'\n */\n theme?: 'light' | 'dark';\n\n /**\n * Editor mode\n * @default 'edit'\n */\n mode?: 'edit' | 'preview';\n\n /**\n * Enable debug mode with additional logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Custom CSS class name\n */\n className?: string;\n\n /**\n * Custom inline styles\n */\n style?: CSSProperties;\n\n /**\n * Initial design data to load\n */\n initialDesign?: DesignJSON;\n\n /**\n * Called when the editor is ready\n */\n onReady?: () => void;\n\n /**\n * Called when the design changes\n */\n onChange?: (design: DesignJSON) => void;\n\n /**\n * Called when a layer is selected\n */\n onLayerSelect?: (layerId: string | null) => void;\n\n /**\n * Called when a layer is added\n */\n onLayerAdd?: (layerId: string) => void;\n\n /**\n * Called when a layer is removed\n */\n onLayerRemove?: (layerId: string) => void;\n\n /**\n * Called when a layer is updated\n */\n onLayerUpdate?: (layerId: string) => void;\n\n /**\n * Called when an error occurs\n */\n onError?: (error: CustomizerError) => void;\n\n /**\n * Called when finalization is complete\n */\n onFinalize?: (result: FinalizeResult) => void;\n\n /**\n * Called when the active view changes (only relevant when using productId)\n */\n onViewChange?: (viewName: string) => void;\n}\n\n/**\n * Handle type exposed via ref\n */\nexport interface CustomizerHandle extends CustomizerInstance {}\n\n/**\n * Customizer React Component\n *\n * @example\n * ```tsx\n * import { Customizer, CustomizerHandle } from '@varianta/sdk/react';\n * import { useRef } from 'react';\n *\n * function App() {\n * const customizerRef = useRef<CustomizerHandle>(null);\n *\n * const handleFinalize = async () => {\n * if (customizerRef.current) {\n * const result = await customizerRef.current.finalize();\n * console.log('Finalized:', result);\n * }\n * };\n *\n * return (\n * <div style={{ width: '100vw', height: '100vh' }}>\n * <Customizer\n * ref={customizerRef}\n * templateId=\"tshirt-001\"\n * theme=\"light\"\n * onChange={(design) => console.log('Design changed:', design)}\n * onReady={() => console.log('Editor ready!')}\n * />\n * <button onClick={handleFinalize}>Finalize Design</button>\n * </div>\n * );\n * }\n * ```\n */\nexport const Customizer = forwardRef<CustomizerHandle, CustomizerProps>(\n (props, ref) => {\n const {\n templateId,\n productId,\n apiUrl,\n theme = 'light',\n mode = 'edit',\n debug = false,\n className,\n style,\n initialDesign,\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n } = props;\n\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<CustomizerInstance | null>(null);\n\n // Store latest callbacks in a ref to avoid stale closures\n const callbacksRef = useRef({\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n });\n\n // Update callbacks ref whenever they change\n useEffect(() => {\n callbacksRef.current = {\n onReady,\n onChange,\n onLayerSelect,\n onLayerAdd,\n onLayerRemove,\n onLayerUpdate,\n onError,\n onFinalize,\n onViewChange,\n };\n }, [onReady, onChange, onLayerSelect, onLayerAdd, onLayerRemove, onLayerUpdate, onError, onFinalize, onViewChange]);\n\n // Initialize the editor\n useEffect(() => {\n if (!containerRef.current) return;\n\n const options: CustomizerOptions = {\n templateId,\n productId,\n apiUrl,\n theme,\n mode,\n debug,\n initialDesign,\n // Use callback refs to always get latest callbacks\n onReady: () => callbacksRef.current.onReady?.(),\n onChange: (design) => callbacksRef.current.onChange?.(design),\n onLayerSelect: (layerId) => callbacksRef.current.onLayerSelect?.(layerId),\n onLayerAdd: (layerId) => callbacksRef.current.onLayerAdd?.(layerId),\n onLayerRemove: (layerId) => callbacksRef.current.onLayerRemove?.(layerId),\n onLayerUpdate: (layerId) => callbacksRef.current.onLayerUpdate?.(layerId),\n onError: (error) => callbacksRef.current.onError?.(error),\n onFinalize: (result) => callbacksRef.current.onFinalize?.(result),\n onViewChange: (viewName) => callbacksRef.current.onViewChange?.(viewName),\n };\n\n try {\n const instance = initCustomizer(containerRef.current, options);\n instanceRef.current = instance;\n } catch (error) {\n console.error('[Customizer React] Failed to initialize:', error);\n callbacksRef.current.onError?.({\n code: 'INIT_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error,\n });\n }\n\n // Cleanup\n return () => {\n if (instanceRef.current) {\n instanceRef.current.destroy();\n instanceRef.current = null;\n }\n };\n }, [templateId, productId, apiUrl, debug, initialDesign]); // Only re-initialize on structural changes\n\n // Update theme when it changes\n useEffect(() => {\n if (instanceRef.current) {\n instanceRef.current.setTheme(theme);\n }\n }, [theme]);\n\n // Update mode when it changes\n useEffect(() => {\n if (instanceRef.current) {\n instanceRef.current.setMode(mode);\n }\n }, [mode]);\n\n // Expose methods via ref\n useImperativeHandle(\n ref,\n () => {\n // Return API that always uses current instanceRef\n return {\n getDesign: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.getDesign();\n },\n setDesign: (design: DesignJSON) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setDesign(design);\n },\n undo: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.undo();\n },\n redo: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.redo();\n },\n canUndo: () => {\n if (!instanceRef.current) return false;\n return instanceRef.current.canUndo();\n },\n canRedo: () => {\n if (!instanceRef.current) return false;\n return instanceRef.current.canRedo();\n },\n finalize: async () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.finalize();\n },\n addTextLayer: (text?: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.addTextLayer(text);\n },\n addImageLayer: async (url: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.addImageLayer(url);\n },\n removeLayer: (layerId: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.removeLayer(layerId);\n },\n selectLayer: (layerId: string | null) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.selectLayer(layerId);\n },\n getSelectedLayerId: () => {\n if (!instanceRef.current) return null;\n return instanceRef.current.getSelectedLayerId();\n },\n getActiveView: () => {\n if (!instanceRef.current) return null;\n return instanceRef.current.getActiveView();\n },\n getViews: () => {\n if (!instanceRef.current) return [];\n return instanceRef.current.getViews();\n },\n setActiveView: (viewName: string) => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setActiveView(viewName);\n },\n setTheme: (newTheme: 'light' | 'dark') => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setTheme(newTheme);\n },\n setMode: (newMode: 'edit' | 'preview') => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n instanceRef.current.setMode(newMode);\n },\n destroy: () => {\n if (!instanceRef.current) return;\n instanceRef.current.destroy();\n instanceRef.current = null;\n },\n getElement: () => {\n if (!instanceRef.current) {\n throw new Error('Editor not initialized');\n }\n return instanceRef.current.getElement();\n },\n };\n },\n [] // Empty deps is OK - we always read from instanceRef.current\n );\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n />\n );\n }\n);\n\nCustomizer.displayName = 'Customizer';\n","/**\n * React hook for controlling the customizer editor\n * @packageDocumentation\n */\n\nimport { useRef, useCallback, useState, useEffect } from 'react';\nimport type { CustomizerHandle } from './Customizer';\nimport type { DesignJSON, FinalizeResult } from '../types';\n\n/**\n * Options for the useCustomizer hook\n */\nexport interface UseCustomizerOptions {\n /**\n * Auto-save design to localStorage\n */\n autoSave?: boolean;\n\n /**\n * localStorage key for auto-save\n * @default 'customizer-design'\n */\n autoSaveKey?: string;\n\n /**\n * Debounce time for auto-save in ms\n * @default 1000\n */\n autoSaveDebounce?: number;\n}\n\n/**\n * Return type for useCustomizer hook\n */\nexport interface UseCustomizerReturn {\n /**\n * Ref to attach to the Customizer component\n */\n customizerRef: React.RefObject<CustomizerHandle | null>;\n\n /**\n * Current design state\n */\n design: DesignJSON | null;\n\n /**\n * Whether undo is available\n */\n canUndo: boolean;\n\n /**\n * Whether redo is available\n */\n canRedo: boolean;\n\n /**\n * Selected layer ID\n */\n selectedLayerId: string | null;\n\n /**\n * Whether finalization is in progress\n */\n isFinalizing: boolean;\n\n /**\n * Finalization result\n */\n finalizeResult: FinalizeResult | null;\n\n /**\n * Get the current design\n */\n getDesign: () => DesignJSON | null;\n\n /**\n * Set a new design\n */\n setDesign: (design: DesignJSON) => void;\n\n /**\n * Undo the last action\n */\n undo: () => void;\n\n /**\n * Redo the last undone action\n */\n redo: () => void;\n\n /**\n * Finalize the design\n */\n finalize: () => Promise<FinalizeResult | null>;\n\n /**\n * Add a text layer\n */\n addTextLayer: (text?: string) => void;\n\n /**\n * Add an image layer\n */\n addImageLayer: (url: string) => Promise<void>;\n\n /**\n * Remove a layer\n */\n removeLayer: (layerId: string) => void;\n\n /**\n * Select a layer\n */\n selectLayer: (layerId: string | null) => void;\n}\n\n/**\n * React hook for controlling the customizer editor\n *\n * @example\n * ```tsx\n * import { Customizer } from '@varianta/sdk/react';\n * import { useCustomizer } from '@varianta/sdk/react';\n *\n * function App() {\n * const {\n * customizerRef,\n * design,\n * canUndo,\n * canRedo,\n * undo,\n * redo,\n * finalize,\n * isFinalizing,\n * } = useCustomizer({ autoSave: true });\n *\n * return (\n * <>\n * <Customizer\n * ref={customizerRef}\n * templateId=\"tshirt-001\"\n * onChange={(d) => console.log('Changed:', d)}\n * />\n * <button onClick={undo} disabled={!canUndo}>Undo</button>\n * <button onClick={redo} disabled={!canRedo}>Redo</button>\n * <button onClick={finalize} disabled={isFinalizing}>\n * {isFinalizing ? 'Finalizing...' : 'Finalize'}\n * </button>\n * </>\n * );\n * }\n * ```\n */\nexport function useCustomizer(\n options: UseCustomizerOptions = {}\n): UseCustomizerReturn {\n const {\n autoSave = false,\n autoSaveKey = 'customizer-design',\n autoSaveDebounce = 1000,\n } = options;\n\n const customizerRef = useRef<CustomizerHandle>(null);\n const [design, setDesign] = useState<DesignJSON | null>(null);\n const [canUndo, setCanUndo] = useState(false);\n const [canRedo, setCanRedo] = useState(false);\n const [selectedLayerId, setSelectedLayerId] = useState<string | null>(null);\n const [isFinalizing, setIsFinalizing] = useState(false);\n const [finalizeResult, setFinalizeResult] = useState<FinalizeResult | null>(\n null\n );\n\n const autoSaveTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n // Auto-save to localStorage\n useEffect(() => {\n if (!autoSave || !design) return;\n\n // Clear existing timeout\n if (autoSaveTimeoutRef.current) {\n clearTimeout(autoSaveTimeoutRef.current);\n }\n\n // Set new timeout\n autoSaveTimeoutRef.current = setTimeout(() => {\n try {\n localStorage.setItem(autoSaveKey, JSON.stringify(design));\n } catch (error) {\n console.error('[useCustomizer] Auto-save failed:', error);\n }\n }, autoSaveDebounce);\n\n return () => {\n if (autoSaveTimeoutRef.current) {\n clearTimeout(autoSaveTimeoutRef.current);\n }\n };\n }, [design, autoSave, autoSaveKey, autoSaveDebounce]);\n\n const getDesign = useCallback(() => {\n if (!customizerRef.current) return null;\n try {\n return customizerRef.current.getDesign();\n } catch (error) {\n console.error('[useCustomizer] getDesign failed:', error);\n return null;\n }\n }, []);\n\n const setDesignCallback = useCallback((newDesign: DesignJSON) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.setDesign(newDesign);\n setDesign(newDesign);\n } catch (error) {\n console.error('[useCustomizer] setDesign failed:', error);\n }\n }, []);\n\n const undo = useCallback(() => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.undo();\n setCanUndo(customizerRef.current.canUndo());\n setCanRedo(customizerRef.current.canRedo());\n } catch (error) {\n console.error('[useCustomizer] undo failed:', error);\n }\n }, []);\n\n const redo = useCallback(() => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.redo();\n setCanUndo(customizerRef.current.canUndo());\n setCanRedo(customizerRef.current.canRedo());\n } catch (error) {\n console.error('[useCustomizer] redo failed:', error);\n }\n }, []);\n\n const finalize = useCallback(async () => {\n if (!customizerRef.current || isFinalizing) return null;\n\n setIsFinalizing(true);\n try {\n const result = await customizerRef.current.finalize();\n setFinalizeResult(result);\n return result;\n } catch (error) {\n console.error('[useCustomizer] finalize failed:', error);\n return null;\n } finally {\n setIsFinalizing(false);\n }\n }, [isFinalizing]);\n\n const addTextLayer = useCallback((text?: string) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.addTextLayer(text);\n } catch (error) {\n console.error('[useCustomizer] addTextLayer failed:', error);\n }\n }, []);\n\n const addImageLayer = useCallback(async (url: string) => {\n if (!customizerRef.current) return;\n try {\n await customizerRef.current.addImageLayer(url);\n } catch (error) {\n console.error('[useCustomizer] addImageLayer failed:', error);\n }\n }, []);\n\n const removeLayer = useCallback((layerId: string) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.removeLayer(layerId);\n } catch (error) {\n console.error('[useCustomizer] removeLayer failed:', error);\n }\n }, []);\n\n const selectLayer = useCallback((layerId: string | null) => {\n if (!customizerRef.current) return;\n try {\n customizerRef.current.selectLayer(layerId);\n setSelectedLayerId(layerId);\n } catch (error) {\n console.error('[useCustomizer] selectLayer failed:', error);\n }\n }, []);\n\n return {\n customizerRef,\n design,\n canUndo,\n canRedo,\n selectedLayerId,\n isFinalizing,\n finalizeResult,\n getDesign,\n setDesign: setDesignCallback,\n undo,\n redo,\n finalize,\n addTextLayer,\n addImageLayer,\n removeLayer,\n selectLayer,\n };\n}\n"],"names":["Customizer","forwardRef","props","ref","templateId","productId","apiUrl","theme","mode","debug","className","style","initialDesign","onReady","onChange","onLayerSelect","onLayerAdd","onLayerRemove","onLayerUpdate","onError","onFinalize","onViewChange","containerRef","useRef","instanceRef","callbacksRef","useEffect","options","design","layerId","error","result","viewName","instance","initCustomizer","useImperativeHandle","text","url","newTheme","newMode","jsx","useCustomizer","autoSave","autoSaveKey","autoSaveDebounce","customizerRef","setDesign","useState","canUndo","setCanUndo","canRedo","setCanRedo","selectedLayerId","setSelectedLayerId","isFinalizing","setIsFinalizing","finalizeResult","setFinalizeResult","autoSaveTimeoutRef","getDesign","useCallback","setDesignCallback","newDesign","undo","redo","finalize","addTextLayer","addImageLayer","removeLayer","selectLayer"],"mappings":";;;AA+JO,MAAMA,IAAaC;AAAA,EACxB,CAACC,GAAOC,MAAQ;AACd,UAAM;AAAA,MACJ,YAAAC;AAAA,MACA,WAAAC;AAAA,MACA,QAAAC;AAAA,MACA,OAAAC,IAAQ;AAAA,MACR,MAAAC,IAAO;AAAA,MACP,OAAAC,IAAQ;AAAA,MACR,WAAAC;AAAA,MACA,OAAAC;AAAA,MACA,eAAAC;AAAA,MACA,SAAAC;AAAA,MAC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C3C,SAASC,GAAO;AACd,gBAAQ,MAAM,uCAAuCA,CAAK;AAAA,MAC5D;AAAA,EACF,GAAG,CAAA,CAAE,GAECuC,IAAcT,EAAY,CAAC/B,MAA2B;AAC1D,QAAKgB,EAAc;AACnB,UAAI;AACF,QAAAA,EAAc,QAAQ,YAAYhB,CAAO,GACzCwB,EAAmBxB,CAAO;AAAA,MAC5B,SAASC,GAAO;AACd,gBAAQ,MAAM,uCAAuCA,CAAK;AAAA,MAC5D;AAAA,EACF,GAAG,CAAA,CAAE;AAEL,SAAO;AAAA,IACL,eAAAe;AAAA,IACA,QAAAjB;AAAA,IACA,SAAAoB;AAAA,IACA,SAAAE;AAAA,IACA,iBAAAE;AAAA,IACA,cAAAE;AAAA,IACA,gBAAAE;AAAA,IACA,WAAAG;AAAA,IACA,WAAWE;AAAA,IACX,MAAAE;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,IACA,cAAAC;AAAA,IACA,eAAAC;AAAA,IACA,aAAAC;AAAA,IACA,aAAAC;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varianta/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Multi-framework JavaScript SDK for product customization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"import": "./dist/index.esm.js",
|
|
13
13
|
"require": "./dist/index.cjs.js"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/types/react/index.d.ts",
|
|
17
|
+
"import": "./dist/react.esm.js",
|
|
18
|
+
"require": "./dist/react.cjs.js"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"files": [
|
package/dist/index.umd.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
(function(C,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(C=typeof globalThis<"u"?globalThis:C||self,E(C.CustomizerSDK={}))})(this,(function(C){"use strict";class E{constructor(e){this.animationFrameId=null,this.needsRender=!0,this.areas=[],this.contents=new Map,this.artboard=null,this.bgImageElement=null,this.loadedImages=new Map,this.loadingImages=new Set,this.zoom=1,this.pan={x:0,y:0},this.selectedAreaId=null,this.hoveredHandle=null,this.eventListeners=new Map,this.safeArea=null,this.safeAreaViolations=new Set,this.showAreaBorders=!0,this.areaSelectionEnabled=!0,this.renderLoop=()=>{try{this.needsRender&&(this.render(),this.needsRender=!1,this.emit("render",void 0))}catch(i){console.error("Error in render loop:",i)}this.animationFrameId=requestAnimationFrame(this.renderLoop)},this.canvas=e;const t=e.getContext("2d");if(!t)throw new Error("Failed to get 2D context from canvas");this.ctx=t}start(){this.animationFrameId===null&&this.renderLoop()}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}setArtboard(e){this.artboard=e,this.requestRender()}getArtboard(){return this.artboard}setAreas(e){this.areas=[...e].sort((t,i)=>t.zIndex-i.zIndex),this.requestRender()}getAreas(){return this.areas}setContents(e){this.contents=e,this.loadContentImages(),this.requestRender()}getContents(){return this.contents}updateContent(e,t){this.contents.set(e,t),t.type==="image"&&this.loadContentImages(),this.requestRender(),this.emit("content:change",{areaId:e,content:t})}removeContent(e){this.contents.delete(e),this.loadedImages.delete(e),this.requestRender()}setBackgroundImage(e){if(this.backgroundImage=e,e?.url&&e.url!==this.bgImageElement?.src){const t=new Image;t.crossOrigin="anonymous",t.onload=()=>{this.bgImageElement=t,this.requestRender()},t.onerror=()=>{this.bgImageElement=null,console.error("Failed to load background image:",e.url),this.requestRender()},t.src=e.url}else e?.url||(this.bgImageElement=null);this.requestRender()}setZoom(e){this.zoom=Math.max(.1,Math.min(5,e)),this.requestRender()}setPan(e){this.pan=e,this.requestRender()}getZoom(){return this.zoom}getPan(){return this.pan}setShowAreaBorders(e){this.showAreaBorders=e,this.requestRender()}setAreaSelectionEnabled(e){this.areaSelectionEnabled=e}getCenteredPan(e){if(!this.artboard)return null;const{width:t,height:i}=this.artboard,n=window.devicePixelRatio||1,a=this.canvas.width/n,o=this.canvas.height/n;return{x:(a/e-t)/2,y:(o/e-i)/2}}requestRender(){this.needsRender=!0}fitToView(){if(!this.artboard)return;const e=0,{width:t,height:i}=this.artboard,n=window.devicePixelRatio||1,a=this.canvas.width/n-e*2,o=this.canvas.height/n-e*2;if(a<=0||o<=0)return;const s=a/t,r=o/i,d=Math.min(s,r),l=this.canvas.width/n,c=this.canvas.height/n,u=(l/d-t)/2,p=(c/d-i)/2;this.zoom=d,this.pan={x:u,y:p},this.requestRender()}setSelectedArea(e){this.selectedAreaId!==e&&(this.selectedAreaId=e,this.requestRender(),this.emit("area:select",{areaId:e}))}getSelectedArea(){return this.selectedAreaId}setHoveredHandle(e){this.hoveredHandle!==e&&(this.hoveredHandle=e,this.requestRender())}getHoveredHandle(){return this.hoveredHandle}screenToCanvas(e,t){const i=window.devicePixelRatio||1,n=e/i,a=t/i,o=n/this.zoom-this.pan.x,s=a/this.zoom-this.pan.y;return{x:o,y:s}}getContentBounds(e){const t=this.areas.find(d=>d.id===e);if(!t)return null;const i=this.contents.get(e);if(!i)return null;const{location:n}=t,{x:a,y:o,width:s,height:r}=n;if(i.type==="text"){const d=i.offset||{x:0,y:0},l=i.scale??1,c=i.rotation??0,u=s*l,p=r*l,g=a+s/2+d.x,m=o+r/2+d.y;return{x:g-u/2,y:m-p/2,width:u,height:p,rotation:c,centerX:g,centerY:m}}else if(i.type==="image"){const d=this.loadedImages.get(e);if(!d)return null;const l=i.offset||{x:0,y:0},c=i.scale??1,u=i.rotation??0,p=d.naturalWidth/d.naturalHeight,g=s/r;let m,v;p>g?(m=s,v=s/p):(v=r,m=r*p);const b=m*c,y=v*c,x=a+s/2+l.x,w=o+r/2+l.y;return{x:x-b/2,y:w-y/2,width:b,height:y,rotation:u,centerX:x,centerY:w}}return null}hitTestContent(e,t){if(!this.areaSelectionEnabled)return null;for(let i=this.areas.length-1;i>=0;i--){const n=this.areas[i],a=this.getContentBounds(n.id);if(a&&this.isPointInBounds(e,t,a))return n.id}return null}hitTestArea(e,t){if(!this.areaSelectionEnabled)return null;for(let i=this.areas.length-1;i>=0;i--){const n=this.areas[i],{x:a,y:o,width:s,height:r}=n.location;if(e>=a&&e<=a+s&&t>=o&&t<=o+r)return n.id}return null}isPointInBounds(e,t,i){const{centerX:n,centerY:a,width:o,height:s,rotation:r}=i,d=-r*Math.PI/180,l=Math.cos(d),c=Math.sin(d),u=e-n,p=t-a,g=u*l-p*c,m=u*c+p*l;return g>=-o/2&&g<=o/2&&m>=-s/2&&m<=s/2}getContentHandlePositions(e){const t=this.areas.find(b=>b.id===e);if(!t)return null;const i=this.contents.get(e);if(!i)return null;const n=this.getContentBounds(e);if(!n)return null;const{centerX:a,centerY:o,width:s,height:r,rotation:d}=n,l=6/this.zoom,c=30/this.zoom,u=d*Math.PI/180,p=Math.cos(u),g=Math.sin(u),m=(b,y)=>({x:a+b*p-y*g,y:o+b*g+y*p}),v=[];if(i.type==="image"&&t.imageOptions?.allowScaling||i.type==="text"&&t.textOptions?.allowScaling){const b=s/2,y=r/2,x=m(-b,-y);v.push({type:"nw",...x,radius:l});const w=m(b,-y);v.push({type:"ne",...w,radius:l});const I=m(b,y);v.push({type:"se",...I,radius:l});const T=m(-b,y);v.push({type:"sw",...T,radius:l})}if(i.type==="image"&&t.imageOptions?.allowRotation||i.type==="text"&&t.textOptions?.allowRotation){const b=m(0,-r/2-c);v.push({type:"rotate",...b,radius:l})}return v}hitTestHandle(e,t,i){const n=this.getContentHandlePositions(i);if(!n)return null;for(const a of n){const o=e-a.x,s=t-a.y;if(Math.sqrt(o*o+s*s)<=a.radius*2)return a.type}return null}isPositioningAllowed(e){const t=this.areas.find(n=>n.id===e);if(!t)return!1;const i=this.contents.get(e);return i?i.type==="text"?t.textOptions?.allowPositioning??!1:t.imageOptions?.allowPositioning??!1:!1}getAreaLocation(e){const t=this.areas.find(i=>i.id===e);return t?t.location:null}getArea(e){return this.areas.find(t=>t.id===e)}setSafeArea(e){this.safeArea=e??null,this.requestRender()}checkSafeAreaViolations(){if(!this.safeArea||!this.artboard)return[];const e=[],{top:t,right:i,bottom:n,left:a}=this.safeArea,o=a,s=t,r=this.artboard.width-i,d=this.artboard.height-n;for(const l of this.areas){if(!this.contents.get(l.id))continue;const c=this.getContentBounds(l.id);if(!c)continue;const{centerX:u,centerY:p,width:g,height:m,rotation:v}=c,b=v*Math.PI/180,y=Math.abs(Math.cos(b)),x=Math.abs(Math.sin(b)),w=g*y+m*x,I=g*x+m*y,T=u-w/2,ee=p-I/2,te=u+w/2,ie=p+I/2;(T<o||ee<s||te>r||ie>d)&&e.push(l.id)}return this.safeAreaViolations=new Set(e),this.requestRender(),e}on(e,t){return this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t),()=>{this.eventListeners.get(e)?.delete(t)}}emit(e,t){const i=this.eventListeners.get(e);if(i)for(const n of i)n(t)}async exportToPNG(){if(!this.artboard)throw new Error("No artboard configured");const{width:e,height:t,backgroundColor:i}=this.artboard,n=document.createElement("canvas");n.width=e,n.height=t;const a=n.getContext("2d");if(!a)throw new Error("Failed to get 2D context for export");a.fillStyle=i,a.fillRect(0,0,e,t),this.backgroundImage?.position==="behind"&&this.bgImageElement&&this.drawBackgroundImageOnContext(a,e,t);for(const o of this.areas)this.drawAreaContentOnContext(a,o);return this.backgroundImage?.position==="overlay"&&this.bgImageElement&&this.drawBackgroundImageOnContext(a,e,t),new Promise((o,s)=>{n.toBlob(r=>{r?o(r):s(new Error("Failed to create PNG blob"))},"image/png",1)})}loadContentImages(){for(const[e,t]of this.contents)if(t.type==="image"&&!this.loadedImages.has(e)&&!this.loadingImages.has(e)){this.loadingImages.add(e);const i=new Image;i.onload=()=>{this.loadedImages.set(e,i),this.loadingImages.delete(e),this.requestRender()},i.onerror=()=>{this.loadingImages.delete(e),console.error("Failed to load image for area:",e)},i.src=t.dataUrl}for(const e of this.loadedImages.keys()){const t=this.contents.get(e);(!t||t.type!=="image")&&this.loadedImages.delete(e)}}render(){const{ctx:e,canvas:t}=this;if(e.fillStyle="#f3f4f6",e.fillRect(0,0,t.width,t.height),!this.artboard)return;e.save();const i=window.devicePixelRatio||1;e.scale(i,i),e.scale(this.zoom,this.zoom),e.translate(this.pan.x,this.pan.y);const{width:n,height:a,backgroundColor:o}=this.artboard;e.fillStyle=o,e.fillRect(0,0,n,a),e.strokeStyle="#d1d5db",e.lineWidth=1/this.zoom,e.strokeRect(0,0,n,a),this.backgroundImage?.position==="behind"&&this.renderBackgroundImage();for(const s of this.areas)this.renderAreaWithContent(s);this.backgroundImage?.position==="overlay"&&this.renderBackgroundImage(),this.renderSafeAreaGuide();for(const s of this.safeAreaViolations){const r=this.areas.find(p=>p.id===s);if(!r)continue;const{x:d,y:l,width:c,height:u}=r.location;e.save(),e.fillStyle="rgba(239, 68, 68, 0.15)",e.fillRect(d,l,c,u),e.restore()}this.selectedAreaId&&this.renderSelectionOverlay(this.selectedAreaId),e.restore()}renderSelectionOverlay(e){const t=this.getContentBounds(e);if(!t){const l=this.areas.find(v=>v.id===e);if(!l)return;const{ctx:c}=this,{x:u,y:p,width:g,height:m}=l.location;c.save(),c.strokeStyle="#3b82f6",c.lineWidth=2/this.zoom,c.setLineDash([]),c.strokeRect(u,p,g,m),c.restore();return}const{ctx:i}=this,{centerX:n,centerY:a,width:o,height:s,rotation:r}=t;i.save(),i.translate(n,a),i.rotate(r*Math.PI/180),i.strokeStyle="#3b82f6",i.lineWidth=2/this.zoom,i.setLineDash([]),i.strokeRect(-o/2,-s/2,o,s),i.restore();const d=this.getContentHandlePositions(e);if(d)for(const l of d){i.save();const c=this.hoveredHandle===l.type,u=c?"#dbeafe":"#ffffff",p=c?"#2563eb":"#3b82f6";if(l.type==="rotate"){const g=this.getRotatedPoint(n,a-s/2,n,a,r);i.beginPath(),i.strokeStyle=p,i.lineWidth=1/this.zoom,i.setLineDash([4/this.zoom,4/this.zoom]),i.moveTo(g.x,g.y),i.lineTo(l.x,l.y),i.stroke(),i.setLineDash([]),i.beginPath(),i.fillStyle=u,i.strokeStyle=p,i.lineWidth=2/this.zoom,i.arc(l.x,l.y,l.radius,0,Math.PI*2),i.fill(),i.stroke(),i.beginPath(),i.strokeStyle=p,i.lineWidth=1.5/this.zoom,i.arc(l.x,l.y,l.radius*.5,-Math.PI*.8,Math.PI*.5),i.stroke()}else i.fillStyle=u,i.strokeStyle=p,i.lineWidth=2/this.zoom,i.fillRect(l.x-l.radius,l.y-l.radius,l.radius*2,l.radius*2),i.strokeRect(l.x-l.radius,l.y-l.radius,l.radius*2,l.radius*2);i.restore()}}getRotatedPoint(e,t,i,n,a){const o=a*Math.PI/180,s=Math.cos(o),r=Math.sin(o),d=e-i,l=t-n;return{x:i+d*s-l*r,y:n+d*r+l*s}}renderBackgroundImage(){if(!this.bgImageElement||!this.artboard||!this.backgroundImage)return;const{ctx:e}=this,{opacity:t}=this.backgroundImage,{width:i,height:n}=this.artboard;e.save(),e.globalAlpha=t;const a=this.bgImageElement.naturalWidth/this.bgImageElement.naturalHeight,o=i/n;let s,r,d,l;a>o?(r=n,s=n*a,d=(i-s)/2,l=0):(s=i,r=i/a,d=0,l=(n-r)/2),e.drawImage(this.bgImageElement,d,l,s,r),e.restore()}renderSafeAreaGuide(){if(!this.safeArea||!this.artboard)return;const{ctx:e}=this,{top:t,right:i,bottom:n,left:a}=this.safeArea,o=a,s=t,r=this.artboard.width-a-i,d=this.artboard.height-t-n;r<=0||d<=0||(e.save(),e.strokeStyle="#22c55e",e.lineWidth=1/this.zoom,e.setLineDash([6/this.zoom,4/this.zoom]),e.strokeRect(o,s,r,d),e.setLineDash([]),e.restore())}renderAreaWithContent(e){const{ctx:t}=this,{location:i,backgroundColor:n}=e,{x:a,y:o,width:s,height:r}=i;n&&(t.fillStyle=n,t.fillRect(a,o,s,r));const d=this.contents.get(e.id);d&&(d.type==="text"?this.renderTextContent(e,d):d.type==="image"&&this.renderImageContent(e,d)),this.showAreaBorders&&e.showBorder&&(t.save(),t.strokeStyle=e.borderColor||"#3b82f6",t.lineWidth=1/this.zoom,t.setLineDash([4/this.zoom,4/this.zoom]),t.strokeRect(a,o,s,r),t.setLineDash([]),t.restore())}renderTextContent(e,t){if(!t.text.trim())return;const{ctx:i}=this,{location:n}=e,{x:a,y:o,width:s,height:r}=n,d=t.offset||{x:0,y:0},l=t.scale??1,c=t.rotation??0,u=a+s/2+d.x,p=o+r/2+d.y;i.save(),i.beginPath(),i.rect(a,o,s,r),i.clip(),i.translate(u,p),i.rotate(c*Math.PI/180),i.scale(l,l),i.font=`${t.size}px ${t.font}, sans-serif`,i.fillStyle=t.color,i.textBaseline="middle";let g;switch(t.align){case"left":i.textAlign="left",g=-s/2+10;break;case"right":i.textAlign="right",g=s/2-10;break;case"center":default:i.textAlign="center",g=0;break}i.fillText(t.text,g,0),i.restore()}renderImageContent(e,t){const i=this.loadedImages.get(e.id);if(!i)return;const{ctx:n}=this,{location:a}=e,{x:o,y:s,width:r,height:d}=a,l=t.offset||{x:0,y:0},c=t.scale??1,u=t.rotation??0;n.save(),n.beginPath(),n.rect(o,s,r,d),n.clip();const p=i.naturalWidth/i.naturalHeight,g=r/d;let m,v;p>g?(m=r,v=r/p):(v=d,m=d*p);const b=m*c,y=v*c,x=o+r/2+l.x,w=s+d/2+l.y;n.translate(x,w),n.rotate(u*Math.PI/180),n.drawImage(i,-b/2,-y/2,b,y),n.restore()}drawBackgroundImageOnContext(e,t,i){if(!this.bgImageElement||!this.backgroundImage)return;const{opacity:n}=this.backgroundImage;e.save(),e.globalAlpha=n;const a=this.bgImageElement.naturalWidth/this.bgImageElement.naturalHeight,o=t/i;let s,r,d,l;a>o?(r=i,s=i*a,d=(t-s)/2,l=0):(s=t,r=t/a,d=0,l=(i-r)/2),e.drawImage(this.bgImageElement,d,l,s,r),e.restore()}drawAreaContentOnContext(e,t){const{location:i,backgroundColor:n}=t,{x:a,y:o,width:s,height:r}=i;n&&(e.fillStyle=n,e.fillRect(a,o,s,r));const d=this.contents.get(t.id);if(d){if(d.type==="text"){if(!d.text.trim())return;const l=d.offset||{x:0,y:0},c=d.scale??1,u=d.rotation??0,p=a+s/2+l.x,g=o+r/2+l.y;e.save(),e.beginPath(),e.rect(a,o,s,r),e.clip(),e.translate(p,g),e.rotate(u*Math.PI/180),e.scale(c,c),e.font=`${d.size}px ${d.font}, sans-serif`,e.fillStyle=d.color,e.textBaseline="middle";let m;switch(d.align){case"left":e.textAlign="left",m=-s/2+10;break;case"right":e.textAlign="right",m=s/2-10;break;case"center":default:e.textAlign="center",m=0;break}e.fillText(d.text,m,0),e.restore()}else if(d.type==="image"){const l=this.loadedImages.get(t.id);if(!l)return;const c=d.offset||{x:0,y:0},u=d.scale??1,p=d.rotation??0;e.save(),e.beginPath(),e.rect(a,o,s,r),e.clip();const g=l.naturalWidth/l.naturalHeight,m=s/r;let v,b;g>m?(v=s,b=s/g):(b=r,v=r*g);const y=v*u,x=b*u,w=a+s/2+c.x,I=o+r/2+c.y;e.translate(w,I),e.rotate(p*Math.PI/180),e.drawImage(l,-y/2,-x/2,y,x),e.restore()}}}destroy(){this.stop(),this.bgImageElement=null,this.loadedImages.clear(),this.loadingImages.clear(),this.eventListeners.clear()}}function M(f){const e=f.textOptions;return{type:"text",text:e?.defaultText||"",font:e?.defaultFont||"Inter",size:e?.defaultSize||24,color:e?.defaultColor||"#000000",align:e?.defaultAlign||"center"}}function z(f){return f.contentType==="text"||f.contentType==="both"}function P(f){return f.contentType==="image"||f.contentType==="both"}const R=50;class N{constructor(e){this.history=[],this.historyIndex=-1,this.listeners=new Set,this.isRestoring=!1,this.state=this.cloneState(e),this.history.push({state:this.cloneState(e),timestamp:Date.now(),description:"Initial state"}),this.historyIndex=0}getState(){return this.state}setState(e,t,i=!1){const n=this.state;this.state={...this.state,...e},!i&&!this.isRestoring&&this.saveToHistory(n,t),this.notifyListeners()}update(e){this.state={...this.state,...e},this.notifyListeners()}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}undo(){return this.canUndo()?(this.historyIndex--,this.restoreFromHistory(),!0):!1}redo(){return this.canRedo()?(this.historyIndex++,this.restoreFromHistory(),!0):!1}canUndo(){return this.historyIndex>0}canRedo(){return this.historyIndex<this.history.length-1}clearHistory(){this.history=[],this.historyIndex=-1}getHistory(){return this.history}saveToHistory(e,t){this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push({state:this.cloneState(e),timestamp:Date.now(),description:t}),this.history.length>R&&this.history.shift(),this.historyIndex=this.history.length-1}restoreFromHistory(){const e=this.history[this.historyIndex];e&&(this.isRestoring=!0,this.state=this.cloneState(e.state),this.notifyListeners(),this.isRestoring=!1)}notifyListeners(){const e=this.state;for(const t of this.listeners)try{t(e)}catch(i){console.error("Error in state change listener:",i)}}cloneState(e){return JSON.parse(JSON.stringify(e))}}class L{constructor(e){this.listeners=new Set,this.areas=e,this.contents=this.buildInitialContents()}buildInitialContents(){const e=new Map;for(const t of this.areas)z(t)&&e.set(t.id,M(t));return e}getContents(){return this.contents}getContent(e){return this.contents.get(e)}setTextContent(e,t){const i=this.contents.get(e),n=this.areas.find(o=>o.id===e),a=n?M(n):{type:"text",text:"",font:"Inter",size:24,color:"#000000",align:"center"};i?.type==="text"?this.contents.set(e,{...i,...t}):this.contents.set(e,{...a,...t}),this.notify()}setImageContent(e,t,i){const n={type:"image",dataUrl:t,filename:i};this.contents.set(e,n),this.notify()}clearContent(e){const t=this.areas.find(i=>i.id===e);t&&z(t)?this.contents.set(e,M(t)):this.contents.delete(e),this.notify()}setContentOffset(e,t){const i=this.contents.get(e);i&&(this.contents.set(e,{...i,offset:t}),this.notify())}setImageScale(e,t){const i=this.contents.get(e);if(!i||i.type!=="image")return;const n=Math.max(.1,Math.min(5,t));this.contents.set(e,{...i,scale:n}),this.notify()}setImageRotation(e,t){const i=this.contents.get(e);if(!i||i.type!=="image")return;let n=t%360;n<0&&(n+=360),this.contents.set(e,{...i,rotation:n}),this.notify()}reset(){this.contents=this.buildInitialContents(),this.notify()}toJSON(){return Array.from(this.contents.entries())}fromJSON(e){this.contents=new Map(e),this.notify()}setContentsQuiet(e){this.contents=new Map(e)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)try{e()}catch(t){console.error("Error in AreaContentManager listener:",t)}}}class S{constructor(){this.listeners=new Map}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}once(e,t){const i=n=>{t(n),this.off(e,i)};return this.on(e,i)}off(e,t){const i=this.listeners.get(e);i&&(i.delete(t),i.size===0&&this.listeners.delete(e))}emit(e,t){const i=this.listeners.get(e);if(i){const n=Array.from(i);for(const a of n)try{a(t)}catch(o){console.error(`Error in event handler for "${String(e)}":`,o)}}}clear(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){return this.listeners.get(e)?.size??0}}class U extends S{constructor(){super(...arguments),this.activeTouches=new Map,this.initialPinchDistance=null,this.lastPinchCenter=null,this.isTwoFingerGesture=!1}get isMultiTouch(){return this.isTwoFingerGesture}handleTouchStart(e){for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t];this.activeTouches.set(i.identifier,{x:i.clientX,y:i.clientY})}if(this.activeTouches.size===2){this.isTwoFingerGesture=!0,e.preventDefault();const[t,i]=Array.from(this.activeTouches.values());this.initialPinchDistance=this.getDistance(t,i),this.lastPinchCenter=this.getCenter(t,i)}}handleTouchMove(e){for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t];this.activeTouches.set(i.identifier,{x:i.clientX,y:i.clientY})}if(this.activeTouches.size===2&&this.initialPinchDistance!==null&&this.lastPinchCenter){e.preventDefault();const[t,i]=Array.from(this.activeTouches.values()),n=this.getDistance(t,i),a=this.getCenter(t,i),o=n/this.initialPinchDistance;this.emit("pinch",{scale:o,centerX:a.x,centerY:a.y});const s=a.x-this.lastPinchCenter.x,r=a.y-this.lastPinchCenter.y;(Math.abs(s)>.5||Math.abs(r)>.5)&&this.emit("pan",{deltaX:s,deltaY:r}),this.initialPinchDistance=n,this.lastPinchCenter=a}}handleTouchEnd(e){for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t];this.activeTouches.delete(i.identifier)}this.activeTouches.size<2&&(this.initialPinchDistance=null,this.lastPinchCenter=null,this.isTwoFingerGesture=!1)}reset(){this.activeTouches.clear(),this.initialPinchDistance=null,this.lastPinchCenter=null,this.isTwoFingerGesture=!1}getDistance(e,t){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}getCenter(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}}class O extends S{constructor(e,t,i,n){super(),this.interactionState={mode:"idle"},this.initialPinchZoom=1,this.canvas=e,this.engine=t,this.getContents=i,this.getSelectedAreaId=n,this.gestureHandler=new U,this.boundMouseDown=this.handleMouseDown.bind(this),this.boundMouseMove=this.handleMouseMove.bind(this),this.boundMouseUp=this.handleMouseUp.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundContextMenu=this.handleContextMenu.bind(this),this.boundDoubleClick=this.handleDoubleClick.bind(this),this.boundTouchStart=this.handleTouchStart.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleTouchEnd.bind(this),e.addEventListener("mousedown",this.boundMouseDown),e.addEventListener("mousemove",this.boundMouseMove),e.addEventListener("mouseup",this.boundMouseUp),e.addEventListener("mouseleave",this.boundMouseLeave),e.addEventListener("contextmenu",this.boundContextMenu),e.addEventListener("dblclick",this.boundDoubleClick),e.addEventListener("touchstart",this.boundTouchStart,{passive:!1}),e.addEventListener("touchmove",this.boundTouchMove,{passive:!1}),e.addEventListener("touchend",this.boundTouchEnd),this.gestureHandler.on("pinch",({scale:a})=>{const o=Math.max(.1,Math.min(5,this.initialPinchZoom*a));this.emit("zoom",{zoom:o})}),this.gestureHandler.on("pan",({deltaX:a,deltaY:o})=>{const s=this.engine.getPan(),r=this.engine.getZoom();this.emit("pan",{pan:{x:s.x+a/r,y:s.y+o/r}})})}getCanvasPosition(e,t){const i=this.canvas.getBoundingClientRect(),n=window.devicePixelRatio||1,a=(e-i.left)*n,o=(t-i.top)*n;return this.engine.screenToCanvas(a,o)}handleMouseDown(e){const t=this.getCanvasPosition(e.clientX,e.clientY);this.processPointerDown(t)}handleMouseMove(e){const t=this.getCanvasPosition(e.clientX,e.clientY);this.processPointerMove(t)}handleMouseUp(){this.processPointerUp()}handleMouseLeave(){this.processPointerUp(),this.emit("cursor",{cursor:"default"})}handleContextMenu(e){e.preventDefault()}handleDoubleClick(e){const t=this.getCanvasPosition(e.clientX,e.clientY);let i=this.engine.hitTestContent(t.x,t.y);i||(i=this.engine.hitTestArea(t.x,t.y)??null),this.emit("context-menu",{areaId:i,clientX:e.clientX,clientY:e.clientY})}handleTouchStart(e){if(this.gestureHandler.handleTouchStart(e),this.gestureHandler.isMultiTouch){this.initialPinchZoom=this.engine.getZoom(),this.interactionState.mode!=="idle"&&(this.interactionState={mode:"idle"});return}if(e.touches.length!==1)return;const t=e.touches[0],i=this.getCanvasPosition(t.clientX,t.clientY);this.processPointerDown(i)&&e.preventDefault()}handleTouchMove(e){if(this.gestureHandler.handleTouchMove(e),this.gestureHandler.isMultiTouch||e.touches.length!==1||this.interactionState.mode==="idle")return;const t=e.touches[0],i=this.getCanvasPosition(t.clientX,t.clientY);this.processPointerMove(i),e.preventDefault()}handleTouchEnd(e){this.gestureHandler.handleTouchEnd(e),this.gestureHandler.isMultiTouch||this.processPointerUp()}processPointerDown(e){const t=this.getSelectedAreaId(),i=this.getContents();if(t){const o=this.engine.hitTestHandle(e.x,e.y,t);if(o){const s=i.get(t),r=this.engine.getContentBounds(t);if(o==="rotate"&&s?.type==="image"&&r){const d=Math.atan2(e.y-r.centerY,e.x-r.centerX)*(180/Math.PI);return this.interactionState={mode:"rotating",areaId:t,startRotation:s.rotation??0,centerPoint:{x:r.centerX,y:r.centerY},startAngle:d},!0}else if(o!=="rotate"&&s?.type==="image"&&r)return this.interactionState={mode:"scaling",areaId:t,handle:o,startScale:s.scale??1,startMousePos:e,pivotPoint:{x:r.centerX,y:r.centerY}},!0}}const n=this.engine.hitTestContent(e.x,e.y);if(n){if(this.emit("area:select",{areaId:n}),this.engine.isPositioningAllowed(n)){const o=i.get(n)?.offset??{x:0,y:0};return this.interactionState={mode:"dragging",areaId:n,startOffset:o,startMousePos:e},!0}return!0}const a=this.engine.hitTestArea(e.x,e.y);return a?(this.emit("area:select",{areaId:a}),!1):(this.emit("area:select",{areaId:null}),!1)}processPointerMove(e){if(this.interactionState.mode==="dragging"){const{areaId:t,startOffset:i,startMousePos:n}=this.interactionState,a=e.x-n.x,o=e.y-n.y;let s={x:i.x+a,y:i.y+o};const r=this.engine.getAreaLocation(t);if(r){const d=r.width/2-10,l=r.height/2-10;s.x=Math.max(-d,Math.min(d,s.x)),s.y=Math.max(-l,Math.min(l,s.y))}this.emit("content:drag",{areaId:t,offset:s});return}if(this.interactionState.mode==="scaling"){const{areaId:t,startScale:i,startMousePos:n,pivotPoint:a}=this.interactionState,o=Math.sqrt(Math.pow(n.x-a.x,2)+Math.pow(n.y-a.y,2)),s=Math.sqrt(Math.pow(e.x-a.x,2)+Math.pow(e.y-a.y,2));if(o>0){const r=s/o,d=Math.max(.1,Math.min(5,i*r));this.emit("content:scale",{areaId:t,scale:d})}return}if(this.interactionState.mode==="rotating"){const{areaId:t,startRotation:i,centerPoint:n,startAngle:a}=this.interactionState,o=Math.atan2(e.y-n.y,e.x-n.x)*(180/Math.PI);let s=i+(o-a);s=s%360,s<0&&(s+=360);const r=[0,90,180,270,360];for(const d of r)if(Math.abs(s-d)<5){s=d===360?0:d;break}this.emit("content:rotate",{areaId:t,rotation:s});return}this.updateCursor(e)}processPointerUp(){this.interactionState.mode!=="idle"&&(this.interactionState={mode:"idle"})}updateCursor(e){const t=this.getSelectedAreaId();let i="default";if(t){const n=this.engine.hitTestHandle(e.x,e.y,t);n?i=n==="rotate"?"crosshair":n==="nw"||n==="se"?"nwse-resize":"nesw-resize":this.engine.hitTestContent(e.x,e.y)===t&&(i=this.engine.isPositioningAllowed(t)?"move":"pointer")}else this.engine.hitTestContent(e.x,e.y)&&(i="pointer");this.emit("cursor",{cursor:i})}setSelectedArea(e){this.engine.setSelectedArea(e)}destroy(){this.canvas.removeEventListener("mousedown",this.boundMouseDown),this.canvas.removeEventListener("mousemove",this.boundMouseMove),this.canvas.removeEventListener("mouseup",this.boundMouseUp),this.canvas.removeEventListener("mouseleave",this.boundMouseLeave),this.canvas.removeEventListener("contextmenu",this.boundContextMenu),this.canvas.removeEventListener("dblclick",this.boundDoubleClick),this.canvas.removeEventListener("touchstart",this.boundTouchStart),this.canvas.removeEventListener("touchmove",this.boundTouchMove),this.canvas.removeEventListener("touchend",this.boundTouchEnd),this.gestureHandler.reset(),this.clear()}}class V{constructor(e="/api"){this.baseUrl=e}async getTemplate(e){try{const t=await fetch(`${this.baseUrl}/templates/${e}`);if(!t.ok){let i=`Failed to load template (${t.status} ${t.statusText}): ${e}
|
|
2
|
-
|
|
3
|
-
`;throw t.status===404?i+="Template not found.":t.status===403?i+="Access forbidden.":t.status>=500&&(i+="Server error."),new Error(i)}return(await t.json()).templateJson}catch(t){throw t instanceof Error&&t.message.includes("Failed to fetch")?new Error(`Network error loading template: ${e}`):t}}async getProduct(e){try{const t=await fetch(`${this.baseUrl}/products/${e}`);if(!t.ok){let i=`Failed to load product (${t.status} ${t.statusText}): ${e}
|
|
4
|
-
|
|
5
|
-
`;throw t.status===404?i+="Product not found.":t.status===403?i+="Access forbidden.":t.status>=500&&(i+="Server error."),new Error(i)}return t.json()}catch(t){throw t instanceof Error&&t.message.includes("Failed to fetch")?new Error(`Network error loading product: ${e}`):t}}async finalizeDesign(e,t){try{const i=await fetch(`${this.baseUrl}/finalize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({shopId:e,templateId:t.templateId,designJson:t})});if(!i.ok){let n=`Failed to finalize design (${i.status} ${i.statusText})
|
|
6
|
-
|
|
7
|
-
`;if(i.status===400){const a=await i.json().catch(()=>({}));n+=a.error||"Invalid design data."}else i.status===429?n+="Rate limit exceeded.":i.status>=500&&(n+="Server error.");throw new Error(n)}return i.json()}catch(i){throw i instanceof Error&&i.message.includes("Failed to fetch")?new Error("Network error finalizing design"):i}}async uploadAsset(e,t){try{const i=new FormData;i.append("shopId",t),i.append("file",e);const n=await fetch(`${this.baseUrl}/assets/upload`,{method:"POST",body:i});if(!n.ok){let a=`Failed to upload asset (${n.status} ${n.statusText})
|
|
8
|
-
|
|
9
|
-
`;if(n.status===400){const o=await n.json().catch(()=>({}));a+=o.error||"Invalid file."}else n.status===413?a+="File too large (max 15MB).":n.status>=500&&(a+="Server error.");throw new Error(a)}return n.json()}catch(i){throw i instanceof Error&&i.message.includes("Failed to fetch")?new Error("Network error uploading asset"):i}}async getStorageUsage(e){try{const t=await fetch(`${this.baseUrl}/assets/usage?shopId=${encodeURIComponent(e)}`);if(!t.ok)throw new Error(`Failed to fetch storage usage (${t.status})`);return t.json()}catch(t){throw t instanceof Error&&t.message.includes("Failed to fetch")?new Error("Network error fetching storage usage"):t}}}function h(f,e,...t){const i=document.createElement(f);return e&&Object.entries(e).forEach(([n,a])=>{n==="class"?i.className=a:n in i?i[n]=a:i.setAttribute(n,String(a))}),t.forEach(n=>{typeof n=="string"?i.appendChild(document.createTextNode(n)):i.appendChild(n)}),i}function F(f,e){let t=null,i=null;const n=(...a)=>{i=a,t&&clearTimeout(t),t=setTimeout(()=>{i&&f(...i),t=null,i=null},e)};return n.flush=()=>{t&&(clearTimeout(t),t=null),i&&(f(...i),i=null)},n.cancel=()=>{t&&(clearTimeout(t),t=null),i=null},n}class $ extends S{constructor(){super(),this.percentLabel=h("span",{class:"zoom-percent"},"100%");const e=h("button",{class:"zoom-btn",title:"Zoom out"},"−");e.addEventListener("click",()=>this.emit("zoom-out",void 0));const t=h("button",{class:"zoom-btn",title:"Fit to view"},"Fit");t.addEventListener("click",()=>this.emit("zoom-fit",void 0));const i=h("button",{class:"zoom-btn",title:"Zoom in"},"+");i.addEventListener("click",()=>this.emit("zoom-in",void 0)),this.viewSelect=document.createElement("select"),this.viewSelect.className="view-select",this.viewSelect.title="Switch view",this.viewSelect.style.display="none",this.viewSelect.addEventListener("change",()=>{this.emit("view-change",{viewName:this.viewSelect.value})}),this.element=h("div",{class:"zoom-toolbar"}),this.element.appendChild(e),this.element.appendChild(t),this.element.appendChild(i),this.element.appendChild(this.percentLabel),this.element.appendChild(this.viewSelect);const n=h("div",{class:"zoom-toolbar-spacer"});this.element.appendChild(n);const a=h("button",{class:"zoom-btn zoom-close-btn",title:"Close editor"},"✕ Close");a.addEventListener("click",()=>this.emit("close",void 0)),this.element.appendChild(a),this.saveBtn=h("button",{class:"zoom-btn zoom-save-btn",title:"Save customization"},"Save Customization"),this.saveBtn.style.display="none",this.saveBtn.addEventListener("click",()=>this.emit("save",void 0)),this.element.appendChild(this.saveBtn)}setZoom(e){this.percentLabel.textContent=`${Math.round(e*100)}%`}showSaveButton(e){this.saveBtn.style.display=e?"":"none"}setSaveDisabled(e,t){this.saveBtn.disabled=e,t&&(this.saveBtn.textContent=t)}setViews(e){this.viewSelect.innerHTML="";for(const t of e){const i=document.createElement("option");i.value=t.viewName,i.textContent=t.viewName,this.viewSelect.appendChild(i)}this.viewSelect.style.display=e.length>1?"":"none"}setActiveView(e){this.viewSelect.value=e}getElement(){return this.element}}const H=[{label:"Inter",value:"Inter"},{label:"Arial",value:"Arial"},{label:"Georgia",value:"Georgia"},{label:"Times New Roman",value:"Times New Roman"},{label:"Courier New",value:"Courier New"}],B=[{label:"L",value:"left"},{label:"C",value:"center"},{label:"R",value:"right"}],A=["image/png","image/jpeg","image/webp","image/svg+xml"],Z=15*1024*1024;class D extends S{constructor(e){super(),this.mode="text",this.isSelected=!1,this.textInputEl=null,this.fontSelectEl=null,this.sizeInputEl=null,this.colorInputEl=null,this.alignGroupEl=null,this.area=e;const t=z(e),i=P(e);this.mode=i&&!t?"image":"text",this.element=h("div",{class:"area-card"}),this.element.addEventListener("click",r=>{r.target.tagName==="INPUT"||r.target.tagName==="SELECT"||r.target.tagName==="BUTTON"||this.emit("select",{areaId:e.id})});const n=h("div",{class:"area-card-header"}),a=h("div",{class:"area-card-name-row"}),o=h("span",{class:"area-card-name"},e.name);if(a.appendChild(o),e.required){const r=h("span",{class:"area-card-badge"},"Required");a.appendChild(r)}n.appendChild(a);const s=h("button",{class:"area-card-reset-btn",title:"Reset content"},"Reset");if(s.addEventListener("click",r=>{r.stopPropagation(),this.emit("clear",{areaId:e.id})}),n.appendChild(s),this.element.appendChild(n),t&&i){const r=h("div",{class:"area-card-mode-switcher"}),d=h("button",{class:"mode-btn mode-btn-active"},"Text");d.dataset.mode="text";const l=h("button",{class:"mode-btn"},"Image");l.dataset.mode="image",d.addEventListener("click",c=>{c.stopPropagation(),this.setMode("text"),d.classList.add("mode-btn-active"),l.classList.remove("mode-btn-active"),this.currentContent?.type==="image"&&this.emit("clear",{areaId:e.id})}),l.addEventListener("click",c=>{c.stopPropagation(),this.setMode("image"),l.classList.add("mode-btn-active"),d.classList.remove("mode-btn-active"),this.currentContent?.type==="text"&&this.emit("clear",{areaId:e.id})}),r.appendChild(d),r.appendChild(l),this.element.appendChild(r)}this.contentContainer=h("div",{class:"area-card-content"}),this.element.appendChild(this.contentContainer),this.transformContainer=h("div",{class:"area-card-transforms"}),this.element.appendChild(this.transformContainer),this.renderContent()}setMode(e){this.mode=e,this.renderContent()}setContent(e){const t=this.currentContent?.type;this.currentContent=e,e?.type==="image"&&(this.mode="image"),this.element.querySelectorAll(".mode-btn").forEach(i=>{const n=i;n.classList.toggle("mode-btn-active",n.dataset.mode===this.mode)}),e?.type!==t||e?.type==="image"||e===void 0?this.renderContent():e?.type==="text"&&this.updateTextValues(e),this.renderTransforms()}setSelected(e){this.isSelected=e,this.element.classList.toggle("area-card-selected",e),this.renderTransforms()}updateTextValues(e){this.textInputEl&&this.textInputEl.value!==e.text&&(this.textInputEl.value=e.text),this.fontSelectEl&&this.fontSelectEl.value!==e.font&&(this.fontSelectEl.value=e.font),this.sizeInputEl&&this.sizeInputEl.value!==String(e.size)&&(this.sizeInputEl.value=String(e.size)),this.colorInputEl&&this.colorInputEl.value!==e.color&&(this.colorInputEl.value=e.color),this.alignGroupEl&&this.alignGroupEl.querySelectorAll(".align-btn").forEach(t=>{const i=t,n=i.title==="Left"?"left":i.title==="Center"?"center":"right";i.classList.toggle("align-btn-active",n===e.align)})}renderContent(){this.contentContainer.innerHTML="",this.textInputEl=null,this.fontSelectEl=null,this.sizeInputEl=null,this.colorInputEl=null,this.alignGroupEl=null;const e=z(this.area),t=P(this.area),i=!t||e&&t&&this.mode==="text",n=!e||e&&t&&this.mode==="image";e&&i&&this.renderTextControls(),t&&n&&this.renderImageControls()}renderTextControls(){const e=this.currentContent,t=e?.type==="text"?e:M(this.area),i=h("input",{class:"area-input-text",type:"text",placeholder:this.area.placeholder||"Enter text..."});i.value=t.text,this.area.textOptions?.maxLength&&(i.maxLength=this.area.textOptions.maxLength),i.addEventListener("input",()=>{this.emit("text:change",{areaId:this.area.id,updates:{text:i.value}})}),this.contentContainer.appendChild(i),this.textInputEl=i;const n=h("div",{class:"area-input-row"}),a=h("select",{class:"area-input-font"});for(const l of H){const c=h("option");c.value=l.value,c.textContent=l.label,l.value===t.font&&(c.selected=!0),a.appendChild(c)}a.addEventListener("change",()=>{this.emit("text:change",{areaId:this.area.id,updates:{font:a.value}})}),n.appendChild(a),this.fontSelectEl=a;const o=h("input",{class:"area-input-size",type:"number"});o.value=String(t.size),o.min=String(this.area.textOptions?.minSize||8),o.max=String(this.area.textOptions?.maxSize||200),o.addEventListener("change",()=>{this.emit("text:change",{areaId:this.area.id,updates:{size:parseInt(o.value,10)||24}})}),n.appendChild(o),this.sizeInputEl=o,this.contentContainer.appendChild(n);const s=h("div",{class:"area-input-row"}),r=h("div",{class:"area-input-align"});for(const l of B){const c=h("button",{class:`align-btn${t.align===l.value?" align-btn-active":""}`,title:l.label==="L"?"Left":l.label==="C"?"Center":"Right"},l.label);c.addEventListener("click",u=>{u.stopPropagation(),this.emit("text:change",{areaId:this.area.id,updates:{align:l.value}}),r.querySelectorAll(".align-btn").forEach(p=>p.classList.remove("align-btn-active")),c.classList.add("align-btn-active")}),r.appendChild(c)}s.appendChild(r),this.alignGroupEl=r;const d=h("input",{class:"area-input-color",type:"color"});d.value=t.color,d.addEventListener("input",()=>{this.emit("text:change",{areaId:this.area.id,updates:{color:d.value}})}),s.appendChild(d),this.colorInputEl=d,this.contentContainer.appendChild(s)}renderImageControls(){const e=this.currentContent;if(e?.type==="image"){const t=h("div",{class:"area-image-preview"}),i=h("img",{class:"area-image-thumb"});i.src=e.dataUrl,i.alt=e.filename||"Uploaded image",t.appendChild(i);const n=h("div",{class:"area-image-info"});n.appendChild(h("span",{class:"area-image-name"},e.filename||"Image"));const a=h("button",{class:"area-image-remove-btn"},"Remove");a.addEventListener("click",o=>{o.stopPropagation(),this.emit("clear",{areaId:this.area.id})}),n.appendChild(a),t.appendChild(n),this.contentContainer.appendChild(t)}else{const t=h("button",{class:"area-upload-btn"},"Upload Image"),i=h("input",{type:"file"});i.accept=A.join(","),i.style.display="none";const n=h("div",{class:"area-validation-error"});n.style.display="none",i.addEventListener("change",()=>{const a=i.files?.[0];if(!a)return;if(!A.includes(a.type)){const s="Only PNG, JPEG, WebP, and SVG images are accepted";n.textContent=s,n.style.display="block",this.emit("validation:error",{areaId:this.area.id,message:s}),i.value="";return}if(a.size>Z){const s="File must be smaller than 15MB";n.textContent=s,n.style.display="block",this.emit("validation:error",{areaId:this.area.id,message:s}),i.value="";return}n.style.display="none";const o=new FileReader;o.onload=()=>{const s=o.result;this.emit("image:change",{areaId:this.area.id,dataUrl:s,filename:a.name})},o.readAsDataURL(a),i.value=""}),t.addEventListener("click",a=>{a.stopPropagation(),i.click()}),this.contentContainer.appendChild(t),this.contentContainer.appendChild(i),this.contentContainer.appendChild(n)}}renderTransforms(){this.transformContainer.innerHTML="";const e=this.currentContent;if(!this.isSelected||!e)return;const t=e.type==="text"?this.area.textOptions?.allowPositioning:this.area.imageOptions?.allowPositioning,i=e.type==="image"&&this.area.imageOptions?.allowScaling,n=e.type==="image"&&this.area.imageOptions?.allowRotation;if(!t&&!i&&!n)return;const a=h("div",{class:"area-card-divider"});this.transformContainer.appendChild(a);const o=h("div",{class:"transform-header"});o.appendChild(h("span",{class:"transform-title"},"Transform"));const s=h("button",{class:"transform-reset-btn"},"Reset");s.addEventListener("click",d=>{d.stopPropagation(),t&&this.emit("offset:change",{areaId:this.area.id,offset:{x:0,y:0}}),i&&this.emit("scale:change",{areaId:this.area.id,scale:1}),n&&this.emit("rotation:change",{areaId:this.area.id,rotation:0})}),o.appendChild(s),this.transformContainer.appendChild(o);const r=e.offset??{x:0,y:0};if(t){const d=h("div",{class:"area-input-row"}),l=h("label",{class:"transform-label"},"X"),c=h("input",{class:"transform-input",type:"number"});c.value=String(Math.round(r.x)),c.addEventListener("change",()=>{this.emit("offset:change",{areaId:this.area.id,offset:{...r,x:parseInt(c.value,10)||0}})});const u=h("label",{class:"transform-label"},"Y"),p=h("input",{class:"transform-input",type:"number"});p.value=String(Math.round(r.y)),p.addEventListener("change",()=>{this.emit("offset:change",{areaId:this.area.id,offset:{...r,y:parseInt(p.value,10)||0}})}),d.appendChild(l),d.appendChild(c),d.appendChild(u),d.appendChild(p),this.transformContainer.appendChild(d)}if(i&&e.type==="image"){const d=e.scale??1,l=h("div",{class:"area-input-row transform-slider-row"}),c=h("label",{class:"transform-label"},`Scale: ${Math.round(d*100)}%`),u=h("input",{class:"transform-slider",type:"range"});u.min="10",u.max="500",u.step="5",u.value=String(Math.round(d*100)),u.addEventListener("input",()=>{const p=parseInt(u.value,10)/100;c.textContent=`Scale: ${Math.round(p*100)}%`,this.emit("scale:change",{areaId:this.area.id,scale:p})}),l.appendChild(c),l.appendChild(u),this.transformContainer.appendChild(l)}if(n&&e.type==="image"){const d=e.rotation??0,l=h("div",{class:"area-input-row transform-slider-row"}),c=h("label",{class:"transform-label"},`Rotation: ${Math.round(d)}°`),u=h("input",{class:"transform-slider",type:"range"});u.min="0",u.max="360",u.step="1",u.value=String(Math.round(d)),u.addEventListener("input",()=>{const p=parseInt(u.value,10);c.textContent=`Rotation: ${p}°`,this.emit("rotation:change",{areaId:this.area.id,rotation:p})}),l.appendChild(c),l.appendChild(u),this.transformContainer.appendChild(l)}}getElement(){return this.element}}class q extends S{constructor(e){super(),this.cards=new Map,this.isMobile=!1,this.boundEscapeHandler=n=>{n.key==="Escape"&&this.emit("dismiss",void 0)},this.backdrop=h("div",{class:"area-panel-backdrop"}),this.backdrop.addEventListener("click",()=>{this.emit("dismiss",void 0)}),this.element=h("div",{class:"area-panel"});const t=h("div",{class:"area-panel-header"});t.appendChild(h("span",{class:"area-panel-title"},"Customize"));const i=h("button",{class:"area-panel-close-btn",title:"Close"},"×");if(i.addEventListener("click",()=>{this.emit("dismiss",void 0)}),t.appendChild(i),this.element.appendChild(t),this.panelContent=h("div",{class:"area-panel-content"}),e.length===0){const n=h("p",{class:"area-panel-empty"},"No customization areas defined.");this.panelContent.appendChild(n)}else for(const n of e){const a=new D(n);this.cards.set(n.id,a),a.on("text:change",o=>this.emit("text:change",o)),a.on("image:change",o=>this.emit("image:change",o)),a.on("clear",o=>this.emit("clear",o)),a.on("select",o=>this.emit("select",o)),a.on("offset:change",o=>this.emit("offset:change",o)),a.on("scale:change",o=>this.emit("scale:change",o)),a.on("rotation:change",o=>this.emit("rotation:change",o)),a.on("validation:error",o=>this.emit("validation:error",o)),this.panelContent.appendChild(a.getElement())}this.element.appendChild(this.panelContent)}setAreas(e){if(this.cards.clear(),this.panelContent.innerHTML="",e.length===0){const t=h("p",{class:"area-panel-empty"},"No customization areas defined.");this.panelContent.appendChild(t)}else for(const t of e){const i=new D(t);this.cards.set(t.id,i),i.on("text:change",n=>this.emit("text:change",n)),i.on("image:change",n=>this.emit("image:change",n)),i.on("clear",n=>this.emit("clear",n)),i.on("select",n=>this.emit("select",n)),i.on("offset:change",n=>this.emit("offset:change",n)),i.on("scale:change",n=>this.emit("scale:change",n)),i.on("rotation:change",n=>this.emit("rotation:change",n)),i.on("validation:error",n=>this.emit("validation:error",n)),this.panelContent.appendChild(i.getElement())}}setContents(e){for(const[t,i]of this.cards)i.setContent(e.get(t))}setSelectedArea(e){for(const[t,i]of this.cards){const n=t===e;i.setSelected(n),i.getElement().style.display=n?"":"none"}e?(this.element.classList.add("area-panel-visible"),this.isMobile&&this.backdrop.classList.add("area-panel-backdrop-visible"),document.addEventListener("keydown",this.boundEscapeHandler)):(this.element.classList.remove("area-panel-visible"),this.isMobile&&this.backdrop.classList.remove("area-panel-backdrop-visible"),document.removeEventListener("keydown",this.boundEscapeHandler))}setMobile(e){this.isMobile=e,this.element.classList.toggle("area-panel-mobile",e),e||(this.element.classList.remove("area-panel-visible"),this.backdrop.classList.remove("area-panel-backdrop-visible"))}getElement(){return this.element}getBackdrop(){return this.backdrop}}class Y{constructor(e=window){this.target=e,this.commands=[],this.isEnabled=!0,this.handleKeyDown=t=>{if(!this.isEnabled)return;const i=t.target;if(!(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)){for(const n of this.commands)if(this.matchesCommand(t,n)){t.preventDefault(),n.handler(t);break}}},this.target.addEventListener("keydown",this.handleKeyDown)}register(e){return this.commands.push(e),()=>{const t=this.commands.indexOf(e);t!==-1&&this.commands.splice(t,1)}}enable(){this.isEnabled=!0}disable(){this.isEnabled=!1}isActive(){return this.isEnabled}matchesCommand(e,t){return!(e.key.toLowerCase()!==t.key.toLowerCase()||t.ctrl!==void 0&&t.ctrl!==e.ctrlKey||t.shift!==void 0&&t.shift!==e.shiftKey||t.alt!==void 0&&t.alt!==e.altKey||t.meta!==void 0&&t.meta!==e.metaKey)}destroy(){this.target.removeEventListener("keydown",this.handleKeyDown),this.commands=[]}}function j(){return/Mac|iPod|iPhone|iPad/.test(navigator.platform)}function X(){return j()?"meta":"ctrl"}function W(f,e,t,i){const n=f/t,a=e/i;return Math.min(n,a)}function J(f,e,t=8,i=10,n=300){const a=W(f,e,t,i),o=a>=n;return{actualDPI:Math.round(a),targetDPI:n,width:f,height:e,passed:o,warning:o?void 0:`Image resolution is ${Math.round(a)} DPI at 100% scale. For best print quality, use images with at least ${n} DPI. This may result in pixelated or blurry prints.`}}const k=':host{--editor-bg: #f3f4f6;--editor-surface: #ffffff;--editor-border: #e5e7eb;--editor-text: #111827;--editor-text-muted: #6b7280;--editor-primary: #3b82f6;--editor-primary-hover: #2563eb;--editor-danger: #ef4444;--editor-radius: 8px;--editor-radius-sm: 4px;--editor-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;--editor-panel-width: 280px;display:block;width:100%;height:100%;font-family:var(--editor-font);font-size:13px;color:var(--editor-text);line-height:1.4}:host([theme="dark"]){--editor-bg: #1f2937;--editor-surface: #374151;--editor-border: #4b5563;--editor-text: #f9fafb;--editor-text-muted: #9ca3af}.editor-container{display:flex;flex-direction:column;width:100%;height:100%;position:relative;overflow:hidden;background:var(--editor-bg)}.layout-desktop .editor-main{display:flex;flex:1;min-height:0}.layout-desktop .canvas-area{flex:1;min-width:0;position:relative;display:flex;flex-direction:column}.layout-desktop .area-panel{width:var(--editor-panel-width);border-left:1px solid var(--editor-border);background:var(--editor-surface);display:none;flex-direction:column;overflow:hidden}.layout-desktop .area-panel.area-panel-visible{display:flex}.layout-mobile .editor-main{display:flex;flex-direction:column;flex:1;min-height:0}.layout-mobile .canvas-area{flex:1;position:relative;display:flex;flex-direction:column;min-height:0}.layout-mobile .area-panel{position:absolute;bottom:0;left:0;right:0;max-height:50%;background:var(--editor-surface);border-top:1px solid var(--editor-border);border-radius:var(--editor-radius) var(--editor-radius) 0 0;box-shadow:0 -4px 20px #00000026;transform:translateY(100%);transition:transform .25s ease-out;z-index:20;display:flex;flex-direction:column;overflow:hidden}.layout-mobile .area-panel.area-panel-visible{transform:translateY(0)}.area-panel-backdrop{display:none}.layout-mobile .area-panel-backdrop{display:block;position:absolute;inset:0;background:#0000004d;z-index:15;opacity:0;pointer-events:none;transition:opacity .25s ease-out}.layout-mobile .area-panel-backdrop.area-panel-backdrop-visible{opacity:1;pointer-events:auto}.zoom-toolbar{display:flex;align-items:center;gap:4px;padding:8px 12px;background:var(--editor-surface);border-bottom:1px solid var(--editor-border)}.zoom-btn{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:14px;font-family:var(--editor-font);transition:background .15s;-webkit-tap-highlight-color:transparent;touch-action:manipulation}.zoom-btn:hover{background:var(--editor-bg)}.zoom-btn:active{background:var(--editor-border)}.zoom-percent{margin-left:8px;font-size:12px;color:var(--editor-text-muted);min-width:40px}.view-select{margin-left:8px;padding:4px 8px;height:32px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);font-family:var(--editor-font);font-size:12px;cursor:pointer;-webkit-tap-highlight-color:transparent}.view-select:hover{background:var(--editor-bg)}.view-select:focus{outline:2px solid var(--editor-primary);outline-offset:-1px}.zoom-toolbar-spacer{flex:1}.zoom-close-btn{width:auto;padding:0 12px;font-size:13px;gap:4px}.zoom-save-btn{width:auto;padding:0 16px;margin-left:8px;font-size:13px;font-weight:600;background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.zoom-save-btn:hover{background:var(--editor-primary-hover)}.zoom-save-btn:disabled{opacity:.5;cursor:not-allowed}.canvas-wrapper{flex:1;position:relative;overflow:hidden;min-height:200px}.editor-canvas{position:absolute;top:0;left:0}.area-panel-header{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid var(--editor-border);flex-shrink:0}.area-panel-title{font-weight:600;font-size:14px}.area-panel-close-btn{width:28px;height:28px;border:none;background:none;color:var(--editor-text-muted);cursor:pointer;font-size:18px;line-height:1;border-radius:var(--editor-radius-sm);display:flex;align-items:center;justify-content:center}.area-panel-close-btn:hover{background:var(--editor-bg);color:var(--editor-text)}.area-panel-content{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:12px}.area-panel-empty{color:var(--editor-text-muted);font-size:12px;text-align:center;padding:20px 0}.area-card{padding:12px;border:1px solid var(--editor-border);border-radius:var(--editor-radius);background:var(--editor-surface);cursor:pointer;transition:border-color .15s}.area-card:hover{border-color:var(--editor-primary)}.area-card-selected{border-color:var(--editor-primary);box-shadow:0 0 0 1px var(--editor-primary)}.area-card-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.area-card-name-row{display:flex;align-items:center;gap:6px}.area-card-name{font-weight:600;font-size:13px}.area-card-badge{display:inline-block;padding:1px 6px;font-size:10px;font-weight:500;background:#fef3c7;color:#92400e;border-radius:10px}.area-card-reset-btn{padding:2px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-text-muted);cursor:pointer;font-size:11px;font-family:var(--editor-font)}.area-card-reset-btn:hover{background:var(--editor-bg);color:var(--editor-danger);border-color:var(--editor-danger)}.area-card-mode-switcher{display:flex;gap:4px;margin-bottom:8px}.mode-btn{flex:1;padding:4px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:12px;font-family:var(--editor-font);transition:all .15s}.mode-btn-active{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.area-input-text{width:100%;padding:6px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:13px;color:var(--editor-text);background:var(--editor-surface);box-sizing:border-box;margin-bottom:6px}.area-input-text:focus{outline:none;border-color:var(--editor-primary);box-shadow:0 0 0 1px var(--editor-primary)}.area-input-row{display:flex;gap:6px;align-items:center;margin-bottom:6px}.area-input-font{flex:1;padding:4px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface);min-width:0}.area-input-size{width:56px;padding:4px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface)}.area-input-align{display:flex;gap:2px}.align-btn{width:28px;height:28px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:12px;font-weight:600;font-family:var(--editor-font)}.align-btn-active{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.area-input-color{width:32px;height:28px;padding:0;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);cursor:pointer;background:none}.area-upload-btn{width:100%;padding:10px;border:2px dashed var(--editor-border);border-radius:var(--editor-radius);background:var(--editor-bg);color:var(--editor-text-muted);cursor:pointer;font-family:var(--editor-font);font-size:12px;text-align:center;transition:all .15s;min-height:44px}.area-upload-btn:hover{border-color:var(--editor-primary);color:var(--editor-primary)}.area-image-preview{display:flex;gap:8px;align-items:center}.area-image-thumb{width:48px;height:48px;object-fit:cover;border-radius:var(--editor-radius-sm);border:1px solid var(--editor-border)}.area-image-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px}.area-image-name{font-size:12px;color:var(--editor-text-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.area-image-remove-btn{padding:2px 8px;border:1px solid var(--editor-danger);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-danger);cursor:pointer;font-size:11px;font-family:var(--editor-font);width:fit-content}.area-image-remove-btn:hover{background:#fef2f2}.area-card-divider{height:1px;background:var(--editor-border);margin:8px 0}.transform-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}.transform-title{font-weight:600;font-size:12px}.transform-reset-btn{padding:2px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-text-muted);cursor:pointer;font-size:11px;font-family:var(--editor-font)}.transform-reset-btn:hover{background:var(--editor-bg)}.transform-label{font-size:11px;color:var(--editor-text-muted);white-space:nowrap}.transform-input{width:60px;padding:3px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface)}.transform-slider-row{flex-direction:column;align-items:stretch}.transform-slider{width:100%;accent-color:var(--editor-primary)}.loading-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;min-height:200px}.loading-spinner{width:32px;height:32px;border:3px solid var(--editor-border);border-top-color:var(--editor-primary);border-radius:50%;animation:spin .8s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.error-container{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%;min-height:200px;padding:20px;text-align:center}.error-title{font-weight:600;font-size:16px;color:var(--editor-danger);margin-bottom:8px}.error-message{font-size:13px;color:var(--editor-text-muted);max-width:400px;white-space:pre-wrap}:host(:focus){outline:2px solid var(--editor-primary);outline-offset:-2px}input:focus,select:focus,button:focus-visible{outline:2px solid var(--editor-primary);outline-offset:-1px}.context-menu{position:absolute;z-index:100;min-width:160px;background:var(--editor-surface);border:1px solid var(--editor-border);border-radius:var(--editor-radius);box-shadow:0 4px 12px #00000026;padding:4px 0;font-size:13px}.context-menu-header{padding:6px 12px;font-weight:600;font-size:12px;color:var(--editor-text-muted);user-select:none}.context-menu-divider{height:1px;background:var(--editor-border);margin:4px 0}.context-menu-item{padding:6px 12px;cursor:pointer;color:var(--editor-text);user-select:none;transition:background .1s}.context-menu-item:hover{background:var(--editor-bg)}.context-menu-item:active{background:var(--editor-border)}.context-menu-item-disabled{color:var(--editor-text-muted);cursor:default;pointer-events:none}.editor-toast{position:absolute;top:16px;left:50%;transform:translate(-50%);padding:10px 20px;border-radius:var(--editor-radius);font-size:13px;font-family:var(--editor-font);line-height:1.4;z-index:200;max-width:400px;text-align:center;animation:toast-in .25s ease-out,toast-out .25s ease-in forwards;animation-delay:0s,var(--toast-duration, 3.75s);pointer-events:none;box-shadow:0 4px 12px #00000026}.editor-toast-warning{background:#fef3c7;color:#92400e;border:1px solid #f59e0b}.editor-toast-error{background:#fef2f2;color:#991b1b;border:1px solid var(--editor-danger)}.editor-toast-info{background:#eff6ff;color:#1e40af;border:1px solid var(--editor-primary)}@keyframes toast-in{0%{opacity:0;transform:translate(-50%) translateY(-10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}@keyframes toast-out{0%{opacity:1;transform:translate(-50%) translateY(0)}to{opacity:0;transform:translate(-50%) translateY(-10px)}}.editor-modal-overlay{position:absolute;inset:0;background:#0006;z-index:300;display:flex;align-items:center;justify-content:center;animation:modal-overlay-in .2s ease-out}@keyframes modal-overlay-in{0%{opacity:0}to{opacity:1}}.editor-modal{background:var(--editor-surface);border-radius:var(--editor-radius);box-shadow:0 8px 32px #0003;max-width:380px;width:calc(100% - 32px);padding:20px;animation:modal-in .2s ease-out}@keyframes modal-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.editor-modal-title{font-weight:600;font-size:15px;margin-bottom:8px;color:var(--editor-text)}.editor-modal-body{font-size:13px;color:var(--editor-text-muted);margin-bottom:16px;line-height:1.5}.editor-modal-actions{display:flex;justify-content:flex-end;gap:8px}.editor-modal-btn{padding:8px 16px;border-radius:var(--editor-radius-sm);font-size:13px;font-family:var(--editor-font);cursor:pointer;border:1px solid var(--editor-border);background:var(--editor-surface);color:var(--editor-text);transition:background .15s}.editor-modal-btn:hover{background:var(--editor-bg)}.editor-modal-btn-primary{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.editor-modal-btn-primary:hover{background:var(--editor-primary-hover)}.area-validation-error{font-size:11px;color:var(--editor-danger);margin-top:4px}@media(pointer:coarse){.zoom-btn{min-width:44px;min-height:44px}.area-input-text,.area-input-font,.area-input-size{min-height:44px;font-size:16px}.align-btn{min-width:44px;min-height:44px}.area-upload-btn{min-height:48px}.view-select{min-height:44px;font-size:16px}}',G="2.0.0",K=768;class Q extends HTMLElement{constructor(){super(),this.resizeObserver=null,this.isReady=!1,this.currentTemplate=null,this.loadingTemplateId=null,this.isMobileLayout=!1,this.productViews=[],this.activeViewName=null,this.perViewContents=new Map,this.subscriptions=[],this.storageUsage=null,this.storageUsageLastRefresh=0,this.emitChange=F(()=>{this.dispatchEvent(new CustomEvent("change",{detail:{design:this.getDesign()},bubbles:!0,composed:!0}))},300),this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["template-id","product-id","theme","mode","store-id","api-url"]}async connectedCallback(){try{this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.renderLoading(),await this.initialize()}catch(e){this.showError("Failed to initialize editor",e)}}disconnectedCallback(){this.cleanup()}attributeChangedCallback(e,t,i){t!==i&&(e==="template-id"&&this.isReady&&i&&this.loadTemplate(i),e==="product-id"&&this.isReady&&i&&this.loadProduct(i))}getDesign(){if(!this.currentTemplate)throw new Error("No design loaded");return{templateId:this.currentTemplate.metadata.id,engineVersion:G,contents:this.contentManager.toJSON(),userData:{}}}setDesign(e){if(e.templateId!==this.currentTemplate?.metadata.id)throw new Error("Design template ID does not match current template");this.contentManager.fromJSON(e.contents),this.syncEngineContents(),this.stateManager.setState({contents:this.contentManager.toJSON(),isDirty:!0})}undo(){this.stateManager.undo()&&this.syncFromState()}redo(){this.stateManager.redo()&&this.syncFromState()}clear(){this.contentManager.reset(),this.syncEngineContents(),this.stateManager.setState({contents:this.contentManager.toJSON(),selectedAreaId:null,isDirty:!1}),this.zoomToolbar?.showSaveButton(!1),this.engine.setSelectedArea(null),this.inputPanel.setSelectedArea(null),this.engine.fitToView(),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()})}selectArea(e){this.handleAreaSelect(e)}getSelectedAreaId(){return this.stateManager.getState().selectedAreaId}getActiveView(){return this.activeViewName}getViews(){return this.productViews.map(e=>({viewName:e.viewName,viewOrder:e.viewOrder,isRequired:e.isRequired,isDefault:e.isDefault,templateId:e.template.id}))}setActiveView(e){if(this.activeViewName===e)return;const t=this.productViews.find(i=>i.viewName===e);if(!t)throw new Error(`View not found: ${e}`);this.switchToView(t)}setAreaContent(e,t){t.type==="text"?this.contentManager.setTextContent(e,t):this.contentManager.setImageContent(e,t.dataUrl,t.filename),this.syncEngineContents(),this.saveContentState()}getAreaContent(e){return this.contentManager.getContent(e)}async finalize(){const e=this.engine.checkSafeAreaViolations();if(e.length>0){const a=this.currentTemplate?.areas||[],o=e.map(s=>a.find(r=>r.id===s)?.name||s).join(", ");if(!await this.showConfirmation("Content outside safe area",`Content in ${o} extends beyond the safe area. It may be trimmed during printing. Continue?`,"Cancel","Proceed Anyway"))throw new Error("Finalization cancelled by user")}const t=this.getDesign(),i=this.getAttribute("store-id")||"demo-shop",n=await this.apiClient.finalizeDesign(i,t);return this.dispatchEvent(new CustomEvent("customizer:finalize",{detail:{designId:n.designId,proofUrl:n.proofUrl,templateId:t.templateId,designJson:t,status:n.status},bubbles:!0,composed:!0})),n}renderLoading(){const e=document.createElement("style");e.textContent=k,this.shadow.appendChild(e);const t=h("div",{class:"loading-container"},h("div",{class:"loading-spinner"}));this.shadow.appendChild(t)}async initialize(){const e=this.getAttribute("api-url")||"http://localhost:4000";this.apiClient=new V(`${e.replace(/\/+$/,"")}/public`);const t=this.getAttribute("product-id"),i=this.getAttribute("template-id");if(!t&&!i)throw new Error("Either template-id or product-id attribute is required");t?await this.loadProduct(t):await this.loadTemplate(i),this.isReady=!0,this.dispatchEvent(new CustomEvent("ready",{bubbles:!0,composed:!0}))}async loadTemplate(e){if(this.loadingTemplateId!==e){this.loadingTemplateId=e;try{const t=await this.apiClient.getTemplate(e);if(this.loadingTemplateId!==e)return;await this.loadTemplateData(t),this.loadingTemplateId=null}catch(t){throw this.loadingTemplateId=null,new Error(`Failed to load template: ${t.message}`)}}}async loadTemplateData(e){this.currentTemplate=e;const t=e.areas||[];this.contentManager=new L(t);const i={template:e,contents:this.contentManager.toJSON(),selectedAreaId:null,zoom:1,pan:{x:0,y:0},isDirty:!1,warnings:[]};this.stateManager=new N(i),this.buildUI(e,t),this.engine=new E(this.canvas),this.engine.setArtboard({width:e.artboard.width,height:e.artboard.height,backgroundColor:e.artboard.backgroundColor??"#ffffff"}),this.engine.setAreas(t),this.engine.setContents(this.contentManager.getContents()),e.backgroundImage&&this.engine.setBackgroundImage(e.backgroundImage);const n=e.artboard.safeArea??e.safeArea;n&&this.engine.setSafeArea(n),this.engine.start(),this.engine.fitToView(),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom()),this.interaction=new O(this.canvas,this.engine,()=>this.contentManager.getContents(),()=>this.stateManager.getState().selectedAreaId),this.wireInteractionEvents(),this.subscriptions.push(this.contentManager.subscribe(()=>{this.syncEngineContents(),this.inputPanel.setContents(this.contentManager.getContents())})),this.keyboard=new Y(this),this.setupKeyboardShortcuts(),this.inputPanel.setContents(this.contentManager.getContents());const a=this.getAttribute("store-id");a&&this.apiClient.getStorageUsage(a).then(o=>{this.storageUsage=o,o.usagePercent>=100?this.showToast("Storage quota exceeded. Upgrade your plan for more storage.","error"):o.usagePercent>=80&&this.showToast(`Storage ${o.usagePercent}% full. Consider upgrading your plan.`,"warning")}).catch(()=>{})}async loadProduct(e){try{const t=await this.apiClient.getProduct(e);if(t.views.length===0)throw new Error("Product has no active templates");this.productViews=t.views,this.perViewContents.clear();const i=t.views.find(n=>n.isDefault)||t.views[0];await this.loadTemplateData(i.template.templateJson),this.activeViewName=i.viewName,this.zoomToolbar&&t.views.length>1&&(this.zoomToolbar.setViews(this.getViews()),this.zoomToolbar.setActiveView(i.viewName))}catch(t){throw new Error(`Failed to load product: ${t.message}`)}}switchToView(e){this.activeViewName&&this.contentManager&&this.perViewContents.set(this.activeViewName,this.contentManager.toJSON()),this.activeViewName=e.viewName,this.zoomToolbar?.setActiveView(e.viewName);const t=e.template.templateJson;this.currentTemplate=t;const i=t.areas||[];this.contentManager=new L(i);const n=this.perViewContents.get(e.viewName);n&&this.contentManager.fromJSON(n),this.engine.setArtboard({width:t.artboard.width,height:t.artboard.height,backgroundColor:t.artboard.backgroundColor??"#ffffff"}),this.engine.setAreas(i),this.engine.setContents(this.contentManager.getContents()),this.engine.setBackgroundImage(t.backgroundImage??void 0);const a=t.artboard.safeArea??t.safeArea;this.engine.setSafeArea(a??null),this.engine.fitToView(),this.stateManager.setState({template:t,contents:this.contentManager.toJSON(),selectedAreaId:null,isDirty:this.stateManager.getState().isDirty,zoom:this.engine.getZoom(),pan:this.engine.getPan(),warnings:[]}),this.zoomToolbar.setZoom(this.engine.getZoom()),this.inputPanel.setAreas(i),this.inputPanel.setContents(this.contentManager.getContents()),this.inputPanel.setSelectedArea(null),this.engine.setSelectedArea(null),this.dispatchEvent(new CustomEvent("view-change",{detail:{viewName:e.viewName},bubbles:!0,composed:!0}))}buildUI(e,t){this.shadow.innerHTML="";const i=document.createElement("style");i.textContent=k,this.shadow.appendChild(i),this.container=h("div",{class:"editor-container"}),this.zoomToolbar=new $,this.subscriptions.push(this.zoomToolbar.on("zoom-in",()=>this.handleZoomIn())),this.subscriptions.push(this.zoomToolbar.on("zoom-out",()=>this.handleZoomOut())),this.subscriptions.push(this.zoomToolbar.on("zoom-fit",()=>this.handleZoomFit())),this.subscriptions.push(this.zoomToolbar.on("view-change",({viewName:o})=>{const s=this.productViews.find(r=>r.viewName===o);s&&this.switchToView(s)})),this.subscriptions.push(this.zoomToolbar.on("close",()=>{this.dispatchEvent(new CustomEvent("customizer:close",{bubbles:!0,composed:!0}))})),this.subscriptions.push(this.zoomToolbar.on("save",async()=>{this.zoomToolbar.setSaveDisabled(!0,"Saving...");try{await this.finalize(),this.zoomToolbar.setSaveDisabled(!0,"Saved!"),this.showToast("Design saved successfully!","info"),setTimeout(()=>{this.zoomToolbar.setSaveDisabled(!1,"Save Customization"),this.zoomToolbar.showSaveButton(!1),this.stateManager.update({isDirty:!1})},2e3)}catch(o){console.error("Customizer: finalize failed",o);const s=o instanceof Error?o.message:"Save failed. Please try again.";this.showToast(s,"error"),this.zoomToolbar.setSaveDisabled(!1,"Save Customization")}}));const n=h("div",{class:"canvas-area"});n.appendChild(this.zoomToolbar.getElement()),this.canvasWrapper=h("div",{class:"canvas-wrapper"}),this.canvas=document.createElement("canvas"),this.canvas.className="editor-canvas",this.canvasWrapper.appendChild(this.canvas),n.appendChild(this.canvasWrapper),this.inputPanel=new q(t),this.wireInputPanelEvents();const a=h("div",{class:"editor-main"});a.appendChild(n),a.appendChild(this.inputPanel.getBackdrop()),a.appendChild(this.inputPanel.getElement()),this.container.appendChild(a),this.shadow.appendChild(this.container),this.resizeObserver=new ResizeObserver(o=>{for(const s of o)s.target===this.canvasWrapper&&this.handleCanvasResize(s.contentRect),s.target===this.container&&this.handleLayoutResize(s.contentRect)}),this.resizeObserver.observe(this.canvasWrapper),this.resizeObserver.observe(this.container)}wireInteractionEvents(){this.subscriptions.push(this.interaction.on("area:select",({areaId:e})=>{this.handleAreaSelect(e)})),this.subscriptions.push(this.interaction.on("content:drag",({areaId:e,offset:t})=>{this.contentManager.setContentOffset(e,t),this.saveContentState()})),this.subscriptions.push(this.interaction.on("content:scale",({areaId:e,scale:t})=>{this.contentManager.setImageScale(e,t),this.saveContentState()})),this.subscriptions.push(this.interaction.on("content:rotate",({areaId:e,rotation:t})=>{this.contentManager.setImageRotation(e,t),this.saveContentState()})),this.subscriptions.push(this.interaction.on("zoom",({zoom:e})=>{this.engine.setZoom(e);const t=this.engine.getCenteredPan(e);t&&this.engine.setPan(t),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom())})),this.subscriptions.push(this.interaction.on("pan",({pan:e})=>{this.engine.setPan(e),this.stateManager.update({pan:e})})),this.subscriptions.push(this.interaction.on("cursor",({cursor:e})=>{this.canvas.style.cursor=e})),this.subscriptions.push(this.interaction.on("context-menu",({areaId:e,clientX:t,clientY:i})=>{this.handleContextMenu(e,t,i)}))}wireInputPanelEvents(){this.subscriptions.push(this.inputPanel.on("text:change",({areaId:e,updates:t})=>{this.contentManager.setTextContent(e,t),this.saveContentState()})),this.subscriptions.push(this.inputPanel.on("image:change",async({areaId:e,dataUrl:t,filename:i})=>{const n=this.contentManager.getContents();let a=0;for(const[s,r]of n)r.type==="image"&&s!==e&&a++;if(a>=10){this.showToast("Maximum of 10 images per design reached","error");return}if(await this.refreshStorageUsage(),this.storageUsage&&this.storageUsage.usagePercent>=100){this.showToast("Storage quota exceeded. Upgrade your plan for more storage.","error");return}const o=this.currentTemplate?.areas.find(s=>s.id===e);if(o&&this.currentTemplate){const s=this.currentTemplate.print.targetDpi;try{const r=new Image,d=await new Promise((p,g)=>{r.onload=()=>p({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>g(new Error("Failed to load image")),r.src=t}),l=o.location.width/s,c=o.location.height/s,u=J(d.width,d.height,l,c,s);if(u.actualDPI<150){if(!await this.showConfirmation("Low resolution detected",`This image is ${u.actualDPI} DPI at print size. Print may appear blurry. Recommended: ${s} DPI.`,"Cancel","Use Anyway"))return}else u.actualDPI<s&&(this.showToast(`Image resolution is ${u.actualDPI} DPI (${s} recommended)`,"warning"),this.stateManager.update({warnings:[...this.stateManager.getState().warnings,{type:"dpi",message:`${u.actualDPI} DPI`,areaId:e}]}))}catch{}}if(this.contentManager.setImageContent(e,t,i),this.saveContentState(),this.storageUsage){const s=Math.round(t.length*.75);this.storageUsage.storageUsed+=s,this.storageUsage.usagePercent=this.storageUsage.storageQuota>0?Math.round(this.storageUsage.storageUsed/this.storageUsage.storageQuota*100):0}})),this.subscriptions.push(this.inputPanel.on("validation:error",({message:e})=>{this.showToast(e,"error")})),this.subscriptions.push(this.inputPanel.on("clear",({areaId:e})=>{this.contentManager.clearContent(e),this.saveContentState()})),this.subscriptions.push(this.inputPanel.on("select",({areaId:e})=>{this.handleAreaSelect(e)})),this.subscriptions.push(this.inputPanel.on("offset:change",({areaId:e,offset:t})=>{this.contentManager.setContentOffset(e,t),this.saveContentState()})),this.subscriptions.push(this.inputPanel.on("scale:change",({areaId:e,scale:t})=>{this.contentManager.setImageScale(e,t),this.saveContentState()})),this.subscriptions.push(this.inputPanel.on("rotation:change",({areaId:e,rotation:t})=>{this.contentManager.setImageRotation(e,t),this.saveContentState()})),this.subscriptions.push(this.inputPanel.on("dismiss",()=>{this.handleAreaSelect(null)}))}handleAreaSelect(e,t=!1){this.stateManager.update({selectedAreaId:e}),this.engine.setSelectedArea(e),this.inputPanel.setSelectedArea(t?e:null),e&&document.activeElement!==this&&this.focus(),this.dispatchEvent(new CustomEvent("area:select",{detail:{areaId:e},bubbles:!0,composed:!0}))}handleContextMenu(e,t,i){this.handleAreaSelect(e,!!e)}handleZoomIn(){const e=this.engine.getZoom(),t=Math.min(e*1.25,5),i=this.engine.getCenteredPan(t);this.engine.setZoom(t),i&&this.engine.setPan(i),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom())}handleZoomOut(){const e=this.engine.getZoom(),t=Math.max(e*.8,.1),i=this.engine.getCenteredPan(t);this.engine.setZoom(t),i&&this.engine.setPan(i),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom())}handleZoomFit(){this.engine.fitToView(),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom())}handleCanvasResize(e){const{width:t,height:i}=e;if(t===0||i===0)return;const n=window.devicePixelRatio||1;this.canvas.width=t*n,this.canvas.height=i*n,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${i}px`,this.engine&&(this.engine.fitToView(),this.stateManager.update({zoom:this.engine.getZoom(),pan:this.engine.getPan()}),this.zoomToolbar.setZoom(this.engine.getZoom()))}handleLayoutResize(e){const t=e.width<K;this.container.classList.toggle("layout-desktop",!t),this.container.classList.toggle("layout-mobile",t),t!==this.isMobileLayout&&(this.isMobileLayout=t,this.inputPanel.setMobile(t))}async refreshStorageUsage(){if(Date.now()-this.storageUsageLastRefresh<3e4)return;const e=this.getAttribute("store-id");if(e)try{this.storageUsage=await this.apiClient.getStorageUsage(e),this.storageUsageLastRefresh=Date.now()}catch{}}saveContentState(){this.stateManager.setState({contents:this.contentManager.toJSON(),isDirty:!0}),this.zoomToolbar?.showSaveButton(!0),this.engine.checkSafeAreaViolations(),this.emitChange()}syncEngineContents(){this.engine?.setContents(this.contentManager.getContents())}syncFromState(){const e=this.stateManager.getState();this.contentManager.setContentsQuiet(e.contents),this.syncEngineContents(),this.inputPanel.setContents(this.contentManager.getContents()),this.engine.setSelectedArea(e.selectedAreaId),this.inputPanel.setSelectedArea(e.selectedAreaId)}setupKeyboardShortcuts(){const e=X();this.keyboard.register({key:"z",[e]:!0,handler:()=>this.undo()}),this.keyboard.register({key:"z",[e]:!0,shift:!0,handler:()=>this.redo()}),this.keyboard.register({key:"Escape",handler:()=>this.handleAreaSelect(null)})}showToast(e,t="info"){const i=h("div",{class:`editor-toast editor-toast-${t}`},e);this.shadow.appendChild(i),setTimeout(()=>i.remove(),4e3)}showConfirmation(e,t,i="Cancel",n="Continue"){return new Promise(a=>{const o=h("div",{class:"editor-modal-overlay"}),s=h("div",{class:"editor-modal"});s.appendChild(h("div",{class:"editor-modal-title"},e)),s.appendChild(h("div",{class:"editor-modal-body"},t));const r=h("div",{class:"editor-modal-actions"}),d=h("button",{class:"editor-modal-btn"},i);d.addEventListener("click",()=>{o.remove(),a(!1)});const l=h("button",{class:"editor-modal-btn editor-modal-btn-primary"},n);l.addEventListener("click",()=>{o.remove(),a(!0)}),r.appendChild(d),r.appendChild(l),s.appendChild(r),o.appendChild(s),o.addEventListener("click",c=>{c.target===o&&(o.remove(),a(!1))}),this.shadow.appendChild(o)})}showError(e,t){this.shadow.innerHTML="";const i=document.createElement("style");i.textContent=k,this.shadow.appendChild(i);const n=h("div",{class:"error-container"});n.appendChild(h("div",{class:"error-title"},e)),n.appendChild(h("div",{class:"error-message"},t?.message??"")),this.shadow.appendChild(n),this.dispatchEvent(new CustomEvent("error",{detail:{message:e,error:t},bubbles:!0,composed:!0}))}cleanup(){for(const e of this.subscriptions)e();this.subscriptions=[],this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.engine?.destroy(),this.interaction?.destroy(),this.keyboard?.destroy(),this.isReady=!1,this.currentTemplate=null,this.productViews=[],this.activeViewName=null,this.perViewContents.clear()}}customElements.get("customizer-editor")||customElements.define("customizer-editor",Q);function _(f,e){const t=typeof f=="string"?document.querySelector(f):f;if(!t)throw new Error(`Container not found: ${typeof f=="string"?f:"provided element is null"}`);if(!e.templateId&&!e.productId)throw new Error("Either templateId or productId must be provided");if(e.templateId&&e.productId)throw new Error("Only one of templateId or productId should be provided, not both");const i=document.createElement("customizer-editor");e.productId?i.setAttribute("product-id",e.productId):i.setAttribute("template-id",e.templateId),e.theme&&i.setAttribute("theme",e.theme),e.mode&&i.setAttribute("mode",e.mode),e.className&&i.classList.add(e.className),i.style.width="100%",i.style.height="100%";const n=[],a=(s,r)=>{i.addEventListener(s,r),n.push({event:s,handler:r})};t.innerHTML="",t.appendChild(i);const o={getDesign(){if(typeof i.getDesign!="function")throw new Error("Editor not ready: getDesign method not available");return i.getDesign()},setDesign(s){if(typeof i.setDesign!="function")throw new Error("Editor not ready: setDesign method not available");i.setDesign(s)},undo(){if(typeof i.undo!="function")throw new Error("Editor not ready: undo method not available");i.undo()},redo(){if(typeof i.redo!="function")throw new Error("Editor not ready: redo method not available");i.redo()},canUndo(){return typeof i.canUndo!="function"?!1:i.canUndo()},canRedo(){return typeof i.canRedo!="function"?!1:i.canRedo()},async finalize(){const s=this.getDesign(),r=e.apiUrl||"https://api.varianta.io";try{const d=await fetch(`${r}/public/finalize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({templateId:s.templateId||e.templateId,designJson:s})});if(!d.ok){const m=await d.json().catch(()=>({message:"Finalization failed"}));throw new Error(m.message||"Finalization failed")}const l=await d.json();let c={designId:l.designId,status:l.status,proofUrl:l.proofUrl??null,errorMessage:l.errorMessage??null};const u=1500,p=40;let g=0;for(;c.status==="processing"&&g<p;){await new Promise(b=>setTimeout(b,u)),g++;const m=await fetch(`${r}/public/designs/${c.designId}/status`);if(!m.ok)throw new Error("Failed to check design status");const v=await m.json();c={designId:v.designId,status:v.status,proofUrl:v.proofUrl??null,errorMessage:v.errorMessage??null}}return c.status==="processing"&&(c={...c,status:"failed",errorMessage:"Render timed out"}),e.onFinalize&&e.onFinalize(c),c}catch(d){const l={code:"FINALIZE_ERROR",message:d instanceof Error?d.message:"Unknown error",details:d};throw e.onError&&e.onError(l),d}},addTextLayer(s){if(typeof i.addTextLayer!="function")throw new Error("Editor not ready: addTextLayer method not available");i.addTextLayer(s)},async addImageLayer(s){if(typeof i.addImageLayer!="function")throw new Error("Editor not ready: addImageLayer method not available");return i.addImageLayer(s)},removeLayer(s){if(typeof i.removeLayer!="function")throw new Error("Editor not ready: removeLayer method not available");i.removeLayer(s)},selectLayer(s){if(typeof i.selectLayer!="function")throw new Error("Editor not ready: selectLayer method not available");i.selectLayer(s)},getSelectedLayerId(){return typeof i.getSelectedLayerId!="function"?null:i.getSelectedLayerId()},getActiveView(){return typeof i.getActiveView!="function"?null:i.getActiveView()},getViews(){return typeof i.getViews!="function"?[]:i.getViews()},setActiveView(s){if(typeof i.setActiveView!="function")throw new Error("Editor not ready: setActiveView method not available");i.setActiveView(s)},setTheme(s){i.setAttribute("theme",s)},setMode(s){i.setAttribute("mode",s)},destroy(){n.forEach(({event:s,handler:r})=>{i.removeEventListener(s,r)}),i.parentNode&&i.parentNode.removeChild(i)},getElement(){return i}};return e.onReady&&a("ready",(()=>{e.onReady?.(o)})),e.onChange&&a("change",(s=>{const r=s.detail.design;e.onChange?.(r)})),e.onLayerSelect&&a("layer:select",(s=>{e.onLayerSelect?.(s.detail.layerId)})),e.onLayerAdd&&a("layer:add",(s=>{e.onLayerAdd?.(s.detail.layerId)})),e.onLayerRemove&&a("layer:remove",(s=>{e.onLayerRemove?.(s.detail.layerId)})),e.onLayerUpdate&&a("layer:update",(s=>{e.onLayerUpdate?.(s.detail.layerId)})),e.onError&&a("error",(s=>{const r=s.detail.error;e.onError?.(r)})),e.onViewChange&&a("view-change",(s=>{e.onViewChange?.(s.detail.viewName)})),e.initialDesign&&i.addEventListener("ready",()=>{e.initialDesign&&i.setDesign(e.initialDesign)},{once:!0}),e.debug&&(console.log("[Customizer SDK] Initialized with options:",e),console.log("[Customizer SDK] Instance:",o)),o}C.initCustomizer=_,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
10
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../../editor/dist/customizer.esm.js","../src/vanilla/index.ts"],"sourcesContent":["class N {\n constructor(t) {\n this.animationFrameId = null, this.needsRender = !0, this.areas = [], this.contents = /* @__PURE__ */ new Map(), this.artboard = null, this.bgImageElement = null, this.loadedImages = /* @__PURE__ */ new Map(), this.loadingImages = /* @__PURE__ */ new Set(), this.zoom = 1, this.pan = { x: 0, y: 0 }, this.selectedAreaId = null, this.hoveredHandle = null, this.eventListeners = /* @__PURE__ */ new Map(), this.safeArea = null, this.safeAreaViolations = /* @__PURE__ */ new Set(), this.showAreaBorders = !0, this.areaSelectionEnabled = !0, this.renderLoop = () => {\n try {\n this.needsRender && (this.render(), this.needsRender = !1, this.emit(\"render\", void 0));\n } catch (i) {\n console.error(\"Error in render loop:\", i);\n }\n this.animationFrameId = requestAnimationFrame(this.renderLoop);\n }, this.canvas = t;\n const e = t.getContext(\"2d\");\n if (!e)\n throw new Error(\"Failed to get 2D context from canvas\");\n this.ctx = e;\n }\n /**\n * Start the render loop\n */\n start() {\n this.animationFrameId === null && this.renderLoop();\n }\n /**\n * Stop the render loop\n */\n stop() {\n this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null);\n }\n /**\n * Set artboard configuration\n */\n setArtboard(t) {\n this.artboard = t, this.requestRender();\n }\n /**\n * Get artboard configuration\n */\n getArtboard() {\n return this.artboard;\n }\n /**\n * Set areas to render\n */\n setAreas(t) {\n this.areas = [...t].sort((e, i) => e.zIndex - i.zIndex), this.requestRender();\n }\n /**\n * Get areas\n */\n getAreas() {\n return this.areas;\n }\n /**\n * Set area contents\n */\n setContents(t) {\n this.contents = t, this.loadContentImages(), this.requestRender();\n }\n /**\n * Get area contents\n */\n getContents() {\n return this.contents;\n }\n /**\n * Update content for a single area\n */\n updateContent(t, e) {\n this.contents.set(t, e), e.type === \"image\" && this.loadContentImages(), this.requestRender(), this.emit(\"content:change\", { areaId: t, content: e });\n }\n /**\n * Remove content for an area\n */\n removeContent(t) {\n this.contents.delete(t), this.loadedImages.delete(t), this.requestRender();\n }\n /**\n * Set background image\n */\n setBackgroundImage(t) {\n if (this.backgroundImage = t, t?.url && t.url !== this.bgImageElement?.src) {\n const e = new Image();\n e.crossOrigin = \"anonymous\", e.onload = () => {\n this.bgImageElement = e, this.requestRender();\n }, e.onerror = () => {\n this.bgImageElement = null, console.error(\"Failed to load background image:\", t.url), this.requestRender();\n }, e.src = t.url;\n } else t?.url || (this.bgImageElement = null);\n this.requestRender();\n }\n /**\n * Set zoom level\n */\n setZoom(t) {\n this.zoom = Math.max(0.1, Math.min(5, t)), this.requestRender();\n }\n /**\n * Set pan offset\n */\n setPan(t) {\n this.pan = t, this.requestRender();\n }\n /**\n * Get zoom level\n */\n getZoom() {\n return this.zoom;\n }\n /**\n * Get pan offset\n */\n getPan() {\n return this.pan;\n }\n /**\n * Set whether area borders are shown\n */\n setShowAreaBorders(t) {\n this.showAreaBorders = t, this.requestRender();\n }\n /**\n * Set whether area selection is enabled\n */\n setAreaSelectionEnabled(t) {\n this.areaSelectionEnabled = t;\n }\n /**\n * Calculate the pan offset needed to center the artboard at a given zoom level\n */\n getCenteredPan(t) {\n if (!this.artboard)\n return null;\n const { width: e, height: i } = this.artboard, s = window.devicePixelRatio || 1, n = this.canvas.width / s, a = this.canvas.height / s;\n return {\n x: (n / t - e) / 2,\n y: (a / t - i) / 2\n };\n }\n /**\n * Request a render on the next frame\n */\n requestRender() {\n this.needsRender = !0;\n }\n /**\n * Fit view to show the entire artboard\n */\n fitToView() {\n if (!this.artboard)\n return;\n const t = 0, { width: e, height: i } = this.artboard, s = window.devicePixelRatio || 1, n = this.canvas.width / s - t * 2, a = this.canvas.height / s - t * 2;\n if (n <= 0 || a <= 0)\n return;\n const o = n / e, r = a / i, l = Math.min(o, r), d = this.canvas.width / s, c = this.canvas.height / s, u = (d / l - e) / 2, p = (c / l - i) / 2;\n this.zoom = l, this.pan = { x: u, y: p }, this.requestRender();\n }\n /**\n * Set the selected area\n */\n setSelectedArea(t) {\n this.selectedAreaId !== t && (this.selectedAreaId = t, this.requestRender(), this.emit(\"area:select\", { areaId: t }));\n }\n /**\n * Get the selected area ID\n */\n getSelectedArea() {\n return this.selectedAreaId;\n }\n /**\n * Set the hovered handle for highlighting\n */\n setHoveredHandle(t) {\n this.hoveredHandle !== t && (this.hoveredHandle = t, this.requestRender());\n }\n /**\n * Get the currently hovered handle\n */\n getHoveredHandle() {\n return this.hoveredHandle;\n }\n /**\n * Convert screen coordinates to canvas coordinates\n */\n screenToCanvas(t, e) {\n const i = window.devicePixelRatio || 1, s = t / i, n = e / i, a = s / this.zoom - this.pan.x, o = n / this.zoom - this.pan.y;\n return { x: a, y: o };\n }\n /**\n * Get content bounds for an area (in artboard coordinates)\n */\n getContentBounds(t) {\n const e = this.areas.find((l) => l.id === t);\n if (!e)\n return null;\n const i = this.contents.get(t);\n if (!i)\n return null;\n const { location: s } = e, { x: n, y: a, width: o, height: r } = s;\n if (i.type === \"text\") {\n const l = i.offset || { x: 0, y: 0 }, d = i.scale ?? 1, c = i.rotation ?? 0, u = o * d, p = r * d, g = n + o / 2 + l.x, m = a + r / 2 + l.y;\n return {\n x: g - u / 2,\n y: m - p / 2,\n width: u,\n height: p,\n rotation: c,\n centerX: g,\n centerY: m\n };\n } else if (i.type === \"image\") {\n const l = this.loadedImages.get(t);\n if (!l)\n return null;\n const d = i.offset || { x: 0, y: 0 }, c = i.scale ?? 1, u = i.rotation ?? 0, p = l.naturalWidth / l.naturalHeight, g = o / r;\n let m, b;\n p > g ? (m = o, b = o / p) : (b = r, m = r * p);\n const y = m * c, w = b * c, v = n + o / 2 + d.x, x = a + r / 2 + d.y;\n return {\n x: v - y / 2,\n y: x - w / 2,\n width: y,\n height: w,\n rotation: u,\n centerX: v,\n centerY: x\n };\n }\n return null;\n }\n /**\n * Hit test content at given canvas coordinates\n * Returns area ID if content was hit, null otherwise\n */\n hitTestContent(t, e) {\n if (!this.areaSelectionEnabled)\n return null;\n for (let i = this.areas.length - 1; i >= 0; i--) {\n const s = this.areas[i], n = this.getContentBounds(s.id);\n if (n && this.isPointInBounds(t, e, n))\n return s.id;\n }\n return null;\n }\n /**\n * Hit test area at given canvas coordinates (ignoring content)\n * Returns area ID if point is inside area bounds\n */\n hitTestArea(t, e) {\n if (!this.areaSelectionEnabled)\n return null;\n for (let i = this.areas.length - 1; i >= 0; i--) {\n const s = this.areas[i], { x: n, y: a, width: o, height: r } = s.location;\n if (t >= n && t <= n + o && e >= a && e <= a + r)\n return s.id;\n }\n return null;\n }\n /**\n * Test if a point is inside rotated bounds\n */\n isPointInBounds(t, e, i) {\n const { centerX: s, centerY: n, width: a, height: o, rotation: r } = i, l = -r * Math.PI / 180, d = Math.cos(l), c = Math.sin(l), u = t - s, p = e - n, g = u * d - p * c, m = u * c + p * d;\n return g >= -a / 2 && g <= a / 2 && m >= -o / 2 && m <= o / 2;\n }\n /**\n * Get handle positions for the selected content\n */\n getContentHandlePositions(t) {\n const e = this.areas.find((v) => v.id === t);\n if (!e)\n return null;\n const i = this.contents.get(t);\n if (!i)\n return null;\n const s = this.getContentBounds(t);\n if (!s)\n return null;\n const { centerX: n, centerY: a, width: o, height: r, rotation: l } = s, d = 6 / this.zoom, c = 30 / this.zoom, u = l * Math.PI / 180, p = Math.cos(u), g = Math.sin(u), m = (v, x) => ({\n x: n + v * p - x * g,\n y: a + v * g + x * p\n }), b = [];\n if (i.type === \"image\" && e.imageOptions?.allowScaling || i.type === \"text\" && e.textOptions?.allowScaling) {\n const v = o / 2, x = r / 2, C = m(-v, -x);\n b.push({ type: \"nw\", ...C, radius: d });\n const S = m(v, -x);\n b.push({ type: \"ne\", ...S, radius: d });\n const z = m(v, x);\n b.push({ type: \"se\", ...z, radius: d });\n const T = m(-v, x);\n b.push({ type: \"sw\", ...T, radius: d });\n }\n if (i.type === \"image\" && e.imageOptions?.allowRotation || i.type === \"text\" && e.textOptions?.allowRotation) {\n const v = m(0, -r / 2 - c);\n b.push({ type: \"rotate\", ...v, radius: d });\n }\n return b;\n }\n /**\n * Hit test handles at given canvas coordinates\n */\n hitTestHandle(t, e, i) {\n const s = this.getContentHandlePositions(i);\n if (!s)\n return null;\n for (const n of s) {\n const a = t - n.x, o = e - n.y;\n if (Math.sqrt(a * a + o * o) <= n.radius * 2)\n return n.type;\n }\n return null;\n }\n /**\n * Check if positioning is allowed for an area\n */\n isPositioningAllowed(t) {\n const e = this.areas.find((s) => s.id === t);\n if (!e)\n return !1;\n const i = this.contents.get(t);\n return i ? i.type === \"text\" ? e.textOptions?.allowPositioning ?? !1 : e.imageOptions?.allowPositioning ?? !1 : !1;\n }\n /**\n * Get area location (for constraint calculations)\n */\n getAreaLocation(t) {\n const e = this.areas.find((i) => i.id === t);\n return e ? e.location : null;\n }\n /**\n * Get area by ID\n */\n getArea(t) {\n return this.areas.find((e) => e.id === t);\n }\n /**\n * Set safe area margins for content safety guides\n */\n setSafeArea(t) {\n this.safeArea = t ?? null, this.requestRender();\n }\n /**\n * Check if any area content extends beyond the safe area bounds.\n * Returns array of violating area IDs.\n */\n checkSafeAreaViolations() {\n if (!this.safeArea || !this.artboard)\n return [];\n const t = [], { top: e, right: i, bottom: s, left: n } = this.safeArea, a = n, o = e, r = this.artboard.width - i, l = this.artboard.height - s;\n for (const d of this.areas) {\n if (!this.contents.get(d.id))\n continue;\n const u = this.getContentBounds(d.id);\n if (!u)\n continue;\n const { centerX: p, centerY: g, width: m, height: b, rotation: y } = u, w = y * Math.PI / 180, v = Math.abs(Math.cos(w)), x = Math.abs(Math.sin(w)), C = m * v + b * x, S = m * x + b * v, z = p - C / 2, T = g - S / 2, D = p + C / 2, O = g + S / 2;\n (z < a || T < o || D > r || O > l) && t.push(d.id);\n }\n return this.safeAreaViolations = new Set(t), this.requestRender(), t;\n }\n /**\n * Add event listener\n */\n on(t, e) {\n return this.eventListeners.has(t) || this.eventListeners.set(t, /* @__PURE__ */ new Set()), this.eventListeners.get(t).add(e), () => {\n this.eventListeners.get(t)?.delete(e);\n };\n }\n /**\n * Emit event\n */\n emit(t, e) {\n const i = this.eventListeners.get(t);\n if (i)\n for (const s of i)\n s(e);\n }\n /**\n * Export to PNG at full resolution\n */\n async exportToPNG() {\n if (!this.artboard)\n throw new Error(\"No artboard configured\");\n const { width: t, height: e, backgroundColor: i } = this.artboard, s = document.createElement(\"canvas\");\n s.width = t, s.height = e;\n const n = s.getContext(\"2d\");\n if (!n)\n throw new Error(\"Failed to get 2D context for export\");\n n.fillStyle = i, n.fillRect(0, 0, t, e), this.backgroundImage?.position === \"behind\" && this.bgImageElement && this.drawBackgroundImageOnContext(n, t, e);\n for (const a of this.areas)\n this.drawAreaContentOnContext(n, a);\n return this.backgroundImage?.position === \"overlay\" && this.bgImageElement && this.drawBackgroundImageOnContext(n, t, e), new Promise((a, o) => {\n s.toBlob((r) => {\n r ? a(r) : o(new Error(\"Failed to create PNG blob\"));\n }, \"image/png\", 1);\n });\n }\n /**\n * Load images from content data URLs\n */\n loadContentImages() {\n for (const [t, e] of this.contents)\n if (e.type === \"image\" && !this.loadedImages.has(t) && !this.loadingImages.has(t)) {\n this.loadingImages.add(t);\n const i = new Image();\n i.onload = () => {\n this.loadedImages.set(t, i), this.loadingImages.delete(t), this.requestRender();\n }, i.onerror = () => {\n this.loadingImages.delete(t), console.error(\"Failed to load image for area:\", t);\n }, i.src = e.dataUrl;\n }\n for (const t of this.loadedImages.keys()) {\n const e = this.contents.get(t);\n (!e || e.type !== \"image\") && this.loadedImages.delete(t);\n }\n }\n /**\n * Render the canvas\n */\n render() {\n const { ctx: t, canvas: e } = this;\n if (t.fillStyle = \"#f3f4f6\", t.fillRect(0, 0, e.width, e.height), !this.artboard)\n return;\n t.save();\n const i = window.devicePixelRatio || 1;\n t.scale(i, i), t.scale(this.zoom, this.zoom), t.translate(this.pan.x, this.pan.y);\n const { width: s, height: n, backgroundColor: a } = this.artboard;\n t.fillStyle = a, t.fillRect(0, 0, s, n), t.strokeStyle = \"#d1d5db\", t.lineWidth = 1 / this.zoom, t.strokeRect(0, 0, s, n), this.backgroundImage?.position === \"behind\" && this.renderBackgroundImage();\n for (const o of this.areas)\n this.renderAreaWithContent(o);\n this.backgroundImage?.position === \"overlay\" && this.renderBackgroundImage(), this.renderSafeAreaGuide();\n for (const o of this.safeAreaViolations) {\n const r = this.areas.find((p) => p.id === o);\n if (!r)\n continue;\n const { x: l, y: d, width: c, height: u } = r.location;\n t.save(), t.fillStyle = \"rgba(239, 68, 68, 0.15)\", t.fillRect(l, d, c, u), t.restore();\n }\n this.selectedAreaId && this.renderSelectionOverlay(this.selectedAreaId), t.restore();\n }\n /**\n * Render selection overlay with handles\n */\n renderSelectionOverlay(t) {\n const e = this.getContentBounds(t);\n if (!e) {\n const d = this.areas.find((b) => b.id === t);\n if (!d)\n return;\n const { ctx: c } = this, { x: u, y: p, width: g, height: m } = d.location;\n c.save(), c.strokeStyle = \"#3b82f6\", c.lineWidth = 2 / this.zoom, c.setLineDash([]), c.strokeRect(u, p, g, m), c.restore();\n return;\n }\n const { ctx: i } = this, { centerX: s, centerY: n, width: a, height: o, rotation: r } = e;\n i.save(), i.translate(s, n), i.rotate(r * Math.PI / 180), i.strokeStyle = \"#3b82f6\", i.lineWidth = 2 / this.zoom, i.setLineDash([]), i.strokeRect(-a / 2, -o / 2, a, o), i.restore();\n const l = this.getContentHandlePositions(t);\n if (l)\n for (const d of l) {\n i.save();\n const c = this.hoveredHandle === d.type, u = c ? \"#dbeafe\" : \"#ffffff\", p = c ? \"#2563eb\" : \"#3b82f6\";\n if (d.type === \"rotate\") {\n const g = this.getRotatedPoint(s, n - o / 2, s, n, r);\n i.beginPath(), i.strokeStyle = p, i.lineWidth = 1 / this.zoom, i.setLineDash([4 / this.zoom, 4 / this.zoom]), i.moveTo(g.x, g.y), i.lineTo(d.x, d.y), i.stroke(), i.setLineDash([]), i.beginPath(), i.fillStyle = u, i.strokeStyle = p, i.lineWidth = 2 / this.zoom, i.arc(d.x, d.y, d.radius, 0, Math.PI * 2), i.fill(), i.stroke(), i.beginPath(), i.strokeStyle = p, i.lineWidth = 1.5 / this.zoom, i.arc(d.x, d.y, d.radius * 0.5, -Math.PI * 0.8, Math.PI * 0.5), i.stroke();\n } else\n i.fillStyle = u, i.strokeStyle = p, i.lineWidth = 2 / this.zoom, i.fillRect(d.x - d.radius, d.y - d.radius, d.radius * 2, d.radius * 2), i.strokeRect(d.x - d.radius, d.y - d.radius, d.radius * 2, d.radius * 2);\n i.restore();\n }\n }\n /**\n * Rotate a point around a center\n */\n getRotatedPoint(t, e, i, s, n) {\n const a = n * Math.PI / 180, o = Math.cos(a), r = Math.sin(a), l = t - i, d = e - s;\n return {\n x: i + l * o - d * r,\n y: s + l * r + d * o\n };\n }\n /**\n * Render background image\n */\n renderBackgroundImage() {\n if (!this.bgImageElement || !this.artboard || !this.backgroundImage)\n return;\n const { ctx: t } = this, { opacity: e } = this.backgroundImage, { width: i, height: s } = this.artboard;\n t.save(), t.globalAlpha = e;\n const n = this.bgImageElement.naturalWidth / this.bgImageElement.naturalHeight, a = i / s;\n let o, r, l, d;\n n > a ? (r = s, o = s * n, l = (i - o) / 2, d = 0) : (o = i, r = i / n, l = 0, d = (s - r) / 2), t.drawImage(this.bgImageElement, l, d, o, r), t.restore();\n }\n /**\n * Render safe area guide as dashed green rectangle\n */\n renderSafeAreaGuide() {\n if (!this.safeArea || !this.artboard)\n return;\n const { ctx: t } = this, { top: e, right: i, bottom: s, left: n } = this.safeArea, a = n, o = e, r = this.artboard.width - n - i, l = this.artboard.height - e - s;\n r <= 0 || l <= 0 || (t.save(), t.strokeStyle = \"#22c55e\", t.lineWidth = 1 / this.zoom, t.setLineDash([6 / this.zoom, 4 / this.zoom]), t.strokeRect(a, o, r, l), t.setLineDash([]), t.restore());\n }\n /**\n * Render an area with its content\n */\n renderAreaWithContent(t) {\n const { ctx: e } = this, { location: i, backgroundColor: s } = t, { x: n, y: a, width: o, height: r } = i;\n s && (e.fillStyle = s, e.fillRect(n, a, o, r));\n const l = this.contents.get(t.id);\n l && (l.type === \"text\" ? this.renderTextContent(t, l) : l.type === \"image\" && this.renderImageContent(t, l)), this.showAreaBorders && t.showBorder && (e.save(), e.strokeStyle = t.borderColor || \"#3b82f6\", e.lineWidth = 1 / this.zoom, e.setLineDash([4 / this.zoom, 4 / this.zoom]), e.strokeRect(n, a, o, r), e.setLineDash([]), e.restore());\n }\n /**\n * Render text content in an area\n */\n renderTextContent(t, e) {\n if (!e.text.trim())\n return;\n const { ctx: i } = this, { location: s } = t, { x: n, y: a, width: o, height: r } = s, l = e.offset || { x: 0, y: 0 }, d = e.scale ?? 1, c = e.rotation ?? 0, u = n + o / 2 + l.x, p = a + r / 2 + l.y;\n i.save(), i.beginPath(), i.rect(n, a, o, r), i.clip(), i.translate(u, p), i.rotate(c * Math.PI / 180), i.scale(d, d), i.font = `${e.size}px ${e.font}, sans-serif`, i.fillStyle = e.color, i.textBaseline = \"middle\";\n let g;\n switch (e.align) {\n case \"left\":\n i.textAlign = \"left\", g = -o / 2 + 10;\n break;\n case \"right\":\n i.textAlign = \"right\", g = o / 2 - 10;\n break;\n case \"center\":\n default:\n i.textAlign = \"center\", g = 0;\n break;\n }\n i.fillText(e.text, g, 0), i.restore();\n }\n /**\n * Render image content in an area\n */\n renderImageContent(t, e) {\n const i = this.loadedImages.get(t.id);\n if (!i)\n return;\n const { ctx: s } = this, { location: n } = t, { x: a, y: o, width: r, height: l } = n, d = e.offset || { x: 0, y: 0 }, c = e.scale ?? 1, u = e.rotation ?? 0;\n s.save(), s.beginPath(), s.rect(a, o, r, l), s.clip();\n const p = i.naturalWidth / i.naturalHeight, g = r / l;\n let m, b;\n p > g ? (m = r, b = r / p) : (b = l, m = l * p);\n const y = m * c, w = b * c, v = a + r / 2 + d.x, x = o + l / 2 + d.y;\n s.translate(v, x), s.rotate(u * Math.PI / 180), s.drawImage(i, -y / 2, -w / 2, y, w), s.restore();\n }\n /**\n * Draw background image on a specific context (for export)\n */\n drawBackgroundImageOnContext(t, e, i) {\n if (!this.bgImageElement || !this.backgroundImage)\n return;\n const { opacity: s } = this.backgroundImage;\n t.save(), t.globalAlpha = s;\n const n = this.bgImageElement.naturalWidth / this.bgImageElement.naturalHeight, a = e / i;\n let o, r, l, d;\n n > a ? (r = i, o = i * n, l = (e - o) / 2, d = 0) : (o = e, r = e / n, l = 0, d = (i - r) / 2), t.drawImage(this.bgImageElement, l, d, o, r), t.restore();\n }\n /**\n * Draw area content on a specific context (for export)\n */\n drawAreaContentOnContext(t, e) {\n const { location: i, backgroundColor: s } = e, { x: n, y: a, width: o, height: r } = i;\n s && (t.fillStyle = s, t.fillRect(n, a, o, r));\n const l = this.contents.get(e.id);\n if (l) {\n if (l.type === \"text\") {\n if (!l.text.trim())\n return;\n const d = l.offset || { x: 0, y: 0 }, c = l.scale ?? 1, u = l.rotation ?? 0, p = n + o / 2 + d.x, g = a + r / 2 + d.y;\n t.save(), t.beginPath(), t.rect(n, a, o, r), t.clip(), t.translate(p, g), t.rotate(u * Math.PI / 180), t.scale(c, c), t.font = `${l.size}px ${l.font}, sans-serif`, t.fillStyle = l.color, t.textBaseline = \"middle\";\n let m;\n switch (l.align) {\n case \"left\":\n t.textAlign = \"left\", m = -o / 2 + 10;\n break;\n case \"right\":\n t.textAlign = \"right\", m = o / 2 - 10;\n break;\n case \"center\":\n default:\n t.textAlign = \"center\", m = 0;\n break;\n }\n t.fillText(l.text, m, 0), t.restore();\n } else if (l.type === \"image\") {\n const d = this.loadedImages.get(e.id);\n if (!d)\n return;\n const c = l.offset || { x: 0, y: 0 }, u = l.scale ?? 1, p = l.rotation ?? 0;\n t.save(), t.beginPath(), t.rect(n, a, o, r), t.clip();\n const g = d.naturalWidth / d.naturalHeight, m = o / r;\n let b, y;\n g > m ? (b = o, y = o / g) : (y = r, b = r * g);\n const w = b * u, v = y * u, x = n + o / 2 + c.x, C = a + r / 2 + c.y;\n t.translate(x, C), t.rotate(p * Math.PI / 180), t.drawImage(d, -w / 2, -v / 2, w, v), t.restore();\n }\n }\n }\n /**\n * Cleanup resources\n */\n destroy() {\n this.stop(), this.bgImageElement = null, this.loadedImages.clear(), this.loadingImages.clear(), this.eventListeners.clear();\n }\n}\nfunction E(f) {\n const t = f.textOptions;\n return {\n type: \"text\",\n text: t?.defaultText || \"\",\n font: t?.defaultFont || \"Inter\",\n size: t?.defaultSize || 24,\n color: t?.defaultColor || \"#000000\",\n align: t?.defaultAlign || \"center\"\n };\n}\nfunction M(f) {\n return f.contentType === \"text\" || f.contentType === \"both\";\n}\nfunction P(f) {\n return f.contentType === \"image\" || f.contentType === \"both\";\n}\nconst H = 50;\nclass B {\n constructor(t) {\n this.history = [], this.historyIndex = -1, this.listeners = /* @__PURE__ */ new Set(), this.isRestoring = !1, this.state = this.cloneState(t), this.history.push({\n state: this.cloneState(t),\n timestamp: Date.now(),\n description: \"Initial state\"\n }), this.historyIndex = 0;\n }\n getState() {\n return this.state;\n }\n /**\n * Update state and save to history\n */\n setState(t, e, i = !1) {\n const s = this.state;\n this.state = { ...this.state, ...t }, !i && !this.isRestoring && this.saveToHistory(s, e), this.notifyListeners();\n }\n /**\n * Update state without saving to history\n * Use for transient changes like zoom/pan\n */\n update(t) {\n this.state = { ...this.state, ...t }, this.notifyListeners();\n }\n subscribe(t) {\n return this.listeners.add(t), () => this.listeners.delete(t);\n }\n undo() {\n return this.canUndo() ? (this.historyIndex--, this.restoreFromHistory(), !0) : !1;\n }\n redo() {\n return this.canRedo() ? (this.historyIndex++, this.restoreFromHistory(), !0) : !1;\n }\n canUndo() {\n return this.historyIndex > 0;\n }\n canRedo() {\n return this.historyIndex < this.history.length - 1;\n }\n clearHistory() {\n this.history = [], this.historyIndex = -1;\n }\n getHistory() {\n return this.history;\n }\n saveToHistory(t, e) {\n this.historyIndex < this.history.length - 1 && (this.history = this.history.slice(0, this.historyIndex + 1)), this.history.push({\n state: this.cloneState(t),\n timestamp: Date.now(),\n description: e\n }), this.history.length > H && this.history.shift(), this.historyIndex = this.history.length - 1;\n }\n restoreFromHistory() {\n const t = this.history[this.historyIndex];\n t && (this.isRestoring = !0, this.state = this.cloneState(t.state), this.notifyListeners(), this.isRestoring = !1);\n }\n notifyListeners() {\n const t = this.state;\n for (const e of this.listeners)\n try {\n e(t);\n } catch (i) {\n console.error(\"Error in state change listener:\", i);\n }\n }\n /**\n * Deep clone state. Contents are already serialized as Array<[string, AreaContent]>\n * so JSON.parse/stringify works correctly.\n */\n cloneState(t) {\n return JSON.parse(JSON.stringify(t));\n }\n}\nclass A {\n constructor(t) {\n this.listeners = /* @__PURE__ */ new Set(), this.areas = t, this.contents = this.buildInitialContents();\n }\n buildInitialContents() {\n const t = /* @__PURE__ */ new Map();\n for (const e of this.areas)\n M(e) && t.set(e.id, E(e));\n return t;\n }\n getContents() {\n return this.contents;\n }\n getContent(t) {\n return this.contents.get(t);\n }\n setTextContent(t, e) {\n const i = this.contents.get(t), s = this.areas.find((a) => a.id === t), n = s ? E(s) : {\n type: \"text\",\n text: \"\",\n font: \"Inter\",\n size: 24,\n color: \"#000000\",\n align: \"center\"\n };\n i?.type === \"text\" ? this.contents.set(t, { ...i, ...e }) : this.contents.set(t, { ...n, ...e }), this.notify();\n }\n setImageContent(t, e, i) {\n const s = {\n type: \"image\",\n dataUrl: e,\n filename: i\n };\n this.contents.set(t, s), this.notify();\n }\n clearContent(t) {\n const e = this.areas.find((i) => i.id === t);\n e && M(e) ? this.contents.set(t, E(e)) : this.contents.delete(t), this.notify();\n }\n setContentOffset(t, e) {\n const i = this.contents.get(t);\n i && (this.contents.set(t, { ...i, offset: e }), this.notify());\n }\n setImageScale(t, e) {\n const i = this.contents.get(t);\n if (!i || i.type !== \"image\") return;\n const s = Math.max(0.1, Math.min(5, e));\n this.contents.set(t, { ...i, scale: s }), this.notify();\n }\n setImageRotation(t, e) {\n const i = this.contents.get(t);\n if (!i || i.type !== \"image\") return;\n let s = e % 360;\n s < 0 && (s += 360), this.contents.set(t, { ...i, rotation: s }), this.notify();\n }\n reset() {\n this.contents = this.buildInitialContents(), this.notify();\n }\n /** Serialize for undo/redo (Map -> Array) */\n toJSON() {\n return Array.from(this.contents.entries());\n }\n /** Restore from serialized data */\n fromJSON(t) {\n this.contents = new Map(t), this.notify();\n }\n /** Replace the entire contents map (e.g. from undo/redo) without notification */\n setContentsQuiet(t) {\n this.contents = new Map(t);\n }\n subscribe(t) {\n return this.listeners.add(t), () => this.listeners.delete(t);\n }\n notify() {\n for (const t of this.listeners)\n try {\n t();\n } catch (e) {\n console.error(\"Error in AreaContentManager listener:\", e);\n }\n }\n}\nclass I {\n constructor() {\n this.listeners = /* @__PURE__ */ new Map();\n }\n /**\n * Register an event listener\n *\n * @param event - Event name\n * @param handler - Event handler function\n * @returns Unsubscribe function\n */\n on(t, e) {\n return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(e), () => this.off(t, e);\n }\n /**\n * Register a one-time event listener\n *\n * @param event - Event name\n * @param handler - Event handler function\n * @returns Unsubscribe function\n */\n once(t, e) {\n const i = (n) => {\n e(n), this.off(t, i);\n };\n return this.on(t, i);\n }\n /**\n * Remove an event listener\n *\n * @param event - Event name\n * @param handler - Event handler function to remove\n */\n off(t, e) {\n const i = this.listeners.get(t);\n i && (i.delete(e), i.size === 0 && this.listeners.delete(t));\n }\n /**\n * Emit an event to all registered listeners\n *\n * @param event - Event name\n * @param data - Event data\n */\n emit(t, e) {\n const i = this.listeners.get(t);\n if (i) {\n const s = Array.from(i);\n for (const n of s)\n try {\n n(e);\n } catch (a) {\n console.error(`Error in event handler for \"${String(t)}\":`, a);\n }\n }\n }\n /**\n * Remove all listeners for an event, or all listeners if no event specified\n *\n * @param event - Optional event name to clear (clears all if not specified)\n */\n clear(t) {\n t ? this.listeners.delete(t) : this.listeners.clear();\n }\n /**\n * Get the number of listeners for an event\n *\n * @param event - Event name\n * @returns Number of listeners\n */\n listenerCount(t) {\n return this.listeners.get(t)?.size ?? 0;\n }\n}\nclass U extends I {\n constructor() {\n super(...arguments), this.activeTouches = /* @__PURE__ */ new Map(), this.initialPinchDistance = null, this.lastPinchCenter = null, this.isTwoFingerGesture = !1;\n }\n /** Whether a multi-touch gesture is currently active */\n get isMultiTouch() {\n return this.isTwoFingerGesture;\n }\n handleTouchStart(t) {\n for (let e = 0; e < t.changedTouches.length; e++) {\n const i = t.changedTouches[e];\n this.activeTouches.set(i.identifier, {\n x: i.clientX,\n y: i.clientY\n });\n }\n if (this.activeTouches.size === 2) {\n this.isTwoFingerGesture = !0, t.preventDefault();\n const [e, i] = Array.from(this.activeTouches.values());\n this.initialPinchDistance = this.getDistance(e, i), this.lastPinchCenter = this.getCenter(e, i);\n }\n }\n handleTouchMove(t) {\n for (let e = 0; e < t.changedTouches.length; e++) {\n const i = t.changedTouches[e];\n this.activeTouches.set(i.identifier, {\n x: i.clientX,\n y: i.clientY\n });\n }\n if (this.activeTouches.size === 2 && this.initialPinchDistance !== null && this.lastPinchCenter) {\n t.preventDefault();\n const [e, i] = Array.from(this.activeTouches.values()), s = this.getDistance(e, i), n = this.getCenter(e, i), a = s / this.initialPinchDistance;\n this.emit(\"pinch\", {\n scale: a,\n centerX: n.x,\n centerY: n.y\n });\n const o = n.x - this.lastPinchCenter.x, r = n.y - this.lastPinchCenter.y;\n (Math.abs(o) > 0.5 || Math.abs(r) > 0.5) && this.emit(\"pan\", { deltaX: o, deltaY: r }), this.initialPinchDistance = s, this.lastPinchCenter = n;\n }\n }\n handleTouchEnd(t) {\n for (let e = 0; e < t.changedTouches.length; e++) {\n const i = t.changedTouches[e];\n this.activeTouches.delete(i.identifier);\n }\n this.activeTouches.size < 2 && (this.initialPinchDistance = null, this.lastPinchCenter = null, this.isTwoFingerGesture = !1);\n }\n reset() {\n this.activeTouches.clear(), this.initialPinchDistance = null, this.lastPinchCenter = null, this.isTwoFingerGesture = !1;\n }\n getDistance(t, e) {\n const i = e.x - t.x, s = e.y - t.y;\n return Math.sqrt(i * i + s * s);\n }\n getCenter(t, e) {\n return {\n x: (t.x + e.x) / 2,\n y: (t.y + e.y) / 2\n };\n }\n}\nclass F extends I {\n constructor(t, e, i, s) {\n super(), this.interactionState = { mode: \"idle\" }, this.initialPinchZoom = 1, this.canvas = t, this.engine = e, this.getContents = i, this.getSelectedAreaId = s, this.gestureHandler = new U(), this.boundMouseDown = this.handleMouseDown.bind(this), this.boundMouseMove = this.handleMouseMove.bind(this), this.boundMouseUp = this.handleMouseUp.bind(this), this.boundMouseLeave = this.handleMouseLeave.bind(this), this.boundContextMenu = this.handleContextMenu.bind(this), this.boundDoubleClick = this.handleDoubleClick.bind(this), this.boundTouchStart = this.handleTouchStart.bind(this), this.boundTouchMove = this.handleTouchMove.bind(this), this.boundTouchEnd = this.handleTouchEnd.bind(this), t.addEventListener(\"mousedown\", this.boundMouseDown), t.addEventListener(\"mousemove\", this.boundMouseMove), t.addEventListener(\"mouseup\", this.boundMouseUp), t.addEventListener(\"mouseleave\", this.boundMouseLeave), t.addEventListener(\"contextmenu\", this.boundContextMenu), t.addEventListener(\"dblclick\", this.boundDoubleClick), t.addEventListener(\"touchstart\", this.boundTouchStart, { passive: !1 }), t.addEventListener(\"touchmove\", this.boundTouchMove, { passive: !1 }), t.addEventListener(\"touchend\", this.boundTouchEnd), this.gestureHandler.on(\"pinch\", ({ scale: n }) => {\n const a = Math.max(0.1, Math.min(5, this.initialPinchZoom * n));\n this.emit(\"zoom\", { zoom: a });\n }), this.gestureHandler.on(\"pan\", ({ deltaX: n, deltaY: a }) => {\n const o = this.engine.getPan(), r = this.engine.getZoom();\n this.emit(\"pan\", {\n pan: {\n x: o.x + n / r,\n y: o.y + a / r\n }\n });\n });\n }\n getCanvasPosition(t, e) {\n const i = this.canvas.getBoundingClientRect(), s = window.devicePixelRatio || 1, n = (t - i.left) * s, a = (e - i.top) * s;\n return this.engine.screenToCanvas(n, a);\n }\n handleMouseDown(t) {\n const e = this.getCanvasPosition(t.clientX, t.clientY);\n this.processPointerDown(e);\n }\n handleMouseMove(t) {\n const e = this.getCanvasPosition(t.clientX, t.clientY);\n this.processPointerMove(e);\n }\n handleMouseUp() {\n this.processPointerUp();\n }\n handleMouseLeave() {\n this.processPointerUp(), this.emit(\"cursor\", { cursor: \"default\" });\n }\n handleContextMenu(t) {\n t.preventDefault();\n }\n handleDoubleClick(t) {\n const e = this.getCanvasPosition(t.clientX, t.clientY);\n let i = this.engine.hitTestContent(e.x, e.y);\n i || (i = this.engine.hitTestArea(e.x, e.y) ?? null), this.emit(\"context-menu\", { areaId: i, clientX: t.clientX, clientY: t.clientY });\n }\n handleTouchStart(t) {\n if (this.gestureHandler.handleTouchStart(t), this.gestureHandler.isMultiTouch) {\n this.initialPinchZoom = this.engine.getZoom(), this.interactionState.mode !== \"idle\" && (this.interactionState = { mode: \"idle\" });\n return;\n }\n if (t.touches.length !== 1) return;\n const e = t.touches[0], i = this.getCanvasPosition(e.clientX, e.clientY);\n this.processPointerDown(i) && t.preventDefault();\n }\n handleTouchMove(t) {\n if (this.gestureHandler.handleTouchMove(t), this.gestureHandler.isMultiTouch || t.touches.length !== 1 || this.interactionState.mode === \"idle\") return;\n const e = t.touches[0], i = this.getCanvasPosition(e.clientX, e.clientY);\n this.processPointerMove(i), t.preventDefault();\n }\n handleTouchEnd(t) {\n this.gestureHandler.handleTouchEnd(t), this.gestureHandler.isMultiTouch || this.processPointerUp();\n }\n /**\n * Process pointer down. Returns true if an interaction started.\n */\n processPointerDown(t) {\n const e = this.getSelectedAreaId(), i = this.getContents();\n if (e) {\n const a = this.engine.hitTestHandle(t.x, t.y, e);\n if (a) {\n const o = i.get(e), r = this.engine.getContentBounds(e);\n if (a === \"rotate\" && o?.type === \"image\" && r) {\n const l = Math.atan2(t.y - r.centerY, t.x - r.centerX) * (180 / Math.PI);\n return this.interactionState = {\n mode: \"rotating\",\n areaId: e,\n startRotation: o.rotation ?? 0,\n centerPoint: { x: r.centerX, y: r.centerY },\n startAngle: l\n }, !0;\n } else if (a !== \"rotate\" && o?.type === \"image\" && r)\n return this.interactionState = {\n mode: \"scaling\",\n areaId: e,\n handle: a,\n startScale: o.scale ?? 1,\n startMousePos: t,\n pivotPoint: { x: r.centerX, y: r.centerY }\n }, !0;\n }\n }\n const s = this.engine.hitTestContent(t.x, t.y);\n if (s) {\n if (this.emit(\"area:select\", { areaId: s }), this.engine.isPositioningAllowed(s)) {\n const o = i.get(s)?.offset ?? { x: 0, y: 0 };\n return this.interactionState = {\n mode: \"dragging\",\n areaId: s,\n startOffset: o,\n startMousePos: t\n }, !0;\n }\n return !0;\n }\n const n = this.engine.hitTestArea(t.x, t.y);\n return n ? (this.emit(\"area:select\", { areaId: n }), !1) : (this.emit(\"area:select\", { areaId: null }), !1);\n }\n processPointerMove(t) {\n if (this.interactionState.mode === \"dragging\") {\n const { areaId: e, startOffset: i, startMousePos: s } = this.interactionState, n = t.x - s.x, a = t.y - s.y;\n let o = {\n x: i.x + n,\n y: i.y + a\n };\n const r = this.engine.getAreaLocation(e);\n if (r) {\n const l = r.width / 2 - 10, d = r.height / 2 - 10;\n o.x = Math.max(-l, Math.min(l, o.x)), o.y = Math.max(-d, Math.min(d, o.y));\n }\n this.emit(\"content:drag\", { areaId: e, offset: o });\n return;\n }\n if (this.interactionState.mode === \"scaling\") {\n const { areaId: e, startScale: i, startMousePos: s, pivotPoint: n } = this.interactionState, a = Math.sqrt(\n Math.pow(s.x - n.x, 2) + Math.pow(s.y - n.y, 2)\n ), o = Math.sqrt(\n Math.pow(t.x - n.x, 2) + Math.pow(t.y - n.y, 2)\n );\n if (a > 0) {\n const r = o / a, l = Math.max(0.1, Math.min(5, i * r));\n this.emit(\"content:scale\", { areaId: e, scale: l });\n }\n return;\n }\n if (this.interactionState.mode === \"rotating\") {\n const { areaId: e, startRotation: i, centerPoint: s, startAngle: n } = this.interactionState, a = Math.atan2(t.y - s.y, t.x - s.x) * (180 / Math.PI);\n let o = i + (a - n);\n o = o % 360, o < 0 && (o += 360);\n const r = [0, 90, 180, 270, 360];\n for (const l of r)\n if (Math.abs(o - l) < 5) {\n o = l === 360 ? 0 : l;\n break;\n }\n this.emit(\"content:rotate\", { areaId: e, rotation: o });\n return;\n }\n this.updateCursor(t);\n }\n processPointerUp() {\n this.interactionState.mode !== \"idle\" && (this.interactionState = { mode: \"idle\" });\n }\n updateCursor(t) {\n const e = this.getSelectedAreaId();\n let i = \"default\";\n if (e) {\n const s = this.engine.hitTestHandle(t.x, t.y, e);\n s ? i = s === \"rotate\" ? \"crosshair\" : s === \"nw\" || s === \"se\" ? \"nwse-resize\" : \"nesw-resize\" : this.engine.hitTestContent(t.x, t.y) === e && (i = this.engine.isPositioningAllowed(e) ? \"move\" : \"pointer\");\n } else\n this.engine.hitTestContent(t.x, t.y) && (i = \"pointer\");\n this.emit(\"cursor\", { cursor: i });\n }\n setSelectedArea(t) {\n this.engine.setSelectedArea(t);\n }\n destroy() {\n this.canvas.removeEventListener(\"mousedown\", this.boundMouseDown), this.canvas.removeEventListener(\"mousemove\", this.boundMouseMove), this.canvas.removeEventListener(\"mouseup\", this.boundMouseUp), this.canvas.removeEventListener(\"mouseleave\", this.boundMouseLeave), this.canvas.removeEventListener(\"contextmenu\", this.boundContextMenu), this.canvas.removeEventListener(\"dblclick\", this.boundDoubleClick), this.canvas.removeEventListener(\"touchstart\", this.boundTouchStart), this.canvas.removeEventListener(\"touchmove\", this.boundTouchMove), this.canvas.removeEventListener(\"touchend\", this.boundTouchEnd), this.gestureHandler.reset(), this.clear();\n }\n}\nclass Z {\n constructor(t = \"/api\") {\n this.baseUrl = t;\n }\n async getTemplate(t) {\n try {\n const e = await fetch(`${this.baseUrl}/templates/${t}`);\n if (!e.ok) {\n let s = `Failed to load template (${e.status} ${e.statusText}): ${t}\n\n`;\n throw e.status === 404 ? s += \"Template not found.\" : e.status === 403 ? s += \"Access forbidden.\" : e.status >= 500 && (s += \"Server error.\"), new Error(s);\n }\n return (await e.json()).templateJson;\n } catch (e) {\n throw e instanceof Error && e.message.includes(\"Failed to fetch\") ? new Error(`Network error loading template: ${t}`) : e;\n }\n }\n async getProduct(t) {\n try {\n const e = await fetch(`${this.baseUrl}/products/${t}`);\n if (!e.ok) {\n let i = `Failed to load product (${e.status} ${e.statusText}): ${t}\n\n`;\n throw e.status === 404 ? i += \"Product not found.\" : e.status === 403 ? i += \"Access forbidden.\" : e.status >= 500 && (i += \"Server error.\"), new Error(i);\n }\n return e.json();\n } catch (e) {\n throw e instanceof Error && e.message.includes(\"Failed to fetch\") ? new Error(`Network error loading product: ${t}`) : e;\n }\n }\n async finalizeDesign(t, e) {\n try {\n const i = await fetch(`${this.baseUrl}/finalize`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n shopId: t,\n templateId: e.templateId,\n designJson: e\n })\n });\n if (!i.ok) {\n let s = `Failed to finalize design (${i.status} ${i.statusText})\n\n`;\n if (i.status === 400) {\n const n = await i.json().catch(() => ({}));\n s += n.error || \"Invalid design data.\";\n } else i.status === 429 ? s += \"Rate limit exceeded.\" : i.status >= 500 && (s += \"Server error.\");\n throw new Error(s);\n }\n return i.json();\n } catch (i) {\n throw i instanceof Error && i.message.includes(\"Failed to fetch\") ? new Error(\"Network error finalizing design\") : i;\n }\n }\n async uploadAsset(t, e) {\n try {\n const i = new FormData();\n i.append(\"shopId\", e), i.append(\"file\", t);\n const s = await fetch(`${this.baseUrl}/assets/upload`, {\n method: \"POST\",\n body: i\n });\n if (!s.ok) {\n let n = `Failed to upload asset (${s.status} ${s.statusText})\n\n`;\n if (s.status === 400) {\n const a = await s.json().catch(() => ({}));\n n += a.error || \"Invalid file.\";\n } else s.status === 413 ? n += \"File too large (max 15MB).\" : s.status >= 500 && (n += \"Server error.\");\n throw new Error(n);\n }\n return s.json();\n } catch (i) {\n throw i instanceof Error && i.message.includes(\"Failed to fetch\") ? new Error(\"Network error uploading asset\") : i;\n }\n }\n async getStorageUsage(t) {\n try {\n const e = await fetch(`${this.baseUrl}/assets/usage?shopId=${encodeURIComponent(t)}`);\n if (!e.ok)\n throw new Error(`Failed to fetch storage usage (${e.status})`);\n return e.json();\n } catch (e) {\n throw e instanceof Error && e.message.includes(\"Failed to fetch\") ? new Error(\"Network error fetching storage usage\") : e;\n }\n }\n}\nfunction h(f, t, ...e) {\n const i = document.createElement(f);\n return t && Object.entries(t).forEach(([s, n]) => {\n s === \"class\" ? i.className = n : s in i ? i[s] = n : i.setAttribute(s, String(n));\n }), e.forEach((s) => {\n typeof s == \"string\" ? i.appendChild(document.createTextNode(s)) : i.appendChild(s);\n }), i;\n}\nfunction $(f, t) {\n let e = null, i = null;\n const s = (...n) => {\n i = n, e && clearTimeout(e), e = setTimeout(() => {\n i && f(...i), e = null, i = null;\n }, t);\n };\n return s.flush = () => {\n e && (clearTimeout(e), e = null), i && (f(...i), i = null);\n }, s.cancel = () => {\n e && (clearTimeout(e), e = null), i = null;\n }, s;\n}\nclass V extends I {\n constructor() {\n super(), this.percentLabel = h(\"span\", { class: \"zoom-percent\" }, \"100%\");\n const t = h(\"button\", {\n class: \"zoom-btn\",\n title: \"Zoom out\"\n }, \"−\");\n t.addEventListener(\"click\", () => this.emit(\"zoom-out\", void 0));\n const e = h(\"button\", {\n class: \"zoom-btn\",\n title: \"Fit to view\"\n }, \"Fit\");\n e.addEventListener(\"click\", () => this.emit(\"zoom-fit\", void 0));\n const i = h(\"button\", {\n class: \"zoom-btn\",\n title: \"Zoom in\"\n }, \"+\");\n i.addEventListener(\"click\", () => this.emit(\"zoom-in\", void 0)), this.viewSelect = document.createElement(\"select\"), this.viewSelect.className = \"view-select\", this.viewSelect.title = \"Switch view\", this.viewSelect.style.display = \"none\", this.viewSelect.addEventListener(\"change\", () => {\n this.emit(\"view-change\", { viewName: this.viewSelect.value });\n }), this.element = h(\"div\", { class: \"zoom-toolbar\" }), this.element.appendChild(t), this.element.appendChild(e), this.element.appendChild(i), this.element.appendChild(this.percentLabel), this.element.appendChild(this.viewSelect);\n const s = h(\"div\", { class: \"zoom-toolbar-spacer\" });\n this.element.appendChild(s);\n const n = h(\"button\", {\n class: \"zoom-btn zoom-close-btn\",\n title: \"Close editor\"\n }, \"✕ Close\");\n n.addEventListener(\"click\", () => this.emit(\"close\", void 0)), this.element.appendChild(n), this.saveBtn = h(\"button\", {\n class: \"zoom-btn zoom-save-btn\",\n title: \"Save customization\"\n }, \"Save Customization\"), this.saveBtn.style.display = \"none\", this.saveBtn.addEventListener(\"click\", () => this.emit(\"save\", void 0)), this.element.appendChild(this.saveBtn);\n }\n setZoom(t) {\n this.percentLabel.textContent = `${Math.round(t * 100)}%`;\n }\n showSaveButton(t) {\n this.saveBtn.style.display = t ? \"\" : \"none\";\n }\n setSaveDisabled(t, e) {\n this.saveBtn.disabled = t, e && (this.saveBtn.textContent = e);\n }\n setViews(t) {\n this.viewSelect.innerHTML = \"\";\n for (const e of t) {\n const i = document.createElement(\"option\");\n i.value = e.viewName, i.textContent = e.viewName, this.viewSelect.appendChild(i);\n }\n this.viewSelect.style.display = t.length > 1 ? \"\" : \"none\";\n }\n setActiveView(t) {\n this.viewSelect.value = t;\n }\n getElement() {\n return this.element;\n }\n}\nconst Y = [\n { label: \"Inter\", value: \"Inter\" },\n { label: \"Arial\", value: \"Arial\" },\n { label: \"Georgia\", value: \"Georgia\" },\n { label: \"Times New Roman\", value: \"Times New Roman\" },\n { label: \"Courier New\", value: \"Courier New\" }\n], W = [\n { label: \"L\", value: \"left\" },\n { label: \"C\", value: \"center\" },\n { label: \"R\", value: \"right\" }\n], L = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/svg+xml\"], X = 15 * 1024 * 1024;\nclass R extends I {\n constructor(t) {\n super(), this.mode = \"text\", this.isSelected = !1, this.textInputEl = null, this.fontSelectEl = null, this.sizeInputEl = null, this.colorInputEl = null, this.alignGroupEl = null, this.area = t;\n const e = M(t), i = P(t);\n this.mode = i && !e ? \"image\" : \"text\", this.element = h(\"div\", { class: \"area-card\" }), this.element.addEventListener(\"click\", (r) => {\n r.target.tagName === \"INPUT\" || r.target.tagName === \"SELECT\" || r.target.tagName === \"BUTTON\" || this.emit(\"select\", { areaId: t.id });\n });\n const s = h(\"div\", { class: \"area-card-header\" }), n = h(\"div\", { class: \"area-card-name-row\" }), a = h(\"span\", { class: \"area-card-name\" }, t.name);\n if (n.appendChild(a), t.required) {\n const r = h(\"span\", { class: \"area-card-badge\" }, \"Required\");\n n.appendChild(r);\n }\n s.appendChild(n);\n const o = h(\"button\", {\n class: \"area-card-reset-btn\",\n title: \"Reset content\"\n }, \"Reset\");\n if (o.addEventListener(\"click\", (r) => {\n r.stopPropagation(), this.emit(\"clear\", { areaId: t.id });\n }), s.appendChild(o), this.element.appendChild(s), e && i) {\n const r = h(\"div\", { class: \"area-card-mode-switcher\" }), l = h(\"button\", {\n class: \"mode-btn mode-btn-active\"\n }, \"Text\");\n l.dataset.mode = \"text\";\n const d = h(\"button\", { class: \"mode-btn\" }, \"Image\");\n d.dataset.mode = \"image\", l.addEventListener(\"click\", (c) => {\n c.stopPropagation(), this.setMode(\"text\"), l.classList.add(\"mode-btn-active\"), d.classList.remove(\"mode-btn-active\"), this.currentContent?.type === \"image\" && this.emit(\"clear\", { areaId: t.id });\n }), d.addEventListener(\"click\", (c) => {\n c.stopPropagation(), this.setMode(\"image\"), d.classList.add(\"mode-btn-active\"), l.classList.remove(\"mode-btn-active\"), this.currentContent?.type === \"text\" && this.emit(\"clear\", { areaId: t.id });\n }), r.appendChild(l), r.appendChild(d), this.element.appendChild(r);\n }\n this.contentContainer = h(\"div\", { class: \"area-card-content\" }), this.element.appendChild(this.contentContainer), this.transformContainer = h(\"div\", { class: \"area-card-transforms\" }), this.element.appendChild(this.transformContainer), this.renderContent();\n }\n setMode(t) {\n this.mode = t, this.renderContent();\n }\n setContent(t) {\n const e = this.currentContent?.type;\n this.currentContent = t, t?.type === \"image\" && (this.mode = \"image\"), this.element.querySelectorAll(\".mode-btn\").forEach((n) => {\n const a = n;\n a.classList.toggle(\"mode-btn-active\", a.dataset.mode === this.mode);\n }), t?.type !== e || t?.type === \"image\" || t === void 0 ? this.renderContent() : t?.type === \"text\" && this.updateTextValues(t), this.renderTransforms();\n }\n setSelected(t) {\n this.isSelected = t, this.element.classList.toggle(\"area-card-selected\", t), this.renderTransforms();\n }\n updateTextValues(t) {\n this.textInputEl && this.textInputEl.value !== t.text && (this.textInputEl.value = t.text), this.fontSelectEl && this.fontSelectEl.value !== t.font && (this.fontSelectEl.value = t.font), this.sizeInputEl && this.sizeInputEl.value !== String(t.size) && (this.sizeInputEl.value = String(t.size)), this.colorInputEl && this.colorInputEl.value !== t.color && (this.colorInputEl.value = t.color), this.alignGroupEl && this.alignGroupEl.querySelectorAll(\".align-btn\").forEach((e) => {\n const i = e, s = i.title === \"Left\" ? \"left\" : i.title === \"Center\" ? \"center\" : \"right\";\n i.classList.toggle(\"align-btn-active\", s === t.align);\n });\n }\n renderContent() {\n this.contentContainer.innerHTML = \"\", this.textInputEl = null, this.fontSelectEl = null, this.sizeInputEl = null, this.colorInputEl = null, this.alignGroupEl = null;\n const t = M(this.area), e = P(this.area), i = !e || t && e && this.mode === \"text\", s = !t || t && e && this.mode === \"image\";\n t && i && this.renderTextControls(), e && s && this.renderImageControls();\n }\n renderTextControls() {\n const t = this.currentContent, e = t?.type === \"text\" ? t : E(this.area), i = h(\"input\", {\n class: \"area-input-text\",\n type: \"text\",\n placeholder: this.area.placeholder || \"Enter text...\"\n });\n i.value = e.text, this.area.textOptions?.maxLength && (i.maxLength = this.area.textOptions.maxLength), i.addEventListener(\"input\", () => {\n this.emit(\"text:change\", { areaId: this.area.id, updates: { text: i.value } });\n }), this.contentContainer.appendChild(i), this.textInputEl = i;\n const s = h(\"div\", { class: \"area-input-row\" }), n = h(\"select\", { class: \"area-input-font\" });\n for (const d of Y) {\n const c = h(\"option\");\n c.value = d.value, c.textContent = d.label, d.value === e.font && (c.selected = !0), n.appendChild(c);\n }\n n.addEventListener(\"change\", () => {\n this.emit(\"text:change\", { areaId: this.area.id, updates: { font: n.value } });\n }), s.appendChild(n), this.fontSelectEl = n;\n const a = h(\"input\", {\n class: \"area-input-size\",\n type: \"number\"\n });\n a.value = String(e.size), a.min = String(this.area.textOptions?.minSize || 8), a.max = String(this.area.textOptions?.maxSize || 200), a.addEventListener(\"change\", () => {\n this.emit(\"text:change\", {\n areaId: this.area.id,\n updates: { size: parseInt(a.value, 10) || 24 }\n });\n }), s.appendChild(a), this.sizeInputEl = a, this.contentContainer.appendChild(s);\n const o = h(\"div\", { class: \"area-input-row\" }), r = h(\"div\", { class: \"area-input-align\" });\n for (const d of W) {\n const c = h(\"button\", {\n class: `align-btn${e.align === d.value ? \" align-btn-active\" : \"\"}`,\n title: d.label === \"L\" ? \"Left\" : d.label === \"C\" ? \"Center\" : \"Right\"\n }, d.label);\n c.addEventListener(\"click\", (u) => {\n u.stopPropagation(), this.emit(\"text:change\", { areaId: this.area.id, updates: { align: d.value } }), r.querySelectorAll(\".align-btn\").forEach((p) => p.classList.remove(\"align-btn-active\")), c.classList.add(\"align-btn-active\");\n }), r.appendChild(c);\n }\n o.appendChild(r), this.alignGroupEl = r;\n const l = h(\"input\", {\n class: \"area-input-color\",\n type: \"color\"\n });\n l.value = e.color, l.addEventListener(\"input\", () => {\n this.emit(\"text:change\", { areaId: this.area.id, updates: { color: l.value } });\n }), o.appendChild(l), this.colorInputEl = l, this.contentContainer.appendChild(o);\n }\n renderImageControls() {\n const t = this.currentContent;\n if (t?.type === \"image\") {\n const e = h(\"div\", { class: \"area-image-preview\" }), i = h(\"img\", { class: \"area-image-thumb\" });\n i.src = t.dataUrl, i.alt = t.filename || \"Uploaded image\", e.appendChild(i);\n const s = h(\"div\", { class: \"area-image-info\" });\n s.appendChild(h(\"span\", { class: \"area-image-name\" }, t.filename || \"Image\"));\n const n = h(\"button\", { class: \"area-image-remove-btn\" }, \"Remove\");\n n.addEventListener(\"click\", (a) => {\n a.stopPropagation(), this.emit(\"clear\", { areaId: this.area.id });\n }), s.appendChild(n), e.appendChild(s), this.contentContainer.appendChild(e);\n } else {\n const e = h(\"button\", { class: \"area-upload-btn\" }, \"Upload Image\"), i = h(\"input\", { type: \"file\" });\n i.accept = L.join(\",\"), i.style.display = \"none\";\n const s = h(\"div\", { class: \"area-validation-error\" });\n s.style.display = \"none\", i.addEventListener(\"change\", () => {\n const n = i.files?.[0];\n if (!n) return;\n if (!L.includes(n.type)) {\n const o = \"Only PNG, JPEG, WebP, and SVG images are accepted\";\n s.textContent = o, s.style.display = \"block\", this.emit(\"validation:error\", { areaId: this.area.id, message: o }), i.value = \"\";\n return;\n }\n if (n.size > X) {\n const o = \"File must be smaller than 15MB\";\n s.textContent = o, s.style.display = \"block\", this.emit(\"validation:error\", { areaId: this.area.id, message: o }), i.value = \"\";\n return;\n }\n s.style.display = \"none\";\n const a = new FileReader();\n a.onload = () => {\n const o = a.result;\n this.emit(\"image:change\", { areaId: this.area.id, dataUrl: o, filename: n.name });\n }, a.readAsDataURL(n), i.value = \"\";\n }), e.addEventListener(\"click\", (n) => {\n n.stopPropagation(), i.click();\n }), this.contentContainer.appendChild(e), this.contentContainer.appendChild(i), this.contentContainer.appendChild(s);\n }\n }\n renderTransforms() {\n this.transformContainer.innerHTML = \"\";\n const t = this.currentContent;\n if (!this.isSelected || !t) return;\n const e = t.type === \"text\" ? this.area.textOptions?.allowPositioning : this.area.imageOptions?.allowPositioning, i = t.type === \"image\" && this.area.imageOptions?.allowScaling, s = t.type === \"image\" && this.area.imageOptions?.allowRotation;\n if (!e && !i && !s) return;\n const n = h(\"div\", { class: \"area-card-divider\" });\n this.transformContainer.appendChild(n);\n const a = h(\"div\", { class: \"transform-header\" });\n a.appendChild(h(\"span\", { class: \"transform-title\" }, \"Transform\"));\n const o = h(\"button\", { class: \"transform-reset-btn\" }, \"Reset\");\n o.addEventListener(\"click\", (l) => {\n l.stopPropagation(), e && this.emit(\"offset:change\", { areaId: this.area.id, offset: { x: 0, y: 0 } }), i && this.emit(\"scale:change\", { areaId: this.area.id, scale: 1 }), s && this.emit(\"rotation:change\", { areaId: this.area.id, rotation: 0 });\n }), a.appendChild(o), this.transformContainer.appendChild(a);\n const r = t.offset ?? { x: 0, y: 0 };\n if (e) {\n const l = h(\"div\", { class: \"area-input-row\" }), d = h(\"label\", { class: \"transform-label\" }, \"X\"), c = h(\"input\", { class: \"transform-input\", type: \"number\" });\n c.value = String(Math.round(r.x)), c.addEventListener(\"change\", () => {\n this.emit(\"offset:change\", {\n areaId: this.area.id,\n offset: { ...r, x: parseInt(c.value, 10) || 0 }\n });\n });\n const u = h(\"label\", { class: \"transform-label\" }, \"Y\"), p = h(\"input\", { class: \"transform-input\", type: \"number\" });\n p.value = String(Math.round(r.y)), p.addEventListener(\"change\", () => {\n this.emit(\"offset:change\", {\n areaId: this.area.id,\n offset: { ...r, y: parseInt(p.value, 10) || 0 }\n });\n }), l.appendChild(d), l.appendChild(c), l.appendChild(u), l.appendChild(p), this.transformContainer.appendChild(l);\n }\n if (i && t.type === \"image\") {\n const l = t.scale ?? 1, d = h(\"div\", { class: \"area-input-row transform-slider-row\" }), c = h(\"label\", { class: \"transform-label\" }, `Scale: ${Math.round(l * 100)}%`), u = h(\"input\", { class: \"transform-slider\", type: \"range\" });\n u.min = \"10\", u.max = \"500\", u.step = \"5\", u.value = String(Math.round(l * 100)), u.addEventListener(\"input\", () => {\n const p = parseInt(u.value, 10) / 100;\n c.textContent = `Scale: ${Math.round(p * 100)}%`, this.emit(\"scale:change\", { areaId: this.area.id, scale: p });\n }), d.appendChild(c), d.appendChild(u), this.transformContainer.appendChild(d);\n }\n if (s && t.type === \"image\") {\n const l = t.rotation ?? 0, d = h(\"div\", { class: \"area-input-row transform-slider-row\" }), c = h(\"label\", { class: \"transform-label\" }, `Rotation: ${Math.round(l)}°`), u = h(\"input\", { class: \"transform-slider\", type: \"range\" });\n u.min = \"0\", u.max = \"360\", u.step = \"1\", u.value = String(Math.round(l)), u.addEventListener(\"input\", () => {\n const p = parseInt(u.value, 10);\n c.textContent = `Rotation: ${p}°`, this.emit(\"rotation:change\", { areaId: this.area.id, rotation: p });\n }), d.appendChild(c), d.appendChild(u), this.transformContainer.appendChild(d);\n }\n }\n getElement() {\n return this.element;\n }\n}\nclass q extends I {\n constructor(t) {\n super(), this.cards = /* @__PURE__ */ new Map(), this.isMobile = !1, this.boundEscapeHandler = (s) => {\n s.key === \"Escape\" && this.emit(\"dismiss\", void 0);\n }, this.backdrop = h(\"div\", { class: \"area-panel-backdrop\" }), this.backdrop.addEventListener(\"click\", () => {\n this.emit(\"dismiss\", void 0);\n }), this.element = h(\"div\", { class: \"area-panel\" });\n const e = h(\"div\", { class: \"area-panel-header\" });\n e.appendChild(h(\"span\", { class: \"area-panel-title\" }, \"Customize\"));\n const i = h(\"button\", { class: \"area-panel-close-btn\", title: \"Close\" }, \"×\");\n if (i.addEventListener(\"click\", () => {\n this.emit(\"dismiss\", void 0);\n }), e.appendChild(i), this.element.appendChild(e), this.panelContent = h(\"div\", { class: \"area-panel-content\" }), t.length === 0) {\n const s = h(\"p\", { class: \"area-panel-empty\" }, \"No customization areas defined.\");\n this.panelContent.appendChild(s);\n } else\n for (const s of t) {\n const n = new R(s);\n this.cards.set(s.id, n), n.on(\"text:change\", (a) => this.emit(\"text:change\", a)), n.on(\"image:change\", (a) => this.emit(\"image:change\", a)), n.on(\"clear\", (a) => this.emit(\"clear\", a)), n.on(\"select\", (a) => this.emit(\"select\", a)), n.on(\"offset:change\", (a) => this.emit(\"offset:change\", a)), n.on(\"scale:change\", (a) => this.emit(\"scale:change\", a)), n.on(\"rotation:change\", (a) => this.emit(\"rotation:change\", a)), n.on(\"validation:error\", (a) => this.emit(\"validation:error\", a)), this.panelContent.appendChild(n.getElement());\n }\n this.element.appendChild(this.panelContent);\n }\n setAreas(t) {\n if (this.cards.clear(), this.panelContent.innerHTML = \"\", t.length === 0) {\n const e = h(\"p\", { class: \"area-panel-empty\" }, \"No customization areas defined.\");\n this.panelContent.appendChild(e);\n } else\n for (const e of t) {\n const i = new R(e);\n this.cards.set(e.id, i), i.on(\"text:change\", (s) => this.emit(\"text:change\", s)), i.on(\"image:change\", (s) => this.emit(\"image:change\", s)), i.on(\"clear\", (s) => this.emit(\"clear\", s)), i.on(\"select\", (s) => this.emit(\"select\", s)), i.on(\"offset:change\", (s) => this.emit(\"offset:change\", s)), i.on(\"scale:change\", (s) => this.emit(\"scale:change\", s)), i.on(\"rotation:change\", (s) => this.emit(\"rotation:change\", s)), i.on(\"validation:error\", (s) => this.emit(\"validation:error\", s)), this.panelContent.appendChild(i.getElement());\n }\n }\n setContents(t) {\n for (const [e, i] of this.cards)\n i.setContent(t.get(e));\n }\n setSelectedArea(t) {\n for (const [e, i] of this.cards) {\n const s = e === t;\n i.setSelected(s), i.getElement().style.display = s ? \"\" : \"none\";\n }\n t ? (this.element.classList.add(\"area-panel-visible\"), this.isMobile && this.backdrop.classList.add(\"area-panel-backdrop-visible\"), document.addEventListener(\"keydown\", this.boundEscapeHandler)) : (this.element.classList.remove(\"area-panel-visible\"), this.isMobile && this.backdrop.classList.remove(\"area-panel-backdrop-visible\"), document.removeEventListener(\"keydown\", this.boundEscapeHandler));\n }\n setMobile(t) {\n this.isMobile = t, this.element.classList.toggle(\"area-panel-mobile\", t), t || (this.element.classList.remove(\"area-panel-visible\"), this.backdrop.classList.remove(\"area-panel-backdrop-visible\"));\n }\n getElement() {\n return this.element;\n }\n getBackdrop() {\n return this.backdrop;\n }\n}\nclass G {\n constructor(t = window) {\n this.target = t, this.commands = [], this.isEnabled = !0, this.handleKeyDown = (e) => {\n if (!this.isEnabled) return;\n const i = e.target;\n if (!(i.tagName === \"INPUT\" || i.tagName === \"TEXTAREA\" || i.isContentEditable)) {\n for (const s of this.commands)\n if (this.matchesCommand(e, s)) {\n e.preventDefault(), s.handler(e);\n break;\n }\n }\n }, this.target.addEventListener(\"keydown\", this.handleKeyDown);\n }\n /**\n * Register a keyboard command\n */\n register(t) {\n return this.commands.push(t), () => {\n const e = this.commands.indexOf(t);\n e !== -1 && this.commands.splice(e, 1);\n };\n }\n /**\n * Enable keyboard handling\n */\n enable() {\n this.isEnabled = !0;\n }\n /**\n * Disable keyboard handling\n */\n disable() {\n this.isEnabled = !1;\n }\n /**\n * Check if keyboard handling is enabled\n */\n isActive() {\n return this.isEnabled;\n }\n /**\n * Check if event matches a command\n */\n matchesCommand(t, e) {\n return !(t.key.toLowerCase() !== e.key.toLowerCase() || e.ctrl !== void 0 && e.ctrl !== t.ctrlKey || e.shift !== void 0 && e.shift !== t.shiftKey || e.alt !== void 0 && e.alt !== t.altKey || e.meta !== void 0 && e.meta !== t.metaKey);\n }\n /**\n * Cleanup\n */\n destroy() {\n this.target.removeEventListener(\"keydown\", this.handleKeyDown), this.commands = [];\n }\n}\nfunction j() {\n return /Mac|iPod|iPhone|iPad/.test(navigator.platform);\n}\nfunction J() {\n return j() ? \"meta\" : \"ctrl\";\n}\nfunction K(f, t, e, i) {\n const s = f / e, n = t / i;\n return Math.min(s, n);\n}\nfunction _(f, t, e = 8, i = 10, s = 300) {\n const n = K(f, t, e, i), a = n >= s;\n return {\n actualDPI: Math.round(n),\n targetDPI: s,\n width: f,\n height: t,\n passed: a,\n warning: a ? void 0 : `Image resolution is ${Math.round(n)} DPI at 100% scale. For best print quality, use images with at least ${s} DPI. This may result in pixelated or blurry prints.`\n };\n}\nconst k = ':host{--editor-bg: #f3f4f6;--editor-surface: #ffffff;--editor-border: #e5e7eb;--editor-text: #111827;--editor-text-muted: #6b7280;--editor-primary: #3b82f6;--editor-primary-hover: #2563eb;--editor-danger: #ef4444;--editor-radius: 8px;--editor-radius-sm: 4px;--editor-font: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;--editor-panel-width: 280px;display:block;width:100%;height:100%;font-family:var(--editor-font);font-size:13px;color:var(--editor-text);line-height:1.4}:host([theme=\"dark\"]){--editor-bg: #1f2937;--editor-surface: #374151;--editor-border: #4b5563;--editor-text: #f9fafb;--editor-text-muted: #9ca3af}.editor-container{display:flex;flex-direction:column;width:100%;height:100%;position:relative;overflow:hidden;background:var(--editor-bg)}.layout-desktop .editor-main{display:flex;flex:1;min-height:0}.layout-desktop .canvas-area{flex:1;min-width:0;position:relative;display:flex;flex-direction:column}.layout-desktop .area-panel{width:var(--editor-panel-width);border-left:1px solid var(--editor-border);background:var(--editor-surface);display:none;flex-direction:column;overflow:hidden}.layout-desktop .area-panel.area-panel-visible{display:flex}.layout-mobile .editor-main{display:flex;flex-direction:column;flex:1;min-height:0}.layout-mobile .canvas-area{flex:1;position:relative;display:flex;flex-direction:column;min-height:0}.layout-mobile .area-panel{position:absolute;bottom:0;left:0;right:0;max-height:50%;background:var(--editor-surface);border-top:1px solid var(--editor-border);border-radius:var(--editor-radius) var(--editor-radius) 0 0;box-shadow:0 -4px 20px #00000026;transform:translateY(100%);transition:transform .25s ease-out;z-index:20;display:flex;flex-direction:column;overflow:hidden}.layout-mobile .area-panel.area-panel-visible{transform:translateY(0)}.area-panel-backdrop{display:none}.layout-mobile .area-panel-backdrop{display:block;position:absolute;inset:0;background:#0000004d;z-index:15;opacity:0;pointer-events:none;transition:opacity .25s ease-out}.layout-mobile .area-panel-backdrop.area-panel-backdrop-visible{opacity:1;pointer-events:auto}.zoom-toolbar{display:flex;align-items:center;gap:4px;padding:8px 12px;background:var(--editor-surface);border-bottom:1px solid var(--editor-border)}.zoom-btn{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:14px;font-family:var(--editor-font);transition:background .15s;-webkit-tap-highlight-color:transparent;touch-action:manipulation}.zoom-btn:hover{background:var(--editor-bg)}.zoom-btn:active{background:var(--editor-border)}.zoom-percent{margin-left:8px;font-size:12px;color:var(--editor-text-muted);min-width:40px}.view-select{margin-left:8px;padding:4px 8px;height:32px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);font-family:var(--editor-font);font-size:12px;cursor:pointer;-webkit-tap-highlight-color:transparent}.view-select:hover{background:var(--editor-bg)}.view-select:focus{outline:2px solid var(--editor-primary);outline-offset:-1px}.zoom-toolbar-spacer{flex:1}.zoom-close-btn{width:auto;padding:0 12px;font-size:13px;gap:4px}.zoom-save-btn{width:auto;padding:0 16px;margin-left:8px;font-size:13px;font-weight:600;background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.zoom-save-btn:hover{background:var(--editor-primary-hover)}.zoom-save-btn:disabled{opacity:.5;cursor:not-allowed}.canvas-wrapper{flex:1;position:relative;overflow:hidden;min-height:200px}.editor-canvas{position:absolute;top:0;left:0}.area-panel-header{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid var(--editor-border);flex-shrink:0}.area-panel-title{font-weight:600;font-size:14px}.area-panel-close-btn{width:28px;height:28px;border:none;background:none;color:var(--editor-text-muted);cursor:pointer;font-size:18px;line-height:1;border-radius:var(--editor-radius-sm);display:flex;align-items:center;justify-content:center}.area-panel-close-btn:hover{background:var(--editor-bg);color:var(--editor-text)}.area-panel-content{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:12px}.area-panel-empty{color:var(--editor-text-muted);font-size:12px;text-align:center;padding:20px 0}.area-card{padding:12px;border:1px solid var(--editor-border);border-radius:var(--editor-radius);background:var(--editor-surface);cursor:pointer;transition:border-color .15s}.area-card:hover{border-color:var(--editor-primary)}.area-card-selected{border-color:var(--editor-primary);box-shadow:0 0 0 1px var(--editor-primary)}.area-card-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}.area-card-name-row{display:flex;align-items:center;gap:6px}.area-card-name{font-weight:600;font-size:13px}.area-card-badge{display:inline-block;padding:1px 6px;font-size:10px;font-weight:500;background:#fef3c7;color:#92400e;border-radius:10px}.area-card-reset-btn{padding:2px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-text-muted);cursor:pointer;font-size:11px;font-family:var(--editor-font)}.area-card-reset-btn:hover{background:var(--editor-bg);color:var(--editor-danger);border-color:var(--editor-danger)}.area-card-mode-switcher{display:flex;gap:4px;margin-bottom:8px}.mode-btn{flex:1;padding:4px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:12px;font-family:var(--editor-font);transition:all .15s}.mode-btn-active{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.area-input-text{width:100%;padding:6px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:13px;color:var(--editor-text);background:var(--editor-surface);box-sizing:border-box;margin-bottom:6px}.area-input-text:focus{outline:none;border-color:var(--editor-primary);box-shadow:0 0 0 1px var(--editor-primary)}.area-input-row{display:flex;gap:6px;align-items:center;margin-bottom:6px}.area-input-font{flex:1;padding:4px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface);min-width:0}.area-input-size{width:56px;padding:4px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface)}.area-input-align{display:flex;gap:2px}.align-btn{width:28px;height:28px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:var(--editor-surface);color:var(--editor-text);cursor:pointer;font-size:12px;font-weight:600;font-family:var(--editor-font)}.align-btn-active{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.area-input-color{width:32px;height:28px;padding:0;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);cursor:pointer;background:none}.area-upload-btn{width:100%;padding:10px;border:2px dashed var(--editor-border);border-radius:var(--editor-radius);background:var(--editor-bg);color:var(--editor-text-muted);cursor:pointer;font-family:var(--editor-font);font-size:12px;text-align:center;transition:all .15s;min-height:44px}.area-upload-btn:hover{border-color:var(--editor-primary);color:var(--editor-primary)}.area-image-preview{display:flex;gap:8px;align-items:center}.area-image-thumb{width:48px;height:48px;object-fit:cover;border-radius:var(--editor-radius-sm);border:1px solid var(--editor-border)}.area-image-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px}.area-image-name{font-size:12px;color:var(--editor-text-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.area-image-remove-btn{padding:2px 8px;border:1px solid var(--editor-danger);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-danger);cursor:pointer;font-size:11px;font-family:var(--editor-font);width:fit-content}.area-image-remove-btn:hover{background:#fef2f2}.area-card-divider{height:1px;background:var(--editor-border);margin:8px 0}.transform-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px}.transform-title{font-weight:600;font-size:12px}.transform-reset-btn{padding:2px 8px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);background:none;color:var(--editor-text-muted);cursor:pointer;font-size:11px;font-family:var(--editor-font)}.transform-reset-btn:hover{background:var(--editor-bg)}.transform-label{font-size:11px;color:var(--editor-text-muted);white-space:nowrap}.transform-input{width:60px;padding:3px 6px;border:1px solid var(--editor-border);border-radius:var(--editor-radius-sm);font-family:var(--editor-font);font-size:12px;color:var(--editor-text);background:var(--editor-surface)}.transform-slider-row{flex-direction:column;align-items:stretch}.transform-slider{width:100%;accent-color:var(--editor-primary)}.loading-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;min-height:200px}.loading-spinner{width:32px;height:32px;border:3px solid var(--editor-border);border-top-color:var(--editor-primary);border-radius:50%;animation:spin .8s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.error-container{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%;min-height:200px;padding:20px;text-align:center}.error-title{font-weight:600;font-size:16px;color:var(--editor-danger);margin-bottom:8px}.error-message{font-size:13px;color:var(--editor-text-muted);max-width:400px;white-space:pre-wrap}:host(:focus){outline:2px solid var(--editor-primary);outline-offset:-2px}input:focus,select:focus,button:focus-visible{outline:2px solid var(--editor-primary);outline-offset:-1px}.context-menu{position:absolute;z-index:100;min-width:160px;background:var(--editor-surface);border:1px solid var(--editor-border);border-radius:var(--editor-radius);box-shadow:0 4px 12px #00000026;padding:4px 0;font-size:13px}.context-menu-header{padding:6px 12px;font-weight:600;font-size:12px;color:var(--editor-text-muted);user-select:none}.context-menu-divider{height:1px;background:var(--editor-border);margin:4px 0}.context-menu-item{padding:6px 12px;cursor:pointer;color:var(--editor-text);user-select:none;transition:background .1s}.context-menu-item:hover{background:var(--editor-bg)}.context-menu-item:active{background:var(--editor-border)}.context-menu-item-disabled{color:var(--editor-text-muted);cursor:default;pointer-events:none}.editor-toast{position:absolute;top:16px;left:50%;transform:translate(-50%);padding:10px 20px;border-radius:var(--editor-radius);font-size:13px;font-family:var(--editor-font);line-height:1.4;z-index:200;max-width:400px;text-align:center;animation:toast-in .25s ease-out,toast-out .25s ease-in forwards;animation-delay:0s,var(--toast-duration, 3.75s);pointer-events:none;box-shadow:0 4px 12px #00000026}.editor-toast-warning{background:#fef3c7;color:#92400e;border:1px solid #f59e0b}.editor-toast-error{background:#fef2f2;color:#991b1b;border:1px solid var(--editor-danger)}.editor-toast-info{background:#eff6ff;color:#1e40af;border:1px solid var(--editor-primary)}@keyframes toast-in{0%{opacity:0;transform:translate(-50%) translateY(-10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}@keyframes toast-out{0%{opacity:1;transform:translate(-50%) translateY(0)}to{opacity:0;transform:translate(-50%) translateY(-10px)}}.editor-modal-overlay{position:absolute;inset:0;background:#0006;z-index:300;display:flex;align-items:center;justify-content:center;animation:modal-overlay-in .2s ease-out}@keyframes modal-overlay-in{0%{opacity:0}to{opacity:1}}.editor-modal{background:var(--editor-surface);border-radius:var(--editor-radius);box-shadow:0 8px 32px #0003;max-width:380px;width:calc(100% - 32px);padding:20px;animation:modal-in .2s ease-out}@keyframes modal-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.editor-modal-title{font-weight:600;font-size:15px;margin-bottom:8px;color:var(--editor-text)}.editor-modal-body{font-size:13px;color:var(--editor-text-muted);margin-bottom:16px;line-height:1.5}.editor-modal-actions{display:flex;justify-content:flex-end;gap:8px}.editor-modal-btn{padding:8px 16px;border-radius:var(--editor-radius-sm);font-size:13px;font-family:var(--editor-font);cursor:pointer;border:1px solid var(--editor-border);background:var(--editor-surface);color:var(--editor-text);transition:background .15s}.editor-modal-btn:hover{background:var(--editor-bg)}.editor-modal-btn-primary{background:var(--editor-primary);color:#fff;border-color:var(--editor-primary)}.editor-modal-btn-primary:hover{background:var(--editor-primary-hover)}.area-validation-error{font-size:11px;color:var(--editor-danger);margin-top:4px}@media(pointer:coarse){.zoom-btn{min-width:44px;min-height:44px}.area-input-text,.area-input-font,.area-input-size{min-height:44px;font-size:16px}.align-btn{min-width:44px;min-height:44px}.area-upload-btn{min-height:48px}.view-select{min-height:44px;font-size:16px}}', Q = \"2.0.0\", tt = 768;\nclass et extends HTMLElement {\n constructor() {\n super(), this.resizeObserver = null, this.isReady = !1, this.currentTemplate = null, this.loadingTemplateId = null, this.isMobileLayout = !1, this.productViews = [], this.activeViewName = null, this.perViewContents = /* @__PURE__ */ new Map(), this.subscriptions = [], this.storageUsage = null, this.storageUsageLastRefresh = 0, this.emitChange = $(() => {\n this.dispatchEvent(\n new CustomEvent(\"change\", {\n detail: { design: this.getDesign() },\n bubbles: !0,\n composed: !0\n })\n );\n }, 300), this.shadow = this.attachShadow({ mode: \"open\" });\n }\n static get observedAttributes() {\n return [\"template-id\", \"product-id\", \"theme\", \"mode\", \"store-id\", \"api-url\"];\n }\n async connectedCallback() {\n try {\n this.hasAttribute(\"tabindex\") || this.setAttribute(\"tabindex\", \"0\"), this.renderLoading(), await this.initialize();\n } catch (t) {\n this.showError(\"Failed to initialize editor\", t);\n }\n }\n disconnectedCallback() {\n this.cleanup();\n }\n attributeChangedCallback(t, e, i) {\n e !== i && (t === \"template-id\" && this.isReady && i && this.loadTemplate(i), t === \"product-id\" && this.isReady && i && this.loadProduct(i));\n }\n // ─── Public API ───\n getDesign() {\n if (!this.currentTemplate) throw new Error(\"No design loaded\");\n return {\n templateId: this.currentTemplate.metadata.id,\n engineVersion: Q,\n contents: this.contentManager.toJSON(),\n userData: {}\n };\n }\n setDesign(t) {\n if (t.templateId !== this.currentTemplate?.metadata.id)\n throw new Error(\"Design template ID does not match current template\");\n this.contentManager.fromJSON(t.contents), this.syncEngineContents(), this.stateManager.setState({\n contents: this.contentManager.toJSON(),\n isDirty: !0\n });\n }\n undo() {\n this.stateManager.undo() && this.syncFromState();\n }\n redo() {\n this.stateManager.redo() && this.syncFromState();\n }\n clear() {\n this.contentManager.reset(), this.syncEngineContents(), this.stateManager.setState({\n contents: this.contentManager.toJSON(),\n selectedAreaId: null,\n isDirty: !1\n }), this.zoomToolbar?.showSaveButton(!1), this.engine.setSelectedArea(null), this.inputPanel.setSelectedArea(null), this.engine.fitToView(), this.stateManager.update({\n zoom: this.engine.getZoom(),\n pan: this.engine.getPan()\n });\n }\n selectArea(t) {\n this.handleAreaSelect(t);\n }\n getSelectedAreaId() {\n return this.stateManager.getState().selectedAreaId;\n }\n getActiveView() {\n return this.activeViewName;\n }\n getViews() {\n return this.productViews.map((t) => ({\n viewName: t.viewName,\n viewOrder: t.viewOrder,\n isRequired: t.isRequired,\n isDefault: t.isDefault,\n templateId: t.template.id\n }));\n }\n setActiveView(t) {\n if (this.activeViewName === t) return;\n const e = this.productViews.find((i) => i.viewName === t);\n if (!e) throw new Error(`View not found: ${t}`);\n this.switchToView(e);\n }\n setAreaContent(t, e) {\n e.type === \"text\" ? this.contentManager.setTextContent(t, e) : this.contentManager.setImageContent(t, e.dataUrl, e.filename), this.syncEngineContents(), this.saveContentState();\n }\n getAreaContent(t) {\n return this.contentManager.getContent(t);\n }\n async finalize() {\n const t = this.engine.checkSafeAreaViolations();\n if (t.length > 0) {\n const n = this.currentTemplate?.areas || [], a = t.map((r) => n.find((l) => l.id === r)?.name || r).join(\", \");\n if (!await this.showConfirmation(\n \"Content outside safe area\",\n `Content in ${a} extends beyond the safe area. It may be trimmed during printing. Continue?`,\n \"Cancel\",\n \"Proceed Anyway\"\n ))\n throw new Error(\"Finalization cancelled by user\");\n }\n const e = this.getDesign(), i = this.getAttribute(\"store-id\") || \"demo-shop\", s = await this.apiClient.finalizeDesign(i, e);\n return this.dispatchEvent(\n new CustomEvent(\"customizer:finalize\", {\n detail: {\n designId: s.designId,\n proofUrl: s.proofUrl,\n templateId: e.templateId,\n designJson: e,\n status: s.status\n },\n bubbles: !0,\n composed: !0\n })\n ), s;\n }\n // ─── Initialization ───\n renderLoading() {\n const t = document.createElement(\"style\");\n t.textContent = k, this.shadow.appendChild(t);\n const e = h(\n \"div\",\n { class: \"loading-container\" },\n h(\"div\", { class: \"loading-spinner\" })\n );\n this.shadow.appendChild(e);\n }\n async initialize() {\n const t = this.getAttribute(\"api-url\") || \"http://localhost:4000\";\n this.apiClient = new Z(`${t.replace(/\\/+$/, \"\")}/public`);\n const e = this.getAttribute(\"product-id\"), i = this.getAttribute(\"template-id\");\n if (!e && !i)\n throw new Error(\"Either template-id or product-id attribute is required\");\n e ? await this.loadProduct(e) : await this.loadTemplate(i), this.isReady = !0, this.dispatchEvent(new CustomEvent(\"ready\", { bubbles: !0, composed: !0 }));\n }\n async loadTemplate(t) {\n if (this.loadingTemplateId !== t) {\n this.loadingTemplateId = t;\n try {\n const e = await this.apiClient.getTemplate(t);\n if (this.loadingTemplateId !== t) return;\n await this.loadTemplateData(e), this.loadingTemplateId = null;\n } catch (e) {\n throw this.loadingTemplateId = null, new Error(`Failed to load template: ${e.message}`);\n }\n }\n }\n async loadTemplateData(t) {\n this.currentTemplate = t;\n const e = t.areas || [];\n this.contentManager = new A(e);\n const i = {\n template: t,\n contents: this.contentManager.toJSON(),\n selectedAreaId: null,\n zoom: 1,\n pan: { x: 0, y: 0 },\n isDirty: !1,\n warnings: []\n };\n this.stateManager = new B(i), this.buildUI(t, e), this.engine = new N(this.canvas), this.engine.setArtboard({\n width: t.artboard.width,\n height: t.artboard.height,\n backgroundColor: t.artboard.backgroundColor ?? \"#ffffff\"\n }), this.engine.setAreas(e), this.engine.setContents(this.contentManager.getContents()), t.backgroundImage && this.engine.setBackgroundImage(t.backgroundImage);\n const s = t.artboard.safeArea ?? t.safeArea;\n s && this.engine.setSafeArea(s), this.engine.start(), this.engine.fitToView(), this.stateManager.update({\n zoom: this.engine.getZoom(),\n pan: this.engine.getPan()\n }), this.zoomToolbar.setZoom(this.engine.getZoom()), this.interaction = new F(\n this.canvas,\n this.engine,\n () => this.contentManager.getContents(),\n () => this.stateManager.getState().selectedAreaId\n ), this.wireInteractionEvents(), this.subscriptions.push(\n this.contentManager.subscribe(() => {\n this.syncEngineContents(), this.inputPanel.setContents(this.contentManager.getContents());\n })\n ), this.keyboard = new G(this), this.setupKeyboardShortcuts(), this.inputPanel.setContents(this.contentManager.getContents());\n const n = this.getAttribute(\"store-id\");\n n && this.apiClient.getStorageUsage(n).then((a) => {\n this.storageUsage = a, a.usagePercent >= 100 ? this.showToast(\"Storage quota exceeded. Upgrade your plan for more storage.\", \"error\") : a.usagePercent >= 80 && this.showToast(`Storage ${a.usagePercent}% full. Consider upgrading your plan.`, \"warning\");\n }).catch(() => {\n });\n }\n async loadProduct(t) {\n try {\n const e = await this.apiClient.getProduct(t);\n if (e.views.length === 0)\n throw new Error(\"Product has no active templates\");\n this.productViews = e.views, this.perViewContents.clear();\n const i = e.views.find((s) => s.isDefault) || e.views[0];\n await this.loadTemplateData(i.template.templateJson), this.activeViewName = i.viewName, this.zoomToolbar && e.views.length > 1 && (this.zoomToolbar.setViews(this.getViews()), this.zoomToolbar.setActiveView(i.viewName));\n } catch (e) {\n throw new Error(`Failed to load product: ${e.message}`);\n }\n }\n switchToView(t) {\n this.activeViewName && this.contentManager && this.perViewContents.set(this.activeViewName, this.contentManager.toJSON()), this.activeViewName = t.viewName, this.zoomToolbar?.setActiveView(t.viewName);\n const e = t.template.templateJson;\n this.currentTemplate = e;\n const i = e.areas || [];\n this.contentManager = new A(i);\n const s = this.perViewContents.get(t.viewName);\n s && this.contentManager.fromJSON(s), this.engine.setArtboard({\n width: e.artboard.width,\n height: e.artboard.height,\n backgroundColor: e.artboard.backgroundColor ?? \"#ffffff\"\n }), this.engine.setAreas(i), this.engine.setContents(this.contentManager.getContents()), this.engine.setBackgroundImage(e.backgroundImage ?? void 0);\n const n = e.artboard.safeArea ?? e.safeArea;\n this.engine.setSafeArea(n ?? null), this.engine.fitToView(), this.stateManager.setState({\n template: e,\n contents: this.contentManager.toJSON(),\n selectedAreaId: null,\n isDirty: this.stateManager.getState().isDirty,\n zoom: this.engine.getZoom(),\n pan: this.engine.getPan(),\n warnings: []\n }), this.zoomToolbar.setZoom(this.engine.getZoom()), this.inputPanel.setAreas(i), this.inputPanel.setContents(this.contentManager.getContents()), this.inputPanel.setSelectedArea(null), this.engine.setSelectedArea(null), this.dispatchEvent(\n new CustomEvent(\"view-change\", {\n detail: { viewName: t.viewName },\n bubbles: !0,\n composed: !0\n })\n );\n }\n buildUI(t, e) {\n this.shadow.innerHTML = \"\";\n const i = document.createElement(\"style\");\n i.textContent = k, this.shadow.appendChild(i), this.container = h(\"div\", { class: \"editor-container\" }), this.zoomToolbar = new V(), this.subscriptions.push(this.zoomToolbar.on(\"zoom-in\", () => this.handleZoomIn())), this.subscriptions.push(this.zoomToolbar.on(\"zoom-out\", () => this.handleZoomOut())), this.subscriptions.push(this.zoomToolbar.on(\"zoom-fit\", () => this.handleZoomFit())), this.subscriptions.push(this.zoomToolbar.on(\"view-change\", ({ viewName: a }) => {\n const o = this.productViews.find((r) => r.viewName === a);\n o && this.switchToView(o);\n })), this.subscriptions.push(this.zoomToolbar.on(\"close\", () => {\n this.dispatchEvent(new CustomEvent(\"customizer:close\", {\n bubbles: !0,\n composed: !0\n }));\n })), this.subscriptions.push(this.zoomToolbar.on(\"save\", async () => {\n this.zoomToolbar.setSaveDisabled(!0, \"Saving...\");\n try {\n await this.finalize(), this.zoomToolbar.setSaveDisabled(!0, \"Saved!\"), this.showToast(\"Design saved successfully!\", \"info\"), setTimeout(() => {\n this.zoomToolbar.setSaveDisabled(!1, \"Save Customization\"), this.zoomToolbar.showSaveButton(!1), this.stateManager.update({ isDirty: !1 });\n }, 2e3);\n } catch (a) {\n console.error(\"Customizer: finalize failed\", a);\n const o = a instanceof Error ? a.message : \"Save failed. Please try again.\";\n this.showToast(o, \"error\"), this.zoomToolbar.setSaveDisabled(!1, \"Save Customization\");\n }\n }));\n const s = h(\"div\", { class: \"canvas-area\" });\n s.appendChild(this.zoomToolbar.getElement()), this.canvasWrapper = h(\"div\", { class: \"canvas-wrapper\" }), this.canvas = document.createElement(\"canvas\"), this.canvas.className = \"editor-canvas\", this.canvasWrapper.appendChild(this.canvas), s.appendChild(this.canvasWrapper), this.inputPanel = new q(e), this.wireInputPanelEvents();\n const n = h(\"div\", { class: \"editor-main\" });\n n.appendChild(s), n.appendChild(this.inputPanel.getBackdrop()), n.appendChild(this.inputPanel.getElement()), this.container.appendChild(n), this.shadow.appendChild(this.container), this.resizeObserver = new ResizeObserver((a) => {\n for (const o of a)\n o.target === this.canvasWrapper && this.handleCanvasResize(o.contentRect), o.target === this.container && this.handleLayoutResize(o.contentRect);\n }), this.resizeObserver.observe(this.canvasWrapper), this.resizeObserver.observe(this.container);\n }\n // ─── Event Wiring ───\n wireInteractionEvents() {\n this.subscriptions.push(\n this.interaction.on(\"area:select\", ({ areaId: t }) => {\n this.handleAreaSelect(t);\n })\n ), this.subscriptions.push(\n this.interaction.on(\"content:drag\", ({ areaId: t, offset: e }) => {\n this.contentManager.setContentOffset(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.interaction.on(\"content:scale\", ({ areaId: t, scale: e }) => {\n this.contentManager.setImageScale(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.interaction.on(\"content:rotate\", ({ areaId: t, rotation: e }) => {\n this.contentManager.setImageRotation(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.interaction.on(\"zoom\", ({ zoom: t }) => {\n this.engine.setZoom(t);\n const e = this.engine.getCenteredPan(t);\n e && this.engine.setPan(e), this.stateManager.update({ zoom: this.engine.getZoom(), pan: this.engine.getPan() }), this.zoomToolbar.setZoom(this.engine.getZoom());\n })\n ), this.subscriptions.push(\n this.interaction.on(\"pan\", ({ pan: t }) => {\n this.engine.setPan(t), this.stateManager.update({ pan: t });\n })\n ), this.subscriptions.push(\n this.interaction.on(\"cursor\", ({ cursor: t }) => {\n this.canvas.style.cursor = t;\n })\n ), this.subscriptions.push(\n this.interaction.on(\"context-menu\", ({ areaId: t, clientX: e, clientY: i }) => {\n this.handleContextMenu(t, e, i);\n })\n );\n }\n wireInputPanelEvents() {\n this.subscriptions.push(\n this.inputPanel.on(\"text:change\", ({ areaId: t, updates: e }) => {\n this.contentManager.setTextContent(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"image:change\", async ({ areaId: t, dataUrl: e, filename: i }) => {\n const s = this.contentManager.getContents();\n let n = 0;\n for (const [o, r] of s)\n r.type === \"image\" && o !== t && n++;\n if (n >= 10) {\n this.showToast(\"Maximum of 10 images per design reached\", \"error\");\n return;\n }\n if (await this.refreshStorageUsage(), this.storageUsage && this.storageUsage.usagePercent >= 100) {\n this.showToast(\"Storage quota exceeded. Upgrade your plan for more storage.\", \"error\");\n return;\n }\n const a = this.currentTemplate?.areas.find((o) => o.id === t);\n if (a && this.currentTemplate) {\n const o = this.currentTemplate.print.targetDpi;\n try {\n const r = new Image(), l = await new Promise((p, g) => {\n r.onload = () => p({ width: r.naturalWidth, height: r.naturalHeight }), r.onerror = () => g(new Error(\"Failed to load image\")), r.src = e;\n }), d = a.location.width / o, c = a.location.height / o, u = _(\n l.width,\n l.height,\n d,\n c,\n o\n );\n if (u.actualDPI < 150) {\n if (!await this.showConfirmation(\n \"Low resolution detected\",\n `This image is ${u.actualDPI} DPI at print size. Print may appear blurry. Recommended: ${o} DPI.`,\n \"Cancel\",\n \"Use Anyway\"\n )) return;\n } else u.actualDPI < o && (this.showToast(\n `Image resolution is ${u.actualDPI} DPI (${o} recommended)`,\n \"warning\"\n ), this.stateManager.update({\n warnings: [\n ...this.stateManager.getState().warnings,\n { type: \"dpi\", message: `${u.actualDPI} DPI`, areaId: t }\n ]\n }));\n } catch {\n }\n }\n if (this.contentManager.setImageContent(t, e, i), this.saveContentState(), this.storageUsage) {\n const o = Math.round(e.length * 0.75);\n this.storageUsage.storageUsed += o, this.storageUsage.usagePercent = this.storageUsage.storageQuota > 0 ? Math.round(this.storageUsage.storageUsed / this.storageUsage.storageQuota * 100) : 0;\n }\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"validation:error\", ({ message: t }) => {\n this.showToast(t, \"error\");\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"clear\", ({ areaId: t }) => {\n this.contentManager.clearContent(t), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"select\", ({ areaId: t }) => {\n this.handleAreaSelect(t);\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"offset:change\", ({ areaId: t, offset: e }) => {\n this.contentManager.setContentOffset(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"scale:change\", ({ areaId: t, scale: e }) => {\n this.contentManager.setImageScale(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"rotation:change\", ({ areaId: t, rotation: e }) => {\n this.contentManager.setImageRotation(t, e), this.saveContentState();\n })\n ), this.subscriptions.push(\n this.inputPanel.on(\"dismiss\", () => {\n this.handleAreaSelect(null);\n })\n );\n }\n // ─── Handlers ───\n handleAreaSelect(t, e = !1) {\n this.stateManager.update({ selectedAreaId: t }), this.engine.setSelectedArea(t), this.inputPanel.setSelectedArea(e ? t : null), t && document.activeElement !== this && this.focus(), this.dispatchEvent(\n new CustomEvent(\"area:select\", {\n detail: { areaId: t },\n bubbles: !0,\n composed: !0\n })\n );\n }\n handleContextMenu(t, e, i) {\n this.handleAreaSelect(t, !!t);\n }\n handleZoomIn() {\n const t = this.engine.getZoom(), e = Math.min(t * 1.25, 5), i = this.engine.getCenteredPan(e);\n this.engine.setZoom(e), i && this.engine.setPan(i), this.stateManager.update({ zoom: this.engine.getZoom(), pan: this.engine.getPan() }), this.zoomToolbar.setZoom(this.engine.getZoom());\n }\n handleZoomOut() {\n const t = this.engine.getZoom(), e = Math.max(t * 0.8, 0.1), i = this.engine.getCenteredPan(e);\n this.engine.setZoom(e), i && this.engine.setPan(i), this.stateManager.update({ zoom: this.engine.getZoom(), pan: this.engine.getPan() }), this.zoomToolbar.setZoom(this.engine.getZoom());\n }\n handleZoomFit() {\n this.engine.fitToView(), this.stateManager.update({ zoom: this.engine.getZoom(), pan: this.engine.getPan() }), this.zoomToolbar.setZoom(this.engine.getZoom());\n }\n handleCanvasResize(t) {\n const { width: e, height: i } = t;\n if (e === 0 || i === 0) return;\n const s = window.devicePixelRatio || 1;\n this.canvas.width = e * s, this.canvas.height = i * s, this.canvas.style.width = `${e}px`, this.canvas.style.height = `${i}px`, this.engine && (this.engine.fitToView(), this.stateManager.update({ zoom: this.engine.getZoom(), pan: this.engine.getPan() }), this.zoomToolbar.setZoom(this.engine.getZoom()));\n }\n handleLayoutResize(t) {\n const e = t.width < tt;\n this.container.classList.toggle(\"layout-desktop\", !e), this.container.classList.toggle(\"layout-mobile\", e), e !== this.isMobileLayout && (this.isMobileLayout = e, this.inputPanel.setMobile(e));\n }\n // ─── State Management ───\n async refreshStorageUsage() {\n if (Date.now() - this.storageUsageLastRefresh < 3e4) return;\n const t = this.getAttribute(\"store-id\");\n if (t)\n try {\n this.storageUsage = await this.apiClient.getStorageUsage(t), this.storageUsageLastRefresh = Date.now();\n } catch {\n }\n }\n saveContentState() {\n this.stateManager.setState({\n contents: this.contentManager.toJSON(),\n isDirty: !0\n }), this.zoomToolbar?.showSaveButton(!0), this.engine.checkSafeAreaViolations(), this.emitChange();\n }\n syncEngineContents() {\n this.engine?.setContents(this.contentManager.getContents());\n }\n syncFromState() {\n const t = this.stateManager.getState();\n this.contentManager.setContentsQuiet(t.contents), this.syncEngineContents(), this.inputPanel.setContents(this.contentManager.getContents()), this.engine.setSelectedArea(t.selectedAreaId), this.inputPanel.setSelectedArea(t.selectedAreaId);\n }\n // ─── Keyboard ───\n setupKeyboardShortcuts() {\n const t = J();\n this.keyboard.register({\n key: \"z\",\n [t]: !0,\n handler: () => this.undo()\n }), this.keyboard.register({\n key: \"z\",\n [t]: !0,\n shift: !0,\n handler: () => this.redo()\n }), this.keyboard.register({\n key: \"Escape\",\n handler: () => this.handleAreaSelect(null)\n });\n }\n // ─── Toast & Modal ───\n showToast(t, e = \"info\") {\n const i = h(\"div\", { class: `editor-toast editor-toast-${e}` }, t);\n this.shadow.appendChild(i), setTimeout(() => i.remove(), 4e3);\n }\n showConfirmation(t, e, i = \"Cancel\", s = \"Continue\") {\n return new Promise((n) => {\n const a = h(\"div\", { class: \"editor-modal-overlay\" }), o = h(\"div\", { class: \"editor-modal\" });\n o.appendChild(h(\"div\", { class: \"editor-modal-title\" }, t)), o.appendChild(h(\"div\", { class: \"editor-modal-body\" }, e));\n const r = h(\"div\", { class: \"editor-modal-actions\" }), l = h(\"button\", { class: \"editor-modal-btn\" }, i);\n l.addEventListener(\"click\", () => {\n a.remove(), n(!1);\n });\n const d = h(\"button\", { class: \"editor-modal-btn editor-modal-btn-primary\" }, s);\n d.addEventListener(\"click\", () => {\n a.remove(), n(!0);\n }), r.appendChild(l), r.appendChild(d), o.appendChild(r), a.appendChild(o), a.addEventListener(\"click\", (c) => {\n c.target === a && (a.remove(), n(!1));\n }), this.shadow.appendChild(a);\n });\n }\n // ─── Error / Cleanup ───\n showError(t, e) {\n this.shadow.innerHTML = \"\";\n const i = document.createElement(\"style\");\n i.textContent = k, this.shadow.appendChild(i);\n const s = h(\"div\", { class: \"error-container\" });\n s.appendChild(h(\"div\", { class: \"error-title\" }, t)), s.appendChild(h(\"div\", { class: \"error-message\" }, e?.message ?? \"\")), this.shadow.appendChild(s), this.dispatchEvent(\n new CustomEvent(\"error\", {\n detail: { message: t, error: e },\n bubbles: !0,\n composed: !0\n })\n );\n }\n cleanup() {\n for (const t of this.subscriptions)\n t();\n this.subscriptions = [], this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), this.engine?.destroy(), this.interaction?.destroy(), this.keyboard?.destroy(), this.isReady = !1, this.currentTemplate = null, this.productViews = [], this.activeViewName = null, this.perViewContents.clear();\n }\n}\ncustomElements.get(\"customizer-editor\") || customElements.define(\"customizer-editor\", et);\nexport {\n et as CustomizerEditor\n};\n//# sourceMappingURL=customizer.esm.js.map\n","/**\n * Vanilla JavaScript SDK for Customizer Editor\n * @packageDocumentation\n */\n\n// Side-effect: registers <customizer-editor> web component.\n// Using namespace import so tsc omits it from .d.ts (value-only usage).\nimport * as _editorModule from '@customizer/editor';\nvoid _editorModule;\nimport type {\n CustomizerOptions,\n CustomizerInstance,\n DesignJSON,\n FinalizeResult,\n CustomizerError,\n CustomizerEditorElement,\n ViewInfo,\n} from '../types';\n\n/**\n * Initialize the customizer editor\n *\n * @param elementOrSelector - DOM element or CSS selector where to mount the editor\n * @param options - Configuration options\n * @returns CustomizerInstance with methods to control the editor\n *\n * @example\n * ```typescript\n * import { initCustomizer } from '@varianta/sdk';\n *\n * const editor = initCustomizer('#editor', {\n * templateId: 'tshirt-001',\n * theme: 'light',\n * onReady: () => console.log('Editor ready!'),\n * onChange: (design) => console.log('Design changed:', design),\n * });\n *\n * // Get current design\n * const design = editor.getDesign();\n *\n * // Finalize design\n * const result = await editor.finalize();\n * ```\n */\nexport function initCustomizer(\n elementOrSelector: HTMLElement | string,\n options: CustomizerOptions\n): CustomizerInstance {\n // Resolve the container element\n const container =\n typeof elementOrSelector === 'string'\n ? document.querySelector<HTMLElement>(elementOrSelector)\n : elementOrSelector;\n\n if (!container) {\n throw new Error(\n `Container not found: ${\n typeof elementOrSelector === 'string'\n ? elementOrSelector\n : 'provided element is null'\n }`\n );\n }\n\n // Validate that exactly one of templateId or productId is provided\n if (!options.templateId && !options.productId) {\n throw new Error('Either templateId or productId must be provided');\n }\n if (options.templateId && options.productId) {\n throw new Error('Only one of templateId or productId should be provided, not both');\n }\n\n // Create the editor element\n const editorElement = document.createElement('customizer-editor') as unknown as CustomizerEditorElement;\n\n // Set attributes\n if (options.productId) {\n editorElement.setAttribute('product-id', options.productId);\n } else {\n editorElement.setAttribute('template-id', options.templateId!);\n }\n if (options.theme) {\n editorElement.setAttribute('theme', options.theme);\n }\n if (options.mode) {\n editorElement.setAttribute('mode', options.mode);\n }\n if (options.className) {\n editorElement.classList.add(options.className);\n }\n\n // Apply custom styles if needed\n editorElement.style.width = '100%';\n editorElement.style.height = '100%';\n\n // Event listeners tracking\n const listeners: Array<{ event: string; handler: EventListener }> = [];\n\n const addEventListener = (event: string, handler: EventListener) => {\n editorElement.addEventListener(event, handler);\n listeners.push({ event, handler });\n };\n\n // Mount the editor first\n container.innerHTML = '';\n container.appendChild(editorElement);\n\n // Create the instance API BEFORE setting up event handlers\n const instance: CustomizerInstance = {\n getDesign(): DesignJSON {\n if (typeof editorElement.getDesign !== 'function') {\n throw new Error('Editor not ready: getDesign method not available');\n }\n return editorElement.getDesign();\n },\n\n setDesign(design: DesignJSON): void {\n if (typeof editorElement.setDesign !== 'function') {\n throw new Error('Editor not ready: setDesign method not available');\n }\n editorElement.setDesign(design);\n },\n\n undo(): void {\n if (typeof editorElement.undo !== 'function') {\n throw new Error('Editor not ready: undo method not available');\n }\n editorElement.undo();\n },\n\n redo(): void {\n if (typeof editorElement.redo !== 'function') {\n throw new Error('Editor not ready: redo method not available');\n }\n editorElement.redo();\n },\n\n canUndo(): boolean {\n if (typeof editorElement.canUndo !== 'function') {\n return false;\n }\n return editorElement.canUndo();\n },\n\n canRedo(): boolean {\n if (typeof editorElement.canRedo !== 'function') {\n return false;\n }\n return editorElement.canRedo();\n },\n\n async finalize(): Promise<FinalizeResult> {\n const design = this.getDesign();\n const apiUrl = options.apiUrl || 'https://api.varianta.io';\n\n try {\n const response = await fetch(`${apiUrl}/public/finalize`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n templateId: (design as any).templateId || options.templateId,\n designJson: design,\n }),\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({\n message: 'Finalization failed',\n }));\n throw new Error(error.message || 'Finalization failed');\n }\n\n const body = await response.json();\n let result: FinalizeResult = {\n designId: body.designId,\n status: body.status,\n proofUrl: body.proofUrl ?? null,\n errorMessage: body.errorMessage ?? null,\n };\n\n // Poll until the render completes (or fails)\n const POLL_INTERVAL = 1500;\n const MAX_POLLS = 40; // ~60 s total\n let polls = 0;\n\n while (result.status === 'processing' && polls < MAX_POLLS) {\n await new Promise((r) => setTimeout(r, POLL_INTERVAL));\n polls++;\n\n const statusRes = await fetch(\n `${apiUrl}/public/designs/${result.designId}/status`,\n );\n if (!statusRes.ok) {\n throw new Error('Failed to check design status');\n }\n const statusBody = await statusRes.json();\n result = {\n designId: statusBody.designId,\n status: statusBody.status,\n proofUrl: statusBody.proofUrl ?? null,\n errorMessage: statusBody.errorMessage ?? null,\n };\n }\n\n if (result.status === 'processing') {\n result = { ...result, status: 'failed', errorMessage: 'Render timed out' };\n }\n\n if (options.onFinalize) {\n options.onFinalize(result);\n }\n\n return result;\n } catch (error) {\n const customizerError: CustomizerError = {\n code: 'FINALIZE_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error,\n };\n\n if (options.onError) {\n options.onError(customizerError);\n }\n\n throw error;\n }\n },\n\n addTextLayer(text?: string): void {\n if (typeof editorElement.addTextLayer !== 'function') {\n throw new Error('Editor not ready: addTextLayer method not available');\n }\n editorElement.addTextLayer(text);\n },\n\n async addImageLayer(url: string): Promise<void> {\n if (typeof editorElement.addImageLayer !== 'function') {\n throw new Error('Editor not ready: addImageLayer method not available');\n }\n return editorElement.addImageLayer(url);\n },\n\n removeLayer(layerId: string): void {\n if (typeof editorElement.removeLayer !== 'function') {\n throw new Error('Editor not ready: removeLayer method not available');\n }\n editorElement.removeLayer(layerId);\n },\n\n selectLayer(layerId: string | null): void {\n if (typeof editorElement.selectLayer !== 'function') {\n throw new Error('Editor not ready: selectLayer method not available');\n }\n editorElement.selectLayer(layerId);\n },\n\n getSelectedLayerId(): string | null {\n if (typeof editorElement.getSelectedLayerId !== 'function') {\n return null;\n }\n return editorElement.getSelectedLayerId();\n },\n\n getActiveView(): string | null {\n if (typeof editorElement.getActiveView !== 'function') {\n return null;\n }\n return editorElement.getActiveView();\n },\n\n getViews(): ViewInfo[] {\n if (typeof editorElement.getViews !== 'function') {\n return [];\n }\n return editorElement.getViews();\n },\n\n setActiveView(viewName: string): void {\n if (typeof editorElement.setActiveView !== 'function') {\n throw new Error('Editor not ready: setActiveView method not available');\n }\n editorElement.setActiveView(viewName);\n },\n\n setTheme(theme: 'light' | 'dark'): void {\n editorElement.setAttribute('theme', theme);\n },\n\n setMode(mode: 'edit' | 'preview'): void {\n editorElement.setAttribute('mode', mode);\n },\n\n destroy(): void {\n // Remove all event listeners\n listeners.forEach(({ event, handler }) => {\n editorElement.removeEventListener(event, handler);\n });\n\n // Remove the element from DOM\n if (editorElement.parentNode) {\n editorElement.parentNode.removeChild(editorElement);\n }\n },\n\n getElement(): HTMLElement {\n return editorElement;\n },\n };\n\n // NOW set up event handlers (after instance is fully created)\n if (options.onReady) {\n addEventListener('ready', (() => {\n options.onReady?.(instance);\n }) as EventListener);\n }\n\n if (options.onChange) {\n addEventListener('change', ((e: CustomEvent) => {\n const design = e.detail.design;\n options.onChange?.(design);\n }) as EventListener);\n }\n\n if (options.onLayerSelect) {\n addEventListener('layer:select', ((e: CustomEvent) => {\n options.onLayerSelect?.(e.detail.layerId);\n }) as EventListener);\n }\n\n if (options.onLayerAdd) {\n addEventListener('layer:add', ((e: CustomEvent) => {\n options.onLayerAdd?.(e.detail.layerId);\n }) as EventListener);\n }\n\n if (options.onLayerRemove) {\n addEventListener('layer:remove', ((e: CustomEvent) => {\n options.onLayerRemove?.(e.detail.layerId);\n }) as EventListener);\n }\n\n if (options.onLayerUpdate) {\n addEventListener('layer:update', ((e: CustomEvent) => {\n options.onLayerUpdate?.(e.detail.layerId);\n }) as EventListener);\n }\n\n if (options.onError) {\n addEventListener('error', ((e: CustomEvent) => {\n const error: CustomizerError = e.detail.error;\n options.onError?.(error);\n }) as EventListener);\n }\n\n if (options.onViewChange) {\n addEventListener('view-change', ((e: CustomEvent) => {\n options.onViewChange?.(e.detail.viewName);\n }) as EventListener);\n }\n\n // Set initial design if provided\n if (options.initialDesign) {\n // Wait for the editor to be ready before setting the design\n editorElement.addEventListener(\n 'ready',\n () => {\n if (options.initialDesign) {\n editorElement.setDesign(options.initialDesign);\n }\n },\n { once: true }\n );\n }\n\n if (options.debug) {\n console.log('[Customizer SDK] Initialized with options:', options);\n console.log('[Customizer SDK] Instance:', instance);\n }\n\n return instance;\n}\n\n/**\n * Re-export types for convenience\n */\nexport type * from '../types';\n"],"names":["N","t","e","s","n","a","o","l","d","b","y","w","v","x","C","S","z","u","p","g","m","T","D","O","E","M","H","B","A","I","F","Z","$","V","Y","W","L","X","R","G","J","K","_","Q","tt","et","r","initCustomizer","elementOrSelector","options","container","editorElement","listeners","addEventListener","event","handler","instance","design","apiUrl","response","error","body","result","POLL_INTERVAL","MAX_POLLS","polls","statusRes","statusBody","customiz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