expressive-charts 0.11.0 → 0.12.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.
- package/CHANGELOG.md +8 -0
- package/README.md +4 -4
- package/dist/define-DeZLs1h7.js.map +1 -1
- package/dist/expressive-charts.global.js +6 -6
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.cjs.map +1 -1
- package/dist/icons/sport.js +1 -1
- package/dist/index.cjs +28 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +23 -23
- package/dist/index.js.map +1 -1
- package/dist/{path-data-DnEckjY8.js → path-data-Cfjk04X8.js} +5 -5
- package/dist/{path-data-DnEckjY8.js.map → path-data-Cfjk04X8.js.map} +1 -1
- package/dist/testing.cjs +7 -7
- package/dist/testing.js +1 -1
- package/dist/{transition-romki_A6.js → transition-BFd3ktZY.js} +5 -5
- package/dist/{transition-romki_A6.js.map → transition-BFd3ktZY.js.map} +1 -1
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -27,6 +27,14 @@ Everything else can still change in a minor release while the library is 0.x: th
|
|
|
27
27
|
|
|
28
28
|
From 1.0, everything the package exports follows semantic versioning: the motion core, the charts, the adapters, the built-in effects and the controls, as well as the effect-author API.
|
|
29
29
|
|
|
30
|
+
## 0.12.0 (16 November 2026)
|
|
31
|
+
|
|
32
|
+
One fix, and newer build tools: `expressive()` reads a `<line>`'s colour from its stroke, whatever its fill, so a line D3 drew is no longer black to the library. The rest of the published code is 0.11.0's, built with rolldown 1.3.2, which writes `Infinity` as `1e400` and names two chunks anew. The demo site gains four charts drawn with D3, each given its effects through `expressive()` as it is: a map, a bullet chart, a funnel and a treemap that drills into a position. Nothing in the effect-author API changes, nothing is exported that 0.11.0 doesn't export, and the fix needs nothing written instead.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **`expressive()` reads a `<line>`'s colour from its stroke, whatever its fill.** A line has no inside, so its fill draws nothing; but the adapter took a mark's fill as its colour unless the fill was `none`, and a `<line>` that sets no `fill` computes as black. So a line D3 drew with `append("line")` was black to the library: its hover colour under `dim`, what effects draw in the mark's colour (`drawIn`'s stroke, `flash`, a halo), and its fade and colour in a chart switch. Now a `<line>`'s colour is its stroke, and one with no stroke, or `stroke: none`, has no colour. A `<line>` whose fill is `none` reads as before, so a page that set `fill: none` to get round this can keep it or take it out. Every other element reads as before, an open `<path>` or `<polyline>` too: a browser fills those, so give a line drawn as a path `fill="none"`, as D3 pages do.
|
|
37
|
+
|
|
30
38
|
## 0.11.0 (12 November 2026)
|
|
31
39
|
|
|
32
40
|
Guides that stay put through a chart switch: a view names its axes, grids and ticks, and one that both views draw the same stays on screen, where it is, while the marks morph; and `hostView([a, b, c])`, one switch view of several attachments on one `<svg>`, so a chart drawn with more than one attachment, such as a dumbbell, switches as one chart. Nothing in the effect-author API changes. Every change is an addition outside the promise, and none needs anything written instead. The 0.x promise, above, now says what 1.0 will promise.
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Composable motion and expressive effects for web charts. Hover, update and morph
|
|
|
15
15
|
|
|
16
16
|
Each picture plays once and stops where its effect ends. **[The demo site](https://deaversbp.github.io/expressive-charts/)** has every effect to try, on the library's charts and on D3, Vega-Lite and hand-written ones, with the motion modes and reduced motion.
|
|
17
17
|
|
|
18
|
-
> **Status: 0.
|
|
18
|
+
> **Status: 0.12.0 (November 2026).** The effect-author API is under [the 0.x promise](#the-0x-promise); the charts, adapters, built-in effects and motion core can still change in a minor release. [CHANGELOG.md](https://github.com/Deaversbp/expressive-charts/blob/main/CHANGELOG.md#0120-16-november-2026) lists what's new and what changed since 0.11.0.
|
|
19
19
|
|
|
20
20
|
- **Effects first.** The mark effects `travel`, `flash`, `wiggle`, `pulse`, `trace`, `drawIn` and the data effects `threshold`, `delta` and `label`, put together with `sequence`, `parallel`, `only` and `stagger`; and the transition effect `morph`, which `chartSwitch` plays to turn each mark of one chart into its mark in the next (a transition can't go into a combinator). An effect reads only a shared description of the mark, so one effect works on every chart, and effects of your own work everywhere the built-in ones do.
|
|
21
21
|
- **Charts and adapters.** Bar, donut and line charts, a switch that morphs one into another, adapters that bring the same effects to SVG marks drawn by other code, and hover linked across them.
|
|
@@ -34,7 +34,7 @@ On a page with no bundler, the script-tag bundle defines one global, `Expressive
|
|
|
34
34
|
|
|
35
35
|
```html
|
|
36
36
|
<div id="sales"></div>
|
|
37
|
-
<script src="https://cdn.jsdelivr.net/npm/expressive-charts@0.
|
|
37
|
+
<script src="https://cdn.jsdelivr.net/npm/expressive-charts@0.12/dist/expressive-charts.global.js"></script>
|
|
38
38
|
<script>
|
|
39
39
|
const { barChart } = ExpressiveCharts;
|
|
40
40
|
barChart("#sales", {
|
|
@@ -227,7 +227,7 @@ From 0.1.0 the library follows semantic versioning. While it's 0.x, the effect-a
|
|
|
227
227
|
- [Examples](https://github.com/Deaversbp/expressive-charts/tree/main/docs/sketches/examples): pages written against the API, which `npm run typecheck` checks: ball-and-cleat bars, a goals vs xG line with playback, a donut that morphs into columns, D3 charts, effects of your own and presets.
|
|
228
228
|
- [Changelog](https://github.com/Deaversbp/expressive-charts/blob/main/CHANGELOG.md), and [the development log](https://github.com/Deaversbp/expressive-charts/blob/main/docs/plan.md): the plan the library was built to, milestone by milestone, with the reasoning behind each decision.
|
|
229
229
|
- [Accessibility audit](https://github.com/Deaversbp/expressive-charts/blob/main/docs/a11y-audit.md) and [screen-reader scripts](https://github.com/Deaversbp/expressive-charts/blob/main/docs/a11y-check.md).
|
|
230
|
-
- [Demos](https://github.com/Deaversbp/expressive-charts/tree/main/demo), on [the demo site](https://deaversbp.github.io/expressive-charts/), or served by `npm run dev`. `bars.html`, `donut.html`, `line.html` and `morph.html` put the library's charts beside D3, Vega-Lite and hand-written ones, with the same effects on each; `season.html` links three charts by matchweek and labels each change with `delta()` and `label()`; `shapes.html` and `charts.html` attach the effects to circles, curves and areas, and to a waterfall, a dumbbell, a radar and a
|
|
230
|
+
- [Demos](https://github.com/Deaversbp/expressive-charts/tree/main/demo), on [the demo site](https://deaversbp.github.io/expressive-charts/), or served by `npm run dev`. `bars.html`, `donut.html`, `line.html` and `morph.html` put the library's charts beside D3, Vega-Lite and hand-written ones, with the same effects on each; `season.html` links three charts by matchweek and labels each change with `delta()` and `label()`; `shapes.html` and `charts.html` attach the effects to circles, curves and areas, and to a waterfall, a dumbbell, a radar, a butterfly, a bullet chart and a funnel, drawn with D3 and Observable Plot; `layouts.html` switches D3 charts between layouts with `hostView()` and `morph()`: bars side by side, stacked and at 100%, areas stacked and at 100%, a radar into bars, a treemap into bars, which also drills into a position (the other positions' tiles fade, then its own grow to fill the chart), and the charts page's dumbbell, three attachments as one view, into bars, with the axes both layouts draw the same kept on screen; `map.html` draws a world map with `d3-geo`, the countries a squad comes from shaded, the one hovered outlined and the rest dimmed, and an arrow travelling each signing's route; `stress.html` is the limits above; and `lab.html` is the single-file prototype the library grew out of.
|
|
231
231
|
- [Contributing](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md) and [issues](https://github.com/Deaversbp/expressive-charts/issues).
|
|
232
232
|
|
|
233
233
|
## Development
|
|
@@ -239,7 +239,7 @@ From 0.1.0 the library follows semantic versioning. While it's 0.x, the effect-a
|
|
|
239
239
|
| `npm run size` | Measures the built package and fails when a size is over its budget in `scripts/size-budget.json` (see [CONTRIBUTING.md](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md#bundle-size)) |
|
|
240
240
|
| `npm run pack-check` | After a build: packs the package, installs it in a new project and checks every entry as ESM and CommonJS, with its types (see [CONTRIBUTING.md](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md#setup)) |
|
|
241
241
|
| `npm test` | Runs the test suite, which also checks [docs/api.md](https://github.com/Deaversbp/expressive-charts/blob/main/docs/api.md) against the exports and type-checks this README's examples |
|
|
242
|
-
| `npm run test:visual:docker` | Runs the screenshot tests of `demo/bars.html`, `donut.html`, `line.html`, `morph.html`, `season.html`, `shapes.html`, `charts.html`, `layouts.html` and `stress.html` in Chromium, and their DOM checks and the accessibility checks (axe) in Chromium, Firefox and WebKit, in Playwright's Linux image (needs Docker; see [CONTRIBUTING.md](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md#visual-tests)) |
|
|
242
|
+
| `npm run test:visual:docker` | Runs the screenshot tests of `demo/bars.html`, `donut.html`, `line.html`, `morph.html`, `season.html`, `shapes.html`, `charts.html`, `layouts.html`, `map.html` and `stress.html` in Chromium, and their DOM checks and the accessibility checks (axe) in Chromium, Firefox and WebKit, in Playwright's Linux image (needs Docker; see [CONTRIBUTING.md](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md#visual-tests)) |
|
|
243
243
|
| `npm run build:site` | Builds the demo pages into `site/`, which `.github/workflows/pages.yml` publishes as [the demo site](https://deaversbp.github.io/expressive-charts/) |
|
|
244
244
|
| `npm run media` | Captures README's pictures (`docs/media/*.gif`) from the demo pages, frame by frame, in Playwright's Linux image (needs Docker; see [CONTRIBUTING.md](https://github.com/Deaversbp/expressive-charts/blob/main/CONTRIBUTING.md#readmes-pictures-and-the-demo-site)) |
|
|
245
245
|
| `npm run bench` | Measures the stress page's cases in headless Chromium against `npm run dev`, unthrottled and at 4×, about 47 minutes; not in CI |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-DeZLs1h7.js","names":[],"sources":["../src/icons/define.ts"],"sourcesContent":["// defineIcon: fills an icon's defaults and checks every field, so effects can rely on all of them.\n\nimport type { Icon, IconShape, Point, Rect } from \"../core\";\n\n/** What defineIcon takes: an Icon whose pivot, footprint and size are optional. */\nexport type IconSpec = Omit<Icon, \"footprint\" | \"pivot\" | \"size\"> & Partial<Pick<Icon, \"footprint\" | \"pivot\" | \"size\">>;\n\nconst GAITS: readonly string[] = [\"roll\", \"step\", \"slide\"];\nconst LINECAPS: readonly string[] = [\"butt\", \"round\"];\nconst LINEJOINS: readonly string[] = [\"miter\", \"round\"];\nconst FILL_RULES: readonly string[] = [\"nonzero\", \"evenodd\"];\n/** Path data: commands, numbers, separators. Anything else (markup, url(), quotes) is a mistake. */\nconst PATH_DATA = /^\\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\\-\\s]*$/;\n\n/**\n * Makes an icon from its parts. Shapes are drawn facing +x, up towards −y, in px at the icon's\n * natural size. Defaults: `pivot` is the anchor, `footprint` reaches from the anchor to the box's\n * edges, `size` is the box's width and `radius` half its height. Bad input throws a RangeError\n * naming the field. The icon and its parts are frozen, since one icon is shared by every run.\n */\nexport function defineIcon(spec: IconSpec): Icon {\n const name = spec?.name;\n if (typeof name !== \"string\" || name === \"\") throw new TypeError(`defineIcon needs a non-empty string name, got ${JSON.stringify(name)}.`);\n const fail = (field: string, problem: string): never => {\n throw new RangeError(`defineIcon: \"${name}\" ${field} ${problem}.`);\n };\n const finite = (field: string, value: unknown): number =>\n typeof value === \"number\" && Number.isFinite(value) ? value : fail(field, `must be a finite number, got ${String(value)}`);\n const positive = (field: string, value: unknown): number => (finite(field, value) > 0 ? (value as number) : fail(field, `must be more than 0, got ${String(value)}`));\n const point = (field: string, value: Point | undefined): Point =>\n value && typeof value === \"object\" ? freeze({ x: finite(`${field}.x`, value.x), y: finite(`${field}.y`, value.y) }) : fail(field, \"must be a point { x, y }\");\n\n if (!Array.isArray(spec.shapes) || spec.shapes.length === 0) fail(\"shapes\", \"must be a non-empty array\");\n const shapes = spec.shapes.map((shape, i) => checkShape(shape, `shapes[${i}]`, fail, finite));\n\n const b = spec.box;\n if (!b || typeof b !== \"object\") fail(\"box\", \"must be a rectangle { x, y, width, height }\");\n const box: Rect = freeze({ x: finite(\"box.x\", b.x), y: finite(\"box.y\", b.y), width: positive(\"box.width\", b.width), height: positive(\"box.height\", b.height) });\n\n const anchor = point(\"anchor\", spec.anchor);\n const pivot = spec.pivot === undefined ? anchor : point(\"pivot\", spec.pivot);\n const footprint = spec.footprint ?? [Math.max(0, anchor.x - box.x), Math.max(0, box.x + box.width - anchor.x)];\n if (!Array.isArray(footprint) || footprint.length !== 2) fail(\"footprint\", \"must be [behind, ahead]\");\n footprint.forEach((reach, i) => {\n if (finite(`footprint[${i}]`, reach) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach}`);\n });\n const size = spec.size === undefined ? box.width : positive(\"size\", spec.size);\n const radius = spec.radius === undefined ? box.height / 2 : positive(\"radius\", spec.radius);\n if (spec.gait !== undefined && !GAITS.includes(spec.gait)) fail(\"gait\", `must be roll, step or slide, got ${String(spec.gait)}`);\n if (spec.upright !== undefined && typeof spec.upright !== \"boolean\") fail(\"upright\", `must be true or false, got ${String(spec.upright)}`);\n\n return freeze({\n name,\n shapes: freeze(shapes),\n box,\n size,\n anchor,\n pivot,\n footprint: freeze([footprint[0], footprint[1]] as const),\n ...(spec.gait !== undefined ? { gait: spec.gait } : {}),\n radius,\n ...(spec.upright !== undefined ? { upright: spec.upright } : {})\n });\n}\n\nfunction checkShape(\n shape: IconShape,\n field: string,\n fail: (field: string, problem: string) => never,\n finite: (field: string, value: unknown) => number\n): IconShape {\n if (!shape || typeof shape !== \"object\") fail(field, \"must be a shape { d, fill?, stroke?, … }\");\n if (typeof shape.d !== \"string\" || !PATH_DATA.test(shape.d)) fail(`${field}.d`, \"must be path data starting with a move\");\n if (shape.clip !== undefined && (typeof shape.clip !== \"string\" || !PATH_DATA.test(shape.clip))) fail(`${field}.clip`, \"must be path data starting with a move\");\n for (const paint of [\"fill\", \"stroke\"] as const) {\n const value = shape[paint];\n if (value !== undefined && (typeof value !== \"string\" || value === \"\")) fail(`${field}.${paint}`, `must be a colour, got ${String(value)}`);\n }\n if (shape.width !== undefined && finite(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);\n if (shape.linecap !== undefined && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);\n if (shape.linejoin !== undefined && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);\n if (shape.fillRule !== undefined && !FILL_RULES.includes(shape.fillRule)) fail(`${field}.fillRule`, `must be nonzero or evenodd, got ${String(shape.fillRule)}`);\n for (const key of [\"opacity\", \"fillOpacity\", \"strokeOpacity\"] as const) {\n const opacity = shape[key] === undefined ? 1 : finite(`${field}.${key}`, shape[key]);\n if (opacity < 0 || opacity > 1) fail(`${field}.${key}`, `must be from 0 to 1, got ${opacity}`);\n }\n const copy: { -readonly [K in keyof IconShape]: IconShape[K] } = { d: shape.d };\n for (const key of [\"fill\", \"stroke\", \"width\", \"linecap\", \"linejoin\", \"clip\", \"fillRule\", \"opacity\", \"fillOpacity\", \"strokeOpacity\"] as const) {\n if (shape[key] !== undefined) (copy as Record<string, unknown>)[key] = shape[key];\n }\n return freeze(copy);\n}\n\nconst freeze = <T>(value: T): T => Object.freeze(value);\n"],"mappings":";AAOA,MAAM,QAA2B;CAAC;CAAQ;CAAQ;AAAO;AACzD,MAAM,WAA8B,CAAC,QAAQ,OAAO;AACpD,MAAM,YAA+B,CAAC,SAAS,OAAO;AACtD,MAAM,aAAgC,CAAC,WAAW,SAAS;AAE3D,MAAM,YAAY;AAQlB,SAAgB,WAAW,MAAsB;CAC/C,MAAM,OAAO,MAAM;CACnB,IAAI,OAAO,SAAS,YAAY,SAAS,IAAI,MAAM,IAAI,UAAU,iDAAiD,KAAK,UAAU,IAAI,EAAE,EAAE;CACzI,MAAM,QAAQ,OAAe,YAA2B;EACtD,MAAM,IAAI,WAAW,gBAAgB,KAAK,IAAI,MAAM,GAAG,QAAQ,EAAE;CACnE;CACA,MAAM,UAAU,OAAe,UAC7B,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAK,OAAO,gCAAgC,OAAO,KAAK,GAAG;CAC3H,MAAM,YAAY,OAAe,UAA4B,OAAO,OAAO,KAAK,IAAI,IAAK,QAAmB,KAAK,OAAO,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,KAAK,GAAG,MAAM,SAAS,0BAA0B,MAAM,OAAO;CAC1I,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,SAAS,SAAS,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,WAAW,8BAA8B,OAAO,MAAM,OAAO,GAAG;CACpJ,IAAI,MAAM,aAAa,KAAA,KAAa,CAAC,UAAU,SAAS,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,YAAY,+BAA+B,OAAO,MAAM,QAAQ,GAAG;CAC1J,IAAI,MAAM,aAAa,KAAA,KAAa,CAAC,WAAW,SAAS,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,YAAY,mCAAmC,OAAO,MAAM,QAAQ,GAAG;CAC/J,KAAK,MAAM,OAAO;EAAC;EAAW;EAAe;CAAe,GAAY;EACtE,MAAM,UAAU,MAAM,SAAS,KAAA,IAAY,IAAI,OAAO,GAAG,MAAM,GAAG,OAAO,MAAM,IAAI;EACnF,IAAI,UAAU,KAAK,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,4BAA4B,SAAS;CAC/F;CACA,MAAM,OAA2D,EAAE,GAAG,MAAM,EAAE;CAC9E,KAAK,MAAM,OAAO;EAAC;EAAQ;EAAU;EAAS;EAAW;EAAY;EAAQ;EAAY;EAAW;EAAe;CAAe,GAChI,IAAI,MAAM,SAAS,KAAA,
|
|
1
|
+
{"version":3,"file":"define-DeZLs1h7.js","names":[],"sources":["../src/icons/define.ts"],"sourcesContent":["// defineIcon: fills an icon's defaults and checks every field, so effects can rely on all of them.\n\nimport type { Icon, IconShape, Point, Rect } from \"../core\";\n\n/** What defineIcon takes: an Icon whose pivot, footprint and size are optional. */\nexport type IconSpec = Omit<Icon, \"footprint\" | \"pivot\" | \"size\"> & Partial<Pick<Icon, \"footprint\" | \"pivot\" | \"size\">>;\n\nconst GAITS: readonly string[] = [\"roll\", \"step\", \"slide\"];\nconst LINECAPS: readonly string[] = [\"butt\", \"round\"];\nconst LINEJOINS: readonly string[] = [\"miter\", \"round\"];\nconst FILL_RULES: readonly string[] = [\"nonzero\", \"evenodd\"];\n/** Path data: commands, numbers, separators. Anything else (markup, url(), quotes) is a mistake. */\nconst PATH_DATA = /^\\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\\-\\s]*$/;\n\n/**\n * Makes an icon from its parts. Shapes are drawn facing +x, up towards −y, in px at the icon's\n * natural size. Defaults: `pivot` is the anchor, `footprint` reaches from the anchor to the box's\n * edges, `size` is the box's width and `radius` half its height. Bad input throws a RangeError\n * naming the field. The icon and its parts are frozen, since one icon is shared by every run.\n */\nexport function defineIcon(spec: IconSpec): Icon {\n const name = spec?.name;\n if (typeof name !== \"string\" || name === \"\") throw new TypeError(`defineIcon needs a non-empty string name, got ${JSON.stringify(name)}.`);\n const fail = (field: string, problem: string): never => {\n throw new RangeError(`defineIcon: \"${name}\" ${field} ${problem}.`);\n };\n const finite = (field: string, value: unknown): number =>\n typeof value === \"number\" && Number.isFinite(value) ? value : fail(field, `must be a finite number, got ${String(value)}`);\n const positive = (field: string, value: unknown): number => (finite(field, value) > 0 ? (value as number) : fail(field, `must be more than 0, got ${String(value)}`));\n const point = (field: string, value: Point | undefined): Point =>\n value && typeof value === \"object\" ? freeze({ x: finite(`${field}.x`, value.x), y: finite(`${field}.y`, value.y) }) : fail(field, \"must be a point { x, y }\");\n\n if (!Array.isArray(spec.shapes) || spec.shapes.length === 0) fail(\"shapes\", \"must be a non-empty array\");\n const shapes = spec.shapes.map((shape, i) => checkShape(shape, `shapes[${i}]`, fail, finite));\n\n const b = spec.box;\n if (!b || typeof b !== \"object\") fail(\"box\", \"must be a rectangle { x, y, width, height }\");\n const box: Rect = freeze({ x: finite(\"box.x\", b.x), y: finite(\"box.y\", b.y), width: positive(\"box.width\", b.width), height: positive(\"box.height\", b.height) });\n\n const anchor = point(\"anchor\", spec.anchor);\n const pivot = spec.pivot === undefined ? anchor : point(\"pivot\", spec.pivot);\n const footprint = spec.footprint ?? [Math.max(0, anchor.x - box.x), Math.max(0, box.x + box.width - anchor.x)];\n if (!Array.isArray(footprint) || footprint.length !== 2) fail(\"footprint\", \"must be [behind, ahead]\");\n footprint.forEach((reach, i) => {\n if (finite(`footprint[${i}]`, reach) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach}`);\n });\n const size = spec.size === undefined ? box.width : positive(\"size\", spec.size);\n const radius = spec.radius === undefined ? box.height / 2 : positive(\"radius\", spec.radius);\n if (spec.gait !== undefined && !GAITS.includes(spec.gait)) fail(\"gait\", `must be roll, step or slide, got ${String(spec.gait)}`);\n if (spec.upright !== undefined && typeof spec.upright !== \"boolean\") fail(\"upright\", `must be true or false, got ${String(spec.upright)}`);\n\n return freeze({\n name,\n shapes: freeze(shapes),\n box,\n size,\n anchor,\n pivot,\n footprint: freeze([footprint[0], footprint[1]] as const),\n ...(spec.gait !== undefined ? { gait: spec.gait } : {}),\n radius,\n ...(spec.upright !== undefined ? { upright: spec.upright } : {})\n });\n}\n\nfunction checkShape(\n shape: IconShape,\n field: string,\n fail: (field: string, problem: string) => never,\n finite: (field: string, value: unknown) => number\n): IconShape {\n if (!shape || typeof shape !== \"object\") fail(field, \"must be a shape { d, fill?, stroke?, … }\");\n if (typeof shape.d !== \"string\" || !PATH_DATA.test(shape.d)) fail(`${field}.d`, \"must be path data starting with a move\");\n if (shape.clip !== undefined && (typeof shape.clip !== \"string\" || !PATH_DATA.test(shape.clip))) fail(`${field}.clip`, \"must be path data starting with a move\");\n for (const paint of [\"fill\", \"stroke\"] as const) {\n const value = shape[paint];\n if (value !== undefined && (typeof value !== \"string\" || value === \"\")) fail(`${field}.${paint}`, `must be a colour, got ${String(value)}`);\n }\n if (shape.width !== undefined && finite(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);\n if (shape.linecap !== undefined && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);\n if (shape.linejoin !== undefined && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);\n if (shape.fillRule !== undefined && !FILL_RULES.includes(shape.fillRule)) fail(`${field}.fillRule`, `must be nonzero or evenodd, got ${String(shape.fillRule)}`);\n for (const key of [\"opacity\", \"fillOpacity\", \"strokeOpacity\"] as const) {\n const opacity = shape[key] === undefined ? 1 : finite(`${field}.${key}`, shape[key]);\n if (opacity < 0 || opacity > 1) fail(`${field}.${key}`, `must be from 0 to 1, got ${opacity}`);\n }\n const copy: { -readonly [K in keyof IconShape]: IconShape[K] } = { d: shape.d };\n for (const key of [\"fill\", \"stroke\", \"width\", \"linecap\", \"linejoin\", \"clip\", \"fillRule\", \"opacity\", \"fillOpacity\", \"strokeOpacity\"] as const) {\n if (shape[key] !== undefined) (copy as Record<string, unknown>)[key] = shape[key];\n }\n return freeze(copy);\n}\n\nconst freeze = <T>(value: T): T => Object.freeze(value);\n"],"mappings":";AAOA,MAAM,QAA2B;CAAC;CAAQ;CAAQ;AAAO;AACzD,MAAM,WAA8B,CAAC,QAAQ,OAAO;AACpD,MAAM,YAA+B,CAAC,SAAS,OAAO;AACtD,MAAM,aAAgC,CAAC,WAAW,SAAS;AAE3D,MAAM,YAAY;AAQlB,SAAgB,WAAW,MAAsB;CAC/C,MAAM,OAAO,MAAM;CACnB,IAAI,OAAO,SAAS,YAAY,SAAS,IAAI,MAAM,IAAI,UAAU,iDAAiD,KAAK,UAAU,IAAI,EAAE,EAAE;CACzI,MAAM,QAAQ,OAAe,YAA2B;EACtD,MAAM,IAAI,WAAW,gBAAgB,KAAK,IAAI,MAAM,GAAG,QAAQ,EAAE;CACnE;CACA,MAAM,UAAU,OAAe,UAC7B,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAK,OAAO,gCAAgC,OAAO,KAAK,GAAG;CAC3H,MAAM,YAAY,OAAe,UAA4B,OAAO,OAAO,KAAK,IAAI,IAAK,QAAmB,KAAK,OAAO,4BAA4B,OAAO,K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