@unmade/text-renderer 1.1.0 → 1.2.0

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.
Files changed (68) hide show
  1. package/README.md +184 -0
  2. package/dist/__vite-browser-external-oLchLuMx.js +7 -0
  3. package/dist/baselines/index.d.ts +59 -0
  4. package/dist/ce-adapter/index.cjs +1 -1
  5. package/dist/ce-adapter/index.js +154 -152
  6. package/dist/constants.d.ts +5 -0
  7. package/dist/fitting/index.d.ts +86 -0
  8. package/dist/glyph/svg-glyph-converter.d.ts +42 -0
  9. package/dist/helpers/bbox.d.ts +34 -0
  10. package/dist/helpers/point.d.ts +17 -0
  11. package/dist/helpers/xml.d.ts +1 -0
  12. package/dist/index.d.ts +17 -249
  13. package/dist/index.js +2221 -2005
  14. package/dist/loading/createLoadedFont.d.ts +53 -0
  15. package/dist/loading/index.d.ts +4 -0
  16. package/dist/measuring/conversion.d.ts +2 -0
  17. package/dist/measuring/index.d.ts +28 -0
  18. package/dist/node/baselines/index.d.ts +59 -0
  19. package/dist/node/ce-adapter/ce-types.d.ts +171 -0
  20. package/dist/node/ce-adapter/extractTextPlacements.d.ts +11 -0
  21. package/dist/node/ce-adapter/index.d.ts +12 -0
  22. package/dist/node/ce-adapter/mapStateToRendererOptions.d.ts +13 -0
  23. package/dist/node/ce-adapter/types.d.ts +56 -0
  24. package/dist/node/constants.d.ts +5 -0
  25. package/dist/node/fitting/index.d.ts +86 -0
  26. package/dist/node/glyph/svg-glyph-converter.d.ts +42 -0
  27. package/dist/node/helpers/bbox.d.ts +34 -0
  28. package/dist/node/helpers/point.d.ts +17 -0
  29. package/dist/node/helpers/xml.d.ts +1 -0
  30. package/dist/node/index.d.ts +17 -249
  31. package/dist/node/index.js +940 -948
  32. package/dist/node/loading/createLoadedFont.d.ts +53 -0
  33. package/dist/node/loading/index.d.ts +4 -0
  34. package/dist/node/measuring/conversion.d.ts +2 -0
  35. package/dist/node/measuring/index.d.ts +28 -0
  36. package/dist/node/renderText.d.ts +5 -0
  37. package/dist/node/rendering/index.d.ts +42 -0
  38. package/dist/node/svg/index.d.ts +11 -0
  39. package/dist/node/types.d.ts +75 -0
  40. package/dist/renderText.d.ts +5 -0
  41. package/dist/rendering/index.d.ts +42 -0
  42. package/dist/rolldown-runtime-DtPi1Y-2.js +13 -0
  43. package/dist/svg/index.d.ts +11 -0
  44. package/dist/types.d.ts +75 -0
  45. package/dist/worker/baselines/index.d.ts +59 -0
  46. package/dist/worker/ce-adapter/ce-types.d.ts +171 -0
  47. package/dist/worker/ce-adapter/extractTextPlacements.d.ts +11 -0
  48. package/dist/worker/ce-adapter/index.d.ts +12 -0
  49. package/dist/worker/ce-adapter/mapStateToRendererOptions.d.ts +13 -0
  50. package/dist/worker/ce-adapter/types.d.ts +56 -0
  51. package/dist/worker/constants.d.ts +5 -0
  52. package/dist/worker/fitting/index.d.ts +86 -0
  53. package/dist/worker/glyph/svg-glyph-converter.d.ts +42 -0
  54. package/dist/worker/helpers/bbox.d.ts +34 -0
  55. package/dist/worker/helpers/point.d.ts +17 -0
  56. package/dist/worker/helpers/xml.d.ts +1 -0
  57. package/dist/worker/index.d.ts +17 -249
  58. package/dist/worker/index.js +8346 -9728
  59. package/dist/worker/loading/createLoadedFont.d.ts +53 -0
  60. package/dist/worker/loading/index.d.ts +4 -0
  61. package/dist/worker/measuring/conversion.d.ts +2 -0
  62. package/dist/worker/measuring/index.d.ts +28 -0
  63. package/dist/worker/renderText.d.ts +5 -0
  64. package/dist/worker/rendering/index.d.ts +42 -0
  65. package/dist/worker/svg/index.d.ts +11 -0
  66. package/dist/worker/types.d.ts +75 -0
  67. package/package.json +19 -11
  68. package/dist/__vite-browser-external-l0sNRNKZ.js +0 -1
