@vielzeug/ink 26.11.23 → 26.11.25
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/ink.cjs +1 -1
- package/dist/ink.cjs.map +1 -1
- package/dist/ink.iife.js +1 -1
- package/dist/ink.iife.js.map +1 -1
- package/dist/ink.js +136 -27
- package/dist/ink.js.map +1 -1
- package/dist/outline.cjs +1 -1
- package/dist/outline.cjs.map +1 -1
- package/dist/outline.d.ts +32 -2
- package/dist/outline.d.ts.map +1 -1
- package/dist/outline.js +93 -11
- package/dist/outline.js.map +1 -1
- package/dist/widths.cjs +1 -1
- package/dist/widths.cjs.map +1 -1
- package/dist/widths.d.ts +34 -0
- package/dist/widths.d.ts.map +1 -1
- package/dist/widths.js +42 -14
- package/dist/widths.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ const d = polylineToSvgPath(strokeOutline(stabilized, widths), { close: true });
|
|
|
32
32
|
|
|
33
33
|
- `stabilizeStroke()`: causal Streamline-style averaging for live drawing; the stroke ends where the pen lifted
|
|
34
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
|
|
35
|
+
- `strokeWidths()`: widths from real pen speed (`distance / Δtime`) with pressure modulation, arc-length end tapers, and synthesized pressure for mouse strokes
|
|
36
|
+
- `strokeOutline()`: closed variable-width outline polygon; selectable round/butt/square caps and round/bevel/miter joins; constant width with a single number
|
|
37
37
|
- `simplifyStroke()`: Ramer-Douglas-Peucker decimation preserving endpoints
|
|
38
38
|
- `polylineToSvgPath()`: SVG `d` strings for strokes and closed rings, with configurable precision
|
|
39
39
|
- Pure functions, zero dependencies, no DOM requirement
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Pure, deterministic geometry functions. No DOM, no timers, no long-lived handles.
|
|
5
5
|
*/
|
|
6
6
|
export { InkConfigError, InkError } from './errors.js';
|
|
7
|
-
export { strokeOutline } from './outline.js';
|
|
7
|
+
export { type StrokeCap, type StrokeJoin, type StrokeOutlineOptions, strokeOutline } from './outline.js';
|
|
8
8
|
export { simplifyStroke } from './simplify.js';
|
|
9
9
|
export { type SmoothStrokeOptions, smoothStroke } from './smoothing.js';
|
|
10
10
|
export { type StabilizeStrokeOptions, stabilizeStroke } from './stabilize.js';
|
|
11
11
|
export { type PolylineToSvgPathOptions, polylineToSvgPath } from './svg.js';
|
|
12
12
|
export type { Point, StrokePoint } from './types.js';
|
|
13
|
-
export { type StrokeWidthOptions, strokeWidths } from './widths.js';
|
|
13
|
+
export { type StrokeTaperOptions, type StrokeWidthOptions, strokeWidths } from './widths.js';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzG,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,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/ink.cjs
CHANGED
|
@@ -1,2 +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
|
|
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)}var e=[`round`,`butt`,`square`],t=[`round`,`bevel`,`miter`];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 segmentNormal(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r);return i===0?null:{x:r/i,y:-n/i}}function applyJoin(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){if(s===0||s===e.length-1){o.push(e[s]);continue}let c=t[s-1],l=t[s],u=t[s+1],d=l.x-c.x,f=l.y-c.y,p=u.x-l.x,m=u.y-l.y,h=Math.hypot(d,f),g=Math.hypot(p,m),_=segmentNormal(c,l),v=segmentNormal(l,u),y=h===0||g===0?1:(d*p+f*m)/(h*g),b=d*m-f*p,x=y<0&&_!==null&&v!==null,S=b===0?y<0:b<0==(a===1);if(!x||b===0){o.push(e[s]);continue}let C=n[s],w=a*(v.x-_.x)*C,T=a*(v.y-_.y)*C,E=(w*m-T*p)/b,D=(w*f-T*d)/b,O={x:l.x+a*_.x*C+E*d,y:l.y+a*_.y*C+E*f};if(S){let t=E>=-1-1e-9&&E<=1e-9&&D>=-1e-9&&D<=1+1e-9;o.push(t?O:e[s]);continue}let k={x:l.x+a*_.x*C,y:l.y+a*_.y*C},A={x:l.x+a*v.x*C,y:l.y+a*v.y*C},j=Math.hypot(O.x-l.x,O.y-l.y);r===`miter`&&j/C<=i?o.push(O):o.push(k,A)}return o}function squareTangent(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,s=Math.hypot(a,o);return s===0?null:{x:a/s,y:o/s}}function strokeOutline(n,r,i={}){let a=requireStrokePoints(n,1),o=typeof r==`number`?a.map(()=>r):r;if(o.length!==a.length)throw new InkConfigError(`Expected widths to hold ${a.length} number(s), received ${o.length}.`);for(let[e,t]of o.entries())if(requireFiniteNumber(t,`widths[${e}]`),t<=0)throw new InkConfigError(`Expected widths[${e}] to be a positive finite number, received ${t}.`);let s=i.cap??`round`;if(!e.includes(s))throw new InkConfigError(`Expected cap to be one of ${e.join(`, `)}, received ${String(s)}.`);let c=i.join??`round`;if(!t.includes(c))throw new InkConfigError(`Expected join to be one of ${t.join(`, `)}, received ${String(c)}.`);let l=4;if(i.miterLimit!==void 0){if(requireFiniteNumber(i.miterLimit,`miterLimit`),i.miterLimit<=0)throw new InkConfigError(`Expected miterLimit to be a positive finite number, received ${i.miterLimit}.`);l=i.miterLimit}let u=[],d=[],f=[];for(let e=0;e<a.length;e++){let t=a[e],n=o[e]/2;u.push(n);let r=normalAt(a,e);d.push({x:t.x+r.x*n,y:t.y+r.y*n}),f.push({x:t.x-r.x*n,y:t.y-r.y*n})}let p=c===`round`?d:applyJoin(d,a,u,c,l,1),m=c===`round`?f:applyJoin(f,a,u,c,l,-1),h=a[0],g=a[a.length-1],_=normalAt(a,0),v=normalAt(a,a.length-1),y=[];if(s===`square`){let e=u[0],t=u[u.length-1],n=squareTangent(a,0),r=squareTangent(a,a.length-1);return n&&y.push({x:f[0].x-n.x*e,y:f[0].y-n.y*e},{x:d[0].x-n.x*e,y:d[0].y-n.y*e}),y.push(...p),r&&y.push({x:d[d.length-1].x+r.x*t,y:d[d.length-1].y+r.y*t},{x:f[f.length-1].x+r.x*t,y:f[f.length-1].y+r.y*t}),y.push(...m.reverse()),y}return s===`round`&&appendCap(y,h,Math.atan2(_.y,_.x)+Math.PI,u[0]),y.push(...p),s===`round`&&appendCap(y,g,Math.atan2(v.y,v.x),u[u.length-1]),y.push(...m.reverse()),y}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 n=.25,r=2,i=.15,a=0,o=.15;function smoothstep(e){let t=clamp(e,0,1);return t*t*(3-2*t)}function arcLengths(e){let t=[0];for(let n=1;n<e.length;n++)t.push(t[n-1]+distance(e[n-1].x,e[n-1].y,e[n].x,e[n].y));return t}function requireTaperLength(e,t){if(requireFiniteNumber(e,t),e<0)throw new InkConfigError(`Expected ${t} to be non-negative, received ${e}.`);return e}function pressureScale(e){let t=clamp(e,0,1);return t<=.5?.5+t:1+(t-.5)*.5}function strokeWidths(e,t){let s=requireStrokePoints(e,1),c=requirePositive(t.width,`width`),l=requireRange(t.thinning??.5,`thinning`,0,1),u=requirePositive(t.referenceSpeed??.5,`referenceSpeed`),d=requireTaperLength(t.taper?.start??0,`taper.start`),f=requireTaperLength(t.taper?.end??0,`taper.end`),p=s.every(e=>e.time!==void 0),m=t.simulatePressure===!0&&p,h=d>0||f>0||m?arcLengths(s):null,g=h?h[h.length-1]:0,_=g*o,v=[],y=1;for(let e=0;e<s.length;e++){if(p&&l>0){let t=s[e],i=s[e+1],a=e>0?s[e-1]:t,o=e>0?t:i;if(o){let e=Math.abs(o.time-a.time);e>0&&(y=clamp((u/(distance(a.x,a.y,o.x,o.y)/e))**l,n,r))}}let t=s[e].pressure;if(t===void 0&&h!==null&&m&&_>0){let n=h[e];t=a+.5*Math.min(smoothstep(n/_),smoothstep((g-n)/_))}let o=t===void 0?1:pressureScale(t),b=1;if(h&&(d>0||f>0)){let t=h[e];d>0&&t<d&&(b=i+.85*smoothstep(t/d));let n=g-t;if(f>0&&n<f){let e=i+.85*smoothstep(n/f);b=Math.min(b,e)}}v.push(c*y*o*b)}return v}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
2
|
//# sourceMappingURL=ink.cjs.map
|
package/dist/ink.cjs.map
CHANGED
|
@@ -1 +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,EA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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"}
|
|
1
|
+
{"version":3,"file":"ink.cjs","names":["message","opts","value","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay","CAPS","JOINS","last","points","prev","i","next","tx","ty","other","len","s","angle","startAngle","outline","center","radius","to","from","out","offsets","input","cur","t1x","t1y","t2x","t2y","l1","l2","n1","n2","cos","cross","sharp","inside","side","h","half","wx","wy","t","u","hit","within","o1","o2","miterLength","join","miterLimit","perPoint","widths","index","w","cap","options","left","right","point","normal","leftSide","rightSide","first","firstNormal","lastNormal","startHalf","endHalf","startTangent","endTangent","b","a","lenSq","p","tolerance","keep","stack","farthest","maxDistance","d","result","linear","p1","p2","t2","t3","alpha","p0","p3","pressure","time","steps","tension","strength","deadZone","source","sx","sy","rounded","precision","close","parts","MIN_SCALE","MAX_SCALE","TAPER_FLOOR","PRESSURE_FLOOR","PRESSURE_RAMP_FRACTION","x","cum","width","thinning","referenceSpeed","taperStart","taperEnd","timed","simulate","total","pressureRamp","lastScale","dt","pressureFactor","taperFactor","remaining","endFactor"],"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/** End treatment for the outline ring. */\nexport type StrokeCap = 'round' | 'butt' | 'square';\n\n/** Corner treatment where the offset sides form a sharp angle. */\nexport type StrokeJoin = 'round' | 'bevel' | 'miter';\n\nexport interface StrokeOutlineOptions {\n /**\n * How the ring closes at each end. `round` adds a half-circle cap, `butt` adds none,\n * `square` extends each end by half the width along the tangent. Default `'round'`.\n */\n cap?: StrokeCap;\n /**\n * How sharp turns are joined on the inside of the turn. `round` keeps the plain\n * normal-offset samples (which approximate a round join), `bevel` replaces the joint\n * with the two adjacent segment-offset points, `miter` extends to the offset-line\n * intersection when within `miterLimit` and falls back to bevel otherwise. Default `'round'`.\n */\n join?: StrokeJoin;\n /**\n * Maximum ratio of miter length to half width before a `miter` join falls back to bevel.\n * Must be positive. Default `4`.\n */\n miterLimit?: number;\n}\n\nconst CAPS: readonly string[] = ['round', 'butt', 'square'];\nconst JOINS: readonly string[] = ['round', 'bevel', 'miter'];\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/** Unit normal of the segment `from` → `to` using the same convention as `normalAt`; null for a degenerate segment. */\nfunction segmentNormal(from: StrokePoint, to: StrokePoint): Point | null {\n const tx = to.x - from.x;\n const ty = to.y - from.y;\n const len = Math.hypot(tx, ty);\n if (len === 0) return null;\n return { x: ty / len, y: -tx / len };\n}\n\n/**\n * Replace the naive central-tangent offset samples at sharp interior turns (angle between\n * consecutive tangents > 90°) with join geometry. `side` is `+1` for the left offsets and\n * `-1` for the right offsets. Only the inside of the turn spikes with plain offsets: there\n * the two offset edges cross, and the crossing is dropped by keeping their intersection\n * (the union vertex) instead of the naive sample. On the outside, `bevel` inserts the two\n * per-segment offset points (a flat corner) and `miter` extends to the offset-line\n * intersection while its distance from the joint stays within `miterLimit` × half width,\n * falling back to bevel beyond it. Turns at or below 90° keep the naive sample, which\n * already reads as a round join.\n */\nfunction applyJoin(\n offsets: readonly Point[],\n input: readonly StrokePoint[],\n half: readonly number[],\n join: 'bevel' | 'miter',\n miterLimit: number,\n side: 1 | -1,\n): Point[] {\n const out: Point[] = [];\n for (let i = 0; i < offsets.length; i++) {\n if (i === 0 || i === offsets.length - 1) {\n out.push(offsets[i]);\n continue;\n }\n const prev = input[i - 1];\n const cur = input[i];\n const next = input[i + 1];\n const t1x = cur.x - prev.x;\n const t1y = cur.y - prev.y;\n const t2x = next.x - cur.x;\n const t2y = next.y - cur.y;\n const l1 = Math.hypot(t1x, t1y);\n const l2 = Math.hypot(t2x, t2y);\n const n1 = segmentNormal(prev, cur);\n const n2 = segmentNormal(cur, next);\n const cos = l1 === 0 || l2 === 0 ? 1 : (t1x * t2x + t1y * t2y) / (l1 * l2);\n const cross = t1x * t2y - t1y * t2x;\n // A turn is sharp when its tangents differ by more than 90° (cos < 0). A left turn\n // (cross < 0 in this normal convention) puts the inside on the +normal side.\n const sharp = cos < 0 && n1 !== null && n2 !== null;\n const inside = cross === 0 ? cos < 0 : cross < 0 === (side === 1);\n if (!sharp || cross === 0) {\n // Not a sharp turn, a degenerate segment, or an exact reversal (parallel offset\n // edges, no finite join vertex): keep the naive sample.\n out.push(offsets[i]);\n continue;\n }\n const h = half[i];\n // Intersection of the two offset lines on this side:\n // line 1: cur + side*n1*h + t*t1; line 2: cur + side*n2*h + u*t2.\n // t = ((side*(n2-n1)*h) × t2) / (t1 × t2), u = ((side*(n2-n1)*h) × t1) / (t1 × t2).\n const wx = side * (n2.x - n1.x) * h;\n const wy = side * (n2.y - n1.y) * h;\n const t = (wx * t2y - wy * t2x) / cross;\n const u = (wx * t1y - wy * t1x) / cross;\n const hit = { x: cur.x + side * n1.x * h + t * t1x, y: cur.y + side * n1.y * h + t * t1y };\n if (inside) {\n // The inner union vertex sits behind the joint along segment 1 and forward along\n // segment 2 (in units of the full segment vectors). If it falls outside either\n // segment's span (e.g. a spike into a very short leg), no clean join vertex exists\n // and the naive sample is kept.\n const within = t >= -1 - 1e-9 && t <= 1e-9 && u >= -1e-9 && u <= 1 + 1e-9;\n out.push(within ? hit : offsets[i]);\n continue;\n }\n // Outside of a sharp turn.\n const o1 = { x: cur.x + side * n1.x * h, y: cur.y + side * n1.y * h };\n const o2 = { x: cur.x + side * n2.x * h, y: cur.y + side * n2.y * h };\n const miterLength = Math.hypot(hit.x - cur.x, hit.y - cur.y);\n if (join === 'miter' && miterLength / h <= miterLimit) {\n out.push(hit);\n } else {\n out.push(o1, o2);\n }\n }\n return out;\n}\n\n/** Unit tangent used to square off the cap at sample `i` (the central segment direction); null when degenerate. */\nfunction squareTangent(points: readonly StrokePoint[], i: number): Point | null {\n const last = points.length - 1;\n const from = points[clamp(i - 1, 0, last)];\n const to = points[clamp(i + 1, 0, last)];\n const tx = to.x - from.x;\n const ty = to.y - from.y;\n const len = Math.hypot(tx, ty);\n if (len === 0) return null;\n return { x: tx / len, y: ty / len };\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 * `options.cap` selects the end treatment: `'round'` half-circle caps (default), `'butt'` for\n * no cap points, `'square'` for a half-width tangent extension at each end. `options.join`\n * selects the inside-corner treatment at turns sharper than 90°: `'round'` (default) keeps the\n * plain offset samples, `'bevel'` replaces each sharp joint with the two adjacent segment-offset\n * points (dropping the crossing spike), and `'miter'` extends to the offset-line intersection\n * while the miter length stays within `options.miterLimit` × half width, falling back to bevel beyond it.\n *\n * @throws {import('./errors.js').InkConfigError} When `widths` is a mismatched array or holds non-positive values, when `cap` or `join` is not a known variant, or when `miterLimit` is not a positive finite number.\n */\nexport function strokeOutline(\n points: readonly StrokePoint[],\n widths: number | readonly number[],\n options: StrokeOutlineOptions = {},\n): 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 const cap = options.cap ?? 'round';\n if (!CAPS.includes(cap)) {\n throw new InkConfigError(`Expected cap to be one of ${CAPS.join(', ')}, received ${String(cap)}.`);\n }\n const join = options.join ?? 'round';\n if (!JOINS.includes(join)) {\n throw new InkConfigError(`Expected join to be one of ${JOINS.join(', ')}, received ${String(join)}.`);\n }\n let miterLimit = 4;\n if (options.miterLimit !== undefined) {\n requireFiniteNumber(options.miterLimit, 'miterLimit');\n if (options.miterLimit <= 0) {\n throw new InkConfigError(`Expected miterLimit to be a positive finite number, received ${options.miterLimit}.`);\n }\n miterLimit = options.miterLimit;\n }\n\n const half: number[] = [];\n const left: Point[] = [];\n const right: Point[] = [];\n for (let i = 0; i < input.length; i++) {\n const point = input[i];\n const h = perPoint[i] / 2;\n half.push(h);\n const normal = normalAt(input, i);\n left.push({ x: point.x + normal.x * h, y: point.y + normal.y * h });\n right.push({ x: point.x - normal.x * h, y: point.y - normal.y * h });\n }\n const leftSide = join === 'round' ? left : applyJoin(left, input, half, join, miterLimit, 1);\n const rightSide = join === 'round' ? right : applyJoin(right, input, half, join, miterLimit, -1);\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 if (cap === 'square') {\n // Square caps: extend each end by half the width along the tangent (two extra points per end).\n const startHalf = half[0];\n const endHalf = half[half.length - 1];\n const startTangent = squareTangent(input, 0);\n const endTangent = squareTangent(input, input.length - 1);\n if (startTangent) {\n outline.push(\n { x: right[0].x - startTangent.x * startHalf, y: right[0].y - startTangent.y * startHalf },\n { x: left[0].x - startTangent.x * startHalf, y: left[0].y - startTangent.y * startHalf },\n );\n }\n outline.push(...leftSide);\n if (endTangent) {\n outline.push(\n { x: left[left.length - 1].x + endTangent.x * endHalf, y: left[left.length - 1].y + endTangent.y * endHalf },\n {\n x: right[right.length - 1].x + endTangent.x * endHalf,\n y: right[right.length - 1].y + endTangent.y * endHalf,\n },\n );\n }\n outline.push(...rightSide.reverse());\n return outline;\n }\n\n if (cap === 'round') {\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, half[0]);\n }\n outline.push(...leftSide);\n if (cap === 'round') {\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), half[half.length - 1]);\n }\n outline.push(...rightSide.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 {\n clamp,\n distance,\n requireFiniteNumber,\n requirePositive,\n requireRange,\n requireStrokePoints,\n} from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StrokeTaperOptions {\n /**\n * Fade-out LENGTH measured along arc length from the last point, in the same units as\n * `width`. Symmetric to `start`. Default `0` (no fade-out).\n */\n end?: number;\n /**\n * Fade-in LENGTH measured along arc length from the first point, in the same units as\n * `width`. Within the first `start` units the width is multiplied by a smoothstep ramp\n * rising from `0.15` to `1`. Default `0` (no fade-in).\n */\n start?: number;\n}\n\nexport interface StrokeWidthOptions {\n /** Pen speed treated as \"neutral\", in pixels per millisecond. Default `0.5`. */\n referenceSpeed?: number;\n /**\n * When `true` and the stroke is timed, synthesize pressure for points that have NO `pressure`\n * from an in/out smoothstep ramp over arc length: the width multiplier drops to `0.5` at each\n * tip (pressure ramps from `0` to neutral `0.5`) so mouse strokes thin at the ends. Points that\n * DO carry `pressure` always use their real value; untimed strokes ignore this option.\n * Default `false`.\n */\n simulatePressure?: boolean;\n /**\n * Taper the stroke ends: fade the width in over `taper.start` and out over `taper.end`\n * units of arc length, multiplying the velocity/pressure profile by a smoothstep ramp that\n * bottoms out at `0.15` of full width. Applied on top of (not instead of) speed and pressure.\n */\n taper?: StrokeTaperOptions;\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/** Width multiplier at the very tip of a taper. */\nconst TAPER_FLOOR = 0.15;\n/** Synthesized pressure at the very tip of a simulated-pressure ramp (maps to 0.5x width). */\nconst PRESSURE_FLOOR = 0;\n/** Fraction of total arc length (each end) over which simulated pressure ramps. */\nconst PRESSURE_RAMP_FRACTION = 0.15;\n\n/** Smoothstep on `[0, 1]`: `3t² - 2t³`, clamped outside the range. */\nfunction smoothstep(t: number): number {\n const x = clamp(t, 0, 1);\n return x * x * (3 - 2 * x);\n}\n\n/** Cumulative arc length at each point, starting at `0`. */\nfunction arcLengths(points: readonly StrokePoint[]): number[] {\n const cum: number[] = [0];\n for (let i = 1; i < points.length; i++) {\n cum.push(cum[i - 1] + distance(points[i - 1].x, points[i - 1].y, points[i].x, points[i].y));\n }\n return cum;\n}\n\n/** Validate a taper length option: finite and non-negative. */\nfunction requireTaperLength(value: number, name: string): number {\n requireFiniteNumber(value, name);\n if (value < 0) {\n throw new InkConfigError(`Expected ${name} to be non-negative, received ${value}.`);\n }\n return value;\n}\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 * `taper` fades the width in over `taper.start` and out over `taper.end` units of arc length\n * (smoothstep ramp, floor `0.15`), multiplying whatever the speed/pressure profile produced, so\n * a tapered stroke still responds to speed in its body. `simulatePressure` fills in pressure for\n * points that lack it on a timed stroke, ramping the width multiplier from `0.5` at each tip to\n * neutral across the first and last 15% of arc length; points with real `pressure` are never\n * overridden.\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 const taperStart = requireTaperLength(options.taper?.start ?? 0, 'taper.start');\n const taperEnd = requireTaperLength(options.taper?.end ?? 0, 'taper.end');\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 // Simulated pressure only makes sense on a timed stroke, and never overrides real pressure.\n const simulate = options.simulatePressure === true && timed;\n\n const needArc = taperStart > 0 || taperEnd > 0 || simulate;\n const cum = needArc ? arcLengths(input) : null;\n const total = cum ? cum[cum.length - 1] : 0;\n const pressureRamp = total * PRESSURE_RAMP_FRACTION;\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\n let pressure = input[i].pressure;\n if (pressure === undefined && cum !== null && simulate && pressureRamp > 0) {\n // Ramp from PRESSURE_FLOOR at each tip up to neutral (0.5) in the body.\n const s = cum[i];\n const ramp = Math.min(smoothstep(s / pressureRamp), smoothstep((total - s) / pressureRamp));\n pressure = PRESSURE_FLOOR + (0.5 - PRESSURE_FLOOR) * ramp;\n }\n const pressureFactor = pressure === undefined ? 1 : pressureScale(pressure);\n\n let taperFactor = 1;\n if (cum && (taperStart > 0 || taperEnd > 0)) {\n const s = cum[i];\n if (taperStart > 0 && s < taperStart) {\n taperFactor = TAPER_FLOOR + (1 - TAPER_FLOOR) * smoothstep(s / taperStart);\n }\n const remaining = total - s;\n if (taperEnd > 0 && remaining < taperEnd) {\n const endFactor = TAPER_FLOOR + (1 - TAPER_FLOOR) * smoothstep(remaining / taperEnd);\n taperFactor = Math.min(taperFactor, endFactor);\n }\n }\n\n widths.push(width * lastScale * pressureFactor * taperFactor);\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,iBAAi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oG,EAAW,GAAKS,EAAYT,EAAU,CACxC,IAAMU,EAAYnB,EAAe,IAAmB,WAAWkB,EAAYT,CAAQ,EACnF,EAAc,KAAK,IAAIQ,EAAaE,CAAS,CAC/C,CACF,CAEAvE,EAAO,KAAKyD,EAAQS,EAAYE,EAAiBC,CAAW,CAC9D,CACA,OAAOrE,CACT,C"}
|
package/dist/ink.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Ink=(function(e){Object.defineProperty(e,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
|
|
1
|
+
var Ink=(function(e){Object.defineProperty(e,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)}var t=[`round`,`butt`,`square`],n=[`round`,`bevel`,`miter`];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 segmentNormal(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r);return i===0?null:{x:r/i,y:-n/i}}function applyJoin(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){if(s===0||s===e.length-1){o.push(e[s]);continue}let c=t[s-1],l=t[s],u=t[s+1],d=l.x-c.x,f=l.y-c.y,p=u.x-l.x,m=u.y-l.y,h=Math.hypot(d,f),g=Math.hypot(p,m),_=segmentNormal(c,l),v=segmentNormal(l,u),y=h===0||g===0?1:(d*p+f*m)/(h*g),b=d*m-f*p,x=y<0&&_!==null&&v!==null,S=b===0?y<0:b<0==(a===1);if(!x||b===0){o.push(e[s]);continue}let C=n[s],w=a*(v.x-_.x)*C,T=a*(v.y-_.y)*C,E=(w*m-T*p)/b,D=(w*f-T*d)/b,O={x:l.x+a*_.x*C+E*d,y:l.y+a*_.y*C+E*f};if(S){let t=E>=-1-1e-9&&E<=1e-9&&D>=-1e-9&&D<=1+1e-9;o.push(t?O:e[s]);continue}let k={x:l.x+a*_.x*C,y:l.y+a*_.y*C},A={x:l.x+a*v.x*C,y:l.y+a*v.y*C},j=Math.hypot(O.x-l.x,O.y-l.y);r===`miter`&&j/C<=i?o.push(O):o.push(k,A)}return o}function squareTangent(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,s=Math.hypot(a,o);return s===0?null:{x:a/s,y:o/s}}function strokeOutline(e,r,i={}){let a=requireStrokePoints(e,1),o=typeof r==`number`?a.map(()=>r):r;if(o.length!==a.length)throw new InkConfigError(`Expected widths to hold ${a.length} number(s), received ${o.length}.`);for(let[e,t]of o.entries())if(requireFiniteNumber(t,`widths[${e}]`),t<=0)throw new InkConfigError(`Expected widths[${e}] to be a positive finite number, received ${t}.`);let s=i.cap??`round`;if(!t.includes(s))throw new InkConfigError(`Expected cap to be one of ${t.join(`, `)}, received ${String(s)}.`);let c=i.join??`round`;if(!n.includes(c))throw new InkConfigError(`Expected join to be one of ${n.join(`, `)}, received ${String(c)}.`);let l=4;if(i.miterLimit!==void 0){if(requireFiniteNumber(i.miterLimit,`miterLimit`),i.miterLimit<=0)throw new InkConfigError(`Expected miterLimit to be a positive finite number, received ${i.miterLimit}.`);l=i.miterLimit}let u=[],d=[],f=[];for(let e=0;e<a.length;e++){let t=a[e],n=o[e]/2;u.push(n);let r=normalAt(a,e);d.push({x:t.x+r.x*n,y:t.y+r.y*n}),f.push({x:t.x-r.x*n,y:t.y-r.y*n})}let p=c===`round`?d:applyJoin(d,a,u,c,l,1),m=c===`round`?f:applyJoin(f,a,u,c,l,-1),h=a[0],g=a[a.length-1],_=normalAt(a,0),v=normalAt(a,a.length-1),y=[];if(s===`square`){let e=u[0],t=u[u.length-1],n=squareTangent(a,0),r=squareTangent(a,a.length-1);return n&&y.push({x:f[0].x-n.x*e,y:f[0].y-n.y*e},{x:d[0].x-n.x*e,y:d[0].y-n.y*e}),y.push(...p),r&&y.push({x:d[d.length-1].x+r.x*t,y:d[d.length-1].y+r.y*t},{x:f[f.length-1].x+r.x*t,y:f[f.length-1].y+r.y*t}),y.push(...m.reverse()),y}return s===`round`&&appendCap(y,h,Math.atan2(_.y,_.x)+Math.PI,u[0]),y.push(...p),s===`round`&&appendCap(y,g,Math.atan2(v.y,v.x),u[u.length-1]),y.push(...m.reverse()),y}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 r=.25,i=2,a=.15,o=0,s=.15;function smoothstep(e){let t=clamp(e,0,1);return t*t*(3-2*t)}function arcLengths(e){let t=[0];for(let n=1;n<e.length;n++)t.push(t[n-1]+distance(e[n-1].x,e[n-1].y,e[n].x,e[n].y));return t}function requireTaperLength(e,t){if(requireFiniteNumber(e,t),e<0)throw new InkConfigError(`Expected ${t} to be non-negative, received ${e}.`);return e}function pressureScale(e){let t=clamp(e,0,1);return t<=.5?.5+t:1+(t-.5)*.5}function strokeWidths(e,t){let n=requireStrokePoints(e,1),c=requirePositive(t.width,`width`),l=requireRange(t.thinning??.5,`thinning`,0,1),u=requirePositive(t.referenceSpeed??.5,`referenceSpeed`),d=requireTaperLength(t.taper?.start??0,`taper.start`),f=requireTaperLength(t.taper?.end??0,`taper.end`),p=n.every(e=>e.time!==void 0),m=t.simulatePressure===!0&&p,h=d>0||f>0||m?arcLengths(n):null,g=h?h[h.length-1]:0,_=g*s,v=[],y=1;for(let e=0;e<n.length;e++){if(p&&l>0){let t=n[e],a=n[e+1],o=e>0?n[e-1]:t,s=e>0?t:a;if(s){let e=Math.abs(s.time-o.time);e>0&&(y=clamp((u/(distance(o.x,o.y,s.x,s.y)/e))**l,r,i))}}let t=n[e].pressure;if(t===void 0&&h!==null&&m&&_>0){let n=h[e];t=o+.5*Math.min(smoothstep(n/_),smoothstep((g-n)/_))}let s=t===void 0?1:pressureScale(t),b=1;if(h&&(d>0||f>0)){let t=h[e];d>0&&t<d&&(b=a+.85*smoothstep(t/d));let n=g-t;if(f>0&&n<f){let e=a+.85*smoothstep(n/f);b=Math.min(b,e)}}v.push(c*y*s*b)}return v}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
2
|
//# sourceMappingURL=ink.iife.js.map
|
package/dist/ink.iife.js.map
CHANGED
|
@@ -1 +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,CAAK,EAAE,EAAE,EAE/F,OAAOA,CACT,CAEA,SAAgB,aAAa,EAAe,EAAc,EAAa,EAAqB,CAC1F,GAAIA,EAAQE,GAAOF,EAAQG,EACzB,MAAM,IAAI,eAAe,YAAYF,EAA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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"}
|
|
1
|
+
{"version":3,"file":"ink.iife.js","names":["exports","message","opts","value","name","min","max","resolved","minPoints","dx","bx","ax","dy","by","ay","CAPS","JOINS","last","points","prev","i","next","tx","ty","other","len","s","angle","startAngle","outline","center","radius","to","from","out","offsets","input","cur","t1x","t1y","t2x","t2y","l1","l2","n1","n2","cos","cross","sharp","inside","side","h","half","wx","wy","t","u","hit","within","o1","o2","miterLength","join","miterLimit","perPoint","widths","index","w","cap","options","left","right","point","normal","leftSide","rightSide","first","firstNormal","lastNormal","startHalf","endHalf","startTangent","endTangent","b","a","lenSq","p","tolerance","keep","stack","farthest","maxDistance","d","result","linear","p1","p2","t2","t3","alpha","p0","p3","pressure","time","steps","tension","strength","deadZone","source","sx","sy","rounded","precision","close","parts","MIN_SCALE","MAX_SCALE","TAPER_FLOOR","PRESSURE_FLOOR","PRESSURE_RAMP_FRACTION","x","cum","width","thinning","referenceSpeed","taperStart","taperEnd","timed","simulate","total","pressureRamp","lastScale","dt","pressureFactor","taperFactor","remaining","endFactor"],"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/** End treatment for the outline ring. */\nexport type StrokeCap = 'round' | 'butt' | 'square';\n\n/** Corner treatment where the offset sides form a sharp angle. */\nexport type StrokeJoin = 'round' | 'bevel' | 'miter';\n\nexport interface StrokeOutlineOptions {\n /**\n * How the ring closes at each end. `round` adds a half-circle cap, `butt` adds none,\n * `square` extends each end by half the width along the tangent. Default `'round'`.\n */\n cap?: StrokeCap;\n /**\n * How sharp turns are joined on the inside of the turn. `round` keeps the plain\n * normal-offset samples (which approximate a round join), `bevel` replaces the joint\n * with the two adjacent segment-offset points, `miter` extends to the offset-line\n * intersection when within `miterLimit` and falls back to bevel otherwise. Default `'round'`.\n */\n join?: StrokeJoin;\n /**\n * Maximum ratio of miter length to half width before a `miter` join falls back to bevel.\n * Must be positive. Default `4`.\n */\n miterLimit?: number;\n}\n\nconst CAPS: readonly string[] = ['round', 'butt', 'square'];\nconst JOINS: readonly string[] = ['round', 'bevel', 'miter'];\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/** Unit normal of the segment `from` → `to` using the same convention as `normalAt`; null for a degenerate segment. */\nfunction segmentNormal(from: StrokePoint, to: StrokePoint): Point | null {\n const tx = to.x - from.x;\n const ty = to.y - from.y;\n const len = Math.hypot(tx, ty);\n if (len === 0) return null;\n return { x: ty / len, y: -tx / len };\n}\n\n/**\n * Replace the naive central-tangent offset samples at sharp interior turns (angle between\n * consecutive tangents > 90°) with join geometry. `side` is `+1` for the left offsets and\n * `-1` for the right offsets. Only the inside of the turn spikes with plain offsets: there\n * the two offset edges cross, and the crossing is dropped by keeping their intersection\n * (the union vertex) instead of the naive sample. On the outside, `bevel` inserts the two\n * per-segment offset points (a flat corner) and `miter` extends to the offset-line\n * intersection while its distance from the joint stays within `miterLimit` × half width,\n * falling back to bevel beyond it. Turns at or below 90° keep the naive sample, which\n * already reads as a round join.\n */\nfunction applyJoin(\n offsets: readonly Point[],\n input: readonly StrokePoint[],\n half: readonly number[],\n join: 'bevel' | 'miter',\n miterLimit: number,\n side: 1 | -1,\n): Point[] {\n const out: Point[] = [];\n for (let i = 0; i < offsets.length; i++) {\n if (i === 0 || i === offsets.length - 1) {\n out.push(offsets[i]);\n continue;\n }\n const prev = input[i - 1];\n const cur = input[i];\n const next = input[i + 1];\n const t1x = cur.x - prev.x;\n const t1y = cur.y - prev.y;\n const t2x = next.x - cur.x;\n const t2y = next.y - cur.y;\n const l1 = Math.hypot(t1x, t1y);\n const l2 = Math.hypot(t2x, t2y);\n const n1 = segmentNormal(prev, cur);\n const n2 = segmentNormal(cur, next);\n const cos = l1 === 0 || l2 === 0 ? 1 : (t1x * t2x + t1y * t2y) / (l1 * l2);\n const cross = t1x * t2y - t1y * t2x;\n // A turn is sharp when its tangents differ by more than 90° (cos < 0). A left turn\n // (cross < 0 in this normal convention) puts the inside on the +normal side.\n const sharp = cos < 0 && n1 !== null && n2 !== null;\n const inside = cross === 0 ? cos < 0 : cross < 0 === (side === 1);\n if (!sharp || cross === 0) {\n // Not a sharp turn, a degenerate segment, or an exact reversal (parallel offset\n // edges, no finite join vertex): keep the naive sample.\n out.push(offsets[i]);\n continue;\n }\n const h = half[i];\n // Intersection of the two offset lines on this side:\n // line 1: cur + side*n1*h + t*t1; line 2: cur + side*n2*h + u*t2.\n // t = ((side*(n2-n1)*h) × t2) / (t1 × t2), u = ((side*(n2-n1)*h) × t1) / (t1 × t2).\n const wx = side * (n2.x - n1.x) * h;\n const wy = side * (n2.y - n1.y) * h;\n const t = (wx * t2y - wy * t2x) / cross;\n const u = (wx * t1y - wy * t1x) / cross;\n const hit = { x: cur.x + side * n1.x * h + t * t1x, y: cur.y + side * n1.y * h + t * t1y };\n if (inside) {\n // The inner union vertex sits behind the joint along segment 1 and forward along\n // segment 2 (in units of the full segment vectors). If it falls outside either\n // segment's span (e.g. a spike into a very short leg), no clean join vertex exists\n // and the naive sample is kept.\n const within = t >= -1 - 1e-9 && t <= 1e-9 && u >= -1e-9 && u <= 1 + 1e-9;\n out.push(within ? hit : offsets[i]);\n continue;\n }\n // Outside of a sharp turn.\n const o1 = { x: cur.x + side * n1.x * h, y: cur.y + side * n1.y * h };\n const o2 = { x: cur.x + side * n2.x * h, y: cur.y + side * n2.y * h };\n const miterLength = Math.hypot(hit.x - cur.x, hit.y - cur.y);\n if (join === 'miter' && miterLength / h <= miterLimit) {\n out.push(hit);\n } else {\n out.push(o1, o2);\n }\n }\n return out;\n}\n\n/** Unit tangent used to square off the cap at sample `i` (the central segment direction); null when degenerate. */\nfunction squareTangent(points: readonly StrokePoint[], i: number): Point | null {\n const last = points.length - 1;\n const from = points[clamp(i - 1, 0, last)];\n const to = points[clamp(i + 1, 0, last)];\n const tx = to.x - from.x;\n const ty = to.y - from.y;\n const len = Math.hypot(tx, ty);\n if (len === 0) return null;\n return { x: tx / len, y: ty / len };\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 * `options.cap` selects the end treatment: `'round'` half-circle caps (default), `'butt'` for\n * no cap points, `'square'` for a half-width tangent extension at each end. `options.join`\n * selects the inside-corner treatment at turns sharper than 90°: `'round'` (default) keeps the\n * plain offset samples, `'bevel'` replaces each sharp joint with the two adjacent segment-offset\n * points (dropping the crossing spike), and `'miter'` extends to the offset-line intersection\n * while the miter length stays within `options.miterLimit` × half width, falling back to bevel beyond it.\n *\n * @throws {import('./errors.js').InkConfigError} When `widths` is a mismatched array or holds non-positive values, when `cap` or `join` is not a known variant, or when `miterLimit` is not a positive finite number.\n */\nexport function strokeOutline(\n points: readonly StrokePoint[],\n widths: number | readonly number[],\n options: StrokeOutlineOptions = {},\n): 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 const cap = options.cap ?? 'round';\n if (!CAPS.includes(cap)) {\n throw new InkConfigError(`Expected cap to be one of ${CAPS.join(', ')}, received ${String(cap)}.`);\n }\n const join = options.join ?? 'round';\n if (!JOINS.includes(join)) {\n throw new InkConfigError(`Expected join to be one of ${JOINS.join(', ')}, received ${String(join)}.`);\n }\n let miterLimit = 4;\n if (options.miterLimit !== undefined) {\n requireFiniteNumber(options.miterLimit, 'miterLimit');\n if (options.miterLimit <= 0) {\n throw new InkConfigError(`Expected miterLimit to be a positive finite number, received ${options.miterLimit}.`);\n }\n miterLimit = options.miterLimit;\n }\n\n const half: number[] = [];\n const left: Point[] = [];\n const right: Point[] = [];\n for (let i = 0; i < input.length; i++) {\n const point = input[i];\n const h = perPoint[i] / 2;\n half.push(h);\n const normal = normalAt(input, i);\n left.push({ x: point.x + normal.x * h, y: point.y + normal.y * h });\n right.push({ x: point.x - normal.x * h, y: point.y - normal.y * h });\n }\n const leftSide = join === 'round' ? left : applyJoin(left, input, half, join, miterLimit, 1);\n const rightSide = join === 'round' ? right : applyJoin(right, input, half, join, miterLimit, -1);\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 if (cap === 'square') {\n // Square caps: extend each end by half the width along the tangent (two extra points per end).\n const startHalf = half[0];\n const endHalf = half[half.length - 1];\n const startTangent = squareTangent(input, 0);\n const endTangent = squareTangent(input, input.length - 1);\n if (startTangent) {\n outline.push(\n { x: right[0].x - startTangent.x * startHalf, y: right[0].y - startTangent.y * startHalf },\n { x: left[0].x - startTangent.x * startHalf, y: left[0].y - startTangent.y * startHalf },\n );\n }\n outline.push(...leftSide);\n if (endTangent) {\n outline.push(\n { x: left[left.length - 1].x + endTangent.x * endHalf, y: left[left.length - 1].y + endTangent.y * endHalf },\n {\n x: right[right.length - 1].x + endTangent.x * endHalf,\n y: right[right.length - 1].y + endTangent.y * endHalf,\n },\n );\n }\n outline.push(...rightSide.reverse());\n return outline;\n }\n\n if (cap === 'round') {\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, half[0]);\n }\n outline.push(...leftSide);\n if (cap === 'round') {\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), half[half.length - 1]);\n }\n outline.push(...rightSide.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 {\n clamp,\n distance,\n requireFiniteNumber,\n requirePositive,\n requireRange,\n requireStrokePoints,\n} from './_validate.js';\nimport { InkConfigError } from './errors.js';\nimport type { StrokePoint } from './types.js';\n\nexport interface StrokeTaperOptions {\n /**\n * Fade-out LENGTH measured along arc length from the last point, in the same units as\n * `width`. Symmetric to `start`. Default `0` (no fade-out).\n */\n end?: number;\n /**\n * Fade-in LENGTH measured along arc length from the first point, in the same units as\n * `width`. Within the first `start` units the width is multiplied by a smoothstep ramp\n * rising from `0.15` to `1`. Default `0` (no fade-in).\n */\n start?: number;\n}\n\nexport interface StrokeWidthOptions {\n /** Pen speed treated as \"neutral\", in pixels per millisecond. Default `0.5`. */\n referenceSpeed?: number;\n /**\n * When `true` and the stroke is timed, synthesize pressure for points that have NO `pressure`\n * from an in/out smoothstep ramp over arc length: the width multiplier drops to `0.5` at each\n * tip (pressure ramps from `0` to neutral `0.5`) so mouse strokes thin at the ends. Points that\n * DO carry `pressure` always use their real value; untimed strokes ignore this option.\n * Default `false`.\n */\n simulatePressure?: boolean;\n /**\n * Taper the stroke ends: fade the width in over `taper.start` and out over `taper.end`\n * units of arc length, multiplying the velocity/pressure profile by a smoothstep ramp that\n * bottoms out at `0.15` of full width. Applied on top of (not instead of) speed and pressure.\n */\n taper?: StrokeTaperOptions;\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/** Width multiplier at the very tip of a taper. */\nconst TAPER_FLOOR = 0.15;\n/** Synthesized pressure at the very tip of a simulated-pressure ramp (maps to 0.5x width). */\nconst PRESSURE_FLOOR = 0;\n/** Fraction of total arc length (each end) over which simulated pressure ramps. */\nconst PRESSURE_RAMP_FRACTION = 0.15;\n\n/** Smoothstep on `[0, 1]`: `3t² - 2t³`, clamped outside the range. */\nfunction smoothstep(t: number): number {\n const x = clamp(t, 0, 1);\n return x * x * (3 - 2 * x);\n}\n\n/** Cumulative arc length at each point, starting at `0`. */\nfunction arcLengths(points: readonly StrokePoint[]): number[] {\n const cum: number[] = [0];\n for (let i = 1; i < points.length; i++) {\n cum.push(cum[i - 1] + distance(points[i - 1].x, points[i - 1].y, points[i].x, points[i].y));\n }\n return cum;\n}\n\n/** Validate a taper length option: finite and non-negative. */\nfunction requireTaperLength(value: number, name: string): number {\n requireFiniteNumber(value, name);\n if (value < 0) {\n throw new InkConfigError(`Expected ${name} to be non-negative, received ${value}.`);\n }\n return value;\n}\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 * `taper` fades the width in over `taper.start` and out over `taper.end` units of arc length\n * (smoothstep ramp, floor `0.15`), multiplying whatever the speed/pressure profile produced, so\n * a tapered stroke still responds to speed in its body. `simulatePressure` fills in pressure for\n * points that lack it on a timed stroke, ramping the width multiplier from `0.5` at each tip to\n * neutral across the first and last 15% of arc length; points with real `pressure` are never\n * overridden.\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 const taperStart = requireTaperLength(options.taper?.start ?? 0, 'taper.start');\n const taperEnd = requireTaperLength(options.taper?.end ?? 0, 'taper.end');\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 // Simulated pressure only makes sense on a timed stroke, and never overrides real pressure.\n const simulate = options.simulatePressure === true && timed;\n\n const needArc = taperStart > 0 || taperEnd > 0 || simulate;\n const cum = needArc ? arcLengths(input) : null;\n const total = cum ? cum[cum.length - 1] : 0;\n const pressureRamp = total * PRESSURE_RAMP_FRACTION;\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\n let pressure = input[i].pressure;\n if (pressure === undefined && cum !== null && simulate && pressureRamp > 0) {\n // Ramp from PRESSURE_FLOOR at each tip up to neutral (0.5) in the body.\n const s = cum[i];\n const ramp = Math.min(smoothstep(s / pressureRamp), smoothstep((total - s) / pressureRamp));\n pressure = PRESSURE_FLOOR + (0.5 - PRESSURE_FLOOR) * ramp;\n }\n const pressureFactor = pressure === undefined ? 1 : pressureScale(pressure);\n\n let taperFactor = 1;\n if (cum && (taperStart > 0 || taperEnd > 0)) {\n const s = cum[i];\n if (taperStart > 0 && s < taperStart) {\n taperFactor = TAPER_FLOOR + (1 - TAPER_FLOOR) * smoothstep(s / taperStart);\n }\n const remaining = total - s;\n if (taperEnd > 0 && remaining < taperEnd) {\n const endFactor = TAPER_FLOOR + (1 - TAPER_FLOOR) * smoothstep(remaining / taperEnd);\n taperFactor = Math.min(taperFactor, endFactor);\n }\n }\n\n widths.push(width * lastScale * pressureFactor * taperFactor);\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,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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