@unmade/text-renderer 0.1.4 → 0.1.5
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/ce-types.d.ts +169 -0
- package/dist/ce-adapter/extractTextPlacements.d.ts +11 -0
- package/dist/ce-adapter/index.cjs +1 -0
- package/dist/ce-adapter/index.d.ts +12 -0
- package/dist/ce-adapter/index.js +157 -0
- package/dist/ce-adapter/mapStateToRendererOptions.d.ts +13 -0
- package/dist/ce-adapter/types.d.ts +56 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +343 -343
- package/dist/node/index.cjs +3 -3
- package/dist/node/index.js +343 -343
- package/dist/worker/index.cjs +8 -8
- package/dist/worker/index.js +628 -628
- package/package.json +15 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for @unmade/configuration-engine
|
|
3
|
+
*
|
|
4
|
+
* CE doesn't ship .d.ts files. These types cover the subset of the
|
|
5
|
+
* factory API and editor shape that the CE adapter needs.
|
|
6
|
+
*/
|
|
7
|
+
export interface EditorPaletteColour {
|
|
8
|
+
id: number;
|
|
9
|
+
hex: string;
|
|
10
|
+
name: string;
|
|
11
|
+
display_name?: string;
|
|
12
|
+
reference?: string | null;
|
|
13
|
+
extra?: object | null;
|
|
14
|
+
categories?: string[];
|
|
15
|
+
lab?: [number, number, number];
|
|
16
|
+
}
|
|
17
|
+
export interface EditorPalette {
|
|
18
|
+
id: number;
|
|
19
|
+
name: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
colours: EditorPaletteColour[];
|
|
22
|
+
extended_palette_id?: number;
|
|
23
|
+
extendedPalette?: EditorPalette;
|
|
24
|
+
categories?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface EditorGarment {
|
|
27
|
+
slug: string;
|
|
28
|
+
size: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
panels_svg?: string;
|
|
31
|
+
embellishment_positions?: EmbellishmentPosition[];
|
|
32
|
+
}
|
|
33
|
+
export interface EmbellishmentPosition {
|
|
34
|
+
placement: string;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
physical_width: number;
|
|
38
|
+
physical_height: number;
|
|
39
|
+
physical_size_units: string;
|
|
40
|
+
baseline_path?: string;
|
|
41
|
+
rotation: number;
|
|
42
|
+
variant?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TextLibraryItemFont {
|
|
45
|
+
id: number;
|
|
46
|
+
font_url: string;
|
|
47
|
+
font_family: string;
|
|
48
|
+
letter_spacing?: number;
|
|
49
|
+
letter_spacing_outline?: number;
|
|
50
|
+
outline_width?: number;
|
|
51
|
+
fixed_colours?: Record<string, {
|
|
52
|
+
reference: string;
|
|
53
|
+
hex: string;
|
|
54
|
+
id: string;
|
|
55
|
+
text: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
export interface TextLibraryItem {
|
|
59
|
+
id: string;
|
|
60
|
+
type: 'text';
|
|
61
|
+
fonts: TextLibraryItemFont[];
|
|
62
|
+
palette?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface PlacementLibraryItem {
|
|
65
|
+
id: string;
|
|
66
|
+
type: string;
|
|
67
|
+
palette?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface BasePlacementSettings {
|
|
70
|
+
manufacturing_methods?: {
|
|
71
|
+
name: string;
|
|
72
|
+
}[];
|
|
73
|
+
vertical_alignment?: string;
|
|
74
|
+
horizontal_alignment?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface PlacementsSettings {
|
|
77
|
+
byId: Record<string, BasePlacementSettings>;
|
|
78
|
+
library: Record<string, PlacementLibraryItem | TextLibraryItem>;
|
|
79
|
+
}
|
|
80
|
+
export interface CombinedEditorSettings {
|
|
81
|
+
editor: string;
|
|
82
|
+
mixins: string[];
|
|
83
|
+
garments: EditorGarment[];
|
|
84
|
+
palettes: number[];
|
|
85
|
+
allPalettes: Record<number, EditorPalette>;
|
|
86
|
+
endpoints: {
|
|
87
|
+
palettes: string;
|
|
88
|
+
[key: string]: string | undefined;
|
|
89
|
+
};
|
|
90
|
+
placements?: PlacementsSettings;
|
|
91
|
+
embellishments?: PlacementsSettings;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
export interface BasePlacementState {
|
|
95
|
+
type: string;
|
|
96
|
+
libraryItemID: string;
|
|
97
|
+
meta?: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
export interface EditorStateVals {
|
|
100
|
+
placements?: Record<string, BasePlacementState>;
|
|
101
|
+
embellishments?: Record<string, BasePlacementState>;
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}
|
|
104
|
+
export interface EditorState {
|
|
105
|
+
garment?: string;
|
|
106
|
+
vals?: EditorStateVals;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
export interface Palettes {
|
|
110
|
+
byId: Record<string, unknown>;
|
|
111
|
+
getColours(paletteId: number): EditorPaletteColour[];
|
|
112
|
+
getUsedColours(paletteId: number, ids: (number | null)[]): (EditorPaletteColour | null)[];
|
|
113
|
+
getExtendedColours(paletteId: number): EditorPaletteColour[];
|
|
114
|
+
}
|
|
115
|
+
export interface PlacementPositionResult {
|
|
116
|
+
placement: string;
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
width: number;
|
|
120
|
+
height: number;
|
|
121
|
+
dimensionsForCanvas: {
|
|
122
|
+
width: number;
|
|
123
|
+
height: number;
|
|
124
|
+
x: number;
|
|
125
|
+
y: number;
|
|
126
|
+
};
|
|
127
|
+
variant: string;
|
|
128
|
+
panel: string;
|
|
129
|
+
rotation: boolean;
|
|
130
|
+
physical_width: number;
|
|
131
|
+
physical_height: number;
|
|
132
|
+
physical_width_decimal: string;
|
|
133
|
+
physical_height_decimal: string;
|
|
134
|
+
physical_size_units: string;
|
|
135
|
+
}
|
|
136
|
+
export interface EditorVariant {
|
|
137
|
+
name: string;
|
|
138
|
+
placements: string[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Editor instance returned by CE's factory.
|
|
142
|
+
*
|
|
143
|
+
* The exact shape depends on which mixins are applied at runtime.
|
|
144
|
+
* We type the parts the CE adapter needs and treat the rest as opaque.
|
|
145
|
+
* Uses Element rather than SVGElement for cross-environment compatibility.
|
|
146
|
+
*/
|
|
147
|
+
export interface ConfigEditor {
|
|
148
|
+
getState(): EditorState & {
|
|
149
|
+
vals: NonNullable<EditorState['vals']>;
|
|
150
|
+
};
|
|
151
|
+
palettes: Palettes;
|
|
152
|
+
settings: CombinedEditorSettings;
|
|
153
|
+
placements?: {
|
|
154
|
+
initialise(): Promise<void>;
|
|
155
|
+
getAssetsAsSVGElements(state: EditorState, manufacturingMethod: string): Promise<Record<string, {
|
|
156
|
+
asset: Element;
|
|
157
|
+
position: PlacementPositionResult;
|
|
158
|
+
}>>;
|
|
159
|
+
};
|
|
160
|
+
embellishments?: {
|
|
161
|
+
initialise(): Promise<void>;
|
|
162
|
+
getAssetsAsSVGElements(state: EditorState, manufacturingMethod: string): Promise<Record<string, {
|
|
163
|
+
asset: Element;
|
|
164
|
+
position: PlacementPositionResult;
|
|
165
|
+
}>>;
|
|
166
|
+
};
|
|
167
|
+
getVariants?(): EditorVariant[];
|
|
168
|
+
getCurrentVariant?(): string;
|
|
169
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigEditor } from './ce-types';
|
|
2
|
+
import { LoadedTextPlacement } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Extract text placements from a loaded config editor instance.
|
|
5
|
+
*
|
|
6
|
+
* Reads the editor state, resolves fonts and colours from settings and
|
|
7
|
+
* palettes, and returns a structured array of text placements ready for
|
|
8
|
+
* rendering or comparison. Processes both the placements and embellishments
|
|
9
|
+
* buckets.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractTextPlacements(editor: ConfigEditor): LoadedTextPlacement[];
|
|
@@ -0,0 +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 x=null,S=null;if(e.colours&&g.palette!=null)try{const l=t.palettes.getUsedColours(g.palette,e.colours);x=l[0]??null,S=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:x,outlineColour:S,position:{width:a.width,height:a.height,physicalWidth:a.physical_width,physicalHeight:a.physical_height,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,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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CE Adapter for @unmade/text-renderer
|
|
3
|
+
*
|
|
4
|
+
* Utilities for extracting text placement state from a loaded
|
|
5
|
+
* @unmade/configuration-engine editor instance and mapping it to
|
|
6
|
+
* renderer options. Intended for use in server-side comparison pipelines
|
|
7
|
+
* and any environment that bridges CE state to the text-renderer.
|
|
8
|
+
*/
|
|
9
|
+
export { extractTextPlacements } from './extractTextPlacements';
|
|
10
|
+
export { mapStateToRendererOptions } from './mapStateToRendererOptions';
|
|
11
|
+
export type { BasePlacementSettings, BasePlacementState, CombinedEditorSettings, ConfigEditor, EditorGarment, EditorPalette, EditorPaletteColour, EditorState, EditorStateVals, EditorVariant, EmbellishmentPosition, Palettes, PlacementLibraryItem, PlacementPositionResult, PlacementsSettings, TextLibraryItem, TextLibraryItemFont, } from './ce-types';
|
|
12
|
+
export type { LoadedTextPlacement, TextPlacementFont, TextPlacementPosition, TextPlacementSpacing, } from './types';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
function z(t) {
|
|
2
|
+
return t.type === "text";
|
|
3
|
+
}
|
|
4
|
+
function C(t) {
|
|
5
|
+
const i = t.getState().garment;
|
|
6
|
+
return t.settings.garments.find((o) => o.slug === i);
|
|
7
|
+
}
|
|
8
|
+
function P(t, n) {
|
|
9
|
+
if (t.embellishment_positions)
|
|
10
|
+
return t.embellishment_positions.find(
|
|
11
|
+
(i) => i.placement === n
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function w(t, n) {
|
|
15
|
+
const i = t.fonts.find((o) => o.id === n);
|
|
16
|
+
if (i)
|
|
17
|
+
return {
|
|
18
|
+
id: i.id,
|
|
19
|
+
fontUrl: i.font_url,
|
|
20
|
+
fontFamily: i.font_family,
|
|
21
|
+
letterSpacing: i.letter_spacing ?? 0,
|
|
22
|
+
letterSpacingOutline: i.letter_spacing_outline ?? 0,
|
|
23
|
+
outlineWidth: i.outline_width ?? 0,
|
|
24
|
+
fixedColours: i.fixed_colours
|
|
25
|
+
};
|
|
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;
|
|
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)
|
|
43
|
+
try {
|
|
44
|
+
const l = t.palettes.getUsedColours(
|
|
45
|
+
g.palette,
|
|
46
|
+
e.colours
|
|
47
|
+
);
|
|
48
|
+
x = l[0] ?? null, S = l[1] ?? null;
|
|
49
|
+
} catch (l) {
|
|
50
|
+
console.warn(`[extractTextPlacements] Colour resolution failed for ${s}:`, l);
|
|
51
|
+
}
|
|
52
|
+
const b = r.byId?.[s], p = {
|
|
53
|
+
vertical: "top",
|
|
54
|
+
horizontal: "left"
|
|
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);
|
|
59
|
+
}
|
|
60
|
+
c.push({
|
|
61
|
+
placementId: s,
|
|
62
|
+
displayName: s,
|
|
63
|
+
source: i,
|
|
64
|
+
text: e.text,
|
|
65
|
+
font: m,
|
|
66
|
+
isCurved: e.isCurved ?? !1,
|
|
67
|
+
isDistributed: e.isDistributed ?? !1,
|
|
68
|
+
verticalAlignment: e.verticalAlignment ?? p.vertical,
|
|
69
|
+
horizontalAlignment: e.horizontalAlignment ?? p.horizontal,
|
|
70
|
+
rotation: e.rotation ?? 0,
|
|
71
|
+
spacing: e.spacing ?? null,
|
|
72
|
+
fillColour: x,
|
|
73
|
+
outlineColour: S,
|
|
74
|
+
position: {
|
|
75
|
+
width: a.width,
|
|
76
|
+
height: a.height,
|
|
77
|
+
physicalWidth: a.physical_width,
|
|
78
|
+
physicalHeight: a.physical_height,
|
|
79
|
+
physicalUnits: a.physical_size_units,
|
|
80
|
+
baselinePath: a.baseline_path,
|
|
81
|
+
rotation: a.rotation
|
|
82
|
+
},
|
|
83
|
+
userSetPhysicalSize: e.retainedPhysicalSize ?? null,
|
|
84
|
+
fontMetrics: e.fontMetrics ?? { size: 0, height: 0, baseline: 0, width: 0 },
|
|
85
|
+
manufacturingMethod: e.manufacturing_method ?? ""
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return c;
|
|
89
|
+
}
|
|
90
|
+
function A(t) {
|
|
91
|
+
const n = t.getState(), i = C(t);
|
|
92
|
+
if (!i)
|
|
93
|
+
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;
|
|
98
|
+
}
|
|
99
|
+
function _(t) {
|
|
100
|
+
return t === "center" ? "centre" : t;
|
|
101
|
+
}
|
|
102
|
+
function O(t) {
|
|
103
|
+
let n = _(t.horizontalAlignment);
|
|
104
|
+
t.isDistributed && (n = "distributed");
|
|
105
|
+
let i;
|
|
106
|
+
t.position.baselinePath ? i = { type: "custom", path: t.position.baselinePath } : t.isCurved ? i = "curved" : i = "flat";
|
|
107
|
+
const o = t.userSetPhysicalSize ? [
|
|
108
|
+
t.userSetPhysicalSize[0],
|
|
109
|
+
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 ? {
|
|
119
|
+
hex: t.fillColour.hex,
|
|
120
|
+
reference: t.fillColour.reference ?? void 0
|
|
121
|
+
} : void 0, s = t.outlineColour ? {
|
|
122
|
+
hex: t.outlineColour.hex,
|
|
123
|
+
reference: t.outlineColour.reference ?? void 0
|
|
124
|
+
} : void 0;
|
|
125
|
+
let h;
|
|
126
|
+
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;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
text: t.text,
|
|
134
|
+
fontUrl: t.font.fontUrl,
|
|
135
|
+
physicalSize: o,
|
|
136
|
+
boxDimensions: {
|
|
137
|
+
width: t.position.width,
|
|
138
|
+
height: t.position.height,
|
|
139
|
+
physicalWidth: t.position.physicalWidth,
|
|
140
|
+
physicalHeight: t.position.physicalHeight,
|
|
141
|
+
physicalUnits: t.position.physicalUnits
|
|
142
|
+
},
|
|
143
|
+
spacing: u,
|
|
144
|
+
verticalAlignment: _(
|
|
145
|
+
t.verticalAlignment
|
|
146
|
+
),
|
|
147
|
+
horizontalAlignment: n,
|
|
148
|
+
baseline: i,
|
|
149
|
+
fillColour: c,
|
|
150
|
+
strokeColour: s,
|
|
151
|
+
colourMap: h
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
A as extractTextPlacements,
|
|
156
|
+
O as mapStateToRendererOptions
|
|
157
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GetRenderedTextOptions } from '../types';
|
|
2
|
+
import { LoadedTextPlacement } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Map a LoadedTextPlacement to GetRenderedTextOptions for the text-renderer.
|
|
5
|
+
*
|
|
6
|
+
* Handles the key differences between config-engine and text-renderer:
|
|
7
|
+
* - American to British English ('center' -> 'centre')
|
|
8
|
+
* - isDistributed flag -> horizontalAlignment: 'distributed'
|
|
9
|
+
* - isCurved flag -> baseline: 'curved'
|
|
10
|
+
* - baselinePath -> baseline: { type: 'custom', path }
|
|
11
|
+
* - snake_case spacing -> camelCase spacing
|
|
12
|
+
*/
|
|
13
|
+
export declare function mapStateToRendererOptions(placement: LoadedTextPlacement): GetRenderedTextOptions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EditorPaletteColour } from './ce-types';
|
|
2
|
+
export interface TextPlacementPosition {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
physicalWidth: number;
|
|
6
|
+
physicalHeight: number;
|
|
7
|
+
physicalUnits: string;
|
|
8
|
+
baselinePath?: string;
|
|
9
|
+
rotation: number;
|
|
10
|
+
}
|
|
11
|
+
export interface TextPlacementFont {
|
|
12
|
+
id: number;
|
|
13
|
+
fontUrl: string;
|
|
14
|
+
fontFamily: string;
|
|
15
|
+
letterSpacing: number;
|
|
16
|
+
letterSpacingOutline: number;
|
|
17
|
+
outlineWidth: number;
|
|
18
|
+
fixedColours?: Record<string, {
|
|
19
|
+
reference: string;
|
|
20
|
+
hex: string;
|
|
21
|
+
id: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface TextPlacementSpacing {
|
|
26
|
+
letter_spacing: number;
|
|
27
|
+
letter_spacing_outline: number;
|
|
28
|
+
line_height?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface LoadedTextPlacement {
|
|
31
|
+
placementId: string;
|
|
32
|
+
displayName: string;
|
|
33
|
+
source: 'placements' | 'embellishments';
|
|
34
|
+
text: string;
|
|
35
|
+
font: TextPlacementFont;
|
|
36
|
+
isCurved: boolean;
|
|
37
|
+
isDistributed: boolean;
|
|
38
|
+
verticalAlignment: string;
|
|
39
|
+
horizontalAlignment: string;
|
|
40
|
+
rotation: number;
|
|
41
|
+
spacing: TextPlacementSpacing | null;
|
|
42
|
+
fillColour: EditorPaletteColour | null;
|
|
43
|
+
outlineColour: EditorPaletteColour | null;
|
|
44
|
+
position: TextPlacementPosition;
|
|
45
|
+
userSetPhysicalSize: [number, string] | null;
|
|
46
|
+
fontMetrics: {
|
|
47
|
+
size: number;
|
|
48
|
+
height: number;
|
|
49
|
+
baseline: number;
|
|
50
|
+
width: number;
|
|
51
|
+
physicalHeight?: number;
|
|
52
|
+
physicalUnits?: string;
|
|
53
|
+
physicalFontSize?: [number, 'mm' | 'in'];
|
|
54
|
+
};
|
|
55
|
+
manufacturingMethod: string;
|
|
56
|
+
}
|