@canvas-commons/2d 0.2.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 (183) hide show
  1. package/LICENSE +22 -0
  2. package/editor/index.css +40 -0
  3. package/editor/index.js +525 -0
  4. package/editor/index.js.map +1 -0
  5. package/lib/index-OvpZ-GsA.d.ts +5673 -0
  6. package/lib/index-OvpZ-GsA.d.ts.map +1 -0
  7. package/lib/index.d.ts +2 -0
  8. package/lib/index.js +10326 -0
  9. package/lib/index.js.map +1 -0
  10. package/lib/jsx-dev-runtime.d.ts +2 -0
  11. package/lib/jsx-dev-runtime.js +2 -0
  12. package/lib/jsx-runtime.d.ts +2 -0
  13. package/lib/jsx-runtime.js +28 -0
  14. package/lib/jsx-runtime.js.map +1 -0
  15. package/package.json +79 -0
  16. package/src/editor/NodeInspectorConfig.tsx +76 -0
  17. package/src/editor/PreviewOverlayConfig.tsx +65 -0
  18. package/src/editor/Provider.tsx +109 -0
  19. package/src/editor/SceneGraphTabConfig.tsx +87 -0
  20. package/src/editor/icons/CircleIcon.tsx +7 -0
  21. package/src/editor/icons/CodeIcon.tsx +8 -0
  22. package/src/editor/icons/CurveIcon.tsx +7 -0
  23. package/src/editor/icons/GridIcon.tsx +7 -0
  24. package/src/editor/icons/IconMap.ts +35 -0
  25. package/src/editor/icons/ImgIcon.tsx +8 -0
  26. package/src/editor/icons/LayoutIcon.tsx +9 -0
  27. package/src/editor/icons/LineIcon.tsx +7 -0
  28. package/src/editor/icons/NodeIcon.tsx +7 -0
  29. package/src/editor/icons/RayIcon.tsx +7 -0
  30. package/src/editor/icons/RectIcon.tsx +7 -0
  31. package/src/editor/icons/ShapeIcon.tsx +7 -0
  32. package/src/editor/icons/TxtIcon.tsx +8 -0
  33. package/src/editor/icons/VideoIcon.tsx +7 -0
  34. package/src/editor/icons/View2DIcon.tsx +10 -0
  35. package/src/editor/index.css +0 -0
  36. package/src/editor/index.ts +19 -0
  37. package/src/editor/shortcuts.ts +27 -0
  38. package/src/editor/tree/DetachedRoot.tsx +27 -0
  39. package/src/editor/tree/NodeElement.tsx +72 -0
  40. package/src/editor/tree/TreeElement.tsx +70 -0
  41. package/src/editor/tree/TreeRoot.tsx +10 -0
  42. package/src/editor/tree/ViewRoot.tsx +20 -0
  43. package/src/editor/tree/index.module.scss +45 -0
  44. package/src/editor/tree/index.ts +4 -0
  45. package/src/editor/tree/navigation.ts +145 -0
  46. package/src/editor/tsconfig.build.json +5 -0
  47. package/src/editor/tsconfig.json +12 -0
  48. package/src/editor/tsdoc.json +4 -0
  49. package/src/editor/utils/SignalSet.ts +37 -0
  50. package/src/editor/utils/index.ts +1 -0
  51. package/src/editor/vite-env.d.ts +1 -0
  52. package/src/lib/code/CodeCursor.ts +468 -0
  53. package/src/lib/code/CodeDiffer.ts +77 -0
  54. package/src/lib/code/CodeFragment.ts +96 -0
  55. package/src/lib/code/CodeHighlighter.ts +73 -0
  56. package/src/lib/code/CodeMetrics.ts +47 -0
  57. package/src/lib/code/CodeRange.test.ts +113 -0
  58. package/src/lib/code/CodeRange.ts +222 -0
  59. package/src/lib/code/CodeScope.ts +100 -0
  60. package/src/lib/code/CodeSelection.ts +28 -0
  61. package/src/lib/code/CodeSignal.ts +348 -0
  62. package/src/lib/code/CodeTokenizer.ts +54 -0
  63. package/src/lib/code/DefaultHighlightStyle.ts +98 -0
  64. package/src/lib/code/LezerHighlighter.ts +113 -0
  65. package/src/lib/code/diff.test.ts +311 -0
  66. package/src/lib/code/diff.ts +319 -0
  67. package/src/lib/code/extractRange.ts +125 -0
  68. package/src/lib/code/index.ts +13 -0
  69. package/src/lib/components/Bezier.ts +103 -0
  70. package/src/lib/components/Camera.ts +401 -0
  71. package/src/lib/components/Circle.ts +310 -0
  72. package/src/lib/components/Code.ts +532 -0
  73. package/src/lib/components/CubicBezier.ts +115 -0
  74. package/src/lib/components/Curve.ts +460 -0
  75. package/src/lib/components/Grid.ts +134 -0
  76. package/src/lib/components/Icon.ts +153 -0
  77. package/src/lib/components/Img.ts +328 -0
  78. package/src/lib/components/Knot.ts +156 -0
  79. package/src/lib/components/Latex.ts +537 -0
  80. package/src/lib/components/Layout.ts +1101 -0
  81. package/src/lib/components/Line.ts +394 -0
  82. package/src/lib/components/Node.ts +1941 -0
  83. package/src/lib/components/Path.ts +132 -0
  84. package/src/lib/components/Polygon.ts +266 -0
  85. package/src/lib/components/QuadBezier.ts +103 -0
  86. package/src/lib/components/Ray.ts +126 -0
  87. package/src/lib/components/Rect.ts +219 -0
  88. package/src/lib/components/SVG.ts +853 -0
  89. package/src/lib/components/Shape.ts +322 -0
  90. package/src/lib/components/Spline.ts +318 -0
  91. package/src/lib/components/Txt.test.tsx +81 -0
  92. package/src/lib/components/Txt.ts +204 -0
  93. package/src/lib/components/TxtLeaf.ts +210 -0
  94. package/src/lib/components/Video.ts +368 -0
  95. package/src/lib/components/View2D.ts +85 -0
  96. package/src/lib/components/__logs__/image-without-source.ts +18 -0
  97. package/src/lib/components/__logs__/line-without-points.ts +31 -0
  98. package/src/lib/components/__logs__/reactive-playback-rate.ts +22 -0
  99. package/src/lib/components/__logs__/spline-with-insufficient-knots.ts +25 -0
  100. package/src/lib/components/__tests__/Camera.test.tsx +73 -0
  101. package/src/lib/components/__tests__/children.test.tsx +142 -0
  102. package/src/lib/components/__tests__/clone.test.tsx +126 -0
  103. package/src/lib/components/__tests__/fontInheritance.test.tsx +102 -0
  104. package/src/lib/components/__tests__/generatorTest.ts +27 -0
  105. package/src/lib/components/__tests__/mockScene2D.ts +50 -0
  106. package/src/lib/components/__tests__/query.test.tsx +122 -0
  107. package/src/lib/components/__tests__/state.test.tsx +60 -0
  108. package/src/lib/components/index.ts +26 -0
  109. package/src/lib/components/types.ts +35 -0
  110. package/src/lib/curves/ArcSegment.ts +169 -0
  111. package/src/lib/curves/CircleSegment.ts +99 -0
  112. package/src/lib/curves/CubicBezierSegment.ts +80 -0
  113. package/src/lib/curves/CurveDrawingInfo.ts +11 -0
  114. package/src/lib/curves/CurvePoint.ts +15 -0
  115. package/src/lib/curves/CurveProfile.ts +28 -0
  116. package/src/lib/curves/KnotInfo.ts +10 -0
  117. package/src/lib/curves/LineSegment.ts +75 -0
  118. package/src/lib/curves/Polynomial.ts +355 -0
  119. package/src/lib/curves/Polynomial2D.ts +62 -0
  120. package/src/lib/curves/PolynomialSegment.ts +151 -0
  121. package/src/lib/curves/QuadBezierSegment.ts +66 -0
  122. package/src/lib/curves/Segment.ts +31 -0
  123. package/src/lib/curves/UniformPolynomialCurveSampler.ts +93 -0
  124. package/src/lib/curves/createCurveProfileLerp.ts +471 -0
  125. package/src/lib/curves/getBezierSplineProfile.ts +227 -0
  126. package/src/lib/curves/getCircleProfile.ts +86 -0
  127. package/src/lib/curves/getPathProfile.ts +177 -0
  128. package/src/lib/curves/getPointAtDistance.ts +21 -0
  129. package/src/lib/curves/getPolylineProfile.test.ts +21 -0
  130. package/src/lib/curves/getPolylineProfile.ts +88 -0
  131. package/src/lib/curves/getRectProfile.ts +138 -0
  132. package/src/lib/curves/index.ts +16 -0
  133. package/src/lib/decorators/canvasStyleSignal.ts +15 -0
  134. package/src/lib/decorators/colorSignal.ts +9 -0
  135. package/src/lib/decorators/compound.ts +85 -0
  136. package/src/lib/decorators/computed.ts +18 -0
  137. package/src/lib/decorators/defaultStyle.ts +15 -0
  138. package/src/lib/decorators/filtersSignal.ts +133 -0
  139. package/src/lib/decorators/index.ts +10 -0
  140. package/src/lib/decorators/initializers.ts +32 -0
  141. package/src/lib/decorators/nodeName.ts +13 -0
  142. package/src/lib/decorators/signal.test.ts +89 -0
  143. package/src/lib/decorators/signal.ts +348 -0
  144. package/src/lib/decorators/spacingSignal.ts +15 -0
  145. package/src/lib/decorators/transformSignals.test.ts +858 -0
  146. package/src/lib/decorators/transformSignals.ts +1633 -0
  147. package/src/lib/decorators/vector2Signal.ts +35 -0
  148. package/src/lib/globals.d.ts +2 -0
  149. package/src/lib/index.ts +9 -0
  150. package/src/lib/jsx-dev-runtime.ts +2 -0
  151. package/src/lib/jsx-runtime.ts +45 -0
  152. package/src/lib/morphers/PathMorpher.ts +8 -0
  153. package/src/lib/morphers/defaultMorpher.ts +43 -0
  154. package/src/lib/morphers/index.ts +4 -0
  155. package/src/lib/morphers/manimMorpher.ts +658 -0
  156. package/src/lib/parse-svg-path.d.ts +14 -0
  157. package/src/lib/partials/Filter.ts +185 -0
  158. package/src/lib/partials/Gradient.ts +103 -0
  159. package/src/lib/partials/Pattern.ts +35 -0
  160. package/src/lib/partials/RoughConfig.ts +180 -0
  161. package/src/lib/partials/ShaderConfig.ts +122 -0
  162. package/src/lib/partials/index.ts +5 -0
  163. package/src/lib/partials/types.ts +58 -0
  164. package/src/lib/scenes/Scene2D.ts +167 -0
  165. package/src/lib/scenes/index.ts +3 -0
  166. package/src/lib/scenes/makeScene2D.ts +19 -0
  167. package/src/lib/scenes/useScene2D.ts +6 -0
  168. package/src/lib/tsconfig.build.json +5 -0
  169. package/src/lib/tsconfig.json +11 -0
  170. package/src/lib/tsdoc.json +4 -0
  171. package/src/lib/utils/CanvasUtils.ts +304 -0
  172. package/src/lib/utils/PathDataBuilder.ts +320 -0
  173. package/src/lib/utils/diff.test.ts +453 -0
  174. package/src/lib/utils/diff.ts +148 -0
  175. package/src/lib/utils/index.ts +5 -0
  176. package/src/lib/utils/is.ts +11 -0
  177. package/src/lib/utils/makeSignalExtensions.ts +29 -0
  178. package/src/lib/utils/rough.ts +513 -0
  179. package/src/lib/utils/withDefaults.tsx +26 -0
  180. package/src/tsconfig.base.json +18 -0
  181. package/src/tsconfig.build.json +8 -0
  182. package/src/tsconfig.json +5 -0
  183. package/tsconfig.project.json +7 -0
