@neoloopy/cld-canvas 0.1.1 → 0.1.2
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 +77 -0
- package/package.json +21 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 neoloopy
|
|
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
CHANGED
|
@@ -115,6 +115,83 @@ Use `Camera.panBy`, `Camera.zoomAt`, `Camera.setScaleAt`, and
|
|
|
115
115
|
`Camera.centerOn` to wire your own pointer, wheel, trackpad, minimap, or toolbar
|
|
116
116
|
controls.
|
|
117
117
|
|
|
118
|
+
## Using It in React (or any framework)
|
|
119
|
+
|
|
120
|
+
There is no framework-specific component — `paint` only needs a `<canvas>` 2D
|
|
121
|
+
context, so a thin wrapper is all it takes. A minimal React component that turns
|
|
122
|
+
a spec into a rendered diagram:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import { useEffect, useRef } from "react";
|
|
126
|
+
import { parse } from "yaml";
|
|
127
|
+
import {
|
|
128
|
+
MemoryStorage,
|
|
129
|
+
NativeEngine,
|
|
130
|
+
Camera,
|
|
131
|
+
SceneCache,
|
|
132
|
+
paint,
|
|
133
|
+
LIGHT,
|
|
134
|
+
} from "@neoloopy/cld-canvas";
|
|
135
|
+
import type { BuildSpec } from "@neoloopy/cld-canvas";
|
|
136
|
+
|
|
137
|
+
export function CldCanvas({ spec }: { spec: BuildSpec }) {
|
|
138
|
+
const ref = useRef<HTMLCanvasElement>(null);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
let alive = true;
|
|
142
|
+
(async () => {
|
|
143
|
+
const engine = new NativeEngine(new MemoryStorage(), parse, {
|
|
144
|
+
modelsRoot: "Models",
|
|
145
|
+
});
|
|
146
|
+
const model = await engine.createModel("model");
|
|
147
|
+
await engine.buildModel(model.folder, spec);
|
|
148
|
+
const graph = await engine.loadGraph(model.folder);
|
|
149
|
+
|
|
150
|
+
const canvas = ref.current;
|
|
151
|
+
const ctx = canvas?.getContext("2d");
|
|
152
|
+
if (!alive || !canvas || !ctx) return;
|
|
153
|
+
|
|
154
|
+
const dpr = window.devicePixelRatio || 1;
|
|
155
|
+
const w = canvas.clientWidth;
|
|
156
|
+
const h = canvas.clientHeight;
|
|
157
|
+
canvas.width = Math.floor(w * dpr);
|
|
158
|
+
canvas.height = Math.floor(h * dpr);
|
|
159
|
+
|
|
160
|
+
const camera = new Camera();
|
|
161
|
+
const sceneCache = new SceneCache();
|
|
162
|
+
const scene = sceneCache.build(graph, new Map(), new Map());
|
|
163
|
+
if (!scene) return;
|
|
164
|
+
sceneCache.fit(camera, w, h);
|
|
165
|
+
|
|
166
|
+
paint(ctx, scene, camera, LIGHT, {
|
|
167
|
+
cssWidth: w,
|
|
168
|
+
cssHeight: h,
|
|
169
|
+
dpr,
|
|
170
|
+
selectedNodeId: null,
|
|
171
|
+
selectedEdgeId: null,
|
|
172
|
+
selectedLoopKey: null,
|
|
173
|
+
liveNodeIds: new Set(),
|
|
174
|
+
linkPreview: null,
|
|
175
|
+
connectNodeId: null,
|
|
176
|
+
loopHighlight: null,
|
|
177
|
+
pulsePhase: 0,
|
|
178
|
+
flowPhase: 0,
|
|
179
|
+
});
|
|
180
|
+
})();
|
|
181
|
+
return () => {
|
|
182
|
+
alive = false;
|
|
183
|
+
};
|
|
184
|
+
}, [spec]);
|
|
185
|
+
|
|
186
|
+
return <canvas ref={ref} style={{ width: "100%", height: 400 }} />;
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
To make it interactive, keep one `Camera` and one `SceneCache` across renders,
|
|
191
|
+
wire `Camera.panBy` / `Camera.zoomAt` to pointer and wheel events, and repaint.
|
|
192
|
+
The same wrapper shape works in Vue, Svelte, or plain DOM — only the lifecycle
|
|
193
|
+
hook changes.
|
|
194
|
+
|
|
118
195
|
## Engine Concepts
|
|
119
196
|
|
|
120
197
|
### Storage
|
package/package.json
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neoloopy/cld-canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "neoloopy",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Framework-agnostic CLD canvas renderer + in-memory edit engine (shared by the neoloopy Obsidian plugin and neoloopy.com).",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"cld",
|
|
9
|
+
"causal-loop-diagram",
|
|
10
|
+
"systems-thinking",
|
|
11
|
+
"system-dynamics",
|
|
12
|
+
"feedback-loops",
|
|
13
|
+
"canvas",
|
|
14
|
+
"diagram",
|
|
15
|
+
"visualization",
|
|
16
|
+
"graph",
|
|
17
|
+
"neoloopy"
|
|
18
|
+
],
|
|
7
19
|
"type": "module",
|
|
8
20
|
"main": "dist/index.js",
|
|
9
21
|
"module": "dist/index.js",
|
|
10
22
|
"types": "dist/index.d.ts",
|
|
11
23
|
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
24
|
+
"sideEffects": false,
|
|
12
25
|
"files": ["dist"],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/frozenabe/neoloopy-obsidian.git",
|
|
29
|
+
"directory": "packages/cld-canvas"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/frozenabe/neoloopy-obsidian/tree/main/packages/cld-canvas#readme",
|
|
32
|
+
"bugs": { "url": "https://github.com/frozenabe/neoloopy-obsidian/issues" },
|
|
13
33
|
"scripts": { "build": "tsc -p tsconfig.json" }
|
|
14
34
|
}
|