@vielzeug/stage 0.0.0-stage → 26.11.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -2
  3. package/dist/_dev.cjs +2 -0
  4. package/dist/_dev.cjs.map +1 -0
  5. package/dist/_dev.d.ts +2 -0
  6. package/dist/_dev.d.ts.map +1 -0
  7. package/dist/_dev.js +5 -0
  8. package/dist/_dev.js.map +1 -0
  9. package/dist/_validate.cjs +2 -0
  10. package/dist/_validate.cjs.map +1 -0
  11. package/dist/_validate.d.ts +3 -0
  12. package/dist/_validate.d.ts.map +1 -0
  13. package/dist/_validate.js +20 -0
  14. package/dist/_validate.js.map +1 -0
  15. package/dist/errors.cjs +2 -0
  16. package/dist/errors.cjs.map +1 -0
  17. package/dist/errors.d.ts +12 -0
  18. package/dist/errors.d.ts.map +1 -0
  19. package/dist/errors.js +9 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.cjs +1 -0
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +3 -0
  25. package/dist/stage.cjs +2 -0
  26. package/dist/stage.cjs.map +1 -0
  27. package/dist/stage.d.ts +101 -0
  28. package/dist/stage.d.ts.map +1 -0
  29. package/dist/stage.iife.js +2 -0
  30. package/dist/stage.iife.js.map +1 -0
  31. package/dist/stage.js +256 -0
  32. package/dist/stage.js.map +1 -0
  33. package/dist/worker/index.cjs +1 -0
  34. package/dist/worker/index.d.ts +3 -0
  35. package/dist/worker/index.d.ts.map +1 -0
  36. package/dist/worker/index.js +3 -0
  37. package/dist/worker/main.cjs +2 -0
  38. package/dist/worker/main.cjs.map +1 -0
  39. package/dist/worker/main.d.ts +45 -0
  40. package/dist/worker/main.d.ts.map +1 -0
  41. package/dist/worker/main.js +114 -0
  42. package/dist/worker/main.js.map +1 -0
  43. package/dist/worker/protocol.d.ts +65 -0
  44. package/dist/worker/protocol.d.ts.map +1 -0
  45. package/dist/worker/serve.cjs +2 -0
  46. package/dist/worker/serve.cjs.map +1 -0
  47. package/dist/worker/serve.d.ts +38 -0
  48. package/dist/worker/serve.d.ts.map +1 -0
  49. package/dist/worker/serve.js +99 -0
  50. package/dist/worker/serve.js.map +1 -0
  51. package/package.json +63 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.cjs","names":["StageUnsupportedError","createStage","StageDisposedError","require_errors","require_stage","stage","current","disposed","scope","error","message","setup","kind","event"],"sources":["../../src/worker/serve.ts"],"sourcesContent":["import { warn } from '../_dev.js';\nimport { StageDisposedError, StageUnsupportedError } from '../errors.js';\nimport type { Stage, StageLayerOptions } from '../stage.js';\nimport { createStage } from '../stage.js';\nimport type { StageWorkerCommand, StageWorkerErrorKind, StageWorkerInit } from './protocol.js';\nimport { STAGE_WORKER_PROTOCOL } from './protocol.js';\n\n/** The message scope available inside a worker (`self` in production). */\nexport type WorkerSelfScope = Readonly<{\n postMessage: (message: unknown) => void;\n addEventListener: (type: 'message', listener: (event: { data: unknown }) => void) => void;\n removeEventListener?: (type: 'message', listener: (event: { data: unknown }) => void) => void;\n}>;\n\nexport type ServeStageSetup<Scene = unknown> = Readonly<{\n /** Layer painters; the worker owns them, the main thread never names layers. */\n layers: readonly StageLayerOptions[];\n /**\n * Called for each `scene` command forwarded from the main thread. The\n * handler owns repaints: call `stage.invalidate(layerId)` for the layers\n * the payload actually changed.\n */\n onScene?: ((scene: Scene, stage: Stage) => void) | undefined;\n /** Called on dispose; release anything the setup or `onScene` allocated. */\n onDispose?: (() => void) | undefined;\n}>;\n\nexport type StageServer = Readonly<{\n readonly stage: Stage | undefined;\n dispose: () => void;\n [Symbol.dispose]: () => void;\n}>;\n\n/**\n * Worker half of a worker-rendered stage: waits for the `init` message,\n * creates a `createStage` bound to the transferred `OffscreenCanvas`, and\n * services resize/transform/invalidate/scene/blob commands. Painters are\n * registered worker-side in `setup`; the main thread only names the layers.\n * `Scene` is the application payload type handled by `onScene`.\n */\nexport function serveStage<Scene = unknown>(\n scope: WorkerSelfScope,\n setup: (init: StageWorkerInit) => ServeStageSetup<Scene>,\n): StageServer {\n let stage: Stage | undefined;\n let current: ServeStageSetup<Scene> | undefined;\n let disposed = false;\n\n const fail = (error: unknown): void => {\n scope.postMessage({ error: String(error), type: 'error' });\n };\n\n const handle = (message: StageWorkerCommand | StageWorkerInit): void => {\n // After dispose the scope may still deliver queued messages (a scope\n // without removeEventListener cannot be fully detached).\n if (disposed) return;\n switch (message.type) {\n case 'init': {\n if (stage) {\n warn('Ignoring a second init message; the canvas was already transferred.');\n return;\n }\n if (message.protocol !== STAGE_WORKER_PROTOCOL) {\n fail(\n new StageUnsupportedError(\n `Main thread protocol ${String(message.protocol)} does not match ${STAGE_WORKER_PROTOCOL}.`,\n ),\n );\n return;\n }\n current = setup(message);\n stage = createStage(message.canvas, {\n background: message.background,\n dpr: message.dpr,\n height: message.height,\n layers: current.layers,\n width: message.width,\n });\n scope.postMessage({ protocol: STAGE_WORKER_PROTOCOL, type: 'ready' });\n return;\n }\n case 'resize': {\n stage?.resize({ height: message.height, width: message.width }, message.dpr);\n return;\n }\n case 'matrix': {\n stage?.setTransform(message.matrix);\n return;\n }\n case 'invalidate': {\n stage?.invalidate(message.layerId);\n return;\n }\n case 'scene': {\n if (stage) current?.onScene?.(message.scene as Scene, stage);\n return;\n }\n case 'blob': {\n if (!stage) {\n scope.postMessage({\n error: 'Stage is not initialized.',\n id: message.id,\n kind: 'failed',\n ok: false,\n type: 'blob',\n });\n return;\n }\n stage.render();\n void stage\n .toBlob(message.options)\n .then((blob) => {\n scope.postMessage({ blob, id: message.id, ok: true, type: 'blob' });\n })\n .catch((error: unknown) => {\n const kind: StageWorkerErrorKind =\n error instanceof StageDisposedError\n ? 'disposed'\n : error instanceof StageUnsupportedError\n ? 'unsupported'\n : 'failed';\n scope.postMessage({ error: String(error), id: message.id, kind, ok: false, type: 'blob' });\n });\n return;\n }\n case 'dispose': {\n shutdown();\n return;\n }\n default: {\n warn(`Ignoring unknown command \"${String((message as { type?: unknown }).type)}\" from main thread.`);\n }\n }\n };\n\n const onMessage = (event: { data: unknown }): void => {\n const message = event.data as (StageWorkerCommand | StageWorkerInit) & { type?: unknown };\n if (!message || typeof message !== 'object' || typeof message.type !== 'string') {\n warn('Ignoring unrecognized message from main thread.');\n return;\n }\n try {\n handle(message);\n } catch (error) {\n fail(error);\n }\n };\n\n const shutdown = (): void => {\n if (disposed) return;\n disposed = true;\n scope.removeEventListener?.('message', onMessage);\n stage?.dispose();\n stage = undefined;\n current?.onDispose?.();\n current = undefined;\n };\n\n scope.addEventListener('message', onMessage);\n\n return {\n dispose: shutdown,\n get stage() {\n return stage;\n },\n [Symbol.dispose]: shutdown,\n };\n}\n"],"mappings":"A,kFAwCA,SAAgB,WACd,EACA,EACa,CACb,IAAIK,EACAC,EACAC,EAAW,GAET,KAAQ,GAAyB,CACrCC,EAAM,YAAY,CAAE,MAAO,OAAOC,CAAK,EAAG,KAAM,OAAQ,CAAC,CAC3D,EAEM,OAAU,GAAwD,CAGtE,GAAI,GACJ,OAAQC,EAAQ,KAAhB,CACE,IAAK,OACH,GAAIL,EAEF,OAEF,GAAIK,EAAQ,WAAA,EAAoC,CAC9C,KACE,IAAIV,EAAAA,sBACF,wBAAwB,OAAOU,EAAQ,QAAQ,EAAE,mBACnD,CACF,EACA,MACF,CACA,EAAUC,EAAMD,CAAO,EACvB,EAAQT,EAAAA,YAAYS,EAAQ,OAAQ,CAClC,WAAYA,EAAQ,WACpB,IAAKA,EAAQ,IACb,OAAQA,EAAQ,OAChB,OAAQJ,EAAQ,OAChB,MAAOI,EAAQ,KACjB,CAAC,EACDF,EAAM,YAAY,CAAE,SAAA,EAAiC,KAAM,OAAQ,CAAC,EACpE,OAEF,IAAK,SACHH,GAAO,OAAO,CAAE,OAAQK,EAAQ,OAAQ,MAAOA,EAAQ,KAAM,EAAGA,EAAQ,GAAG,EAC3E,OAEF,IAAK,SACHL,G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
1
+ import type { Stage, StageLayerOptions } from '../stage.js';
2
+ import type { StageWorkerInit } from './protocol.js';
3
+ /** The message scope available inside a worker (`self` in production). */
4
+ export type WorkerSelfScope = Readonly<{
5
+ postMessage: (message: unknown) => void;
6
+ addEventListener: (type: 'message', listener: (event: {
7
+ data: unknown;
8
+ }) => void) => void;
9
+ removeEventListener?: (type: 'message', listener: (event: {
10
+ data: unknown;
11
+ }) => void) => void;
12
+ }>;
13
+ export type ServeStageSetup<Scene = unknown> = Readonly<{
14
+ /** Layer painters; the worker owns them, the main thread never names layers. */
15
+ layers: readonly StageLayerOptions[];
16
+ /**
17
+ * Called for each `scene` command forwarded from the main thread. The
18
+ * handler owns repaints: call `stage.invalidate(layerId)` for the layers
19
+ * the payload actually changed.
20
+ */
21
+ onScene?: ((scene: Scene, stage: Stage) => void) | undefined;
22
+ /** Called on dispose; release anything the setup or `onScene` allocated. */
23
+ onDispose?: (() => void) | undefined;
24
+ }>;
25
+ export type StageServer = Readonly<{
26
+ readonly stage: Stage | undefined;
27
+ dispose: () => void;
28
+ [Symbol.dispose]: () => void;
29
+ }>;
30
+ /**
31
+ * Worker half of a worker-rendered stage: waits for the `init` message,
32
+ * creates a `createStage` bound to the transferred `OffscreenCanvas`, and
33
+ * services resize/transform/invalidate/scene/blob commands. Painters are
34
+ * registered worker-side in `setup`; the main thread only names the layers.
35
+ * `Scene` is the application payload type handled by `onScene`.
36
+ */
37
+ export declare function serveStage<Scene = unknown>(scope: WorkerSelfScope, setup: (init: StageWorkerInit) => ServeStageSetup<Scene>): StageServer;
38
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/worker/serve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,KAAK,EAA4C,eAAe,EAAE,MAAM,eAAe,CAAC;AAG/F,0EAA0E;AAC1E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supportedError as t } from "../errors.js";
3
+ import { createStage as n } from "../stage.js";
4
+ // src/worker/serve.ts
5
+ function serveStage(r, i) {
6
+ let a, o, s = !1, fail = (e) => {
7
+ r.postMessage({
8
+ error: String(e),
9
+ type: "error"
10
+ });
11
+ }, handle = (c) => {
12
+ if (!s) switch (c.type) {
13
+ case "init":
14
+ if (a) return;
15
+ if (c.protocol !== 2) {
16
+ fail(new t(`Main thread protocol ${String(c.protocol)} does not match 2.`));
17
+ return;
18
+ }
19
+ o = i(c), a = n(c.canvas, {
20
+ background: c.background,
21
+ dpr: c.dpr,
22
+ height: c.height,
23
+ layers: o.layers,
24
+ width: c.width
25
+ }), r.postMessage({
26
+ protocol: 2,
27
+ type: "ready"
28
+ });
29
+ return;
30
+ case "resize":
31
+ a?.resize({
32
+ height: c.height,
33
+ width: c.width
34
+ }, c.dpr);
35
+ return;
36
+ case "matrix":
37
+ a?.setTransform(c.matrix);
38
+ return;
39
+ case "invalidate":
40
+ a?.invalidate(c.layerId);
41
+ return;
42
+ case "scene":
43
+ a && o?.onScene?.(c.scene, a);
44
+ return;
45
+ case "blob":
46
+ if (!a) {
47
+ r.postMessage({
48
+ error: "Stage is not initialized.",
49
+ id: c.id,
50
+ kind: "failed",
51
+ ok: !1,
52
+ type: "blob"
53
+ });
54
+ return;
55
+ }
56
+ a.render(), a.toBlob(c.options).then((e) => {
57
+ r.postMessage({
58
+ blob: e,
59
+ id: c.id,
60
+ ok: !0,
61
+ type: "blob"
62
+ });
63
+ }).catch((n) => {
64
+ let i = n instanceof e ? "disposed" : n instanceof t ? "unsupported" : "failed";
65
+ r.postMessage({
66
+ error: String(n),
67
+ id: c.id,
68
+ kind: i,
69
+ ok: !1,
70
+ type: "blob"
71
+ });
72
+ });
73
+ return;
74
+ case "dispose":
75
+ shutdown();
76
+ return;
77
+ default: `${String(c.type)}`;
78
+ }
79
+ }, onMessage = (e) => {
80
+ let t = e.data;
81
+ if (t && typeof t == "object" && typeof t.type == "string") try {
82
+ handle(t);
83
+ } catch (e) {
84
+ fail(e);
85
+ }
86
+ }, shutdown = () => {
87
+ s || (s = !0, r.removeEventListener?.("message", onMessage), a?.dispose(), a = void 0, o?.onDispose?.(), o = void 0);
88
+ };
89
+ return r.addEventListener("message", onMessage), {
90
+ dispose: shutdown,
91
+ get stage() {
92
+ return a;
93
+ },
94
+ [Symbol.dispose]: shutdown
95
+ };
96
+ }
97
+ export { serveStage };
98
+
99
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","names":["stage","current","disposed","error","message","StageUnsupportedError","setup","createStage","scope","kind","StageDisposedError","event"],"sources":["../../src/worker/serve.ts"],"sourcesContent":["import { warn } from '../_dev.js';\nimport { StageDisposedError, StageUnsupportedError } from '../errors.js';\nimport type { Stage, StageLayerOptions } from '../stage.js';\nimport { createStage } from '../stage.js';\nimport type { StageWorkerCommand, StageWorkerErrorKind, StageWorkerInit } from './protocol.js';\nimport { STAGE_WORKER_PROTOCOL } from './protocol.js';\n\n/** The message scope available inside a worker (`self` in production). */\nexport type WorkerSelfScope = Readonly<{\n postMessage: (message: unknown) => void;\n addEventListener: (type: 'message', listener: (event: { data: unknown }) => void) => void;\n removeEventListener?: (type: 'message', listener: (event: { data: unknown }) => void) => void;\n}>;\n\nexport type ServeStageSetup<Scene = unknown> = Readonly<{\n /** Layer painters; the worker owns them, the main thread never names layers. */\n layers: readonly StageLayerOptions[];\n /**\n * Called for each `scene` command forwarded from the main thread. The\n * handler owns repaints: call `stage.invalidate(layerId)` for the layers\n * the payload actually changed.\n */\n onScene?: ((scene: Scene, stage: Stage) => void) | undefined;\n /** Called on dispose; release anything the setup or `onScene` allocated. */\n onDispose?: (() => void) | undefined;\n}>;\n\nexport type StageServer = Readonly<{\n readonly stage: Stage | undefined;\n dispose: () => void;\n [Symbol.dispose]: () => void;\n}>;\n\n/**\n * Worker half of a worker-rendered stage: waits for the `init` message,\n * creates a `createStage` bound to the transferred `OffscreenCanvas`, and\n * services resize/transform/invalidate/scene/blob commands. Painters are\n * registered worker-side in `setup`; the main thread only names the layers.\n * `Scene` is the application payload type handled by `onScene`.\n */\nexport function serveStage<Scene = unknown>(\n scope: WorkerSelfScope,\n setup: (init: StageWorkerInit) => ServeStageSetup<Scene>,\n): StageServer {\n let stage: Stage | undefined;\n let current: ServeStageSetup<Scene> | undefined;\n let disposed = false;\n\n const fail = (error: unknown): void => {\n scope.postMessage({ error: String(error), type: 'error' });\n };\n\n const handle = (message: StageWorkerCommand | StageWorkerInit): void => {\n // After dispose the scope may still deliver queued messages (a scope\n // without removeEventListener cannot be fully detached).\n if (disposed) return;\n switch (message.type) {\n case 'init': {\n if (stage) {\n warn('Ignoring a second init message; the canvas was already transferred.');\n return;\n }\n if (message.protocol !== STAGE_WORKER_PROTOCOL) {\n fail(\n new StageUnsupportedError(\n `Main thread protocol ${String(message.protocol)} does not match ${STAGE_WORKER_PROTOCOL}.`,\n ),\n );\n return;\n }\n current = setup(message);\n stage = createStage(message.canvas, {\n background: message.background,\n dpr: message.dpr,\n height: message.height,\n layers: current.layers,\n width: message.width,\n });\n scope.postMessage({ protocol: STAGE_WORKER_PROTOCOL, type: 'ready' });\n return;\n }\n case 'resize': {\n stage?.resize({ height: message.height, width: message.width }, message.dpr);\n return;\n }\n case 'matrix': {\n stage?.setTransform(message.matrix);\n return;\n }\n case 'invalidate': {\n stage?.invalidate(message.layerId);\n return;\n }\n case 'scene': {\n if (stage) current?.onScene?.(message.scene as Scene, stage);\n return;\n }\n case 'blob': {\n if (!stage) {\n scope.postMessage({\n error: 'Stage is not initialized.',\n id: message.id,\n kind: 'failed',\n ok: false,\n type: 'blob',\n });\n return;\n }\n stage.render();\n void stage\n .toBlob(message.options)\n .then((blob) => {\n scope.postMessage({ blob, id: message.id, ok: true, type: 'blob' });\n })\n .catch((error: unknown) => {\n const kind: StageWorkerErrorKind =\n error instanceof StageDisposedError\n ? 'disposed'\n : error instanceof StageUnsupportedError\n ? 'unsupported'\n : 'failed';\n scope.postMessage({ error: String(error), id: message.id, kind, ok: false, type: 'blob' });\n });\n return;\n }\n case 'dispose': {\n shutdown();\n return;\n }\n default: {\n warn(`Ignoring unknown command \"${String((message as { type?: unknown }).type)}\" from main thread.`);\n }\n }\n };\n\n const onMessage = (event: { data: unknown }): void => {\n const message = event.data as (StageWorkerCommand | StageWorkerInit) & { type?: unknown };\n if (!message || typeof message !== 'object' || typeof message.type !== 'string') {\n warn('Ignoring unrecognized message from main thread.');\n return;\n }\n try {\n handle(message);\n } catch (error) {\n fail(error);\n }\n };\n\n const shutdown = (): void => {\n if (disposed) return;\n disposed = true;\n scope.removeEventListener?.('message', onMessage);\n stage?.dispose();\n stage = undefined;\n current?.onDispose?.();\n current = undefined;\n };\n\n scope.addEventListener('message', onMessage);\n\n return {\n dispose: shutdown,\n get stage() {\n return stage;\n },\n [Symbol.dispose]: shutdown,\n };\n}\n"],"mappings":";;;;AAwCA,SAAgB,WACd,GACA,GACa;CACb,IAAIA,GACAC,GACAC,IAAW,IAET,QAAQ,MAAyB;EACrC,EAAM,YAAY;GAAE,OAAO,OAAOC,CAAK;GAAG,MAAM;EAAQ,CAAC;CAC3D,GAEM,UAAU,MAAwD;EAGtE,IAAI,IACJ,QAAQC,EAAQ,MAAhB;GACE,KAAK;IACH,IAAIJ,GAEF;IAEF,IAAII,EAAQ,aAAA,GAAoC;KAC9C,KACE,IAAIC,EACF,wBAAwB,OAAOD,EAAQ,QAAQ,EAAE,mBACnD,CACF;KACA;IACF;IASA,AARA,IAAUE,EAAMF,CAAO,GACvB,IAAQG,EAAYH,EAAQ,QAAQ;KAClC,YAAYA,EAAQ;KACpB,KAAKA,EAAQ;KACb,QAAQA,EAAQ;KAChB,QAAQH,EAAQ;KAChB,OAAOG,EAAQ;IACjB,CAAC,GACDI,EAAM,YAAY;KAAE,UAAA;KAAiC,MAAM;IAAQ,CAAC;IACpE;GAEF,KAAK;IACH,GAAO,OAAO;KAAE,QAAQJ,EAAQ;KAAQ,OAAOA,EAAQ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OR;EACT;GACC,OAAO,UAAU;CACpB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@vielzeug/stage",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "26.11.24",
4
+ "description": "Retained-mode 2D canvas stage engine with DPR-aware layers, dirty repaints, and PNG export",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/helmuthdu/vielzeug",
8
+ "directory": "packages/stage"
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
+ "./worker": {
28
+ "import": "./dist/worker/index.js",
29
+ "require": "./dist/worker/index.cjs",
30
+ "types": "./dist/worker/index.d.ts"
31
+ }
32
+ },
33
+ "typesVersions": {
34
+ "*": {
35
+ "worker": [
36
+ "dist/worker/index.d.ts"
37
+ ]
38
+ }
39
+ },
40
+ "sideEffects": false,
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org/"
44
+ },
45
+ "scripts": {
46
+ "build": "vite build && bun run --silent build:bundle && bun run --silent build:types && bun run --silent test:types && bun run --silent verify:exports",
47
+ "build:bundle": "vite build --config vite.bundle.config.ts",
48
+ "build:types": "tsc -p tsconfig.declarations.json",
49
+ "fix": "biome check --write src",
50
+ "lint": "biome ci src",
51
+ "prepublishOnly": "bun run --silent build",
52
+ "test": "vitest",
53
+ "test:types": "tsc -p tsconfig.type-tests.json",
54
+ "verify:exports": "bun verify-exports.mjs"
55
+ },
56
+ "dependencies": {
57
+ "@vielzeug/atlas": "26.11.24"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^26.6.6",
61
+ "typescript": "^6.0.3",
62
+ "vite": "^8.3.6",
63
+ "vitest": "^5.1.0"
64
+ }
65
+ }