@vielzeug/prism 2.2.6 → 26.10.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/README.md +19 -40
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -6
- package/dist/_dev.js.map +1 -1
- package/dist/animation/easing.cjs +1 -1
- package/dist/animation/easing.cjs.map +1 -1
- package/dist/animation/easing.js +1 -13
- package/dist/animation/easing.js.map +1 -1
- package/dist/animation/motion.cjs +1 -1
- package/dist/animation/motion.cjs.map +1 -1
- package/dist/animation/motion.js +1 -12
- package/dist/animation/motion.js.map +1 -1
- package/dist/animation/transition.cjs +1 -1
- package/dist/animation/transition.cjs.map +1 -1
- package/dist/animation/transition.js +1 -28
- package/dist/animation/transition.js.map +1 -1
- package/dist/animation/tween.cjs +1 -1
- package/dist/animation/tween.cjs.map +1 -1
- package/dist/animation/tween.js +1 -7
- package/dist/animation/tween.js.map +1 -1
- package/dist/axes/axis.cjs +1 -1
- package/dist/axes/axis.cjs.map +1 -1
- package/dist/axes/axis.d.ts +1 -0
- package/dist/axes/axis.d.ts.map +1 -1
- package/dist/axes/axis.js +1 -59
- package/dist/axes/axis.js.map +1 -1
- package/dist/axes/grid.cjs +1 -1
- package/dist/axes/grid.cjs.map +1 -1
- package/dist/axes/grid.js +1 -29
- package/dist/axes/grid.js.map +1 -1
- package/dist/axes/scale-utils.cjs +1 -1
- package/dist/axes/scale-utils.cjs.map +1 -1
- package/dist/axes/scale-utils.js +1 -10
- package/dist/axes/scale-utils.js.map +1 -1
- package/dist/charts/area/area-chart.cjs +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.d.ts +2 -2
- package/dist/charts/area/area-chart.d.ts.map +1 -1
- package/dist/charts/area/area-chart.js +1 -61
- package/dist/charts/area/area-chart.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts +2 -2
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +1 -73
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.d.ts +2 -2
- package/dist/charts/bar/bar-chart.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js +1 -172
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.js +1 -28
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.js +1 -106
- package/dist/charts/bar/bar-renderer.js.map +1 -1
- package/dist/charts/line/line-chart.cjs +1 -1
- package/dist/charts/line/line-chart.cjs.map +1 -1
- package/dist/charts/line/line-chart.d.ts +2 -2
- package/dist/charts/line/line-chart.d.ts.map +1 -1
- package/dist/charts/line/line-chart.js +1 -62
- package/dist/charts/line/line-chart.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts +2 -2
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +1 -100
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/pie/pie-chart.cjs +1 -1
- package/dist/charts/pie/pie-chart.cjs.map +1 -1
- package/dist/charts/pie/pie-chart.d.ts +2 -2
- package/dist/charts/pie/pie-chart.d.ts.map +1 -1
- package/dist/charts/pie/pie-chart.js +1 -160
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/pie/pie-renderer.cjs +1 -1
- package/dist/charts/pie/pie-renderer.cjs.map +1 -1
- package/dist/charts/pie/pie-renderer.js +1 -76
- package/dist/charts/pie/pie-renderer.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts +2 -2
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +1 -192
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs +1 -1
- package/dist/core/cartesian-model.cjs.map +1 -1
- package/dist/core/cartesian-model.js +1 -30
- package/dist/core/cartesian-model.js.map +1 -1
- package/dist/core/cartesian-scales.cjs +1 -1
- package/dist/core/cartesian-scales.cjs.map +1 -1
- package/dist/core/cartesian-scales.js +1 -37
- package/dist/core/cartesian-scales.js.map +1 -1
- package/dist/core/chart-base.cjs +1 -1
- package/dist/core/chart-base.cjs.map +1 -1
- package/dist/core/chart-base.d.ts +2 -4
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +1 -62
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.d.ts +9 -10
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +1 -101
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/layout.cjs +1 -1
- package/dist/core/layout.cjs.map +1 -1
- package/dist/core/layout.js +1 -22
- package/dist/core/layout.js.map +1 -1
- package/dist/core/responsive.cjs +1 -1
- package/dist/core/responsive.cjs.map +1 -1
- package/dist/core/responsive.js +1 -19
- package/dist/core/responsive.js.map +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +1 -18
- package/dist/devtools.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -12
- package/dist/interaction/crosshair.cjs +1 -1
- package/dist/interaction/crosshair.cjs.map +1 -1
- package/dist/interaction/crosshair.js +1 -45
- package/dist/interaction/crosshair.js.map +1 -1
- package/dist/interaction/events.cjs +1 -1
- package/dist/interaction/events.cjs.map +1 -1
- package/dist/interaction/events.js +1 -11
- package/dist/interaction/events.js.map +1 -1
- package/dist/interaction/legend.cjs +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.js +1 -30
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/series-interaction.cjs +1 -1
- package/dist/interaction/series-interaction.cjs.map +1 -1
- package/dist/interaction/series-interaction.js +1 -97
- package/dist/interaction/series-interaction.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js +1 -63
- package/dist/interaction/tooltip.js.map +1 -1
- package/dist/prism.cjs +1 -1
- package/dist/prism.cjs.map +1 -1
- package/dist/prism.iife.js +1 -1
- package/dist/prism.iife.js.map +1 -1
- package/dist/prism.js +1 -1
- package/dist/prism.js.map +1 -1
- package/dist/scales/band.cjs +1 -1
- package/dist/scales/band.cjs.map +1 -1
- package/dist/scales/band.js +1 -39
- package/dist/scales/band.js.map +1 -1
- package/dist/scales/linear.cjs +1 -1
- package/dist/scales/linear.cjs.map +1 -1
- package/dist/scales/linear.js +1 -43
- package/dist/scales/linear.js.map +1 -1
- package/dist/scales/time.cjs +1 -1
- package/dist/scales/time.cjs.map +1 -1
- package/dist/scales/time.js +1 -61
- package/dist/scales/time.js.map +1 -1
- package/dist/svg/element.cjs +1 -1
- package/dist/svg/element.cjs.map +1 -1
- package/dist/svg/element.js +1 -22
- package/dist/svg/element.js.map +1 -1
- package/dist/svg/path.cjs +1 -1
- package/dist/svg/path.cjs.map +1 -1
- package/dist/svg/path.js +1 -48
- package/dist/svg/path.js.map +1 -1
- package/dist/svg/text.cjs +1 -1
- package/dist/svg/text.cjs.map +1 -1
- package/dist/svg/text.js +1 -9
- package/dist/svg/text.js.map +1 -1
- package/dist/theme/index.cjs +1 -1
- package/dist/theme/index.cjs.map +1 -1
- package/dist/theme/index.js +1 -19
- package/dist/theme/index.js.map +1 -1
- package/dist/types.d.ts +24 -48
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -9
- package/dist/core/resolve.cjs +0 -2
- package/dist/core/resolve.cjs.map +0 -1
- package/dist/core/resolve.d.ts +0 -9
- package/dist/core/resolve.d.ts.map +0 -1
- package/dist/core/resolve.js +0 -15
- package/dist/core/resolve.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,72 +1,50 @@
|
|
|
1
1
|
# @vielzeug/prism
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@vielzeug/prism) [](https://opensource.org/licenses/MIT)
|
|
6
|
-
|
|
7
|
-
<details>
|
|
8
|
-
<summary>Quick Reference</summary>
|
|
9
|
-
|
|
10
|
-
**Package:** `@vielzeug/prism` · **Category:** UI / Visualization
|
|
11
|
-
|
|
12
|
-
**Key exports:** `createLineChart`, `createBarChart`, `createAreaChart`, `createPieChart`, `createSparkline`, `linearScale`, `timeScale`, `bandScale`, `seriesColor`, `setTheme`
|
|
13
|
-
|
|
14
|
-
**When to use:** Data visualization with reactive charts that auto-update when signal-based data sources change. Renders accessible SVG, themeable via CSS custom properties.
|
|
15
|
-
|
|
16
|
-
**Related:** [@vielzeug/ripple](https://vielzeug.dev/ripple/) · [@vielzeug/refine](https://vielzeug.dev/refine/) · [@vielzeug/orbit](https://vielzeug.dev/orbit/)
|
|
17
|
-
|
|
18
|
-
</details>
|
|
19
|
-
|
|
20
|
-
`@vielzeug/prism` is part of Vielzeug. It depends on Orbit for tooltips and Ripple for reactivity, and ships as a TypeScript package with ESM+CJS output.
|
|
3
|
+
> Responsive SVG charts with explicit updates — line, bar, area, pie, sparkline
|
|
21
4
|
|
|
22
5
|
## Installation
|
|
23
6
|
|
|
24
7
|
```sh
|
|
25
|
-
# pnpm
|
|
26
8
|
pnpm add @vielzeug/prism
|
|
27
|
-
# npm
|
|
28
9
|
npm install @vielzeug/prism
|
|
29
|
-
# yarn
|
|
30
10
|
yarn add @vielzeug/prism
|
|
31
11
|
```
|
|
32
12
|
|
|
33
|
-
## Sub-paths
|
|
34
|
-
|
|
35
|
-
| Import | Purpose |
|
|
36
|
-
| -------------------------- | -------------------------------------------------------------- |
|
|
37
|
-
| `@vielzeug/prism` | Chart factories, scales, and types |
|
|
38
|
-
| `@vielzeug/prism/theme` | Default CSS custom properties (light + dark mode) |
|
|
39
|
-
| `@vielzeug/prism/devtools` | `warn` / `issue` helpers (dev-only, tree-shaken in production) |
|
|
40
|
-
|
|
41
13
|
## Quick Start
|
|
42
14
|
|
|
43
15
|
```ts
|
|
44
16
|
import { createLineChart, setTheme } from '@vielzeug/prism';
|
|
45
|
-
import { signal } from '@vielzeug/ripple';
|
|
46
17
|
import '@vielzeug/prism/theme';
|
|
47
18
|
|
|
48
19
|
// Optional: apply a custom color palette at startup
|
|
49
20
|
setTheme({ colors: ['#6366f1', '#22d3ee', '#f59e0b', '#10b981'] });
|
|
50
21
|
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
let series = [
|
|
23
|
+
{
|
|
24
|
+
color: '#3b82f6',
|
|
25
|
+
data: [
|
|
26
|
+
{ key: 1, value: 10 },
|
|
27
|
+
{ key: 2, value: 25 },
|
|
28
|
+
{ key: 3, value: 18 },
|
|
29
|
+
{ key: 4, value: 32 },
|
|
30
|
+
],
|
|
31
|
+
name: 'Revenue',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
57
34
|
|
|
58
35
|
const chart = createLineChart(document.getElementById('chart')!, {
|
|
59
36
|
a11y: { ariaLabel: 'Revenue by month' },
|
|
60
|
-
series
|
|
37
|
+
series,
|
|
61
38
|
xAxis: { position: 'bottom' },
|
|
62
39
|
yAxis: { position: 'left', grid: true },
|
|
63
40
|
tooltip: true,
|
|
64
41
|
crosshair: true,
|
|
65
|
-
onHover: (event) => console.log(event?.
|
|
42
|
+
onHover: (event) => console.log(event?.datum),
|
|
66
43
|
});
|
|
67
44
|
|
|
68
|
-
//
|
|
69
|
-
|
|
45
|
+
// Replace data explicitly when application state changes
|
|
46
|
+
series = [{ ...series[0]!, data: [...series[0]!.data, { key: 5, value: 28 }] }];
|
|
47
|
+
chart.update(series);
|
|
70
48
|
|
|
71
49
|
// Cleanup (also works with TC39 `using` declarations)
|
|
72
50
|
chart.dispose();
|
|
@@ -78,6 +56,7 @@ chart.dispose();
|
|
|
78
56
|
- [Usage Guide](https://vielzeug.dev/prism/usage)
|
|
79
57
|
- [API Reference](https://vielzeug.dev/prism/api)
|
|
80
58
|
- [Examples](https://vielzeug.dev/prism/examples)
|
|
59
|
+
- [Migration Guide](https://vielzeug.dev/prism/migration)
|
|
81
60
|
|
|
82
61
|
## License
|
|
83
62
|
|
package/dist/_dev.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function warn(e){}exports.warn=warn;
|
|
2
2
|
//# sourceMappingURL=_dev.cjs.map
|
package/dist/_dev.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,
|
|
1
|
+
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC"}
|
package/dist/_dev.js
CHANGED
package/dist/_dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={"ease-in":e=>e*e,"ease-in-out":e=>e<.5?2*e*e:1-(-2*e+2)**2/2,"ease-out":e=>1-(1-e)*(1-e),linear:e=>e};function
|
|
1
|
+
var e={"ease-in":e=>e*e,"ease-in-out":e=>e<.5?2*e*e:1-(-2*e+2)**2/2,"ease-out":e=>1-(1-e)*(1-e),linear:e=>e};function resolveEasing(t){return typeof t==`function`?t:t!==void 0&&Object.hasOwn(e,t)?e[t]:e[`ease-out`]}exports.easings=e,exports.resolveEasing=resolveEasing;
|
|
2
2
|
//# sourceMappingURL=easing.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,
|
|
1
|
+
{"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
|
package/dist/animation/easing.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = {
|
|
3
|
-
"ease-in": (e) => e * e,
|
|
4
|
-
"ease-in-out": (e) => e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2,
|
|
5
|
-
"ease-out": (e) => 1 - (1 - e) * (1 - e),
|
|
6
|
-
linear: (e) => e
|
|
7
|
-
};
|
|
8
|
-
function t(t) {
|
|
9
|
-
return typeof t == "function" ? t : t !== void 0 && Object.hasOwn(e, t) ? e[t] : e["ease-out"];
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { e as easings, t as resolveEasing };
|
|
13
|
-
|
|
1
|
+
var e={"ease-in":e=>e*e,"ease-in-out":e=>e<.5?2*e*e:1-(-2*e+2)**2/2,"ease-out":e=>1-(1-e)*(1-e),linear:e=>e};function resolveEasing(t){return typeof t==`function`?t:t!==void 0&&Object.hasOwn(e,t)?e[t]:e[`ease-out`]}export{e as easings,resolveEasing};
|
|
14
2
|
//# sourceMappingURL=easing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function resolveMotion(e,t=300){let n=e?.preference??`system`,r=typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=n===`never`||n===`system`&&r?0:e?.duration??t;return{...e,duration:i,stagger:Math.max(0,e?.stagger??0)}}exports.resolveMotion=resolveMotion;
|
|
2
2
|
//# sourceMappingURL=motion.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion.cjs","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":"AAEA,SAAgB,
|
|
1
|
+
{"version":3,"file":"motion.cjs","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":"AAEA,SAAgB,cACd,EACA,EAAkB,IAC2D,CAC7E,IAAM,EAAa,GAAQ,YAAc,SACnC,EAAU,OAAO,WAAe,KAAe,WAAW,kCAAkC,CAAC,CAAC,QAC9F,EACJ,IAAe,SAAY,IAAe,UAAY,EAAW,EAAK,GAAQ,UAAY,EAE5F,MAAO,CAAE,GAAG,EAAQ,WAAU,QAAS,KAAK,IAAI,EAAG,GAAQ,SAAW,CAAC,CAAE,CAC3E"}
|
package/dist/animation/motion.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e, t = 300) {
|
|
3
|
-
let n = e?.preference ?? "system", r = typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches, i = n === "never" || n === "system" && r ? 0 : e?.duration ?? t;
|
|
4
|
-
return {
|
|
5
|
-
...e,
|
|
6
|
-
duration: i,
|
|
7
|
-
stagger: Math.max(0, e?.stagger ?? 0)
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { e as resolveMotion };
|
|
12
|
-
|
|
1
|
+
function resolveMotion(e,t=300){let n=e?.preference??`system`,r=typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=n===`never`||n===`system`&&r?0:e?.duration??t;return{...e,duration:i,stagger:Math.max(0,e?.stagger??0)}}export{resolveMotion};
|
|
13
2
|
//# sourceMappingURL=motion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion.js","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"motion.js","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":"AAEA,SAAgB,cACd,EACA,EAAkB,IAC2D,CAC7E,IAAM,EAAa,GAAQ,YAAc,SACnC,EAAU,OAAO,WAAe,KAAe,WAAW,kCAAkC,CAAC,CAAC,QAC9F,EACJ,IAAe,SAAY,IAAe,UAAY,EAAW,EAAK,GAAQ,UAAY,EAE5F,MAAO,CAAE,GAAG,EAAQ,WAAU,QAAS,KAAK,IAAI,EAAG,GAAQ,SAAW,CAAC,CAAE,CAC3E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./easing.cjs"),t=require("./motion.cjs"),n=require("./tween.cjs");function
|
|
1
|
+
const e=require("./easing.cjs"),t=require("./motion.cjs"),n=require("./tween.cjs");function animate(r,i,a,o){let s=t.resolveMotion(i),c=s.duration,l=e.resolveEasing(s.easing),u=s.stagger;if(c===0||r.length===0){for(let e of r)for(let[t,{to:n}]of Object.entries(e.attrs))e.el.setAttribute(t,String(n));return a?.(),()=>{}}let d=null,f=!1,p=Math.max(c,c+u*(r.length-1));function frame(e){if(f||o?.aborted)return;d===null&&(d=e);let t=e-d;for(let e=0;e<r.length;e++){let i=r[e],a=u*e,o=Math.max(0,t-a),s=Math.min(1,o/c),d=l(s);for(let[e,{from:t,to:r}]of Object.entries(i.attrs))i.el.setAttribute(e,String(n.tweenNumber(t,r,d)))}t<p?requestAnimationFrame(frame):a?.()}return requestAnimationFrame(frame),()=>{f=!0}}exports.animate=animate;
|
|
2
2
|
//# sourceMappingURL=transition.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.cjs","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":"mFAgBA,SAAgB,
|
|
1
|
+
{"version":3,"file":"transition.cjs","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":"mFAgBA,SAAgB,QACd,EACA,EACA,EACA,EACY,CACZ,IAAM,EAAS,EAAA,cAAc,CAAM,EAC7B,EAAW,EAAO,SAClB,EAAS,EAAA,cAAc,EAAO,MAAM,EACpC,EAAU,EAAO,QAEvB,GAAI,IAAa,GAAK,EAAQ,SAAW,EAAG,CAC1C,IAAK,IAAM,KAAU,EACnB,IAAK,GAAM,CAAC,EAAM,CAAE,SAAS,OAAO,QAAQ,EAAO,KAAK,EACtD,EAAO,GAAG,aAAa,EAAM,OAAO,CAAE,CAAC,EAM3C,OAFA,IAAa,MAEA,CAAC,CAChB,CAEA,IAAI,EAA2B,KAC3B,EAAY,GACV,EAAgB,KAAK,IAAI,EAAU,EAAW,GAAW,EAAQ,OAAS,EAAE,EAElF,SAAS,MAAM,EAAmB,CAChC,GAAI,GAAa,GAAQ,QAAS,OAE9B,IAAc,OAAM,EAAY,GAEpC,IAAM,EAAU,EAAY,EAE5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAM,EAAS,EAAQ,GACjB,EAAQ,EAAU,EAClB,EAAe,KAAK,IAAI,EAAG,EAAU,CAAK,EAC1C,EAAI,KAAK,IAAI,EAAG,EAAe,CAAQ,EACvC,EAAQ,EAAO,CAAC,EAEtB,IAAK,GAAM,CAAC,EAAM,CAAE,OAAM,SAAS,OAAO,QAAQ,EAAO,KAAK,EAC5D,EAAO,GAAG,aAAa,EAAM,OAAO,EAAA,YAAY,EAAM,EAAI,CAAK,CAAC,CAAC,CAErE,CAEI,EAAU,EACZ,sBAAsB,KAAK,EAE3B,IAAa,CAEjB,CAIA,OAFA,sBAAsB,KAAK,MAEd,CACX,EAAY,EACd,CACF"}
|
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolveMotion as t } from "./motion.js";
|
|
3
|
-
import { tweenNumber as n } from "./tween.js";
|
|
4
|
-
//#region src/animation/transition.ts
|
|
5
|
-
function r(r, i, a, o) {
|
|
6
|
-
let s = t(i), c = s.duration, l = e(s.easing), u = s.stagger;
|
|
7
|
-
if (c === 0 || r.length === 0) {
|
|
8
|
-
for (let e of r) for (let [t, { to: n }] of Object.entries(e.attrs)) e.el.setAttribute(t, String(n));
|
|
9
|
-
return a?.(), () => {};
|
|
10
|
-
}
|
|
11
|
-
let d = null, f = !1, p = Math.max(c, c + u * (r.length - 1));
|
|
12
|
-
function m(e) {
|
|
13
|
-
if (f || o?.aborted) return;
|
|
14
|
-
d === null && (d = e);
|
|
15
|
-
let t = e - d;
|
|
16
|
-
for (let e = 0; e < r.length; e++) {
|
|
17
|
-
let i = r[e], a = u * e, o = Math.max(0, t - a), s = Math.min(1, o / c), d = l(s);
|
|
18
|
-
for (let [e, { from: t, to: r }] of Object.entries(i.attrs)) i.el.setAttribute(e, String(n(t, r, d)));
|
|
19
|
-
}
|
|
20
|
-
t < p ? requestAnimationFrame(m) : a?.();
|
|
21
|
-
}
|
|
22
|
-
return requestAnimationFrame(m), () => {
|
|
23
|
-
f = !0;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { r as animate };
|
|
28
|
-
|
|
1
|
+
import{resolveEasing as e}from"./easing.js";import{resolveMotion as t}from"./motion.js";import{tweenNumber as n}from"./tween.js";function animate(r,i,a,o){let s=t(i),c=s.duration,l=e(s.easing),u=s.stagger;if(c===0||r.length===0){for(let e of r)for(let[t,{to:n}]of Object.entries(e.attrs))e.el.setAttribute(t,String(n));return a?.(),()=>{}}let d=null,f=!1,p=Math.max(c,c+u*(r.length-1));function frame(e){if(f||o?.aborted)return;d===null&&(d=e);let t=e-d;for(let e=0;e<r.length;e++){let i=r[e],a=u*e,o=Math.max(0,t-a),s=Math.min(1,o/c),d=l(s);for(let[e,{from:t,to:r}]of Object.entries(i.attrs))i.el.setAttribute(e,String(n(t,r,d)))}t<p?requestAnimationFrame(frame):a?.()}return requestAnimationFrame(frame),()=>{f=!0}}export{animate};
|
|
29
2
|
//# sourceMappingURL=transition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.js","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"transition.js","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":"iIAgBA,SAAgB,QACd,EACA,EACA,EACA,EACY,CACZ,IAAM,EAAS,EAAc,CAAM,EAC7B,EAAW,EAAO,SAClB,EAAS,EAAc,EAAO,MAAM,EACpC,EAAU,EAAO,QAEvB,GAAI,IAAa,GAAK,EAAQ,SAAW,EAAG,CAC1C,IAAK,IAAM,KAAU,EACnB,IAAK,GAAM,CAAC,EAAM,CAAE,SAAS,OAAO,QAAQ,EAAO,KAAK,EACtD,EAAO,GAAG,aAAa,EAAM,OAAO,CAAE,CAAC,EAM3C,OAFA,IAAa,MAEA,CAAC,CAChB,CAEA,IAAI,EAA2B,KAC3B,EAAY,GACV,EAAgB,KAAK,IAAI,EAAU,EAAW,GAAW,EAAQ,OAAS,EAAE,EAElF,SAAS,MAAM,EAAmB,CAChC,GAAI,GAAa,GAAQ,QAAS,OAE9B,IAAc,OAAM,EAAY,GAEpC,IAAM,EAAU,EAAY,EAE5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAM,EAAS,EAAQ,GACjB,EAAQ,EAAU,EAClB,EAAe,KAAK,IAAI,EAAG,EAAU,CAAK,EAC1C,EAAI,KAAK,IAAI,EAAG,EAAe,CAAQ,EACvC,EAAQ,EAAO,CAAC,EAEtB,IAAK,GAAM,CAAC,EAAM,CAAE,OAAM,SAAS,OAAO,QAAQ,EAAO,KAAK,EAC5D,EAAO,GAAG,aAAa,EAAM,OAAO,EAAY,EAAM,EAAI,CAAK,CAAC,CAAC,CAErE,CAEI,EAAU,EACZ,sBAAsB,KAAK,EAE3B,IAAa,CAEjB,CAIA,OAFA,sBAAsB,KAAK,MAEd,CACX,EAAY,EACd,CACF"}
|
package/dist/animation/tween.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function tweenNumber(e,t,n){return e+(t-e)*n}exports.tweenNumber=tweenNumber;
|
|
2
2
|
//# sourceMappingURL=tween.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tween.cjs","names":[],"sources":["../../src/animation/tween.ts"],"sourcesContent":["export function tweenNumber(from: number, to: number, t: number): number {\n return from + (to - from) * t;\n}\n"],"mappings":"AAAA,SAAgB,
|
|
1
|
+
{"version":3,"file":"tween.cjs","names":[],"sources":["../../src/animation/tween.ts"],"sourcesContent":["export function tweenNumber(from: number, to: number, t: number): number {\n return from + (to - from) * t;\n}\n"],"mappings":"AAAA,SAAgB,YAAY,EAAc,EAAY,EAAmB,CACvE,OAAO,GAAQ,EAAK,GAAQ,CAC9B"}
|
package/dist/animation/tween.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tween.js","names":[],"sources":["../../src/animation/tween.ts"],"sourcesContent":["export function tweenNumber(from: number, to: number, t: number): number {\n return from + (to - from) * t;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tween.js","names":[],"sources":["../../src/animation/tween.ts"],"sourcesContent":["export function tweenNumber(from: number, to: number, t: number): number {\n return from + (to - from) * t;\n}\n"],"mappings":"AAAA,SAAgB,YAAY,EAAc,EAAY,EAAmB,CACvE,OAAO,GAAQ,EAAK,GAAQ,CAC9B"}
|
package/dist/axes/axis.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var
|
|
1
|
+
const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function renderAxis(r,i,a,o,s=`bottom`){e.removeChildren(r);let c=a.position??s,l=c===`bottom`||c===`top`,u=c===`top`||c===`left`,d=u?-1:1,f=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:l?o:0,y1:0,y2:l?0:o});r.appendChild(f);let p=i.ticks(resolveTickCount(a,o,s)),m=a.tickFormat??defaultTickFormat;for(let a of p){let o=n.mapTick(i,a),s=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:l?o:0,x2:l?o:6*d,y1:l?0:o,y2:l?6*d:o});r.appendChild(s);let c=t.createTextElement(m(a),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":l?u?`auto`:`hanging`:`middle`,"text-anchor":l?`middle`:u?`end`:`start`,x:l?o:6*d*1.5,y:l?6*d*1.5:o});r.appendChild(c)}if(a.label){let n=t.createTextElement(a.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});l?e.setAttributes(n,{x:o/2,y:6*d*6}):e.setAttributes(n,{transform:`translate(${6*d*7}, ${o/2}) rotate(-90)`}),r.appendChild(n)}}exports.positionAxis=positionAxis,exports.renderAxis=renderAxis,exports.resolveTickCount=resolveTickCount;
|
|
2
2
|
//# sourceMappingURL=axis.cjs.map
|
package/dist/axes/axis.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection *
|
|
1
|
+
{"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"kGAKA,IAAM,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK,IAAa,QAAU,aAAa,EAAM,KAAO,IAAA,GAElG,EAAW,EAAO,aAAa,YAAa,CAAS,EACpD,EAAO,gBAAgB,WAAW,CACzC,CAEA,SAAgB,iBAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC7B,CAOA,SAAgB,WACd,EACA,EACA,EACA,EACA,EAAgC,SAC1B,CACN,EAAA,eAAe,CAAM,EAErB,IAAM,EAAW,EAAO,UAAY,EAC9B,EAAe,IAAa,UAAY,IAAa,MACrD,EAAa,IAAa,OAAS,IAAa,OAEhD,EAAgB,EAAa,GAAK,EAElC,EAAW,EAAA,iBAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAmB,EACnB,GAAI,EAAe,EAAS,EAC5B,GAAmB,EACnB,GAAI,EAAe,EAAI,CACzB,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAM,MAAM,iBAAiB,EAAQ,EAAQ,CAAe,CAAC,EACrE,EAAS,EAAO,YAAc,kBAEpC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAA,QAAQ,EAAO,CAAI,EACzB,EAAW,EAAA,iBAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAI,EAAe,EAAM,EACzB,GAAI,EAAe,EAAM,EAAW,EACpC,GAAI,EAAe,EAAI,EACvB,GAAI,EAAe,EAAW,EAAgB,CAChD,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAA,kBAAkB,EAAO,CAAI,EAAG,CAC5C,cAAe,OACf,MAAO,mBACP,oBAAqB,EAAgB,EAAa,OAAS,UAAa,SACxE,cAAe,EAAe,SAAW,EAAa,MAAQ,QAC9D,EAAG,EAAe,EAAM,EAAW,EAAgB,IACnD,EAAG,EAAe,EAAW,EAAgB,IAAM,CACrD,CAAC,EAED,EAAO,YAAY,CAAK,CAC1B,CAEA,GAAI,EAAO,MAAO,CAChB,IAAM,EAAU,EAAA,kBAAkB,EAAO,MAAO,CAC9C,MAAO,mBACP,oBAAqB,SACrB,cAAe,QACjB,CAAC,EAEG,EACF,EAAA,cAAc,EAAS,CAAE,EAAG,EAAS,EAAG,EAAG,EAAW,EAAgB,CAAE,CAAC,EAEzE,EAAA,cAAc,EAAS,CACrB,UAAW,aAAa,EAAW,EAAgB,EAAE,IAAI,EAAS,EAAE,cACtE,CAAC,EAGH,EAAO,YAAY,CAAO,CAC5B,CACF"}
|
package/dist/axes/axis.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type AnyScale } from './scale-utils';
|
|
|
5
5
|
* `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the
|
|
6
6
|
* one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).
|
|
7
7
|
*/
|
|
8
|
+
export declare function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void;
|
|
8
9
|
export declare function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number;
|
|
9
10
|
/**
|
|
10
11
|
* `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an
|
package/dist/axes/axis.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/axes/axis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,GAAG,MAAM,CAM1G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,YAAuB,GACvC,IAAI,CAiEN"}
|
|
1
|
+
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/axes/axis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM7G;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,GAAG,MAAM,CAM1G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,YAAuB,GACvC,IAAI,CAiEN"}
|
package/dist/axes/axis.js
CHANGED
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createTextElement as r } from "../svg/text.js";
|
|
3
|
-
import { mapTick as i } from "./scale-utils.js";
|
|
4
|
-
//#region src/axes/axis.ts
|
|
5
|
-
var a = (e) => e instanceof Date ? e.toLocaleDateString(void 0, {
|
|
6
|
-
month: "short",
|
|
7
|
-
year: "numeric"
|
|
8
|
-
}) : String(e);
|
|
9
|
-
function o(e, t, n) {
|
|
10
|
-
let r = e.position ?? n, i = r === "bottom" || r === "top" ? Math.max(2, Math.floor(t / 80)) : Math.max(2, Math.floor(t / 50));
|
|
11
|
-
return e.tickCount ?? i;
|
|
12
|
-
}
|
|
13
|
-
function s(s, c, l, u, d = "bottom") {
|
|
14
|
-
t(s);
|
|
15
|
-
let f = l.position ?? d, p = f === "bottom" || f === "top", m = f === "top" || f === "left", h = m ? -1 : 1, g = e("line", {
|
|
16
|
-
"aria-hidden": "true",
|
|
17
|
-
class: "prism-axis-line",
|
|
18
|
-
x1: 0,
|
|
19
|
-
x2: p ? u : 0,
|
|
20
|
-
y1: 0,
|
|
21
|
-
y2: p ? 0 : u
|
|
22
|
-
});
|
|
23
|
-
s.appendChild(g);
|
|
24
|
-
let _ = c.ticks(o(l, u, d)), v = l.tickFormat ?? a;
|
|
25
|
-
for (let t of _) {
|
|
26
|
-
let n = i(c, t), a = e("line", {
|
|
27
|
-
"aria-hidden": "true",
|
|
28
|
-
class: "prism-axis-tick",
|
|
29
|
-
x1: p ? n : 0,
|
|
30
|
-
x2: p ? n : 6 * h,
|
|
31
|
-
y1: p ? 0 : n,
|
|
32
|
-
y2: p ? 6 * h : n
|
|
33
|
-
});
|
|
34
|
-
s.appendChild(a);
|
|
35
|
-
let o = r(v(t), {
|
|
36
|
-
"aria-hidden": "true",
|
|
37
|
-
class: "prism-axis-label",
|
|
38
|
-
"dominant-baseline": p ? m ? "auto" : "hanging" : "middle",
|
|
39
|
-
"text-anchor": p ? "middle" : m ? "end" : "start",
|
|
40
|
-
x: p ? n : 6 * h * 1.5,
|
|
41
|
-
y: p ? 6 * h * 1.5 : n
|
|
42
|
-
});
|
|
43
|
-
s.appendChild(o);
|
|
44
|
-
}
|
|
45
|
-
if (l.label) {
|
|
46
|
-
let e = r(l.label, {
|
|
47
|
-
class: "prism-axis-title",
|
|
48
|
-
"dominant-baseline": "middle",
|
|
49
|
-
"text-anchor": "middle"
|
|
50
|
-
});
|
|
51
|
-
p ? n(e, {
|
|
52
|
-
x: u / 2,
|
|
53
|
-
y: 6 * h * 3.5
|
|
54
|
-
}) : n(e, { transform: `translate(${6 * h * 4}, ${u / 2}) rotate(-90)` }), s.appendChild(e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
export { s as renderAxis, o as resolveTickCount };
|
|
59
|
-
|
|
1
|
+
import{createSvgElement as e,removeChildren as t,setAttributes as n}from"../svg/element.js";import{createTextElement as r}from"../svg/text.js";import{mapTick as i}from"./scale-utils.js";var defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function renderAxis(a,o,s,c,l=`bottom`){t(a);let u=s.position??l,d=u===`bottom`||u===`top`,f=u===`top`||u===`left`,p=f?-1:1,m=e(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:d?c:0,y1:0,y2:d?0:c});a.appendChild(m);let h=o.ticks(resolveTickCount(s,c,l)),g=s.tickFormat??defaultTickFormat;for(let t of h){let n=i(o,t),s=e(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:d?n:0,x2:d?n:6*p,y1:d?0:n,y2:d?6*p:n});a.appendChild(s);let c=r(g(t),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":d?f?`auto`:`hanging`:`middle`,"text-anchor":d?`middle`:f?`end`:`start`,x:d?n:6*p*1.5,y:d?6*p*1.5:n});a.appendChild(c)}if(s.label){let e=r(s.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});d?n(e,{x:c/2,y:6*p*6}):n(e,{transform:`translate(${6*p*7}, ${c/2}) rotate(-90)`}),a.appendChild(e)}}export{positionAxis,renderAxis,resolveTickCount};
|
|
60
2
|
//# sourceMappingURL=axis.js.map
|
package/dist/axes/axis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection *
|
|
1
|
+
{"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"0LAKA,IAAM,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK,IAAa,QAAU,aAAa,EAAM,KAAO,IAAA,GAElG,EAAW,EAAO,aAAa,YAAa,CAAS,EACpD,EAAO,gBAAgB,WAAW,CACzC,CAEA,SAAgB,iBAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC7B,CAOA,SAAgB,WACd,EACA,EACA,EACA,EACA,EAAgC,SAC1B,CACN,EAAe,CAAM,EAErB,IAAM,EAAW,EAAO,UAAY,EAC9B,EAAe,IAAa,UAAY,IAAa,MACrD,EAAa,IAAa,OAAS,IAAa,OAEhD,EAAgB,EAAa,GAAK,EAElC,EAAW,EAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAmB,EACnB,GAAI,EAAe,EAAS,EAC5B,GAAmB,EACnB,GAAI,EAAe,EAAI,CACzB,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAM,MAAM,iBAAiB,EAAQ,EAAQ,CAAe,CAAC,EACrE,EAAS,EAAO,YAAc,kBAEpC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAQ,EAAO,CAAI,EACzB,EAAW,EAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAI,EAAe,EAAM,EACzB,GAAI,EAAe,EAAM,EAAW,EACpC,GAAI,EAAe,EAAI,EACvB,GAAI,EAAe,EAAW,EAAgB,CAChD,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAkB,EAAO,CAAI,EAAG,CAC5C,cAAe,OACf,MAAO,mBACP,oBAAqB,EAAgB,EAAa,OAAS,UAAa,SACxE,cAAe,EAAe,SAAW,EAAa,MAAQ,QAC9D,EAAG,EAAe,EAAM,EAAW,EAAgB,IACnD,EAAG,EAAe,EAAW,EAAgB,IAAM,CACrD,CAAC,EAED,EAAO,YAAY,CAAK,CAC1B,CAEA,GAAI,EAAO,MAAO,CAChB,IAAM,EAAU,EAAkB,EAAO,MAAO,CAC9C,MAAO,mBACP,oBAAqB,SACrB,cAAe,QACjB,CAAC,EAEG,EACF,EAAc,EAAS,CAAE,EAAG,EAAS,EAAG,EAAG,EAAW,EAAgB,CAAE,CAAC,EAEzE,EAAc,EAAS,CACrB,UAAW,aAAa,EAAW,EAAgB,EAAE,IAAI,EAAS,EAAE,cACtE,CAAC,EAGH,EAAO,YAAY,CAAO,CAC5B,CACF"}
|
package/dist/axes/grid.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../svg/element.cjs"),t=require("./scale-utils.cjs");function
|
|
1
|
+
const e=require("../svg/element.cjs"),t=require("./scale-utils.cjs");function renderGrid(n,r,i,a,o,s=10){e.removeChildren(n);let c=i!==!0&&i.color||void 0,l=i!==!0&&i.dash||void 0,u=r.ticks(s);for(let i of u){let s=t.mapTick(r,i),u={class:`prism-grid-line`,stroke:c??`var(--prism-grid-color)`,"stroke-dasharray":l,"stroke-opacity":`var(--prism-grid-opacity)`};o===`vertical`?Object.assign(u,{x1:s,x2:s,y1:0,y2:a}):Object.assign(u,{x1:0,x2:a,y1:s,y2:s}),n.appendChild(e.createSvgElement(`line`,u))}}exports.renderGrid=renderGrid;
|
|
2
2
|
//# sourceMappingURL=grid.cjs.map
|
package/dist/axes/grid.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.cjs","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":"qEAIA,SAAgB,
|
|
1
|
+
{"version":3,"file":"grid.cjs","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":"qEAIA,SAAgB,WACd,EACA,EACA,EACA,EACA,EACA,EAAY,GACN,CACN,EAAA,eAAe,CAAM,EAErB,IAAM,EAAS,IAAW,IAAQ,EAAO,OAAU,IAAA,GAC7C,EAAQ,IAAW,IAAQ,EAAO,MAAS,IAAA,GAC3C,EAAQ,EAAM,MAAM,CAAS,EAEnC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAA,QAAQ,EAAO,CAAI,EACzB,EAAqD,CACzD,MAAO,kBACP,OAAQ,GAAS,0BACjB,mBAAoB,EACpB,iBAAkB,2BACpB,EAEI,IAAc,WAChB,OAAO,OAAO,EAAO,CAAE,GAAI,EAAK,GAAI,EAAK,GAAI,EAAG,GAAI,CAAY,CAAC,EAEjE,OAAO,OAAO,EAAO,CAAE,GAAI,EAAG,GAAI,EAAa,GAAI,EAAK,GAAI,CAAI,CAAC,EAGnE,EAAO,YAAY,EAAA,iBAAiB,OAAQ,CAAK,CAAC,CACpD,CACF"}
|
package/dist/axes/grid.js
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { mapTick as n } from "./scale-utils.js";
|
|
3
|
-
//#region src/axes/grid.ts
|
|
4
|
-
function r(r, i, a, o, s, c = 10) {
|
|
5
|
-
t(r);
|
|
6
|
-
let l = a !== !0 && a.color || void 0, u = a !== !0 && a.dash || void 0, d = i.ticks(c);
|
|
7
|
-
for (let t of d) {
|
|
8
|
-
let a = n(i, t), c = {
|
|
9
|
-
class: "prism-grid-line",
|
|
10
|
-
stroke: l ?? "var(--prism-grid-color)",
|
|
11
|
-
"stroke-dasharray": u,
|
|
12
|
-
"stroke-opacity": "var(--prism-grid-opacity)"
|
|
13
|
-
};
|
|
14
|
-
s === "vertical" ? Object.assign(c, {
|
|
15
|
-
x1: a,
|
|
16
|
-
x2: a,
|
|
17
|
-
y1: 0,
|
|
18
|
-
y2: o
|
|
19
|
-
}) : Object.assign(c, {
|
|
20
|
-
x1: 0,
|
|
21
|
-
x2: o,
|
|
22
|
-
y1: a,
|
|
23
|
-
y2: a
|
|
24
|
-
}), r.appendChild(e("line", c));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { r as renderGrid };
|
|
29
|
-
|
|
1
|
+
import{createSvgElement as e,removeChildren as t}from"../svg/element.js";import{mapTick as n}from"./scale-utils.js";function renderGrid(r,i,a,o,s,c=10){t(r);let l=a!==!0&&a.color||void 0,u=a!==!0&&a.dash||void 0,d=i.ticks(c);for(let t of d){let a=n(i,t),c={class:`prism-grid-line`,stroke:l??`var(--prism-grid-color)`,"stroke-dasharray":u,"stroke-opacity":`var(--prism-grid-opacity)`};s===`vertical`?Object.assign(c,{x1:a,x2:a,y1:0,y2:o}):Object.assign(c,{x1:0,x2:o,y1:a,y2:a}),r.appendChild(e(`line`,c))}}export{renderGrid};
|
|
30
2
|
//# sourceMappingURL=grid.js.map
|
package/dist/axes/grid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.js","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"grid.js","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":"oHAIA,SAAgB,WACd,EACA,EACA,EACA,EACA,EACA,EAAY,GACN,CACN,EAAe,CAAM,EAErB,IAAM,EAAS,IAAW,IAAQ,EAAO,OAAU,IAAA,GAC7C,EAAQ,IAAW,IAAQ,EAAO,MAAS,IAAA,GAC3C,EAAQ,EAAM,MAAM,CAAS,EAEnC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAQ,EAAO,CAAI,EACzB,EAAqD,CACzD,MAAO,kBACP,OAAQ,GAAS,0BACjB,mBAAoB,EACpB,iBAAkB,2BACpB,EAEI,IAAc,WAChB,OAAO,OAAO,EAAO,CAAE,GAAI,EAAK,GAAI,EAAK,GAAI,EAAG,GAAI,CAAY,CAAC,EAEjE,OAAO,OAAO,EAAO,CAAE,GAAI,EAAG,GAAI,EAAa,GAAI,EAAK,GAAI,CAAI,CAAC,EAGnE,EAAO,YAAY,EAAiB,OAAQ,CAAK,CAAC,CACpD,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function isBandScale(e){return typeof e.bandwidth==`function`}function mapTick(e,t){return isBandScale(e)?e.map(t)+e.bandwidth()/2:e.map(t)}exports.mapTick=mapTick;
|
|
2
2
|
//# sourceMappingURL=scale-utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale-utils.cjs","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with —\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union — the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,
|
|
1
|
+
{"version":3,"file":"scale-utils.cjs","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with —\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union — the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,YAAY,EAAqC,CACxD,OAAO,OAAQ,EAAoB,WAAc,UACnD,CAmBA,SAAgB,QAAQ,EAAiB,EAAsC,CAG7E,OAFI,YAAY,CAAK,EAAU,EAAM,IAAI,CAAc,EAAI,EAAM,UAAU,EAAI,EAEvE,EAA+B,IAAI,CAAqB,CAClE"}
|
package/dist/axes/scale-utils.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e) {
|
|
3
|
-
return typeof e.bandwidth == "function";
|
|
4
|
-
}
|
|
5
|
-
function t(t, n) {
|
|
6
|
-
return e(t) ? t.map(n) + t.bandwidth() / 2 : t.map(n);
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as mapTick };
|
|
10
|
-
|
|
1
|
+
function isBandScale(e){return typeof e.bandwidth==`function`}function mapTick(e,t){return isBandScale(e)?e.map(t)+e.bandwidth()/2:e.map(t)}export{mapTick};
|
|
11
2
|
//# sourceMappingURL=scale-utils.js.map
|