@printine/pod-editor 0.1.17 → 0.1.18
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/contracts/api-design.d.ts +8 -0
- package/dist/{design-BF_TXP1X.js → design-CWY-22HD.js} +5432 -5420
- package/dist/full-designer.js +3 -2
- package/dist/index.js +4 -4
- package/dist/pixel-map-BvQ0VU_i.js +199 -0
- package/dist/pixi-print-base-CKs4lF7h.js +91 -0
- package/dist/renderer/default-print-color.d.ts +6 -0
- package/dist/renderer/material-preview.d.ts +10 -0
- package/dist/renderer/pixi-print-base.d.ts +11 -0
- package/dist/renderer/render-layer-output.d.ts +3 -0
- package/dist/{semi-interact-editor-CNcIzYjP.js → semi-interact-editor-nZVBXXQn.js} +469 -464
- package/dist/semi-renderer.js +1 -1
- package/docs/DEFAULT_PRINT_COLOR.md +58 -0
- package/package.json +4 -2
- package/dist/pixel-map-7kj7mLV1.js +0 -134
package/dist/full-designer.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { c as
|
|
3
|
+
import { c as s } from "./design-CWY-22HD.js";
|
|
4
4
|
import "./engine/events.js";
|
|
5
5
|
import "zustand/react/shallow";
|
|
6
6
|
import "./engine/history.js";
|
|
7
7
|
import "lodash-es/throttle";
|
|
8
8
|
import "./engine/constants.js";
|
|
9
9
|
import "./engine/utils/common.js";
|
|
10
|
+
import "./pixel-map-BvQ0VU_i.js";
|
|
10
11
|
import "./designer-store-Da9fICz8.js";
|
|
11
12
|
export {
|
|
12
|
-
|
|
13
|
+
s as default
|
|
13
14
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { AdvancedIText as G } from "./engine/fabric.js";
|
|
2
|
-
import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-
|
|
3
|
-
import { F as K, S as V, u as X } from "./design-
|
|
2
|
+
import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-CWY-22HD.js";
|
|
3
|
+
import { F as K, S as V, u as X } from "./design-CWY-22HD.js";
|
|
4
4
|
import { jsx as r, jsxs as R } from "react/jsx-runtime";
|
|
5
5
|
import { useMemo as b, useEffect as a } from "react";
|
|
6
6
|
import { DEFAULT_PRINTINE_ASSET_BASE_URL as U, createAssetCenterApiClient as B } from "./api/asset-client.js";
|
|
7
7
|
import { s as d } from "./designer-store-Da9fICz8.js";
|
|
8
8
|
import { A as $, u as q } from "./designer-store-Da9fICz8.js";
|
|
9
9
|
import { d as y, s as M } from "./config-D2qm60gf.js";
|
|
10
|
-
import { P as Q, a as ee } from "./semi-interact-editor-
|
|
11
|
-
import { P as te } from "./pixel-map-
|
|
10
|
+
import { P as Q, a as ee } from "./semi-interact-editor-nZVBXXQn.js";
|
|
11
|
+
import { P as te } from "./pixel-map-BvQ0VU_i.js";
|
|
12
12
|
import { CanvasDesigner as ae, renderPlacementPreviews as ne } from "./engine/canvas-designer.js";
|
|
13
13
|
import { Editor as ie } from "./engine/editor.js";
|
|
14
14
|
import { HistoryManager as me } from "./engine/history.js";
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsxs as p, jsx as f } from "react/jsx-runtime";
|
|
2
|
+
function A({ image: t, alt: e = "Product preview", loading: r, failed: n, onRetry: i }) {
|
|
3
|
+
return /* @__PURE__ */ p("div", { "data-print-material-preview": "true", style: { position: "relative", width: "100%", height: "100%", minHeight: 80 }, children: [
|
|
4
|
+
t && /* @__PURE__ */ f("img", { src: t, alt: e, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
|
|
5
|
+
(!t || n) && /* @__PURE__ */ p("div", { role: n ? "alert" : "status", "aria-live": "polite", style: {
|
|
6
|
+
position: "absolute",
|
|
7
|
+
inset: 0,
|
|
8
|
+
minHeight: 80,
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
justifyContent: "center",
|
|
13
|
+
gap: 8,
|
|
14
|
+
padding: 12,
|
|
15
|
+
textAlign: "center",
|
|
16
|
+
background: "#f3f4f6",
|
|
17
|
+
color: "#374151",
|
|
18
|
+
fontSize: 12
|
|
19
|
+
}, children: [
|
|
20
|
+
/* @__PURE__ */ f("span", { children: n ? "Preview could not be generated." : "Generating preview…" }),
|
|
21
|
+
n && i && /* @__PURE__ */ f(
|
|
22
|
+
"button",
|
|
23
|
+
{
|
|
24
|
+
type: "button",
|
|
25
|
+
disabled: r,
|
|
26
|
+
onClick: (s) => {
|
|
27
|
+
s.stopPropagation(), i();
|
|
28
|
+
},
|
|
29
|
+
style: { border: "1px solid #9ca3af", borderRadius: 4, background: "#fff", padding: "5px 12px", cursor: "pointer" },
|
|
30
|
+
children: "Retry"
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
] })
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
function h(t) {
|
|
37
|
+
return typeof t == "string" && /^#[\da-f]{6}$/i.test(t) ? t.toLowerCase() : void 0;
|
|
38
|
+
}
|
|
39
|
+
function w(t, e, r = !!t.texture) {
|
|
40
|
+
return !t.design || r || !!(e ?? t.color) || !!h(t.defaultPrintColor);
|
|
41
|
+
}
|
|
42
|
+
function m(...t) {
|
|
43
|
+
for (const e of t) if (e !== void 0) return e === null ? null : h(e) ?? null;
|
|
44
|
+
}
|
|
45
|
+
function v(t, e) {
|
|
46
|
+
const r = m(t.defaultPrintColor, e);
|
|
47
|
+
return { ...t, defaultPrintColor: r, render_areas: t.render_areas.map((n) => ({
|
|
48
|
+
...n,
|
|
49
|
+
defaultPrintColor: n.design ? m(n.defaultPrintColor, n.area?.defaultPrintColor, r) : void 0
|
|
50
|
+
})) };
|
|
51
|
+
}
|
|
52
|
+
function U(t) {
|
|
53
|
+
return { ...t, areas: t.areas.map((e) => ({
|
|
54
|
+
...e,
|
|
55
|
+
defaultPrintColor: m(e.defaultPrintColor, t.defaultPrintColor)
|
|
56
|
+
})), renders: (t.renders || []).map((e) => v(e, t.defaultPrintColor)) };
|
|
57
|
+
}
|
|
58
|
+
function L(t) {
|
|
59
|
+
return t.some((e) => e.design && !!h(e.defaultPrintColor));
|
|
60
|
+
}
|
|
61
|
+
const b = `(function(){"use strict";class V{constructor(t=32*1024*1024,n=4,r){this.budget=t,this.concurrency=n,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(t){this.pinned=new Set(t),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[t,n]of this.entries){if(this.bytes<=this.budget)break;!n.bytes||this.pinned.has(t)||(this.entries.delete(t),this.bytes-=n.bytes,this.onEvict?.(t))}}clear(){for(const t of this.waiting.splice(0))t.cancel();for(const t of this.entries.keys())this.onEvict?.(t);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(t){const n=this.waiting.findIndex(s=>s.source===t&&!s.foreground);if(n<0)return;const[r]=this.waiting.splice(n,1);r.foreground=!0;const o=this.waiting.findIndex(s=>!s.foreground);this.waiting.splice(o<0?this.waiting.length:o,0,r)}async fetchBlob(t,n){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:t,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),n&&this.promote(t))});try{const r=await fetch(t);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(t,n=!0){const r=this.entries.get(t);if(r)return this.entries.delete(t),this.entries.set(t,r),n&&this.promote(t),r.ready;const o={ready:this.fetchBlob(t,n),bytes:0};return this.entries.set(t,o),o.ready.then(s=>{this.entries.get(t)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(t)===o&&this.entries.delete(t)}),o.ready}}function I(i){return typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i.toLowerCase():void 0}function P(i,t,n=!!i.texture){return!i.design||n||!!(t??i.color)||!!I(i.defaultPrintColor)}const v=44,$=32*1024*1024,L=new Map;let M=0;const X=new V;function x(i,t=0){return typeof i=="number"&&Number.isFinite(i)?i:t}function U(i,t=1){const n=x(i,t);return Math.max(0,Math.min(1,n>1?n/255:n))}function j(i=new Set){for(const[t,n]of L){if(M<=$)break;i.has(t)||!n.bitmap||(L.delete(t),M-=n.bytes,n.bitmap.close())}}async function k(i,t){if(!i)return null;if(i instanceof ImageBitmap)return i;t.add(i);let n=L.get(i);return n?(L.delete(i),L.set(i,n)):(n={bytes:0,promise:X.load(i).then(createImageBitmap)},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 K(i){const t=i;return!!t&&Array.isArray(t.uLines)&&t.uLines.length>=2&&Array.isArray(t.vLines)&&t.vLines.length>=2&&Array.isArray(t.grid)&&t.grid.length===t.vLines.length&&t.grid.every(n=>Array.isArray(n)&&n.length===t.uLines.length)}function Q(i){const t=i;if(!t||!Array.isArray(t.vertices)||!Array.isArray(t.uvs)||!Array.isArray(t.indices)||!t.vertices.length||t.vertices.length%2!==0||t.uvs.length!==t.vertices.length||!t.indices.length||t.indices.length%3!==0)return!1;const n=t.vertices.length/2;return t.vertices.every(Number.isFinite)&&t.uvs.every(Number.isFinite)&&t.indices.every(r=>Number.isInteger(r)&&r>=0&&r<n&&r<=65535)}function J(i){return i.some(t=>t.some(n=>["r","l","u","d"].some(r=>{const o=n[r];return typeof o=="object"&&!!o.moved})))}function Z(i,t){const n=i[t];return n?.moved?{dx:x(n.dx)-x(n.baseDx),dy:x(n.dy)-x(n.baseDy)}:{dx:0,dy:0}}function S(i,t,n,r,o){const s=1-o;return{x:s**3*i.x+3*s*s*o*t.x+3*s*o*o*n.x+o**3*r.x,y:s**3*i.y+3*s*s*o*t.y+3*s*o*o*n.y+o**3*r.y}}function q(i,t,n,r,o,s){const m=(c,b)=>({dx:(b.x-c.x)/3,dy:(b.y-c.y)/3}),u=(c,b,R)=>{const f=m(c,b),l=Z(c,R);return{x:c.x+f.dx+l.dx,y:c.y+f.dy+l.dy}},d=S(i,u(i,t,"r"),u(t,i,"l"),t,o),a=S(n,u(n,r,"r"),u(r,n,"l"),r,o),g=S(i,u(i,n,"d"),u(n,i,"u"),n,s),h=S(t,u(t,r,"d"),u(r,t,"u"),r,s),y={x:i.x*(1-o)*(1-s)+t.x*o*(1-s)+n.x*(1-o)*s+r.x*o*s,y:i.y*(1-o)*(1-s)+t.y*o*(1-s)+n.y*(1-o)*s+r.y*o*s};return{x:d.x*(1-s)+a.x*s+g.x*(1-o)+h.x*o-y.x,y:d.y*(1-s)+a.y*s+g.y*(1-o)+h.y*o-y.y}}function C(i,t){if(i.length<=2)return 0;let n=0,r=i.length;const o=t-1e-9;for(;n<r;){const s=n+r>>1;i[s]<o?n=s+1:r=s}return Math.min(Math.max(n-1,0),i.length-2)}function ee(i,t,n,r){const o=C(i.uLines,t),s=C(i.vLines,n),m=i.uLines[o+1]-i.uLines[o],u=i.vLines[s+1]-i.vLines[s],d=m>1e-9?(t-i.uLines[o])/m:0,a=u>1e-9?(n-i.vLines[s])/u:0,[g,h]=[i.grid[s][o],i.grid[s][o+1]],[y,c]=[i.grid[s+1][o],i.grid[s+1][o+1]];return r?q(g,h,y,c,d,a):{x:g.x*(1-d)*(1-a)+h.x*d*(1-a)+y.x*(1-d)*a+c.x*d*a,y:g.y*(1-d)*(1-a)+h.y*d*(1-a)+y.y*(1-d)*a+c.y*d*a}}function D(i){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(const s of i)t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:t,minY:n,maxX:r,maxY:o}}function te(i,t){const n=i.config??i.texture_transform??{},r=n.transform??{},o=i.textureSize??n.textureSize,s=x(o?.[0]),m=x(o?.[1]),u=t.width,d=t.height;if(!(s>0&&m>0&&u>0&&d>0&&(s!==u||m!==d)))return{...r};const g=s/u,h=m/d,y=Math.sqrt(g*h);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*y}:{},...typeof r.scale=="number"?{scale:r.scale*y}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*g}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*h}:{}}}function ne(i,t,n,r){if(r||!i.length)return i;const o=D(i),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},m=typeof t.scaleX=="number"?t.scaleX:typeof t.scale=="number"?t.scale:n,u=typeof t.scaleY=="number"?t.scaleY:typeof t.scale=="number"?t.scale:n,d=m/(n||1)*x(t.flipX,1),a=u/(n||1)*x(t.flipY,1),g=x(t.rotation)*Math.PI/180,h=Math.cos(g),y=Math.sin(g),c=i.map(l=>{const _=(l.x-s.x)*d,T=(l.y-s.y)*a;return{x:_*h-T*y+s.x,y:_*y+T*h+s.y}}),b=D(c),R=typeof t.translateX=="number"?t.translateX-b.minX:0,f=typeof t.translateY=="number"?t.translateY-b.minY:0;return R||f?c.map(l=>({x:l.x+R,y:l.y+f})):c}function ie(i,t){if(!Q(t))return null;const n=new Float32Array(t.vertices.length);for(let r=0;r<t.vertices.length;r+=2)n[r]=i.x+t.vertices[r],n[r+1]=i.y+t.vertices[r+1];return{vertices:n,uvs:new Float32Array(t.uvs),indices:new Uint16Array(t.indices)}}function N(i,t){const n=i.config??i.texture_transform??{},r=ie(i,n);if(r)return r;const o=te(i,t),s=K(n.mesh)?n.mesh:null;let m,u=x(o.baseScale,1);if(s){const f=J(s.grid);m=(l,_)=>ee(s,l,_,f)}else{const f=Math.max(i.width/t.width,i.height/t.height);u=typeof o.baseScale=="number"?o.baseScale:Math.min(1,f);const l=t.width*u,_=t.height*u,T=(i.width-l)/2,A=(i.height-_)/2;m=(B,ge)=>({x:T+l*B,y:A+_*ge})}const d=[],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;d.push(m(T,l)),a[g++]=T,a[g++]=l}}const h=ne(d,o,u,!!o.baked),y=new Float32Array(h.length*2);h.forEach((f,l)=>{y[l*2]=i.x+f.x,y[l*2+1]=i.y+f.y});const c=new Uint16Array(v*v*6);let b=0;const R=v+1;for(let f=0;f<v;f+=1)for(let l=0;l<v;l+=1){const _=f*R+l,T=_+1,A=_+R,B=A+1;c[b++]=_,c[b++]=T,c[b++]=A,c[b++]=T,c[b++]=B,c[b++]=A}return{vertices:y,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 e=O,re=\`#version 300 es
|
|
62
|
+
in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
|
|
63
|
+
out vec2 v_uv; out vec2 v_position;
|
|
64
|
+
void main() {
|
|
65
|
+
vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
|
|
66
|
+
gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
|
|
67
|
+
v_uv = a_uv; v_position = a_position;
|
|
68
|
+
}\`,oe=\`#version 300 es
|
|
69
|
+
precision highp float;
|
|
70
|
+
uniform sampler2D u_image; uniform sampler2D u_mask;
|
|
71
|
+
uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
|
|
72
|
+
in vec2 v_uv; in vec2 v_position; out vec4 out_color;
|
|
73
|
+
void main() {
|
|
74
|
+
vec4 source = texture(u_image, v_uv);
|
|
75
|
+
if (u_mode == 1) {
|
|
76
|
+
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
77
|
+
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
78
|
+
vec4 mask = texture(u_mask, maskUv);
|
|
79
|
+
source *= mask.a;
|
|
80
|
+
} else if (u_mode == 2) {
|
|
81
|
+
float tintAlpha = source.a * u_tint.a;
|
|
82
|
+
source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
|
|
83
|
+
} else if (u_mode == 3) {
|
|
84
|
+
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
85
|
+
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
86
|
+
vec4 mask = texture(u_mask, maskUv);
|
|
87
|
+
// Compose the premultiplied artwork over its fill before clipping. Applying
|
|
88
|
+
// mask alpha to each term separately would count translucent edges twice.
|
|
89
|
+
vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
|
|
90
|
+
source = (source + fill * (1.0 - source.a)) * mask.a;
|
|
91
|
+
}
|
|
92
|
+
if (u_mode == 4) source = vec4(u_tint.rgb * u_tint.a, u_tint.a);
|
|
93
|
+
else if (u_mode == 5) source += vec4(u_tint.rgb * u_tint.a, u_tint.a) * (1.0 - source.a);
|
|
94
|
+
out_color = source * u_opacity;
|
|
95
|
+
}\`;function G(i,t){const n=e.createShader(i);if(!n)throw new Error("Could not create WebGL shader");if(e.shaderSource(n,t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n)||"WebGL shader compilation failed");return n}const E=e.createProgram();if(!E)throw new Error("Could not create WebGL program");if(e.attachShader(E,G(e.VERTEX_SHADER,re)),e.attachShader(E,G(e.FRAGMENT_SHADER,oe)),e.linkProgram(E),!e.getProgramParameter(E,e.LINK_STATUS))throw new Error(e.getProgramInfoLog(E)||"WebGL program link failed");const Y=e.getAttribLocation(E,"a_position"),W=e.getAttribLocation(E,"a_uv"),se=e.getUniformLocation(E,"u_resolution"),ae=e.getUniformLocation(E,"u_image"),ce=e.getUniformLocation(E,"u_mask"),le=e.getUniformLocation(E,"u_mode"),ue=e.getUniformLocation(E,"u_opacity"),fe=e.getUniformLocation(E,"u_tint"),de=e.getUniformLocation(E,"u_mask_rect");function H(i,t=!1){if(t)return i;const n=e.createTexture();if(!n)throw new Error("Could not create WebGL texture");return e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i),n}function me(i){const t=String(i??"normal").toLowerCase();e.enable(e.BLEND),t==="multiply"||t==="2"?e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}function F(i){if(!i)return[1,1,1,1];const t=/^#([\\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 o=null;t&&(o=t[1].split("").map(m=>Number.parseInt(m+m,16))),n&&(o=[n[1].slice(0,2),n[1].slice(2,4),n[1].slice(4,6)].map(m=>Number.parseInt(m,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]);const s=r?.[4]===void 0?1:Math.max(0,Math.min(1,Number(r[4])));return o?[o[0]/255,o[1]/255,o[2]/255,s]:[1,1,1,1]}function z(i,t,n,r){return{vertices:new Float32Array([i,t,i+n,t,i,t+r,i+n,t+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function w(i,t,n={}){e.useProgram(E),me(n.blend);const r=e.createBuffer(),o=e.createBuffer(),s=e.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,i.vertices,e.STREAM_DRAW),e.enableVertexAttribArray(Y),e.vertexAttribPointer(Y,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,i.uvs,e.STATIC_DRAW),e.enableVertexAttribArray(W),e.vertexAttribPointer(W,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s),e.bufferData(e.ELEMENT_ARRAY_BUFFER,i.indices,e.STATIC_DRAW),e.activeTexture(e.TEXTURE0);const m=H(t,n.imageIsTexture);e.bindTexture(e.TEXTURE_2D,m),e.uniform1i(ae,0);let u=null;n.mask&&(e.activeTexture(e.TEXTURE1),u=H(n.mask),e.bindTexture(e.TEXTURE_2D,u),e.uniform1i(ce,1)),e.uniform2f(se,p.width,p.height),e.uniform1i(le,n.mode??0),e.uniform1f(ue,n.opacity??1),e.uniform4fv(fe,n.tint??[1,1,1,1]),e.uniform4fv(de,n.maskRect??[0,0,1,1]),e.drawElements(e.TRIANGLES,i.indices.length,e.UNSIGNED_SHORT,0),e.deleteBuffer(r),e.deleteBuffer(o),e.deleteBuffer(s),n.imageIsTexture||e.deleteTexture(m),u&&e.deleteTexture(u)}function he(i,t){const n=e.createTexture(),r=e.createFramebuffer();if(!n||!r)throw new Error("Could not allocate WebGL layer target");if(e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i,t,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw new Error("WebGL layer framebuffer is incomplete");return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),{texture:n,framebuffer:r}}async function ye(i){const t=i.areas.find(a=>a.name==="bg");if(!t)throw new Error("WebGL worker rendering requires a bg render area");const n=x(i.options.targetSize),r=n>0?n/Math.max(t.width,t.height):Math.max(.1,x(i.options.scale,1)),o=i.options.composition==="design-layer";p.width=Math.max(1,Math.round(t.width*r)),p.height=Math.max(1,Math.round(t.height*r)),e.viewport(0,0,p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const s=new Set,m=new Set;for(const a of i.areas)o&&!a.design||P(a,i.options.color)&&(a.image&&m.add(a.image),typeof a.texture=="string"&&m.add(a.texture));await Promise.all([...m].map(a=>k(a,s)));const u=a=>z(a.x*r,a.y*r,a.width*r,a.height*r);let d;try{for(const a of i.areas){if(o&&!a.design||!P(a,i.options.color))continue;const g=await k(a.image,s);if(!g)continue;if(!a.design){w(u(a),g,{blend:a.export?.blend,opacity:U(a.export?.opacity)});continue}const h=await k(a.texture,s),y=i.options.color??a.color,c=a.config??a.texture_transform??{},b=o?"normal":c.blendMode??"multiply",R=I(a.defaultPrintColor);if(R){d??=he(p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,d.framebuffer),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const f=c.textureSize??[a.width,a.height],l=N(a,h??{width:f[0],height:f[1]});for(let A=0;A<l.vertices.length;A++)l.vertices[A]*=r;w(l,g,{mode:4,tint:F(R),blend:"normal"});const _=c.blendMode??(y?"multiply":"normal");h?w(l,h,{mode:y?5:0,tint:F(y),blend:_}):y&&w(l,g,{mode:4,tint:F(y),blend:_}),e.bindFramebuffer(e.FRAMEBUFFER,null);const T=z(0,0,p.width,p.height);T.uvs=new Float32Array([0,1,1,1,0,0,1,0]),w(T,d.texture,{imageIsTexture:!0,mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h?.close();continue}if(h){const f=N(a,h);for(let l=0;l<f.vertices.length;l+=1)f.vertices[l]*=r;o?w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}):y?w(f,h,{mode:3,mask:g,tint:F(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:b,opacity:U(c.opacity)}):w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":c.blendMode,opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h.close()}else y&&w(u(a),g,{mode:2,tint:F(y),blend:b,opacity:U(c.opacity)})}e.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{d&&(e.deleteFramebuffer(d.framebuffer),e.deleteTexture(d.texture)),j(s)}}self.onmessage=async i=>{const t=i.data;if(t.type==="preload"){try{await Promise.all([...new Set(t.sources)].map(n=>L.has(n)?Promise.resolve():X.load(n,t.priority===!0))),self.postMessage({type:"preloaded",id:t.id})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}return}if(t.type==="render")try{self.postMessage({type:"result",id:t.id,blob:await ye(t)})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}}})();
|
|
96
|
+
`, y = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", b], { type: "text/javascript;charset=utf-8" });
|
|
97
|
+
function R(t) {
|
|
98
|
+
let e;
|
|
99
|
+
try {
|
|
100
|
+
if (e = y && (self.URL || self.webkitURL).createObjectURL(y), !e) throw "";
|
|
101
|
+
const r = new Worker(e, {
|
|
102
|
+
name: t?.name
|
|
103
|
+
});
|
|
104
|
+
return r.addEventListener("error", () => {
|
|
105
|
+
(self.URL || self.webkitURL).revokeObjectURL(e);
|
|
106
|
+
}), r;
|
|
107
|
+
} catch {
|
|
108
|
+
return new Worker(
|
|
109
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(b),
|
|
110
|
+
{
|
|
111
|
+
name: t?.name
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function d(t) {
|
|
117
|
+
if (!t) return t;
|
|
118
|
+
const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
|
|
119
|
+
if (!e) return t;
|
|
120
|
+
try {
|
|
121
|
+
return new URL(t, e).href;
|
|
122
|
+
} catch {
|
|
123
|
+
return t;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class E {
|
|
127
|
+
constructor() {
|
|
128
|
+
this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve();
|
|
129
|
+
}
|
|
130
|
+
static isSupported() {
|
|
131
|
+
return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
|
|
132
|
+
}
|
|
133
|
+
ensureWorker() {
|
|
134
|
+
if (this.worker) return this.worker;
|
|
135
|
+
if (!E.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
|
|
136
|
+
const e = new R();
|
|
137
|
+
return e.onmessage = (r) => {
|
|
138
|
+
const n = r.data, i = this.pending.get(n.id);
|
|
139
|
+
i && (this.pending.delete(n.id), n.type === "result" ? i.resolve(n.blob) : n.type === "preloaded" ? i.resolve(null) : i.reject(new Error(n.message)));
|
|
140
|
+
}, e.onerror = (r) => {
|
|
141
|
+
const n = r.filename ? ` (${r.filename}:${r.lineno}:${r.colno})` : "", i = r.error instanceof Error ? r.error : new Error(`${r.message || "Pixel-map worker failed"}${n}`);
|
|
142
|
+
this.pending.forEach(({ reject: s }) => s(i)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
143
|
+
}, e.onmessageerror = () => {
|
|
144
|
+
const r = new Error("Pixel-map worker could not deserialize its render payload");
|
|
145
|
+
this.pending.forEach(({ reject: n }) => n(r)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
146
|
+
}, this.worker = e, e;
|
|
147
|
+
}
|
|
148
|
+
/** Warm compressed resources without exporting Fabric or entering the GPU queue. */
|
|
149
|
+
async preloadAssets(e, r = !1) {
|
|
150
|
+
const n = [...new Set(e.filter(Boolean).map(d))];
|
|
151
|
+
if (!n.length) return;
|
|
152
|
+
const i = this.ensureWorker(), s = ++this.nextRequestId;
|
|
153
|
+
await new Promise((u, a) => {
|
|
154
|
+
this.pending.set(s, { resolve: u, reject: a });
|
|
155
|
+
try {
|
|
156
|
+
i.postMessage({ type: "preload", id: s, sources: n, priority: r });
|
|
157
|
+
} catch (c) {
|
|
158
|
+
this.pending.delete(s), a(c instanceof Error ? c : new Error(String(c)));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async onOffscreenRender(e, r = {}) {
|
|
163
|
+
const n = e.flatMap((a) => r.composition === "design-layer" && !a.design ? [] : w(a, r.color) ? [a.image, typeof a.texture == "string" ? a.texture : ""] : []), i = this.preloadAssets(n, !0);
|
|
164
|
+
i.catch(() => {
|
|
165
|
+
});
|
|
166
|
+
const s = async () => {
|
|
167
|
+
await i;
|
|
168
|
+
const a = this.ensureWorker(), c = ++this.nextRequestId, g = await Promise.all(e.map(async (o) => {
|
|
169
|
+
const l = o.texture instanceof ImageBitmap ? await createImageBitmap(o.texture) : typeof o.texture == "string" ? d(o.texture) : o.texture;
|
|
170
|
+
return {
|
|
171
|
+
...o,
|
|
172
|
+
image: d(o.image),
|
|
173
|
+
texture: l
|
|
174
|
+
};
|
|
175
|
+
})), x = g.map((o) => o.texture).filter((o) => o instanceof ImageBitmap);
|
|
176
|
+
return new Promise((o, l) => {
|
|
177
|
+
this.pending.set(c, { resolve: o, reject: l });
|
|
178
|
+
const _ = { type: "render", id: c, areas: g, options: r };
|
|
179
|
+
a.postMessage(_, x);
|
|
180
|
+
});
|
|
181
|
+
}, u = this.renderQueue.then(s, s);
|
|
182
|
+
return this.renderQueue = u.then(() => {
|
|
183
|
+
}, () => {
|
|
184
|
+
}), u;
|
|
185
|
+
}
|
|
186
|
+
destroy() {
|
|
187
|
+
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();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
A as M,
|
|
192
|
+
E as P,
|
|
193
|
+
w as a,
|
|
194
|
+
U as b,
|
|
195
|
+
L as h,
|
|
196
|
+
m as i,
|
|
197
|
+
h as n,
|
|
198
|
+
v as r
|
|
199
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
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";
|
|
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
|
+
let D = 0;
|
|
5
|
+
async function U(t, c) {
|
|
6
|
+
const d = t.config ?? t.texture_transform ?? {};
|
|
7
|
+
let i, a = d.textureSize?.[0] ?? t.width, r = d.textureSize?.[1] ?? t.height;
|
|
8
|
+
if (t.texture instanceof ImageBitmap)
|
|
9
|
+
i = t.texture, a = t.texture.width, r = t.texture.height;
|
|
10
|
+
else if (t.texture) {
|
|
11
|
+
const n = await L.load(t.texture);
|
|
12
|
+
i = n.baseTexture.resource.source, a = n.width, r = n.height;
|
|
13
|
+
}
|
|
14
|
+
if (![a, r].every((n) => Number.isFinite(n) && n > 0) || a * r > 16e6) throw new Error("Printable workspace exceeds safe dimensions");
|
|
15
|
+
const e = document.createElement("canvas");
|
|
16
|
+
e.width = Math.ceil(a), e.height = Math.ceil(r);
|
|
17
|
+
const l = e.getContext("2d");
|
|
18
|
+
if (!l) throw new Error("Canvas 2D is unavailable");
|
|
19
|
+
return c && (l.fillStyle = c, l.fillRect(0, 0, e.width, e.height)), i && l.drawImage(i, 0, 0, e.width, e.height), createImageBitmap(e, { premultiplyAlpha: "premultiply" });
|
|
20
|
+
}
|
|
21
|
+
async function j(t, c, d = {}) {
|
|
22
|
+
if (!c.some((r) => r.design && T(r.defaultPrintColor))) return t.onOffscreenRender(c, d);
|
|
23
|
+
const i = t, a = [];
|
|
24
|
+
try {
|
|
25
|
+
const r = [];
|
|
26
|
+
for (const e of c) {
|
|
27
|
+
const l = e.design && T(e.defaultPrintColor);
|
|
28
|
+
if (!l) {
|
|
29
|
+
r.push(e);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (![e.width, e.height].every((s) => Number.isFinite(s) && s > 0) || e.width * e.height > 16e6) throw new Error("Printable frame exceeds safe dimensions");
|
|
33
|
+
const n = e.config ?? e.texture_transform ?? {}, y = d.color ?? e.color, x = await U(e, y), u = `__print_base_${++D}`;
|
|
34
|
+
let m, p, f;
|
|
35
|
+
try {
|
|
36
|
+
p = await i.addSticker(x, {
|
|
37
|
+
...e,
|
|
38
|
+
name: u,
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0,
|
|
41
|
+
toFront: !1,
|
|
42
|
+
enable: !1,
|
|
43
|
+
config: { ...n, opacity: 1 }
|
|
44
|
+
});
|
|
45
|
+
const s = i.layers.get(u);
|
|
46
|
+
if (!s) throw new Error("Printable geometry could not be initialized");
|
|
47
|
+
const w = s.meshManager.meshInstance, o = s.meshManager.texMesh, E = o.material.texture.baseTexture;
|
|
48
|
+
E.alphaMode = I.PREMULTIPLIED_ALPHA, E.update();
|
|
49
|
+
const b = w.filters?.find((P) => P.maskSprite);
|
|
50
|
+
if (!b?.maskSprite) throw new Error("Printable mask is unavailable");
|
|
51
|
+
const A = b.maskSprite;
|
|
52
|
+
w.filters = null, b.destroy(), w.alpha = 1, o.alpha = 1, o.blendMode = B(n.blendMode ?? (y ? "multiply" : "normal")), o.visible = !!(e.texture || y);
|
|
53
|
+
const R = new v(S.WHITE);
|
|
54
|
+
R.tint = Number.parseInt(l.slice(1), 16);
|
|
55
|
+
const h = new F(o.geometry, R, void 0, o.drawMode);
|
|
56
|
+
h.position.copyFrom(o.position), h.scale.copyFrom(o.scale), h.pivot.copyFrom(o.pivot), h.rotation = o.rotation, h.blendMode = g.NORMAL, o.parent.addChildAt(h, o.parent.getChildIndex(o)), f = new O(A), f.blendMode = g.NORMAL, p.filters = [f], p.alpha = 1, m = _.create({ width: Math.ceil(e.width), height: Math.ceil(e.height), resolution: 1 }), i.app.renderer.render(p, { renderTexture: m, clear: !0 });
|
|
57
|
+
const C = i.app.renderer.extract.canvas(m), k = await new Promise((P) => C.toBlob(P, "image/png"));
|
|
58
|
+
if (!k) throw new Error("Could not export printable group");
|
|
59
|
+
const M = URL.createObjectURL(k);
|
|
60
|
+
a.push(M), await L.load({ src: M, loadParser: "loadTextures" }), r.push({
|
|
61
|
+
...e,
|
|
62
|
+
name: u,
|
|
63
|
+
design: 0,
|
|
64
|
+
image: M,
|
|
65
|
+
texture: "",
|
|
66
|
+
defaultPrintColor: null,
|
|
67
|
+
export: { blend: "normal", opacity: N(n.opacity) }
|
|
68
|
+
});
|
|
69
|
+
} finally {
|
|
70
|
+
const s = i.layers.get(u);
|
|
71
|
+
try {
|
|
72
|
+
s?.meshManager.dispose();
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
p?.destroy({ children: !0 });
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
f?.destroy(), m?.destroy(!0), i.layers.delete(u), S.from(x).destroy(!0), x.close();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return await t.onOffscreenRender(r, d);
|
|
83
|
+
} finally {
|
|
84
|
+
for (const r of a)
|
|
85
|
+
await L.unload(r).catch(() => {
|
|
86
|
+
}), URL.revokeObjectURL(r);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
j as renderPixiWithPrintBase
|
|
91
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BasePlate, Render, RenderArea } from '../contracts/api-design';
|
|
2
|
+
/** Explicit null stops inheritance. Missing fields keep existing host behavior. */
|
|
3
|
+
export declare function inheritedPrintColor(...values: Array<string | null | undefined>): string | null | undefined;
|
|
4
|
+
export declare function renderWithPrintColor<T extends Pick<Render, 'render_areas' | 'defaultPrintColor'>>(render: T, parent?: string | null): T;
|
|
5
|
+
export declare function basePlateWithPrintColor(basePlate: BasePlate): BasePlate;
|
|
6
|
+
export declare function hasPrintBase(areas: ReadonlyArray<Pick<RenderArea, 'design' | 'defaultPrintColor'>>): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface MaterialPreviewProps {
|
|
2
|
+
image?: string;
|
|
3
|
+
alt?: string;
|
|
4
|
+
loading?: boolean;
|
|
5
|
+
failed?: boolean;
|
|
6
|
+
onRetry?: () => void;
|
|
7
|
+
}
|
|
8
|
+
/** Supplier photographs are never a fallback for an active physical material policy. */
|
|
9
|
+
export declare function MaterialPreview({ image, alt, loading, failed, onRetry }: MaterialPreviewProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RenderArea } from '../contracts/api-design';
|
|
2
|
+
import type { StickerPlugin } from './sticker';
|
|
3
|
+
type Area = Omit<RenderArea, 'texture'> & {
|
|
4
|
+
texture?: string | ImageBitmap;
|
|
5
|
+
color?: string;
|
|
6
|
+
config?: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
type Options = NonNullable<Parameters<StickerPlugin['onOffscreenRender']>[1]>;
|
|
9
|
+
/** Group opt-in physical base + artwork before applying mask and opacity once. */
|
|
10
|
+
export declare function renderPixiWithPrintBase(plugin: StickerPlugin, areas: Area[], options?: Options): Promise<Blob | undefined>;
|
|
11
|
+
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/** Only explicit opaque HEX defaults create a physical printable surface. */
|
|
2
|
+
export declare function normalizeDefaultPrintColor(color: unknown): string | undefined;
|
|
1
3
|
/** Shared by resource preparation and the compositor: empty masks produce no pixels. */
|
|
2
4
|
export declare function renderLayerHasOutput(area: {
|
|
3
5
|
design: number;
|
|
4
6
|
texture?: unknown;
|
|
5
7
|
color?: string;
|
|
8
|
+
defaultPrintColor?: string | null;
|
|
6
9
|
}, color?: string, hasTexture?: boolean): boolean;
|