@revideo/2d 0.3.7-beta.987 → 0.3.7-blue.987

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/editor/index.css CHANGED
@@ -30,4 +30,4 @@
30
30
  background-color: var(--background-color);
31
31
  border-radius: var(--radius);
32
32
  margin-right: 8px;
33
- }
33
+ }
package/editor/index.js CHANGED
@@ -1,101 +1,71 @@
1
- import {
2
- computed,
3
- signal,
4
- useComputed,
5
- useSignal,
6
- useSignalEffect,
7
- } from '@preact/signals';
8
- import {NODE_NAME} from '@revideo/2d';
9
- import {SceneRenderEvent, Vector2} from '@revideo/core';
10
- import {
11
- AccountTree,
12
- AutoField,
13
- Button,
14
- Collapse,
15
- Group,
16
- Label,
17
- MouseButton,
18
- OverlayWrapper,
19
- Pane,
20
- Separator,
21
- Tab,
22
- Toggle,
23
- UnknownField,
24
- emphasize,
25
- findAndOpenFirstUserFile,
26
- makeEditorPlugin,
27
- useApplication,
28
- useCurrentScene,
29
- usePanels,
30
- useReducedMotion,
31
- useViewportContext,
32
- useViewportMatrix,
33
- } from '@revideo/ui';
34
- import {createContext} from 'preact';
35
- import {useContext, useEffect, useMemo, useRef} from 'preact/hooks';
36
- import {Fragment, jsx, jsxs} from 'preact/jsx-runtime';
1
+ import { useApplication, useCurrentScene, Pane, Separator, Group, Label, Button, findAndOpenFirstUserFile, UnknownField, AutoField, useViewportContext, useViewportMatrix, OverlayWrapper, MouseButton, Toggle, Collapse, usePanels, useReducedMotion, emphasize, Tab, AccountTree, makeEditorPlugin } from '@revideo/ui';
2
+ import { signal, computed, useSignalEffect, useComputed, useSignal } from '@preact/signals';
3
+ import { jsx, jsxs, Fragment } from 'preact/jsx-runtime';
4
+ import { SceneRenderEvent, Vector2 } from '@revideo/core';
5
+ import { createContext } from 'preact';
6
+ import { useMemo, useContext, useRef, useEffect } from 'preact/hooks';
7
+ import { NODE_NAME } from '@revideo/2d';
37
8
  import './index.css';
38
9
 
39
10
  const PluginContext = createContext(null);
40
11
  const NodeInspectorKey = '@revideo/2d/node-inspector';
41
12
  function usePluginState() {
42
- return useContext(PluginContext);
13
+ return useContext(PluginContext);
43
14
  }
