@trokster/l-cursor 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hrakotom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Infinite Zoom
2
+
3
+ A semantic-zoom visualization library: one generic engine driving a **radial
4
+ fractal** you can fall into forever. As you zoom in, the camera re-bases its
5
+ referential (see [`THEORY.md`](./THEORY.md)) so the scale number never escapes a
6
+ ~3-decade band and floating-point precision never rots. Off-screen and sub-pixel
7
+ nodes are never drawn — render cost is `O(visible)`, independent of tree size.
8
+
9
+ ## Demo (`npm run dev`)
10
+
11
+ `/zoom/radial` — children ring inside each node; click to dive, wheel/pinch to
12
+ zoom, drag to pan, zoom out to rise. Each node carries a live **HTML portal** (a
13
+ real component sized in screen pixels) that swaps detail as you approach.
14
+
15
+ ## Architecture
16
+
17
+ - `core/engine.js` — generic engine: bounded-scale camera, referential rebasing
18
+ (the infinite-zoom trick), level-of-detail with ghost child previews, sibling
19
+ context, and viewport culling. Display-agnostic.
20
+ - `core/{camera,rebase,interaction,tree}.js` — affine camera, the pixel-exact
21
+ rebase math, pointer/pinch/wheel + inertia, shared tree indexing.
22
+ - `layouts/radial.js` — `layout(index, rootId, opts)` returning `{ nodes, order }`.
23
+ The engine is generic over any self-similar, child-contained layout; radial is
24
+ the one shipped here.
25
+ - `viz/ZoomScene.svelte` — the renderer: world-static SVG under a single animated
26
+ transform, spring fly-to navigation, breadcrumbs, enter-fades, and
27
+ resolution-adaptive HTML **portals** (live components inside each node's core).
28
+
29
+ ```js
30
+ import { ZoomScene, indexTree, radialLayout } from '@trokster/l-cursor';
31
+ // <ZoomScene index={indexTree(data)} layout={radialLayout} nodeStyle="rings" />
32
+ ```
33
+
34
+ The math (rebase derivation, LOD, culling, self-similarity) lives in
35
+ [`THEORY.md`](./THEORY.md). A copy-paste integration guide for LLMs/agents is in
36
+ [`LLM.md`](./LLM.md).
37
+
38
+ ## Develop
39
+
40
+ ```bash
41
+ npm install
42
+ npm run dev # SvelteKit playground at /zoom/radial
43
+ npm run test:unit -- --run # Vitest (engine + component, headless)
44
+ npm run lint # Prettier + ESLint
45
+ npm run build # package the library to dist/ (svelte-package + publint)
46
+ ```
47
+
48
+ The package is Svelte 5 (runes) and SVG-only — no canvas, WebGL, or runtime
49
+ dependencies. `import` from `@trokster/l-cursor` in any SvelteKit/Vite project.
@@ -0,0 +1,30 @@
1
+ export function createCamera(initial?: {}): {
2
+ state: import("svelte/store").Writable<{
3
+ x: any;
4
+ y: any;
5
+ sx: any;
6
+ sy: any;
7
+ }>;
8
+ get: () => {
9
+ x: any;
10
+ y: any;
11
+ sx: any;
12
+ sy: any;
13
+ };
14
+ set: (p: any) => void;
15
+ pan: (dx: any, dy: any) => void;
16
+ zoomAt: (factor: any, cx: any, cy: any) => void;
17
+ zoomAtXY: (fx: any, fy: any, cx: any, cy: any) => void;
18
+ worldToScreen: (wx: any, wy: any, s?: {
19
+ x: any;
20
+ y: any;
21
+ sx: any;
22
+ sy: any;
23
+ }) => any[];
24
+ screenToWorld: (px: any, py: any, s?: {
25
+ x: any;
26
+ y: any;
27
+ sx: any;
28
+ sy: any;
29
+ }) => number[];
30
+ };
@@ -0,0 +1,80 @@
1
+ import { writable, get } from 'svelte/store';
2
+
3
+ // Affine camera, per-axis. World -> screen is:
4
+ //
5
+ // screenX = worldX * sx + x
6
+ // screenY = worldY * sy + y
7
+ //
8
+ // Uniform layouts (radial / pack / network) keep sx === sy. Treemap allows
9
+ // sx !== sy (rectangles stretch per axis). See THEORY.md §3.
10
+ //
11
+ // We do NOT clamp scale here — the engine rebases (THEORY.md §4) to keep scale
12
+ // inside a healthy band, which is a cleaner mechanism than hard clamping.
13
+
14
+ export function createCamera(initial = {}) {
15
+ const state = writable({
16
+ x: initial.x ?? 0,
17
+ y: initial.y ?? 0,
18
+ sx: initial.sx ?? initial.scale ?? 1,
19
+ sy: initial.sy ?? initial.scale ?? 1
20
+ });
21
+
22
+ function set(p) {
23
+ state.update((s) => {
24
+ const next = { ...s };
25
+ if (p.x != null) next.x = p.x;
26
+ if (p.y != null) next.y = p.y;
27
+ if (p.scale != null) {
28
+ next.sx = p.scale;
29
+ next.sy = p.scale;
30
+ }
31
+ if (p.sx != null) next.sx = p.sx;
32
+ if (p.sy != null) next.sy = p.sy;
33
+ return next;
34
+ });
35
+ }
36
+
37
+ function pan(dx, dy) {
38
+ state.update((s) => ({ ...s, x: s.x + dx, y: s.y + dy }));
39
+ }
40
+
41
+ // Uniform zoom toward screen point (cx, cy) keeping that world point fixed.
42
+ function zoomAt(factor, cx, cy) {
43
+ state.update((s) => {
44
+ const nsx = s.sx * factor;
45
+ const nsy = s.sy * factor;
46
+ const wx = (cx - s.x) / s.sx;
47
+ const wy = (cy - s.y) / s.sy;
48
+ return { sx: nsx, sy: nsy, x: cx - wx * nsx, y: cy - wy * nsy };
49
+ });
50
+ }
51
+
52
+ // Anisotropic zoom (treemap): independent factors per axis.
53
+ function zoomAtXY(fx, fy, cx, cy) {
54
+ state.update((s) => {
55
+ const nsx = s.sx * fx;
56
+ const nsy = s.sy * fy;
57
+ const wx = (cx - s.x) / s.sx;
58
+ const wy = (cy - s.y) / s.sy;
59
+ return { sx: nsx, sy: nsy, x: cx - wx * nsx, y: cy - wy * nsy };
60
+ });
61
+ }
62
+
63
+ function worldToScreen(wx, wy, s = get(state)) {
64
+ return [wx * s.sx + s.x, wy * s.sy + s.y];
65
+ }
66
+ function screenToWorld(px, py, s = get(state)) {
67
+ return [(px - s.x) / s.sx, (py - s.y) / s.sy];
68
+ }
69
+
70
+ return {
71
+ state,
72
+ get: () => get(state),
73
+ set,
74
+ pan,
75
+ zoomAt,
76
+ zoomAtXY,
77
+ worldToScreen,
78
+ screenToWorld
79
+ };
80
+ }
@@ -0,0 +1,67 @@
1
+ export function createEngine({ index, layout, camera, config }: {
2
+ index: any;
3
+ layout: any;
4
+ camera: any;
5
+ config?: {};
6
+ }): {
7
+ setViewport: (w: any, h: any) => void;
8
+ fit: (frac?: number) => void;
9
+ fitCamera: (frac?: number) => {
10
+ sx: number;
11
+ sy: number;
12
+ x: number;
13
+ y: number;
14
+ };
15
+ frame: () => {
16
+ items: {
17
+ id: any;
18
+ parentId: any;
19
+ kind: any;
20
+ depth: any;
21
+ absDepth: any;
22
+ childCount: any;
23
+ data: any;
24
+ open: boolean;
25
+ openness: any;
26
+ leaf: boolean;
27
+ alpha: any;
28
+ showLabel: boolean;
29
+ }[];
30
+ rootId: any;
31
+ cam: any;
32
+ edges: any;
33
+ links: {
34
+ id: string;
35
+ x1: any;
36
+ y1: any;
37
+ x2: any;
38
+ y2: any;
39
+ r1: any;
40
+ r2: any;
41
+ alpha: any;
42
+ }[];
43
+ };
44
+ reset: (id: any) => void;
45
+ setAnchor: (x: any, y: any) => void;
46
+ clearAnchor: () => void;
47
+ pick: (px: any, py: any) => any;
48
+ readonly rootId: any;
49
+ readonly config: {
50
+ rootSize: number;
51
+ maxDepth: number;
52
+ contextUp: number;
53
+ treeLinks: boolean;
54
+ descendAt: number;
55
+ ascendAt: number;
56
+ minPx: number;
57
+ openPx: number;
58
+ childPreview: boolean;
59
+ previewPx: number;
60
+ previewMax: number;
61
+ labelPx: number;
62
+ maxScale: number;
63
+ minScale: number;
64
+ layoutOpts: {};
65
+ };
66
+ readonly layout: any;
67
+ };