@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.
- package/LICENSE +22 -0
- package/editor/index.css +40 -0
- package/editor/index.js +525 -0
- package/editor/index.js.map +1 -0
- package/lib/index-OvpZ-GsA.d.ts +5673 -0
- package/lib/index-OvpZ-GsA.d.ts.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +10326 -0
- package/lib/index.js.map +1 -0
- package/lib/jsx-dev-runtime.d.ts +2 -0
- package/lib/jsx-dev-runtime.js +2 -0
- package/lib/jsx-runtime.d.ts +2 -0
- package/lib/jsx-runtime.js +28 -0
- package/lib/jsx-runtime.js.map +1 -0
- package/package.json +79 -0
- package/src/editor/NodeInspectorConfig.tsx +76 -0
- package/src/editor/PreviewOverlayConfig.tsx +65 -0
- package/src/editor/Provider.tsx +109 -0
- package/src/editor/SceneGraphTabConfig.tsx +87 -0
- package/src/editor/icons/CircleIcon.tsx +7 -0
- package/src/editor/icons/CodeIcon.tsx +8 -0
- package/src/editor/icons/CurveIcon.tsx +7 -0
- package/src/editor/icons/GridIcon.tsx +7 -0
- package/src/editor/icons/IconMap.ts +35 -0
- package/src/editor/icons/ImgIcon.tsx +8 -0
- package/src/editor/icons/LayoutIcon.tsx +9 -0
- package/src/editor/icons/LineIcon.tsx +7 -0
- package/src/editor/icons/NodeIcon.tsx +7 -0
- package/src/editor/icons/RayIcon.tsx +7 -0
- package/src/editor/icons/RectIcon.tsx +7 -0
- package/src/editor/icons/ShapeIcon.tsx +7 -0
- package/src/editor/icons/TxtIcon.tsx +8 -0
- package/src/editor/icons/VideoIcon.tsx +7 -0
- package/src/editor/icons/View2DIcon.tsx +10 -0
- package/src/editor/index.css +0 -0
- package/src/editor/index.ts +19 -0
- package/src/editor/shortcuts.ts +27 -0
- package/src/editor/tree/DetachedRoot.tsx +27 -0
- package/src/editor/tree/NodeElement.tsx +72 -0
- package/src/editor/tree/TreeElement.tsx +70 -0
- package/src/editor/tree/TreeRoot.tsx +10 -0
- package/src/editor/tree/ViewRoot.tsx +20 -0
- package/src/editor/tree/index.module.scss +45 -0
- package/src/editor/tree/index.ts +4 -0
- package/src/editor/tree/navigation.ts +145 -0
- package/src/editor/tsconfig.build.json +5 -0
- package/src/editor/tsconfig.json +12 -0
- package/src/editor/tsdoc.json +4 -0
- package/src/editor/utils/SignalSet.ts +37 -0
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/vite-env.d.ts +1 -0
- package/src/lib/code/CodeCursor.ts +468 -0
- package/src/lib/code/CodeDiffer.ts +77 -0
- package/src/lib/code/CodeFragment.ts +96 -0
- package/src/lib/code/CodeHighlighter.ts +73 -0
- package/src/lib/code/CodeMetrics.ts +47 -0
- package/src/lib/code/CodeRange.test.ts +113 -0
- package/src/lib/code/CodeRange.ts +222 -0
- package/src/lib/code/CodeScope.ts +100 -0
- package/src/lib/code/CodeSelection.ts +28 -0
- package/src/lib/code/CodeSignal.ts +348 -0
- package/src/lib/code/CodeTokenizer.ts +54 -0
- package/src/lib/code/DefaultHighlightStyle.ts +98 -0
- package/src/lib/code/LezerHighlighter.ts +113 -0
- package/src/lib/code/diff.test.ts +311 -0
- package/src/lib/code/diff.ts +319 -0
- package/src/lib/code/extractRange.ts +125 -0
- package/src/lib/code/index.ts +13 -0
- package/src/lib/components/Bezier.ts +103 -0
- package/src/lib/components/Camera.ts +401 -0
- package/src/lib/components/Circle.ts +310 -0
- package/src/lib/components/Code.ts +532 -0
- package/src/lib/components/CubicBezier.ts +115 -0
- package/src/lib/components/Curve.ts +460 -0
- package/src/lib/components/Grid.ts +134 -0
- package/src/lib/components/Icon.ts +153 -0
- package/src/lib/components/Img.ts +328 -0
- package/src/lib/components/Knot.ts +156 -0
- package/src/lib/components/Latex.ts +537 -0
- package/src/lib/components/Layout.ts +1101 -0
- package/src/lib/components/Line.ts +394 -0
- package/src/lib/components/Node.ts +1941 -0
- package/src/lib/components/Path.ts +132 -0
- package/src/lib/components/Polygon.ts +266 -0
- package/src/lib/components/QuadBezier.ts +103 -0
- package/src/lib/components/Ray.ts +126 -0
- package/src/lib/components/Rect.ts +219 -0
- package/src/lib/components/SVG.ts +853 -0
- package/src/lib/components/Shape.ts +322 -0
- package/src/lib/components/Spline.ts +318 -0
- package/src/lib/components/Txt.test.tsx +81 -0
- package/src/lib/components/Txt.ts +204 -0
- package/src/lib/components/TxtLeaf.ts +210 -0
- package/src/lib/components/Video.ts +368 -0
- package/src/lib/components/View2D.ts +85 -0
- package/src/lib/components/__logs__/image-without-source.ts +18 -0
- package/src/lib/components/__logs__/line-without-points.ts +31 -0
- package/src/lib/components/__logs__/reactive-playback-rate.ts +22 -0
- package/src/lib/components/__logs__/spline-with-insufficient-knots.ts +25 -0
- package/src/lib/components/__tests__/Camera.test.tsx +73 -0
- package/src/lib/components/__tests__/children.test.tsx +142 -0
- package/src/lib/components/__tests__/clone.test.tsx +126 -0
- package/src/lib/components/__tests__/fontInheritance.test.tsx +102 -0
- package/src/lib/components/__tests__/generatorTest.ts +27 -0
- package/src/lib/components/__tests__/mockScene2D.ts +50 -0
- package/src/lib/components/__tests__/query.test.tsx +122 -0
- package/src/lib/components/__tests__/state.test.tsx +60 -0
- package/src/lib/components/index.ts +26 -0
- package/src/lib/components/types.ts +35 -0
- package/src/lib/curves/ArcSegment.ts +169 -0
- package/src/lib/curves/CircleSegment.ts +99 -0
- package/src/lib/curves/CubicBezierSegment.ts +80 -0
- package/src/lib/curves/CurveDrawingInfo.ts +11 -0
- package/src/lib/curves/CurvePoint.ts +15 -0
- package/src/lib/curves/CurveProfile.ts +28 -0
- package/src/lib/curves/KnotInfo.ts +10 -0
- package/src/lib/curves/LineSegment.ts +75 -0
- package/src/lib/curves/Polynomial.ts +355 -0
- package/src/lib/curves/Polynomial2D.ts +62 -0
- package/src/lib/curves/PolynomialSegment.ts +151 -0
- package/src/lib/curves/QuadBezierSegment.ts +66 -0
- package/src/lib/curves/Segment.ts +31 -0
- package/src/lib/curves/UniformPolynomialCurveSampler.ts +93 -0
- package/src/lib/curves/createCurveProfileLerp.ts +471 -0
- package/src/lib/curves/getBezierSplineProfile.ts +227 -0
- package/src/lib/curves/getCircleProfile.ts +86 -0
- package/src/lib/curves/getPathProfile.ts +177 -0
- package/src/lib/curves/getPointAtDistance.ts +21 -0
- package/src/lib/curves/getPolylineProfile.test.ts +21 -0
- package/src/lib/curves/getPolylineProfile.ts +88 -0
- package/src/lib/curves/getRectProfile.ts +138 -0
- package/src/lib/curves/index.ts +16 -0
- package/src/lib/decorators/canvasStyleSignal.ts +15 -0
- package/src/lib/decorators/colorSignal.ts +9 -0
- package/src/lib/decorators/compound.ts +85 -0
- package/src/lib/decorators/computed.ts +18 -0
- package/src/lib/decorators/defaultStyle.ts +15 -0
- package/src/lib/decorators/filtersSignal.ts +133 -0
- package/src/lib/decorators/index.ts +10 -0
- package/src/lib/decorators/initializers.ts +32 -0
- package/src/lib/decorators/nodeName.ts +13 -0
- package/src/lib/decorators/signal.test.ts +89 -0
- package/src/lib/decorators/signal.ts +348 -0
- package/src/lib/decorators/spacingSignal.ts +15 -0
- package/src/lib/decorators/transformSignals.test.ts +858 -0
- package/src/lib/decorators/transformSignals.ts +1633 -0
- package/src/lib/decorators/vector2Signal.ts +35 -0
- package/src/lib/globals.d.ts +2 -0
- package/src/lib/index.ts +9 -0
- package/src/lib/jsx-dev-runtime.ts +2 -0
- package/src/lib/jsx-runtime.ts +45 -0
- package/src/lib/morphers/PathMorpher.ts +8 -0
- package/src/lib/morphers/defaultMorpher.ts +43 -0
- package/src/lib/morphers/index.ts +4 -0
- package/src/lib/morphers/manimMorpher.ts +658 -0
- package/src/lib/parse-svg-path.d.ts +14 -0
- package/src/lib/partials/Filter.ts +185 -0
- package/src/lib/partials/Gradient.ts +103 -0
- package/src/lib/partials/Pattern.ts +35 -0
- package/src/lib/partials/RoughConfig.ts +180 -0
- package/src/lib/partials/ShaderConfig.ts +122 -0
- package/src/lib/partials/index.ts +5 -0
- package/src/lib/partials/types.ts +58 -0
- package/src/lib/scenes/Scene2D.ts +167 -0
- package/src/lib/scenes/index.ts +3 -0
- package/src/lib/scenes/makeScene2D.ts +19 -0
- package/src/lib/scenes/useScene2D.ts +6 -0
- package/src/lib/tsconfig.build.json +5 -0
- package/src/lib/tsconfig.json +11 -0
- package/src/lib/tsdoc.json +4 -0
- package/src/lib/utils/CanvasUtils.ts +304 -0
- package/src/lib/utils/PathDataBuilder.ts +320 -0
- package/src/lib/utils/diff.test.ts +453 -0
- package/src/lib/utils/diff.ts +148 -0
- package/src/lib/utils/index.ts +5 -0
- package/src/lib/utils/is.ts +11 -0
- package/src/lib/utils/makeSignalExtensions.ts +29 -0
- package/src/lib/utils/rough.ts +513 -0
- package/src/lib/utils/withDefaults.tsx +26 -0
- package/src/tsconfig.base.json +18 -0
- package/src/tsconfig.build.json +8 -0
- package/src/tsconfig.json +5 -0
- 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,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,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" />
|