@unmade/text-renderer 0.1.7 → 0.1.9

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