@printine/pod-editor 0.1.19 → 0.1.21

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.
Files changed (34) hide show
  1. package/README.md +8 -0
  2. package/dist/components/context.d.ts +7 -0
  3. package/dist/components/menus/sca.d.ts +2 -4
  4. package/dist/components/personalization-background.d.ts +6 -0
  5. package/dist/components/personalization-controller.d.ts +2 -0
  6. package/dist/components/personalization-preview.d.ts +5 -0
  7. package/dist/components/personalization-shared.d.ts +3 -0
  8. package/dist/components/preview/real-time/index.d.ts +2 -1
  9. package/dist/components/semi-deisgn-config.d.ts +8 -2
  10. package/dist/{design-BXbmX1Tb.js → design-zuaYzDgn.js} +8687 -8449
  11. package/dist/designer-store-BZFMaojO.js +261 -0
  12. package/dist/engine/constants.js +1 -1
  13. package/dist/engine/editor.js +120 -116
  14. package/dist/engine/events.d.ts +6 -0
  15. package/dist/engine/managers/event.js +1 -1
  16. package/dist/full-designer.js +3 -3
  17. package/dist/i18n/personalization.d.ts +3 -0
  18. package/dist/index.js +6 -6
  19. package/dist/lib/personalization.d.ts +78 -0
  20. package/dist/personalization-preview-D9z7Ketn.js +352 -0
  21. package/dist/pixel-map-CSpWvUYE.js +315 -0
  22. package/dist/{pixi-print-base-CKs4lF7h.js → pixi-print-base-DIvtSF7v.js} +1 -1
  23. package/dist/renderer/pixel-map.d.ts +9 -2
  24. package/dist/{semi-interact-editor-nZVBXXQn.js → semi-interact-editor-DpzQN5ZB.js} +2 -2
  25. package/dist/semi-renderer.js +1 -1
  26. package/dist/state/designer-store.d.ts +2 -0
  27. package/dist/state/designer-store.js +1 -1
  28. package/dist/style.css +1 -1
  29. package/docs/BUYER_PERSONALIZATION.md +137 -0
  30. package/docs/HOST_DATA_CONTRACT.md +1 -1
  31. package/docs/SEMI_RENDERER.md +37 -1
  32. package/package.json +3 -1
  33. package/dist/designer-store-Da9fICz8.js +0 -153
  34. package/dist/pixel-map-BvQ0VU_i.js +0 -199