44
- function Provider({children}) {
45
- const {inspection} = useApplication();
46
- const currentScene = useCurrentScene();
47
- const state = useMemo(() => {
48
- const scene = signal(currentScene);
49
- const selectedKey = signal(null);
50
- const afterRender = signal(0);
51
- const hoveredKey = signal(null);
52
- const openNodes = new Map();
53
- const selectedChain = computed(() => {
54
- const chain = new Set();
55
- const key = selectedKey.value;
56
- const selectedNode = scene.value?.getNode(key);
57
- if (selectedNode) {
58
- let node = selectedNode.parent() ?? null;
59
- while (node) {
60
- chain.add(node.key);
61
- node = node.parent();
15
+ function Provider({ children }) {
16
+ const { inspection } = useApplication();
17
+ const currentScene = useCurrentScene();
18
+ const state = useMemo(() => {
19
+ const scene = signal(currentScene);
20
+ const selectedKey = signal(null);
21
+ const afterRender = signal(0);
22
+ const hoveredKey = signal(null);
23
+ const openNodes = new Map();
24
+ const selectedChain = computed(() => {
25
+ const chain = new Set();
26
+ const key = selectedKey.value;
27
+ const selectedNode = scene.value?.getNode(key);
28
+ if (selectedNode) {
29
+ let node = selectedNode.parent() ?? null;
30
+ while (node) {
31
+ chain.add(node.key);
32
+ node = node.parent();
33
+ }
34
+ }
35
+ return chain;
36
+ });
37
+ return {
38
+ selectedKey,
39
+ hoveredKey,
40
+ afterRender,
41
+ openNodes,
42
+ selectedChain,
43
+ scene,
44
+ };
45
+ }, []);
46
+ state.scene.value = currentScene;
47
+ useSignalEffect(() => state.scene.value?.onRenderLifecycle.subscribe(([event]) => {
48
+ if (event === SceneRenderEvent.AfterRender) {
49
+ state.afterRender.value++;
50
+ }
51
+ }));
52
+ useSignalEffect(() => {
53
+ const { key, payload } = inspection.value;
54
+ if (key === NodeInspectorKey) {
55
+ state.selectedKey.value = payload;
62
56
  }
63
- }
64
- return chain;
65
57
  });
66
- return {
67
- selectedKey,
68
- hoveredKey,
69
- afterRender,
70
- openNodes,
71
- selectedChain,
72
- scene,
73
- };
74
- }, []);
75
- state.scene.value = currentScene;
76
- useSignalEffect(() =>
77
- state.scene.value?.onRenderLifecycle.subscribe(([event]) => {
78
- if (event === SceneRenderEvent.AfterRender) {
79
- state.afterRender.value++;
80
- }
81
- }),
82
- );
83
- useSignalEffect(() => {
84
- const {key, payload} = inspection.value;
85
- if (key === NodeInspectorKey) {
86
- state.selectedKey.value = payload;
87
- }
88
- });
89
- useSignalEffect(() => {
90
- const nodeKey = state.selectedKey.value;
91
- const {key, payload} = inspection.peek();
92
- if (key === NodeInspectorKey && !nodeKey) {
93
- inspection.value = {key: '', payload: null};
94
- } else if (payload !== nodeKey) {
95
- inspection.value = {key: NodeInspectorKey, payload: nodeKey};
96
- }
97
- });
98
- return jsx(PluginContext.Provider, {value: state, children: children});
58
+ useSignalEffect(() => {
59
+ const nodeKey = state.selectedKey.value;
60
+ const { key, payload } = inspection.peek();
61
+ if (key === NodeInspectorKey && !nodeKey) {
62
+ inspection.value = { key: '', payload: null };
63
+ }
64
+ else if (payload !== nodeKey) {
65
+ inspection.value = { key: NodeInspectorKey, payload: nodeKey };
66
+ }
67
+ });
68
+ return (jsx(PluginContext.Provider, { value: state, children: children }));
99
69
  }
100
70
 
101
71
  function Component$1() {
@@ -168,46 +138,43 @@ const NodeInspectorConfig = {
168
138
  component: Component$1,
169
139
  };
170
140
 
171
- function Component({children}) {
172
- const state = useViewportContext();
173
- const {scene, selectedKey} = usePluginState();
174
- const matrix = useViewportMatrix();
175
- return jsx(OverlayWrapper, {
176
- onPointerDown: event => {
177
- if (event.button !== MouseButton.Left || event.shiftKey) return;
178
- if (!scene.value) return;
179
- event.stopPropagation();
180
- const position = new Vector2(
181
- event.x - state.rect.x,
182
- event.y - state.rect.y,
183
- ).transformAsPoint(matrix.inverse());
184
- selectedKey.value = scene.value.inspectPosition(position.x, position.y);
185
- },
186
- children: children,
187
- });
141
+ function Component({ children }) {
142
+ const state = useViewportContext();
143
+ const { scene, selectedKey } = usePluginState();
144
+ const matrix = useViewportMatrix();
145
+ return (jsx(OverlayWrapper, { onPointerDown: event => {
146
+ if (event.button !== MouseButton.Left || event.shiftKey)
147
+ return;
148
+ if (!scene.value)
149
+ return;
150
+ event.stopPropagation();
151
+ const position = new Vector2(event.x - state.rect.x, event.y - state.rect.y).transformAsPoint(matrix.inverse());
152
+ selectedKey.value = scene.value.inspectPosition(position.x, position.y);
153
+ }, children: children }));
188
154
  }
189
155
  function drawHook() {
190
- const {selectedKey, hoveredKey, afterRender, scene} = usePluginState();
191
- selectedKey.value;
192
- hoveredKey.value;
193
- afterRender.value;
194
- return (ctx, matrix) => {
195
- const currentScene = scene.peek();
196
- if (!currentScene) return;
197
- let node = currentScene.getNode(selectedKey.value);
198
- if (node) {
199
- currentScene.drawOverlay(node.key, matrix, ctx);
200
- }
201
- node = currentScene.getNode(hoveredKey.value);
202
- if (node && hoveredKey.value !== selectedKey.value) {
203
- ctx.globalAlpha = 0.5;
204
- currentScene.drawOverlay(hoveredKey.value, matrix, ctx);
205
- }
206
- };
156
+ const { selectedKey, hoveredKey, afterRender, scene } = usePluginState();
157
+ selectedKey.value;
158
+ hoveredKey.value;
159
+ afterRender.value;
160
+ return (ctx, matrix) => {
161
+ const currentScene = scene.peek();
162
+ if (!currentScene)
163
+ return;
164
+ let node = currentScene.getNode(selectedKey.value);
165
+ if (node) {
166
+ currentScene.drawOverlay(node.key, matrix, ctx);
167
+ }
168
+ node = currentScene.getNode(hoveredKey.value);
169
+ if (node && hoveredKey.value !== selectedKey.value) {
170
+ ctx.globalAlpha = 0.5;
171
+ currentScene.drawOverlay(hoveredKey.value, matrix, ctx);
172
+ }
173
+ };
207
174
  }
208
175
  const PreviewOverlayConfig = {
209
- drawHook,
210
- component: Component,
176
+ drawHook,
177
+ component: Component,
211
178
  };
212
179
 
213
180
  function CircleIcon() {
@@ -391,31 +358,9 @@ const IconMap = {
391
358
  View2D: View2DIcon,
392
359
  };
393
360
 
394
- function r(e) {
395
- var t,
396
- f,
397
- n = '';
398
- if ('string' == typeof e || 'number' == typeof e) n += e;
399
- else if ('object' == typeof e)
400
- if (Array.isArray(e)) {
401
- var o = e.length;
402
- for (t = 0; t < o; t++)
403
- e[t] && (f = r(e[t])) && (n && (n += ' '), (n += f));
404
- } else for (f in e) e[f] && (n && (n += ' '), (n += f));
405
- return n;
406
- }
407
- function clsx() {
408
- for (var e, t, f = 0, n = '', o = arguments.length; f < o; f++)
409
- (e = arguments[f]) && (t = r(e)) && (n && (n += ' '), (n += t));
410
- return n;
411
- }
361
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
412
362
 
413
- var styles = {
414
- root: 'index-module_root__omEd0',
415
- label: 'index-module_label__9BJvW',
416
- active: 'index-module_active__KevXv',
417
- parent: 'index-module_parent__5nc9I',
418
- };
363
+ var styles = {"root":"index-module_root__omEd0","label":"index-module_label__9BJvW","active":"index-module_active__KevXv","parent":"index-module_parent__5nc9I"};
419
364
 
420
365
  const DEPTH_VAR = '--depth';
421
366
  function TreeElement({
@@ -620,5 +565,5 @@ var index = makeEditorPlugin(() => {
620
565
  };
621
566
  });
622
567
 
623
- export {index as default};
568
+ export { index as default };
624
569
  //# sourceMappingURL=index.js.map