@edv4h/usketch-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/dist/command-registry.d.ts +3 -0
  3. package/dist/command-registry.d.ts.map +1 -0
  4. package/dist/command-registry.js +43 -0
  5. package/dist/command-registry.js.map +1 -0
  6. package/dist/create-app.d.ts +29 -0
  7. package/dist/create-app.d.ts.map +1 -0
  8. package/dist/create-app.js +78 -0
  9. package/dist/create-app.js.map +1 -0
  10. package/dist/event-bus.d.ts +3 -0
  11. package/dist/event-bus.d.ts.map +1 -0
  12. package/dist/event-bus.js +25 -0
  13. package/dist/event-bus.js.map +1 -0
  14. package/dist/index.d.ts +13 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +11 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/layer-manager.d.ts +3 -0
  19. package/dist/layer-manager.d.ts.map +1 -0
  20. package/dist/layer-manager.js +21 -0
  21. package/dist/layer-manager.js.map +1 -0
  22. package/dist/lod/index.d.ts +4 -0
  23. package/dist/lod/index.d.ts.map +1 -0
  24. package/dist/lod/index.js +3 -0
  25. package/dist/lod/index.js.map +1 -0
  26. package/dist/lod/lod-controller.d.ts +20 -0
  27. package/dist/lod/lod-controller.d.ts.map +1 -0
  28. package/dist/lod/lod-controller.js +51 -0
  29. package/dist/lod/lod-controller.js.map +1 -0
  30. package/dist/lod/policies.d.ts +31 -0
  31. package/dist/lod/policies.d.ts.map +1 -0
  32. package/dist/lod/policies.js +74 -0
  33. package/dist/lod/policies.js.map +1 -0
  34. package/dist/plugin-registry.d.ts +7 -0
  35. package/dist/plugin-registry.d.ts.map +1 -0
  36. package/dist/plugin-registry.js +15 -0
  37. package/dist/plugin-registry.js.map +1 -0
  38. package/dist/shape-registry.d.ts +3 -0
  39. package/dist/shape-registry.d.ts.map +1 -0
  40. package/dist/shape-registry.js +15 -0
  41. package/dist/shape-registry.js.map +1 -0
  42. package/dist/shortcut-registry.d.ts +3 -0
  43. package/dist/shortcut-registry.d.ts.map +1 -0
  44. package/dist/shortcut-registry.js +45 -0
  45. package/dist/shortcut-registry.js.map +1 -0
  46. package/dist/tool-registry.d.ts +3 -0
  47. package/dist/tool-registry.d.ts.map +1 -0
  48. package/dist/tool-registry.js +20 -0
  49. package/dist/tool-registry.js.map +1 -0
  50. package/dist/transient-registry.d.ts +3 -0
  51. package/dist/transient-registry.d.ts.map +1 -0
  52. package/dist/transient-registry.js +58 -0
  53. package/dist/transient-registry.js.map +1 -0
  54. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 EdV4H
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import type { CommandRegistry } from "@edv4h/usketch-shared";
2
+ export declare function createCommandRegistry(): CommandRegistry;
3
+ //# sourceMappingURL=command-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-registry.d.ts","sourceRoot":"","sources":["../src/command-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAItE,wBAAgB,qBAAqB,IAAI,eAAe,CA6CvD"}
@@ -0,0 +1,43 @@
1
+ const MAX_HISTORY = 100;
2
+ export function createCommandRegistry() {
3
+ const history = [];
4
+ let cursor = -1;
5
+ return {
6
+ execute(command) {
7
+ // Discard redo history beyond cursor
8
+ history.length = cursor + 1;
9
+ command.execute();
10
+ history.push(command);
11
+ cursor++;
12
+ if (history.length > MAX_HISTORY) {
13
+ history.shift();
14
+ cursor--;
15
+ }
16
+ },
17
+ undo() {
18
+ if (cursor < 0)
19
+ return;
20
+ history[cursor].undo();
21
+ cursor--;
22
+ },
23
+ redo() {
24
+ if (cursor >= history.length - 1)
25
+ return;
26
+ cursor++;
27
+ history[cursor].execute();
28
+ },
29
+ canUndo() {
30
+ return cursor >= 0;
31
+ },
32
+ canRedo() {
33
+ return cursor < history.length - 1;
34
+ },
35
+ getHistorySize() {
36
+ return history.length;
37
+ },
38
+ getCursor() {
39
+ return cursor;
40
+ },
41
+ };
42
+ }
43
+ //# sourceMappingURL=command-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-registry.js","sourceRoot":"","sources":["../src/command-registry.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,UAAU,qBAAqB;IACpC,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;IAEhB,OAAO;QACN,OAAO,CAAC,OAAgB;YACvB,qCAAqC;YACrC,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC;YAC5B,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,EAAE,CAAC;YACT,IAAI,OAAO,CAAC,MAAM,GAAG,WAAW,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,MAAM,EAAE,CAAC;YACV,CAAC;QACF,CAAC;QAED,IAAI;YACH,IAAI,MAAM,GAAG,CAAC;gBAAE,OAAO;YACvB,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;YACvB,MAAM,EAAE,CAAC;QACV,CAAC;QAED,IAAI;YACH,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO;YACzC,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QAED,OAAO;YACN,OAAO,MAAM,IAAI,CAAC,CAAC;QACpB,CAAC;QAED,OAAO;YACN,OAAO,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACpC,CAAC;QAED,cAAc;YACb,OAAO,OAAO,CAAC,MAAM,CAAC;QACvB,CAAC;QAED,SAAS;YACR,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { BoardStore, CommandRegistry, EventBus, LayerManager, LodPolicy, RenderMode, ShapeRegistry, ShortcutRegistry, ToolRegistry, TransientRegistry, UsketchPlugin } from "@edv4h/usketch-shared";
2
+ import { type LodControllerInternal } from "./lod/index.js";
3
+ export interface AppInstance {
4
+ store: BoardStore;
5
+ layers: LayerManager;
6
+ tools: ToolRegistry;
7
+ shapes: ShapeRegistry;
8
+ commands: CommandRegistry;
9
+ shortcuts: ShortcutRegistry;
10
+ events: EventBus;
11
+ transient: TransientRegistry;
12
+ lod: LodControllerInternal;
13
+ plugins: readonly UsketchPlugin[];
14
+ destroy(): void;
15
+ }
16
+ export interface CreateAppOptions {
17
+ store: BoardStore;
18
+ plugins: UsketchPlugin[];
19
+ /**
20
+ * Optional LOD configuration. If omitted, a sensible default is used
21
+ * (zoom + shape-count composite policy, starting in `interactive` mode).
22
+ */
23
+ lod?: {
24
+ policy?: LodPolicy;
25
+ initialMode?: RenderMode;
26
+ };
27
+ }
28
+ export declare function createApp(options: CreateAppOptions): Promise<AppInstance>;
29
+ //# sourceMappingURL=create-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,SAAS,EAET,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAKN,KAAK,qBAAqB,EAC1B,MAAM,gBAAgB,CAAC;AAOxB,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,eAAe,CAAC;IAC1B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,GAAG,EAAE,qBAAqB,CAAC;IAC3B,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,OAAO,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,GAAG,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,SAAS,CAAC;QACnB,WAAW,CAAC,EAAE,UAAU,CAAC;KACzB,CAAC;CACF;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CA0E/E"}
@@ -0,0 +1,78 @@
1
+ import { createCommandRegistry } from "./command-registry.js";
2
+ import { createEventBus } from "./event-bus.js";
3
+ import { createLayerManager } from "./layer-manager.js";
4
+ import { createCompositeLodPolicy, createLodController, createShapeCountLodPolicy, createZoomLodPolicy, } from "./lod/index.js";
5
+ import { createPluginRegistry } from "./plugin-registry.js";
6
+ import { createShapeRegistry } from "./shape-registry.js";
7
+ import { createShortcutRegistry } from "./shortcut-registry.js";
8
+ import { createToolRegistry } from "./tool-registry.js";
9
+ import { createTransientRegistry } from "./transient-registry.js";
10
+ export async function createApp(options) {
11
+ const { store, plugins } = options;
12
+ const layers = createLayerManager();
13
+ const tools = createToolRegistry();
14
+ const shapes = createShapeRegistry();
15
+ const commands = createCommandRegistry();
16
+ const shortcuts = createShortcutRegistry();
17
+ const events = createEventBus();
18
+ const transient = createTransientRegistry();
19
+ const pluginRegistry = createPluginRegistry();
20
+ const lodPolicy = options.lod?.policy ??
21
+ createCompositeLodPolicy([
22
+ createZoomLodPolicy({ enterAt: 0.5, exitAt: 0.7 }),
23
+ createShapeCountLodPolicy({ enterAt: 1000, exitAt: 800 }),
24
+ ]);
25
+ const lod = createLodController({
26
+ policy: lodPolicy,
27
+ initialMode: options.lod?.initialMode ?? "interactive",
28
+ });
29
+ const ctx = {
30
+ store,
31
+ layers,
32
+ tools,
33
+ shapes,
34
+ commands,
35
+ shortcuts,
36
+ events,
37
+ transient,
38
+ lod,
39
+ };
40
+ // Bridge store mutations to EventBus
41
+ const unsubMutation = store.onMutation((event) => {
42
+ events.emit(event.type, event.payload);
43
+ });
44
+ // Register and setup plugins
45
+ try {
46
+ for (const plugin of plugins) {
47
+ pluginRegistry.register(plugin);
48
+ await plugin.setup(ctx);
49
+ }
50
+ }
51
+ catch (error) {
52
+ unsubMutation();
53
+ throw error;
54
+ }
55
+ // Register core shortcuts
56
+ shortcuts.register("Ctrl+Z", () => commands.undo());
57
+ shortcuts.register("Ctrl+Shift+Z", () => commands.redo());
58
+ return {
59
+ store,
60
+ layers,
61
+ tools,
62
+ shapes,
63
+ commands,
64
+ shortcuts,
65
+ events,
66
+ transient,
67
+ lod,
68
+ plugins: pluginRegistry.getAll(),
69
+ destroy() {
70
+ for (const plugin of plugins) {
71
+ plugin.teardown?.();
72
+ }
73
+ lod.destroy();
74
+ unsubMutation();
75
+ },
76
+ };
77
+ }
78
+ //# sourceMappingURL=create-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-app.js","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACN,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,GAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AA6BlE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAyB;IACxD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEnC,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,KAAK,GAAG,kBAAkB,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,sBAAsB,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,uBAAu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cAAc,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1D,OAAO;QACN,KAAK;QACL,MAAM;QACN,KAAK;QACL,MAAM;QACN,QAAQ;QACR,SAAS;QACT,MAAM;QACN,SAAS;QACT,GAAG;QACH,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE;QAChC,OAAO;YACN,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrB,CAAC;YACD,GAAG,CAAC,OAAO,EAAE,CAAC;YACd,aAAa,EAAE,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { EventBus } from "@edv4h/usketch-shared";
2
+ export declare function createEventBus(): EventBus;
3
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,wBAAgB,cAAc,IAAI,QAAQ,CAyBzC"}
@@ -0,0 +1,25 @@
1
+ export function createEventBus() {
2
+ const listeners = new Map();
3
+ return {
4
+ on(event, handler) {
5
+ if (!listeners.has(event)) {
6
+ listeners.set(event, new Set());
7
+ }
8
+ // biome-ignore lint/style/noNonNullAssertion: guaranteed by has() check above
9
+ const handlers = listeners.get(event);
10
+ handlers.add(handler);
11
+ return () => {
12
+ handlers.delete(handler);
13
+ };
14
+ },
15
+ emit(event, data) {
16
+ const handlers = listeners.get(event);
17
+ if (handlers) {
18
+ for (const handler of handlers) {
19
+ handler(data);
20
+ }
21
+ }
22
+ },
23
+ };
24
+ }
25
+ //# sourceMappingURL=event-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc;IAC7B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;IAElE,OAAO;QACN,EAAE,CAAc,KAAa,EAAE,OAA0B;YACxD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACjC,CAAC;YACD,8EAA8E;YAC9E,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC;YACvC,QAAQ,CAAC,GAAG,CAAC,OAAkC,CAAC,CAAC;YACjD,OAAO,GAAG,EAAE;gBACX,QAAQ,CAAC,MAAM,CAAC,OAAkC,CAAC,CAAC;YACrD,CAAC,CAAC;QACH,CAAC;QAED,IAAI,CAAc,KAAa,EAAE,IAAO;YACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,QAAQ,EAAE,CAAC;gBACd,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;oBAChC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACf,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ export { createCommandRegistry } from "./command-registry.js";
2
+ export type { AppInstance, CreateAppOptions } from "./create-app.js";
3
+ export { createApp } from "./create-app.js";
4
+ export { createEventBus } from "./event-bus.js";
5
+ export { createLayerManager } from "./layer-manager.js";
6
+ export type { CreateLodControllerOptions, LodControllerInternal } from "./lod/index.js";
7
+ export { createCompositeLodPolicy, createFpsLodPolicy, createLodController, createShapeCountLodPolicy, createZoomLodPolicy, } from "./lod/index.js";
8
+ export { createPluginRegistry } from "./plugin-registry.js";
9
+ export { createShapeRegistry } from "./shape-registry.js";
10
+ export { createShortcutRegistry } from "./shortcut-registry.js";
11
+ export { createToolRegistry } from "./tool-registry.js";
12
+ export { createTransientRegistry } from "./transient-registry.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { createCommandRegistry } from "./command-registry.js";
2
+ export { createApp } from "./create-app.js";
3
+ export { createEventBus } from "./event-bus.js";
4
+ export { createLayerManager } from "./layer-manager.js";
5
+ export { createCompositeLodPolicy, createFpsLodPolicy, createLodController, createShapeCountLodPolicy, createZoomLodPolicy, } from "./lod/index.js";
6
+ export { createPluginRegistry } from "./plugin-registry.js";
7
+ export { createShapeRegistry } from "./shape-registry.js";
8
+ export { createShortcutRegistry } from "./shortcut-registry.js";
9
+ export { createToolRegistry } from "./tool-registry.js";
10
+ export { createTransientRegistry } from "./transient-registry.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { LayerManager } from "@edv4h/usketch-shared";
2
+ export declare function createLayerManager(): LayerManager;
3
+ //# sourceMappingURL=layer-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer-manager.d.ts","sourceRoot":"","sources":["../src/layer-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEjE,wBAAgB,kBAAkB,IAAI,YAAY,CAuBjD"}
@@ -0,0 +1,21 @@
1
+ export function createLayerManager() {
2
+ const layers = new Map();
3
+ let sorted = [];
4
+ function rebuildSorted() {
5
+ sorted = [...layers.values()].sort((a, b) => a.order - b.order);
6
+ }
7
+ return {
8
+ register(layer) {
9
+ layers.set(layer.id, layer);
10
+ rebuildSorted();
11
+ },
12
+ unregister(layerId) {
13
+ layers.delete(layerId);
14
+ rebuildSorted();
15
+ },
16
+ getLayers() {
17
+ return sorted;
18
+ },
19
+ };
20
+ }
21
+ //# sourceMappingURL=layer-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer-manager.js","sourceRoot":"","sources":["../src/layer-manager.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IACjC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IACxC,IAAI,MAAM,GAAqB,EAAE,CAAC;IAElC,SAAS,aAAa;QACrB,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;IAED,OAAO;QACN,QAAQ,CAAC,KAAY;YACpB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAC5B,aAAa,EAAE,CAAC;QACjB,CAAC;QAED,UAAU,CAAC,OAAe;YACzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACvB,aAAa,EAAE,CAAC;QACjB,CAAC;QAED,SAAS;YACR,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { CreateLodControllerOptions, LodControllerInternal } from "./lod-controller.js";
2
+ export { createLodController } from "./lod-controller.js";
3
+ export { createCompositeLodPolicy, createFpsLodPolicy, createShapeCountLodPolicy, createZoomLodPolicy, } from "./policies.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lod/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,yBAAyB,EACzB,mBAAmB,GACnB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createLodController } from "./lod-controller.js";
2
+ export { createCompositeLodPolicy, createFpsLodPolicy, createShapeCountLodPolicy, createZoomLodPolicy, } from "./policies.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lod/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,yBAAyB,EACzB,mBAAmB,GACnB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { LodController, LodPolicy, LodPolicyContext, RenderMode } from "@edv4h/usketch-shared";
2
+ export interface LodControllerInternal extends LodController {
3
+ /** Called by the canvas render loop on each frame with the latest context. */
4
+ tick(ctx: LodPolicyContext): void;
5
+ destroy(): void;
6
+ }
7
+ export interface CreateLodControllerOptions {
8
+ policy: LodPolicy;
9
+ initialMode?: RenderMode;
10
+ }
11
+ /**
12
+ * Create a LOD controller. The controller owns the current `RenderMode` and a
13
+ * pluggable `LodPolicy`. Each frame the canvas calls `tick(ctx)` with the
14
+ * latest viewport / shape count / fps; the policy decides the next mode.
15
+ *
16
+ * Listeners registered via `onModeChange` are notified only when the mode
17
+ * actually changes (not every tick).
18
+ */
19
+ export declare function createLodController(opts: CreateLodControllerOptions): LodControllerInternal;
20
+ //# sourceMappingURL=lod-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lod-controller.d.ts","sourceRoot":"","sources":["../../src/lod/lod-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEpG,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC3D,8EAA8E;IAC9E,IAAI,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAClC,OAAO,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IAC1C,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,UAAU,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,0BAA0B,GAAG,qBAAqB,CAwC3F"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Create a LOD controller. The controller owns the current `RenderMode` and a
3
+ * pluggable `LodPolicy`. Each frame the canvas calls `tick(ctx)` with the
4
+ * latest viewport / shape count / fps; the policy decides the next mode.
5
+ *
6
+ * Listeners registered via `onModeChange` are notified only when the mode
7
+ * actually changes (not every tick).
8
+ */
9
+ export function createLodController(opts) {
10
+ let currentMode = opts.initialMode ?? "interactive";
11
+ let policy = opts.policy;
12
+ let manualOverride = null;
13
+ const listeners = new Set();
14
+ function notify(mode) {
15
+ for (const listener of listeners)
16
+ listener(mode);
17
+ }
18
+ function applyMode(next) {
19
+ if (next === currentMode)
20
+ return;
21
+ currentMode = next;
22
+ notify(next);
23
+ }
24
+ return {
25
+ getMode() {
26
+ return currentMode;
27
+ },
28
+ onModeChange(listener) {
29
+ listeners.add(listener);
30
+ return () => listeners.delete(listener);
31
+ },
32
+ setPolicy(next) {
33
+ policy = next;
34
+ },
35
+ setManualOverride(mode) {
36
+ manualOverride = mode;
37
+ if (mode !== null)
38
+ applyMode(mode);
39
+ },
40
+ tick(ctx) {
41
+ if (manualOverride !== null)
42
+ return;
43
+ const next = policy.evaluate({ ...ctx, currentMode });
44
+ applyMode(next);
45
+ },
46
+ destroy() {
47
+ listeners.clear();
48
+ },
49
+ };
50
+ }
51
+ //# sourceMappingURL=lod-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lod-controller.js","sourceRoot":"","sources":["../../src/lod/l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,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { LodPolicy } from "@edv4h/usketch-shared";
2
+ interface HysteresisOptions {
3
+ /** Threshold to enter LOD mode (when current mode is interactive). */
4
+ enterAt?: number;
5
+ /** Threshold to exit LOD mode (when current mode is lod). */
6
+ exitAt?: number;
7
+ }
8
+ /**
9
+ * Switch to `lod` when zoom drops below `enterAt`, switch back to `interactive`
10
+ * when zoom rises above `exitAt`. Defaults: enter at 0.5, exit at 0.7.
11
+ */
12
+ export declare function createZoomLodPolicy(opts?: HysteresisOptions): LodPolicy;
13
+ /**
14
+ * Switch to `lod` when shape count exceeds `enterAt`, back to `interactive`
15
+ * when it drops below `exitAt`. Defaults: enter at 1000, exit at 800.
16
+ */
17
+ export declare function createShapeCountLodPolicy(opts?: HysteresisOptions): LodPolicy;
18
+ /**
19
+ * Switch to `lod` when smoothed FPS drops below `enterAt`, back to
20
+ * `interactive` when it recovers above `exitAt`. FPS is the closest
21
+ * proxy for CPU/GPU load available in the browser. Defaults: 30 / 50.
22
+ */
23
+ export declare function createFpsLodPolicy(opts?: HysteresisOptions): LodPolicy;
24
+ /**
25
+ * Combine multiple policies. If any child policy demands `lod`, the composite
26
+ * returns `lod`. `gpu-only` is preserved if any child returns it (and no child
27
+ * returns `lod`). Otherwise returns `interactive`.
28
+ */
29
+ export declare function createCompositeLodPolicy(policies: readonly LodPolicy[]): LodPolicy;
30
+ export {};
31
+ //# sourceMappingURL=policies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/lod/policies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgC,MAAM,uBAAuB,CAAC;AAErF,UAAU,iBAAiB;IAC1B,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,iBAAsB,GAAG,SAAS,CAY3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,GAAE,iBAAsB,GAAG,SAAS,CAYjF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,iBAAsB,GAAG,SAAS,CAY1E;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAalF"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Switch to `lod` when zoom drops below `enterAt`, switch back to `interactive`
3
+ * when zoom rises above `exitAt`. Defaults: enter at 0.5, exit at 0.7.
4
+ */
5
+ export function createZoomLodPolicy(opts = {}) {
6
+ const enterAt = opts.enterAt ?? 0.5;
7
+ const exitAt = opts.exitAt ?? 0.7;
8
+ return {
9
+ id: "lod-policy:zoom",
10
+ evaluate(ctx) {
11
+ if (ctx.currentMode === "lod") {
12
+ return ctx.viewport.zoom > exitAt ? "interactive" : "lod";
13
+ }
14
+ return ctx.viewport.zoom < enterAt ? "lod" : "interactive";
15
+ },
16
+ };
17
+ }
18
+ /**
19
+ * Switch to `lod` when shape count exceeds `enterAt`, back to `interactive`
20
+ * when it drops below `exitAt`. Defaults: enter at 1000, exit at 800.
21
+ */
22
+ export function createShapeCountLodPolicy(opts = {}) {
23
+ const enterAt = opts.enterAt ?? 1000;
24
+ const exitAt = opts.exitAt ?? 800;
25
+ return {
26
+ id: "lod-policy:shape-count",
27
+ evaluate(ctx) {
28
+ if (ctx.currentMode === "lod") {
29
+ return ctx.shapeCount < exitAt ? "interactive" : "lod";
30
+ }
31
+ return ctx.shapeCount > enterAt ? "lod" : "interactive";
32
+ },
33
+ };
34
+ }
35
+ /**
36
+ * Switch to `lod` when smoothed FPS drops below `enterAt`, back to
37
+ * `interactive` when it recovers above `exitAt`. FPS is the closest
38
+ * proxy for CPU/GPU load available in the browser. Defaults: 30 / 50.
39
+ */
40
+ export function createFpsLodPolicy(opts = {}) {
41
+ const enterAt = opts.enterAt ?? 30;
42
+ const exitAt = opts.exitAt ?? 50;
43
+ return {
44
+ id: "lod-policy:fps",
45
+ evaluate(ctx) {
46
+ if (ctx.currentMode === "lod") {
47
+ return ctx.fps > exitAt ? "interactive" : "lod";
48
+ }
49
+ return ctx.fps < enterAt ? "lod" : "interactive";
50
+ },
51
+ };
52
+ }
53
+ /**
54
+ * Combine multiple policies. If any child policy demands `lod`, the composite
55
+ * returns `lod`. `gpu-only` is preserved if any child returns it (and no child
56
+ * returns `lod`). Otherwise returns `interactive`.
57
+ */
58
+ export function createCompositeLodPolicy(policies) {
59
+ return {
60
+ id: "lod-policy:composite",
61
+ evaluate(ctx) {
62
+ let result = "interactive";
63
+ for (const p of policies) {
64
+ const r = p.evaluate(ctx);
65
+ if (r === "lod")
66
+ return "lod";
67
+ if (r === "gpu-only")
68
+ result = "gpu-only";
69
+ }
70
+ return result;
71
+ },
72
+ };
73
+ }
74
+ //# sourceMappingURL=policies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policies.js","sourceRoot":"","sources":["../../src/lod/policies.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA0B,EAAE;IAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC;IAClC,OAAO;QACN,EAAE,EAAE,iBAAiB;QACrB,QAAQ,CAAC,GAAqB;YAC7B,IAAI,GAAG,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;gBAC/B,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;YAC3D,CAAC;YACD,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAA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AAqB;YAC7B,IAAI,MAAM,GAAe,aAAa,CAAC;YACvC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC1B,IAAI,CAAC,KAAK,KAAK;oBAAE,OAAO,KAAK,CAAC;gBAC9B,IAAI,CAAC,KAAK,UAAU;oBAAE,MAAM,GAAG,UAAU,CAAC;YAC3C,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { UsketchPlugin } from "@edv4h/usketch-shared";
2
+ export declare function createPluginRegistry(): {
3
+ register(plugin: UsketchPlugin): void;
4
+ get(id: string): UsketchPlugin | undefined;
5
+ getAll(): readonly UsketchPlugin[];
6
+ };
7
+ //# sourceMappingURL=plugin-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../src/plugin-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,wBAAgB,oBAAoB;qBAIjB,aAAa,GAAG,IAAI;YAI7B,MAAM,GAAG,aAAa,GAAG,SAAS;cAIhC,SAAS,aAAa,EAAE;EAInC"}
@@ -0,0 +1,15 @@
1
+ export function createPluginRegistry() {
2
+ const plugins = new Map();
3
+ return {
4
+ register(plugin) {
5
+ plugins.set(plugin.id, plugin);
6
+ },
7
+ get(id) {
8
+ return plugins.get(id);
9
+ },
10
+ getAll() {
11
+ return [...plugins.values()];
12
+ },
13
+ };
14
+ }
15
+ //# sourceMappingURL=plugin-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-registry.js","sourceRoot":"","sources":["../src/plugin-registry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB;IACnC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEjD,OAAO;QACN,QAAQ,CAAC,MAAqB;YAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,GAAG,CAAC,EAAU;YACb,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;QAED,MAAM;YACL,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ShapeRegistry } from "@edv4h/usketch-shared";
2
+ export declare function createShapeRegistry(): ShapeRegistry;
3
+ //# sourceMappingURL=shape-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-registry.d.ts","sourceRoot":"","sources":["../src/shape-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE5E,wBAAgB,mBAAmB,IAAI,aAAa,CAgBnD"}
@@ -0,0 +1,15 @@
1
+ export function createShapeRegistry() {
2
+ const definitions = new Map();
3
+ return {
4
+ register(type, definition) {
5
+ definitions.set(type, definition);
6
+ },
7
+ get(type) {
8
+ return definitions.get(type);
9
+ },
10
+ getAll() {
11
+ return definitions;
12
+ },
13
+ };
14
+ }
15
+ //# sourceMappingURL=shape-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-registry.js","sourceRoot":"","sources":["../src/shape-registry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,mBAAmB;IAClC,MAAM,WAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEvD,OAAO;QACN,QAAQ,CAAC,IAAY,EAAE,UAA2B;YACjD,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACnC,CAAC;QAED,GAAG,CAAC,IAAY;YACf,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,MAAM;YACL,OAAO,WAAW,CAAC;QACpB,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ShortcutRegistry } from "@edv4h/usketch-shared";
2
+ export declare function createShortcutRegistry(): ShortcutRegistry;
3
+ //# sourceMappingURL=shortcut-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcut-registry.d.ts","sourceRoot":"","sources":["../src/shortcut-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAyB9D,wBAAgB,sBAAsB,IAAI,gBAAgB,CAuBzD"}
@@ -0,0 +1,45 @@
1
+ function normalizeCombo(combo) {
2
+ return combo
3
+ .toLowerCase()
4
+ .split("+")
5
+ .map((k) => k.trim())
6
+ .sort()
7
+ .join("+");
8
+ }
9
+ function eventToCombo(event) {
10
+ const parts = [];
11
+ if (event.ctrlKey || event.metaKey)
12
+ parts.push("ctrl");
13
+ if (event.shiftKey)
14
+ parts.push("shift");
15
+ if (event.altKey)
16
+ parts.push("alt");
17
+ const key = event.key.toLowerCase();
18
+ if (!["control", "meta", "shift", "alt"].includes(key)) {
19
+ parts.push(key);
20
+ }
21
+ return parts.sort().join("+");
22
+ }
23
+ export function createShortcutRegistry() {
24
+ const shortcuts = new Map();
25
+ return {
26
+ register(combo, callback) {
27
+ const normalized = normalizeCombo(combo);
28
+ shortcuts.set(normalized, callback);
29
+ return () => {
30
+ shortcuts.delete(normalized);
31
+ };
32
+ },
33
+ handleKeyDown(event) {
34
+ const combo = eventToCombo(event);
35
+ const callback = shortcuts.get(combo);
36
+ if (callback) {
37
+ event.preventDefault();
38
+ callback();
39
+ return true;
40
+ }
41
+ return false;
42
+ },
43
+ };
44
+ }
45
+ //# sourceMappingURL=shortcut-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcut-registry.js","sourceRoot":"","sources":["../src/shortcut-registry.ts"],"names":[],"mappings":"AAEA,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aAAa,CAAC,KAAoB;YACjC,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAClC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,QAAQ,EAAE,CAAC;gBACd,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,QAAQ,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC;YACb,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ToolRegistry } from "@edv4h/usketch-shared";
2
+ export declare function createToolRegistry(): ToolRegistry;
3
+ //# sourceMappingURL=tool-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../src/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1E,wBAAgB,kBAAkB,IAAI,YAAY,CAsBjD"}
@@ -0,0 +1,20 @@
1
+ export function createToolRegistry() {
2
+ const tools = new Map();
3
+ return {
4
+ register(id, definition) {
5
+ tools.set(id, definition);
6
+ },
7
+ get(id) {
8
+ return tools.get(id);
9
+ },
10
+ getAll() {
11
+ return tools;
12
+ },
13
+ getOrdered() {
14
+ return [...tools.entries()]
15
+ .map(([id, definition]) => ({ id, definition }))
16
+ .sort((a, b) => (a.definition.order ?? 0) - (b.definition.order ?? 0));
17
+ },
18
+ };
19
+ }
20
+ //# sourceMappingURL=tool-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-registry.js","sourceRoot":"","sources":["../src/tool-registry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IACjC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEhD,OAAO;QACN,QAAQ,CAAC,EAAU,EAAE,UAA0B;YAC9C,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;QAC3B,CAAC;QAED,GAAG,CAAC,EAAU;YACb,OAAO,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC;QAED,MAAM;YACL,OAAO,KAAK,CAAC;QACd,CAAC;QAED,UAAU;YACT,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;iBACzB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;iBAC/C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;QACzE,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { TransientRegistry } from "@edv4h/usketch-shared";
2
+ export declare function createTransientRegistry(): TransientRegistry;
3
+ //# sourceMappingURL=transient-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transient-registry.d.ts","sourceRoot":"","sources":["../src/transient-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,iBAAiB,EAAqB,MAAM,uBAAuB,CAAC;AAEnG,wBAAgB,uBAAuB,IAAI,iBAAiB,CA+D3D"}
@@ -0,0 +1,58 @@
1
+ export function createTransientRegistry() {
2
+ const types = new Map();
3
+ const objects = new Map();
4
+ const timers = new Map();
5
+ const listeners = new Set();
6
+ function notify() {
7
+ for (const listener of listeners) {
8
+ listener();
9
+ }
10
+ }
11
+ function scheduleExpiry(obj) {
12
+ if (obj.ttl != null) {
13
+ const elapsed = Date.now() - obj.createdAt;
14
+ const remaining = Math.max(0, obj.ttl - elapsed);
15
+ const timer = setTimeout(() => {
16
+ objects.delete(obj.id);
17
+ timers.delete(obj.id);
18
+ notify();
19
+ }, remaining);
20
+ timers.set(obj.id, timer);
21
+ }
22
+ }
23
+ return {
24
+ registerType(type, renderer) {
25
+ types.set(type, renderer);
26
+ },
27
+ getRenderer(type) {
28
+ return types.get(type);
29
+ },
30
+ emit(obj) {
31
+ const existing = timers.get(obj.id);
32
+ if (existing)
33
+ clearTimeout(existing);
34
+ objects.set(obj.id, obj);
35
+ scheduleExpiry(obj);
36
+ notify();
37
+ },
38
+ dismiss(id) {
39
+ objects.delete(id);
40
+ const timer = timers.get(id);
41
+ if (timer) {
42
+ clearTimeout(timer);
43
+ timers.delete(id);
44
+ }
45
+ notify();
46
+ },
47
+ getAll() {
48
+ return objects;
49
+ },
50
+ subscribe(listener) {
51
+ listeners.add(listener);
52
+ return () => {
53
+ listeners.delete(listener);
54
+ };
55
+ },
56
+ };
57
+ }
58
+ //# sourceMappingURL=transient-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transient-registry.js","sourceRoot":"","sources":["../src/transient-registry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,uBAAuB;IACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA6B,CAAC;IACnD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IACnD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyC,CAAC;IAChE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAExC,SAAS,MAAM;QACd,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAClC,QAAQ,EAAE,CAAC;QACZ,CAAC;IACF,CAAC;IAED,SAAS,cAAc,CAAC,GAAoB;QAC3C,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC;YAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,C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AC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACX,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@edv4h/usketch-core",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "@edv4h/usketch-shared": "1.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "5.9.3",
19
+ "vitest": "3.2.4"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/EdV4H/usketch.git",
32
+ "directory": "packages/core"
33
+ },
34
+ "homepage": "https://github.com/EdV4H/usketch#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/EdV4H/usketch/issues"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.json",
40
+ "typecheck": "tsc --noEmit",
41
+ "test": "vitest run --passWithNoTests",
42
+ "clean": "rm -rf dist"
43
+ }
44
+ }