@@ -0,0 +1,27 @@
1
+ import {makeShortcuts} from '@canvas-commons/editor';
2
+ export const SCENE_GRAPH_SHORTCUTS = makeShortcuts('scene-graph', {
3
+ moveUp: {
4
+ display: '↑',
5
+ description: 'Go up',
6
+ key: 'ArrowUp',
7
+ modifiers: {},
8
+ },
9
+ modeDown: {
10
+ display: '↓',
11
+ description: 'Go down',
12
+ key: 'ArrowDown',
13
+ modifiers: {},
14
+ },
15
+ expandOrMoveDown: {
16
+ display: '→',
17
+ description: 'Expand / Enter',
18
+ key: 'ArrowRight',
19
+ modifiers: {},
20
+ },
21
+ collapseOrMoveUp: {
22
+ display: '←',
23
+ description: 'Collapse / Leave',
24
+ key: 'ArrowLeft',
25
+ modifiers: {},
26
+ },
27
+ });
@@ -0,0 +1,27 @@
1
+ import {usePluginState} from '../Provider';
2
+ import {NodeElement} from './NodeElement';
3
+ import {TreeElement} from './TreeElement';
4
+ import {TreeRoot} from './TreeRoot';
5
+
6
+ export function DetachedRoot() {
7
+ const {afterRender, openDetached, scene} = usePluginState();
8
+ const currentScene = scene.value;
9
+ const children = currentScene ? [...currentScene.getDetachedNodes()] : [];
10
+ afterRender.value;
11
+
12
+ return children.length > 0 ? (
13
+ <TreeRoot>
14
+ <TreeElement
15
+ open={openDetached.value}
16
+ hasChildren
17
+ onToggle={value => {
18
+ openDetached.value = value;
19
+ }}
20
+ label="Detached nodes"
21
+ >
22
+ {openDetached.value &&
23
+ children.map(child => <NodeElement node={child} depth={1} />)}
24
+ </TreeElement>
25
+ </TreeRoot>
26
+ ) : null;
27
+ }
@@ -0,0 +1,72 @@
1
+ import {NODE_NAME, Node} from '@canvas-commons/2d';
2
+ import {useComputed, useSignal, useSignalEffect} from '@preact/signals';
3
+ import {useEffect, useRef} from 'preact/hooks';
4
+ import {usePluginState} from '../Provider';
5
+ import {IconMap} from '../icons/IconMap';
6
+ import {TreeElement} from './TreeElement';
7
+
8
+ interface NodeElementProps {
9
+ node: Node;
10
+ depth?: number;
11
+ }
12
+
13
+ export function NodeElement({node, depth = 0}: NodeElementProps) {
14
+ const {
15
+ selectedNode,
16
+ visibleNodes,
17
+ selectNode,
18
+ hoveredKey,
19
+ openNodes,
20
+ afterRender,
21
+ } = usePluginState();
22
+ const ref = useRef<HTMLDivElement>(null);
23
+ const nodeSignal = useSignal(node);
24
+ nodeSignal.value = node;
25
+
26
+ const open = useComputed(() => openNodes.has(nodeSignal.value.key));
27
+
28
+ useEffect(() => {
29
+ visibleNodes.add(node.key);
30
+ return () => {
31
+ visibleNodes.delete(node.key);
32
+ };
33
+ }, [node.key]);
34
+
35
+ const children = useComputed(() => {
36
+ afterRender.value;
37
+ return nodeSignal.value.peekChildren();
38
+ });
39
+
40
+ useSignalEffect(() => {
41
+ if (node.key === selectedNode.value?.key) {
42
+ ref.current?.scrollIntoView({block: 'nearest', behavior: 'instant'});
43
+ }
44
+ });
45
+
46
+ const Icon = IconMap[node[NODE_NAME]] ?? IconMap.Node;
47
+
48
+ return (
49
+ <TreeElement
50
+ forwardRef={ref}
51
+ open={open.value}
52
+ hasChildren={children.value.length > 0}
53
+ onToggle={value => openNodes.toggle(node.key, value)}
54
+ depth={depth}
55
+ icon={<Icon />}
56
+ label={node.key}
57
+ selected={selectedNode.value === node}
58
+ onClick={event => {
59
+ selectNode(node.key);
60
+ event.stopPropagation();
61
+ }}
62
+ onPointerEnter={() => (hoveredKey.value = node.key)}
63
+ onPointerLeave={() => (hoveredKey.value = null)}
64
+ >
65
+ {open.value &&
66
+ children.value.length > 0 &&
67
+ children.value.map(child => (
68
+ <NodeElement node={child} depth={depth + 1} />
69
+ ))}
70
+ </TreeElement>
71
+ );
72
+ }
@@ -0,0 +1,70 @@
1
+ import {Toggle} from '@canvas-commons/editor';
2
+ import {clsx} from 'clsx';
3
+ import {ComponentChildren, JSX} from 'preact';
4
+ import {Ref} from 'preact/hooks';
5
+ import styles from './index.module.scss';
6
+
7
+ const DEPTH_VAR = '--depth';
8
+
9
+ interface TreeElementProps extends Omit<
10
+ JSX.HTMLAttributes<HTMLDivElement>,
11
+ 'label' | 'icon' | 'onToggle'
12
+ > {
13
+ icon?: ComponentChildren;
14
+ label: ComponentChildren;
15
+ children?: ComponentChildren;
16
+ selected?: boolean;
17
+ open: boolean;
18
+ hasChildren?: boolean;
19
+ onToggle?: (value: boolean) => void;
20
+ depth?: number;
21
+ forwardRef?: Ref<HTMLDivElement>;
22
+ }
23
+
24
+ export function TreeElement({
25
+ label,
26
+ children,
27
+ selected,
28
+ hasChildren,
29
+ depth = 0,
30
+ open,
31
+ onToggle,
32
+ icon,
33
+ forwardRef,
34
+ ...props
35
+ }: TreeElementProps) {
36
+ return (
37
+ <>
38
+ <div
39
+ className={clsx(
40
+ styles.entry,
41
+ selected && styles.active,
42
+ hasChildren && styles.parent,
43
+ )}
44
+ onDblClick={() => {
45
+ if (hasChildren) {
46
+ onToggle?.(!open);
47
+ }
48
+ }}
49
+ {...props}
50
+ style={{[DEPTH_VAR]: `${depth}`}}
51
+ >
52
+ <div ref={forwardRef} className={styles.label}>
53
+ {hasChildren && (
54
+ <Toggle
55
+ animated={false}
56
+ open={open}
57
+ onToggle={onToggle}
58
+ onDblClick={e => {
59
+ e.stopPropagation();
60
+ }}
61
+ />
62
+ )}
63
+ {icon}
64
+ {label}
65
+ </div>
66
+ </div>
67
+ {children}
68
+ </>
69
+ );
70
+ }
@@ -0,0 +1,10 @@
1
+ import {clsx} from 'clsx';
2
+ import {JSX} from 'preact';
3
+ import styles from './index.module.scss';
4
+
5
+ export function TreeRoot({
6
+ className,
7
+ ...props
8
+ }: JSX.HTMLAttributes<HTMLDivElement>) {
9
+ return <div className={clsx(styles.root, className)} {...props} />;
10
+ }
@@ -0,0 +1,20 @@
1
+ import {useSignal, useSignalEffect} from '@preact/signals';
2
+ import {usePluginState} from '../Provider';
3
+ import {NodeElement} from './NodeElement';
4
+ import {TreeRoot} from './TreeRoot';
5
+
6
+ export function ViewRoot() {
7
+ const {scene} = usePluginState();
8
+ const view = useSignal(scene.value?.getView());
9
+
10
+ useSignalEffect(() => {
11
+ view.value = scene.value?.getView();
12
+ return scene.value?.onReset.subscribe(() => {
13
+ view.value = scene.value?.getView();
14
+ });
15
+ });
16
+
17
+ return view.value ? (
18
+ <TreeRoot>{<NodeElement node={view.value} />}</TreeRoot>
19
+ ) : null;
20
+ }
@@ -0,0 +1,45 @@
1
+ .root {
2
+ margin-top: -1px;
3
+ padding: 3px 0 4px;
4
+ border-top: 2px solid var(--background-color);
5
+ width: max-content;
6
+ min-width: 100%;
7
+ }
8
+
9
+ .entry {
10
+ --depth: 0;
11
+
12
+ padding: 4px 0 4px calc(var(--depth) * 22px + 24px);
13
+ border-radius: var(--radius);
14
+ user-select: none;
15
+ cursor: pointer;
16
+
17
+ &:hover {
18
+ background-color: var(--surface-color-hover);
19
+ }
20
+
21
+ &.active {
22
+ --surface-color-hover: none;
23
+ background-color: var(--theme-overlay);
24
+ color: var(--theme);
25
+ }
26
+
27
+ &.parent {
28
+ padding-left: calc(var(--depth) * 22px);
29
+ }
30
+ }
31
+
32
+ .label {
33
+ width: max-content;
34
+ display: flex;
35
+ padding-right: 8px;
36
+
37
+ > svg {
38
+ width: 20px;
39
+ height: 20px;
40
+ align-self: center;
41
+ background-color: var(--background-color);
42
+ border-radius: var(--radius);
43
+ margin-right: 8px;
44
+ }
45
+ }
@@ -0,0 +1,4 @@
1
+ export * from './DetachedRoot';
2
+ export * from './navigation';
3
+ export * from './NodeElement';
4
+ export * from './ViewRoot';
@@ -0,0 +1,145 @@
1
+ import {Node} from '@canvas-commons/2d';
2
+ import {useShortcuts} from '@canvas-commons/editor';
3
+ import {useComputed} from '@preact/signals';
4
+ import {usePluginState} from '../Provider';
5
+ import {SCENE_GRAPH_SHORTCUTS} from '../shortcuts';
6
+
7
+ export function useKeyboardNavigation() {
8
+ const {selectedNode, scene, afterRender, openNodes, selectNode} =
9
+ usePluginState();
10
+
11
+ const detachedNodes = useComputed(() => {
12
+ afterRender.value;
13
+ const detachedNodes: string[] = [];
14
+ for (const node of scene.value?.getDetachedNodes() ?? []) {
15
+ detachedNodes.push(node.key);
16
+ }
17
+ return detachedNodes;
18
+ });
19
+
20
+ function selectView() {
21
+ selectNode(scene.value?.getView()?.key ?? null);
22
+ }
23
+
24
+ function findNextNodeUp(node: Node): string | null {
25
+ const detachedIndex = detachedNodes.value.indexOf(node.key);
26
+ if (detachedIndex > 0) {
27
+ return detachedNodes.value[detachedIndex - 1];
28
+ } else if (detachedIndex === 0) {
29
+ // Go back to the scene graph after reaching the top of detached nodes:
30
+ return findLowestNode();
31
+ }
32
+
33
+ const parent = node.parent();
34
+ if (!parent) {
35
+ return null;
36
+ }
37
+
38
+ const siblings = parent.peekChildren();
39
+ const index = siblings.indexOf(node);
40
+ if (index < 1) {
41
+ return parent.key;
42
+ }
43
+
44
+ let current = siblings[index - 1];
45
+ while (current) {
46
+ const children = current.peekChildren();
47
+ if (openNodes.has(current.key) && children.length > 0) {
48
+ current = children.at(-1)!;
49
+ } else {
50
+ return current.key;
51
+ }
52
+ }
53
+
54
+ return null;
55
+ }
56
+
57
+ function findNextNodeDown(node: Node): string | null {
58
+ if (openNodes.has(node.key)) {
59
+ const children = node.peekChildren();
60
+ if (children.length > 0) {
61
+ return children[0].key;
62
+ }
63
+ }
64
+
65
+ let current = node;
66
+ while (current) {
67
+ const parent = current.parent();
68
+ if (!parent) {
69
+ const detachedIndex = detachedNodes.value.indexOf(node.key);
70
+ if (detachedIndex >= 0) {
71
+ return detachedNodes.value[detachedIndex + 1] ?? null;
72
+ }
73
+
74
+ // Try jumping down to the detached section after reaching the bottom:
75
+ return detachedNodes.value[0] ?? null;
76
+ }
77
+
78
+ const siblings = parent.peekChildren();
79
+ const index = siblings.indexOf(current);
80
+ if (index < siblings.length - 1) {
81
+ return siblings[index + 1].key;
82
+ }
83
+
84
+ current = parent;
85
+ }
86
+
87
+ return null;
88
+ }
89
+
90
+ function findLowestNode(): string | null {
91
+ let current: Node | undefined = scene.value?.getView();
92
+ while (current) {
93
+ const children = current.peekChildren();
94
+ if (openNodes.has(current.key) && children.length > 0) {
95
+ current = children.at(-1)!;
96
+ } else {
97
+ return current.key;
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+
103
+ useShortcuts(SCENE_GRAPH_SHORTCUTS, {
104
+ moveUp: () => {
105
+ const node = selectedNode.value;
106
+ if (!node) {
107
+ selectView();
108
+ return;
109
+ }
110
+
111
+ selectNode(findNextNodeUp(node) ?? node.key);
112
+ },
113
+ collapseOrMoveUp: () => {
114
+ const node = selectedNode.value;
115
+ if (!node) {
116
+ selectView();
117
+ return;
118
+ }
119
+
120
+ if (!openNodes.delete(node.key)) {
121
+ selectNode(node.parent()?.key ?? node.key);
122
+ }
123
+ },
124
+ modeDown: () => {
125
+ const node = selectedNode.value;
126
+ if (!node) {
127
+ selectView();
128
+ return;
129
+ }
130
+
131
+ selectNode(findNextNodeDown(node) ?? node.key);
132
+ },
133
+ expandOrMoveDown: () => {
134
+ const node = selectedNode.value;
135
+ if (!node) {
136
+ selectView();
137
+ return;
138
+ }
139
+
140
+ if (node.peekChildren().length === 0 || !openNodes.add(node.key)) {
141
+ selectNode(findNextNodeDown(node) ?? node.key);
142
+ }
143
+ },
144
+ });
145
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "references": [{"path": "../lib/tsconfig.build.json"}],
4
+ "include": ["**/*"]
5
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx",
5
+ "jsxImportSource": "preact",
6
+ "paths": {
7
+ "@canvas-commons/2d": ["../lib"]
8
+ }
9
+ },
10
+ "references": [{"path": "../lib/tsconfig.json"}],
11
+ "include": ["**/*"]
12
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../../../tsdoc.json"]
4
+ }
@@ -0,0 +1,37 @@
1
+ import {signal} from '@preact/signals';
2
+
3
+ export class SignalSet<T> {
4
+ private readonly set = new Set<T>();
5
+ private readonly signal = signal(0);
6
+
7
+ public has(value: T) {
8
+ this.signal.value;
9
+ return this.set.has(value);
10
+ }
11
+
12
+ public peekHas(value: T) {
13
+ return this.set.has(value);
14
+ }
15
+
16
+ public add(value: T): boolean {
17
+ if (this.set.has(value)) {
18
+ return false;
19
+ }
20
+
21
+ this.set.add(value);
22
+ this.signal.value++;
23
+ return true;
24
+ }
25
+
26
+ public delete(value: T): boolean {
27
+ const result = this.set.delete(value);
28
+ if (result) {
29
+ this.signal.value++;
30
+ }
31
+ return result;
32
+ }
33
+
34
+ public toggle(value: T, state: boolean): boolean {
35
+ return state ? this.add(value) : this.delete(value);
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export * from './SignalSet';
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />