@unmade/text-renderer 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ce-adapter/index.cjs +1 -1
- package/dist/ce-adapter/index.js +61 -65
- package/dist/index.cjs +3 -3
- package/dist/index.js +458 -458
- package/dist/node/index.cjs +3 -3
- package/dist/node/index.js +458 -458
- package/dist/worker/index.cjs +12 -12
- package/dist/worker/index.js +745 -745
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function _(t){return t.type==="text"}function C(t){const i=t.getState().garment;return t.settings.garments.find(o=>o.slug===i)}function P(t,n){if(t.embellishment_positions)return t.embellishment_positions.find(i=>i.placement===n)}function M(t,n){const i=t.fonts.find(o=>o.id===n);if(i)return{id:i.id,fontUrl:i.font_url,fontFamily:i.font_family,letterSpacing:i.letter_spacing??0,letterSpacingOutline:i.letter_spacing_outline??0,outlineWidth:i.outline_width??0,fixedColours:i.fixed_colours}}function v(t,n,i,o,a){const{library:h}=a,u=[];for(const[s,g]of Object.entries(o)){if(g.type!=="text")continue;const d=g,{meta:e}=d;if(!e?.text)continue;const{libraryItemID:y}=d,c=h[y];if(!c||!_(c))continue;const f=e.font;if(f===void 0)continue;const S=M(c,f);if(!S)continue;const r=P(n,s);if(!r)continue;let x=null,b=null;if(e.colours&&c.palette!=null)try{const l=t.palettes.getUsedColours(c.palette,e.colours);x=l[0]??null,b=l[1]??null}catch(l){console.warn(`[extractTextPlacements] Colour resolution failed for ${s}:`,l)}const m=a.byId?.[s],p={vertical:"top",horizontal:"left"};if(m){const l=m;l.vertical_alignment&&(p.vertical=l.vertical_alignment),l.horizontal_alignment&&(p.horizontal=l.horizontal_alignment)}u.push({placementId:s,displayName:s,source:i,text:e.text,font:S,isCurved:e.isCurved??!1,isDistributed:e.isDistributed??!1,verticalAlignment:e.verticalAlignment??p.vertical,horizontalAlignment:e.horizontalAlignment??p.horizontal,rotation:e.rotation??0,spacing:e.spacing??null,fillColour:x,outlineColour:b,position:{width:r.width,height:r.height,physicalWidth:r.physical_width_decimal,physicalHeight:r.physical_height_decimal,physicalUnits:r.physical_size_units,baselinePath:r.baseline_path,rotation:r.rotation},userSetPhysicalSize:e.retainedPhysicalSize??null,fontMetrics:e.fontMetrics??{size:0,height:0,baseline:0,width:0},manufacturingMethod:e.manufacturing_method??""})}return u}function w(t){const n=t.getState(),i=C(t);if(!i)return console.warn("[extractTextPlacements] No matching garment found"),[];const o=[],a=n.vals?.placements,h=t.settings.placements;a&&h&&o.push(...v(t,i,"placements",a,h));const u=n.vals?.embellishments,s=t.settings.embellishments;return u&&s&&o.push(...v(t,i,"embellishments",u,s)),o.length===0&&console.warn("[extractTextPlacements] No text entries found in either placements or embellishments"),o}function z(t){return t==="center"?"centre":t}function A(t){let n=z(t.horizontalAlignment);t.isDistributed&&(n="distributed");let i;t.position.baselinePath?i={type:"custom",path:t.position.baselinePath}:t.isCurved?i="curved":i="flat";const o=t.userSetPhysicalSize?[t.userSetPhysicalSize[0],t.userSetPhysicalSize[1]]:t.fontMetrics.physicalFontSize!=null?t.fontMetrics.physicalFontSize:[t.position.physicalHeight,t.position.physicalUnits],h=!t.userSetPhysicalSize&&t.fontMetrics.physicalFontSize!=null&&t.fontMetrics.physicalHeight!=null&&t.fontMetrics.physicalUnits===t.position.physicalUnits&&t.fontMetrics.height>0?t.position.height/t.fontMetrics.height*t.fontMetrics.physicalHeight:t.position.physicalHeight,s={outlineWidth:t.outlineColour!=null?t.font.outlineWidth:0,letterSpacing:t.spacing?.letter_spacing??0,letterSpacingOutline:t.spacing?.letter_spacing_outline??0},g=t.fillColour?{hex:t.fillColour.hex,reference:t.fillColour.reference??void 0}:void 0,d=t.outlineColour?{hex:t.outlineColour.hex,reference:t.outlineColour.reference??void 0}:void 0;let e;if(t.font.fixedColours){const y={};for(const[c,f]of Object.entries(t.font.fixedColours))y[c]={hex:f.hex,reference:f.reference};e=y}return{text:t.text,fontUrl:t.font.fontUrl,physicalSize:o,fontSizeFallback:t.fontMetrics.size,boxDimensions:{width:t.position.width,height:t.position.height,physicalWidth:t.position.physicalWidth,physicalHeight:h,physicalUnits:t.position.physicalUnits},spacing:s,verticalAlignment:z(t.verticalAlignment),horizontalAlignment:n,baseline:i,fillColour:g,strokeColour:d,colourMap:e}}exports.extractTextPlacements=w;exports.mapStateToRendererOptions=A;
|
package/dist/ce-adapter/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _(t) {
|
|
2
2
|
return t.type === "text";
|
|
3
3
|
}
|
|
4
4
|
function C(t) {
|
|
@@ -11,7 +11,7 @@ function P(t, n) {
|
|
|
11
11
|
(i) => i.placement === n
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function M(t, n) {
|
|
15
15
|
const i = t.fonts.find((o) => o.id === n);
|
|
16
16
|
if (i)
|
|
17
17
|
return {
|
|
@@ -24,110 +24,106 @@ function w(t, n) {
|
|
|
24
24
|
fixedColours: i.fixed_colours
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const { library:
|
|
29
|
-
for (const [s,
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
27
|
+
function z(t, n, i, o, a) {
|
|
28
|
+
const { library: h } = a, u = [];
|
|
29
|
+
for (const [s, g] of Object.entries(o)) {
|
|
30
|
+
if (g.type !== "text") continue;
|
|
31
|
+
const d = g, { meta: e } = d;
|
|
32
32
|
if (!e?.text) continue;
|
|
33
|
-
const { libraryItemID:
|
|
34
|
-
if (!
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
41
|
-
let
|
|
42
|
-
if (e.colours &&
|
|
33
|
+
const { libraryItemID: y } = d, c = h[y];
|
|
34
|
+
if (!c || !_(c)) continue;
|
|
35
|
+
const f = e.font;
|
|
36
|
+
if (f === void 0) continue;
|
|
37
|
+
const x = M(c, f);
|
|
38
|
+
if (!x) continue;
|
|
39
|
+
const r = P(n, s);
|
|
40
|
+
if (!r) continue;
|
|
41
|
+
let S = null, b = null;
|
|
42
|
+
if (e.colours && c.palette != null)
|
|
43
43
|
try {
|
|
44
44
|
const l = t.palettes.getUsedColours(
|
|
45
|
-
|
|
45
|
+
c.palette,
|
|
46
46
|
e.colours
|
|
47
47
|
);
|
|
48
|
-
|
|
48
|
+
S = l[0] ?? null, b = l[1] ?? null;
|
|
49
49
|
} catch (l) {
|
|
50
50
|
console.warn(`[extractTextPlacements] Colour resolution failed for ${s}:`, l);
|
|
51
51
|
}
|
|
52
|
-
const
|
|
52
|
+
const m = a.byId?.[s], p = {
|
|
53
53
|
vertical: "top",
|
|
54
54
|
horizontal: "left"
|
|
55
55
|
};
|
|
56
|
-
if (
|
|
57
|
-
const l =
|
|
56
|
+
if (m) {
|
|
57
|
+
const l = m;
|
|
58
58
|
l.vertical_alignment && (p.vertical = l.vertical_alignment), l.horizontal_alignment && (p.horizontal = l.horizontal_alignment);
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
u.push({
|
|
61
61
|
placementId: s,
|
|
62
62
|
displayName: s,
|
|
63
63
|
source: i,
|
|
64
64
|
text: e.text,
|
|
65
|
-
font:
|
|
65
|
+
font: x,
|
|
66
66
|
isCurved: e.isCurved ?? !1,
|
|
67
67
|
isDistributed: e.isDistributed ?? !1,
|
|
68
68
|
verticalAlignment: e.verticalAlignment ?? p.vertical,
|
|
69
69
|
horizontalAlignment: e.horizontalAlignment ?? p.horizontal,
|
|
70
70
|
rotation: e.rotation ?? 0,
|
|
71
71
|
spacing: e.spacing ?? null,
|
|
72
|
-
fillColour:
|
|
73
|
-
outlineColour:
|
|
72
|
+
fillColour: S,
|
|
73
|
+
outlineColour: b,
|
|
74
74
|
position: {
|
|
75
|
-
width:
|
|
76
|
-
height:
|
|
77
|
-
physicalWidth:
|
|
78
|
-
physicalHeight:
|
|
79
|
-
physicalUnits:
|
|
80
|
-
baselinePath:
|
|
81
|
-
rotation:
|
|
75
|
+
width: r.width,
|
|
76
|
+
height: r.height,
|
|
77
|
+
physicalWidth: r.physical_width_decimal,
|
|
78
|
+
physicalHeight: r.physical_height_decimal,
|
|
79
|
+
physicalUnits: r.physical_size_units,
|
|
80
|
+
baselinePath: r.baseline_path,
|
|
81
|
+
rotation: r.rotation
|
|
82
82
|
},
|
|
83
83
|
userSetPhysicalSize: e.retainedPhysicalSize ?? null,
|
|
84
84
|
fontMetrics: e.fontMetrics ?? { size: 0, height: 0, baseline: 0, width: 0 },
|
|
85
85
|
manufacturingMethod: e.manufacturing_method ?? ""
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
return
|
|
88
|
+
return u;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function w(t) {
|
|
91
91
|
const n = t.getState(), i = C(t);
|
|
92
92
|
if (!i)
|
|
93
93
|
return console.warn("[extractTextPlacements] No matching garment found"), [];
|
|
94
|
-
const o = [],
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
return
|
|
94
|
+
const o = [], a = n.vals?.placements, h = t.settings.placements;
|
|
95
|
+
a && h && o.push(...z(t, i, "placements", a, h));
|
|
96
|
+
const u = n.vals?.embellishments, s = t.settings.embellishments;
|
|
97
|
+
return u && s && o.push(...z(t, i, "embellishments", u, s)), o.length === 0 && console.warn("[extractTextPlacements] No text entries found in either placements or embellishments"), o;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function v(t) {
|
|
100
100
|
return t === "center" ? "centre" : t;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
let n =
|
|
102
|
+
function A(t) {
|
|
103
|
+
let n = v(t.horizontalAlignment);
|
|
104
104
|
t.isDistributed && (n = "distributed");
|
|
105
105
|
let i;
|
|
106
106
|
t.position.baselinePath ? i = { type: "custom", path: t.position.baselinePath } : t.isCurved ? i = "curved" : i = "flat";
|
|
107
107
|
const o = t.userSetPhysicalSize ? [
|
|
108
108
|
t.userSetPhysicalSize[0],
|
|
109
109
|
t.userSetPhysicalSize[1]
|
|
110
|
-
] : t.fontMetrics.physicalFontSize != null ? t.fontMetrics.physicalFontSize : [t.position.physicalHeight, t.position.physicalUnits],
|
|
111
|
-
outlineWidth:
|
|
112
|
-
letterSpacing: t.spacing
|
|
113
|
-
letterSpacingOutline: t.spacing
|
|
114
|
-
}
|
|
115
|
-
outlineWidth: r ? t.font.outlineWidth : 0,
|
|
116
|
-
letterSpacing: t.font.letterSpacing,
|
|
117
|
-
letterSpacingOutline: t.font.letterSpacingOutline
|
|
118
|
-
}, c = t.fillColour ? {
|
|
110
|
+
] : t.fontMetrics.physicalFontSize != null ? t.fontMetrics.physicalFontSize : [t.position.physicalHeight, t.position.physicalUnits], h = !t.userSetPhysicalSize && t.fontMetrics.physicalFontSize != null && t.fontMetrics.physicalHeight != null && t.fontMetrics.physicalUnits === t.position.physicalUnits && t.fontMetrics.height > 0 ? t.position.height / t.fontMetrics.height * t.fontMetrics.physicalHeight : t.position.physicalHeight, s = {
|
|
111
|
+
outlineWidth: t.outlineColour != null ? t.font.outlineWidth : 0,
|
|
112
|
+
letterSpacing: t.spacing?.letter_spacing ?? 0,
|
|
113
|
+
letterSpacingOutline: t.spacing?.letter_spacing_outline ?? 0
|
|
114
|
+
}, g = t.fillColour ? {
|
|
119
115
|
hex: t.fillColour.hex,
|
|
120
116
|
reference: t.fillColour.reference ?? void 0
|
|
121
|
-
} : void 0,
|
|
117
|
+
} : void 0, d = t.outlineColour ? {
|
|
122
118
|
hex: t.outlineColour.hex,
|
|
123
119
|
reference: t.outlineColour.reference ?? void 0
|
|
124
120
|
} : void 0;
|
|
125
|
-
let
|
|
121
|
+
let e;
|
|
126
122
|
if (t.font.fixedColours) {
|
|
127
|
-
const
|
|
128
|
-
for (const [
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
const y = {};
|
|
124
|
+
for (const [c, f] of Object.entries(t.font.fixedColours))
|
|
125
|
+
y[c] = { hex: f.hex, reference: f.reference };
|
|
126
|
+
e = y;
|
|
131
127
|
}
|
|
132
128
|
return {
|
|
133
129
|
text: t.text,
|
|
@@ -138,21 +134,21 @@ function O(t) {
|
|
|
138
134
|
width: t.position.width,
|
|
139
135
|
height: t.position.height,
|
|
140
136
|
physicalWidth: t.position.physicalWidth,
|
|
141
|
-
physicalHeight:
|
|
137
|
+
physicalHeight: h,
|
|
142
138
|
physicalUnits: t.position.physicalUnits
|
|
143
139
|
},
|
|
144
|
-
spacing:
|
|
145
|
-
verticalAlignment:
|
|
140
|
+
spacing: s,
|
|
141
|
+
verticalAlignment: v(
|
|
146
142
|
t.verticalAlignment
|
|
147
143
|
),
|
|
148
144
|
horizontalAlignment: n,
|
|
149
145
|
baseline: i,
|
|
150
|
-
fillColour:
|
|
151
|
-
strokeColour:
|
|
152
|
-
colourMap:
|
|
146
|
+
fillColour: g,
|
|
147
|
+
strokeColour: d,
|
|
148
|
+
colourMap: e
|
|
153
149
|
};
|
|
154
150
|
}
|
|
155
151
|
export {
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
w as extractTextPlacements,
|
|
153
|
+
A as mapStateToRendererOptions
|
|
158
154
|
};
|