@vielzeug/ink 0.0.0-stage → 26.11.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/_validate.cjs +2 -0
  4. package/dist/_validate.cjs.map +1 -0
  5. package/dist/_validate.d.ts +11 -0
  6. package/dist/_validate.d.ts.map +1 -0
  7. package/dist/_validate.js +32 -0
  8. package/dist/_validate.js.map +1 -0
  9. package/dist/errors.cjs +2 -0
  10. package/dist/errors.cjs.map +1 -0
  11. package/dist/errors.d.ts +8 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +9 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.cjs +1 -0
  16. package/dist/index.d.ts +14 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +8 -0
  19. package/dist/ink.cjs +2 -0
  20. package/dist/ink.cjs.map +1 -0
  21. package/dist/ink.iife.js +2 -0
  22. package/dist/ink.iife.js.map +1 -0
  23. package/dist/ink.js +191 -0
  24. package/dist/ink.js.map +1 -0
  25. package/dist/outline.cjs +2 -0
  26. package/dist/outline.cjs.map +1 -0
  27. package/dist/outline.d.ts +14 -0
  28. package/dist/outline.d.ts.map +1 -0
  29. package/dist/outline.js +48 -0
  30. package/dist/outline.js.map +1 -0
  31. package/dist/simplify.cjs +2 -0
  32. package/dist/simplify.cjs.map +1 -0
  33. package/dist/simplify.d.ts +12 -0
  34. package/dist/simplify.d.ts.map +1 -0
  35. package/dist/simplify.js +29 -0
  36. package/dist/simplify.js.map +1 -0
  37. package/dist/smoothing.cjs +2 -0
  38. package/dist/smoothing.cjs.map +1 -0
  39. package/dist/smoothing.d.ts +20 -0
  40. package/dist/smoothing.d.ts.map +1 -0
  41. package/dist/smoothing.js +39 -0
  42. package/dist/smoothing.js.map +1 -0
  43. package/dist/stabilize.cjs +2 -0
  44. package/dist/stabilize.cjs.map +1 -0
  45. package/dist/stabilize.d.ts +24 -0
  46. package/dist/stabilize.d.ts.map +1 -0
  47. package/dist/stabilize.js +25 -0
  48. package/dist/stabilize.js.map +1 -0
  49. package/dist/svg.cjs +2 -0
  50. package/dist/svg.cjs.map +1 -0
  51. package/dist/svg.d.ts +27 -0
  52. package/dist/svg.d.ts.map +1 -0
  53. package/dist/svg.js +14 -0
  54. package/dist/svg.js.map +1 -0
  55. package/dist/types.d.ts +20 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/widths.cjs +2 -0
  58. package/dist/widths.cjs.map +1 -0
  59. package/dist/widths.d.ts +26 -0
  60. package/dist/widths.d.ts.map +1 -0
  61. package/dist/widths.js +28 -0
  62. package/dist/widths.js.map +1 -0
  63. package/package.json +48 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Helmuth Saatkamp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # @vielzeug/ink
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Causal stroke stabilization, smoothing, speed-based width profiling, and SVG path output
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @vielzeug/ink
9
+ npm install @vielzeug/ink
10
+ yarn add @vielzeug/ink
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { polylineToSvgPath, stabilizeStroke, strokeOutline, strokeWidths } from '@vielzeug/ink';
17
+
18
+ // Stamp samples with PointerEvent.timeStamp for speed-derived widths.
19
+ const samples = [
20
+ { time: 0, x: 0, y: 0 },
21
+ { time: 16, x: 12, y: 3 },
22
+ { time: 32, x: 25, y: -2 },
23
+ { time: 48, x: 40, y: 1 },
24
+ ];
25
+
26
+ const stabilized = stabilizeStroke(samples);
27
+ const widths = strokeWidths(stabilized, { width: 6 });
28
+ const d = polylineToSvgPath(strokeOutline(stabilized, widths), { close: true });
29
+ ```
30
+
31
+ ## Features
32
+
33
+ - `stabilizeStroke()`: causal Streamline-style averaging for live drawing; the stroke ends where the pen lifted
34
+ - `smoothStroke()`: deterministic Catmull-Rom resampling after capture
35
+ - `strokeWidths()`: widths from real pen speed (`distance / Δtime`) with pressure modulation
36
+ - `strokeOutline()`: closed variable-width outline polygon with capped ends; constant width with a single number
37
+ - `simplifyStroke()`: Ramer-Douglas-Peucker decimation preserving endpoints
38
+ - `polylineToSvgPath()`: SVG `d` strings for strokes and closed rings, with configurable precision
39
+ - Pure functions, zero dependencies, no DOM requirement
40
+
41
+ ## Documentation
42
+
43
+ - [Overview](https://vielzeug.dev/ink/)
44
+ - [Usage Guide](https://vielzeug.dev/ink/usage)
45
+ - [API Reference](https://vielzeug.dev/ink/api)
46
+ - [Examples](https://vielzeug.dev/ink/examples)
47
+ - [Migration Guide](https://vielzeug.dev/ink/migration)
48
+
49
+ ## License
50
+
51
+ MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
@@ -0,0 +1,2 @@
1
+ const e=require("./errors.cjs");function requireFiniteNumber(t,n){if(typeof t!=`number`||!Number.isFinite(t))throw new e.InkConfigError(`Expected ${n} to be a finite number, received ${String(t)}.`);return t}function requireRange(t,n,r,i){if(t<r||t>i)throw new e.InkConfigError(`Expected ${n} to be within [${r}, ${i}], received ${t}.`);return t}function requirePositive(e,t){return requireRange(requireFiniteNumber(e,t),t,Number.MIN_VALUE,1/0)}function requireInteger(t,n,r,i){let a=requireFiniteNumber(t,n);if(!Number.isInteger(a))throw new e.InkConfigError(`Expected ${n} to be an integer, received ${String(t)}.`);return requireRange(a,n,r,i)}function requireStrokePoints(t,n=0){if(t.length<n)throw new e.InkConfigError(`Expected at least ${n} stroke point(s), received ${t.length}.`);return t}function clamp(e,t,n){return Math.min(n,Math.max(t,e))}function distance(e,t,n,r){let i=n-e,a=r-t;return Math.hypot(i,a)}exports.clamp=clamp,exports.distance=distance,exports.requireFiniteNumber=requireFiniteNumber,exports.requireInteger=requireInteger,exports.requirePositive=requirePositive,exports.requireRange=requireRange,exports.requireStrokePoints=requireStrokePoints;
2
+ //# sourceMappingURL=_validate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_validate.cjs","names":["InkConfigError","require_errors","value","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay"],"sources":["../src/_validate.ts"],"sourcesContent":["/** Internal validation helpers. Shared by every public entry point; never exported.\n *\n * Stroke points arrive typed and are produced by capture loops, not by untrusted\n * input, so they are not validated per point (matching atlas and wire). Only\n * option ranges and algorithm preconditions are checked.\n */\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport function requireFiniteNumber(value: unknown, name: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new InkConfigError(`Expected ${name} to be a finite number, received ${String(value)}.`);\n }\n return value;\n}\n\nexport function requireRange(value: number, name: string, min: number, max: number): number {\n if (value < min || value > max) {\n throw new InkConfigError(`Expected ${name} to be within [${min}, ${max}], received ${value}.`);\n }\n return value;\n}\n\nexport function requirePositive(value: unknown, name: string): number {\n return requireRange(requireFiniteNumber(value, name), name, Number.MIN_VALUE, Number.POSITIVE_INFINITY);\n}\n\nexport function requireInteger(value: unknown, name: string, min: number, max: number): number {\n const resolved = requireFiniteNumber(value, name);\n if (!Number.isInteger(resolved)) {\n throw new InkConfigError(`Expected ${name} to be an integer, received ${String(value)}.`);\n }\n return requireRange(resolved, name, min, max);\n}\n\n/** Checks the array shape and minimum length of a stroke; the points themselves are trusted as typed. */\nexport function requireStrokePoints(value: readonly StrokePoint[], minPoints = 0): readonly StrokePoint[] {\n if (value.length < minPoints) {\n throw new InkConfigError(`Expected at least ${minPoints} stroke point(s), received ${value.length}.`);\n }\n return value;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\n/** Distance between two points. */\nexport function distance(ax: number, ay: number, bx: number, by: number): number {\n const dx = bx - ax;\n const dy = by - ay;\n return Math.hypot(dx, dy);\n}\n"],"mappings":"A,gCASA,SAAgB,oBAAoB,EAAgB,EAAsB,CACxE,GAAI,OAAOE,GAAU,UAAY,CAAC,OAAO,SAASA,CAAK,EACrD,MAAM,IAAIF,EAAAA,eAAe,YAAYG,EAAK,mCAAmC,OAAOD,CAAK,EAAE,EAAE,EAE/F,OAAOA,CACT,CAEA,SAAgB,aAAa,EAAe,EAAc,EAAa,EAAqB,CAC1F,GAAIA,EAAQE,GAAOF,EAAQG,EACzB,MAAM,IAAIL,EAAAA,eAAe,YAAYG,EAAK,iBAAiBC,EAAI,IAAIC,EAAI,cAAcH,EAAM,EAAE,EAE/F,OAAOA,CACT,CAEA,SAAgB,gBAAgB,EAAgB,EAAsB,CACpE,OAAO,aAAa,oBAAoBA,EAAOC,CAAI,EAAGA,EAAM,OAAO,UAAW,GAAwB,CACxG,CAEA,SAAgB,eAAe,EAAgB,EAAc,EAAa,EAAqB,CAC7F,IAAMG,EAAW,oBAAoBJ,EAAOC,CAAI,EAChD,GAAI,CAAC,OAAO,UAAUG,CAAQ,EAC5B,MAAM,IAAIN,EAAAA,eAAe,YAAYG,EAAK,8BAA8B,OAAOD,CAAK,EAAE,EAAE,EAE1F,OAAO,aAAaI,EAAUH,EAAMC,EAAKC,CAAG,CAC9C,CAGA,SAAgB,oBAAoB,EAA+B,EAAY,EAA2B,CACxG,GAAIH,EAAM,OAASK,EACjB,MAAM,IAAIP,EAAAA,eAAe,qBAAqBO,EAAU,6BAA6BL,EAAM,OAAO,EAAE,EAEtG,OAAOA,CACT,CAEA,SAAgB,MAAM,EAAe,EAAa,EAAqB,CACrE,OAAO,KAAK,IAAIG,EAAK,KAAK,IAAID,EAAKF,CAAK,CAAC,CAC3C,CAGA,SAAgB,SAAS,EAAY,EAAY,EAAY,EAAoB,CAC/E,IAAMM,EAAKC,EAAKC,EACVC,EAAKC,EAAKC,EAChB,OAAO,KAAK,MAAML,EAAIG,CAAE,CAC1B,C"}
@@ -0,0 +1,11 @@
1
+ import type { StrokePoint } from './types.js';
2
+ export declare function requireFiniteNumber(value: unknown, name: string): number;
3
+ export declare function requireRange(value: number, name: string, min: number, max: number): number;
4
+ export declare function requirePositive(value: unknown, name: string): number;
5
+ export declare function requireInteger(value: unknown, name: string, min: number, max: number): number;
6
+ /** Checks the array shape and minimum length of a stroke; the points themselves are trusted as typed. */
7
+ export declare function requireStrokePoints(value: readonly StrokePoint[], minPoints?: number): readonly StrokePoint[];
8
+ export declare function clamp(value: number, min: number, max: number): number;
9
+ /** Distance between two points. */
10
+ export declare function distance(ax: number, ay: number, bx: number, by: number): number;
11
+ //# sourceMappingURL=_validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_validate.d.ts","sourceRoot":"","sources":["../src/_validate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKxE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK1F;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAM7F;AAED,yGAAyG;AACzG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,SAAS,SAAI,GAAG,SAAS,WAAW,EAAE,CAKxG;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,mCAAmC;AACnC,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAI/E"}
@@ -0,0 +1,32 @@
1
+ import { InkConfigError as e } from "./errors.js";
2
+ // src/_validate.ts
3
+ function requireFiniteNumber(t, n) {
4
+ if (typeof t != "number" || !Number.isFinite(t)) throw new e(`Expected ${n} to be a finite number, received ${String(t)}.`);
5
+ return t;
6
+ }
7
+ function requireRange(t, n, r, i) {
8
+ if (t < r || t > i) throw new e(`Expected ${n} to be within [${r}, ${i}], received ${t}.`);
9
+ return t;
10
+ }
11
+ function requirePositive(e, t) {
12
+ return requireRange(requireFiniteNumber(e, t), t, Number.MIN_VALUE, Infinity);
13
+ }
14
+ function requireInteger(t, n, r, i) {
15
+ let a = requireFiniteNumber(t, n);
16
+ if (!Number.isInteger(a)) throw new e(`Expected ${n} to be an integer, received ${String(t)}.`);
17
+ return requireRange(a, n, r, i);
18
+ }
19
+ function requireStrokePoints(t, n = 0) {
20
+ if (t.length < n) throw new e(`Expected at least ${n} stroke point(s), received ${t.length}.`);
21
+ return t;
22
+ }
23
+ function clamp(e, t, n) {
24
+ return Math.min(n, Math.max(t, e));
25
+ }
26
+ function distance(e, t, n, r) {
27
+ let i = n - e, a = r - t;
28
+ return Math.hypot(i, a);
29
+ }
30
+ export { clamp, distance, requireFiniteNumber, requireInteger, requirePositive, requireRange, requireStrokePoints };
31
+
32
+ //# sourceMappingURL=_validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_validate.js","names":["value","InkConfigError","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay"],"sources":["../src/_validate.ts"],"sourcesContent":["/** Internal validation helpers. Shared by every public entry point; never exported.\n *\n * Stroke points arrive typed and are produced by capture loops, not by untrusted\n * input, so they are not validated per point (matching atlas and wire). Only\n * option ranges and algorithm preconditions are checked.\n */\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport function requireFiniteNumber(value: unknown, name: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new InkConfigError(`Expected ${name} to be a finite number, received ${String(value)}.`);\n }\n return value;\n}\n\nexport function requireRange(value: number, name: string, min: number, max: number): number {\n if (value < min || value > max) {\n throw new InkConfigError(`Expected ${name} to be within [${min}, ${max}], received ${value}.`);\n }\n return value;\n}\n\nexport function requirePositive(value: unknown, name: string): number {\n return requireRange(requireFiniteNumber(value, name), name, Number.MIN_VALUE, Number.POSITIVE_INFINITY);\n}\n\nexport function requireInteger(value: unknown, name: string, min: number, max: number): number {\n const resolved = requireFiniteNumber(value, name);\n if (!Number.isInteger(resolved)) {\n throw new InkConfigError(`Expected ${name} to be an integer, received ${String(value)}.`);\n }\n return requireRange(resolved, name, min, max);\n}\n\n/** Checks the array shape and minimum length of a stroke; the points themselves are trusted as typed. */\nexport function requireStrokePoints(value: readonly StrokePoint[], minPoints = 0): readonly StrokePoint[] {\n if (value.length < minPoints) {\n throw new InkConfigError(`Expected at least ${minPoints} stroke point(s), received ${value.length}.`);\n }\n return value;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\n/** Distance between two points. */\nexport function distance(ax: number, ay: number, bx: number, by: number): number {\n const dx = bx - ax;\n const dy = by - ay;\n return Math.hypot(dx, dy);\n}\n"],"mappings":";;AASA,SAAgB,oBAAoB,GAAgB,GAAsB;CACxE,IAAI,OAAOA,KAAU,YAAY,CAAC,OAAO,SAASA,CAAK,GACrD,MAAM,IAAIC,EAAe,YAAYC,EAAK,mCAAmC,OAAOF,CAAK,EAAE,EAAE;CAE/F,OAAOA;AACT;AAEA,SAAgB,aAAa,GAAe,GAAc,GAAa,GAAqB;CAC1F,IAAIA,IAAQG,KAAOH,IAAQI,GACzB,MAAM,IAAIH,EAAe,YAAYC,EAAK,iBAAiBC,EAAI,IAAIC,EAAI,cAAcJ,EAAM,EAAE;CAE/F,OAAOA;AACT;AAEA,SAAgB,gBAAgB,GAAgB,GAAsB;CACpE,OAAO,aAAa,oBAAoBA,GAAOE,CAAI,GAAGA,GAAM,OAAO,WAAW,QAAwB;AACxG;AAEA,SAAgB,eAAe,GAAgB,GAAc,GAAa,GAAqB;CAC7F,IAAMG,IAAW,oBAAoBL,GAAOE,CAAI;CAChD,IAAI,CAAC,OAAO,UAAUG,CAAQ,GAC5B,MAAM,IAAIJ,EAAe,YAAYC,EAAK,8BAA8B,OAAOF,CAAK,EAAE,EAAE;CAE1F,OAAO,aAAaK,GAAUH,GAAMC,GAAKC,CAAG;AAC9C;AAGA,SAAgB,oBAAoB,GAA+B,IAAY,GAA2B;CACxG,IAAIJ,EAAM,SAASM,GACjB,MAAM,IAAIL,EAAe,qBAAqBK,EAAU,6BAA6BN,EAAM,OAAO,EAAE;CAEtG,OAAOA;AACT;AAEA,SAAgB,MAAM,GAAe,GAAa,GAAqB;CACrE,OAAO,KAAK,IAAII,GAAK,KAAK,IAAID,GAAKH,CAAK,CAAC;AAC3C;AAGA,SAAgB,SAAS,GAAY,GAAY,GAAY,GAAoB;CAC/E,IAAMO,IAAKC,IAAKC,GACVC,IAAKC,IAAKC;CAChB,OAAO,KAAK,MAAML,GAAIG,CAAE;AAC1B"}
@@ -0,0 +1,2 @@
1
+ var InkError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},InkConfigError=class extends InkError{};exports.InkConfigError=InkConfigError,exports.InkError=InkError;
2
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","names":["message","opts"],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ink errors. Use `instanceof InkError` to catch any ink-originated error. */\nexport class InkError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when ink options are invalid, such as a negative `tolerance`, a `tension` outside `[0, 1]`, or a non-positive `width`. */\nexport class InkConfigError extends InkError {}\n"],"mappings":"AACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAMA,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,eAAb,cAAoC,QAAS,CAAC,E"}
@@ -0,0 +1,8 @@
1
+ /** Base class for all ink errors. Use `instanceof InkError` to catch any ink-originated error. */
2
+ export declare class InkError extends Error {
3
+ constructor(message: string, opts?: ErrorOptions);
4
+ }
5
+ /** Thrown when ink options are invalid, such as a negative `tolerance`, a `tension` outside `[0, 1]`, or a non-positive `width`. */
6
+ export declare class InkConfigError extends InkError {
7
+ }
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,oIAAoI;AACpI,qBAAa,cAAe,SAAQ,QAAQ;CAAG"}
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/errors.ts
2
+ var InkError = class extends Error {
3
+ constructor(e, t) {
4
+ super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
+ }
6
+ }, InkConfigError = class extends InkError {};
7
+ export { InkConfigError, InkError };
8
+
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":["message","opts"],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ink errors. Use `instanceof InkError` to catch any ink-originated error. */\nexport class InkError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when ink options are invalid, such as a negative `tolerance`, a `tension` outside `[0, 1]`, or a non-positive `width`. */\nexport class InkConfigError extends InkError {}\n"],"mappings":";AACA,IAAa,WAAb,cAA8B,MAAM;CAClC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAMA,GAASC,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,iBAAb,cAAoC,SAAS,CAAC"}
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./outline.cjs"),n=require("./simplify.cjs"),r=require("./smoothing.cjs"),i=require("./stabilize.cjs"),a=require("./svg.cjs"),o=require("./widths.cjs");exports.InkConfigError=e.InkConfigError,exports.InkError=e.InkError,exports.polylineToSvgPath=a.polylineToSvgPath,exports.simplifyStroke=n.simplifyStroke,exports.smoothStroke=r.smoothStroke,exports.stabilizeStroke=i.stabilizeStroke,exports.strokeOutline=t.strokeOutline,exports.strokeWidths=o.strokeWidths;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @vielzeug/ink: freehand stroke smoothing, width profiling, and SVG path output.
3
+ *
4
+ * Pure, deterministic geometry functions. No DOM, no timers, no long-lived handles.
5
+ */
6
+ export { InkConfigError, InkError } from './errors.js';
7
+ export { strokeOutline } from './outline.js';
8
+ export { simplifyStroke } from './simplify.js';
9
+ export { type SmoothStrokeOptions, smoothStroke } from './smoothing.js';
10
+ export { type StabilizeStrokeOptions, stabilizeStroke } from './stabilize.js';
11
+ export { type PolylineToSvgPathOptions, polylineToSvgPath } from './svg.js';
12
+ export type { Point, StrokePoint } from './types.js';
13
+ export { type StrokeWidthOptions, strokeWidths } from './widths.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC5E,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { InkConfigError as e, InkError as t } from "./errors.js";
2
+ import { strokeOutline as n } from "./outline.js";
3
+ import { simplifyStroke as r } from "./simplify.js";
4
+ import { smoothStroke as i } from "./smoothing.js";
5
+ import { stabilizeStroke as a } from "./stabilize.js";
6
+ import { polylineToSvgPath as o } from "./svg.js";
7
+ import { strokeWidths as s } from "./widths.js";
8
+ export { e as InkConfigError, t as InkError, o as polylineToSvgPath, r as simplifyStroke, i as smoothStroke, a as stabilizeStroke, n as strokeOutline, s as strokeWidths };
package/dist/ink.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var InkError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},InkConfigError=class extends InkError{};function requireFiniteNumber(e,t){if(typeof e!=`number`||!Number.isFinite(e))throw new InkConfigError(`Expected ${t} to be a finite number, received ${String(e)}.`);return e}function requireRange(e,t,n,r){if(e<n||e>r)throw new InkConfigError(`Expected ${t} to be within [${n}, ${r}], received ${e}.`);return e}function requirePositive(e,t){return requireRange(requireFiniteNumber(e,t),t,Number.MIN_VALUE,1/0)}function requireInteger(e,t,n,r){let i=requireFiniteNumber(e,t);if(!Number.isInteger(i))throw new InkConfigError(`Expected ${t} to be an integer, received ${String(e)}.`);return requireRange(i,t,n,r)}function requireStrokePoints(e,t=0){if(e.length<t)throw new InkConfigError(`Expected at least ${t} stroke point(s), received ${e.length}.`);return e}function clamp(e,t,n){return Math.min(n,Math.max(t,e))}function distance(e,t,n,r){let i=n-e,a=r-t;return Math.hypot(i,a)}function normalAt(e,t){let n=e.length-1,r=e[clamp(t-1,0,n)],i=e[clamp(t+1,0,n)],a=i.x-r.x,o=i.y-r.y;if(a===0&&o===0){let r=e[clamp(t+1,0,n)];a=r.x-e[t].x,o=r.y-e[t].y}let s=Math.hypot(a,o);return s===0?{x:0,y:-1}:{x:o/s,y:-a/s}}function appendCap(e,t,n,r){for(let i=1;i<8;i++){let a=n+i/8*Math.PI;e.push({x:t.x+Math.cos(a)*r,y:t.y+Math.sin(a)*r})}}function strokeOutline(e,t){let n=requireStrokePoints(e,1),r=typeof t==`number`?n.map(()=>t):t;if(r.length!==n.length)throw new InkConfigError(`Expected widths to hold ${n.length} number(s), received ${r.length}.`);for(let[e,t]of r.entries())if(requireFiniteNumber(t,`widths[${e}]`),t<=0)throw new InkConfigError(`Expected widths[${e}] to be a positive finite number, received ${t}.`);let i=[],a=[];for(let e=0;e<n.length;e++){let t=n[e],o=r[e]/2,s=normalAt(n,e);i.push({x:t.x+s.x*o,y:t.y+s.y*o}),a.push({x:t.x-s.x*o,y:t.y-s.y*o})}let o=n[0],s=n[n.length-1],c=normalAt(n,0),l=normalAt(n,n.length-1),u=[];return appendCap(u,o,Math.atan2(c.y,c.x)+Math.PI,r[0]/2),u.push(...i),appendCap(u,s,Math.atan2(l.y,l.x),r[r.length-1]/2),u.push(...a.reverse()),u}function perpendicularDistance(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(i*e.x-r*e.y+n.x*t.y-n.y*t.x)/Math.sqrt(a)}function simplifyStroke(e,t){let n=requireStrokePoints(e);if(requireFiniteNumber(t,`tolerance`),t<0)throw new InkConfigError(`Expected tolerance to be >= 0, received ${t}.`);if(n.length<3)return n.map(e=>({...e}));let r=new Uint8Array(n.length);r[0]=1,r[n.length-1]=1;let i=[[0,n.length-1]];for(;i.length>0;){let[e,a]=i.pop(),o=-1,s=-1;for(let t=e+1;t<a;t++){let r=perpendicularDistance(n[t],n[e],n[a]);r>s&&(s=r,o=t)}o!==-1&&s>t&&(r[o]=1,i.push([e,o],[o,a]))}let a=[];for(let e=0;e<n.length;e++)r[e]&&a.push(n[e]);return a}function catmullRomAxis(e,t,n,r,i,a){let o=t+(n-t)*i,s=i*i,c=s*i;return o+a*(.5*(2*t+i*(n-e)+s*(2*e-5*t+4*n-r)+c*(3*t-3*n-e+r))-o)}function lerpField(e,t,n){return e!==void 0&&t!==void 0?e+(t-e)*n:e??t}function emitPoint(e,t,n,r){let i={x:e,y:t};return n!==void 0&&(i.pressure=n),r!==void 0&&(i.time=r),i}function catmullRomResample(e,t,n){let r=[],i=e.length-1,at=t=>e[clamp(t,0,i)];for(let e=0;e<i;e++){let[i,a,o,s]=[at(e-1),at(e),at(e+1),at(e+2)];for(let e=0;e<n;e++){let c=e/n;r.push(emitPoint(catmullRomAxis(i.x,a.x,o.x,s.x,c,t),catmullRomAxis(i.y,a.y,o.y,s.y,c,t),lerpField(a.pressure,o.pressure,c),lerpField(a.time,o.time,c)))}}return r.push(emitPoint(e[i].x,e[i].y,e[i].pressure,e[i].time)),r}function smoothStroke(e,t={}){let n=requireStrokePoints(e),r=requireRange(t.tension??1,`tension`,0,1),i=requireInteger(t.steps??8,`steps`,2,1e3);return n.length<3?n.map(e=>({...e})):catmullRomResample(n,r,i)}function stabilizeStroke(e,t={}){let n=requireStrokePoints(e),r=requireRange(t.strength??.5,`strength`,0,1);if(n.length<2)return n.map(e=>({...e}));let i=1-r*.9,a=(1-i)*2,emit=(e,t,n)=>{let r={x:e,y:t};return n.pressure!==void 0&&(r.pressure=n.pressure),n.time!==void 0&&(r.time=n.time),r},o=[emit(n[0].x,n[0].y,n[0])],s=n[0].x,c=n[0].y;for(let e=1;e<n.length;e++){let t=n[e];if(e===n.length-1){o.push(emit(t.x,t.y,t));break}distance(s,c,t.x,t.y)<a||(s+=(t.x-s)*i,c+=(t.y-c)*i),o.push(emit(s,c,t))}return o}function format(e,t){let n=Number(e.toFixed(t))+0;return String(n)}function polylineToSvgPath(e,t={}){let n=requireStrokePoints(e,1),r=t.close??!1,i=requireInteger(t.precision??2,`precision`,0,12),a=[`M ${format(n[0].x,i)} ${format(n[0].y,i)}`];for(let e=1;e<n.length;e++)a.push(`L ${format(n[e].x,i)} ${format(n[e].y,i)}`);return r&&a.push(`Z`),a.join(` `)}var e=.25,t=2;function pressureScale(e){let t=clamp(e,0,1);return t<=.5?.5+t:1+(t-.5)*.5}function strokeWidths(n,r){let i=requireStrokePoints(n,1),a=requirePositive(r.width,`width`),o=requireRange(r.thinning??.5,`thinning`,0,1),s=requirePositive(r.referenceSpeed??.5,`referenceSpeed`),c=i.every(e=>e.time!==void 0),l=[],u=1;for(let n=0;n<i.length;n++){if(c&&o>0){let r=i[n],a=i[n+1],c=n>0?i[n-1]:r,l=n>0?r:a;if(l){let n=Math.abs(l.time-c.time);n>0&&(u=clamp((s/(distance(c.x,c.y,l.x,l.y)/n))**o,e,t))}}let r=i[n].pressure;l.push(a*u*(r===void 0?1:pressureScale(r)))}return l}exports.InkConfigError=InkConfigError,exports.InkError=InkError,exports.polylineToSvgPath=polylineToSvgPath,exports.simplifyStroke=simplifyStroke,exports.smoothStroke=smoothStroke,exports.stabilizeStroke=stabilizeStroke,exports.strokeOutline=strokeOutline,exports.strokeWidths=strokeWidths;
2
+ //# sourceMappingURL=ink.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ink.cjs","names":["message","opts","value","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay","last","points","prev","i","next","tx","ty","other","len","s","angle","startAngle","outline","center","radius","input","perPoint","widths","index","w","left","right","point","half","normal","first","firstNormal","lastNormal","b","a","lenSq","p","tolerance","keep","stack","farthest","maxDistance","d","result","linear","p1","p2","t","t2","t3","alpha","p0","p3","pressure","time","steps","tension","options","strength","deadZone","source","sx","sy","rounded","precision","close","parts","MIN_SCALE","MAX_SCALE","width","thinning","referenceSpeed","timed","lastScale","from","to","dt"],"sources":["../src/errors.ts","../src/_validate.ts","../src/outline.ts","../src/simplify.ts","../src/smoothing.ts","../src/stabilize.ts","../src/svg.ts","../src/widths.ts"],"sourcesContent":["/** Base class for all ink errors. Use `instanceof InkError` to catch any ink-originated error. */\nexport class InkError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when ink options are invalid, such as a negative `tolerance`, a `tension` outside `[0, 1]`, or a non-positive `width`. */\nexport class InkConfigError extends InkError {}\n","/** Internal validation helpers. Shared by every public entry point; never exported.\n *\n * Stroke points arrive typed and are produced by capture loops, not by untrusted\n * input, so they are not validated per point (matching atlas and wire). Only\n * option ranges and algorithm preconditions are checked.\n */\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport function requireFiniteNumber(value: unknown, name: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new InkConfigError(`Expected ${name} to be a finite number, received ${String(value)}.`);\n }\n return value;\n}\n\nexport function requireRange(value: number, name: string, min: number, max: number): number {\n if (value < min || value > max) {\n throw new InkConfigError(`Expected ${name} to be within [${min}, ${max}], received ${value}.`);\n }\n return value;\n}\n\nexport function requirePositive(value: unknown, name: string): number {\n return requireRange(requireFiniteNumber(value, name), name, Number.MIN_VALUE, Number.POSITIVE_INFINITY);\n}\n\nexport function requireInteger(value: unknown, name: string, min: number, max: number): number {\n const resolved = requireFiniteNumber(value, name);\n if (!Number.isInteger(resolved)) {\n throw new InkConfigError(`Expected ${name} to be an integer, received ${String(value)}.`);\n }\n return requireRange(resolved, name, min, max);\n}\n\n/** Checks the array shape and minimum length of a stroke; the points themselves are trusted as typed. */\nexport function requireStrokePoints(value: readonly StrokePoint[], minPoints = 0): readonly StrokePoint[] {\n if (value.length < minPoints) {\n throw new InkConfigError(`Expected at least ${minPoints} stroke point(s), received ${value.length}.`);\n }\n return value;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\n/** Distance between two points. */\nexport function distance(ax: number, ay: number, bx: number, by: number): number {\n const dx = bx - ax;\n const dy = by - ay;\n return Math.hypot(dx, dy);\n}\n","/** Closed variable-width polygon approximating a stroked path. */\n\nimport { clamp, requireFiniteNumber, requireStrokePoints } from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { Point, StrokePoint } from './types.js';\n\n/** Unit normal at sample `i` of a polyline, derived from the central tangent; falls back to adjacent segments. */\nfunction normalAt(points: readonly Point[], i: number): Point {\n const last = points.length - 1;\n const prev = points[clamp(i - 1, 0, last)];\n const next = points[clamp(i + 1, 0, last)];\n let tx = next.x - prev.x;\n let ty = next.y - prev.y;\n if (tx === 0 && ty === 0) {\n // Degenerate central tangent (e.g. a spike back on itself): use the outgoing segment.\n const other = points[clamp(i + 1, 0, last)];\n tx = other.x - points[i].x;\n ty = other.y - points[i].y;\n }\n const len = Math.hypot(tx, ty);\n if (len === 0) return { x: 0, y: -1 };\n return { x: ty / len, y: -tx / len };\n}\n\n/** Append the interior points of a half-circle cap: samples from `startAngle` to `startAngle + PI`, endpoints excluded. */\nfunction appendCap(outline: Point[], center: Point, startAngle: number, radius: number): void {\n const steps = 8;\n for (let s = 1; s < steps; s++) {\n const angle = startAngle + Math.PI * (s / steps);\n outline.push({ x: center.x + Math.cos(angle) * radius, y: center.y + Math.sin(angle) * radius });\n }\n}\n\n/**\n * Build a closed polygon approximating the variable-width stroke through `points`.\n *\n * Each sample is offset by half its width along the local normal; the ring runs the start cap,\n * the left side forward, the end cap, and the right side backward, so it is closed without a\n * repeated final point. Pass a constant `width` for a uniform stroke, or one width per point\n * (from `strokeWidths`) for a variable one. Deterministic: identical input produces an identical ring.\n *\n * @throws {import('./errors.js').InkConfigError} When `widths` is a mismatched array or holds non-positive values.\n */\nexport function strokeOutline(points: readonly StrokePoint[], widths: number | readonly number[]): Point[] {\n const input = requireStrokePoints(points, 1);\n const perPoint: readonly number[] = typeof widths === 'number' ? input.map(() => widths) : widths;\n if (perPoint.length !== input.length) {\n throw new InkConfigError(`Expected widths to hold ${input.length} number(s), received ${perPoint.length}.`);\n }\n for (const [index, w] of perPoint.entries()) {\n requireFiniteNumber(w, `widths[${index}]`);\n if (w <= 0) {\n throw new InkConfigError(`Expected widths[${index}] to be a positive finite number, received ${w}.`);\n }\n }\n\n const left: Point[] = [];\n const right: Point[] = [];\n for (let i = 0; i < input.length; i++) {\n const point = input[i];\n const half = perPoint[i] / 2;\n const normal = normalAt(input, i);\n left.push({ x: point.x + normal.x * half, y: point.y + normal.y * half });\n right.push({ x: point.x - normal.x * half, y: point.y - normal.y * half });\n }\n\n const first = input[0];\n const last = input[input.length - 1];\n const firstNormal = normalAt(input, 0);\n const lastNormal = normalAt(input, input.length - 1);\n\n const outline: Point[] = [];\n // Start cap: half-circle from the right offset of the first sample, around its back, to the left offset.\n appendCap(outline, first, Math.atan2(firstNormal.y, firstNormal.x) + Math.PI, perPoint[0] / 2);\n outline.push(...left);\n // End cap: half-circle from the left offset of the last sample, around its front, to the right offset.\n appendCap(outline, last, Math.atan2(lastNormal.y, lastNormal.x), perPoint[perPoint.length - 1] / 2);\n outline.push(...right.reverse());\n return outline;\n}\n","/** Ramer-Douglas-Peucker stroke decimation. */\n\nimport { requireFiniteNumber, requireStrokePoints } from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\n/** Perpendicular distance from `p` to the infinite line through `a`-`b`; point distance when degenerate. */\nfunction perpendicularDistance(p: StrokePoint, a: StrokePoint, b: StrokePoint): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lenSq = dx * dx + dy * dy;\n if (lenSq === 0) return Math.hypot(p.x - a.x, p.y - a.y);\n const cross = Math.abs(dy * p.x - dx * p.y + b.x * a.y - b.y * a.x);\n return cross / Math.sqrt(lenSq);\n}\n\n/**\n * Decimate a stroke with Ramer-Douglas-Peucker: iteratively drop the point farthest from the\n * chord when its distance is under `tolerance`, keeping the first and last points. The result is\n * always a subsequence of the input (same object references), so metadata like `pressure` survives.\n *\n * @throws {import('./errors.js').InkConfigError} When `points` is invalid or `tolerance` is not a\n * non-negative finite number.\n */\nexport function simplifyStroke(points: readonly StrokePoint[], tolerance: number): StrokePoint[] {\n const input = requireStrokePoints(points);\n requireFiniteNumber(tolerance, 'tolerance');\n if (tolerance < 0) {\n throw new InkConfigError(`Expected tolerance to be >= 0, received ${tolerance}.`);\n }\n if (input.length < 3) return input.map((point) => ({ ...point }));\n\n // Iterative RDP with an explicit stack: no recursion depth limit on long strokes.\n const keep = new Uint8Array(input.length);\n keep[0] = 1;\n keep[input.length - 1] = 1;\n const stack: [number, number][] = [[0, input.length - 1]];\n while (stack.length > 0) {\n const [first, last] = stack.pop() as [number, number];\n let farthest = -1;\n let maxDistance = -1;\n for (let i = first + 1; i < last; i++) {\n const d = perpendicularDistance(input[i], input[first], input[last]);\n if (d > maxDistance) {\n maxDistance = d;\n farthest = i;\n }\n }\n if (farthest !== -1 && maxDistance > tolerance) {\n keep[farthest] = 1;\n stack.push([first, farthest], [farthest, last]);\n }\n }\n\n const result: StrokePoint[] = [];\n for (let i = 0; i < input.length; i++) {\n if (keep[i]) result.push(input[i]);\n }\n return result;\n}\n","/** Stroke smoothing: deterministic Catmull-Rom resampling. */\n\nimport { clamp, requireInteger, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface SmoothStrokeOptions {\n /** Samples emitted per input segment (minimum 2). Default 8. */\n steps?: number;\n /** Interpolation tension. `0` is linear, `1` is the standard uniform spline. Default `1`. */\n tension?: number;\n}\n\n/**\n * Interpolation basis for one axis; `t` in `[0, 1]`. `alpha` blends linear\n * interpolation (`alpha = 0`) with the standard uniform Catmull-Rom spline\n * (`alpha = 1`), so `tension: 0` is genuinely linear.\n */\nfunction catmullRomAxis(p0: number, p1: number, p2: number, p3: number, t: number, alpha: number): number {\n const linear = p1 + (p2 - p1) * t;\n const t2 = t * t;\n const t3 = t2 * t;\n const spline =\n 0.5 * (2 * p1 + t * (p2 - p0) + t2 * (2 * p0 - 5 * p1 + 4 * p2 - p3) + t3 * (3 * p1 - 3 * p2 - p0 + p3));\n return linear + alpha * (spline - linear);\n}\n\n/** Linear interpolation of optional metadata; keeps the field absent when neither side has it. */\nfunction lerpField(a: number | undefined, b: number | undefined, t: number): number | undefined {\n if (a !== undefined && b !== undefined) return a + (b - a) * t;\n return a ?? b;\n}\n\nfunction emitPoint(x: number, y: number, pressure?: number, time?: number): StrokePoint {\n const point: { x: number; y: number; pressure?: number; time?: number } = { x, y };\n if (pressure !== undefined) point.pressure = pressure;\n if (time !== undefined) point.time = time;\n return point;\n}\n\nfunction catmullRomResample(points: readonly StrokePoint[], tension: number, steps: number): StrokePoint[] {\n const result: StrokePoint[] = [];\n const last = points.length - 1;\n // Duplicated end controls keep the spline interpolating the true endpoints.\n const at = (index: number): StrokePoint => points[clamp(index, 0, last)];\n for (let i = 0; i < last; i++) {\n const [p0, p1, p2, p3] = [at(i - 1), at(i), at(i + 1), at(i + 2)];\n for (let s = 0; s < steps; s++) {\n const t = s / steps;\n result.push(\n emitPoint(\n catmullRomAxis(p0.x, p1.x, p2.x, p3.x, t, tension),\n catmullRomAxis(p0.y, p1.y, p2.y, p3.y, t, tension),\n lerpField(p1.pressure, p2.pressure, t),\n lerpField(p1.time, p2.time, t),\n ),\n );\n }\n }\n result.push(emitPoint(points[last].x, points[last].y, points[last].pressure, points[last].time));\n return result;\n}\n\n/**\n * Resample a freehand stroke through a uniform Catmull-Rom spline: `steps` samples per input\n * segment, with the first and last input points preserved exactly. `pressure` and `time` are\n * interpolated linearly, so widths computed from the output match widths computed from the input.\n *\n * For jitter removal *while drawing*, use `stabilizeStroke` instead: this function adds points and\n * looks ahead, so it is the post-capture step.\n *\n * @throws {import('./errors.js').InkConfigError} When options are out of range.\n */\nexport function smoothStroke(points: readonly StrokePoint[], options: SmoothStrokeOptions = {}): StrokePoint[] {\n const input = requireStrokePoints(points);\n const tension = requireRange(options.tension ?? 1, 'tension', 0, 1);\n const steps = requireInteger(options.steps ?? 8, 'steps', 2, 1000);\n if (input.length < 3) return input.map((point) => ({ ...point }));\n return catmullRomResample(input, tension, steps);\n}\n","/** Causal stroke stabilization: Streamline-style low-pass for use while drawing. */\n\nimport { distance, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StabilizeStrokeOptions {\n /**\n * How strongly the filter pulls toward each incoming sample. `0` keeps the raw input,\n * `1` is maximum smoothing. Default `0.5`.\n */\n strength?: number;\n}\n\n/**\n * Remove hand jitter from a stroke *while it is being drawn*: a causal exponential\n * average toward each incoming sample, with a jitter dead zone so straight lines stay crisp.\n *\n * Output length always equals input length, so per-point widths and metadata stay aligned with\n * the source samples. The last output point is always the last input point — the stroke ends\n * exactly where the pen lifted, never short of it. Inside the dead zone the previous smoothed\n * position repeats, but the incoming sample's `pressure` and `time` are carried through.\n *\n * Deterministic and pure: the same input always returns the same output.\n *\n * @throws {import('./errors.js').InkConfigError} When `strength` is out of range.\n */\nexport function stabilizeStroke(points: readonly StrokePoint[], options: StabilizeStrokeOptions = {}): StrokePoint[] {\n const input = requireStrokePoints(points);\n const strength = requireRange(options.strength ?? 0.5, 'strength', 0, 1);\n if (input.length < 2) return input.map((point) => ({ ...point }));\n // strength 0 -> alpha 1 (no smoothing); strength 1 -> alpha 0.1 (heavy smoothing).\n const alpha = 1 - strength * 0.9;\n const deadZone = (1 - alpha) * 2;\n const emit = (x: number, y: number, source: StrokePoint): StrokePoint => {\n const point: { x: number; y: number; pressure?: number; time?: number } = { x, y };\n if (source.pressure !== undefined) point.pressure = source.pressure;\n if (source.time !== undefined) point.time = source.time;\n return point;\n };\n\n const result: StrokePoint[] = [emit(input[0].x, input[0].y, input[0])];\n let sx = input[0].x;\n let sy = input[0].y;\n for (let i = 1; i < input.length; i++) {\n const point = input[i];\n if (i === input.length - 1) {\n // Snap to the final sample so the stroke never trails past where the pen lifted.\n result.push(emit(point.x, point.y, point));\n break;\n }\n if (distance(sx, sy, point.x, point.y) < deadZone) {\n result.push(emit(sx, sy, point));\n continue;\n }\n sx += (point.x - sx) * alpha;\n sy += (point.y - sy) * alpha;\n result.push(emit(sx, sy, point));\n }\n return result;\n}\n","/** SVG path `d` string output for polylines and outline polygons. */\n\nimport { requireInteger, requireStrokePoints } from './_validate.js';\nimport type { Point } from './types.js';\n\nexport interface PolylineToSvgPathOptions {\n /** Append `Z` to close the path. Use for outline rings from `strokeOutline`. Default `false`. */\n close?: boolean;\n /** Decimal places for emitted coordinates (`0`-`12`). Default `2`. */\n precision?: number;\n}\n\nfunction format(value: number, precision: number): string {\n // `+ 0` normalizes -0 to 0 so output is stable across platforms.\n const rounded = Number(value.toFixed(precision)) + 0;\n return String(rounded);\n}\n\n/**\n * Serialize a polyline as an SVG path `d` string: `M x y` followed by one `L x y` per remaining\n * point. Coordinates are rounded to `precision` decimal places.\n *\n * Works for both open strokes and closed rings: pass `close: true` for the outline polygon\n * returned by `strokeOutline`.\n *\n * @example\n * ```ts\n * polylineToSvgPath([{ x: 0, y: 0 }, { x: 10, y: 5 }]);\n * // 'M 0 0 L 10 5'\n * polylineToSvgPath(strokeOutline(points, 4), { close: true });\n * // 'M ... L ... Z'\n * ```\n *\n * @throws {import('./errors.js').InkConfigError} When `points` is empty or `precision` is out of range.\n */\nexport function polylineToSvgPath(points: readonly Point[], options: PolylineToSvgPathOptions = {}): string {\n const input = requireStrokePoints(points, 1);\n const close = options.close ?? false;\n const precision = requireInteger(options.precision ?? 2, 'precision', 0, 12);\n const parts: string[] = [`M ${format(input[0].x, precision)} ${format(input[0].y, precision)}`];\n for (let i = 1; i < input.length; i++) {\n parts.push(`L ${format(input[i].x, precision)} ${format(input[i].y, precision)}`);\n }\n if (close) parts.push('Z');\n return parts.join(' ');\n}\n","/** Velocity- and pressure-modulated stroke widths. */\n\nimport { clamp, distance, requirePositive, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StrokeWidthOptions {\n /** Pen speed treated as \"neutral\", in pixels per millisecond. Default `0.5`. */\n referenceSpeed?: number;\n /** How strongly speed modulates width: `0` disables velocity, `1` is fully inverse-proportional. Default `0.5`. */\n thinning?: number;\n /** Width at reference speed with neutral pressure. Must be positive. */\n width: number;\n}\n\n/** Fixed velocity-scale range; slow strokes at most double, fast strokes at most quarter. */\nconst MIN_SCALE = 0.25;\nconst MAX_SCALE = 2;\n\n/**\n * Pressure response curve, clamped to `[0, 1]`:\n * `0.5` (the neutral value a mouse reports) maps to exactly `1`, so a stroke with\n * neutral pressure is as wide as one without pressure data. Range: `[0.5, 1.25]`.\n */\nfunction pressureScale(pressure: number): number {\n const p = clamp(pressure, 0, 1);\n return p <= 0.5 ? 0.5 + p : 1 + (p - 0.5) * 0.5;\n}\n\n/**\n * Compute one width per stroke point from pen speed and optional pressure.\n *\n * Speed is `distance / Δtime` between consecutive points, which stays correct after any\n * smoothing, stabilization, or simplification — the pipeline order no longer matters. When any\n * point lacks `time`, or a Δtime is zero, velocity modulation is disabled for the whole stroke\n * (width becomes `width × pressure`) instead of falling back to a spacing proxy that resampling\n * would distort. Slow widens, fast narrows, clamped to a fixed `[0.25, 2]` scale.\n *\n * The first point uses the forward segment; degenerate (zero-length) segments keep the previous\n * scale so stationary samples do not spike.\n *\n * @throws {import('./errors.js').InkConfigError} When options are out of range or `points` is empty.\n */\nexport function strokeWidths(points: readonly StrokePoint[], options: StrokeWidthOptions): number[] {\n const input = requireStrokePoints(points, 1);\n const width = requirePositive(options.width, 'width');\n const thinning = requireRange(options.thinning ?? 0.5, 'thinning', 0, 1);\n const referenceSpeed = requirePositive(options.referenceSpeed ?? 0.5, 'referenceSpeed');\n\n // Velocity needs a timestamp on every point; otherwise it is off for the whole stroke.\n const timed = input.every((point) => point.time !== undefined);\n\n const widths: number[] = [];\n let lastScale = 1;\n for (let i = 0; i < input.length; i++) {\n if (timed && thinning > 0) {\n const point = input[i];\n const next = input[i + 1];\n // First point looks forward; the rest look at the segment they arrived on.\n const from = i > 0 ? input[i - 1] : point;\n const to = i > 0 ? point : next;\n if (to) {\n const dt = Math.abs((to.time as number) - (from.time as number));\n if (dt > 0) {\n const speed = distance(from.x, from.y, to.x, to.y) / dt;\n // Slow (speed < reference) widens: scale = (referenceSpeed / speed) ^ thinning.\n lastScale = clamp((referenceSpeed / speed) ** thinning, MIN_SCALE, MAX_SCALE);\n }\n }\n }\n const pressure = input[i].pressure;\n widths.push(width * lastScale * (pressure === undefined ? 1 : pressureScale(pressure)));\n }\n return widths;\n}\n"],"mappings":"A,mEACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAMA,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,eAAb,cAAoC,QAAS,CAAC,ECD9C,SAAgB,oBAAoB,EAAgB,EAAsB,CACxE,GAAI,OAAOC,GAAU,UAAY,CAAC,OAAO,SAASA,CAAK,EACrD,MAAM,IAAI,eAAe,YAAYC,EAAK,mCAAmC,OAAOD,CAAK,EAAE,EAAE,EAE/F,OAAOA,CACT,CAEA,SAAgB,aAAa,EAAe,EAAc,EAAa,EAAqB,CAC1F,GAAIA,EAAQE,GAAOF,EAAQG,EACzB,MAAM,IAAI,eAAe,YAAYF,EAAK,iBAAiBC,EAAI,IAAIC,EAAI,cAAcH,EAAM,EAAE,EAE/F,OAAOA,CACT,CAEA,SAAgB,gBAAgB,EAAgB,EAAsB,CACpE,OAAO,aAAa,oBAAoBA,EAAOC,CAAI,EAAGA,EAAM,OAAO,UAAW,GAAwB,CACxG,CAEA,SAAgB,eAAe,EAAgB,EAAc,EAAa,EAAqB,CAC7F,IAAMG,EAAW,oBAAoBJ,EAAOC,CAAI,EAChD,GAAI,CAAC,OAAO,UAAUG,CAAQ,EAC5B,MAAM,IAAI,eAAe,YAAYH,EAAK,8BAA8B,OAAOD,CAAK,EAAE,EAAE,EAE1F,OAAO,aAAaI,EAAUH,EAAMC,EAAKC,CAAG,CAC9C,CAGA,SAAgB,oBAAoB,EAA+B,EAAY,EAA2B,CACxG,GAAIH,EAAM,OAASK,EACjB,MAAM,IAAI,eAAe,qBAAqBA,EAAU,6BAA6BL,EAAM,OAAO,EAAE,EAEtG,OAAOA,CACT,CAEA,SAAgB,MAAM,EAAe,EAAa,EAAqB,CACrE,OAAO,KAA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object.setPrototypeOf(this,new.target.prototype)}},InkConfigError=class extends InkError{};function requireFiniteNumber(e,t){if(typeof e!=`number`||!Number.isFinite(e))throw new InkConfigError(`Expected ${t} to be a finite number, received ${String(e)}.`);return e}function requireRange(e,t,n,r){if(e<n||e>r)throw new InkConfigError(`Expected ${t} to be within [${n}, ${r}], received ${e}.`);return e}function requirePositive(e,t){return requireRange(requireFiniteNumber(e,t),t,Number.MIN_VALUE,1/0)}function requireInteger(e,t,n,r){let i=requireFiniteNumber(e,t);if(!Number.isInteger(i))throw new InkConfigError(`Expected ${t} to be an integer, received ${String(e)}.`);return requireRange(i,t,n,r)}function requireStrokePoints(e,t=0){if(e.length<t)throw new InkConfigError(`Expected at least ${t} stroke point(s), received ${e.length}.`);return e}function clamp(e,t,n){return Math.min(n,Math.max(t,e))}function distance(e,t,n,r){let i=n-e,a=r-t;return Math.hypot(i,a)}function normalAt(e,t){let n=e.length-1,r=e[clamp(t-1,0,n)],i=e[clamp(t+1,0,n)],a=i.x-r.x,o=i.y-r.y;if(a===0&&o===0){let r=e[clamp(t+1,0,n)];a=r.x-e[t].x,o=r.y-e[t].y}let s=Math.hypot(a,o);return s===0?{x:0,y:-1}:{x:o/s,y:-a/s}}function appendCap(e,t,n,r){for(let i=1;i<8;i++){let a=n+i/8*Math.PI;e.push({x:t.x+Math.cos(a)*r,y:t.y+Math.sin(a)*r})}}function strokeOutline(e,t){let n=requireStrokePoints(e,1),r=typeof t==`number`?n.map(()=>t):t;if(r.length!==n.length)throw new InkConfigError(`Expected widths to hold ${n.length} number(s), received ${r.length}.`);for(let[e,t]of r.entries())if(requireFiniteNumber(t,`widths[${e}]`),t<=0)throw new InkConfigError(`Expected widths[${e}] to be a positive finite number, received ${t}.`);let i=[],a=[];for(let e=0;e<n.length;e++){let t=n[e],o=r[e]/2,s=normalAt(n,e);i.push({x:t.x+s.x*o,y:t.y+s.y*o}),a.push({x:t.x-s.x*o,y:t.y-s.y*o})}let o=n[0],s=n[n.length-1],c=normalAt(n,0),l=normalAt(n,n.length-1),u=[];return appendCap(u,o,Math.atan2(c.y,c.x)+Math.PI,r[0]/2),u.push(...i),appendCap(u,s,Math.atan2(l.y,l.x),r[r.length-1]/2),u.push(...a.reverse()),u}function perpendicularDistance(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(i*e.x-r*e.y+n.x*t.y-n.y*t.x)/Math.sqrt(a)}function simplifyStroke(e,t){let n=requireStrokePoints(e);if(requireFiniteNumber(t,`tolerance`),t<0)throw new InkConfigError(`Expected tolerance to be >= 0, received ${t}.`);if(n.length<3)return n.map(e=>({...e}));let r=new Uint8Array(n.length);r[0]=1,r[n.length-1]=1;let i=[[0,n.length-1]];for(;i.length>0;){let[e,a]=i.pop(),o=-1,s=-1;for(let t=e+1;t<a;t++){let r=perpendicularDistance(n[t],n[e],n[a]);r>s&&(s=r,o=t)}o!==-1&&s>t&&(r[o]=1,i.push([e,o],[o,a]))}let a=[];for(let e=0;e<n.length;e++)r[e]&&a.push(n[e]);return a}function catmullRomAxis(e,t,n,r,i,a){let o=t+(n-t)*i,s=i*i,c=s*i;return o+a*(.5*(2*t+i*(n-e)+s*(2*e-5*t+4*n-r)+c*(3*t-3*n-e+r))-o)}function lerpField(e,t,n){return e!==void 0&&t!==void 0?e+(t-e)*n:e??t}function emitPoint(e,t,n,r){let i={x:e,y:t};return n!==void 0&&(i.pressure=n),r!==void 0&&(i.time=r),i}function catmullRomResample(e,t,n){let r=[],i=e.length-1,at=t=>e[clamp(t,0,i)];for(let e=0;e<i;e++){let[i,a,o,s]=[at(e-1),at(e),at(e+1),at(e+2)];for(let e=0;e<n;e++){let c=e/n;r.push(emitPoint(catmullRomAxis(i.x,a.x,o.x,s.x,c,t),catmullRomAxis(i.y,a.y,o.y,s.y,c,t),lerpField(a.pressure,o.pressure,c),lerpField(a.time,o.time,c)))}}return r.push(emitPoint(e[i].x,e[i].y,e[i].pressure,e[i].time)),r}function smoothStroke(e,t={}){let n=requireStrokePoints(e),r=requireRange(t.tension??1,`tension`,0,1),i=requireInteger(t.steps??8,`steps`,2,1e3);return n.length<3?n.map(e=>({...e})):catmullRomResample(n,r,i)}function stabilizeStroke(e,t={}){let n=requireStrokePoints(e),r=requireRange(t.strength??.5,`strength`,0,1);if(n.length<2)return n.map(e=>({...e}));let i=1-r*.9,a=(1-i)*2,emit=(e,t,n)=>{let r={x:e,y:t};return n.pressure!==void 0&&(r.pressure=n.pressure),n.time!==void 0&&(r.time=n.time),r},o=[emit(n[0].x,n[0].y,n[0])],s=n[0].x,c=n[0].y;for(let e=1;e<n.length;e++){let t=n[e];if(e===n.length-1){o.push(emit(t.x,t.y,t));break}distance(s,c,t.x,t.y)<a||(s+=(t.x-s)*i,c+=(t.y-c)*i),o.push(emit(s,c,t))}return o}function format(e,t){let n=Number(e.toFixed(t))+0;return String(n)}function polylineToSvgPath(e,t={}){let n=requireStrokePoints(e,1),r=t.close??!1,i=requireInteger(t.precision??2,`precision`,0,12),a=[`M ${format(n[0].x,i)} ${format(n[0].y,i)}`];for(let e=1;e<n.length;e++)a.push(`L ${format(n[e].x,i)} ${format(n[e].y,i)}`);return r&&a.push(`Z`),a.join(` `)}var t=.25,n=2;function pressureScale(e){let t=clamp(e,0,1);return t<=.5?.5+t:1+(t-.5)*.5}function strokeWidths(e,r){let i=requireStrokePoints(e,1),a=requirePositive(r.width,`width`),o=requireRange(r.thinning??.5,`thinning`,0,1),s=requirePositive(r.referenceSpeed??.5,`referenceSpeed`),c=i.every(e=>e.time!==void 0),l=[],u=1;for(let e=0;e<i.length;e++){if(c&&o>0){let r=i[e],a=i[e+1],c=e>0?i[e-1]:r,l=e>0?r:a;if(l){let e=Math.abs(l.time-c.time);e>0&&(u=clamp((s/(distance(c.x,c.y,l.x,l.y)/e))**o,t,n))}}let r=i[e].pressure;l.push(a*u*(r===void 0?1:pressureScale(r)))}return l}return e.InkConfigError=InkConfigError,e.InkError=InkError,e.polylineToSvgPath=polylineToSvgPath,e.simplifyStroke=simplifyStroke,e.smoothStroke=smoothStroke,e.stabilizeStroke=stabilizeStroke,e.strokeOutline=strokeOutline,e.strokeWidths=strokeWidths,e})({});
2
+ //# sourceMappingURL=ink.iife.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ink.iife.js","names":["exports","message","opts","value","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay","last","points","prev","i","next","tx","ty","other","len","s","angle","startAngle","outline","center","radius","input","perPoint","widths","index","w","left","right","point","half","normal","first","firstNormal","lastNormal","b","a","lenSq","p","tolerance","keep","stack","farthest","maxDistance","d","result","linear","p1","p2","t","t2","t3","alpha","p0","p3","pressure","time","steps","tension","options","strength","deadZone","source","sx","sy","rounded","precision","close","parts","MIN_SCALE","MAX_SCALE","width","thinning","referenceSpeed","timed","lastScale","from","to","dt"],"sources":["../src/errors.ts","../src/_validate.ts","../src/outline.ts","../src/simplify.ts","../src/smoothing.ts","../src/stabilize.ts","../src/svg.ts","../src/widths.ts"],"sourcesContent":["/** Base class for all ink errors. Use `instanceof InkError` to catch any ink-originated error. */\nexport class InkError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when ink options are invalid, such as a negative `tolerance`, a `tension` outside `[0, 1]`, or a non-positive `width`. */\nexport class InkConfigError extends InkError {}\n","/** Internal validation helpers. Shared by every public entry point; never exported.\n *\n * Stroke points arrive typed and are produced by capture loops, not by untrusted\n * input, so they are not validated per point (matching atlas and wire). Only\n * option ranges and algorithm preconditions are checked.\n */\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport function requireFiniteNumber(value: unknown, name: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new InkConfigError(`Expected ${name} to be a finite number, received ${String(value)}.`);\n }\n return value;\n}\n\nexport function requireRange(value: number, name: string, min: number, max: number): number {\n if (value < min || value > max) {\n throw new InkConfigError(`Expected ${name} to be within [${min}, ${max}], received ${value}.`);\n }\n return value;\n}\n\nexport function requirePositive(value: unknown, name: string): number {\n return requireRange(requireFiniteNumber(value, name), name, Number.MIN_VALUE, Number.POSITIVE_INFINITY);\n}\n\nexport function requireInteger(value: unknown, name: string, min: number, max: number): number {\n const resolved = requireFiniteNumber(value, name);\n if (!Number.isInteger(resolved)) {\n throw new InkConfigError(`Expected ${name} to be an integer, received ${String(value)}.`);\n }\n return requireRange(resolved, name, min, max);\n}\n\n/** Checks the array shape and minimum length of a stroke; the points themselves are trusted as typed. */\nexport function requireStrokePoints(value: readonly StrokePoint[], minPoints = 0): readonly StrokePoint[] {\n if (value.length < minPoints) {\n throw new InkConfigError(`Expected at least ${minPoints} stroke point(s), received ${value.length}.`);\n }\n return value;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\n/** Distance between two points. */\nexport function distance(ax: number, ay: number, bx: number, by: number): number {\n const dx = bx - ax;\n const dy = by - ay;\n return Math.hypot(dx, dy);\n}\n","/** Closed variable-width polygon approximating a stroked path. */\n\nimport { clamp, requireFiniteNumber, requireStrokePoints } from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { Point, StrokePoint } from './types.js';\n\n/** Unit normal at sample `i` of a polyline, derived from the central tangent; falls back to adjacent segments. */\nfunction normalAt(points: readonly Point[], i: number): Point {\n const last = points.length - 1;\n const prev = points[clamp(i - 1, 0, last)];\n const next = points[clamp(i + 1, 0, last)];\n let tx = next.x - prev.x;\n let ty = next.y - prev.y;\n if (tx === 0 && ty === 0) {\n // Degenerate central tangent (e.g. a spike back on itself): use the outgoing segment.\n const other = points[clamp(i + 1, 0, last)];\n tx = other.x - points[i].x;\n ty = other.y - points[i].y;\n }\n const len = Math.hypot(tx, ty);\n if (len === 0) return { x: 0, y: -1 };\n return { x: ty / len, y: -tx / len };\n}\n\n/** Append the interior points of a half-circle cap: samples from `startAngle` to `startAngle + PI`, endpoints excluded. */\nfunction appendCap(outline: Point[], center: Point, startAngle: number, radius: number): void {\n const steps = 8;\n for (let s = 1; s < steps; s++) {\n const angle = startAngle + Math.PI * (s / steps);\n outline.push({ x: center.x + Math.cos(angle) * radius, y: center.y + Math.sin(angle) * radius });\n }\n}\n\n/**\n * Build a closed polygon approximating the variable-width stroke through `points`.\n *\n * Each sample is offset by half its width along the local normal; the ring runs the start cap,\n * the left side forward, the end cap, and the right side backward, so it is closed without a\n * repeated final point. Pass a constant `width` for a uniform stroke, or one width per point\n * (from `strokeWidths`) for a variable one. Deterministic: identical input produces an identical ring.\n *\n * @throws {import('./errors.js').InkConfigError} When `widths` is a mismatched array or holds non-positive values.\n */\nexport function strokeOutline(points: readonly StrokePoint[], widths: number | readonly number[]): Point[] {\n const input = requireStrokePoints(points, 1);\n const perPoint: readonly number[] = typeof widths === 'number' ? input.map(() => widths) : widths;\n if (perPoint.length !== input.length) {\n throw new InkConfigError(`Expected widths to hold ${input.length} number(s), received ${perPoint.length}.`);\n }\n for (const [index, w] of perPoint.entries()) {\n requireFiniteNumber(w, `widths[${index}]`);\n if (w <= 0) {\n throw new InkConfigError(`Expected widths[${index}] to be a positive finite number, received ${w}.`);\n }\n }\n\n const left: Point[] = [];\n const right: Point[] = [];\n for (let i = 0; i < input.length; i++) {\n const point = input[i];\n const half = perPoint[i] / 2;\n const normal = normalAt(input, i);\n left.push({ x: point.x + normal.x * half, y: point.y + normal.y * half });\n right.push({ x: point.x - normal.x * half, y: point.y - normal.y * half });\n }\n\n const first = input[0];\n const last = input[input.length - 1];\n const firstNormal = normalAt(input, 0);\n const lastNormal = normalAt(input, input.length - 1);\n\n const outline: Point[] = [];\n // Start cap: half-circle from the right offset of the first sample, around its back, to the left offset.\n appendCap(outline, first, Math.atan2(firstNormal.y, firstNormal.x) + Math.PI, perPoint[0] / 2);\n outline.push(...left);\n // End cap: half-circle from the left offset of the last sample, around its front, to the right offset.\n appendCap(outline, last, Math.atan2(lastNormal.y, lastNormal.x), perPoint[perPoint.length - 1] / 2);\n outline.push(...right.reverse());\n return outline;\n}\n","/** Ramer-Douglas-Peucker stroke decimation. */\n\nimport { requireFiniteNumber, requireStrokePoints } from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\n/** Perpendicular distance from `p` to the infinite line through `a`-`b`; point distance when degenerate. */\nfunction perpendicularDistance(p: StrokePoint, a: StrokePoint, b: StrokePoint): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lenSq = dx * dx + dy * dy;\n if (lenSq === 0) return Math.hypot(p.x - a.x, p.y - a.y);\n const cross = Math.abs(dy * p.x - dx * p.y + b.x * a.y - b.y * a.x);\n return cross / Math.sqrt(lenSq);\n}\n\n/**\n * Decimate a stroke with Ramer-Douglas-Peucker: iteratively drop the point farthest from the\n * chord when its distance is under `tolerance`, keeping the first and last points. The result is\n * always a subsequence of the input (same object references), so metadata like `pressure` survives.\n *\n * @throws {import('./errors.js').InkConfigError} When `points` is invalid or `tolerance` is not a\n * non-negative finite number.\n */\nexport function simplifyStroke(points: readonly StrokePoint[], tolerance: number): StrokePoint[] {\n const input = requireStrokePoints(points);\n requireFiniteNumber(tolerance, 'tolerance');\n if (tolerance < 0) {\n throw new InkConfigError(`Expected tolerance to be >= 0, received ${tolerance}.`);\n }\n if (input.length < 3) return input.map((point) => ({ ...point }));\n\n // Iterative RDP with an explicit stack: no recursion depth limit on long strokes.\n const keep = new Uint8Array(input.length);\n keep[0] = 1;\n keep[input.length - 1] = 1;\n const stack: [number, number][] = [[0, input.length - 1]];\n while (stack.length > 0) {\n const [first, last] = stack.pop() as [number, number];\n let farthest = -1;\n let maxDistance = -1;\n for (let i = first + 1; i < last; i++) {\n const d = perpendicularDistance(input[i], input[first], input[last]);\n if (d > maxDistance) {\n maxDistance = d;\n farthest = i;\n }\n }\n if (farthest !== -1 && maxDistance > tolerance) {\n keep[farthest] = 1;\n stack.push([first, farthest], [farthest, last]);\n }\n }\n\n const result: StrokePoint[] = [];\n for (let i = 0; i < input.length; i++) {\n if (keep[i]) result.push(input[i]);\n }\n return result;\n}\n","/** Stroke smoothing: deterministic Catmull-Rom resampling. */\n\nimport { clamp, requireInteger, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface SmoothStrokeOptions {\n /** Samples emitted per input segment (minimum 2). Default 8. */\n steps?: number;\n /** Interpolation tension. `0` is linear, `1` is the standard uniform spline. Default `1`. */\n tension?: number;\n}\n\n/**\n * Interpolation basis for one axis; `t` in `[0, 1]`. `alpha` blends linear\n * interpolation (`alpha = 0`) with the standard uniform Catmull-Rom spline\n * (`alpha = 1`), so `tension: 0` is genuinely linear.\n */\nfunction catmullRomAxis(p0: number, p1: number, p2: number, p3: number, t: number, alpha: number): number {\n const linear = p1 + (p2 - p1) * t;\n const t2 = t * t;\n const t3 = t2 * t;\n const spline =\n 0.5 * (2 * p1 + t * (p2 - p0) + t2 * (2 * p0 - 5 * p1 + 4 * p2 - p3) + t3 * (3 * p1 - 3 * p2 - p0 + p3));\n return linear + alpha * (spline - linear);\n}\n\n/** Linear interpolation of optional metadata; keeps the field absent when neither side has it. */\nfunction lerpField(a: number | undefined, b: number | undefined, t: number): number | undefined {\n if (a !== undefined && b !== undefined) return a + (b - a) * t;\n return a ?? b;\n}\n\nfunction emitPoint(x: number, y: number, pressure?: number, time?: number): StrokePoint {\n const point: { x: number; y: number; pressure?: number; time?: number } = { x, y };\n if (pressure !== undefined) point.pressure = pressure;\n if (time !== undefined) point.time = time;\n return point;\n}\n\nfunction catmullRomResample(points: readonly StrokePoint[], tension: number, steps: number): StrokePoint[] {\n const result: StrokePoint[] = [];\n const last = points.length - 1;\n // Duplicated end controls keep the spline interpolating the true endpoints.\n const at = (index: number): StrokePoint => points[clamp(index, 0, last)];\n for (let i = 0; i < last; i++) {\n const [p0, p1, p2, p3] = [at(i - 1), at(i), at(i + 1), at(i + 2)];\n for (let s = 0; s < steps; s++) {\n const t = s / steps;\n result.push(\n emitPoint(\n catmullRomAxis(p0.x, p1.x, p2.x, p3.x, t, tension),\n catmullRomAxis(p0.y, p1.y, p2.y, p3.y, t, tension),\n lerpField(p1.pressure, p2.pressure, t),\n lerpField(p1.time, p2.time, t),\n ),\n );\n }\n }\n result.push(emitPoint(points[last].x, points[last].y, points[last].pressure, points[last].time));\n return result;\n}\n\n/**\n * Resample a freehand stroke through a uniform Catmull-Rom spline: `steps` samples per input\n * segment, with the first and last input points preserved exactly. `pressure` and `time` are\n * interpolated linearly, so widths computed from the output match widths computed from the input.\n *\n * For jitter removal *while drawing*, use `stabilizeStroke` instead: this function adds points and\n * looks ahead, so it is the post-capture step.\n *\n * @throws {import('./errors.js').InkConfigError} When options are out of range.\n */\nexport function smoothStroke(points: readonly StrokePoint[], options: SmoothStrokeOptions = {}): StrokePoint[] {\n const input = requireStrokePoints(points);\n const tension = requireRange(options.tension ?? 1, 'tension', 0, 1);\n const steps = requireInteger(options.steps ?? 8, 'steps', 2, 1000);\n if (input.length < 3) return input.map((point) => ({ ...point }));\n return catmullRomResample(input, tension, steps);\n}\n","/** Causal stroke stabilization: Streamline-style low-pass for use while drawing. */\n\nimport { distance, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StabilizeStrokeOptions {\n /**\n * How strongly the filter pulls toward each incoming sample. `0` keeps the raw input,\n * `1` is maximum smoothing. Default `0.5`.\n */\n strength?: number;\n}\n\n/**\n * Remove hand jitter from a stroke *while it is being drawn*: a causal exponential\n * average toward each incoming sample, with a jitter dead zone so straight lines stay crisp.\n *\n * Output length always equals input length, so per-point widths and metadata stay aligned with\n * the source samples. The last output point is always the last input point — the stroke ends\n * exactly where the pen lifted, never short of it. Inside the dead zone the previous smoothed\n * position repeats, but the incoming sample's `pressure` and `time` are carried through.\n *\n * Deterministic and pure: the same input always returns the same output.\n *\n * @throws {import('./errors.js').InkConfigError} When `strength` is out of range.\n */\nexport function stabilizeStroke(points: readonly StrokePoint[], options: StabilizeStrokeOptions = {}): StrokePoint[] {\n const input = requireStrokePoints(points);\n const strength = requireRange(options.strength ?? 0.5, 'strength', 0, 1);\n if (input.length < 2) return input.map((point) => ({ ...point }));\n // strength 0 -> alpha 1 (no smoothing); strength 1 -> alpha 0.1 (heavy smoothing).\n const alpha = 1 - strength * 0.9;\n const deadZone = (1 - alpha) * 2;\n const emit = (x: number, y: number, source: StrokePoint): StrokePoint => {\n const point: { x: number; y: number; pressure?: number; time?: number } = { x, y };\n if (source.pressure !== undefined) point.pressure = source.pressure;\n if (source.time !== undefined) point.time = source.time;\n return point;\n };\n\n const result: StrokePoint[] = [emit(input[0].x, input[0].y, input[0])];\n let sx = input[0].x;\n let sy = input[0].y;\n for (let i = 1; i < input.length; i++) {\n const point = input[i];\n if (i === input.length - 1) {\n // Snap to the final sample so the stroke never trails past where the pen lifted.\n result.push(emit(point.x, point.y, point));\n break;\n }\n if (distance(sx, sy, point.x, point.y) < deadZone) {\n result.push(emit(sx, sy, point));\n continue;\n }\n sx += (point.x - sx) * alpha;\n sy += (point.y - sy) * alpha;\n result.push(emit(sx, sy, point));\n }\n return result;\n}\n","/** SVG path `d` string output for polylines and outline polygons. */\n\nimport { requireInteger, requireStrokePoints } from './_validate.js';\nimport type { Point } from './types.js';\n\nexport interface PolylineToSvgPathOptions {\n /** Append `Z` to close the path. Use for outline rings from `strokeOutline`. Default `false`. */\n close?: boolean;\n /** Decimal places for emitted coordinates (`0`-`12`). Default `2`. */\n precision?: number;\n}\n\nfunction format(value: number, precision: number): string {\n // `+ 0` normalizes -0 to 0 so output is stable across platforms.\n const rounded = Number(value.toFixed(precision)) + 0;\n return String(rounded);\n}\n\n/**\n * Serialize a polyline as an SVG path `d` string: `M x y` followed by one `L x y` per remaining\n * point. Coordinates are rounded to `precision` decimal places.\n *\n * Works for both open strokes and closed rings: pass `close: true` for the outline polygon\n * returned by `strokeOutline`.\n *\n * @example\n * ```ts\n * polylineToSvgPath([{ x: 0, y: 0 }, { x: 10, y: 5 }]);\n * // 'M 0 0 L 10 5'\n * polylineToSvgPath(strokeOutline(points, 4), { close: true });\n * // 'M ... L ... Z'\n * ```\n *\n * @throws {import('./errors.js').InkConfigError} When `points` is empty or `precision` is out of range.\n */\nexport function polylineToSvgPath(points: readonly Point[], options: PolylineToSvgPathOptions = {}): string {\n const input = requireStrokePoints(points, 1);\n const close = options.close ?? false;\n const precision = requireInteger(options.precision ?? 2, 'precision', 0, 12);\n const parts: string[] = [`M ${format(input[0].x, precision)} ${format(input[0].y, precision)}`];\n for (let i = 1; i < input.length; i++) {\n parts.push(`L ${format(input[i].x, precision)} ${format(input[i].y, precision)}`);\n }\n if (close) parts.push('Z');\n return parts.join(' ');\n}\n","/** Velocity- and pressure-modulated stroke widths. */\n\nimport { clamp, distance, requirePositive, requireRange, requireStrokePoints } from './_validate.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StrokeWidthOptions {\n /** Pen speed treated as \"neutral\", in pixels per millisecond. Default `0.5`. */\n referenceSpeed?: number;\n /** How strongly speed modulates width: `0` disables velocity, `1` is fully inverse-proportional. Default `0.5`. */\n thinning?: number;\n /** Width at reference speed with neutral pressure. Must be positive. */\n width: number;\n}\n\n/** Fixed velocity-scale range; slow strokes at most double, fast strokes at most quarter. */\nconst MIN_SCALE = 0.25;\nconst MAX_SCALE = 2;\n\n/**\n * Pressure response curve, clamped to `[0, 1]`:\n * `0.5` (the neutral value a mouse reports) maps to exactly `1`, so a stroke with\n * neutral pressure is as wide as one without pressure data. Range: `[0.5, 1.25]`.\n */\nfunction pressureScale(pressure: number): number {\n const p = clamp(pressure, 0, 1);\n return p <= 0.5 ? 0.5 + p : 1 + (p - 0.5) * 0.5;\n}\n\n/**\n * Compute one width per stroke point from pen speed and optional pressure.\n *\n * Speed is `distance / Δtime` between consecutive points, which stays correct after any\n * smoothing, stabilization, or simplification — the pipeline order no longer matters. When any\n * point lacks `time`, or a Δtime is zero, velocity modulation is disabled for the whole stroke\n * (width becomes `width × pressure`) instead of falling back to a spacing proxy that resampling\n * would distort. Slow widens, fast narrows, clamped to a fixed `[0.25, 2]` scale.\n *\n * The first point uses the forward segment; degenerate (zero-length) segments keep the previous\n * scale so stationary samples do not spike.\n *\n * @throws {import('./errors.js').InkConfigError} When options are out of range or `points` is empty.\n */\nexport function strokeWidths(points: readonly StrokePoint[], options: StrokeWidthOptions): number[] {\n const input = requireStrokePoints(points, 1);\n const width = requirePositive(options.width, 'width');\n const thinning = requireRange(options.thinning ?? 0.5, 'thinning', 0, 1);\n const referenceSpeed = requirePositive(options.referenceSpeed ?? 0.5, 'referenceSpeed');\n\n // Velocity needs a timestamp on every point; otherwise it is off for the whole stroke.\n const timed = input.every((point) => point.time !== undefined);\n\n const widths: number[] = [];\n let lastScale = 1;\n for (let i = 0; i < input.length; i++) {\n if (timed && thinning > 0) {\n const point = input[i];\n const next = input[i + 1];\n // First point looks forward; the rest look at the segment they arrived on.\n const from = i > 0 ? input[i - 1] : point;\n const to = i > 0 ? point : next;\n if (to) {\n const dt = Math.abs((to.time as number) - (from.time as number));\n if (dt > 0) {\n const speed = distance(from.x, from.y, to.x, to.y) / dt;\n // Slow (speed < reference) widens: scale = (referenceSpeed / speed) ^ thinning.\n lastScale = clamp((referenceSpeed / speed) ** thinning, MIN_SCALE, MAX_SCALE);\n }\n }\n }\n const pressure = input[i].pressure;\n widths.push(width * lastScale * (pressure === undefined ? 1 : pressureScale(pressure)));\n }\n return widths;\n}\n"],"mappings":"A,kFACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAMC,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,eAAb,cAAoC,QAAS,CAAC,ECD9C,SAAgB,oBAAoB,EAAgB,EAAsB,CACxE,GAAI,OAAOC,GAAU,UAAY,CAAC,OAAO,SAASA,CAAK,EACrD,MAAM,IAAI,eAAe,YAAYC,EAAK,mCAAmC,OAAOD,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AAUO,EAAM,OAAS,IAAA,EAAS,EAEvDL,EAAmB,CAAC,EACtBmD,EAAY,EAChB,IAAK,IAAIjE,EAAI,EAAGA,EAAIY,EAAM,OAAQ,IAAK,CACrC,GAAIoD,GAASF,EAAW,EAAG,CACzB,IAAM3C,EAAQP,EAAMZ,GACdC,EAAOW,EAAMZ,EAAI,GAEjBkE,EAAOlE,EAAI,EAAIY,EAAMZ,EAAI,GAAKmB,EAC9BgD,EAAKnE,EAAI,EAAImB,EAAQlB,EAC3B,GAAIkE,EAAI,CACN,IAAMC,EAAK,KAAK,IAAKD,EAAG,KAAmBD,EAAK,IAAe,EAC3DE,EAAK,IAGP,EAAY,OAAOL,GAFL,SAASG,EAAK,EAAGA,EAAK,EAAGC,EAAG,EAAGA,EAAG,CAAC,EAAIC,KAEPN,EAAUH,EAAWC,CAAS,EAEhF,CACF,CACA,IAAMf,EAAWjC,EAAMZ,EAAE,CAAC,SAC1Bc,EAAO,KAAK+C,EAAQI,GAAapB,IAAa,IAAA,GAAY,EAAI,cAAcA,CAAQ,EAAE,CACxF,CACA,OAAO/B,CACT,C"}
package/dist/ink.js ADDED
@@ -0,0 +1,191 @@
1
+ // src/errors.ts
2
+ var InkError = class extends Error {
3
+ constructor(e, t) {
4
+ super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
+ }
6
+ }, InkConfigError = class extends InkError {};
7
+ // src/_validate.ts
8
+ function requireFiniteNumber(e, t) {
9
+ if (typeof e != "number" || !Number.isFinite(e)) throw new InkConfigError(`Expected ${t} to be a finite number, received ${String(e)}.`);
10
+ return e;
11
+ }
12
+ function requireRange(e, t, n, r) {
13
+ if (e < n || e > r) throw new InkConfigError(`Expected ${t} to be within [${n}, ${r}], received ${e}.`);
14
+ return e;
15
+ }
16
+ function requirePositive(e, t) {
17
+ return requireRange(requireFiniteNumber(e, t), t, Number.MIN_VALUE, Infinity);
18
+ }
19
+ function requireInteger(e, t, n, r) {
20
+ let i = requireFiniteNumber(e, t);
21
+ if (!Number.isInteger(i)) throw new InkConfigError(`Expected ${t} to be an integer, received ${String(e)}.`);
22
+ return requireRange(i, t, n, r);
23
+ }
24
+ function requireStrokePoints(e, t = 0) {
25
+ if (e.length < t) throw new InkConfigError(`Expected at least ${t} stroke point(s), received ${e.length}.`);
26
+ return e;
27
+ }
28
+ function clamp(e, t, n) {
29
+ return Math.min(n, Math.max(t, e));
30
+ }
31
+ function distance(e, t, n, r) {
32
+ let i = n - e, a = r - t;
33
+ return Math.hypot(i, a);
34
+ }
35
+ // src/outline.ts
36
+ function normalAt(e, t) {
37
+ let n = e.length - 1, r = e[clamp(t - 1, 0, n)], i = e[clamp(t + 1, 0, n)], a = i.x - r.x, o = i.y - r.y;
38
+ if (a === 0 && o === 0) {
39
+ let r = e[clamp(t + 1, 0, n)];
40
+ a = r.x - e[t].x, o = r.y - e[t].y;
41
+ }
42
+ let s = Math.hypot(a, o);
43
+ return s === 0 ? {
44
+ x: 0,
45
+ y: -1
46
+ } : {
47
+ x: o / s,
48
+ y: -a / s
49
+ };
50
+ }
51
+ function appendCap(e, t, n, r) {
52
+ for (let i = 1; i < 8; i++) {
53
+ let a = n + i / 8 * Math.PI;
54
+ e.push({
55
+ x: t.x + Math.cos(a) * r,
56
+ y: t.y + Math.sin(a) * r
57
+ });
58
+ }
59
+ }
60
+ function strokeOutline(e, t) {
61
+ let n = requireStrokePoints(e, 1), r = typeof t == "number" ? n.map(() => t) : t;
62
+ if (r.length !== n.length) throw new InkConfigError(`Expected widths to hold ${n.length} number(s), received ${r.length}.`);
63
+ for (let [e, t] of r.entries()) if (requireFiniteNumber(t, `widths[${e}]`), t <= 0) throw new InkConfigError(`Expected widths[${e}] to be a positive finite number, received ${t}.`);
64
+ let i = [], a = [];
65
+ for (let e = 0; e < n.length; e++) {
66
+ let t = n[e], o = r[e] / 2, s = normalAt(n, e);
67
+ i.push({
68
+ x: t.x + s.x * o,
69
+ y: t.y + s.y * o
70
+ }), a.push({
71
+ x: t.x - s.x * o,
72
+ y: t.y - s.y * o
73
+ });
74
+ }
75
+ let o = n[0], s = n[n.length - 1], c = normalAt(n, 0), l = normalAt(n, n.length - 1), u = [];
76
+ return appendCap(u, o, Math.atan2(c.y, c.x) + Math.PI, r[0] / 2), u.push(...i), appendCap(u, s, Math.atan2(l.y, l.x), r[r.length - 1] / 2), u.push(...a.reverse()), u;
77
+ }
78
+ // src/simplify.ts
79
+ function perpendicularDistance(e, t, n) {
80
+ let r = n.x - t.x, i = n.y - t.y, a = r * r + i * i;
81
+ return a === 0 ? Math.hypot(e.x - t.x, e.y - t.y) : Math.abs(i * e.x - r * e.y + n.x * t.y - n.y * t.x) / Math.sqrt(a);
82
+ }
83
+ function simplifyStroke(e, t) {
84
+ let n = requireStrokePoints(e);
85
+ if (requireFiniteNumber(t, "tolerance"), t < 0) throw new InkConfigError(`Expected tolerance to be >= 0, received ${t}.`);
86
+ if (n.length < 3) return n.map((e) => ({ ...e }));
87
+ let r = new Uint8Array(n.length);
88
+ r[0] = 1, r[n.length - 1] = 1;
89
+ let i = [[0, n.length - 1]];
90
+ for (; i.length > 0;) {
91
+ let [e, a] = i.pop(), o = -1, s = -1;
92
+ for (let t = e + 1; t < a; t++) {
93
+ let r = perpendicularDistance(n[t], n[e], n[a]);
94
+ r > s && (s = r, o = t);
95
+ }
96
+ o !== -1 && s > t && (r[o] = 1, i.push([e, o], [o, a]));
97
+ }
98
+ let a = [];
99
+ for (let e = 0; e < n.length; e++) r[e] && a.push(n[e]);
100
+ return a;
101
+ }
102
+ // src/smoothing.ts
103
+ function catmullRomAxis(e, t, n, r, i, a) {
104
+ let o = t + (n - t) * i, s = i * i, c = s * i;
105
+ return o + a * (.5 * (2 * t + i * (n - e) + s * (2 * e - 5 * t + 4 * n - r) + c * (3 * t - 3 * n - e + r)) - o);
106
+ }
107
+ function lerpField(e, t, n) {
108
+ return e !== void 0 && t !== void 0 ? e + (t - e) * n : e ?? t;
109
+ }
110
+ function emitPoint(e, t, n, r) {
111
+ let i = {
112
+ x: e,
113
+ y: t
114
+ };
115
+ return n !== void 0 && (i.pressure = n), r !== void 0 && (i.time = r), i;
116
+ }
117
+ function catmullRomResample(e, t, n) {
118
+ let r = [], i = e.length - 1, at = (t) => e[clamp(t, 0, i)];
119
+ for (let e = 0; e < i; e++) {
120
+ let [i, a, o, s] = [
121
+ at(e - 1),
122
+ at(e),
123
+ at(e + 1),
124
+ at(e + 2)
125
+ ];
126
+ for (let e = 0; e < n; e++) {
127
+ let c = e / n;
128
+ r.push(emitPoint(catmullRomAxis(i.x, a.x, o.x, s.x, c, t), catmullRomAxis(i.y, a.y, o.y, s.y, c, t), lerpField(a.pressure, o.pressure, c), lerpField(a.time, o.time, c)));
129
+ }
130
+ }
131
+ return r.push(emitPoint(e[i].x, e[i].y, e[i].pressure, e[i].time)), r;
132
+ }
133
+ function smoothStroke(e, t = {}) {
134
+ let n = requireStrokePoints(e), r = requireRange(t.tension ?? 1, "tension", 0, 1), i = requireInteger(t.steps ?? 8, "steps", 2, 1e3);
135
+ return n.length < 3 ? n.map((e) => ({ ...e })) : catmullRomResample(n, r, i);
136
+ }
137
+ // src/stabilize.ts
138
+ function stabilizeStroke(e, t = {}) {
139
+ let n = requireStrokePoints(e), r = requireRange(t.strength ?? .5, "strength", 0, 1);
140
+ if (n.length < 2) return n.map((e) => ({ ...e }));
141
+ let i = 1 - r * .9, a = (1 - i) * 2, emit = (e, t, n) => {
142
+ let r = {
143
+ x: e,
144
+ y: t
145
+ };
146
+ return n.pressure !== void 0 && (r.pressure = n.pressure), n.time !== void 0 && (r.time = n.time), r;
147
+ }, o = [emit(n[0].x, n[0].y, n[0])], s = n[0].x, c = n[0].y;
148
+ for (let e = 1; e < n.length; e++) {
149
+ let t = n[e];
150
+ if (e === n.length - 1) {
151
+ o.push(emit(t.x, t.y, t));
152
+ break;
153
+ }
154
+ distance(s, c, t.x, t.y) < a || (s += (t.x - s) * i, c += (t.y - c) * i), o.push(emit(s, c, t));
155
+ }
156
+ return o;
157
+ }
158
+ // src/svg.ts
159
+ function format(e, t) {
160
+ let n = Number(e.toFixed(t)) + 0;
161
+ return String(n);
162
+ }
163
+ function polylineToSvgPath(e, t = {}) {
164
+ let n = requireStrokePoints(e, 1), r = t.close ?? !1, i = requireInteger(t.precision ?? 2, "precision", 0, 12), a = [`M ${format(n[0].x, i)} ${format(n[0].y, i)}`];
165
+ for (let e = 1; e < n.length; e++) a.push(`L ${format(n[e].x, i)} ${format(n[e].y, i)}`);
166
+ return r && a.push("Z"), a.join(" ");
167
+ }
168
+ // src/widths.ts
169
+ var e = .25, t = 2;
170
+ function pressureScale(e) {
171
+ let t = clamp(e, 0, 1);
172
+ return t <= .5 ? .5 + t : 1 + (t - .5) * .5;
173
+ }
174
+ function strokeWidths(n, r) {
175
+ let i = requireStrokePoints(n, 1), a = requirePositive(r.width, "width"), o = requireRange(r.thinning ?? .5, "thinning", 0, 1), s = requirePositive(r.referenceSpeed ?? .5, "referenceSpeed"), c = i.every((e) => e.time !== void 0), l = [], u = 1;
176
+ for (let n = 0; n < i.length; n++) {
177
+ if (c && o > 0) {
178
+ let r = i[n], a = i[n + 1], c = n > 0 ? i[n - 1] : r, l = n > 0 ? r : a;
179
+ if (l) {
180
+ let n = Math.abs(l.time - c.time);
181
+ n > 0 && (u = clamp((s / (distance(c.x, c.y, l.x, l.y) / n)) ** o, e, t));
182
+ }
183
+ }
184
+ let r = i[n].pressure;
185
+ l.push(a * u * (r === void 0 ? 1 : pressureScale(r)));
186
+ }
187
+ return l;
188
+ }
189
+ export { InkConfigError, InkError, polylineToSvgPath, simplifyStroke, smoothStroke, stabilizeStroke, strokeOutline, strokeWidths };
190
+
191
+ //# sourceMappingURL=ink.js.map