@vielzeug/ink 0.0.0-stage → 26.11.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/_validate.cjs +2 -0
- package/dist/_validate.cjs.map +1 -0
- package/dist/_validate.d.ts +11 -0
- package/dist/_validate.d.ts.map +1 -0
- package/dist/_validate.js +32 -0
- package/dist/_validate.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/ink.cjs +2 -0
- package/dist/ink.cjs.map +1 -0
- package/dist/ink.iife.js +2 -0
- package/dist/ink.iife.js.map +1 -0
- package/dist/ink.js +191 -0
- package/dist/ink.js.map +1 -0
- package/dist/outline.cjs +2 -0
- package/dist/outline.cjs.map +1 -0
- package/dist/outline.d.ts +14 -0
- package/dist/outline.d.ts.map +1 -0
- package/dist/outline.js +48 -0
- package/dist/outline.js.map +1 -0
- package/dist/simplify.cjs +2 -0
- package/dist/simplify.cjs.map +1 -0
- package/dist/simplify.d.ts +12 -0
- package/dist/simplify.d.ts.map +1 -0
- package/dist/simplify.js +29 -0
- package/dist/simplify.js.map +1 -0
- package/dist/smoothing.cjs +2 -0
- package/dist/smoothing.cjs.map +1 -0
- package/dist/smoothing.d.ts +20 -0
- package/dist/smoothing.d.ts.map +1 -0
- package/dist/smoothing.js +39 -0
- package/dist/smoothing.js.map +1 -0
- package/dist/stabilize.cjs +2 -0
- package/dist/stabilize.cjs.map +1 -0
- package/dist/stabilize.d.ts +24 -0
- package/dist/stabilize.d.ts.map +1 -0
- package/dist/stabilize.js +25 -0
- package/dist/stabilize.js.map +1 -0
- package/dist/svg.cjs +2 -0
- package/dist/svg.cjs.map +1 -0
- package/dist/svg.d.ts +27 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/svg.js +14 -0
- package/dist/svg.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/widths.cjs +2 -0
- package/dist/widths.cjs.map +1 -0
- package/dist/widths.d.ts +26 -0
- package/dist/widths.d.ts.map +1 -0
- package/dist/widths.js +28 -0
- package/dist/widths.js.map +1 -0
- package/package.json +48 -4
package/dist/widths.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { clamp as e, distance as t, requirePositive as n, requireRange as r, requireStrokePoints as i } from "./_validate.js";
|
|
2
|
+
// src/widths.ts
|
|
3
|
+
var a = .25, o = 2;
|
|
4
|
+
function pressureScale(t) {
|
|
5
|
+
let n = e(t, 0, 1);
|
|
6
|
+
return n <= .5 ? .5 + n : 1 + (n - .5) * .5;
|
|
7
|
+
}
|
|
8
|
+
function strokeWidths(s, c) {
|
|
9
|
+
let l = i(s, 1), u = n(c.width, "width"), d = r(c.thinning ?? .5, "thinning", 0, 1), f = n(c.referenceSpeed ?? .5, "referenceSpeed"), p = l.every((e) => e.time !== void 0), m = [], h = 1;
|
|
10
|
+
for (let n = 0; n < l.length; n++) {
|
|
11
|
+
if (p && d > 0) {
|
|
12
|
+
let r = l[n], i = l[n + 1], s = n > 0 ? l[n - 1] : r, c = n > 0 ? r : i;
|
|
13
|
+
if (c) {
|
|
14
|
+
let n = Math.abs(c.time - s.time);
|
|
15
|
+
if (n > 0) {
|
|
16
|
+
let r = t(s.x, s.y, c.x, c.y) / n;
|
|
17
|
+
h = e((f / r) ** d, a, o);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let r = l[n].pressure;
|
|
22
|
+
m.push(u * h * (r === void 0 ? 1 : pressureScale(r)));
|
|
23
|
+
}
|
|
24
|
+
return m;
|
|
25
|
+
}
|
|
26
|
+
export { strokeWidths };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=widths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widths.js","names":["MIN_SCALE","MAX_SCALE","p","clamp","pressure","input","requireStrokePoints","points","width","requirePositive","options","thinning","requireRange","referenceSpeed","timed","point","widths","lastScale","i","next","from","to","dt","speed","distance"],"sources":["../src/widths.ts"],"sourcesContent":["/** 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":";;AAeA,IAAMA,IAAY,KACZC,IAAY;AAOlB,SAAS,cAAc,GAA0B;CAC/C,IAAMC,IAAIC,EAAMC,GAAU,GAAG,CAAC;CAC9B,OAAOF,KAAK,KAAM,KAAMA,IAAI,KAAKA,IAAI,MAAO;AAC9C;AAgBA,SAAgB,aAAa,GAAgC,GAAuC;CAClG,IAAMG,IAAQC,EAAoBC,GAAQ,CAAC,GACrCC,IAAQC,EAAgBC,EAAQ,OAAO,OAAO,GAC9CC,IAAWC,EAAaF,EAAQ,YAAY,IAAK,YAAY,GAAG,CAAC,GACjEG,IAAiBJ,EAAgBC,EAAQ,kBAAkB,IAAK,gBAAgB,GAGhFI,IAAQT,EAAM,OAAO,MAAUU,EAAM,SAAS,KAAA,CAAS,GAEvDC,IAAmB,CAAC,GACtBC,IAAY;CAChB,KAAK,IAAIC,IAAI,GAAGA,IAAIb,EAAM,QAAQ,KAAK;EACrC,IAAIS,KAASH,IAAW,GAAG;GACzB,IAAMI,IAAQV,EAAMa,IACdC,IAAOd,EAAMa,IAAI,IAEjBE,IAAOF,IAAI,IAAIb,EAAMa,IAAI,KAAKH,GAC9BM,IAAKH,IAAI,IAAIH,IAAQI;GAC3B,IAAIE,GAAI;IACN,IAAMC,IAAK,KAAK,IAAKD,EAAG,OAAmBD,EAAK,IAAe;IAC/D,IAAIE,IAAK,GAAG;KACV,IAAMC,IAAQC,EAASJ,EAAK,GAAGA,EAAK,GAAGC,EAAG,GAAGA,EAAG,CAAC,IAAIC;KAErD,IAAYnB,GAAOU,IAAiBU,MAAUZ,GAAUX,GAAWC,CAAS;IAC9E;GACF;EACF;EACA,IAAMG,IAAWC,EAAMa,EAAE,CAAC;EAC1B,EAAO,KAAKV,IAAQS,KAAab,MAAa,KAAA,IAAY,IAAI,cAAcA,CAAQ,EAAE;CACxF;CACA,OAAOY;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/ink",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "26.11.23",
|
|
4
|
+
"description": "Causal stroke stabilization, smoothing, speed-based width profiling, and SVG path output",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/helmuthdu/vielzeug",
|
|
8
|
+
"directory": "packages/ink"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"registry": "https://registry.npmjs.org/"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vite build && bun run --silent build:bundle && bun run --silent build:types && bun run --silent test:types && bun run --silent verify:exports",
|
|
35
|
+
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
36
|
+
"build:types": "tsc -p tsconfig.declarations.json",
|
|
37
|
+
"test:types": "tsc -p tsconfig.type-tests.json",
|
|
38
|
+
"verify:exports": "node verify-exports.mjs",
|
|
39
|
+
"fix": "biome check --write src",
|
|
40
|
+
"lint": "biome ci src",
|
|
41
|
+
"prepublishOnly": "bun run --silent build",
|
|
42
|
+
"test": "vitest"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^26.6.6",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"vite": "^8.3.6",
|
|
48
|
+
"vitest": "^5.1.0"
|
|
49
|
+
}
|
|
50
|
+
}
|