@oim-media/core 1.31.0 → 1.32.1

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/README.md CHANGED
@@ -26,7 +26,7 @@ URLs only) and `@oim-media/core/generative` and `@oim-media/core/generative/cata
26
26
 
27
27
  - `OimMetadataSchema`, `OvmMetadataSchema`, `OIMOrOVMMetadata`: Zod schemas of the
28
28
  metadata. Types `OIMMetadata`, `OVMMetadata`, `Slot`, `TextMark`, `Reveal`, ...
29
- - `CONTRACT_VERSION`: the contract version this build implements (`"1.31.0"`).
29
+ - `CONTRACT_VERSION`: the contract version this build implements (`"1.32.1"`).
30
30
  - `BASE_CONTRACT_VERSION`, `PLAYER_CAPABILITIES`, `VERSION_BY_CAPABILITY`, `minVersionFor`.
31
31
  - `MAX_SLOTS`, `MAX_MARKS`, `MARK_NAME`, `PALETTE_NAME_PATTERN`, `CSS_GRADIENT_PATTERN`.
32
32
 
@@ -41,7 +41,7 @@
41
41
  * the format can change without the player being touched. Tying both numbers
42
42
  * together would make an internal fix look like a format break.
43
43
  */
44
- export declare const CONTRACT_VERSION = "1.31.0";
44
+ export declare const CONTRACT_VERSION = "1.32.1";
45
45
  /**
46
46
  * The first version of the format. Whatever requires nothing more requires this.
47
47
  *
@@ -41,7 +41,9 @@
41
41
  * the format can change without the player being touched. Tying both numbers
42
42
  * together would make an internal fix look like a format break.
43
43
  */
44
- export const CONTRACT_VERSION = "1.31.0";
44
+ export const CONTRACT_VERSION = "1.32.1";
45
+ // 1.32.1: an SVG icon with a gradient, pattern or generative fill keeps its paths (upgrade falls back to svgRawXml) and the player cuts that fill to them; no format change.
46
+ // 1.32.0: additive, no existing file changes: a mask takes any frame shape and a window frame takes the fill* paints; a filter takes a shape (geoShape) and a rounded clip; the player draws duotone in sRGB and no longer offsets window frames and filters vertically; mask silhouettes come from the shared catalogue (one changed-pixel exception, see CHANGELOG).
45
47
  // 1.31.0: no format change; the 2.0 scene painter paints blur, shadow, glow and backdrop effects.
46
48
  // 1.30.2: no format change; 2.0 canvas colour, drawings and icon paint, and text centred on its box despite the italic room.
47
49
  // 1.30.1: no format change; the CDN player loads generative fills and pattern tiles on demand.
package/dist/fill.d.ts CHANGED
@@ -50,6 +50,18 @@ export interface Shape {
50
50
  * editor, viewer and static export. Do not duplicate it.
51
51
  */
52
52
  export declare function getFillCss(shape: Shape): CSSProperties;
53
+ /** The fill fields a window frame reuses from shapes, plus the 1.x frame colour. */
54
+ export type MaskFrameFillStyle = Pick<Shape, "fillType" | "fillColor" | "fillColorRole" | "fillGradient" | "fillImage" | "fillImageCrop" | "fillImageFlipX" | "fillImageFlipY"> & {
55
+ maskBgColor?: string;
56
+ maskBgColorRole?: string;
57
+ };
58
+ /**
59
+ * The CSS of a window frame. A frame without `fillType` is the 1.x colour
60
+ * `maskBgColor`; with one, it takes the shape fill model through `getFillCss`.
61
+ * Patterns and generative fills are not frame fills. For `image` this returns only the
62
+ * colour underneath: the renderers paint the photo over it, as they do for shapes.
63
+ */
64
+ export declare function maskFrameFillCss(style: MaskFrameFillStyle): CSSProperties;
53
65
  /**
54
66
  * The shapes a pattern layer can take. Open strokes (line, scribble) are out:
55
67
  * they cannot hold a tile. The editor's picker reads this list.
package/dist/fill.js CHANGED
@@ -8,6 +8,7 @@ import { generatePatternSVG } from "./patterns.js";
8
8
  import { GEO_SHAPES, pointsToAttribute } from "./geoShapes.js";
9
9
  import { isSafeCssGradient } from "./css-gradient.js";
10
10
  import { frameSilhouette } from "./frame-silhouette.js";
11
+ import { resolveCssColor } from "./dynamic-colors.js";
11
12
  /** The directions with their own `@keyframes`. See `player-oim/src/core/styles.ts`. */
12
13
  const DIRECCIONES = new Set([
13
14
  "right", "left", "up", "down", "zoom-in", "zoom-out", "pulse",
@@ -115,6 +116,18 @@ export function getFillCss(shape) {
115
116
  }
116
117
  return res;
117
118
  }
119
+ /**
120
+ * The CSS of a window frame. A frame without `fillType` is the 1.x colour
121
+ * `maskBgColor`; with one, it takes the shape fill model through `getFillCss`.
122
+ * Patterns and generative fills are not frame fills. For `image` this returns only the
123
+ * colour underneath: the renderers paint the photo over it, as they do for shapes.
124
+ */
125
+ export function maskFrameFillCss(style) {
126
+ if (!style.fillType) {
127
+ return getFillCss({ fillType: "color", fillColor: resolveCssColor(style.maskBgColorRole, style.maskBgColor) });
128
+ }
129
+ return getFillCss({ ...style, fillColor: resolveCssColor(style.fillColorRole, style.fillColor) });
130
+ }
118
131
  /**
119
132
  * The shapes a pattern layer can take. Open strokes (line, scribble) are out:
120
133
  * they cannot hold a tile. The editor's picker reads this list.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The clip of a filter layer: a rectangle with corner radii by default, or a catalogue
8
+ * shape. CANONICAL: the editor, the player and the export call this one function.
9
+ */
10
+ import { type MaskBox } from "./mask-outline.js";
11
+ export interface FilterClipInput {
12
+ geoShape?: string;
13
+ borderRadiusTopLeft?: number;
14
+ borderRadiusTopRight?: number;
15
+ borderRadiusBottomRight?: number;
16
+ borderRadiusBottomLeft?: number;
17
+ }
18
+ /** min(r, w/2, h/2): the same cut the editor makes. A non-finite radius counts as 0. */
19
+ export declare function clampRadius(r: number, width: number, height: number): number;
20
+ /**
21
+ * Silhouette of the filter clip in canvas coordinates inside `box`. The rectangle (default)
22
+ * takes the corner radii; circle and the other frame shapes come from `maskOutlinePath`.
23
+ * Returns null when there is no shape clip: a line or scribble, or an unknown name.
24
+ */
25
+ export declare function filterClipPath(input: FilterClipInput, box: MaskBox): string | null;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The clip of a filter layer: a rectangle with corner radii by default, or a catalogue
8
+ * shape. CANONICAL: the editor, the player and the export call this one function.
9
+ */
10
+ import { maskOutlinePath } from "./mask-outline.js";
11
+ /** Open strokes cannot clip: a filter needs a surface. The schema rejects them too. */
12
+ const OPEN_STROKES = new Set(["line", "scribble"]);
13
+ /** The Bezier constant for a quarter circle. */
14
+ const KAPPA = 0.5523;
15
+ /** min(r, w/2, h/2): the same cut the editor makes. A non-finite radius counts as 0. */
16
+ export function clampRadius(r, width, height) {
17
+ const safe = Number.isFinite(r) ? r : 0;
18
+ return Math.max(0, Math.min(safe, width / 2, height / 2));
19
+ }
20
+ function roundedRectPath(box, [tl, tr, br, bl]) {
21
+ const { x, y, width: w, height: h } = box;
22
+ const k = KAPPA;
23
+ return [
24
+ `M${x + tl} ${y}`,
25
+ `L${x + w - tr} ${y}`,
26
+ `C${x + w - tr + k * tr} ${y} ${x + w} ${y + tr - k * tr} ${x + w} ${y + tr}`,
27
+ `L${x + w} ${y + h - br}`,
28
+ `C${x + w} ${y + h - br + k * br} ${x + w - br + k * br} ${y + h} ${x + w - br} ${y + h}`,
29
+ `L${x + bl} ${y + h}`,
30
+ `C${x + bl - k * bl} ${y + h} ${x} ${y + h - bl + k * bl} ${x} ${y + h - bl}`,
31
+ `L${x} ${y + tl}`,
32
+ `C${x} ${y + tl - k * tl} ${x + tl - k * tl} ${y} ${x + tl} ${y}`,
33
+ "Z",
34
+ ].join(" ");
35
+ }
36
+ /**
37
+ * Silhouette of the filter clip in canvas coordinates inside `box`. The rectangle (default)
38
+ * takes the corner radii; circle and the other frame shapes come from `maskOutlinePath`.
39
+ * Returns null when there is no shape clip: a line or scribble, or an unknown name.
40
+ */
41
+ export function filterClipPath(input, box) {
42
+ const name = input.geoShape;
43
+ if (!name || name === "rect" || name === "rectangle") {
44
+ const radii = [
45
+ input.borderRadiusTopLeft ?? 0,
46
+ input.borderRadiusTopRight ?? 0,
47
+ input.borderRadiusBottomRight ?? 0,
48
+ input.borderRadiusBottomLeft ?? 0,
49
+ ].map((r) => clampRadius(r, box.width, box.height));
50
+ return roundedRectPath(box, radii);
51
+ }
52
+ if (OPEN_STROKES.has(name))
53
+ return null;
54
+ return maskOutlinePath({ geoShape: name }, box);
55
+ }
package/dist/index.d.ts CHANGED
@@ -17,6 +17,9 @@ export * from "./reveal.js";
17
17
  export * from "./keyframes.js";
18
18
  export * from "./crop.js";
19
19
  export * from "./geoShapes.js";
20
+ export * from "./path-data.js";
21
+ export * from "./mask-outline.js";
22
+ export * from "./filter-shape.js";
20
23
  export * from "./frame-silhouette.js";
21
24
  export * from "./parallaxCss.js";
22
25
  export * from "./reeditPermission.js";
package/dist/index.js CHANGED
@@ -32,6 +32,12 @@ export * from "./crop.js";
32
32
  // oversizing. None of them imports anything, so moving them was trivial; what was
33
33
  // costly was the machinery that existed to keep the two copies equal.
34
34
  export * from "./geoShapes.js";
35
+ // path-data.ts: the one SVG path parser for mask outlines, shared by player and editor.
36
+ export * from "./path-data.js";
37
+ // mask-outline.ts: the silhouette a mask cuts with, drawn from the catalogue (contract 1.32.0).
38
+ export * from "./mask-outline.js";
39
+ // filter-shape.ts: the clip of a filter layer, shared by editor, player and export (1.32.0).
40
+ export * from "./filter-shape.js";
35
41
  // frame-silhouette.ts: the outline a photo frame crops to, shared by player and editor (1.19.0).
36
42
  export * from "./frame-silhouette.js";
37
43
  export * from "./parallaxCss.js";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export interface MaskBox {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ export interface MaskOutlineInput {
13
+ geoShape?: string;
14
+ svgPath?: string;
15
+ svgViewBox?: string;
16
+ }
17
+ /**
18
+ * Silhouette in canvas coordinates inside `box`. Returns null when the name is not in
19
+ * the catalogue and there is no svgPath: it never falls back to a circle.
20
+ */
21
+ export declare function maskOutlinePath(input: MaskOutlineInput, box: MaskBox): string | null;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The silhouette a mask cuts with, placed in a box on the canvas.
8
+ *
9
+ * CANONICAL: the editor and the player both draw masks through this function.
10
+ * It reads the catalogue in geoShapes.ts, so a mask can take any catalogue shape.
11
+ */
12
+ import { shapeDrawing } from "./geoShapes.js";
13
+ import { transformPathData } from "./path-data.js";
14
+ /** The catalogue lives in a 0-100 space. */
15
+ const CATALOGUE_VIEWBOX = [0, 0, 100, 100];
16
+ /** Its shapes sit in 5..95 so strokes keep a margin. A mask fills its box with that content, so the edges land on the box. */
17
+ const CATALOGUE_CONTENT = [5, 5, 90, 90];
18
+ /** A line is a stroke, but as a mask it must cut a surface or it would cut nothing. */
19
+ const LINE_SURFACE = { kind: "polygon", points: [[5, 45], [95, 45], [95, 55], [5, 55]] };
20
+ /** Open strokes other than the line (the scribble) are closed so they enclose an area. */
21
+ function surfaceOf(name, drawing) {
22
+ if (name === "line")
23
+ return LINE_SURFACE;
24
+ if (drawing.kind === "path" && !drawing.fillable)
25
+ return { ...drawing, d: `${drawing.d} Z`, fillable: true };
26
+ return drawing;
27
+ }
28
+ function parseViewBox(raw) {
29
+ if (raw === undefined)
30
+ return CATALOGUE_VIEWBOX;
31
+ const nums = raw.trim().split(/[\s,]+/).map(Number);
32
+ if (nums.length !== 4 || nums.some((n) => !Number.isFinite(n)))
33
+ return null;
34
+ const [, , w, h] = nums;
35
+ if (w <= 0 || h <= 0)
36
+ return null;
37
+ return nums;
38
+ }
39
+ /** Maps path data from a viewBox into the box, or null when the data is not a path. Stretches x and y independently, as the editor's boxMatrix does. */
40
+ function fitToBox(d, [vx, vy, vw, vh], box) {
41
+ return transformPathData(d, (x, y) => [
42
+ box.x + ((x - vx) / vw) * box.width,
43
+ box.y + ((y - vy) / vh) * box.height,
44
+ ]);
45
+ }
46
+ /**
47
+ * Silhouette in canvas coordinates inside `box`. Returns null when the name is not in
48
+ * the catalogue and there is no svgPath: it never falls back to a circle.
49
+ */
50
+ export function maskOutlinePath(input, box) {
51
+ const name = input.geoShape;
52
+ const drawing = shapeDrawing(name);
53
+ if (name && drawing) {
54
+ const surface = surfaceOf(name, drawing);
55
+ const d = surface.kind === "polygon"
56
+ ? surface.points.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x} ${y}`).join(" ") + " Z"
57
+ : surface.d;
58
+ return fitToBox(d, name === "line" ? CATALOGUE_VIEWBOX : CATALOGUE_CONTENT, box);
59
+ }
60
+ if (input.svgPath) {
61
+ const viewBox = parseViewBox(input.svgViewBox);
62
+ return viewBox ? fitToBox(input.svgPath, viewBox, box) : null;
63
+ }
64
+ return null;
65
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * SVG path data parser shared by the player and the editor.
8
+ *
9
+ * CANONICAL: one parser for every mask outline. Ported from the editor's
10
+ * frame-svg.ts; do not fork it. Quadratic curves and arcs become cubics so a
11
+ * single affine map stays exact.
12
+ */
13
+ export type PathOp = {
14
+ cmd: "M" | "L" | "C" | "Z";
15
+ args: number[];
16
+ };
17
+ /** Normalizes M L H V C Q S T A Z (absolute and relative) to absolute M L C Z. null when malformed. */
18
+ export declare function normalizePathData(d: string): PathOp[] | null;
19
+ /** Applies an affine-style point map to a path and returns absolute path data (0.01 precision), or null. */
20
+ export declare function transformPathData(d: string, map: (x: number, y: number) => [number, number]): string | null;
@@ -0,0 +1,242 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ const NUMBER = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
7
+ const ARG_COUNT = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7, Z: 0 };
8
+ /** SVG 1.1 F.6: an elliptical arc as cubic curves, or null when it is a straight line. */
9
+ function arcToCubics(x1, y1, rx0, ry0, angleDeg, largeArc, sweep, x2, y2) {
10
+ let rx = Math.abs(rx0);
11
+ let ry = Math.abs(ry0);
12
+ if (rx === 0 || ry === 0 || (x1 === x2 && y1 === y2))
13
+ return null;
14
+ const phi = (angleDeg * Math.PI) / 180;
15
+ const cos = Math.cos(phi);
16
+ const sin = Math.sin(phi);
17
+ const dx = (x1 - x2) / 2;
18
+ const dy = (y1 - y2) / 2;
19
+ const x1p = cos * dx + sin * dy;
20
+ const y1p = -sin * dx + cos * dy;
21
+ const lambda = (x1p * x1p) / (rx * rx) + (y1p * y1p) / (ry * ry);
22
+ if (lambda > 1) {
23
+ rx *= Math.sqrt(lambda);
24
+ ry *= Math.sqrt(lambda);
25
+ }
26
+ const num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
27
+ const den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
28
+ let coef = Math.sqrt(Math.max(0, num / den));
29
+ if (largeArc === sweep)
30
+ coef = -coef;
31
+ const cxp = (coef * rx * y1p) / ry;
32
+ const cyp = (-coef * ry * x1p) / rx;
33
+ const cx = cos * cxp - sin * cyp + (x1 + x2) / 2;
34
+ const cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
35
+ const ux = (x1p - cxp) / rx;
36
+ const uy = (y1p - cyp) / ry;
37
+ const vx = (-x1p - cxp) / rx;
38
+ const vy = (-y1p - cyp) / ry;
39
+ const angle = (ax, ay, bx, by) => {
40
+ const k = (ax * bx + ay * by) / (Math.hypot(ax, ay) * Math.hypot(bx, by));
41
+ const a = Math.acos(Math.max(-1, Math.min(1, k)));
42
+ return ax * by - ay * bx < 0 ? -a : a;
43
+ };
44
+ const theta1 = angle(1, 0, ux, uy);
45
+ let dTheta = angle(ux, uy, vx, vy);
46
+ if (!sweep && dTheta > 0)
47
+ dTheta -= 2 * Math.PI;
48
+ else if (sweep && dTheta < 0)
49
+ dTheta += 2 * Math.PI;
50
+ const segments = Math.max(1, Math.ceil(Math.abs(dTheta) / (Math.PI / 2) - 1e-9));
51
+ const delta = dTheta / segments;
52
+ const k = (4 / 3) * Math.tan(delta / 4);
53
+ const point = (t) => [
54
+ cx + rx * cos * Math.cos(t) - ry * sin * Math.sin(t),
55
+ cy + rx * sin * Math.cos(t) + ry * cos * Math.sin(t),
56
+ ];
57
+ const tangent = (t) => [
58
+ -rx * cos * Math.sin(t) - ry * sin * Math.cos(t),
59
+ -rx * sin * Math.sin(t) + ry * cos * Math.cos(t),
60
+ ];
61
+ const curves = [];
62
+ for (let s = 0; s < segments; s++) {
63
+ const ta = theta1 + s * delta;
64
+ const tb = ta + delta;
65
+ const pa = point(ta);
66
+ const pb = point(tb);
67
+ const da = tangent(ta);
68
+ const db = tangent(tb);
69
+ curves.push([pa[0] + k * da[0], pa[1] + k * da[1], pb[0] - k * db[0], pb[1] - k * db[1], pb[0], pb[1]]);
70
+ }
71
+ return curves;
72
+ }
73
+ /** Normalizes M L H V C Q S T A Z (absolute and relative) to absolute M L C Z. null when malformed. */
74
+ export function normalizePathData(d) {
75
+ // SVG requires the first command to be a moveto; "" and "L10 10" are not paths.
76
+ if (!/^\s*[Mm]/.test(d))
77
+ return null;
78
+ const ops = [];
79
+ let i = 0;
80
+ let cmd = "";
81
+ let x = 0;
82
+ let y = 0;
83
+ let startX = 0;
84
+ let startY = 0;
85
+ let lastType = "";
86
+ let lastCtrl = [0, 0];
87
+ const skip = () => {
88
+ while (i < d.length && /[\s,]/.test(d[i]))
89
+ i++;
90
+ };
91
+ const readNumber = () => {
92
+ skip();
93
+ NUMBER.lastIndex = i;
94
+ const m = NUMBER.exec(d);
95
+ if (!m)
96
+ return null;
97
+ i = NUMBER.lastIndex;
98
+ return Number(m[0]);
99
+ };
100
+ const readFlag = () => {
101
+ skip();
102
+ if (d[i] !== "0" && d[i] !== "1")
103
+ return null;
104
+ return Number(d[i++]);
105
+ };
106
+ for (;;) {
107
+ skip();
108
+ if (i >= d.length)
109
+ break;
110
+ if (/[A-Za-z]/.test(d[i])) {
111
+ if (!"MmLlHhVvCcSsQqTtAaZz".includes(d[i]))
112
+ return null;
113
+ cmd = d[i++];
114
+ }
115
+ else if (cmd === "" || cmd === "Z" || cmd === "z") {
116
+ return null;
117
+ }
118
+ else if (cmd === "M") {
119
+ cmd = "L"; // extra pairs after a moveto are lineto
120
+ }
121
+ else if (cmd === "m") {
122
+ cmd = "l";
123
+ }
124
+ const upper = cmd.toUpperCase();
125
+ const rel = cmd !== upper;
126
+ const a = [];
127
+ for (let k = 0; k < ARG_COUNT[upper]; k++) {
128
+ const v = upper === "A" && (k === 3 || k === 4) ? readFlag() : readNumber();
129
+ if (v === null)
130
+ return null;
131
+ a.push(v);
132
+ }
133
+ const ox = rel ? x : 0;
134
+ const oy = rel ? y : 0;
135
+ switch (upper) {
136
+ case "Z":
137
+ ops.push({ cmd: "Z", args: [] });
138
+ x = startX;
139
+ y = startY;
140
+ lastType = "";
141
+ break;
142
+ case "M":
143
+ x = a[0] + ox;
144
+ y = a[1] + oy;
145
+ startX = x;
146
+ startY = y;
147
+ ops.push({ cmd: "M", args: [x, y] });
148
+ lastType = "";
149
+ break;
150
+ case "L":
151
+ x = a[0] + ox;
152
+ y = a[1] + oy;
153
+ ops.push({ cmd: "L", args: [x, y] });
154
+ lastType = "";
155
+ break;
156
+ case "H":
157
+ x = a[0] + ox;
158
+ ops.push({ cmd: "L", args: [x, y] });
159
+ lastType = "";
160
+ break;
161
+ case "V":
162
+ y = a[0] + oy;
163
+ ops.push({ cmd: "L", args: [x, y] });
164
+ lastType = "";
165
+ break;
166
+ case "C": {
167
+ const c1 = [a[0] + ox, a[1] + oy];
168
+ const c2 = [a[2] + ox, a[3] + oy];
169
+ const end = [a[4] + ox, a[5] + oy];
170
+ ops.push({ cmd: "C", args: [...c1, ...c2, ...end] });
171
+ lastCtrl = [c2[0], c2[1]];
172
+ lastType = "C";
173
+ [x, y] = end;
174
+ break;
175
+ }
176
+ case "S": {
177
+ const c1 = lastType === "C" ? [2 * x - lastCtrl[0], 2 * y - lastCtrl[1]] : [x, y];
178
+ const c2 = [a[0] + ox, a[1] + oy];
179
+ const end = [a[2] + ox, a[3] + oy];
180
+ ops.push({ cmd: "C", args: [...c1, ...c2, ...end] });
181
+ lastCtrl = [c2[0], c2[1]];
182
+ lastType = "C";
183
+ [x, y] = end;
184
+ break;
185
+ }
186
+ case "Q":
187
+ case "T": {
188
+ const q = upper === "Q"
189
+ ? [a[0] + ox, a[1] + oy]
190
+ : lastType === "Q" ? [2 * x - lastCtrl[0], 2 * y - lastCtrl[1]] : [x, y];
191
+ const end = upper === "Q" ? [a[2] + ox, a[3] + oy] : [a[0] + ox, a[1] + oy];
192
+ ops.push({
193
+ cmd: "C",
194
+ args: [
195
+ x + (2 / 3) * (q[0] - x), y + (2 / 3) * (q[1] - y),
196
+ end[0] + (2 / 3) * (q[0] - end[0]), end[1] + (2 / 3) * (q[1] - end[1]),
197
+ end[0], end[1],
198
+ ],
199
+ });
200
+ lastCtrl = [q[0], q[1]];
201
+ lastType = "Q";
202
+ [x, y] = end;
203
+ break;
204
+ }
205
+ case "A": {
206
+ const end = [a[5] + ox, a[6] + oy];
207
+ const curves = arcToCubics(x, y, a[0], a[1], a[2], a[3], a[4], end[0], end[1]);
208
+ if (curves)
209
+ for (const c of curves)
210
+ ops.push({ cmd: "C", args: c });
211
+ else
212
+ ops.push({ cmd: "L", args: end });
213
+ lastType = "";
214
+ [x, y] = end;
215
+ break;
216
+ }
217
+ }
218
+ }
219
+ return ops;
220
+ }
221
+ /** Applies an affine-style point map to a path and returns absolute path data (0.01 precision), or null. */
222
+ export function transformPathData(d, map) {
223
+ const ops = normalizePathData(d);
224
+ if (!ops)
225
+ return null;
226
+ const fmt = (n) => {
227
+ const r = Math.round(n * 100) / 100;
228
+ return String(r); // String(-0) is "0", so negative zero needs no guard
229
+ };
230
+ return ops
231
+ .map(({ cmd, args }) => {
232
+ if (cmd === "Z")
233
+ return "Z";
234
+ const nums = [];
235
+ for (let k = 0; k < args.length; k += 2) {
236
+ const [px, py] = map(args[k], args[k + 1]);
237
+ nums.push(fmt(px), fmt(py));
238
+ }
239
+ return cmd + nums.join(" ");
240
+ })
241
+ .join("");
242
+ }