@printine/pod-editor 0.1.15 → 0.1.17
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/components/semi-renderer.d.ts +3 -1
- package/dist/{design-CZvEVkwi.js → design-BF_TXP1X.js} +1 -1
- package/dist/full-designer.js +1 -1
- package/dist/index.js +4 -4
- package/dist/{pixel-map-dSys7UAx.js → pixel-map-7kj7mLV1.js} +26 -29
- package/dist/renderer/pixel-map.d.ts +3 -0
- package/dist/renderer/render-layer-output.d.ts +1 -0
- package/dist/{semi-interact-editor-DfzphWy3.js → semi-interact-editor-CNcIzYjP.js} +358 -350
- package/dist/semi-renderer.js +1 -1
- package/dist/style.css +1 -1
- package/docs/COLOR_BLEND_FIX.md +23 -0
- package/docs/SEMI_RENDERER.md +7 -2
- package/package.json +1 -1
|
@@ -49,7 +49,9 @@ export interface PrintineSemiRendererProps {
|
|
|
49
49
|
preloadDesignData?: SemiRendererDesignData;
|
|
50
50
|
/** A cached object URL usable by host loading UI. Valid for this component's resource session. */
|
|
51
51
|
onAssetReady?: (source: string, url: string) => void;
|
|
52
|
-
/**
|
|
52
|
+
/** `global` preserves the legacy first-printable-color behavior; `placement` keeps fills local. */
|
|
53
|
+
colorMode?: 'global' | 'placement';
|
|
54
|
+
/** Explicit global fill override, including an empty string, in either color mode. */
|
|
53
55
|
backgroundColor?: string;
|
|
54
56
|
/** Resolution factor passed to the local Sticker renderer. */
|
|
55
57
|
scale?: number;
|
|
@@ -15,7 +15,7 @@ import { isSvg as Qp, inchToPixel as Vo } from "./engine/utils/measure.js";
|
|
|
15
15
|
import { a as ze, A as $c } from "./designer-store-Da9fICz8.js";
|
|
16
16
|
import { BLEND_MODES_MAP as zc, DEFAULT_FONT_SIZE as e1, ALIGN_TYPES as t1, ELEMENT_TITLE_MAP as Bc, LAYER_BLACK_LIST as n1 } from "./engine/constants.js";
|
|
17
17
|
import { StickerPlugin as r1, Sticker3DPlugin as Vc } from "./renderer/sticker.js";
|
|
18
|
-
import { P as Va } from "./pixel-map-
|
|
18
|
+
import { P as Va } from "./pixel-map-7kj7mLV1.js";
|
|
19
19
|
import jc from "lodash-es/throttle";
|
|
20
20
|
import { debounce as wi } from "lodash-es";
|
|
21
21
|
import { blobUrlToFile as o1, generateThumbImage as a1, xyToDirectionOffset as i1, directionOffsetToXY as s1, urlToBlob as bl, dataUrlToFile as wl } from "./engine/utils/common.js";
|
package/dist/full-designer.js
CHANGED
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-BF_TXP1X.js";
|
|
3
|
+
import { F as K, S as V, u as X } from "./design-BF_TXP1X.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-CNcIzYjP.js";
|
|
11
|
+
import { P as te } from "./pixel-map-7kj7mLV1.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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const h = `(function(){"use strict";class W{constructor(e=32*1024*1024,t=4,r){this.budget=e,this.concurrency=t,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(t=>{t.foreground=this.pinned.has(t.source)}),this.waiting.sort((t,r)=>Number(r.foreground)-Number(t.foreground)),this.trim()}trim(){for(const[e,t]of this.entries){if(this.bytes<=this.budget)break;!t.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=t.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 t=this.waiting.findIndex(s=>s.source===e&&!s.foreground);if(t<0)return;const[r]=this.waiting.splice(t,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(e,t){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:e,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),t&&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,t=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),t&&this.promote(e),r.ready;const o={ready:this.fetchBlob(e,t),bytes:0};return this.entries.set(e,o),o.ready.then(s=>{this.entries.get(e)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(e)===o&&this.entries.delete(e)}),o.ready}}function I(n,e,t=!!n.texture){return!n.design||t||!!e}const
|
|
1
|
+
const h = `(function(){"use strict";class W{constructor(e=32*1024*1024,t=4,r){this.budget=e,this.concurrency=t,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(t=>{t.foreground=this.pinned.has(t.source)}),this.waiting.sort((t,r)=>Number(r.foreground)-Number(t.foreground)),this.trim()}trim(){for(const[e,t]of this.entries){if(this.bytes<=this.budget)break;!t.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=t.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 t=this.waiting.findIndex(s=>s.source===e&&!s.foreground);if(t<0)return;const[r]=this.waiting.splice(t,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(e,t){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:e,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),t&&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,t=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),t&&this.promote(e),r.ready;const o={ready:this.fetchBlob(e,t),bytes:0};return this.entries.set(e,o),o.ready.then(s=>{this.entries.get(e)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(e)===o&&this.entries.delete(e)}),o.ready}}function I(n,e,t=!!n.texture){return!n.design||t||!!(e??n.color)}const w=44,H=32*1024*1024,T=new Map;let U=0;const N=new W;function x(n,e=0){return typeof n=="number"&&Number.isFinite(n)?n:e}function R(n,e=1){const t=x(n,e);return Math.max(0,Math.min(1,t>1?t/255:t))}function z(n=new Set){for(const[e,t]of T){if(U<=H)break;n.has(e)||!t.bitmap||(T.delete(e),U-=t.bytes,t.bitmap.close())}}async function M(n,e){if(!n)return null;if(n instanceof ImageBitmap)return n;e.add(n);let t=T.get(n);return t?(T.delete(n),T.set(n,t)):(t={bytes:0,promise:N.load(n).then(createImageBitmap)},T.set(n,t),t.promise.then(r=>{t.bitmap=r,t.bytes=r.width*r.height*4,U+=t.bytes}).catch(()=>T.delete(n))),t.promise}function V(n){const e=n;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(t=>Array.isArray(t)&&t.length===e.uLines.length)}function $(n){const e=n;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 t=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<t&&r<=65535)}function j(n){return n.some(e=>e.some(t=>["r","l","u","d"].some(r=>{const o=t[r];return typeof o=="object"&&!!o.moved})))}function K(n,e){const t=n[e];return t?.moved?{dx:x(t.dx)-x(t.baseDx),dy:x(t.dy)-x(t.baseDy)}:{dx:0,dy:0}}function k(n,e,t,r,o){const s=1-o;return{x:s**3*n.x+3*s*s*o*e.x+3*s*o*o*t.x+o**3*r.x,y:s**3*n.y+3*s*s*o*e.y+3*s*o*o*t.y+o**3*r.y}}function Q(n,e,t,r,o,s){const h=(u,g)=>({dx:(g.x-u.x)/3,dy:(g.y-u.y)/3}),c=(u,g,v)=>{const b=h(u,g),d=K(u,v);return{x:u.x+b.dx+d.dx,y:u.y+b.dy+d.dy}},a=k(n,c(n,e,"r"),c(e,n,"l"),e,o),l=k(t,c(t,r,"r"),c(r,t,"l"),r,o),m=k(n,c(n,t,"d"),c(t,n,"u"),t,s),y=k(e,c(e,r,"d"),c(r,e,"u"),r,s),f={x:n.x*(1-o)*(1-s)+e.x*o*(1-s)+t.x*(1-o)*s+r.x*o*s,y:n.y*(1-o)*(1-s)+e.y*o*(1-s)+t.y*(1-o)*s+r.y*o*s};return{x:a.x*(1-s)+l.x*s+m.x*(1-o)+y.x*o-f.x,y:a.y*(1-s)+l.y*s+m.y*(1-o)+y.y*o-f.y}}function P(n,e){if(n.length<=2)return 0;let t=0,r=n.length;const o=e-1e-9;for(;t<r;){const s=t+r>>1;n[s]<o?t=s+1:r=s}return Math.min(Math.max(t-1,0),n.length-2)}function J(n,e,t,r){const o=P(n.uLines,e),s=P(n.vLines,t),h=n.uLines[o+1]-n.uLines[o],c=n.vLines[s+1]-n.vLines[s],a=h>1e-9?(e-n.uLines[o])/h:0,l=c>1e-9?(t-n.vLines[s])/c:0,[m,y]=[n.grid[s][o],n.grid[s][o+1]],[f,u]=[n.grid[s+1][o],n.grid[s+1][o+1]];return r?Q(m,y,f,u,a,l):{x:m.x*(1-a)*(1-l)+y.x*a*(1-l)+f.x*(1-a)*l+u.x*a*l,y:m.y*(1-a)*(1-l)+y.y*a*(1-l)+f.y*(1-a)*l+u.y*a*l}}function F(n){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(const s of n)e=Math.min(e,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:e,minY:t,maxX:r,maxY:o}}function Z(n,e){const t=n.config??n.texture_transform??{},r=t.transform??{},o=n.textureSize??t.textureSize,s=x(o?.[0]),h=x(o?.[1]),c=e.width,a=e.height;if(!(s>0&&h>0&&c>0&&a>0&&(s!==c||h!==a)))return{...r};const m=s/c,y=h/a,f=Math.sqrt(m*y);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*f}:{},...typeof r.scale=="number"?{scale:r.scale*f}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*m}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*y}:{}}}function q(n,e,t,r){if(r||!n.length)return n;const o=F(n),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},h=typeof e.scaleX=="number"?e.scaleX:typeof e.scale=="number"?e.scale:t,c=typeof e.scaleY=="number"?e.scaleY:typeof e.scale=="number"?e.scale:t,a=h/(t||1)*x(e.flipX,1),l=c/(t||1)*x(e.flipY,1),m=x(e.rotation)*Math.PI/180,y=Math.cos(m),f=Math.sin(m),u=n.map(d=>{const _=(d.x-s.x)*a,E=(d.y-s.y)*l;return{x:_*y-E*f+s.x,y:_*f+E*y+s.y}}),g=F(u),v=typeof e.translateX=="number"?e.translateX-g.minX:0,b=typeof e.translateY=="number"?e.translateY-g.minY:0;return v||b?u.map(d=>({x:d.x+v,y:d.y+b})):u}function ee(n,e){if(!$(e))return null;const t=new Float32Array(e.vertices.length);for(let r=0;r<e.vertices.length;r+=2)t[r]=n.x+e.vertices[r],t[r+1]=n.y+e.vertices[r+1];return{vertices:t,uvs:new Float32Array(e.uvs),indices:new Uint16Array(e.indices)}}function te(n,e){const t=n.config??n.texture_transform??{},r=ee(n,t);if(r)return r;const o=Z(n,e),s=V(t.mesh)?t.mesh:null;let h,c=x(o.baseScale,1);if(s){const b=j(s.grid);h=(d,_)=>J(s,d,_,b)}else{const b=Math.max(n.width/e.width,n.height/e.height);c=typeof o.baseScale=="number"?o.baseScale:Math.min(1,b);const d=e.width*c,_=e.height*c,E=(n.width-d)/2,S=(n.height-_)/2;h=(B,he)=>({x:E+d*B,y:S+_*he})}const a=[],l=new Float32Array((w+1)**2*2);let m=0;for(let b=0;b<=w;b+=1){const d=b/w;for(let _=0;_<=w;_+=1){const E=_/w;a.push(h(E,d)),l[m++]=E,l[m++]=d}}const y=q(a,o,c,!!o.baked),f=new Float32Array(y.length*2);y.forEach((b,d)=>{f[d*2]=n.x+b.x,f[d*2+1]=n.y+b.y});const u=new Uint16Array(w*w*6);let g=0;const v=w+1;for(let b=0;b<w;b+=1)for(let d=0;d<w;d+=1){const _=b*v+d,E=_+1,S=_+v,B=S+1;u[g++]=_,u[g++]=E,u[g++]=S,u[g++]=E,u[g++]=B,u[g++]=S}return{vertices:f,uvs:l,indices:u}}const A=new OffscreenCanvas(1,1),X=A.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!X)throw new Error("WebGL2 is unavailable in the render worker");const i=X,ne=\`#version 300 es
|
|
2
2
|
in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
|
|
3
3
|
out vec2 v_uv; out vec2 v_position;
|
|
4
4
|
void main() {
|
|
@@ -24,16 +24,13 @@ void main() {
|
|
|
24
24
|
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
25
25
|
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
26
26
|
vec4 mask = texture(u_mask, maskUv);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
vec3 designColor = source.rgb * designMask;
|
|
32
|
-
vec3 fillColor = u_tint.rgb * maskAlpha;
|
|
33
|
-
source = vec4(designColor + fillColor * (1.0 - designAlpha), combinedAlpha);
|
|
27
|
+
// Compose the premultiplied artwork over its fill before clipping. Applying
|
|
28
|
+
// mask alpha to each term separately would count translucent edges twice.
|
|
29
|
+
vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
|
|
30
|
+
source = (source + fill * (1.0 - source.a)) * mask.a;
|
|
34
31
|
}
|
|
35
32
|
out_color = source * u_opacity;
|
|
36
|
-
}\`;function
|
|
33
|
+
}\`;function C(n,e){const t=i.createShader(n);if(!t)throw new Error("Could not create WebGL shader");if(i.shaderSource(t,e),i.compileShader(t),!i.getShaderParameter(t,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(t)||"WebGL shader compilation failed");return t}const p=i.createProgram();if(!p)throw new Error("Could not create WebGL program");if(i.attachShader(p,C(i.VERTEX_SHADER,ne)),i.attachShader(p,C(i.FRAGMENT_SHADER,ie)),i.linkProgram(p),!i.getProgramParameter(p,i.LINK_STATUS))throw new Error(i.getProgramInfoLog(p)||"WebGL program link failed");const D=i.getAttribLocation(p,"a_position"),Y=i.getAttribLocation(p,"a_uv"),re=i.getUniformLocation(p,"u_resolution"),oe=i.getUniformLocation(p,"u_image"),se=i.getUniformLocation(p,"u_mask"),ae=i.getUniformLocation(p,"u_mode"),ce=i.getUniformLocation(p,"u_opacity"),le=i.getUniformLocation(p,"u_tint"),ue=i.getUniformLocation(p,"u_mask_rect");function O(n,e=!1){if(e)return n;const t=i.createTexture();if(!t)throw new Error("Could not create WebGL texture");return i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),t}function fe(n){const e=String(n??"normal").toLowerCase();i.enable(i.BLEND),e==="multiply"||e==="2"?i.blendFuncSeparate(i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA):i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)}function G(n){if(!n)return[1,1,1,1];const e=/^#([\\da-f]{3})$/i.exec(n),t=/^#([\\da-f]{6})$/i.exec(n),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)/i.exec(n);let o=null;return e&&(o=e[1].split("").map(s=>Number.parseInt(s+s,16))),t&&(o=[t[1].slice(0,2),t[1].slice(2,4),t[1].slice(4,6)].map(s=>Number.parseInt(s,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]),o?[o[0]/255,o[1]/255,o[2]/255,1]:[1,1,1,1]}function de(n,e,t,r){return{vertices:new Float32Array([n,e,n+t,e,n,e+r,n+t,e+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function L(n,e,t={}){i.useProgram(p),fe(t.blend);const r=i.createBuffer(),o=i.createBuffer(),s=i.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");i.bindBuffer(i.ARRAY_BUFFER,r),i.bufferData(i.ARRAY_BUFFER,n.vertices,i.STREAM_DRAW),i.enableVertexAttribArray(D),i.vertexAttribPointer(D,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,o),i.bufferData(i.ARRAY_BUFFER,n.uvs,i.STATIC_DRAW),i.enableVertexAttribArray(Y),i.vertexAttribPointer(Y,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s),i.bufferData(i.ELEMENT_ARRAY_BUFFER,n.indices,i.STATIC_DRAW),i.activeTexture(i.TEXTURE0);const h=O(e,t.imageIsTexture);i.bindTexture(i.TEXTURE_2D,h),i.uniform1i(oe,0);let c=null;t.mask&&(i.activeTexture(i.TEXTURE1),c=O(t.mask),i.bindTexture(i.TEXTURE_2D,c),i.uniform1i(se,1)),i.uniform2f(re,A.width,A.height),i.uniform1i(ae,t.mode??0),i.uniform1f(ce,t.opacity??1),i.uniform4fv(le,t.tint??[1,1,1,1]),i.uniform4fv(ue,t.maskRect??[0,0,1,1]),i.drawElements(i.TRIANGLES,n.indices.length,i.UNSIGNED_SHORT,0),i.deleteBuffer(r),i.deleteBuffer(o),i.deleteBuffer(s),t.imageIsTexture||i.deleteTexture(h),c&&i.deleteTexture(c)}async function me(n){const e=n.areas.find(a=>a.name==="bg");if(!e)throw new Error("WebGL worker rendering requires a bg render area");const t=x(n.options.targetSize),r=t>0?t/Math.max(e.width,e.height):Math.max(.1,x(n.options.scale,1)),o=n.options.composition==="design-layer";A.width=Math.max(1,Math.round(e.width*r)),A.height=Math.max(1,Math.round(e.height*r)),i.viewport(0,0,A.width,A.height),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT);const s=new Set,h=new Set;for(const a of n.areas)o&&!a.design||I(a,n.options.color)&&(a.image&&h.add(a.image),typeof a.texture=="string"&&h.add(a.texture));await Promise.all([...h].map(a=>M(a,s)));const c=a=>de(a.x*r,a.y*r,a.width*r,a.height*r);try{for(const a of n.areas){if(o&&!a.design||!I(a,n.options.color))continue;const l=await M(a.image,s);if(!l)continue;if(!a.design){L(c(a),l,{blend:a.export?.blend,opacity:R(a.export?.opacity)});continue}const m=await M(a.texture,s),y=n.options.color??a.color,f=a.config??a.texture_transform??{},u=o?"normal":f.blendMode??"multiply";if(m){const g=te(a,m);for(let v=0;v<g.vertices.length;v+=1)g.vertices[v]*=r;o?L(g,m,{mode:1,mask:l,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:R(f.opacity)}):y?L(g,m,{mode:3,mask:l,tint:G(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:u,opacity:R(f.opacity)}):L(g,m,{mode:1,mask:l,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":f.blendMode,opacity:R(f.opacity)}),a.texture instanceof ImageBitmap&&m.close()}else y&&L(c(a),l,{mode:2,tint:G(y),blend:u,opacity:R(f.opacity)})}i.finish();try{return await A.convertToBlob({type:n.options.format??"image/png",quality:n.options.quality??.9})}catch{return A.convertToBlob({type:"image/png"})}}finally{z(s)}}self.onmessage=async n=>{const e=n.data;if(e.type==="preload"){try{await Promise.all([...new Set(e.sources)].map(t=>T.has(t)?Promise.resolve():N.load(t,e.priority===!0))),self.postMessage({type:"preloaded",id:e.id})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}return}if(e.type==="render")try{self.postMessage({type:"result",id:e.id,blob:await me(e)})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}}})();
|
|
37
34
|
`, m = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", h], { type: "text/javascript;charset=utf-8" });
|
|
38
35
|
function b(i) {
|
|
39
36
|
let e;
|
|
@@ -55,7 +52,7 @@ function b(i) {
|
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
function x(i, e, t = !!i.texture) {
|
|
58
|
-
return !i.design || t || !!e;
|
|
55
|
+
return !i.design || t || !!(e ?? i.color);
|
|
59
56
|
}
|
|
60
57
|
function f(i) {
|
|
61
58
|
if (!i) return i;
|
|
@@ -67,7 +64,7 @@ function f(i) {
|
|
|
67
64
|
return i;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
class
|
|
67
|
+
class p {
|
|
71
68
|
constructor() {
|
|
72
69
|
this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve();
|
|
73
70
|
}
|
|
@@ -76,14 +73,14 @@ class g {
|
|
|
76
73
|
}
|
|
77
74
|
ensureWorker() {
|
|
78
75
|
if (this.worker) return this.worker;
|
|
79
|
-
if (!
|
|
76
|
+
if (!p.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
|
|
80
77
|
const e = new b();
|
|
81
78
|
return e.onmessage = (t) => {
|
|
82
|
-
const r = t.data,
|
|
83
|
-
|
|
79
|
+
const r = t.data, o = this.pending.get(r.id);
|
|
80
|
+
o && (this.pending.delete(r.id), r.type === "result" ? o.resolve(r.blob) : r.type === "preloaded" ? o.resolve(null) : o.reject(new Error(r.message)));
|
|
84
81
|
}, e.onerror = (t) => {
|
|
85
|
-
const r = t.filename ? ` (${t.filename}:${t.lineno}:${t.colno})` : "",
|
|
86
|
-
this.pending.forEach(({ reject: a }) => a(
|
|
82
|
+
const r = t.filename ? ` (${t.filename}:${t.lineno}:${t.colno})` : "", o = t.error instanceof Error ? t.error : new Error(`${t.message || "Pixel-map worker failed"}${r}`);
|
|
83
|
+
this.pending.forEach(({ reject: a }) => a(o)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
87
84
|
}, e.onmessageerror = () => {
|
|
88
85
|
const t = new Error("Pixel-map worker could not deserialize its render payload");
|
|
89
86
|
this.pending.forEach(({ reject: r }) => r(t)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
@@ -93,34 +90,34 @@ class g {
|
|
|
93
90
|
async preloadAssets(e, t = !1) {
|
|
94
91
|
const r = [...new Set(e.filter(Boolean).map(f))];
|
|
95
92
|
if (!r.length) return;
|
|
96
|
-
const
|
|
97
|
-
await new Promise((u,
|
|
98
|
-
this.pending.set(a, { resolve: u, reject:
|
|
93
|
+
const o = this.ensureWorker(), a = ++this.nextRequestId;
|
|
94
|
+
await new Promise((u, s) => {
|
|
95
|
+
this.pending.set(a, { resolve: u, reject: s });
|
|
99
96
|
try {
|
|
100
|
-
|
|
97
|
+
o.postMessage({ type: "preload", id: a, sources: r, priority: t });
|
|
101
98
|
} catch (c) {
|
|
102
|
-
this.pending.delete(a),
|
|
99
|
+
this.pending.delete(a), s(c instanceof Error ? c : new Error(String(c)));
|
|
103
100
|
}
|
|
104
101
|
});
|
|
105
102
|
}
|
|
106
103
|
async onOffscreenRender(e, t = {}) {
|
|
107
|
-
const r = e.flatMap((
|
|
108
|
-
|
|
104
|
+
const r = e.flatMap((s) => t.composition === "design-layer" && !s.design ? [] : x(s, t.color) ? [s.image, typeof s.texture == "string" ? s.texture : ""] : []), o = this.preloadAssets(r, !0);
|
|
105
|
+
o.catch(() => {
|
|
109
106
|
});
|
|
110
107
|
const a = async () => {
|
|
111
|
-
await
|
|
112
|
-
const
|
|
108
|
+
await o;
|
|
109
|
+
const s = this.ensureWorker(), c = ++this.nextRequestId, d = await Promise.all(e.map(async (n) => {
|
|
113
110
|
const l = n.texture instanceof ImageBitmap ? await createImageBitmap(n.texture) : typeof n.texture == "string" ? f(n.texture) : n.texture;
|
|
114
111
|
return {
|
|
115
112
|
...n,
|
|
116
113
|
image: f(n.image),
|
|
117
114
|
texture: l
|
|
118
115
|
};
|
|
119
|
-
})),
|
|
116
|
+
})), y = d.map((n) => n.texture).filter((n) => n instanceof ImageBitmap);
|
|
120
117
|
return new Promise((n, l) => {
|
|
121
118
|
this.pending.set(c, { resolve: n, reject: l });
|
|
122
|
-
const
|
|
123
|
-
|
|
119
|
+
const g = { type: "render", id: c, areas: d, options: t };
|
|
120
|
+
s.postMessage(g, y);
|
|
124
121
|
});
|
|
125
122
|
}, u = this.renderQueue.then(a, a);
|
|
126
123
|
return this.renderQueue = u.then(() => {
|
|
@@ -132,6 +129,6 @@ class g {
|
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
export {
|
|
135
|
-
|
|
132
|
+
p as P,
|
|
136
133
|
x as r
|
|
137
134
|
};
|
|
@@ -5,9 +5,12 @@ import type { RenderArea } from '../contracts/api-design';
|
|
|
5
5
|
*/
|
|
6
6
|
export type PixelMapArea = Omit<RenderArea, 'texture'> & {
|
|
7
7
|
texture?: string | ImageBitmap;
|
|
8
|
+
/** This printable placement's fill; never inferred from another placement. */
|
|
9
|
+
color?: string;
|
|
8
10
|
config?: Record<string, unknown>;
|
|
9
11
|
};
|
|
10
12
|
export interface PixelMapRenderOptions {
|
|
13
|
+
/** Explicit global override; omission preserves each area's own fill. */
|
|
11
14
|
color?: string;
|
|
12
15
|
scale?: number;
|
|
13
16
|
/** Longest output edge in CSS-independent pixels. */
|