@@ -0,0 +1,53 @@
1
+ import { Face, Font } from 'harfbuzzjs';
2
+ export interface SVGGlyphData {
3
+ svg: string;
4
+ viewbox: string;
5
+ }
6
+ export interface LoadedFont {
7
+ unitsPerEm: number;
8
+ names: {
9
+ fontFamily: string;
10
+ };
11
+ svgGlyphs?: Map<number, SVGGlyphData>;
12
+ charToGlyph(char: string): {
13
+ index: number;
14
+ advanceWidth: number;
15
+ name: string;
16
+ getBoundingBox(): {
17
+ x1: number;
18
+ y1: number;
19
+ x2: number;
20
+ y2: number;
21
+ };
22
+ };
23
+ getPath(text: string, x: number, y: number, fontSize: number, options?: {
24
+ drawSVG?: boolean;
25
+ }): {
26
+ getBoundingBox(): {
27
+ x1: number;
28
+ y1: number;
29
+ x2: number;
30
+ y2: number;
31
+ };
32
+ toPathData(decimals?: number): string;
33
+ };
34
+ getPaths(text: string, x: number, y: number, fontSize: number, options?: {
35
+ drawSVG?: boolean;
36
+ }): Array<{
37
+ getBoundingBox(): {
38
+ x1: number;
39
+ y1: number;
40
+ x2: number;
41
+ y2: number;
42
+ };
43
+ toPathData(decimals?: number): string;
44
+ }>;
45
+ }
46
+ export declare function boundsFromPath(pathData: string): {
47
+ x1: number;
48
+ y1: number;
49
+ x2: number;
50
+ y2: number;
51
+ } | null;
52
+ export declare function transformPath(pathData: string, scaleX: number, scaleY: number, dx: number): string;
53
+ export declare function createLoadedFont(face: Face, font: Font, familyName: string, svgGlyphs?: Map<number, SVGGlyphData>): LoadedFont;
@@ -0,0 +1,4 @@
1
+ import { createLoadedFont, LoadedFont } from './createLoadedFont';
2
+ export { createLoadedFont, type LoadedFont };
3
+ export declare const getFontCache: () => Map<string, LoadedFont>;
4
+ export declare const loadFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
@@ -0,0 +1,2 @@
1
+ export declare function millimetersToInches(value: number): number;
2
+ export declare function inchesToMillimeters(value: number): number;
@@ -0,0 +1,28 @@
1
+ import { LoadedFont } from '../loading';
2
+ import { BoxDimensions, PhysicalSize, TextSpacing } from '../types';
3
+ export interface GetFontSizeFromPhysicalSizeOptions {
4
+ font: LoadedFont;
5
+ boxDimensions: BoxDimensions;
6
+ physicalSize: PhysicalSize;
7
+ spacing?: TextSpacing;
8
+ }
9
+ export interface GetTextMetricsAtFontSizeOptions {
10
+ font: LoadedFont;
11
+ text: string;
12
+ fontSize: number;
13
+ spacing?: TextSpacing;
14
+ }
15
+ /**
16
+ * This is the character we use to calculate font sizes
17
+ * when fixed physical text height is set for a placement.
18
+ *
19
+ * The 'I' character is used because of its flat top and bottom.
20
+ * https://en.wikipedia.org/wiki/Cap_height
21
+ */
22
+ export declare const getStandardCharacter: (font: LoadedFont) => string;
23
+ export declare const getFontSizeFromPhysicalSize: ({ font, boxDimensions, physicalSize, spacing, }: GetFontSizeFromPhysicalSizeOptions) => number;
24
+ export declare const getTextMetricsAtFontSize: ({ font, text, fontSize, spacing, }: GetTextMetricsAtFontSizeOptions) => {
25
+ width: number;
26
+ height: number;
27
+ baseline: number;
28
+ };
@@ -0,0 +1,5 @@
1
+ import { RenderTextOptions } from './types';
2
+ /**
3
+ * Synchronous text renderer. Requires a pre-loaded font.
4
+ */
5
+ export declare const renderText: (options: RenderTextOptions) => string;
@@ -0,0 +1,42 @@
1
+ import { LoadedFont } from '../loading';
2
+ import { ColourMap, GlyphFill, HorizontalTextAlignmentValues, PlatformMatrix, TextSpacing } from '../types';
3
+ export interface SvgGlyphEntry {
4
+ content: string;
5
+ viewBox: string;
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ glyphIndex: number;
11
+ }
12
+ export interface PathEntry {
13
+ attributes: {
14
+ d: string;
15
+ 'data-character': string;
16
+ transform: string;
17
+ };
18
+ path: unknown;
19
+ matrix: PlatformMatrix;
20
+ glyphData: {
21
+ index: number;
22
+ bbox: {
23
+ x1: number;
24
+ y1: number;
25
+ x2: number;
26
+ y2: number;
27
+ };
28
+ };
29
+ svgGlyph?: SvgGlyphEntry;
30
+ fills?: GlyphFill[];
31
+ }
32
+ export declare const fontUnitsToPixels: (value: number, fontSize: number, unitsPerEm: number) => number;
33
+ export interface GetTextAsPathDataOptions {
34
+ font: LoadedFont;
35
+ baselinePath: string;
36
+ text: string;
37
+ fontSize: number;
38
+ spacing?: TextSpacing;
39
+ horizontalAlignment?: HorizontalTextAlignmentValues;
40
+ colourMap?: ColourMap;
41
+ }
42
+ export declare const getTextAsPathData: ({ font, baselinePath, text, fontSize, spacing, horizontalAlignment, colourMap, }: GetTextAsPathDataOptions) => PathEntry[];
@@ -0,0 +1,11 @@
1
+ import { PathEntry } from '../rendering';
2
+ import { BoxDimensions, ColourInfo, TextSpacing } from '../types';
3
+ export interface AssembleSvgOptions {
4
+ boxDimensions: BoxDimensions;
5
+ paths: PathEntry[];
6
+ spacing?: TextSpacing;
7
+ fontSize?: number;
8
+ fillColour?: ColourInfo;
9
+ strokeColour?: ColourInfo;
10
+ }
11
+ export declare const assembleSvg: ({ boxDimensions, paths, spacing, fontSize, fillColour, strokeColour, }: AssembleSvgOptions) => string;
@@ -0,0 +1,75 @@
1
+ import { DOMMatrix } from '@unmade/platform';
2
+ import { LoadedFont } from './loading';
3
+ /** The platform's matrix, which is not the same shape as the DOM's DOMMatrix. */
4
+ export type PlatformMatrix = InstanceType<typeof DOMMatrix>;
5
+ export type MeasurementUnits = 'mm' | 'in';
6
+ export type BoxDimensions = {
7
+ width: number;
8
+ height: number;
9
+ physicalWidth: number;
10
+ physicalHeight: number;
11
+ physicalUnits: MeasurementUnits;
12
+ };
13
+ export type VerticalTextAlignmentValues = 'centre' | 'top' | 'bottom';
14
+ export type HorizontalTextAlignmentValues = 'left' | 'centre' | 'right' | 'distributed';
15
+ export type PhysicalSize = [height: number, units: MeasurementUnits];
16
+ export type BaselineType = 'flat' | 'curved';
17
+ export type BaselineConfig = {
18
+ type: 'flat';
19
+ } | {
20
+ type: 'curved';
21
+ } | {
22
+ type: 'custom';
23
+ path: string;
24
+ };
25
+ export interface ColourInfo {
26
+ readonly hex: string;
27
+ readonly reference?: string;
28
+ }
29
+ export interface GlyphFill {
30
+ readonly pathData: string;
31
+ readonly colour: ColourInfo;
32
+ }
33
+ /** Maps original hex colour → replacement ColourInfo. */
34
+ export type ColourMap = Readonly<Record<string, ColourInfo>>;
35
+ export interface TextSpacing {
36
+ readonly outlineWidth: number;
37
+ readonly letterSpacing: number;
38
+ readonly letterSpacingOutline: number;
39
+ }
40
+ /** Options for synchronous renderText (font already loaded). */
41
+ export interface RenderTextOptions {
42
+ text: string;
43
+ font: LoadedFont;
44
+ physicalSize: PhysicalSize;
45
+ /** When provided, bypasses the physicalSize → font size calculation. */
46
+ fontSize?: number;
47
+ boxDimensions: BoxDimensions;
48
+ spacing?: TextSpacing;
49
+ verticalAlignment?: VerticalTextAlignmentValues;
50
+ baseline?: BaselineType | BaselineConfig;
51
+ horizontalAlignment?: HorizontalTextAlignmentValues;
52
+ fillColour?: ColourInfo;
53
+ strokeColour?: ColourInfo;
54
+ colourMap?: ColourMap;
55
+ }
56
+ /** Options for async getRenderedText (loads font from URL). */
57
+ export interface GetRenderedTextOptions {
58
+ text: string;
59
+ fontUrl: string;
60
+ physicalSize: PhysicalSize;
61
+ /**
62
+ * Fallback font size (in pixels) to use if the calculated size causes a
63
+ * TOO_WIDE error. Useful when the caller has an authoritative size (e.g.
64
+ * from the CE) that avoids floating-point rounding issues.
65
+ */
66
+ fontSizeFallback?: number;
67
+ boxDimensions: BoxDimensions;
68
+ spacing?: TextSpacing;
69
+ verticalAlignment?: VerticalTextAlignmentValues;
70
+ baseline?: BaselineType | BaselineConfig;
71
+ horizontalAlignment?: HorizontalTextAlignmentValues;
72
+ fillColour?: ColourInfo;
73
+ strokeColour?: ColourInfo;
74
+ colourMap?: ColourMap;
75
+ }
@@ -0,0 +1,5 @@
1
+ import { RenderTextOptions } from './types';
2
+ /**
3
+ * Synchronous text renderer. Requires a pre-loaded font.
4
+ */
5
+ export declare const renderText: (options: RenderTextOptions) => string;
@@ -0,0 +1,42 @@
1
+ import { LoadedFont } from '../loading';
2
+ import { ColourMap, GlyphFill, HorizontalTextAlignmentValues, PlatformMatrix, TextSpacing } from '../types';
3
+ export interface SvgGlyphEntry {
4
+ content: string;
5
+ viewBox: string;
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ glyphIndex: number;
11
+ }
12
+ export interface PathEntry {
13
+ attributes: {
14
+ d: string;
15
+ 'data-character': string;
16
+ transform: string;
17
+ };
18
+ path: unknown;
19
+ matrix: PlatformMatrix;
20
+ glyphData: {
21
+ index: number;
22
+ bbox: {
23
+ x1: number;
24
+ y1: number;
25
+ x2: number;
26
+ y2: number;
27
+ };
28
+ };
29
+ svgGlyph?: SvgGlyphEntry;
30
+ fills?: GlyphFill[];
31
+ }
32
+ export declare const fontUnitsToPixels: (value: number, fontSize: number, unitsPerEm: number) => number;
33
+ export interface GetTextAsPathDataOptions {
34
+ font: LoadedFont;
35
+ baselinePath: string;
36
+ text: string;
37
+ fontSize: number;
38
+ spacing?: TextSpacing;
39
+ horizontalAlignment?: HorizontalTextAlignmentValues;
40
+ colourMap?: ColourMap;
41
+ }
42
+ export declare const getTextAsPathData: ({ font, baselinePath, text, fontSize, spacing, horizontalAlignment, colourMap, }: GetTextAsPathDataOptions) => PathEntry[];
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, i, o, s) => {
3
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
4
+ get: ((e) => i[e]).bind(null, d),
5
+ enumerable: !(s = n(i, d)) || s.enumerable
6
+ });
7
+ return e;
8
+ }, c = (n, r, o) => (o = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
9
+ value: n,
10
+ enumerable: !0
11
+ }) : o, n));
12
+ //#endregion
13
+ export { c as n, o as t };
@@ -0,0 +1,11 @@
1
+ import { PathEntry } from '../rendering';
2
+ import { BoxDimensions, ColourInfo, TextSpacing } from '../types';
3
+ export interface AssembleSvgOptions {
4
+ boxDimensions: BoxDimensions;
5
+ paths: PathEntry[];
6
+ spacing?: TextSpacing;
7
+ fontSize?: number;
8
+ fillColour?: ColourInfo;
9
+ strokeColour?: ColourInfo;
10
+ }
11
+ export declare const assembleSvg: ({ boxDimensions, paths, spacing, fontSize, fillColour, strokeColour, }: AssembleSvgOptions) => string;
@@ -0,0 +1,75 @@
1
+ import { DOMMatrix } from '@unmade/platform';
2
+ import { LoadedFont } from './loading';
3
+ /** The platform's matrix, which is not the same shape as the DOM's DOMMatrix. */
4
+ export type PlatformMatrix = InstanceType<typeof DOMMatrix>;
5
+ export type MeasurementUnits = 'mm' | 'in';
6
+ export type BoxDimensions = {
7
+ width: number;
8
+ height: number;
9
+ physicalWidth: number;
10
+ physicalHeight: number;
11
+ physicalUnits: MeasurementUnits;
12
+ };
13
+ export type VerticalTextAlignmentValues = 'centre' | 'top' | 'bottom';
14
+ export type HorizontalTextAlignmentValues = 'left' | 'centre' | 'right' | 'distributed';
15
+ export type PhysicalSize = [height: number, units: MeasurementUnits];
16
+ export type BaselineType = 'flat' | 'curved';
17
+ export type BaselineConfig = {
18
+ type: 'flat';
19
+ } | {
20
+ type: 'curved';
21
+ } | {
22
+ type: 'custom';
23
+ path: string;
24
+ };
25
+ export interface ColourInfo {
26
+ readonly hex: string;
27
+ readonly reference?: string;
28
+ }
29
+ export interface GlyphFill {
30
+ readonly pathData: string;
31
+ readonly colour: ColourInfo;
32
+ }
33
+ /** Maps original hex colour → replacement ColourInfo. */
34
+ export type ColourMap = Readonly<Record<string, ColourInfo>>;
35
+ export interface TextSpacing {
36
+ readonly outlineWidth: number;
37
+ readonly letterSpacing: number;
38
+ readonly letterSpacingOutline: number;
39
+ }
40
+ /** Options for synchronous renderText (font already loaded). */
41
+ export interface RenderTextOptions {
42
+ text: string;
43
+ font: LoadedFont;
44
+ physicalSize: PhysicalSize;
45
+ /** When provided, bypasses the physicalSize → font size calculation. */
46
+ fontSize?: number;
47
+ boxDimensions: BoxDimensions;
48
+ spacing?: TextSpacing;
49
+ verticalAlignment?: VerticalTextAlignmentValues;
50
+ baseline?: BaselineType | BaselineConfig;
51
+ horizontalAlignment?: HorizontalTextAlignmentValues;
52
+ fillColour?: ColourInfo;
53
+ strokeColour?: ColourInfo;
54
+ colourMap?: ColourMap;
55
+ }
56
+ /** Options for async getRenderedText (loads font from URL). */
57
+ export interface GetRenderedTextOptions {
58
+ text: string;
59
+ fontUrl: string;
60
+ physicalSize: PhysicalSize;
61
+ /**
62
+ * Fallback font size (in pixels) to use if the calculated size causes a
63
+ * TOO_WIDE error. Useful when the caller has an authoritative size (e.g.
64
+ * from the CE) that avoids floating-point rounding issues.
65
+ */
66
+ fontSizeFallback?: number;
67
+ boxDimensions: BoxDimensions;
68
+ spacing?: TextSpacing;
69
+ verticalAlignment?: VerticalTextAlignmentValues;
70
+ baseline?: BaselineType | BaselineConfig;
71
+ horizontalAlignment?: HorizontalTextAlignmentValues;
72
+ fillColour?: ColourInfo;
73
+ strokeColour?: ColourInfo;
74
+ colourMap?: ColourMap;
75
+ }
@@ -0,0 +1,59 @@
1
+ import { BaselineConfig, BaselineType, BoxDimensions, VerticalTextAlignmentValues } from '../types';
2
+ /**
3
+ * Normalise a baseline option (string shorthand or object) into a BaselineConfig.
4
+ */
5
+ export declare const normaliseBaselineOption: (baseline: BaselineType | BaselineConfig | undefined) => BaselineConfig;
6
+ /**
7
+ * Validate a custom baseline SVG path string.
8
+ */
9
+ export declare const validateCustomBaselinePath: (path: string) => void;
10
+ export interface GenerateFlatBaselineOptions {
11
+ boxDimensions: BoxDimensions;
12
+ totalTextHeight: number;
13
+ baseline: number;
14
+ lineHeight: number;
15
+ verticalAlignment?: VerticalTextAlignmentValues;
16
+ lineNumber?: number;
17
+ }
18
+ /**
19
+ * Generate a path as a baseline for straight text
20
+ * This can be called multiple times for multiline text by incrementing the lineNumber parameter
21
+ *
22
+ * @returns an SVG path command to draw the baseline
23
+ */
24
+ export declare const generateFlatBaseline: ({ boxDimensions, totalTextHeight, baseline, lineHeight, verticalAlignment, lineNumber, }: GenerateFlatBaselineOptions) => string;
25
+ export interface GenerateCurvedBaselineOptions {
26
+ boxDimensions: BoxDimensions;
27
+ baseline: number;
28
+ textHeight: number;
29
+ verticalAlignment: VerticalTextAlignmentValues;
30
+ }
31
+ /** Where the arch sits vertically: its peak, and the baseline at its ends. */
32
+ export interface CurvedBaselineGeometry {
33
+ /** y of the peak — the highest point of the baseline. */
34
+ curveTop: number;
35
+ /** y of the two ends — the lowest points of the baseline. */
36
+ curveBottom: number;
37
+ /** Horizontal gap left at each end so the outer glyphs are not clipped. */
38
+ curveXInset: number;
39
+ }
40
+ /**
41
+ * The arch's placement, on its own so that the path and anything reasoning
42
+ * about where the text will land come from one calculation.
43
+ *
44
+ * Sizing needs this: it has to know where the renderer will actually put the
45
+ * baseline before it can say whether the text riding it clears the box. Working
46
+ * that out separately is what let the fit engine believe a size fitted while
47
+ * the render clipped.
48
+ */
49
+ export declare const curvedBaselineGeometry: ({ boxDimensions, baseline, textHeight, verticalAlignment, }: GenerateCurvedBaselineOptions) => CurvedBaselineGeometry;
50
+ /**
51
+ * Generate a path command to curve text and align that text to the top of the box.
52
+ * Uses two quadratic bezier curves — one from the bottom left to the peak, and a
53
+ * second mirrored from the peak to the end.
54
+ *
55
+ * Curved text is not currently supported for multiline text.
56
+ *
57
+ * @returns an SVG path command to draw the curve
58
+ */
59
+ export declare const generateCurvedBaseline: ({ boxDimensions, baseline, textHeight, verticalAlignment, }: GenerateCurvedBaselineOptions) => string;
@@ -0,0 +1,171 @@
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_width_decimal: number;
40
+ physical_height_decimal: number;
41
+ physical_size_units: string;
42
+ baseline_path?: string;
43
+ rotation: number;
44
+ variant?: string;
45
+ }
46
+ export interface TextLibraryItemFont {
47
+ id: number;
48
+ font_url: string;
49
+ font_family: string;
50
+ letter_spacing?: number;
51
+ letter_spacing_outline?: number;
52
+ outline_width?: number;
53
+ fixed_colours?: Record<string, {
54
+ reference: string;
55
+ hex: string;
56
+ id: string;
57
+ text: string;
58
+ }>;
59
+ }
60
+ export interface TextLibraryItem {
61
+ id: string;
62
+ type: 'text';
63
+ fonts: TextLibraryItemFont[];
64
+ palette?: number;
65
+ }
66
+ export interface PlacementLibraryItem {
67
+ id: string;
68
+ type: string;
69
+ palette?: number;
70
+ }
71
+ export interface BasePlacementSettings {
72
+ manufacturing_methods?: {
73
+ name: string;
74
+ }[];
75
+ vertical_alignment?: string;
76
+ horizontal_alignment?: string;
77
+ }
78
+ export interface PlacementsSettings {
79
+ byId: Record<string, BasePlacementSettings>;
80
+ library: Record<string, PlacementLibraryItem | TextLibraryItem>;
81
+ }
82
+ export interface CombinedEditorSettings {
83
+ editor: string;
84
+ mixins: string[];
85
+ garments: EditorGarment[];
86
+ palettes: number[];
87
+ allPalettes: Record<number, EditorPalette>;
88
+ endpoints: {
89
+ palettes: string;
90
+ [key: string]: string | undefined;
91
+ };
92
+ placements?: PlacementsSettings;
93
+ embellishments?: PlacementsSettings;
94
+ [key: string]: unknown;
95
+ }
96
+ export interface BasePlacementState {
97
+ type: string;
98
+ libraryItemID: string;
99
+ meta?: Record<string, unknown>;
100
+ }
101
+ export interface EditorStateVals {
102
+ placements?: Record<string, BasePlacementState>;
103
+ embellishments?: Record<string, BasePlacementState>;
104
+ [key: string]: unknown;
105
+ }
106
+ export interface EditorState {
107
+ garment?: string;
108
+ vals?: EditorStateVals;
109
+ [key: string]: unknown;
110
+ }
111
+ export interface Palettes {
112
+ byId: Record<string, unknown>;
113
+ getColours(paletteId: number): EditorPaletteColour[];
114
+ getUsedColours(paletteId: number, ids: (number | null)[]): (EditorPaletteColour | null)[];
115
+ getExtendedColours(paletteId: number): EditorPaletteColour[];
116
+ }
117
+ export interface PlacementPositionResult {
118
+ placement: string;
119
+ x: number;
120
+ y: number;
121
+ width: number;
122
+ height: number;
123
+ dimensionsForCanvas: {
124
+ width: number;
125
+ height: number;
126
+ x: number;
127
+ y: number;
128
+ };
129
+ variant: string;
130
+ panel: string;
131
+ rotation: boolean;
132
+ physical_width: number;
133
+ physical_height: number;
134
+ physical_width_decimal: string;
135
+ physical_height_decimal: string;
136
+ physical_size_units: string;
137
+ }
138
+ export interface EditorVariant {
139
+ name: string;
140
+ placements: string[];
141
+ }
142
+ /**
143
+ * Editor instance returned by CE's factory.
144
+ *
145
+ * The exact shape depends on which mixins are applied at runtime.
146
+ * We type the parts the CE adapter needs and treat the rest as opaque.
147
+ * Uses Element rather than SVGElement for cross-environment compatibility.
148
+ */
149
+ export interface ConfigEditor {
150
+ getState(): EditorState & {
151
+ vals: NonNullable<EditorState['vals']>;
152
+ };
153
+ palettes: Palettes;
154
+ settings: CombinedEditorSettings;
155
+ placements?: {
156
+ initialise(): Promise<void>;
157
+ getAssetsAsSVGElements(state: EditorState, manufacturingMethod: string): Promise<Record<string, {
158
+ asset: Element;
159
+ position: PlacementPositionResult;
160
+ }>>;
161
+ };
162
+ embellishments?: {
163
+ initialise(): Promise<void>;
164
+ getAssetsAsSVGElements(state: EditorState, manufacturingMethod: string): Promise<Record<string, {
165
+ asset: Element;
166
+ position: PlacementPositionResult;
167
+ }>>;
168
+ };
169
+ getVariants?(): EditorVariant[];
170
+ getCurrentVariant?(): string;
171
+ }
@@ -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,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,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;