@unmade/text-renderer 0.1.10 → 0.1.11
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 +23 -23
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function C(t){return t.type==="text"}function P(t){const i=t.getState().garment;return t.settings.garments.find(s=>s.slug===i)}function M(t,o){if(t.embellishment_positions)return t.embellishment_positions.find(i=>i.placement===o)}function w(t,o){const i=t.fonts.find(s=>s.id===o);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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function C(t){return t.type==="text"}function P(t){const i=t.getState().garment;return t.settings.garments.find(s=>s.slug===i)}function M(t,o){if(t.embellishment_positions)return t.embellishment_positions.find(i=>i.placement===o)}function w(t,o){const i=t.fonts.find(s=>s.id===o);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,o,i,s,a){const{library:h}=a,u=[];for(const[l,g]of Object.entries(s)){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(c))continue;const f=e.font;if(f===void 0)continue;const S=w(c,f);if(!S)continue;const r=M(o,l);if(!r)continue;let x=null,b=null;if(e.colours&&c.palette!=null)try{const n=t.palettes.getUsedColours(c.palette,e.colours);x=n[0]??null,b=n[1]??null}catch(n){console.warn(`[extractTextPlacements] Colour resolution failed for ${l}:`,n)}const m=a.byId?.[l],p={vertical:"top",horizontal:"left"};if(m){const n=m;n.vertical_alignment&&(p.vertical=n.vertical_alignment),n.horizontal_alignment&&(p.horizontal=n.horizontal_alignment)}u.push({placementId:l,displayName:l,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:(()=>{const n=e.fontMetrics??{size:0,height:0,baseline:0,width:0},_=n.physicalFontSize||(n.physicalHeight!=null&&n.physicalHeight>0&&n.physicalUnits!=null?[n.physicalHeight,n.physicalUnits]:void 0);return{...n,physicalFontSize:_}})(),manufacturingMethod:e.manufacturing_method??""})}return u}function U(t){const o=t.getState(),i=P(t);if(!i)return console.warn("[extractTextPlacements] No matching garment found"),[];const s=[],a=o.vals?.placements,h=t.settings.placements;a&&h&&s.push(...v(t,i,"placements",a,h));const u=o.vals?.embellishments,l=t.settings.embellishments;return u&&l&&s.push(...v(t,i,"embellishments",u,l)),s.length===0&&console.warn("[extractTextPlacements] No text entries found in either placements or embellishments"),s}function z(t){return t==="center"?"centre":t}function A(t){let o=z(t.horizontalAlignment);t.isDistributed&&(o="distributed");let i;t.position.baselinePath?i={type:"custom",path:t.position.baselinePath}:t.isCurved?i="curved":i="flat";const s=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.isCurved&&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,l={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:s,fontSizeFallback:t.fontMetrics.size,boxDimensions:{width:t.position.width,height:t.position.height,physicalWidth:t.position.physicalWidth,physicalHeight:h,physicalUnits:t.position.physicalUnits},spacing:l,verticalAlignment:z(t.verticalAlignment),horizontalAlignment:o,baseline:i,fillColour:g,strokeColour:d,colourMap:e}}exports.extractTextPlacements=U;exports.mapStateToRendererOptions=A;
|
package/dist/ce-adapter/index.js
CHANGED
|
@@ -3,16 +3,16 @@ function C(t) {
|
|
|
3
3
|
}
|
|
4
4
|
function P(t) {
|
|
5
5
|
const i = t.getState().garment;
|
|
6
|
-
return t.settings.garments.find((
|
|
6
|
+
return t.settings.garments.find((o) => o.slug === i);
|
|
7
7
|
}
|
|
8
|
-
function M(t,
|
|
8
|
+
function M(t, s) {
|
|
9
9
|
if (t.embellishment_positions)
|
|
10
10
|
return t.embellishment_positions.find(
|
|
11
|
-
(i) => i.placement ===
|
|
11
|
+
(i) => i.placement === s
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
|
-
function w(t,
|
|
15
|
-
const i = t.fonts.find((
|
|
14
|
+
function w(t, s) {
|
|
15
|
+
const i = t.fonts.find((o) => o.id === s);
|
|
16
16
|
if (i)
|
|
17
17
|
return {
|
|
18
18
|
id: i.id,
|
|
@@ -24,19 +24,19 @@ function w(t, o) {
|
|
|
24
24
|
fixedColours: i.fixed_colours
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function z(t,
|
|
28
|
-
const { library:
|
|
29
|
-
for (const [l, g] of Object.entries(
|
|
27
|
+
function z(t, s, i, o, h) {
|
|
28
|
+
const { library: a } = h, u = [];
|
|
29
|
+
for (const [l, g] of Object.entries(o)) {
|
|
30
30
|
if (g.type !== "text") continue;
|
|
31
31
|
const d = g, { meta: e } = d;
|
|
32
32
|
if (!e?.text) continue;
|
|
33
|
-
const { libraryItemID: y } = d, c =
|
|
33
|
+
const { libraryItemID: y } = d, c = a[y];
|
|
34
34
|
if (!c || !C(c)) continue;
|
|
35
35
|
const f = e.font;
|
|
36
36
|
if (f === void 0) continue;
|
|
37
37
|
const S = w(c, f);
|
|
38
38
|
if (!S) continue;
|
|
39
|
-
const r = M(
|
|
39
|
+
const r = M(s, l);
|
|
40
40
|
if (!r) continue;
|
|
41
41
|
let x = null, b = null;
|
|
42
42
|
if (e.colours && c.palette != null)
|
|
@@ -49,7 +49,7 @@ function z(t, o, i, s, a) {
|
|
|
49
49
|
} catch (n) {
|
|
50
50
|
console.warn(`[extractTextPlacements] Colour resolution failed for ${l}:`, n);
|
|
51
51
|
}
|
|
52
|
-
const m =
|
|
52
|
+
const m = h.byId?.[l], p = {
|
|
53
53
|
vertical: "top",
|
|
54
54
|
horizontal: "left"
|
|
55
55
|
};
|
|
@@ -91,26 +91,26 @@ function z(t, o, i, s, a) {
|
|
|
91
91
|
return u;
|
|
92
92
|
}
|
|
93
93
|
function U(t) {
|
|
94
|
-
const
|
|
94
|
+
const s = t.getState(), i = P(t);
|
|
95
95
|
if (!i)
|
|
96
96
|
return console.warn("[extractTextPlacements] No matching garment found"), [];
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const u =
|
|
100
|
-
return u && l &&
|
|
97
|
+
const o = [], h = s.vals?.placements, a = t.settings.placements;
|
|
98
|
+
h && a && o.push(...z(t, i, "placements", h, a));
|
|
99
|
+
const u = s.vals?.embellishments, l = t.settings.embellishments;
|
|
100
|
+
return u && l && o.push(...z(t, i, "embellishments", u, l)), o.length === 0 && console.warn("[extractTextPlacements] No text entries found in either placements or embellishments"), o;
|
|
101
101
|
}
|
|
102
102
|
function v(t) {
|
|
103
103
|
return t === "center" ? "centre" : t;
|
|
104
104
|
}
|
|
105
105
|
function A(t) {
|
|
106
|
-
let
|
|
107
|
-
t.isDistributed && (
|
|
106
|
+
let s = v(t.horizontalAlignment);
|
|
107
|
+
t.isDistributed && (s = "distributed");
|
|
108
108
|
let i;
|
|
109
109
|
t.position.baselinePath ? i = { type: "custom", path: t.position.baselinePath } : t.isCurved ? i = "curved" : i = "flat";
|
|
110
|
-
const
|
|
110
|
+
const o = t.userSetPhysicalSize ? [
|
|
111
111
|
t.userSetPhysicalSize[0],
|
|
112
112
|
t.userSetPhysicalSize[1]
|
|
113
|
-
] : t.fontMetrics.physicalFontSize != null ? t.fontMetrics.physicalFontSize : [t.position.physicalHeight, t.position.physicalUnits],
|
|
113
|
+
] : t.fontMetrics.physicalFontSize != null ? t.fontMetrics.physicalFontSize : [t.position.physicalHeight, t.position.physicalUnits], a = !t.userSetPhysicalSize && t.fontMetrics.physicalFontSize != null && !t.isCurved && 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, l = {
|
|
114
114
|
outlineWidth: t.outlineColour != null ? t.font.outlineWidth : 0,
|
|
115
115
|
letterSpacing: t.spacing?.letter_spacing ?? 0,
|
|
116
116
|
letterSpacingOutline: t.spacing?.letter_spacing_outline ?? 0
|
|
@@ -131,20 +131,20 @@ function A(t) {
|
|
|
131
131
|
return {
|
|
132
132
|
text: t.text,
|
|
133
133
|
fontUrl: t.font.fontUrl,
|
|
134
|
-
physicalSize:
|
|
134
|
+
physicalSize: o,
|
|
135
135
|
fontSizeFallback: t.fontMetrics.size,
|
|
136
136
|
boxDimensions: {
|
|
137
137
|
width: t.position.width,
|
|
138
138
|
height: t.position.height,
|
|
139
139
|
physicalWidth: t.position.physicalWidth,
|
|
140
|
-
physicalHeight:
|
|
140
|
+
physicalHeight: a,
|
|
141
141
|
physicalUnits: t.position.physicalUnits
|
|
142
142
|
},
|
|
143
143
|
spacing: l,
|
|
144
144
|
verticalAlignment: v(
|
|
145
145
|
t.verticalAlignment
|
|
146
146
|
),
|
|
147
|
-
horizontalAlignment:
|
|
147
|
+
horizontalAlignment: s,
|
|
148
148
|
baseline: i,
|
|
149
149
|
fillColour: g,
|
|
150
150
|
strokeColour: d,
|