@@ -0,0 +1,315 @@
1
+ import { jsxs as A, jsx as b } from "react/jsx-runtime";
2
+ import { isSvg as B } from "./engine/utils/measure.js";
3
+ function j({ image: r, alt: e = "Product preview", loading: t, failed: n, onRetry: o }) {
4
+ return /* @__PURE__ */ A("div", { "data-print-material-preview": "true", style: { position: "relative", width: "100%", height: "100%", minHeight: 80 }, children: [
5
+ r && /* @__PURE__ */ b("img", { src: r, alt: e, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
6
+ (!r || n) && /* @__PURE__ */ A("div", { role: n ? "alert" : "status", "aria-live": "polite", style: {
7
+ position: "absolute",
8
+ inset: 0,
9
+ minHeight: 80,
10
+ display: "flex",
11
+ flexDirection: "column",
12
+ alignItems: "center",
13
+ justifyContent: "center",
14
+ gap: 8,
15
+ padding: 12,
16
+ textAlign: "center",
17
+ background: "#f3f4f6",
18
+ color: "#374151",
19
+ fontSize: 12
20
+ }, children: [
21
+ /* @__PURE__ */ b("span", { children: n ? "Preview could not be generated." : "Generating preview…" }),
22
+ n && o && /* @__PURE__ */ b(
23
+ "button",
24
+ {
25
+ type: "button",
26
+ disabled: t,
27
+ onClick: (c) => {
28
+ c.stopPropagation(), o();
29
+ },
30
+ style: { border: "1px solid #9ca3af", borderRadius: 4, background: "#fff", padding: "5px 12px", cursor: "pointer" },
31
+ children: "Retry"
32
+ }
33
+ )
34
+ ] })
35
+ ] });
36
+ }
37
+ function E(r) {
38
+ return typeof r == "string" && /^#[\da-f]{6}$/i.test(r) ? r.toLowerCase() : void 0;
39
+ }
40
+ function C(r, e, t = !!r.texture) {
41
+ return !r.design || t || !!(e ?? r.color) || !!E(r.defaultPrintColor);
42
+ }
43
+ function w(...r) {
44
+ for (const e of r) if (e !== void 0) return e === null ? null : E(e) ?? null;
45
+ }
46
+ function I(r, e) {
47
+ const t = w(r.defaultPrintColor, e);
48
+ return { ...r, defaultPrintColor: t, render_areas: r.render_areas.map((n) => ({
49
+ ...n,
50
+ defaultPrintColor: n.design ? w(n.defaultPrintColor, n.area?.defaultPrintColor, t) : void 0
51
+ })) };
52
+ }
53
+ function H(r) {
54
+ return { ...r, areas: r.areas.map((e) => ({
55
+ ...e,
56
+ defaultPrintColor: w(e.defaultPrintColor, r.defaultPrintColor)
57
+ })), renders: (r.renders || []).map((e) => I(e, r.defaultPrintColor)) };
58
+ }
59
+ function q(r) {
60
+ return r.some((e) => e.design && !!E(e.defaultPrintColor));
61
+ }
62
+ const S = `(function(){"use strict";class \${constructor(e=32*1024*1024,n=4,r){this.budget=e,this.concurrency=n,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(e){this.pinned=new Set(e),this.waiting.forEach(n=>{n.foreground=this.pinned.has(n.source)}),this.waiting.sort((n,r)=>Number(r.foreground)-Number(n.foreground)),this.trim()}trim(){for(const[e,n]of this.entries){if(this.bytes<=this.budget)break;!n.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=n.bytes,this.onEvict?.(e))}}clear(){for(const e of this.waiting.splice(0))e.cancel();for(const e of this.entries.keys())this.onEvict?.(e);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(e){const n=this.waiting.findIndex(o=>o.source===e&&!o.foreground);if(n<0)return;const[r]=this.waiting.splice(n,1);r.foreground=!0;const s=this.waiting.findIndex(o=>!o.foreground);this.waiting.splice(s<0?this.waiting.length:s,0,r)}async fetchBlob(e,n){await new Promise((r,s)=>{const o=()=>{this.active+=1,r()};this.active<this.concurrency?o():(this.waiting.push({source:e,foreground:!1,start:o,cancel:()=>s(new Error("Resource cache was released"))}),n&&this.promote(e))});try{const r=await fetch(e);if(!r.ok)throw new Error(\`Could not load render asset (\${r.status})\`);return await r.blob()}finally{this.active-=1,this.waiting.shift()?.start()}}load(e,n=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),n&&this.promote(e),r.ready;const s={ready:this.fetchBlob(e,n),bytes:0};return this.entries.set(e,s),s.ready.then(o=>{this.entries.get(e)===s&&(s.bytes=o.size,this.bytes+=s.bytes,this.trim())}).catch(()=>{this.entries.get(e)===s&&this.entries.delete(e)}),s.ready}}function I(i){return typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i.toLowerCase():void 0}function P(i,e,n=!!i.texture){return!i.design||n||!!(e??i.color)||!!I(i.defaultPrintColor)}const v=44,V=32*1024*1024,L=new Map;let M=0;const X=new $;function x(i,e=0){return typeof i=="number"&&Number.isFinite(i)?i:e}function U(i,e=1){const n=x(i,e);return Math.max(0,Math.min(1,n>1?n/255:n))}function j(i=new Set){for(const[e,n]of L){if(M<=V)break;i.has(e)||!n.bitmap||(L.delete(e),M-=n.bytes,n.bitmap.close())}}function K(i){return createImageBitmap(i).catch(e=>{const n=e instanceof Error?e.message:String(e);throw new Error(\`Render layer image could not be decoded (\${i.type||"unknown"}): \${n}\`)})}async function k(i,e){if(!i)return null;if(i instanceof ImageBitmap)return i;e.add(i);let n=L.get(i);return n?(L.delete(i),L.set(i,n)):(n={bytes:0,promise:X.load(i).then(K)},L.set(i,n),n.promise.then(r=>{n.bitmap=r,n.bytes=r.width*r.height*4,M+=n.bytes}).catch(()=>L.delete(i))),n.promise}function Q(i){for(const e of i)e.image instanceof ImageBitmap&&e.image.close(),e.texture instanceof ImageBitmap&&e.texture.close()}function J(i){const e=i;return!!e&&Array.isArray(e.uLines)&&e.uLines.length>=2&&Array.isArray(e.vLines)&&e.vLines.length>=2&&Array.isArray(e.grid)&&e.grid.length===e.vLines.length&&e.grid.every(n=>Array.isArray(n)&&n.length===e.uLines.length)}function Z(i){const e=i;if(!e||!Array.isArray(e.vertices)||!Array.isArray(e.uvs)||!Array.isArray(e.indices)||!e.vertices.length||e.vertices.length%2!==0||e.uvs.length!==e.vertices.length||!e.indices.length||e.indices.length%3!==0)return!1;const n=e.vertices.length/2;return e.vertices.every(Number.isFinite)&&e.uvs.every(Number.isFinite)&&e.indices.every(r=>Number.isInteger(r)&&r>=0&&r<n&&r<=65535)}function q(i){return i.some(e=>e.some(n=>["r","l","u","d"].some(r=>{const s=n[r];return typeof s=="object"&&!!s.moved})))}function ee(i,e){const n=i[e];return n?.moved?{dx:x(n.dx)-x(n.baseDx),dy:x(n.dy)-x(n.baseDy)}:{dx:0,dy:0}}function S(i,e,n,r,s){const o=1-s;return{x:o**3*i.x+3*o*o*s*e.x+3*o*s*s*n.x+s**3*r.x,y:o**3*i.y+3*o*o*s*e.y+3*o*s*s*n.y+s**3*r.y}}function te(i,e,n,r,s,o){const d=(c,E)=>({dx:(E.x-c.x)/3,dy:(E.y-c.y)/3}),u=(c,E,w)=>{const f=d(c,E),l=ee(c,w);return{x:c.x+f.dx+l.dx,y:c.y+f.dy+l.dy}},y=S(i,u(i,e,"r"),u(e,i,"l"),e,s),a=S(n,u(n,r,"r"),u(r,n,"l"),r,s),g=S(i,u(i,n,"d"),u(n,i,"u"),n,o),m=S(e,u(e,r,"d"),u(r,e,"u"),r,o),h={x:i.x*(1-s)*(1-o)+e.x*s*(1-o)+n.x*(1-s)*o+r.x*s*o,y:i.y*(1-s)*(1-o)+e.y*s*(1-o)+n.y*(1-s)*o+r.y*s*o};return{x:y.x*(1-o)+a.x*o+g.x*(1-s)+m.x*s-h.x,y:y.y*(1-o)+a.y*o+g.y*(1-s)+m.y*s-h.y}}function C(i,e){if(i.length<=2)return 0;let n=0,r=i.length;const s=e-1e-9;for(;n<r;){const o=n+r>>1;i[o]<s?n=o+1:r=o}return Math.min(Math.max(n-1,0),i.length-2)}function ne(i,e,n,r){const s=C(i.uLines,e),o=C(i.vLines,n),d=i.uLines[s+1]-i.uLines[s],u=i.vLines[o+1]-i.vLines[o],y=d>1e-9?(e-i.uLines[s])/d:0,a=u>1e-9?(n-i.vLines[o])/u:0,[g,m]=[i.grid[o][s],i.grid[o][s+1]],[h,c]=[i.grid[o+1][s],i.grid[o+1][s+1]];return r?te(g,m,h,c,y,a):{x:g.x*(1-y)*(1-a)+m.x*y*(1-a)+h.x*(1-y)*a+c.x*y*a,y:g.y*(1-y)*(1-a)+m.y*y*(1-a)+h.y*(1-y)*a+c.y*y*a}}function D(i){let e=1/0,n=1/0,r=-1/0,s=-1/0;for(const o of i)e=Math.min(e,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x),s=Math.max(s,o.y);return{minX:e,minY:n,maxX:r,maxY:s}}function ie(i,e){const n=i.config??i.texture_transform??{},r=n.transform??{},s=i.textureSize??n.textureSize,o=x(s?.[0]),d=x(s?.[1]),u=e.width,y=e.height;if(!(o>0&&d>0&&u>0&&y>0&&(o!==u||d!==y)))return{...r};const g=o/u,m=d/y,h=Math.sqrt(g*m);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*h}:{},...typeof r.scale=="number"?{scale:r.scale*h}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*g}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*m}:{}}}function re(i,e,n,r){if(r||!i.length)return i;const s=D(i),o={x:(s.minX+s.maxX)/2,y:(s.minY+s.maxY)/2},d=typeof e.scaleX=="number"?e.scaleX:typeof e.scale=="number"?e.scale:n,u=typeof e.scaleY=="number"?e.scaleY:typeof e.scale=="number"?e.scale:n,y=d/(n||1)*x(e.flipX,1),a=u/(n||1)*x(e.flipY,1),g=x(e.rotation)*Math.PI/180,m=Math.cos(g),h=Math.sin(g),c=i.map(l=>{const _=(l.x-o.x)*y,T=(l.y-o.y)*a;return{x:_*m-T*h+o.x,y:_*h+T*m+o.y}}),E=D(c),w=typeof e.translateX=="number"?e.translateX-E.minX:0,f=typeof e.translateY=="number"?e.translateY-E.minY:0;return w||f?c.map(l=>({x:l.x+w,y:l.y+f})):c}function oe(i,e){if(!Z(e))return null;const n=new Float32Array(e.vertices.length);for(let r=0;r<e.vertices.length;r+=2)n[r]=i.x+e.vertices[r],n[r+1]=i.y+e.vertices[r+1];return{vertices:n,uvs:new Float32Array(e.uvs),indices:new Uint16Array(e.indices)}}function N(i,e){const n=i.config??i.texture_transform??{},r=oe(i,n);if(r)return r;const s=ie(i,e),o=J(n.mesh)?n.mesh:null;let d,u=x(s.baseScale,1);if(o){const f=q(o.grid);d=(l,_)=>ne(o,l,_,f)}else{const f=Math.max(i.width/e.width,i.height/e.height);u=typeof s.baseScale=="number"?s.baseScale:Math.min(1,f);const l=e.width*u,_=e.height*u,T=(i.width-l)/2,A=(i.height-_)/2;d=(B,Ee)=>({x:T+l*B,y:A+_*Ee})}const y=[],a=new Float32Array((v+1)**2*2);let g=0;for(let f=0;f<=v;f+=1){const l=f/v;for(let _=0;_<=v;_+=1){const T=_/v;y.push(d(T,l)),a[g++]=T,a[g++]=l}}const m=re(y,s,u,!!s.baked),h=new Float32Array(m.length*2);m.forEach((f,l)=>{h[l*2]=i.x+f.x,h[l*2+1]=i.y+f.y});const c=new Uint16Array(v*v*6);let E=0;const w=v+1;for(let f=0;f<v;f+=1)for(let l=0;l<v;l+=1){const _=f*w+l,T=_+1,A=_+w,B=A+1;c[E++]=_,c[E++]=T,c[E++]=A,c[E++]=T,c[E++]=B,c[E++]=A}return{vertices:h,uvs:a,indices:c}}const p=new OffscreenCanvas(1,1),O=p.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!O)throw new Error("WebGL2 is unavailable in the render worker");const t=O,se=\`#version 300 es
63
+ in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
64
+ out vec2 v_uv; out vec2 v_position;
65
+ void main() {
66
+ vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
67
+ gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
68
+ v_uv = a_uv; v_position = a_position;
69
+ }\`,ae=\`#version 300 es
70
+ precision highp float;
71
+ uniform sampler2D u_image; uniform sampler2D u_mask;
72
+ uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
73
+ in vec2 v_uv; in vec2 v_position; out vec4 out_color;
74
+ void main() {
75
+ vec4 source = texture(u_image, v_uv);
76
+ if (u_mode == 1) {
77
+ vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
78
+ if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
79
+ vec4 mask = texture(u_mask, maskUv);
80
+ source *= mask.a;
81
+ } else if (u_mode == 2) {
82
+ float tintAlpha = source.a * u_tint.a;
83
+ source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
84
+ } else if (u_mode == 3) {
85
+ vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
86
+ if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
87
+ vec4 mask = texture(u_mask, maskUv);
88
+ // Compose the premultiplied artwork over its fill before clipping. Applying
89
+ // mask alpha to each term separately would count translucent edges twice.
90
+ vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
91
+ source = (source + fill * (1.0 - source.a)) * mask.a;
92
+ }
93
+ if (u_mode == 4) source = vec4(u_tint.rgb * u_tint.a, u_tint.a);
94
+ else if (u_mode == 5) source += vec4(u_tint.rgb * u_tint.a, u_tint.a) * (1.0 - source.a);
95
+ out_color = source * u_opacity;
96
+ }\`;function G(i,e){const n=t.createShader(i);if(!n)throw new Error("Could not create WebGL shader");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n)||"WebGL shader compilation failed");return n}const b=t.createProgram();if(!b)throw new Error("Could not create WebGL program");if(t.attachShader(b,G(t.VERTEX_SHADER,se)),t.attachShader(b,G(t.FRAGMENT_SHADER,ae)),t.linkProgram(b),!t.getProgramParameter(b,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(b)||"WebGL program link failed");const Y=t.getAttribLocation(b,"a_position"),W=t.getAttribLocation(b,"a_uv"),ce=t.getUniformLocation(b,"u_resolution"),le=t.getUniformLocation(b,"u_image"),ue=t.getUniformLocation(b,"u_mask"),fe=t.getUniformLocation(b,"u_mode"),de=t.getUniformLocation(b,"u_opacity"),me=t.getUniformLocation(b,"u_tint"),he=t.getUniformLocation(b,"u_mask_rect");function H(i,e=!1){if(e)return i;const n=t.createTexture();if(!n)throw new Error("Could not create WebGL texture");return t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),n}function ge(i){const e=String(i??"normal").toLowerCase();t.enable(t.BLEND),e==="multiply"||e==="2"?t.blendFuncSeparate(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA):t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function F(i){if(!i)return[1,1,1,1];const e=/^#([\\da-f]{3})$/i.exec(i),n=/^#([\\da-f]{6})$/i.exec(i),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([+-]?(?:\\d*\\.)?\\d+))?/i.exec(i);let s=null;e&&(s=e[1].split("").map(d=>Number.parseInt(d+d,16))),n&&(s=[n[1].slice(0,2),n[1].slice(2,4),n[1].slice(4,6)].map(d=>Number.parseInt(d,16))),r&&(s=[Number(r[1]),Number(r[2]),Number(r[3])]);const o=r?.[4]===void 0?1:Math.max(0,Math.min(1,Number(r[4])));return s?[s[0]/255,s[1]/255,s[2]/255,o]:[1,1,1,1]}function z(i,e,n,r){return{vertices:new Float32Array([i,e,i+n,e,i,e+r,i+n,e+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function R(i,e,n={}){t.useProgram(b),ge(n.blend);const r=t.createBuffer(),s=t.createBuffer(),o=t.createBuffer();if(!r||!s||!o)throw new Error("Could not allocate WebGL geometry");t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,i.vertices,t.STREAM_DRAW),t.enableVertexAttribArray(Y),t.vertexAttribPointer(Y,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,i.uvs,t.STATIC_DRAW),t.enableVertexAttribArray(W),t.vertexAttribPointer(W,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,o),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i.indices,t.STATIC_DRAW),t.activeTexture(t.TEXTURE0);const d=H(e,n.imageIsTexture);t.bindTexture(t.TEXTURE_2D,d),t.uniform1i(le,0);let u=null;n.mask&&(t.activeTexture(t.TEXTURE1),u=H(n.mask),t.bindTexture(t.TEXTURE_2D,u),t.uniform1i(ue,1)),t.uniform2f(ce,p.width,p.height),t.uniform1i(fe,n.mode??0),t.uniform1f(de,n.opacity??1),t.uniform4fv(me,n.tint??[1,1,1,1]),t.uniform4fv(he,n.maskRect??[0,0,1,1]),t.drawElements(t.TRIANGLES,i.indices.length,t.UNSIGNED_SHORT,0),t.deleteBuffer(r),t.deleteBuffer(s),t.deleteBuffer(o),n.imageIsTexture||t.deleteTexture(d),u&&t.deleteTexture(u)}function ye(i,e){const n=t.createTexture(),r=t.createFramebuffer();if(!n||!r)throw new Error("Could not allocate WebGL layer target");if(t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,i,e,0,t.RGBA,t.UNSIGNED_BYTE,null),t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0),t.checkFramebufferStatus(t.FRAMEBUFFER)!==t.FRAMEBUFFER_COMPLETE)throw new Error("WebGL layer framebuffer is incomplete");return t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,null),{texture:n,framebuffer:r}}async function _e(i){const e=new Set;let n;try{const r=i.areas.find(a=>a.name==="bg");if(!r)throw new Error("WebGL worker rendering requires a bg render area");const s=x(i.options.targetSize),o=s>0?s/Math.max(r.width,r.height):Math.max(.1,x(i.options.scale,1)),d=i.options.composition==="design-layer";p.width=Math.max(1,Math.round(r.width*o)),p.height=Math.max(1,Math.round(r.height*o)),t.viewport(0,0,p.width,p.height),t.bindFramebuffer(t.FRAMEBUFFER,null),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const u=new Set;for(const a of i.areas)d&&!a.design||P(a,i.options.color)&&(typeof a.image=="string"&&a.image&&u.add(a.image),typeof a.texture=="string"&&u.add(a.texture));await Promise.all([...u].map(a=>k(a,e)));const y=a=>z(a.x*o,a.y*o,a.width*o,a.height*o);for(const a of i.areas){if(d&&!a.design||!P(a,i.options.color))continue;const g=await k(a.image,e);if(!g)continue;if(!a.design){R(y(a),g,{blend:a.export?.blend,opacity:U(a.export?.opacity)});continue}const m=await k(a.texture,e),h=i.options.color??a.color,c=a.config??a.texture_transform??{},E=d?"normal":c.blendMode??"multiply",w=I(a.defaultPrintColor);if(w){n??=ye(p.width,p.height),t.bindFramebuffer(t.FRAMEBUFFER,n.framebuffer),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const f=c.textureSize??[a.width,a.height],l=N(a,m??{width:f[0],height:f[1]});for(let A=0;A<l.vertices.length;A++)l.vertices[A]*=o;R(l,g,{mode:4,tint:F(w),blend:"normal"});const _=c.blendMode??(h?"multiply":"normal");m?R(l,m,{mode:h?5:0,tint:F(h),blend:_}):h&&R(l,g,{mode:4,tint:F(h),blend:_}),t.bindFramebuffer(t.FRAMEBUFFER,null);const T=z(0,0,p.width,p.height);T.uvs=new Float32Array([0,1,1,1,0,0,1,0]),R(T,n.texture,{imageIsTexture:!0,mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:"normal",opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&m?.close();continue}if(m){const f=N(a,m);for(let l=0;l<f.vertices.length;l+=1)f.vertices[l]*=o;d?R(f,m,{mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:"normal",opacity:U(c.opacity)}):h?R(f,m,{mode:3,mask:g,tint:F(h),maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:E,opacity:U(c.opacity)}):R(f,m,{mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:d?"normal":c.blendMode,opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&m.close()}else h&&R(y(a),g,{mode:2,tint:F(h),blend:E,opacity:U(c.opacity)})}t.finish();try{return await p.convertToBlob({type:i.options.format??"image/png",quality:i.options.quality??.9})}catch{return p.convertToBlob({type:"image/png"})}}finally{Q(i.areas),n&&(t.deleteFramebuffer(n.framebuffer),t.deleteTexture(n.texture)),j(e)}}self.onmessage=async i=>{const e=i.data;if(e.type==="preload"){try{await Promise.all([...new Set(e.sources)].map(n=>L.has(n)?Promise.resolve():X.load(n,e.priority===!0))),self.postMessage({type:"preloaded",id:e.id})}catch(n){self.postMessage({type:"error",id:e.id,message:n instanceof Error?n.message:String(n)})}return}if(e.type==="render")try{self.postMessage({type:"result",id:e.id,blob:await _e(e)})}catch(n){self.postMessage({type:"error",id:e.id,message:n instanceof Error?n.message:String(n)})}}})();
97
+ `, k = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", S], { type: "text/javascript;charset=utf-8" });
98
+ function N(r) {
99
+ let e;
100
+ try {
101
+ if (e = k && (self.URL || self.webkitURL).createObjectURL(k), !e) throw "";
102
+ const t = new Worker(e, {
103
+ name: r?.name
104
+ });
105
+ return t.addEventListener("error", () => {
106
+ (self.URL || self.webkitURL).revokeObjectURL(e);
107
+ }), t;
108
+ } catch {
109
+ return new Worker(
110
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(S),
111
+ {
112
+ name: r?.name
113
+ }
114
+ );
115
+ }
116
+ }
117
+ const D = 32 * 1024 * 1024;
118
+ function L(r, e = 0) {
119
+ return typeof r == "number" && Number.isFinite(r) ? r : e;
120
+ }
121
+ function X(r, e) {
122
+ const t = r.find((o) => o.name === "bg");
123
+ if (!t) return;
124
+ const n = L(e.targetSize);
125
+ return n > 0 ? n / Math.max(t.width, t.height) : Math.max(0.1, L(e.scale, 1));
126
+ }
127
+ function O(r, e) {
128
+ return e.composition === "design-layer" && !r.design ? !1 : C(r, e.color);
129
+ }
130
+ function U(r, e, t) {
131
+ return `${r}\0${e}\0${t}`;
132
+ }
133
+ async function W(r) {
134
+ if (r.startsWith("blob:"))
135
+ try {
136
+ const e = await fetch(r);
137
+ return e.ok ? (await e.blob()).type.toLowerCase().includes("svg") : !1;
138
+ } catch {
139
+ return !1;
140
+ }
141
+ return B(r);
142
+ }
143
+ function G(r) {
144
+ return new Promise((e, t) => {
145
+ const n = new Image();
146
+ n.onload = () => e(n), n.onerror = () => t(new Error("SVG image load failed")), n.src = r;
147
+ });
148
+ }
149
+ async function Y(r, e, t) {
150
+ if (!Number.isFinite(e) || !Number.isFinite(t) || e < 1 || t < 1)
151
+ throw new Error("Invalid SVG raster size");
152
+ const n = await fetch(r);
153
+ if (!n.ok) throw new Error(`Could not load render asset (${n.status})`);
154
+ const o = await n.blob(), c = o.type.toLowerCase().includes("svg") ? o : new Blob([o], { type: "image/svg+xml" }), a = URL.createObjectURL(c);
155
+ let s;
156
+ try {
157
+ const l = await G(a);
158
+ s = document.createElement("canvas"), s.width = e, s.height = t;
159
+ const d = s.getContext("2d");
160
+ if (!d) throw new Error("Canvas context creation failed");
161
+ return d.drawImage(l, 0, 0, e, t), await createImageBitmap(s);
162
+ } finally {
163
+ URL.revokeObjectURL(a), s && (s.width = 0, s.height = 0);
164
+ }
165
+ }
166
+ function y(r) {
167
+ if (!r) return r;
168
+ const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
169
+ if (!e) return r;
170
+ try {
171
+ return new URL(r, e).href;
172
+ } catch {
173
+ return r;
174
+ }
175
+ }
176
+ class M {
177
+ constructor() {
178
+ this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve(), this.svgChecks = /* @__PURE__ */ new Map(), this.rasterCache = /* @__PURE__ */ new Map(), this.rasterCacheBytes = 0, this.rasterPins = /* @__PURE__ */ new Set();
179
+ }
180
+ static isSupported() {
181
+ return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
182
+ }
183
+ ensureWorker() {
184
+ if (this.worker) return this.worker;
185
+ if (!M.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
186
+ const e = new N();
187
+ return e.onmessage = (t) => {
188
+ const n = t.data, o = this.pending.get(n.id);
189
+ o && (this.pending.delete(n.id), n.type === "result" ? o.resolve(n.blob) : n.type === "preloaded" ? o.resolve(null) : o.reject(new Error(n.message)));
190
+ }, e.onerror = (t) => {
191
+ const n = t.filename ? ` (${t.filename}:${t.lineno}:${t.colno})` : "", o = t.error instanceof Error ? t.error : new Error(`${t.message || "Pixel-map worker failed"}${n}`);
192
+ this.pending.forEach(({ reject: c }) => c(o)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
193
+ }, e.onmessageerror = () => {
194
+ const t = new Error("Pixel-map worker could not deserialize its render payload");
195
+ this.pending.forEach(({ reject: n }) => n(t)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
196
+ }, this.worker = e, e;
197
+ }
198
+ isSvgImage(e) {
199
+ const t = this.svgChecks.get(e);
200
+ if (t) return t;
201
+ const n = W(e);
202
+ return this.svgChecks.set(e, n), n;
203
+ }
204
+ rasterizeSvgLayer(e, t, n) {
205
+ const o = U(e, t, n), c = this.rasterCache.get(o);
206
+ if (c)
207
+ return this.rasterCache.delete(o), this.rasterCache.set(o, c), c.promise;
208
+ const a = { bytes: 0, promise: Y(e, t, n) };
209
+ return this.rasterCache.set(o, a), a.promise.then((s) => {
210
+ if (this.rasterCache.get(o) !== a) {
211
+ s.close();
212
+ return;
213
+ }
214
+ a.bitmap = s, a.bytes = t * n * 4, this.rasterCacheBytes += a.bytes, this.rasterCache.delete(o), this.rasterCache.set(o, a), this.trimRasterCache();
215
+ }).catch(() => {
216
+ this.rasterCache.get(o) === a && this.rasterCache.delete(o);
217
+ }), a.promise;
218
+ }
219
+ trimRasterCache() {
220
+ for (const [e, t] of this.rasterCache) {
221
+ if (this.rasterCacheBytes <= D) break;
222
+ this.rasterPins.has(e) || !t.bitmap || (this.rasterCache.delete(e), this.rasterCacheBytes -= t.bytes, t.bitmap.close());
223
+ }
224
+ }
225
+ /** Warm compressed resources without exporting Fabric or entering the GPU queue. */
226
+ async preloadAssets(e, t = !1) {
227
+ const n = [...new Set(e.filter(Boolean).map(y))];
228
+ if (!n.length) return;
229
+ const o = this.ensureWorker(), c = ++this.nextRequestId;
230
+ await new Promise((a, s) => {
231
+ this.pending.set(c, { resolve: a, reject: s });
232
+ try {
233
+ o.postMessage({ type: "preload", id: c, sources: n, priority: t });
234
+ } catch (l) {
235
+ this.pending.delete(c), s(l instanceof Error ? l : new Error(String(l)));
236
+ }
237
+ });
238
+ }
239
+ async onOffscreenRender(e, t = {}) {
240
+ const n = e.flatMap((s) => t.composition === "design-layer" && !s.design ? [] : C(s, t.color) ? [s.image, typeof s.texture == "string" ? s.texture : ""] : []), o = this.preloadAssets(n, !0);
241
+ o.catch(() => {
242
+ });
243
+ const c = async () => {
244
+ await o;
245
+ const s = this.ensureWorker(), l = ++this.nextRequestId, d = X(e, t), x = /* @__PURE__ */ new Set(), m = [];
246
+ let v = !0;
247
+ const _ = (f) => (v ? m.push(f) : f.close(), f);
248
+ try {
249
+ const f = d === void 0 ? [] : e.flatMap((i) => {
250
+ if (!O(i, t) || !i.image) return [];
251
+ const u = y(i.image);
252
+ return [{ area: i, source: u, svg: this.isSvgImage(u) }];
253
+ }), g = [];
254
+ for (const i of f)
255
+ await i.svg && g.push(i);
256
+ const R = /* @__PURE__ */ new Map(), P = d === void 0 ? [] : g.map((i) => {
257
+ const u = Math.max(1, Math.round(i.area.width * d)), p = Math.max(1, Math.round(i.area.height * d)), h = U(i.source, u, p);
258
+ return this.rasterPins.add(h), x.add(h), { candidate: i, pending: this.rasterizeSvgLayer(i.source, u, p) };
259
+ });
260
+ for (const i of P)
261
+ try {
262
+ const u = await i.pending;
263
+ R.set(i.candidate.area, _(await createImageBitmap(u)));
264
+ } catch (u) {
265
+ throw new Error(`Could not rasterize SVG render layer "${i.candidate.area.name}"`, { cause: u });
266
+ }
267
+ const T = await Promise.all(e.map(async (i) => {
268
+ const u = i.texture instanceof ImageBitmap ? _(await createImageBitmap(i.texture)) : typeof i.texture == "string" ? y(i.texture) : i.texture;
269
+ return {
270
+ ...i,
271
+ image: R.get(i) ?? y(i.image),
272
+ texture: u
273
+ };
274
+ })), F = T.flatMap((i) => [
275
+ i.texture instanceof ImageBitmap ? i.texture : void 0,
276
+ i.image instanceof ImageBitmap ? i.image : void 0
277
+ ].filter((u) => u instanceof ImageBitmap));
278
+ return await new Promise((i, u) => {
279
+ this.pending.set(l, { resolve: i, reject: u });
280
+ const p = { type: "render", id: l, areas: T, options: t };
281
+ try {
282
+ s.postMessage(p, F), m.length = 0;
283
+ } catch (h) {
284
+ this.pending.delete(l), u(h instanceof Error ? h : new Error(String(h)));
285
+ }
286
+ });
287
+ } catch (f) {
288
+ v = !1;
289
+ for (const g of m) g.close();
290
+ throw m.length = 0, f;
291
+ } finally {
292
+ for (const f of x) this.rasterPins.delete(f);
293
+ this.trimRasterCache();
294
+ }
295
+ }, a = this.renderQueue.then(c, c);
296
+ return this.renderQueue = a.then(() => {
297
+ }, () => {
298
+ }), a;
299
+ }
300
+ destroy() {
301
+ this.worker?.terminate(), this.worker = null, this.pending.forEach(({ reject: e }) => e(new Error("Pixel-map renderer was destroyed"))), this.pending.clear(), this.renderQueue = Promise.resolve();
302
+ for (const e of this.rasterCache.values()) e.bitmap?.close();
303
+ this.rasterCache.clear(), this.rasterCacheBytes = 0, this.rasterPins.clear(), this.svgChecks.clear();
304
+ }
305
+ }
306
+ export {
307
+ j as M,
308
+ M as P,
309
+ C as a,
310
+ H as b,
311
+ q as h,
312
+ w as i,
313
+ E as n,
314
+ I as r
315
+ };
@@ -1,5 +1,5 @@
1
1
  import { ALPHA_MODES as I, BLEND_MODES as g, MeshMaterial as v, Texture as S, Mesh as F, SpriteMaskFilter as O, RenderTexture as _, Assets as L } from "pixi.js";
2
- import { n as T } from "./pixel-map-BvQ0VU_i.js";
2
+ import { n as T } from "./pixel-map-CSpWvUYE.js";
3
3
  const N = (t) => typeof t == "number" && Number.isFinite(t) ? Math.max(0, Math.min(1, t > 1 ? t / 255 : t)) : 1, B = (t) => String(t).toLowerCase() === "multiply" || t === 2 ? g.MULTIPLY : g.NORMAL;
4
4
  let D = 0;
5
5
  async function U(t, c) {
@@ -23,16 +23,23 @@ export interface PixelMapRenderOptions {
23
23
  cacheKey?: string | number;
24
24
  }
25
25
  /**
26
- * A small client for the pixel-mapping Worker. It owns neither textures nor
27
- * object URLs, so callers can keep their current Fabric/Pixi lifecycle rules.
26
+ * A small client for the pixel-mapping Worker. Callers keep their textures
27
+ * and object URLs; SVG rasters cached here are closed in destroy().
28
28
  */
29
29
  export declare class PixelMapRenderer {
30
30
  private worker;
31
31
  private nextRequestId;
32
32
  private pending;
33
33
  private renderQueue;
34
+ private svgChecks;
35
+ private rasterCache;
36
+ private rasterCacheBytes;
37
+ private rasterPins;
34
38
  static isSupported(): boolean;
35
39
  private ensureWorker;
40
+ private isSvgImage;
41
+ private rasterizeSvgLayer;
42
+ private trimRasterCache;
36
43
  /** Warm compressed resources without exporting Fabric or entering the GPU queue. */
37
44
  preloadAssets(sources: string[], priority?: boolean): Promise<void>;
38
45
  onOffscreenRender(areas: PixelMapArea[], options?: PixelMapRenderOptions): Promise<Blob | null>;
@@ -1,7 +1,7 @@
1
1
  import { jsxs as Ae, jsx as H } from "react/jsx-runtime";
2
2
  import { forwardRef as Ge, useRef as S, useState as Z, useCallback as N, useEffect as ie, useImperativeHandle as Je } from "react";
3
3
  import { LAYER_BLACK_LIST as Oe, BLEND_MODES_MAP as Ke } from "./engine/constants.js";
4
- import { P as Ye, h as Qe, r as Ze, i as pe, M as $e, a as je } from "./pixel-map-BvQ0VU_i.js";
4
+ import { P as Ye, h as Qe, r as Ze, i as pe, M as $e, a as je } from "./pixel-map-CSpWvUYE.js";
5
5
  import "./engine/fabric.js";
6
6
  import { v4 as et } from "uuid";
7
7
  import { cloneObject as G, urlToDataURL as tt } from "./engine/utils/common.js";
@@ -1291,7 +1291,7 @@ const Bt = Ge(
1291
1291
  quality: 0.85,
1292
1292
  format: "image/png",
1293
1293
  cacheKey: e.id
1294
- }) : await (await import("./pixi-print-base-CKs4lF7h.js")).renderPixiWithPrintBase(V, ke, {
1294
+ }) : await (await import("./pixi-print-base-DIvtSF7v.js")).renderPixiWithPrintBase(V, ke, {
1295
1295
  color: Se,
1296
1296
  cleanCache: !1,
1297
1297
  scale: o,
@@ -1,4 +1,4 @@
1
- import { P as i, a as n } from "./semi-interact-editor-nZVBXXQn.js";
1
+ import { P as i, a as n } from "./semi-interact-editor-DpzQN5ZB.js";
2
2
  export {
3
3
  i as PrintineSemiInteractEditor,
4
4
  n as PrintineSemiRenderer
@@ -20,6 +20,7 @@ export interface DesignerState {
20
20
  copiedObjects: string | null;
21
21
  /** Semi-custom element configuration keyed by fabric object id. */
22
22
  semiCustom: Record<string, any>;
23
+ semiCustomDrafts: Record<string, any>;
23
24
  semiCustomBackground: SemiCustomBackground;
24
25
  initData: (loadHostFonts?: () => Promise<Font[]>, loadHostColors?: () => Promise<string[]>) => void;
25
26
  getFontList: (loadHostFonts?: () => Promise<Font[]>) => Promise<void>;
@@ -34,6 +35,7 @@ export interface DesignerState {
34
35
  setCopiedObjects: (objects: any) => void;
35
36
  setSemiCustom: (data: Record<string, any>) => void;
36
37
  setSemiCustomItem: (id: string, data: Record<string, any> | undefined) => void;
38
+ toggleSemiCustomItem: (id: string, defaults: Record<string, any>) => void;
37
39
  delSemiCustomInfo: (id: string) => void;
38
40
  setSemiCustomBackground: (data: SemiCustomBackground) => void;
39
41
  setSemiCustomBackgroundItem: (key: string, value: any) => void;
@@ -1,7 +1,7 @@
1
1
  import "zustand";
2
2
  import "../engine/history.js";
3
3
  import "../engine/utils/font.js";
4
- import { a as i, u as m } from "../designer-store-Da9fICz8.js";
4
+ import { a as i, u as m } from "../designer-store-BZFMaojO.js";
5
5
  export {
6
6
  i as useDesignStore,
7
7
  m as useDesignerStore