Skip to content

AI-native design editor. Open-source Figma alternative.

Reorganize Vue SDK modules by domain

Danila Poyarkov0a770248a230
diff --git a/REFACTOR.md b/REFACTOR.md
deleted file mode 100644
index 8a5698a86..000000000
--- a/REFACTOR.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# Refactoring Roadmap
-
-Status of all items from the codebase audit.
-
-## πŸ”΄ Critical (Architectural Debt)
-
-### 1. `src/stores/editor.ts` β€” was 2,505 lines
-
-**Status:** βœ… Done β€” extracted to `packages/core/src/editor/` (15 modules). App store is 570 lines, spreads `Editor` + adds file I/O, export, flash effects.
-
-### 2. `src/composables/use-canvas-input.ts` β€” was 1,501 lines
-
-**Status:** βœ… Done β€” split into 5 modules in `packages/vue/src/input/` (types, geometry, pan-zoom, resize, auto-layout). Orchestrator: 815 lines.
-
-### 3. State is fully mutable to all consumers
-
-**Status:** πŸ”œ Deferred β€” `shallowReadonly` + setter methods. Low priority since SDK composables now type against `Editor` not raw state.
-
-## 🟑 Medium (Code Quality)
-
-### 4. Fire-and-forget async calls β€” 10+ unhandled
-
-**Status:** πŸ”œ Deferred β€” needs `safeFire()` helper.
-
-### 5. Module-level state in composables
-
-**Status:** πŸ”œ Deferred β€” `use-chat.ts` and `use-menu.ts` are app-specific, low urgency.
-
-### 6. Bounding-box computation duplicated ~10 times
-
-**Status:** βœ… Done β€” `computeBounds()` added to geometry.ts. snap.ts deduplicated with `rotatedBBox()`.
-
-### 7. "Node not found" guard repeated 44 times in tools
-
-**Status:** βœ… Partially done β€” `requireNode()` + `NodeNotFoundError` added to tools/schema.ts. Tool-by-tool adoption is incremental.
-
-### 8. Barrel import overuse
-
-**Status:** πŸ”œ Deferred β€” gradual migration to subpath imports.
-
-### 9. `kiwi-serialize.ts` misplaced
-
-**Status:** βœ… Done β€” moved to `packages/core/src/kiwi/kiwi-serialize.ts`.
-
-### 10. `tools/stock-photo.ts` throws instead of returning `{ error }`
-
-**Status:** βœ… Already correct β€” exports use `return { error }`, throws are internal only.
-
-## 🟒 Low Priority (Polish)
-
-### 11. Large Vue components (8 over 300 lines)
-
-**Status:** πŸ”œ Deferred β€” split incrementally.
-
-### 12. Icon import bloat
-
-**Status:** πŸ”œ Deferred.
-
-### 13. Unscoped `<style>` in `CodePanel.vue`
-
-**Status:** βœ… Done β€” scoped.
-
-### 14. Dead exports
-
-**Status:** βœ… Done β€” removed `createPropertyChange` from undo.ts, un-exported `queryFonts`/`FontInfo` from fonts.ts. `copy*` functions kept (tested).
-
-### 15. Renderer circular imports
-
-**Status:** βœ… Not actionable β€” type-only imports, no runtime cycles.
-
-### 16. Duplicate font weight maps
-
-**Status:** βœ… Done β€” single `FONT_WEIGHT_NAMES` in fonts.ts, figma-api-proxy.ts imports from there.
-
-### 17. Rotated corners reimplemented
-
-**Status:** βœ… Done β€” snap.ts now uses `rotatedBBox()` from geometry.ts. overlays.ts kept (different β€” screen coords).
-
-### 18. Duplicate .fig scaffold/zip assembly
-
-**Status:** βœ… Done β€” zip assembly extracted to `fig-compress.ts`. DOCUMENT scaffold intentionally different (clipboard vs full export).
-
-### 19. Group/Frame/Component/ComponentSet creation β€” 4Γ— copy-paste
-
-**Status:** βœ… Already fixed β€” `wrapSelectionInContainer()` in structure.ts handles all 4 types.
-
-### 20. `console.warn`/`console.error` (30 total)
-
-**Status:** πŸ”œ Deferred β€” all legitimate error handlers, structured logger is a nice-to-have.
-
-## Additional work completed
-
-- **vue-tsc errors**: Fixed all 135, now a check gate (was never checked before)
-- **`@open-pencil/vue` SDK**: Headless package with renderless components plus shared editor composables for selection, commands, viewport, and menu models
-- **SDK command spine**: `useSelectionCapabilities()`, `useEditorCommands()`, `useViewportKind()`, `useMenuModel()` now power keyboard/menu/context-menu flows
-- **App UI primitives cleanup**: base app-styled components moved under `src/components/ui/`, `ui` prop adopted for grouped/simple selects, lightweight `useComponentUI()` added and expanded into button/input/icon-button helpers; slot helpers now have `useMenuUI()`, `usePopoverUI()`, `useDialogUI()`, `useTooltipUI()`, `useSelectUI()`
-- **Formatter restored**: `.oxfmtrc.json` recovered from git history, import sorting restored, formatting now covers all packages
-- **Editor variable actions**: 7 undo-able CRUD operations, wired into VariablesDialog
-- **Editor alignment actions**: alignNodes, flipNodes, rotateNodes, wired into PositionSection
-- **`updateNodeWithUndo` auto-renders**: eliminated 15+ redundant requestRender() calls
-- **Merged `useNodeProps` + `useMultiProps`**: single composable, no duplicate computed refs
-- **`toolCursor()` utility**: replaces if/else chain
-- **`toast.ts` rename**: singleton module, not a composable
-- **`computeBounds()` utility**: bounding box helper in geometry.ts
-- **`requireNode()` helper**: for tool guard patterns
-- **`tsgo --noEmit`**: added to check script
-- **EditorStore simplified**: spreads Editor instead of listing 80+ methods manually
diff --git a/SDK-PLAN.md b/SDK-PLAN.md
deleted file mode 100644
index 7587a2db0..000000000
--- a/SDK-PLAN.md
+++ /dev/null
@@ -1,188 +0,0 @@
-# @open-pencil/vue SDK Redesign Plan
-
-Goal: Reka UI-style headless components for building editors like OpenPencil.
-OpenPencil app becomes a styled composition of these primitives.
-
-## Principles
-
-1. Every app component maps to an SDK headless primitive
-2. Reka UI naming: `XxxRoot`, `XxxItem`, `XxxTrigger` with `v-slot`
-3. No app opinions β€” no icons, cursors, toast, constants, styling
-4. Composable over component when headless (no DOM = composable)
-5. App = styled SDK composition
-
-## SDK Component Inventory
-
-### Canvas
-
-| SDK | Type | Slot props / API |
-|-----|------|-----------------|
-| `CanvasRoot` | Component | Provides editor context + canvas lifecycle |
-| `CanvasSurface` | Component | `<canvas>` with render loop, `@ready` event |
-| `useCanvasInput()` | Composable | Mouse/touch/gesture, cursor override |
-| `usePanZoom()` | Composable | Wheel, pinch, pan |
-| `useTextEdit()` | Composable | Text editing, IME, caret |
-| `useCanvasDrop()` | Composable | File drag-and-drop |
-
-### Layers
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `LayerTreeRoot` | Component | Tree data, expand/collapse, selection |
-| `LayerTreeItem` | Component | DnD, rename, visibility, lock per row |
-
-### Pages
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `PageList` | Component | pages, currentPageId, switchPage, addPage, deletePage |
-
-### Toolbar
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `ToolbarRoot` | Component | activeTool, tools, flyouts |
-| `ToolbarItem` | Component | active state, select handler |
-
-### Properties
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `useNodeProps()` | Composable | Selection-aware property editing with undo |
-| `PositionControls` | Component | x, y, w, h, rotation, alignment actions |
-| `FillControlsRoot` | Component | fill CRUD, variable binding helpers |
-| `StrokeControlsRoot` | Component | stroke align/side/weight helpers |
-| `EffectsControlsRoot` | Component | effect defaults, scrub/commit helpers |
-| `AppearanceControlsRoot` | Component | corner radius, opacity, visibility helpers |
-| `TypographyControlsRoot` | Component | font family/weight/size, alignment, decoration helpers |
-| `LayoutControlsRoot` | Component | auto-layout/grid, sizing, padding, alignment helpers |
-| `ExportControls` | Component | Format/scale, export trigger |
-| `PageControls` | Component | Page background color |
-| `VariablesIndicator` | Component | Variable count |
-
-### Color
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `FillPickerRoot` | Component | Fill type tabs, delegates to sub-pickers |
-| `GradientEditorRoot` | Component | Stops, subtype |
-| `GradientEditorBar` | Component | Draggable stop bar |
-| `GradientEditorStop` | Component | Single stop |
-| `ImageFillControls` | Component | Preview, file picker, scale mode |
-| `ColorPickerRoot` | Component | Color popover |
-| `ColorInput` | Component | Swatch + hex |
-
-### Variables
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `VariablesEditorRoot` | Component | collections, active tab/search state, table instance, collection actions |
-
-### Menus
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `useEditorCommands()` | Composable | Typed command registry, enablement, run helpers |
-| `useMenuModel()` | Composable | Renderless menu trees for app/context/mobile menus |
-| `EditorContextMenu` | Component | Optional thin renderer over `useMenuModel().canvasMenu` |
-| `EditorMenuBar` | Component | Optional thin renderer over `useMenuModel().appMenu` |
-
-### Inputs
-
-| SDK | Type | Slot props |
-|-----|------|-----------|
-| `ScrubInput` | Component | Drag-to-change number input |
-| `FontPickerRoot` | Component | Font family combobox behavior + slots |
-
-### Composables (existing, keep)
-
-| SDK | Purpose |
-|-----|---------|
-| `useEditor()` | Inject editor |
-| `useSelectionState()` | Reactive selection queries |
-| `useSelectionCapabilities()` | Selection-aware command enablement |
-| `useEditorCommands()` | Shared command execution layer |
-| `useMenuModel()` | Renderless menu data model |
-| `useViewportKind()` | Shared mobile/desktop breakpoint state |
-| `useNodeProps()` | Property editing with undo |
-| `useInlineRename()` | Inline rename input |
-| `useLayerDrag()` | Atlaskit tree DnD |
-| `useFontStatus()` | Font loading state |
-
-## NOT in SDK (app-specific)
-
-- `chat/` (6 files) β€” AI providers, ACP
-- `CollabPanel` β€” P2P/Yjs
-- `MobileHud`, `MobileDrawer` β€” app mobile layout
-- `SafariBanner` β€” browser detection
-- `TabBar` β€” multi-tab files
-- `AppToast` β€” toast styling
-- `CodePanel` β€” JSX generation
-- `use-collab.ts`, `use-chat.ts`, `use-keyboard.ts`, `use-menu.ts`
-- app-styled UI primitives in `src/components/ui/` (`AppSelect`, `AppGroupedSelect`, `Tip`, style helpers) stay outside SDK unless rewritten as headless/generic primitives
-
-## Migration Phases
-
-### Phase 1: Establish pattern (3 exemplars)
-- `ScrubInput` β€” pure UI, no editor dep
-- `PageList` β€” clean up existing
-- `ToolbarRoot`/`ToolbarItem` β€” headless tool selector
-
-### Phase 2: Canvas primitives
-- `CanvasRoot`/`CanvasSurface`
-- Clean `useCanvasInput`, `usePanZoom`, `useTextEdit`, `useCanvasDrop`
-
-### Phase 3: Property primitives
-- βœ… `FillControlsRoot`, `StrokeControlsRoot`, `EffectsControlsRoot`
-- βœ… `PositionControlsRoot`, `AppearanceControlsRoot`, `TypographyControlsRoot`, `LayoutControlsRoot`
-- βœ… `FontPickerRoot`
-- Next: tighten slot APIs and decide whether `ColorInput` / richer fill picker pieces belong in SDK
-
-### Phase 4: Layer tree primitives
-- `LayerTreeRoot`/`LayerTreeItem` with Atlaskit DnD
-- Rename, selection sync
-
-### Phase 5: Menu primitives
-- βœ… `useEditorCommands()`
-- βœ… `useMenuModel()`
-- Next: optional `EditorContextMenu`, `EditorMenuBar` renderers once app-side host overrides settle
-
-### Phase 6: Dialog/picker primitives
-- βœ… `VariablesEditorRoot`
-- `FillPickerRoot`, `GradientEditorRoot`, `ImageFillControls`
-- `ExportControls`
-
-### Phase 7: App migration
-- Rewrite every app component as styled SDK composition
-- App files = styling + layout only
-
-## Current status
-
-Completed:
-- `useSelectionCapabilities()`
-- `useEditorCommands()`
-- `useViewportKind()`
-- `useMenuModel()`
-- `FontPickerRoot`
-- `PageListRoot`
-- `PositionControlsRoot`
-- `TypographyControlsRoot`
-- `AppearanceControlsRoot`
-- `LayoutControlsRoot`
-- `FillControlsRoot`
-- `StrokeControlsRoot`
-- `EffectsControlsRoot`
-- `VariablesEditorRoot`
-- `CanvasMenu.vue` partly rendered from SDK menu model
-- `AppMenu.vue` partly rendered from SDK menu model
-- keyboard shortcuts migrated to shared command execution for core editor actions
-
-Next recommended steps:
-1. Tighten SDK slot APIs to avoid broad "ctx dump" slot objects where possible
-2. Continue peeling reusable editor logic from root components into shared composables (`useVariablesEditor`, fill/effect/stroke helpers, etc.)
-3. Decide whether `ColorInput`, `FillPickerRoot`, and image/gradient subcontrols should move into SDK next
-4. Standardize remaining app primitives on the `ui` + `useComponentUI()` pattern, preferring semantic slot overrides over raw class props
-5. Continue moving app-styled reusable components into `src/components/ui/`
-6. Normalize slot-based style helpers (`menu`, `dialog`, `popover`, `tooltip`, `select`) around the same override conventions
-7. Move remaining `MobileHud` menu/action groups behind command/menu abstractions
-8. Decide whether `EditorContextMenu` / `EditorMenuBar` should exist as SDK renderers or stay as app renderers over SDK data
diff --git a/packages/vue/ARCHITECTURE.md b/packages/vue/ARCHITECTURE.md
new file mode 100644
index 000000000..f83ad0470
--- /dev/null
+++ b/packages/vue/ARCHITECTURE.md
@@ -0,0 +1,23 @@
+# @open-pencil/vue architecture
+
+## Folder conventions
+
+- `Canvas/`, `ColorPicker/`, `FillPicker/`, `FontPicker/`, `GradientEditor/`, `LayerTree/`, `PageList/`, `PropertyList/`, `ScrubInput/`, `Toolbar/` β€” component families and colocated helpers for structural/headless primitives
+- `controls/` β€” editor control composables used by app property panels (`useAppearance`, `useLayout`, `usePosition`, `useTypography`, `useFillControls`, `useStrokeControls`, `useEffectsControls`, `useExport`, `useNodeProps`, `usePropScrub`)
+- `VariablesEditor/` β€” variables domain composables and table wiring
+- `selection/` β€” selection-focused composables (`useSelectionState`, `useSelectionCapabilities`)
+- `context/` β€” dependency injection helpers (`editorContext`, `createContext`)
+- `internal/` β€” cross-cutting internals not intended as primary public primitives (`useSceneComputed`, `toolCursor`)
+- `shared/` β€” remaining cross-domain helpers that are still generic and not yet better served by a domain folder
+
+## Naming conventions
+
+- Composable filenames match export names: `useFillControls.ts`, `useVariablesEditor.ts`
+- Structural primitives follow Reka-style anatomy naming: `XxxRoot`, `XxxItem`, `XxxTrigger`
+- Prefer composables over thin root wrappers when there is no meaningful structural UI coordination
+
+## Public API guidance
+
+- Export stable, intentional entry points from `src/index.ts`
+- Prefer composables for property-panel/editor logic
+- Prefer component families for true headless UI primitives with internal coordination
diff --git a/packages/vue/src/Canvas/CanvasRoot.vue b/packages/vue/src/Canvas/CanvasRoot.vue
index b56449b79..a65d63a18 100644
--- a/packages/vue/src/Canvas/CanvasRoot.vue
+++ b/packages/vue/src/Canvas/CanvasRoot.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref } from 'vue'
-import { useEditor } from '../shared/editorContext'
+import { useEditor } from '../context/editorContext'
import { useCanvas } from '../shared/useCanvas'
import { provideCanvas } from './context'
@@ -18,7 +18,12 @@ const ready = ref(false)
const { renderNow, hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle } = useCanvas(
canvasRef,
editor,
- { ...props, onReady: () => { ready.value = true } }
+ {
+ ...props,
+ onReady: () => {
+ ready.value = true
+ }
+ }
)
provideCanvas({
@@ -32,9 +37,5 @@ provideCanvas({
</script>
<template>
- <slot
- :canvas-ref="canvasRef"
- :ready="ready"
- :render-now="renderNow"
- />
+ <slot :canvas-ref="canvasRef" :ready="ready" :render-now="renderNow" />
</template>
diff --git a/packages/vue/src/Canvas/CanvasSurface.vue b/packages/vue/src/Canvas/CanvasSurface.vue
index 2b20ceb1e..a18281c55 100644
--- a/packages/vue/src/Canvas/CanvasSurface.vue
+++ b/packages/vue/src/Canvas/CanvasSurface.vue
@@ -5,7 +5,14 @@ const { canvasRef } = useCanvasContext()
</script>
<template>
- <canvas :ref="(el) => { canvasRef = el as HTMLCanvasElement | null }" v-bind="$attrs" />
+ <canvas
+ :ref="
+ (el) => {
+ canvasRef = el as HTMLCanvasElement | null
+ }
+ "
+ v-bind="$attrs"
+ />
</template>
<script lang="ts">
diff --git a/packages/vue/src/shared/useCanvasDrop.ts b/packages/vue/src/Canvas/useCanvasDrop.ts
similarity index 100%
rename from packages/vue/src/shared/useCanvasDrop.ts
rename to packages/vue/src/Canvas/useCanvasDrop.ts
diff --git a/packages/vue/src/shared/useCanvasInput.ts b/packages/vue/src/Canvas/useCanvasInput.ts
similarity index 95%
rename from packages/vue/src/shared/useCanvasInput.ts
rename to packages/vue/src/Canvas/useCanvasInput.ts
index d8ea17e1a..ac41fa9d0 100644
--- a/packages/vue/src/shared/useCanvasInput.ts
+++ b/packages/vue/src/Canvas/useCanvasInput.ts
@@ -9,17 +9,21 @@ import {
degToRad
} from '@open-pencil/core'
-import type { Editor } from '@open-pencil/core/editor'
-import type { SceneNode } from '@open-pencil/core'
+import { handleDrawMove, handleDrawUp } from '../shared/input/draw'
+import { hitTestCornerRotation } from '../shared/input/geometry'
+import { handleMoveMove, handleMoveUp } from '../shared/input/move'
+import { setupPanZoom } from '../shared/input/pan-zoom'
+import { applyResize } from '../shared/input/resize'
+import {
+ handleSelectDown,
+ updateHoverCursor,
+ type HitTestFns
+} from '../shared/input/select'
+import { TOOL_TO_NODE } from '../shared/input/types'
-import type { DragMarquee, DragPan, DragRotate, DragState } from './input/types'
-import { TOOL_TO_NODE } from './input/types'
-import { hitTestCornerRotation } from './input/geometry'
-import { setupPanZoom } from './input/pan-zoom'
-import { applyResize } from './input/resize'
-import { handleMoveMove, handleMoveUp } from './input/move'
-import { handleSelectDown, updateHoverCursor, type HitTestFns } from './input/select'
-import { handleDrawMove, handleDrawUp } from './input/draw'
+import type { DragMarquee, DragPan, DragRotate, DragState } from '../shared/input/types'
+import type { SceneNode } from '@open-pencil/core'
+import type { Editor } from '@open-pencil/core/editor'
export function useCanvasInput(
canvasRef: Ref<HTMLCanvasElement | null>,
@@ -272,8 +276,16 @@ export function useCanvasInput(
if (tool === 'SELECT') {
handleSelectDown(
- e, sx, sy, cx, cy, editor, hitFns,
- tryStartRotation, handleTextEditClick, setDrag
+ e,
+ sx,
+ sy,
+ cx,
+ cy,
+ editor,
+ hitFns,
+ tryStartRotation,
+ handleTextEditClick,
+ setDrag
)
return
}
diff --git a/packages/vue/src/shared/useTextEdit.ts b/packages/vue/src/Canvas/useTextEdit.ts
similarity index 100%
rename from packages/vue/src/shared/useTextEdit.ts
rename to packages/vue/src/Canvas/useTextEdit.ts
index e2c53fec3..383cfbd93 100644
--- a/packages/vue/src/shared/useTextEdit.ts
+++ b/packages/vue/src/Canvas/useTextEdit.ts
@@ -9,8 +9,8 @@ import {
toggleItalicInRange
} from '@open-pencil/core'
-import type { Editor } from '@open-pencil/core/editor'
import type { SceneNode } from '@open-pencil/core'
+import type { Editor } from '@open-pencil/core/editor'
const CARET_BLINK_MS = 530
diff --git a/packages/vue/src/EffectsControls/EffectsControlsRoot.vue b/packages/vue/src/EffectsControls/EffectsControlsRoot.vue
deleted file mode 100644
index 345963bba..000000000
--- a/packages/vue/src/EffectsControls/EffectsControlsRoot.vue
+++ /dev/null
@@ -1,119 +0,0 @@
-<script setup lang="ts">
-import { ref } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-
-import type { Color, Effect, SceneNode } from '@open-pencil/core'
-
-type EffectType = Effect['type']
-
-const editor = useEditor()
-
-const expandedIndex = ref<number | null>(null)
-const effectsBeforeScrub = ref<Effect[] | null>(null)
-
-const EFFECT_LABELS: Record<string, string> = {
- DROP_SHADOW: 'Drop shadow',
- INNER_SHADOW: 'Inner shadow',
- LAYER_BLUR: 'Layer blur',
- BACKGROUND_BLUR: 'Background blur',
- FOREGROUND_BLUR: 'Foreground blur'
-}
-
-const EFFECT_TYPES = Object.keys(EFFECT_LABELS) as EffectType[]
-const effectOptions = EFFECT_TYPES.map((t) => ({ value: t, label: EFFECT_LABELS[t] }))
-
-function isShadow(type: string) {
- return type === 'DROP_SHADOW' || type === 'INNER_SHADOW'
-}
-
-function defaultEffect(): Effect {
- return {
- type: 'DROP_SHADOW',
- color: { r: 0, g: 0, b: 0, a: 0.25 },
- offset: { x: 0, y: 4 },
- radius: 4,
- spread: 0,
- visible: true
- }
-}
-
-function scrubEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
- if (!node) return
- if (!effectsBeforeScrub.value) {
- effectsBeforeScrub.value = node.effects.map((e) => ({
- ...e,
- color: { ...e.color },
- offset: { ...e.offset }
- }))
- }
- const effects = [...node.effects]
- effects[index] = { ...effects[index], ...changes }
- editor.updateNode(node.id, { effects })
- editor.requestRender()
-}
-
-function commitEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
- if (!node) return
- const previous = effectsBeforeScrub.value
- effectsBeforeScrub.value = null
- const effects = [...node.effects]
- effects[index] = { ...effects[index], ...changes }
- editor.updateNode(node.id, { effects })
- editor.requestRender()
- if (previous) {
- editor.commitNodeUpdate(node.id, { effects: previous }, 'Change effect')
- }
-}
-
-function updateType(
- patch: (index: number, changes: Partial<Effect>) => void,
- node: SceneNode | null,
- index: number,
- type: EffectType
-) {
- if (!node) return
- const changes: Partial<Effect> = { type }
- if (!isShadow(type)) {
- changes.offset = { x: 0, y: 0 }
- changes.spread = 0
- } else if (!isShadow(node.effects[index].type)) {
- changes.offset = { x: 0, y: 4 }
- changes.spread = 0
- }
- patch(index, changes)
-}
-
-function updateColor(
- patch: (index: number, changes: Partial<Effect>) => void,
- index: number,
- color: Color
-) {
- patch(index, { color })
-}
-
-function handleRemove(removeFn: (index: number) => void, index: number) {
- removeFn(index)
- if (expandedIndex.value === index) expandedIndex.value = null
- else if (expandedIndex.value !== null && expandedIndex.value > index) expandedIndex.value--
-}
-
-function toggleExpand(index: number) {
- expandedIndex.value = expandedIndex.value === index ? null : index
-}
-</script>
-
-<template>
- <slot
- :expanded-index="expandedIndex"
- :effect-options="effectOptions"
- :default-effect="defaultEffect()"
- :is-shadow="isShadow"
- :scrub-effect="scrubEffect"
- :commit-effect="commitEffect"
- :update-type="updateType"
- :update-color="updateColor"
- :handle-remove="handleRemove"
- :toggle-expand="toggleExpand"
- />
-</template>
diff --git a/packages/vue/src/EffectsControls/index.ts b/packages/vue/src/EffectsControls/index.ts
deleted file mode 100644
index 01c50f3eb..000000000
--- a/packages/vue/src/EffectsControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as EffectsControlsRoot } from './EffectsControlsRoot.vue'
diff --git a/packages/vue/src/FillControls/FillControlsRoot.vue b/packages/vue/src/FillControls/FillControlsRoot.vue
deleted file mode 100644
index d9ee7766b..000000000
--- a/packages/vue/src/FillControls/FillControlsRoot.vue
+++ /dev/null
@@ -1,20 +0,0 @@
-<script setup lang="ts">
-import { DEFAULT_SHAPE_FILL } from '@open-pencil/core'
-
-import { useFillVariableBinding } from '../shared/use-fill-variable-binding'
-
-const ctx = useFillVariableBinding()
-</script>
-
-<template>
- <slot
- :store="ctx.store"
- :default-fill="DEFAULT_SHAPE_FILL"
- :color-variables="ctx.colorVariables.value"
- :search-term="ctx.searchTerm.value"
- :filtered-variables="ctx.filteredVariables.value"
- :get-bound-variable="ctx.getBoundVariable"
- :bind-fill-variable="ctx.bindFillVariable"
- :unbind-fill-variable="ctx.unbindFillVariable"
- />
-</template>
diff --git a/packages/vue/src/FillControls/index.ts b/packages/vue/src/FillControls/index.ts
deleted file mode 100644
index 514f63c1a..000000000
--- a/packages/vue/src/FillControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as FillControlsRoot } from './FillControlsRoot.vue'
diff --git a/packages/vue/src/FillPicker/FillPickerRoot.vue b/packages/vue/src/FillPicker/FillPickerRoot.vue
index 81b64943d..fd56e9fff 100644
--- a/packages/vue/src/FillPicker/FillPickerRoot.vue
+++ b/packages/vue/src/FillPicker/FillPickerRoot.vue
@@ -2,7 +2,7 @@
import { computed } from 'vue'
import { PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
-import { useFillPicker } from '../shared/useFillPicker'
+import { useFillPicker } from '../FillPicker/useFillPicker'
import type { Fill } from '@open-pencil/core'
diff --git a/packages/vue/src/shared/useFillPicker.ts b/packages/vue/src/FillPicker/useFillPicker.ts
similarity index 95%
rename from packages/vue/src/shared/useFillPicker.ts
rename to packages/vue/src/FillPicker/useFillPicker.ts
index 2b9e58376..1f3a005af 100644
--- a/packages/vue/src/shared/useFillPicker.ts
+++ b/packages/vue/src/FillPicker/useFillPicker.ts
@@ -1,4 +1,5 @@
import { computed, type Ref } from 'vue'
+
import { colorToCSS } from '@open-pencil/core'
import type { Fill, GradientStop } from '@open-pencil/core'
@@ -18,10 +19,7 @@ function gradientCSS(stops: GradientStop[]): string {
return stops.map((s) => `${colorToCSS(s.color)} ${s.position * 100}%`).join(', ')
}
-export function useFillPicker(
- fill: Ref<Fill>,
- onUpdate: (fill: Fill) => void
-) {
+export function useFillPicker(fill: Ref<Fill>, onUpdate: (fill: Fill) => void) {
const category = computed(() => FILL_CATEGORY[fill.value.type] ?? 'SOLID')
function toSolid() {
diff --git a/packages/vue/src/FontPicker/FontPickerRoot.vue b/packages/vue/src/FontPicker/FontPickerRoot.vue
index 4fa100b99..f4b16c917 100644
--- a/packages/vue/src/FontPicker/FontPickerRoot.vue
+++ b/packages/vue/src/FontPicker/FontPickerRoot.vue
@@ -13,7 +13,7 @@ import {
type AcceptableValue
} from 'reka-ui'
-import { useFontPicker } from '../shared/useFontPicker'
+import { useFontPicker } from '../FontPicker/useFontPicker'
const props = defineProps<{
listFamilies: () => Promise<string[]>
@@ -21,6 +21,7 @@ const props = defineProps<{
contentClass?: string
itemClass?: string
searchClass?: string
+ viewportClass?: string
emptyClass?: string
emptySearchText?: string
emptyFontsText?: string
@@ -32,6 +33,10 @@ const emit = defineEmits<{ select: [family: string] }>()
const inputRef = ref<HTMLInputElement | null>(null)
+function setInputRef(el: HTMLInputElement | null) {
+ inputRef.value = el
+}
+
const { searchTerm, open, filtered, select } = useFontPicker({
modelValue,
listFamilies: props.listFamilies,
@@ -67,7 +72,7 @@ const { searchTerm, open, filtered, select } = useFontPicker({
@open-auto-focus.prevent
@vue:mounted="nextTick(() => inputRef?.focus())"
>
- <slot name="search" :search-term="searchTerm">
+ <slot name="search" :search-term="searchTerm" :set-input-ref="setInputRef">
<ComboboxInput
ref="inputRef"
v-model="searchTerm"
@@ -80,7 +85,7 @@ const { searchTerm, open, filtered, select } = useFontPicker({
/>
</slot>
- <ComboboxViewport class="max-h-72 overflow-y-auto">
+ <ComboboxViewport :class="viewportClass ?? 'max-h-72 overflow-y-auto'">
<ComboboxVirtualizer
v-slot="{ option }"
:options="filtered"
@@ -88,7 +93,11 @@ const { searchTerm, open, filtered, select } = useFontPicker({
:estimate-size="36"
>
<slot name="item" :family="option" :selected="option === modelValue">
- <ComboboxItem :value="option" :class="itemClass" :style="{ fontFamily: `'${option}', sans-serif` }">
+ <ComboboxItem
+ :value="option"
+ :class="itemClass"
+ :style="{ fontFamily: `'${option}', sans-serif` }"
+ >
<ComboboxItemIndicator>
<slot name="indicator" :selected="option === modelValue" />
</ComboboxItemIndicator>
diff --git a/packages/vue/src/shared/useFontPicker.ts b/packages/vue/src/FontPicker/useFontPicker.ts
similarity index 100%
rename from packages/vue/src/shared/useFontPicker.ts
rename to packages/vue/src/FontPicker/useFontPicker.ts
index 065a20e02..d997d3c33 100644
--- a/packages/vue/src/shared/useFontPicker.ts
+++ b/packages/vue/src/FontPicker/useFontPicker.ts
@@ -1,5 +1,5 @@
-import { computed, onMounted, ref, watch } from 'vue'
import { useFilter } from 'reka-ui'
+import { computed, onMounted, ref, watch } from 'vue'
export interface UseFontPickerOptions {
modelValue: { value: string }
diff --git a/packages/vue/src/GradientEditor/GradientEditorRoot.vue b/packages/vue/src/GradientEditor/GradientEditorRoot.vue
index 44f864190..aff84d8f3 100644
--- a/packages/vue/src/GradientEditor/GradientEditorRoot.vue
+++ b/packages/vue/src/GradientEditor/GradientEditorRoot.vue
@@ -87,7 +87,10 @@ function updateStopColor(index: number, hex: string) {
function updateStopOpacity(index: number, opacity: number) {
const s = [...stops.value]
- s[index] = { ...s[index], color: { ...s[index].color, a: Math.max(0, Math.min(1, opacity / 100)) } }
+ s[index] = {
+ ...s[index],
+ color: { ...s[index].color, a: Math.max(0, Math.min(1, opacity / 100)) }
+ }
emitStops(s)
}
diff --git a/packages/vue/src/shared/useGradientStops.ts b/packages/vue/src/GradientEditor/useGradientStops.ts
similarity index 94%
rename from packages/vue/src/shared/useGradientStops.ts
rename to packages/vue/src/GradientEditor/useGradientStops.ts
index b83802871..f5b30955e 100644
--- a/packages/vue/src/shared/useGradientStops.ts
+++ b/packages/vue/src/GradientEditor/useGradientStops.ts
@@ -1,4 +1,5 @@
import { computed, ref, type Ref } from 'vue'
+
import { colorToCSS, parseColor } from '@open-pencil/core'
import type { Color, Fill, GradientStop, GradientTransform } from '@open-pencil/core'
@@ -23,10 +24,7 @@ const DEFAULT_TRANSFORMS: Record<GradientSubtype, GradientTransform> = {
GRADIENT_DIAMOND: { m00: 0.5, m01: 0, m02: 0.5, m10: 0, m11: 0.5, m12: 0.5 }
}
-export function useGradientStops(
- fill: Ref<Fill>,
- onUpdate: (fill: Fill) => void
-) {
+export function useGradientStops(fill: Ref<Fill>, onUpdate: (fill: Fill) => void) {
const activeStopIndex = ref(0)
const stops = computed(() => fill.value.gradientStops ?? [])
const subtype = computed(() => fill.value.type as GradientSubtype)
@@ -87,7 +85,10 @@ export function useGradientStops(
function updateStopOpacity(index: number, opacity: number) {
const s = [...stops.value]
- s[index] = { ...s[index], color: { ...s[index].color, a: Math.max(0, Math.min(1, opacity / 100)) } }
+ s[index] = {
+ ...s[index],
+ color: { ...s[index].color, a: Math.max(0, Math.min(1, opacity / 100)) }
+ }
emitStops(s)
}
diff --git a/packages/vue/src/LayerTree/LayerTreeItem.vue b/packages/vue/src/LayerTree/LayerTreeItem.vue
index e3321d83c..ebb59021b 100644
--- a/packages/vue/src/LayerTree/LayerTreeItem.vue
+++ b/packages/vue/src/LayerTree/LayerTreeItem.vue
@@ -45,11 +45,36 @@ defineExpose({ rowEl })
:is-selected="isSelected"
:is-dragging="isDragging"
:pad-left="padLeft"
- :select="(additive: boolean) => { emit('select', node.id, additive); ctx.select(node.id, additive) }"
- :toggle-expand="() => { emit('toggleExpand', node.id); ctx.toggleExpand(node.id) }"
- :toggle-visibility="() => { emit('toggleVisibility', node.id); ctx.toggleVisibility(node.id) }"
- :toggle-lock="() => { emit('toggleLock', node.id); ctx.toggleLock(node.id) }"
- :rename="(name: string) => { emit('rename', node.id, name); ctx.rename(node.id, name) }"
+ :select="
+ (additive: boolean) => {
+ emit('select', node.id, additive)
+ ctx.select(node.id, additive)
+ }
+ "
+ :toggle-expand="
+ () => {
+ emit('toggleExpand', node.id)
+ ctx.toggleExpand(node.id)
+ }
+ "
+ :toggle-visibility="
+ () => {
+ emit('toggleVisibility', node.id)
+ ctx.toggleVisibility(node.id)
+ }
+ "
+ :toggle-lock="
+ () => {
+ emit('toggleLock', node.id)
+ ctx.toggleLock(node.id)
+ }
+ "
+ :rename="
+ (name: string) => {
+ emit('rename', node.id, name)
+ ctx.rename(node.id, name)
+ }
+ "
/>
</div>
</template>
diff --git a/packages/vue/src/LayerTree/LayerTreeRoot.vue b/packages/vue/src/LayerTree/LayerTreeRoot.vue
index 5aa4217e3..f24a7319d 100644
--- a/packages/vue/src/LayerTree/LayerTreeRoot.vue
+++ b/packages/vue/src/LayerTree/LayerTreeRoot.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, ref, watch } from 'vue'
-import { useEditor } from '../shared/editorContext'
+import { useEditor } from '../context/editorContext'
import { provideLayerTree } from './context'
import type { LayerNode } from './context'
diff --git a/packages/vue/src/shared/useLayerDrag.ts b/packages/vue/src/LayerTree/useLayerDrag.ts
similarity index 80%
rename from packages/vue/src/shared/useLayerDrag.ts
rename to packages/vue/src/LayerTree/useLayerDrag.ts
index 9b2d379a4..7e7d53d7f 100644
--- a/packages/vue/src/shared/useLayerDrag.ts
+++ b/packages/vue/src/LayerTree/useLayerDrag.ts
@@ -1,12 +1,16 @@
-import { onScopeDispose, ref, watchEffect, type Ref } from 'vue'
-import { draggable, dropTargetForElements, monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'
-import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine'
import {
attachInstruction,
extractInstruction,
type Instruction,
type ItemMode
} from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item'
+import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine'
+import {
+ draggable,
+ dropTargetForElements,
+ monitorForElements
+} from '@atlaskit/pragmatic-drag-and-drop/element/adapter'
+import { onScopeDispose, ref, watchEffect, type Ref } from 'vue'
import type { Editor } from '@open-pencil/core/editor'
@@ -22,46 +26,45 @@ type TreeInstruction = Extract<
{ type: 'reorder-above' | 'reorder-below' | 'make-child' }
>
-export function useLayerDrag(
- editor: Editor,
- indentPerLevel = 16
-) {
+export function useLayerDrag(editor: Editor, indentPerLevel = 16) {
const draggingId = ref<string | null>(null)
const instruction = ref<TreeInstruction | null>(null)
const instructionTargetId = ref<string | null>(null)
- function setupItem(
- el: Ref<HTMLElement | null>,
- item: () => DragItem
- ) {
+ function setupItem(el: Ref<HTMLElement | null>, item: () => DragItem) {
watchEffect((onCleanup) => {
const element = el.value
if (!element) return
const data = item()
- const mode: ItemMode = data.hasChildren
- ? 'expanded'
- : 'standard'
+ const mode: ItemMode = data.hasChildren ? 'expanded' : 'standard'
const cleanup = combine(
draggable({
element,
getInitialData: () => ({ id: data.id }),
- onDragStart: () => { draggingId.value = data.id },
- onDrop: () => { draggingId.value = null }
+ onDragStart: () => {
+ draggingId.value = data.id
+ },
+ onDrop: () => {
+ draggingId.value = null
+ }
}),
dropTargetForElements({
element,
getData: ({ input, element: el }) =>
- attachInstruction({ id: data.id }, {
- input,
- element: el,
- indentPerLevel,
- currentLevel: data.level,
- mode,
- block: []
- }),
+ attachInstruction(
+ { id: data.id },
+ {
+ input,
+ element: el,
+ indentPerLevel,
+ currentLevel: data.level,
+ mode,
+ block: []
+ }
+ ),
canDrop: ({ source }) => source.data.id !== data.id,
onDrag: ({ self }) => {
const inst = extractInstruction(self.data) as TreeInstruction | null
diff --git a/packages/vue/src/PageList/PageListRoot.vue b/packages/vue/src/PageList/PageListRoot.vue
index 96c657f96..e55bee81e 100644
--- a/packages/vue/src/PageList/PageListRoot.vue
+++ b/packages/vue/src/PageList/PageListRoot.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
-import { usePageList } from '../shared/usePageList'
+import { usePageList } from '../PageList/usePageList'
const props = defineProps<{
dividerPattern?: RegExp
diff --git a/packages/vue/src/shared/usePageList.ts b/packages/vue/src/PageList/usePageList.ts
similarity index 78%
rename from packages/vue/src/shared/usePageList.ts
rename to packages/vue/src/PageList/usePageList.ts
index ce858c91d..baae38f0d 100644
--- a/packages/vue/src/shared/usePageList.ts
+++ b/packages/vue/src/PageList/usePageList.ts
@@ -1,7 +1,7 @@
import { computed } from 'vue'
-import { useEditor } from './editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
export function usePageList() {
const editor = useEditor()
diff --git a/packages/vue/src/StrokeControls/StrokeControlsRoot.vue b/packages/vue/src/StrokeControls/StrokeControlsRoot.vue
deleted file mode 100644
index ae21d34f1..000000000
--- a/packages/vue/src/StrokeControls/StrokeControlsRoot.vue
+++ /dev/null
@@ -1,145 +0,0 @@
-<script setup lang="ts">
-import { ref } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-
-import type { SceneNode, Stroke } from '@open-pencil/core'
-
-type StrokeSides = 'ALL' | 'TOP' | 'BOTTOM' | 'LEFT' | 'RIGHT' | 'CUSTOM'
-
-const store = useEditor()
-
-const ALIGN_OPTIONS: { value: Stroke['align']; label: string }[] = [
- { value: 'INSIDE', label: 'Inside' },
- { value: 'CENTER', label: 'Center' },
- { value: 'OUTSIDE', label: 'Outside' }
-]
-
-const SIDE_OPTIONS: { value: StrokeSides; label: string }[] = [
- { value: 'ALL', label: 'All' },
- { value: 'TOP', label: 'Top' },
- { value: 'BOTTOM', label: 'Bottom' },
- { value: 'LEFT', label: 'Left' },
- { value: 'RIGHT', label: 'Right' },
- { value: 'CUSTOM', label: 'Custom' }
-]
-
-const BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const
-const sideMenuOpen = ref(false)
-
-function updateAlign(align: Stroke['align'], activeNode: SceneNode) {
- const strokes = activeNode.strokes.map((s) => ({ ...s, align }))
- store.updateNodeWithUndo(activeNode.id, { strokes }, 'Change stroke align')
-}
-
-function currentAlign(activeNode: SceneNode | null): Stroke['align'] {
- if (!activeNode || activeNode.strokes.length === 0) return 'CENTER'
- return activeNode.strokes[0].align
-}
-
-function currentSides(activeNode: SceneNode | null): StrokeSides {
- if (!activeNode?.independentStrokeWeights) return 'ALL'
- const {
- borderTopWeight: t,
- borderRightWeight: r,
- borderBottomWeight: b,
- borderLeftWeight: l
- } = activeNode
- const active = [t > 0, r > 0, b > 0, l > 0]
- const count = active.filter(Boolean).length
- if (count === 4 && t === r && r === b && b === l) return 'ALL'
- if (count === 1) {
- if (t > 0) return 'TOP'
- if (b > 0) return 'BOTTOM'
- if (l > 0) return 'LEFT'
- if (r > 0) return 'RIGHT'
- }
- return 'CUSTOM'
-}
-
-function selectSide(side: StrokeSides, activeNode: SceneNode) {
- const weight = activeNode.strokes.length > 0 ? activeNode.strokes[0].weight : 1
- if (side === 'ALL') {
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: false,
- borderTopWeight: 0,
- borderRightWeight: 0,
- borderBottomWeight: 0,
- borderLeftWeight: 0
- } as Partial<SceneNode>,
- 'Stroke all sides'
- )
- } else if (side === 'CUSTOM') {
- const w = activeNode.independentStrokeWeights
- ? {
- top: activeNode.borderTopWeight,
- right: activeNode.borderRightWeight,
- bottom: activeNode.borderBottomWeight,
- left: activeNode.borderLeftWeight
- }
- : { top: weight, right: weight, bottom: weight, left: weight }
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: true,
- borderTopWeight: w.top,
- borderRightWeight: w.right,
- borderBottomWeight: w.bottom,
- borderLeftWeight: w.left
- } as Partial<SceneNode>,
- 'Custom stroke sides'
- )
- } else {
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: true,
- borderTopWeight: side === 'TOP' ? weight : 0,
- borderRightWeight: side === 'RIGHT' ? weight : 0,
- borderBottomWeight: side === 'BOTTOM' ? weight : 0,
- borderLeftWeight: side === 'LEFT' ? weight : 0
- } as Partial<SceneNode>,
- `Stroke ${side.toLowerCase()} only`
- )
- }
- sideMenuOpen.value = false
-}
-
-function updateBorderWeight(
- side: (typeof BORDER_SIDES)[number],
- value: number,
- activeNode: SceneNode
-) {
- const key = `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
- store.updateNodeWithUndo(
- activeNode.id,
- { [key]: value } as Partial<SceneNode>,
- 'Change stroke weight'
- )
-}
-
-const defaultStroke: Stroke = {
- color: { r: 0, g: 0, b: 0, a: 1 },
- weight: 1,
- opacity: 1,
- visible: true,
- align: 'CENTER'
-}
-</script>
-
-<template>
- <slot
- :align-options="ALIGN_OPTIONS"
- :side-options="SIDE_OPTIONS"
- :border-sides="BORDER_SIDES"
- :side-menu-open="sideMenuOpen"
- :default-stroke="defaultStroke"
- :update-align="updateAlign"
- :current-align="currentAlign"
- :current-sides="currentSides"
- :select-side="selectSide"
- :update-border-weight="updateBorderWeight"
- />
-</template>
diff --git a/packages/vue/src/StrokeControls/index.ts b/packages/vue/src/StrokeControls/index.ts
deleted file mode 100644
index 5f09a93c9..000000000
--- a/packages/vue/src/StrokeControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as StrokeControlsRoot } from './StrokeControlsRoot.vue'
diff --git a/packages/vue/src/shared/useToolbarState.ts b/packages/vue/src/Toolbar/useToolbarState.ts
similarity index 100%
rename from packages/vue/src/shared/useToolbarState.ts
rename to packages/vue/src/Toolbar/useToolbarState.ts
diff --git a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
deleted file mode 100644
index 0e69cc76e..000000000
--- a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
+++ /dev/null
@@ -1,37 +0,0 @@
-<script setup lang="ts">
-import { type Component } from 'vue'
-
-import { useVariablesEditor } from '../shared/use-variables-editor'
-
-const props = defineProps<{
- colorInput: Component
- icons: Record<string, Component>
- fallbackIcon: Component
- deleteIcon: Component
-}>()
-
-const ctx = useVariablesEditor({
- colorInput: props.colorInput,
- icons: props.icons,
- fallbackIcon: props.fallbackIcon,
- deleteIcon: props.deleteIcon
-})
-</script>
-
-<template>
- <slot
- :collections="ctx.collections"
- :variables="ctx.variables"
- :active-collection-id="ctx.activeCollectionId"
- :active-modes="ctx.activeModes"
- :search-term="ctx.searchTerm"
- :editing-collection-id="ctx.editingCollectionId"
- :table="ctx.table"
- :has-collections="ctx.hasCollections"
- :add-collection="ctx.addCollection"
- :add-variable="ctx.addVariable"
- :set-collection-input-ref="ctx.setCollectionInputRef"
- :start-rename-collection="ctx.startRenameCollection"
- :commit-rename-collection="ctx.commitRenameCollection"
- />
-</template>
diff --git a/packages/vue/src/VariablesEditor/index.ts b/packages/vue/src/VariablesEditor/index.ts
index da6554126..e69de29bb 100644
--- a/packages/vue/src/VariablesEditor/index.ts
+++ b/packages/vue/src/VariablesEditor/index.ts
@@ -1 +0,0 @@
-export { default as VariablesEditorRoot } from './VariablesEditorRoot.vue'
diff --git a/packages/vue/src/shared/useVariables.ts b/packages/vue/src/VariablesEditor/useVariables.ts
similarity index 97%
rename from packages/vue/src/shared/useVariables.ts
rename to packages/vue/src/VariablesEditor/useVariables.ts
index 057363703..596e68b1c 100644
--- a/packages/vue/src/shared/useVariables.ts
+++ b/packages/vue/src/VariablesEditor/useVariables.ts
@@ -1,8 +1,9 @@
import { ref, computed, watch } from 'vue'
+
import { colorToHexRaw, parseColor, randomHex } from '@open-pencil/core'
-import { useEditor } from './editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
import type { Color, Variable, VariableCollection, VariableValue } from '@open-pencil/core'
diff --git a/packages/vue/src/shared/useVariablesDialogState.ts b/packages/vue/src/VariablesEditor/useVariablesDialogState.ts
similarity index 100%
rename from packages/vue/src/shared/useVariablesDialogState.ts
rename to packages/vue/src/VariablesEditor/useVariablesDialogState.ts
diff --git a/packages/vue/src/shared/use-variables-editor.ts b/packages/vue/src/VariablesEditor/useVariablesEditor.ts
similarity index 100%
rename from packages/vue/src/shared/use-variables-editor.ts
rename to packages/vue/src/VariablesEditor/useVariablesEditor.ts
diff --git a/packages/vue/src/shared/useVariablesTable.ts b/packages/vue/src/VariablesEditor/useVariablesTable.ts
similarity index 97%
rename from packages/vue/src/shared/useVariablesTable.ts
rename to packages/vue/src/VariablesEditor/useVariablesTable.ts
index c6d9889a7..d5056c506 100644
--- a/packages/vue/src/shared/useVariablesTable.ts
+++ b/packages/vue/src/VariablesEditor/useVariablesTable.ts
@@ -1,9 +1,8 @@
-import { computed, h, type Component } from 'vue'
import { EditableArea, EditableInput, EditablePreview, EditableRoot } from 'reka-ui'
-import type { ColumnDef } from '@tanstack/vue-table'
+import { computed, h, type Component } from 'vue'
import type { Color, Variable, VariableValue } from '@open-pencil/core'
-
+import type { ColumnDef } from '@tanstack/vue-table'
import type { ComputedRef } from 'vue'
interface VariablesTableOptions {
@@ -54,7 +53,8 @@ export function useVariablesTable(options: VariablesTableOptions) {
{
defaultValue: options.shortName(variable),
class: 'min-w-0 flex-1',
- onSubmit: (value: string | null | undefined) => value && commitNameEdit(variable, value)
+ onSubmit: (value: string | null | undefined) =>
+ value && commitNameEdit(variable, value)
},
() =>
h(EditableArea, { class: 'flex' }, () => [
diff --git a/packages/vue/src/shared/createContext.ts b/packages/vue/src/context/createContext.ts
similarity index 74%
rename from packages/vue/src/shared/createContext.ts
rename to packages/vue/src/context/createContext.ts
index ad716a31f..5b158c165 100644
--- a/packages/vue/src/shared/createContext.ts
+++ b/packages/vue/src/context/createContext.ts
@@ -1,6 +1,7 @@
-import type { InjectionKey } from 'vue'
import { inject, provide } from 'vue'
+import type { InjectionKey } from 'vue'
+
export function createContext<T>(name: string) {
const key: InjectionKey<T> = Symbol(name)
@@ -12,7 +13,9 @@ export function createContext<T>(name: string) {
const injectContext = (): T => {
const value = inject(key)
if (!value) {
- throw new Error(`[open-pencil] Injection \`${name}\` not found. Component must be used within the corresponding Root.`)
+ throw new Error(
+ `[open-pencil] Injection \`${name}\` not found. Component must be used within the corresponding Root.`
+ )
}
return value
}
diff --git a/packages/vue/src/shared/editorContext.ts b/packages/vue/src/context/editorContext.ts
similarity index 100%
rename from packages/vue/src/shared/editorContext.ts
rename to packages/vue/src/context/editorContext.ts
diff --git a/packages/vue/src/shared/useAppearance.ts b/packages/vue/src/controls/useAppearance.ts
similarity index 91%
rename from packages/vue/src/shared/useAppearance.ts
rename to packages/vue/src/controls/useAppearance.ts
index 76e6b6cb1..cf7780319 100644
--- a/packages/vue/src/shared/useAppearance.ts
+++ b/packages/vue/src/controls/useAppearance.ts
@@ -1,12 +1,12 @@
import { computed } from 'vue'
-import { useEditor } from './editorContext'
-import { MIXED } from './useNodeProps'
-import { usePropScrub } from './usePropScrub'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
+import { MIXED } from '../controls/useNodeProps'
+import { usePropScrub } from '../controls/usePropScrub'
+import type { MixedValue } from '../controls/useNodeProps'
import type { SceneNode } from '@open-pencil/core'
-import type { MixedValue } from './useNodeProps'
const CORNER_RADIUS_TYPES = new Set([
'RECTANGLE',
@@ -132,7 +132,8 @@ export function useAppearance() {
}
} else {
const n = node.value
- if (n) editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ if (n)
+ editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
}
}
diff --git a/packages/vue/src/controls/useEffectsControls.ts b/packages/vue/src/controls/useEffectsControls.ts
new file mode 100644
index 000000000..71a1aa2c3
--- /dev/null
+++ b/packages/vue/src/controls/useEffectsControls.ts
@@ -0,0 +1,117 @@
+import { ref } from 'vue'
+
+import { useEditor } from '../context/editorContext'
+
+import type { Color, Effect, SceneNode } from '@open-pencil/core'
+
+type EffectType = Effect['type']
+
+const EFFECT_LABELS: Record<string, string> = {
+ DROP_SHADOW: 'Drop shadow',
+ INNER_SHADOW: 'Inner shadow',
+ LAYER_BLUR: 'Layer blur',
+ BACKGROUND_BLUR: 'Background blur',
+ FOREGROUND_BLUR: 'Foreground blur'
+}
+
+const EFFECT_TYPES = Object.keys(EFFECT_LABELS) as EffectType[]
+
+export function useEffectsControls() {
+ const editor = useEditor()
+
+ const expandedIndex = ref<number | null>(null)
+ const effectsBeforeScrub = ref<Effect[] | null>(null)
+ const effectOptions = EFFECT_TYPES.map((t) => ({ value: t, label: EFFECT_LABELS[t] }))
+
+ function isShadow(type: string) {
+ return type === 'DROP_SHADOW' || type === 'INNER_SHADOW'
+ }
+
+ function createDefaultEffect(): Effect {
+ return {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.25 },
+ offset: { x: 0, y: 4 },
+ radius: 4,
+ spread: 0,
+ visible: true
+ }
+ }
+
+ function scrubEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
+ if (!effectsBeforeScrub.value) {
+ effectsBeforeScrub.value = node.effects.map((e) => ({
+ ...e,
+ color: { ...e.color },
+ offset: { ...e.offset }
+ }))
+ }
+ const effects = [...node.effects]
+ effects[index] = { ...effects[index], ...changes }
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
+ }
+
+ function commitEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
+ const previous = effectsBeforeScrub.value
+ effectsBeforeScrub.value = null
+ const effects = [...node.effects]
+ effects[index] = { ...effects[index], ...changes }
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
+ if (previous) {
+ editor.commitNodeUpdate(node.id, { effects: previous }, 'Change effect')
+ }
+ }
+
+ function updateType(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ node: SceneNode | null,
+ index: number,
+ type: EffectType
+ ) {
+ if (!node) return
+ const changes: Partial<Effect> = { type }
+ if (!isShadow(type)) {
+ changes.offset = { x: 0, y: 0 }
+ changes.spread = 0
+ } else if (!isShadow(node.effects[index].type)) {
+ changes.offset = { x: 0, y: 4 }
+ changes.spread = 0
+ }
+ patch(index, changes)
+ }
+
+ function updateColor(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ index: number,
+ color: Color
+ ) {
+ patch(index, { color })
+ }
+
+ function handleRemove(removeFn: (index: number) => void, index: number) {
+ removeFn(index)
+ if (expandedIndex.value === index) expandedIndex.value = null
+ else if (expandedIndex.value !== null && expandedIndex.value > index) expandedIndex.value--
+ }
+
+ function toggleExpand(index: number) {
+ expandedIndex.value = expandedIndex.value === index ? null : index
+ }
+
+ return {
+ expandedIndex,
+ effectOptions,
+ createDefaultEffect,
+ isShadow,
+ scrubEffect,
+ commitEffect,
+ updateType,
+ updateColor,
+ handleRemove,
+ toggleExpand
+ }
+}
diff --git a/packages/vue/src/shared/useExport.ts b/packages/vue/src/controls/useExport.ts
similarity index 92%
rename from packages/vue/src/shared/useExport.ts
rename to packages/vue/src/controls/useExport.ts
index a14330f0d..6c946bbb6 100644
--- a/packages/vue/src/shared/useExport.ts
+++ b/packages/vue/src/controls/useExport.ts
@@ -1,7 +1,7 @@
import { ref } from 'vue'
-import { useEditor } from './editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
import type { ExportFormat } from '@open-pencil/core'
diff --git a/packages/vue/src/controls/useFillControls.ts b/packages/vue/src/controls/useFillControls.ts
new file mode 100644
index 000000000..614a4d0b9
--- /dev/null
+++ b/packages/vue/src/controls/useFillControls.ts
@@ -0,0 +1,12 @@
+import { DEFAULT_SHAPE_FILL } from '@open-pencil/core'
+
+import { useFillVariableBinding } from './useFillVariableBinding'
+
+export function useFillControls() {
+ const ctx = useFillVariableBinding()
+
+ return {
+ ...ctx,
+ defaultFill: DEFAULT_SHAPE_FILL
+ }
+}
diff --git a/packages/vue/src/shared/use-fill-variable-binding.ts b/packages/vue/src/controls/useFillVariableBinding.ts
similarity index 95%
rename from packages/vue/src/shared/use-fill-variable-binding.ts
rename to packages/vue/src/controls/useFillVariableBinding.ts
index 886c00bd3..3e3458f82 100644
--- a/packages/vue/src/shared/use-fill-variable-binding.ts
+++ b/packages/vue/src/controls/useFillVariableBinding.ts
@@ -1,7 +1,7 @@
-import { computed, ref } from 'vue'
import { useFilter } from 'reka-ui'
+import { computed, ref } from 'vue'
-import { useEditor } from './editorContext'
+import { useEditor } from '../context/editorContext'
import type { Variable } from '@open-pencil/core'
diff --git a/packages/vue/src/shared/useLayout.ts b/packages/vue/src/controls/useLayout.ts
similarity index 68%
rename from packages/vue/src/shared/useLayout.ts
rename to packages/vue/src/controls/useLayout.ts
index 5e4546221..dc1b665f9 100644
--- a/packages/vue/src/shared/useLayout.ts
+++ b/packages/vue/src/controls/useLayout.ts
@@ -1,7 +1,7 @@
import { computed, ref } from 'vue'
-import { useEditor } from './editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
import type {
SceneNode,
@@ -15,15 +15,27 @@ import type {
type AlignCell = { primary: LayoutAlign; counter: LayoutCounterAlign }
const ALIGN_HORIZONTAL: AlignCell[] = [
- { primary: 'MIN', counter: 'MIN' }, { primary: 'CENTER', counter: 'MIN' }, { primary: 'MAX', counter: 'MIN' },
- { primary: 'MIN', counter: 'CENTER' }, { primary: 'CENTER', counter: 'CENTER' }, { primary: 'MAX', counter: 'CENTER' },
- { primary: 'MIN', counter: 'MAX' }, { primary: 'CENTER', counter: 'MAX' }, { primary: 'MAX', counter: 'MAX' }
+ { primary: 'MIN', counter: 'MIN' },
+ { primary: 'CENTER', counter: 'MIN' },
+ { primary: 'MAX', counter: 'MIN' },
+ { primary: 'MIN', counter: 'CENTER' },
+ { primary: 'CENTER', counter: 'CENTER' },
+ { primary: 'MAX', counter: 'CENTER' },
+ { primary: 'MIN', counter: 'MAX' },
+ { primary: 'CENTER', counter: 'MAX' },
+ { primary: 'MAX', counter: 'MAX' }
]
const ALIGN_VERTICAL: AlignCell[] = [
- { primary: 'MIN', counter: 'MIN' }, { primary: 'MIN', counter: 'CENTER' }, { primary: 'MIN', counter: 'MAX' },
- { primary: 'CENTER', counter: 'MIN' }, { primary: 'CENTER', counter: 'CENTER' }, { primary: 'CENTER', counter: 'MAX' },
- { primary: 'MAX', counter: 'MIN' }, { primary: 'MAX', counter: 'CENTER' }, { primary: 'MAX', counter: 'MAX' }
+ { primary: 'MIN', counter: 'MIN' },
+ { primary: 'MIN', counter: 'CENTER' },
+ { primary: 'MIN', counter: 'MAX' },
+ { primary: 'CENTER', counter: 'MIN' },
+ { primary: 'CENTER', counter: 'CENTER' },
+ { primary: 'CENTER', counter: 'MAX' },
+ { primary: 'MAX', counter: 'MIN' },
+ { primary: 'MAX', counter: 'CENTER' },
+ { primary: 'MAX', counter: 'MAX' }
]
const TRACK_SIZING_OPTIONS: { value: GridTrackSizing; label: string }[] = [
@@ -52,7 +64,8 @@ export function useLayout() {
const widthSizing = computed<LayoutSizing>(() => {
const n = node.value
if (!n) return 'FIXED'
- if (isFlex.value) return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
+ if (isFlex.value)
+ return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
if (isInAutoLayout.value && n.layoutGrow > 0) return 'FILL'
return 'FIXED'
})
@@ -88,7 +101,11 @@ export function useLayout() {
const hasUniformPadding = computed(() => {
const n = node.value
if (!n) return true
- return n.paddingTop === n.paddingRight && n.paddingRight === n.paddingBottom && n.paddingBottom === n.paddingLeft
+ return (
+ n.paddingTop === n.paddingRight &&
+ n.paddingRight === n.paddingBottom &&
+ n.paddingBottom === n.paddingLeft
+ )
})
function updateProp(key: string, value: number | string) {
@@ -96,7 +113,12 @@ export function useLayout() {
}
function commitProp(key: string, _value: number | string, previous: number | string) {
- if (node.value) editor.commitNodeUpdate(node.value.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ if (node.value)
+ editor.commitNodeUpdate(
+ node.value.id,
+ { [key]: previous } as Partial<SceneNode>,
+ `Change ${key}`
+ )
}
function setWidthSizing(sizing: LayoutSizing) {
@@ -121,22 +143,42 @@ export function useLayout() {
function setUniformPadding(v: number) {
if (!node.value) return
- editor.updateNode(node.value.id, { paddingTop: v, paddingRight: v, paddingBottom: v, paddingLeft: v })
+ editor.updateNode(node.value.id, {
+ paddingTop: v,
+ paddingRight: v,
+ paddingBottom: v,
+ paddingLeft: v
+ })
}
function commitUniformPadding(_value: number, previous: number) {
if (!node.value) return
- editor.commitNodeUpdate(node.value.id, {
- paddingTop: previous, paddingRight: previous, paddingBottom: previous, paddingLeft: previous
- } as unknown as Partial<SceneNode>, 'Change padding')
+ editor.commitNodeUpdate(
+ node.value.id,
+ {
+ paddingTop: previous,
+ paddingRight: previous,
+ paddingBottom: previous,
+ paddingLeft: previous
+ } as unknown as Partial<SceneNode>,
+ 'Change padding'
+ )
}
function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { primaryAxisAlign: primary, counterAxisAlign: counter }, 'Change alignment')
+ editor.updateNodeWithUndo(
+ node.value.id,
+ { primaryAxisAlign: primary, counterAxisAlign: counter },
+ 'Change alignment'
+ )
}
- function updateGridTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number, updates: Partial<GridTrack>) {
+ function updateGridTrack(
+ prop: 'gridTemplateColumns' | 'gridTemplateRows',
+ index: number,
+ updates: Partial<GridTrack>
+ ) {
if (!node.value) return
const tracks = [...node.value[prop]]
tracks[index] = { ...tracks[index], ...updates }
@@ -145,12 +187,20 @@ export function useLayout() {
function addTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows') {
if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { [prop]: [...node.value[prop], { sizing: 'FR' as const, value: 1 }] }, 'Add grid track')
+ editor.updateNodeWithUndo(
+ node.value.id,
+ { [prop]: [...node.value[prop], { sizing: 'FR' as const, value: 1 }] },
+ 'Add grid track'
+ )
}
function removeTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number) {
if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { [prop]: node.value[prop].filter((_: GridTrack, i: number) => i !== index) }, 'Remove grid track')
+ editor.updateNodeWithUndo(
+ node.value.id,
+ { [prop]: node.value[prop].filter((_: GridTrack, i: number) => i !== index) },
+ 'Remove grid track'
+ )
}
function trackLabel(track: GridTrack): string {
diff --git a/packages/vue/src/shared/useNodeProps.ts b/packages/vue/src/controls/useNodeProps.ts
similarity index 97%
rename from packages/vue/src/shared/useNodeProps.ts
rename to packages/vue/src/controls/useNodeProps.ts
index 59e801126..a84551512 100644
--- a/packages/vue/src/shared/useNodeProps.ts
+++ b/packages/vue/src/controls/useNodeProps.ts
@@ -1,7 +1,7 @@
import { computed } from 'vue'
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
import type { Fill, SceneNode, Stroke } from '@open-pencil/core'
diff --git a/packages/vue/src/shared/usePosition.ts b/packages/vue/src/controls/usePosition.ts
similarity index 90%
rename from packages/vue/src/shared/usePosition.ts
rename to packages/vue/src/controls/usePosition.ts
index 9244e8af2..819207540 100644
--- a/packages/vue/src/shared/usePosition.ts
+++ b/packages/vue/src/controls/usePosition.ts
@@ -1,8 +1,8 @@
import { computed } from 'vue'
-import { useEditor } from './editorContext'
-import { usePropScrub } from './usePropScrub'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
+import { usePropScrub } from '../controls/usePropScrub'
import type { SceneNode } from '@open-pencil/core'
diff --git a/packages/vue/src/shared/usePropScrub.ts b/packages/vue/src/controls/usePropScrub.ts
similarity index 82%
rename from packages/vue/src/shared/usePropScrub.ts
rename to packages/vue/src/controls/usePropScrub.ts
index 41c8b2524..f3dfdc432 100644
--- a/packages/vue/src/shared/usePropScrub.ts
+++ b/packages/vue/src/controls/usePropScrub.ts
@@ -25,7 +25,12 @@ export function usePropScrub(editor: Editor) {
}
}
- function commitProp(nodes: SceneNode[], key: string, _value: number | string, previous: number | string) {
+ function commitProp(
+ nodes: SceneNode[],
+ key: string,
+ _value: number | string,
+ previous: number | string
+ ) {
if (nodes.length > 1) {
for (const n of nodes) {
const prev = previousValues.get(n.id)?.[key] ?? previous
@@ -34,7 +39,8 @@ export function usePropScrub(editor: Editor) {
previousValues.clear()
} else {
const n = nodes[0]
- if (n) editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ if (n)
+ editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
}
}
diff --git a/packages/vue/src/controls/useStrokeControls.ts b/packages/vue/src/controls/useStrokeControls.ts
new file mode 100644
index 000000000..ee000219d
--- /dev/null
+++ b/packages/vue/src/controls/useStrokeControls.ts
@@ -0,0 +1,142 @@
+import { ref } from 'vue'
+
+import { useEditor } from '../context/editorContext'
+
+import type { SceneNode, Stroke } from '@open-pencil/core'
+
+type StrokeSides = 'ALL' | 'TOP' | 'BOTTOM' | 'LEFT' | 'RIGHT' | 'CUSTOM'
+
+const ALIGN_OPTIONS: { value: Stroke['align']; label: string }[] = [
+ { value: 'INSIDE', label: 'Inside' },
+ { value: 'CENTER', label: 'Center' },
+ { value: 'OUTSIDE', label: 'Outside' }
+]
+
+const SIDE_OPTIONS: { value: StrokeSides; label: string }[] = [
+ { value: 'ALL', label: 'All' },
+ { value: 'TOP', label: 'Top' },
+ { value: 'BOTTOM', label: 'Bottom' },
+ { value: 'LEFT', label: 'Left' },
+ { value: 'RIGHT', label: 'Right' },
+ { value: 'CUSTOM', label: 'Custom' }
+]
+
+const BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const
+const DEFAULT_STROKE: Stroke = {
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ weight: 1,
+ opacity: 1,
+ visible: true,
+ align: 'CENTER'
+}
+
+export function useStrokeControls() {
+ const store = useEditor()
+ const sideMenuOpen = ref(false)
+
+ function updateAlign(align: Stroke['align'], activeNode: SceneNode) {
+ const strokes = activeNode.strokes.map((s) => ({ ...s, align }))
+ store.updateNodeWithUndo(activeNode.id, { strokes }, 'Change stroke align')
+ }
+
+ function currentAlign(activeNode: SceneNode | null): Stroke['align'] {
+ if (!activeNode || activeNode.strokes.length === 0) return 'CENTER'
+ return activeNode.strokes[0].align
+ }
+
+ function currentSides(activeNode: SceneNode | null): StrokeSides {
+ if (!activeNode?.independentStrokeWeights) return 'ALL'
+ const {
+ borderTopWeight: t,
+ borderRightWeight: r,
+ borderBottomWeight: b,
+ borderLeftWeight: l
+ } = activeNode
+ const active = [t > 0, r > 0, b > 0, l > 0]
+ const count = active.filter(Boolean).length
+ if (count === 4 && t === r && r === b && b === l) return 'ALL'
+ if (count === 1) {
+ if (t > 0) return 'TOP'
+ if (b > 0) return 'BOTTOM'
+ if (l > 0) return 'LEFT'
+ if (r > 0) return 'RIGHT'
+ }
+ return 'CUSTOM'
+ }
+
+ function selectSide(side: StrokeSides, activeNode: SceneNode) {
+ const weight = activeNode.strokes.length > 0 ? activeNode.strokes[0].weight : 1
+ if (side === 'ALL') {
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: false,
+ borderTopWeight: 0,
+ borderRightWeight: 0,
+ borderBottomWeight: 0,
+ borderLeftWeight: 0
+ } as Partial<SceneNode>,
+ 'Stroke all sides'
+ )
+ } else if (side === 'CUSTOM') {
+ const w = activeNode.independentStrokeWeights
+ ? {
+ top: activeNode.borderTopWeight,
+ right: activeNode.borderRightWeight,
+ bottom: activeNode.borderBottomWeight,
+ left: activeNode.borderLeftWeight
+ }
+ : { top: weight, right: weight, bottom: weight, left: weight }
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: true,
+ borderTopWeight: w.top,
+ borderRightWeight: w.right,
+ borderBottomWeight: w.bottom,
+ borderLeftWeight: w.left
+ } as Partial<SceneNode>,
+ 'Custom stroke sides'
+ )
+ } else {
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: true,
+ borderTopWeight: side === 'TOP' ? weight : 0,
+ borderRightWeight: side === 'RIGHT' ? weight : 0,
+ borderBottomWeight: side === 'BOTTOM' ? weight : 0,
+ borderLeftWeight: side === 'LEFT' ? weight : 0
+ } as Partial<SceneNode>,
+ `Stroke ${side.toLowerCase()} only`
+ )
+ }
+ sideMenuOpen.value = false
+ }
+
+ function updateBorderWeight(
+ side: (typeof BORDER_SIDES)[number],
+ value: number,
+ activeNode: SceneNode
+ ) {
+ const key = `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
+ store.updateNodeWithUndo(
+ activeNode.id,
+ { [key]: value } as Partial<SceneNode>,
+ 'Change stroke weight'
+ )
+ }
+
+ return {
+ alignOptions: ALIGN_OPTIONS,
+ sideOptions: SIDE_OPTIONS,
+ borderSides: BORDER_SIDES,
+ sideMenuOpen,
+ defaultStroke: DEFAULT_STROKE,
+ updateAlign,
+ currentAlign,
+ currentSides,
+ selectSide,
+ updateBorderWeight
+ }
+}
diff --git a/packages/vue/src/shared/useTypography.ts b/packages/vue/src/controls/useTypography.ts
similarity index 86%
rename from packages/vue/src/shared/useTypography.ts
rename to packages/vue/src/controls/useTypography.ts
index ddfe8f11f..95df2363a 100644
--- a/packages/vue/src/shared/useTypography.ts
+++ b/packages/vue/src/controls/useTypography.ts
@@ -1,11 +1,12 @@
import { computed } from 'vue'
+
import { FONT_WEIGHT_NAMES, weightToStyle } from '@open-pencil/core'
-import type { SceneNode, TextDecoration } from '@open-pencil/core'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
+import { useNodeFontStatus } from '../shared/useFontStatus'
-import { useEditor } from './editorContext'
-import { useNodeFontStatus } from './useFontStatus'
-import { useSceneComputed } from './useSceneComputed'
+import type { SceneNode, TextDecoration } from '@open-pencil/core'
type TextAlign = 'LEFT' | 'CENTER' | 'RIGHT'
@@ -29,8 +30,8 @@ export function useTypography(options: UseTypographyOptions = {}) {
const fontWeight = computed(() => node.value?.fontWeight ?? 400)
const fontSize = computed(() => node.value?.fontSize ?? 16)
- const currentWeightLabel = computed(() =>
- FONT_WEIGHT_NAMES[node.value?.fontWeight ?? 400] ?? 'Regular'
+ const currentWeightLabel = computed(
+ () => FONT_WEIGHT_NAMES[node.value?.fontWeight ?? 400] ?? 'Regular'
)
const activeFormatting = computed(() => {
@@ -63,7 +64,11 @@ export function useTypography(options: UseTypographyOptions = {}) {
function setAlign(align: TextAlign) {
if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { textAlignHorizontal: align }, 'Change text alignment')
+ editor.updateNodeWithUndo(
+ node.value.id,
+ { textAlignHorizontal: align },
+ 'Change text alignment'
+ )
}
function toggleBold() {
@@ -105,7 +110,11 @@ export function useTypography(options: UseTypographyOptions = {}) {
function commitProp(key: string, _value: number | string, previous: number | string) {
if (node.value) {
- editor.commitNodeUpdate(node.value.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ editor.commitNodeUpdate(
+ node.value.id,
+ { [key]: previous } as Partial<SceneNode>,
+ `Change ${key}`
+ )
}
}
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index cf2f39ebb..fcbcf7264 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -7,49 +7,50 @@ export type {
} from '@open-pencil/core/editor'
export { createEditor, EDITOR_TOOLS, TOOL_SHORTCUTS } from '@open-pencil/core/editor'
-export { provideEditor, useEditor, EDITOR_KEY } from './shared/editorContext'
+export { provideEditor, useEditor, EDITOR_KEY } from './context/editorContext'
export { useCanvas } from './shared/useCanvas'
export type { UseCanvasOptions } from './shared/useCanvas'
-export { useCanvasInput } from './shared/useCanvasInput'
-export { useTextEdit } from './shared/useTextEdit'
-export { useCanvasDrop, extractImageFilesFromClipboard } from './shared/useCanvasDrop'
-export { useNodeProps, MIXED } from './shared/useNodeProps'
-export type { MixedValue } from './shared/useNodeProps'
-export { useSceneComputed } from './shared/useSceneComputed'
-export { useSelectionState } from './shared/useSelectionState'
+export { useCanvasInput } from './Canvas/useCanvasInput'
+export { useTextEdit } from './Canvas/useTextEdit'
+export { useCanvasDrop, extractImageFilesFromClipboard } from './Canvas/useCanvasDrop'
+export { useNodeProps, MIXED } from './controls/useNodeProps'
+export type { MixedValue } from './controls/useNodeProps'
+export { useSceneComputed } from './internal/useSceneComputed'
+export { useSelectionState } from './selection/useSelectionState'
export { useSelectionCapabilities } from './selection/useSelectionCapabilities'
export { useEditorCommands } from './commands/useEditorCommands'
export type { EditorCommand, EditorCommandId } from './commands/useEditorCommands'
export { useMenuModel } from './commands/useMenuModel'
export type { MenuEntry } from './commands/useMenuModel'
export { useViewportKind } from './viewport/useViewportKind'
-export { useLayerDrag } from './shared/useLayerDrag'
+export { useLayerDrag } from './LayerTree/useLayerDrag'
export { useInlineRename } from './shared/useInlineRename'
-export { useToolbarState } from './shared/useToolbarState'
+export { useToolbarState } from './Toolbar/useToolbarState'
export { useNodeFontStatus } from './shared/useFontStatus'
-export { usePropScrub } from './shared/usePropScrub'
-export { toolCursor } from './shared/toolCursor'
-export { usePosition } from './shared/usePosition'
-export { useLayout } from './shared/useLayout'
-export { useAppearance } from './shared/useAppearance'
-export { useTypography } from './shared/useTypography'
-export type { UseTypographyOptions } from './shared/useTypography'
-export { useExport } from './shared/useExport'
-export { useVariables } from './shared/useVariables'
-export { useVariablesDialogState } from './shared/useVariablesDialogState'
-export { useVariablesEditor } from './shared/use-variables-editor'
-export { useVariablesTable } from './shared/useVariablesTable'
-export { useFillPicker } from './shared/useFillPicker'
-export { useFillVariableBinding } from './shared/use-fill-variable-binding'
-export { useGradientStops } from './shared/useGradientStops'
-export { usePageList } from './shared/usePageList'
-export { useFontPicker } from './shared/useFontPicker'
+export { usePropScrub } from './controls/usePropScrub'
+export { toolCursor } from './internal/toolCursor'
+export { usePosition } from './controls/usePosition'
+export { useLayout } from './controls/useLayout'
+export { useAppearance } from './controls/useAppearance'
+export { useTypography } from './controls/useTypography'
+export type { UseTypographyOptions } from './controls/useTypography'
+export { useExport } from './controls/useExport'
+export { useVariables } from './VariablesEditor/useVariables'
+export { useVariablesDialogState } from './VariablesEditor/useVariablesDialogState'
+export { useVariablesEditor } from './VariablesEditor/useVariablesEditor'
+export { useVariablesTable } from './VariablesEditor/useVariablesTable'
+export { useFillControls } from './controls/useFillControls'
+export { useFillPicker } from './FillPicker/useFillPicker'
+export { useFillVariableBinding } from './controls/useFillVariableBinding'
+export { useEffectsControls } from './controls/useEffectsControls'
+export { useGradientStops } from './GradientEditor/useGradientStops'
+export { useStrokeControls } from './controls/useStrokeControls'
+export { usePageList } from './PageList/usePageList'
+export { useFontPicker } from './FontPicker/useFontPicker'
export * from './Canvas'
export * from './ColorPicker'
-export * from './EffectsControls'
-export * from './FillControls'
export * from './FillPicker'
export * from './FontPicker'
export * from './GradientEditor'
@@ -60,7 +61,5 @@ export * from './PageList'
export * from './PositionControls'
export * from './PropertyList'
export * from './ScrubInput'
-export * from './StrokeControls'
export * from './TypographyControls'
export * from './Toolbar'
-export * from './VariablesEditor'
diff --git a/packages/vue/src/shared/toolCursor.ts b/packages/vue/src/internal/toolCursor.ts
similarity index 96%
rename from packages/vue/src/shared/toolCursor.ts
rename to packages/vue/src/internal/toolCursor.ts
index 75a762aef..14a64b39f 100644
--- a/packages/vue/src/shared/toolCursor.ts
+++ b/packages/vue/src/internal/toolCursor.ts
@@ -11,7 +11,7 @@ const TOOL_CURSORS: Record<Tool, string> = {
STAR: 'crosshair',
TEXT: 'text',
PEN: 'crosshair',
- HAND: 'grab',
+ HAND: 'grab'
}
export function toolCursor(tool: Tool, override?: string | null): string {
diff --git a/packages/vue/src/shared/useSceneComputed.ts b/packages/vue/src/internal/useSceneComputed.ts
similarity index 91%
rename from packages/vue/src/shared/useSceneComputed.ts
rename to packages/vue/src/internal/useSceneComputed.ts
index 540fe73b0..81e51330c 100644
--- a/packages/vue/src/shared/useSceneComputed.ts
+++ b/packages/vue/src/internal/useSceneComputed.ts
@@ -1,6 +1,6 @@
import { computed, type ComputedRef } from 'vue'
-import { useEditor } from '../shared/editorContext'
+import { useEditor } from '../context/editorContext'
/**
* Creates a computed ref that re-evaluates when the scene graph changes.
diff --git a/packages/vue/src/selection/useSelectionCapabilities.ts b/packages/vue/src/selection/useSelectionCapabilities.ts
index 998e3aaaf..2ac5edaff 100644
--- a/packages/vue/src/selection/useSelectionCapabilities.ts
+++ b/packages/vue/src/selection/useSelectionCapabilities.ts
@@ -1,6 +1,6 @@
import { computed } from 'vue'
-import { useSelectionState } from '../shared/useSelectionState'
+import { useSelectionState } from '../selection/useSelectionState'
export function useSelectionCapabilities() {
const {
@@ -32,7 +32,9 @@ export function useSelectionCapabilities() {
const canCreateInstance = computed(() => selectedNode.value?.type === 'COMPONENT')
const canMoveToPage = computed(() => hasSelection.value && editor.graph.getPages().length > 1)
const canPaste = computed(() => true)
- const canSelectAll = computed(() => editor.graph.getChildren(editor.state.currentPageId).length > 0)
+ const canSelectAll = computed(
+ () => editor.graph.getChildren(editor.state.currentPageId).length > 0
+ )
const canUndo = computed(() => editor.undo.canUndo)
const canRedo = computed(() => editor.undo.canRedo)
const canZoomToSelection = computed(() => hasSelection.value)
diff --git a/packages/vue/src/shared/useSelectionState.ts b/packages/vue/src/selection/useSelectionState.ts
similarity index 83%
rename from packages/vue/src/shared/useSelectionState.ts
rename to packages/vue/src/selection/useSelectionState.ts
index 35407f28a..342e7bf2a 100644
--- a/packages/vue/src/shared/useSelectionState.ts
+++ b/packages/vue/src/selection/useSelectionState.ts
@@ -1,7 +1,7 @@
import { computed } from 'vue'
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from './useSceneComputed'
+import { useEditor } from '../context/editorContext'
+import { useSceneComputed } from '../internal/useSceneComputed'
import type { SceneNode } from '@open-pencil/core'
@@ -12,9 +12,7 @@ export function useSelectionState() {
const hasSelection = computed(() => selectedIds.value.size > 0)
- const selectedNode = useSceneComputed<SceneNode | null>(
- () => editor.getSelectedNode() ?? null
- )
+ const selectedNode = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
const selectedCount = computed(() => selectedIds.value.size)
diff --git a/packages/vue/src/shared/input/auto-layout.ts b/packages/vue/src/shared/input/auto-layout.ts
index 8f07ffc94..ecbde9a50 100644
--- a/packages/vue/src/shared/input/auto-layout.ts
+++ b/packages/vue/src/shared/input/auto-layout.ts
@@ -1,8 +1,7 @@
+import type { DragMove } from './types'
import type { SceneNode, Vector } from '@open-pencil/core'
import type { Editor } from '@open-pencil/core/editor'
-import type { DragMove } from './types'
-
export function computeIndicatorPosition(
children: SceneNode[],
insertIndex: number,
@@ -74,7 +73,14 @@ export function computeAutoLayoutIndicatorForFrame(
}
}
- const indicatorPos = computeIndicatorPosition(children, insertIndex, parent, parentAbs, isRow, editor)
+ const indicatorPos = computeIndicatorPosition(
+ children,
+ insertIndex,
+ parent,
+ parentAbs,
+ isRow,
+ editor
+ )
const crossStart = isRow ? parentAbs.y + parent.paddingTop : parentAbs.x + parent.paddingLeft
const crossLength = isRow
? parent.height - parent.paddingTop - parent.paddingBottom
@@ -90,12 +96,7 @@ export function computeAutoLayoutIndicatorForFrame(
})
}
-export function computeAutoLayoutIndicator(
- d: DragMove,
- cx: number,
- cy: number,
- editor: Editor
-) {
+export function computeAutoLayoutIndicator(d: DragMove, cx: number, cy: number, editor: Editor) {
if (!d.autoLayoutParentId) return
const parent = editor.graph.getNode(d.autoLayoutParentId)
if (!parent || parent.layoutMode === 'NONE') return
diff --git a/packages/vue/src/shared/input/draw.ts b/packages/vue/src/shared/input/draw.ts
index d078010c6..d946c357b 100644
--- a/packages/vue/src/shared/input/draw.ts
+++ b/packages/vue/src/shared/input/draw.ts
@@ -1,8 +1,13 @@
-import type { Editor } from '@open-pencil/core/editor'
-
import type { DragDraw } from './types'
+import type { Editor } from '@open-pencil/core/editor'
-export function handleDrawMove(d: DragDraw, cx: number, cy: number, shiftKey: boolean, editor: Editor) {
+export function handleDrawMove(
+ d: DragDraw,
+ cx: number,
+ cy: number,
+ shiftKey: boolean,
+ editor: Editor
+) {
let w = cx - d.startX
let h = cy - d.startY
diff --git a/packages/vue/src/shared/input/geometry.ts b/packages/vue/src/shared/input/geometry.ts
index 2cb9d9284..688ac2ddf 100644
--- a/packages/vue/src/shared/input/geometry.ts
+++ b/packages/vue/src/shared/input/geometry.ts
@@ -1,10 +1,10 @@
import { CORNER_ROTATE_ZONE, HANDLE_HIT_RADIUS } from '@open-pencil/core'
-import type { Vector } from '@open-pencil/core'
-
-import type { CornerPosition, HandlePosition } from './types'
import rotateCursorSvg from '../assets/rotate-cursor.svg?raw'
+import type { CornerPosition, HandlePosition } from './types'
+import type { Vector } from '@open-pencil/core'
+
export const HANDLE_CURSORS: Record<HandlePosition, string> = {
nw: 'nwse-resize',
n: 'ns-resize',
diff --git a/packages/vue/src/shared/input/move.ts b/packages/vue/src/shared/input/move.ts
index 365aa50a6..ce70a1956 100644
--- a/packages/vue/src/shared/input/move.ts
+++ b/packages/vue/src/shared/input/move.ts
@@ -1,10 +1,11 @@
import { AUTO_LAYOUT_BREAK_THRESHOLD, computeSelectionBounds, computeSnap } from '@open-pencil/core'
-import type { SceneNode } from '@open-pencil/core'
-import type { Editor } from '@open-pencil/core/editor'
-import type { DragMove, DragState } from './types'
import { computeAutoLayoutIndicator, computeAutoLayoutIndicatorForFrame } from './auto-layout'
+import type { DragMove, DragState } from './types'
+import type { SceneNode } from '@open-pencil/core'
+import type { Editor } from '@open-pencil/core/editor'
+
export function detectAutoLayoutParent(editor: Editor): string | undefined {
if (editor.state.selectedIds.size !== 1) return undefined
const selectedId = [...editor.state.selectedIds][0]
diff --git a/packages/vue/src/shared/input/pan-zoom.ts b/packages/vue/src/shared/input/pan-zoom.ts
index 44ba4f233..02102ec38 100644
--- a/packages/vue/src/shared/input/pan-zoom.ts
+++ b/packages/vue/src/shared/input/pan-zoom.ts
@@ -1,9 +1,8 @@
import { useEventListener } from '@vueuse/core'
-import type { Ref } from 'vue'
-
-import type { Editor } from '@open-pencil/core/editor'
import type { DragState } from './types'
+import type { Editor } from '@open-pencil/core/editor'
+import type { Ref } from 'vue'
export function setupPanZoom(
canvasRef: Ref<HTMLCanvasElement | null>,
diff --git a/packages/vue/src/shared/input/resize.ts b/packages/vue/src/shared/input/resize.ts
index 83cf9a839..29c48b38c 100644
--- a/packages/vue/src/shared/input/resize.ts
+++ b/packages/vue/src/shared/input/resize.ts
@@ -1,8 +1,8 @@
-import type { Rect } from '@open-pencil/core'
-import type { Editor } from '@open-pencil/core/editor'
+import { hitTestHandle } from './geometry'
import type { DragResize, HandlePosition } from './types'
-import { hitTestHandle } from './geometry'
+import type { Rect } from '@open-pencil/core'
+import type { Editor } from '@open-pencil/core/editor'
export function constrainToAspectRatio(
handle: HandlePosition,
diff --git a/packages/vue/src/shared/input/select.ts b/packages/vue/src/shared/input/select.ts
index c950e121b..5c740adfe 100644
--- a/packages/vue/src/shared/input/select.ts
+++ b/packages/vue/src/shared/input/select.ts
@@ -1,15 +1,15 @@
-import type { SceneNode } from '@open-pencil/core'
-import type { Editor } from '@open-pencil/core/editor'
-
-import type { DragState } from './types'
import {
HANDLE_CURSORS,
hitTestHandle,
hitTestCornerRotation,
cornerRotationCursor
} from './geometry'
-import { tryStartResize } from './resize'
import { duplicateAndDrag, detectAutoLayoutParent } from './move'
+import { tryStartResize } from './resize'
+
+import type { DragState } from './types'
+import type { SceneNode } from '@open-pencil/core'
+import type { Editor } from '@open-pencil/core/editor'
export interface HitTestFns {
hitTestInScope: (cx: number, cy: number, deep: boolean) => SceneNode | null
@@ -19,9 +19,16 @@ export interface HitTestFns {
hitTestFrameTitle: (cx: number, cy: number) => SceneNode | null
}
-export function resolveHit(cx: number, cy: number, editor: Editor, fns: HitTestFns): SceneNode | null {
+export function resolveHit(
+ cx: number,
+ cy: number,
+ editor: Editor,
+ fns: HitTestFns
+): SceneNode | null {
const titleHit =
- fns.hitTestFrameTitle(cx, cy) ?? fns.hitTestSectionTitle(cx, cy) ?? fns.hitTestComponentLabel(cx, cy)
+ fns.hitTestFrameTitle(cx, cy) ??
+ fns.hitTestSectionTitle(cx, cy) ??
+ fns.hitTestComponentLabel(cx, cy)
if (titleHit) return titleHit
const hit = fns.hitTestInScope(cx, cy, false)
@@ -90,8 +97,7 @@ export function handleSelectDown(
const originals = new Map<string, { x: number; y: number; parentId: string }>()
for (const id of editor.state.selectedIds) {
const n = editor.graph.getNode(id)
- if (n)
- originals.set(id, { x: n.x, y: n.y, parentId: n.parentId ?? editor.state.currentPageId })
+ if (n) originals.set(id, { x: n.x, y: n.y, parentId: n.parentId ?? editor.state.currentPageId })
}
if (e.altKey && editor.state.selectedIds.size > 0) {
@@ -165,7 +171,9 @@ export function updateHoverCursor(
}
const hit =
- fns.hitTestSectionTitle(cx, cy) ?? fns.hitTestComponentLabel(cx, cy) ?? fns.hitTestInScope(cx, cy, false)
+ fns.hitTestSectionTitle(cx, cy) ??
+ fns.hitTestComponentLabel(cx, cy) ??
+ fns.hitTestInScope(cx, cy, false)
editor.setHoveredNode(hit && !editor.state.selectedIds.has(hit.id) ? hit.id : null)
return cursor
diff --git a/packages/vue/src/shared/useCanvas.ts b/packages/vue/src/shared/useCanvas.ts
index bed873f79..8930114dd 100644
--- a/packages/vue/src/shared/useCanvas.ts
+++ b/packages/vue/src/shared/useCanvas.ts
@@ -1,10 +1,10 @@
import { useRafFn, useResizeObserver } from '@vueuse/core'
import { onMounted, onScopeDispose, type Ref } from 'vue'
-import { useViewportKind } from '../viewport/useViewportKind'
-
import { getCanvasKit, getGpuBackend, SkiaRenderer } from '@open-pencil/core'
+import { useViewportKind } from '../viewport/useViewportKind'
+
import type { Editor } from '@open-pencil/core/editor'
import type { CanvasKit } from 'canvaskit-wasm'
@@ -133,7 +133,10 @@ export function useCanvas(
options?.onReady?.()
}
- const params = typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : new URLSearchParams()
+ const params =
+ typeof window !== 'undefined'
+ ? new URLSearchParams(window.location.search)
+ : new URLSearchParams()
const noRulersParam = params.has('no-rulers')
const { isMobile } = useViewportKind()
diff --git a/src/components/VariablesDialog.vue b/src/components/VariablesDialog.vue
index aae3093ea..e4454052a 100644
--- a/src/components/VariablesDialog.vue
+++ b/src/components/VariablesDialog.vue
@@ -14,7 +14,7 @@ import {
} from 'reka-ui'
import { FlexRender } from '@tanstack/vue-table'
-import { VariablesEditorRoot } from '@open-pencil/vue'
+import { useVariablesEditor } from '@open-pencil/vue'
import IconHash from '~icons/lucide/hash'
import IconPalette from '~icons/lucide/palette'
@@ -34,16 +34,16 @@ const variableTypeIcons: Record<string, Component> = {
STRING: IconType,
BOOLEAN: IconToggleLeft
}
+
+const ctx = useVariablesEditor({
+ colorInput: ColorInput,
+ icons: variableTypeIcons,
+ fallbackIcon: IconToggleLeft,
+ deleteIcon: IconX
+})
</script>
<template>
- <VariablesEditorRoot
- v-slot="ctx"
- :color-input="ColorInput"
- :icons="variableTypeIcons"
- :fallback-icon="IconToggleLeft"
- :delete-icon="IconX"
- >
<DialogRoot v-model:open="open">
<DialogPortal>
<DialogOverlay :class="cls.overlay" />
@@ -198,5 +198,4 @@ const variableTypeIcons: Record<string, Component> = {
</DialogContent>
</DialogPortal>
</DialogRoot>
- </VariablesEditorRoot>
</template>
diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vue
index af24544ec..a2cd488b0 100644
--- a/src/components/properties/EffectsSection.vue
+++ b/src/components/properties/EffectsSection.vue
@@ -4,135 +4,98 @@ import ColorInput from '@/components/ColorInput.vue'
import ScrubInput from '@/components/ScrubInput.vue'
import { iconButton } from '@/components/ui/icon-button'
import { sectionLabel, sectionWrapper } from '@/components/ui/section'
-import { EffectsControlsRoot, PropertyListRoot } from '@open-pencil/vue'
+import { PropertyListRoot, useEffectsControls } from '@open-pencil/vue'
import { colorToCSS } from '@open-pencil/core'
import type { Effect } from '@open-pencil/core'
+
+const effectsCtx = useEffectsControls()
</script>
<template>
- <EffectsControlsRoot v-slot="effectsCtx">
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
- prop-key="effects"
- label="Effects"
- >
- <div data-test-id="effects-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Effects</label>
- <button
- data-test-id="effects-section-add"
- :class="iconButton()"
- @click="add(effectsCtx.defaultEffect)"
- >
- +
- </button>
- </div>
-
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
-
- <div
- v-for="(effect, i) in items as Effect[]"
- :key="i"
- data-test-id="effects-item"
- :data-test-index="i"
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
+ prop-key="effects"
+ label="Effects"
+ >
+ <div data-test-id="effects-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Effects</label>
+ <button
+ data-test-id="effects-section-add"
+ :class="iconButton()"
+ @click="add(effectsCtx.createDefaultEffect())"
>
- <div class="group flex items-center gap-1.5 py-0.5">
- <button
- v-if="effectsCtx.isShadow(effect.type)"
- class="size-5 shrink-0 cursor-pointer rounded border border-border"
- :style="{ background: colorToCSS(effect.color) }"
- @click="effectsCtx.toggleExpand(i)"
- />
- <button
- v-else
- class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
- @click="effectsCtx.toggleExpand(i)"
- >
- <icon-lucide-blend class="size-3 text-muted" />
- </button>
+ +
+ </button>
+ </div>
- <AppSelect
- :model-value="effect.type"
- :options="effectsCtx.effectOptions"
- @update:model-value="effectsCtx.updateType(patch, activeNode, i, $event as Effect['type'])"
- />
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
- <button
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton()" @click="effectsCtx.handleRemove(remove, i)">βˆ’</button>
- </div>
+ <div
+ v-for="(effect, i) in items as Effect[]"
+ :key="i"
+ data-test-id="effects-item"
+ :data-test-index="i"
+ >
+ <div class="group flex items-center gap-1.5 py-0.5">
+ <button
+ v-if="effectsCtx.isShadow(effect.type)"
+ class="size-5 shrink-0 cursor-pointer rounded border border-border"
+ :style="{ background: colorToCSS(effect.color) }"
+ @click="effectsCtx.toggleExpand(i)"
+ />
+ <button
+ v-else
+ class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
+ @click="effectsCtx.toggleExpand(i)"
+ >
+ <icon-lucide-blend class="size-3 text-muted" />
+ </button>
- <div v-if="effectsCtx.expandedIndex === i" class="flex flex-col gap-1.5 py-1.5">
- <template v-if="effectsCtx.isShadow(effect.type)">
- <div class="flex items-center gap-1.5">
- <ScrubInput
- icon="X"
- :model-value="effect.offset.x"
- @update:model-value="
- effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
- "
- @commit="
- effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
- "
- />
- <ScrubInput
- icon="Y"
- :model-value="effect.offset.y"
- @update:model-value="
- effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
- "
- @commit="
- effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
- "
- />
- </div>
+ <AppSelect
+ :model-value="effect.type"
+ :options="effectsCtx.effectOptions"
+ @update:model-value="effectsCtx.updateType(patch, activeNode, i, $event as Effect['type'])"
+ />
- <div class="flex items-center gap-1.5">
- <ScrubInput
- icon="B"
- :model-value="effect.radius"
- :min="0"
- @update:model-value="effectsCtx.scrubEffect(activeNode, i, { radius: $event })"
- @commit="effectsCtx.commitEffect(activeNode, i, { radius: $event })"
- />
- <ScrubInput
- icon="S"
- :model-value="effect.spread"
- @update:model-value="effectsCtx.scrubEffect(activeNode, i, { spread: $event })"
- @commit="effectsCtx.commitEffect(activeNode, i, { spread: $event })"
- />
- </div>
+ <button
+ class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton()" @click="effectsCtx.handleRemove(remove, i)">βˆ’</button>
+ </div>
- <div class="flex items-center gap-1.5">
- <ColorInput :color="effect.color" editable @update="effectsCtx.updateColor(patch, i, $event)" />
- <ScrubInput
- class="w-14"
- suffix="%"
- :model-value="Math.round(effect.color.a * 100)"
- :min="0"
- :max="100"
- @update:model-value="
- effectsCtx.scrubEffect(activeNode, i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- @commit="
- effectsCtx.commitEffect(activeNode, i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- />
- </div>
- </template>
+ <div v-if="effectsCtx.expandedIndex.value === i" class="flex flex-col gap-1.5 py-1.5">
+ <template v-if="effectsCtx.isShadow(effect.type)">
+ <div class="flex items-center gap-1.5">
+ <ScrubInput
+ icon="X"
+ :model-value="effect.offset.x"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
+ "
+ />
+ <ScrubInput
+ icon="Y"
+ :model-value="effect.offset.y"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
+ "
+ />
+ </div>
- <template v-else>
+ <div class="flex items-center gap-1.5">
<ScrubInput
icon="B"
:model-value="effect.radius"
@@ -140,10 +103,47 @@ import type { Effect } from '@open-pencil/core'
@update:model-value="effectsCtx.scrubEffect(activeNode, i, { radius: $event })"
@commit="effectsCtx.commitEffect(activeNode, i, { radius: $event })"
/>
- </template>
- </div>
+ <ScrubInput
+ icon="S"
+ :model-value="effect.spread"
+ @update:model-value="effectsCtx.scrubEffect(activeNode, i, { spread: $event })"
+ @commit="effectsCtx.commitEffect(activeNode, i, { spread: $event })"
+ />
+ </div>
+
+ <div class="flex items-center gap-1.5">
+ <ColorInput :color="effect.color" editable @update="effectsCtx.updateColor(patch, i, $event)" />
+ <ScrubInput
+ class="w-14"
+ suffix="%"
+ :model-value="Math.round(effect.color.a * 100)"
+ :min="0"
+ :max="100"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ />
+ </div>
+ </template>
+
+ <template v-else>
+ <ScrubInput
+ icon="B"
+ :model-value="effect.radius"
+ :min="0"
+ @update:model-value="effectsCtx.scrubEffect(activeNode, i, { radius: $event })"
+ @commit="effectsCtx.commitEffect(activeNode, i, { radius: $event })"
+ />
+ </template>
</div>
</div>
- </PropertyListRoot>
- </EffectsControlsRoot>
+ </div>
+ </PropertyListRoot>
</template>
diff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vue
index bb1bdeed5..c236b3627 100644
--- a/src/components/properties/FillSection.vue
+++ b/src/components/properties/FillSection.vue
@@ -12,7 +12,7 @@ import {
} from 'reka-ui'
import { colorToCSS, colorToHexRaw } from '@open-pencil/core'
-import { FillControlsRoot, PropertyListRoot } from '@open-pencil/vue'
+import { PropertyListRoot, useFillControls } from '@open-pencil/vue'
import FillPicker from '@/components/FillPicker.vue'
import ScrubInput from '@/components/ScrubInput.vue'
@@ -21,138 +21,138 @@ import { iconButton } from '@/components/ui/icon-button'
import { sectionLabel, sectionWrapper } from '@/components/ui/section'
import type { Fill, Variable } from '@open-pencil/core'
+
+const fillCtx = useFillControls()
</script>
<template>
- <FillControlsRoot v-slot="fillCtx">
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, update, patch, toggleVisibility }"
- prop-key="fills"
- label="Fill"
- >
- <div data-test-id="fill-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Fill</label>
- <button
- data-test-id="fill-section-add"
- :class="iconButton()"
- @click="add({ ...fillCtx.defaultFill })"
- >
- +
- </button>
- </div>
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed fills</p>
- <div
- v-for="(fill, i) in items as Fill[]"
- :key="i"
- data-test-id="fill-item"
- :data-test-index="i"
- class="group flex items-center gap-1.5 py-0.5"
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, add, remove, update, patch, toggleVisibility }"
+ prop-key="fills"
+ label="Fill"
+ >
+ <div data-test-id="fill-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Fill</label>
+ <button
+ data-test-id="fill-section-add"
+ :class="iconButton()"
+ @click="add({ ...fillCtx.defaultFill })"
>
- <FillPicker :fill="fill" @update="update(i, $event)" />
+ +
+ </button>
+ </div>
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed fills</p>
+ <div
+ v-for="(fill, i) in items as Fill[]"
+ :key="i"
+ data-test-id="fill-item"
+ :data-test-index="i"
+ class="group flex items-center gap-1.5 py-0.5"
+ >
+ <FillPicker :fill="fill" @update="update(i, $event)" />
- <template v-if="activeNode && fillCtx.getBoundVariable(activeNode.id, i)">
- <span
- class="min-w-0 flex-1 truncate rounded bg-violet-500/10 px-1 font-mono text-xs text-violet-400"
+ <template v-if="activeNode && fillCtx.getBoundVariable(activeNode.id, i)">
+ <span
+ class="min-w-0 flex-1 truncate rounded bg-violet-500/10 px-1 font-mono text-xs text-violet-400"
+ >
+ {{ fillCtx.getBoundVariable(activeNode.id, i)!.name }}
+ </span>
+ <Tip label="Detach variable">
+ <button
+ data-test-id="fill-unbind-variable"
+ class="cursor-pointer border-none bg-transparent p-0 text-violet-400 hover:text-surface"
+ @click="fillCtx.unbindFillVariable(activeNode.id, i)"
>
- {{ fillCtx.getBoundVariable(activeNode.id, i)!.name }}
- </span>
- <Tip label="Detach variable">
- <button
- data-test-id="fill-unbind-variable"
- class="cursor-pointer border-none bg-transparent p-0 text-violet-400 hover:text-surface"
- @click="fillCtx.unbindFillVariable(activeNode.id, i)"
- >
- <icon-lucide-unlink class="size-3" />
- </button>
- </Tip>
- </template>
- <template v-else>
- <span class="min-w-0 flex-1 font-mono text-xs text-surface">
- <template v-if="fill.type === 'SOLID'">{{ colorToHexRaw(fill.color) }}</template>
- <template v-else-if="fill.type.startsWith('GRADIENT')">{{
- fill.type.replace('GRADIENT_', '')
- }}</template>
- <template v-else>{{ fill.type }}</template>
- </span>
- </template>
+ <icon-lucide-unlink class="size-3" />
+ </button>
+ </Tip>
+ </template>
+ <template v-else>
+ <span class="min-w-0 flex-1 font-mono text-xs text-surface">
+ <template v-if="fill.type === 'SOLID'">{{ colorToHexRaw(fill.color) }}</template>
+ <template v-else-if="fill.type.startsWith('GRADIENT')">{{
+ fill.type.replace('GRADIENT_', '')
+ }}</template>
+ <template v-else>{{ fill.type }}</template>
+ </span>
+ </template>
- <ScrubInput
- class="w-12"
- suffix="%"
- :model-value="Math.round(fill.opacity * 100)"
- :min="0"
- :max="100"
- @update:model-value="patch(i, { opacity: Math.max(0, Math.min(1, $event / 100)) })"
- />
+ <ScrubInput
+ class="w-12"
+ suffix="%"
+ :model-value="Math.round(fill.opacity * 100)"
+ :min="0"
+ :max="100"
+ @update:model-value="patch(i, { opacity: Math.max(0, Math.min(1, $event / 100)) })"
+ />
- <PopoverRoot
- v-if="
- fillCtx.colorVariables.length > 0 &&
- fill.type === 'SOLID' &&
- activeNode &&
- !fillCtx.getBoundVariable(activeNode.id, i)
- "
- >
- <Tip label="Apply variable">
- <PopoverTrigger class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface">
- <icon-lucide-link class="size-3.5" />
- </PopoverTrigger>
- </Tip>
- <PopoverPortal>
- <PopoverContent
- side="left"
- :side-offset="8"
- class="z-50 w-56 rounded-lg border border-border bg-panel shadow-lg"
+ <PopoverRoot
+ v-if="
+ fillCtx.colorVariables.value.length > 0 &&
+ fill.type === 'SOLID' &&
+ activeNode &&
+ !fillCtx.getBoundVariable(activeNode.id, i)
+ "
+ >
+ <Tip label="Apply variable">
+ <PopoverTrigger class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface">
+ <icon-lucide-link class="size-3.5" />
+ </PopoverTrigger>
+ </Tip>
+ <PopoverPortal>
+ <PopoverContent
+ side="left"
+ :side-offset="8"
+ class="z-50 w-56 rounded-lg border border-border bg-panel shadow-lg"
+ >
+ <ComboboxRoot
+ @update:model-value="
+ activeNode && fillCtx.bindFillVariable(activeNode.id, i, ($event as Variable).id)
+ "
>
- <ComboboxRoot
- @update:model-value="
- activeNode && fillCtx.bindFillVariable(activeNode.id, i, ($event as Variable).id)
- "
- >
- <ComboboxInput
- :model-value="fillCtx.searchTerm"
- @update:model-value="fillCtx.searchTerm = String($event)"
- placeholder="Search variables…"
- class="w-full border-b border-border bg-transparent px-2 py-1.5 text-[11px] text-surface outline-none placeholder:text-muted"
- />
- <ComboboxContent class="max-h-48 overflow-y-auto p-1">
- <ComboboxEmpty class="px-2 py-3 text-center text-[11px] text-muted"
- >No variables found</ComboboxEmpty
- >
- <ComboboxItem
- v-for="v in fillCtx.filteredVariables"
- :key="v.id"
- :value="v"
- class="flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-[11px] text-surface data-[highlighted]:bg-hover"
- >
- <div
- class="size-3 shrink-0 rounded-sm border border-border"
- :style="{
- background:
- fillCtx.store.resolveColorVariable(v.id)
- ? colorToCSS(fillCtx.store.resolveColorVariable(v.id)!)
- : '#000'
- }"
- />
- <span class="min-w-0 flex-1 truncate">{{ v.name }}</span>
- </ComboboxItem>
- </ComboboxContent>
- </ComboboxRoot>
- </PopoverContent>
- </PopoverPortal>
- </PopoverRoot>
+ <ComboboxInput
+ :model-value="fillCtx.searchTerm.value"
+ placeholder="Search variables…"
+ class="w-full border-b border-border bg-transparent px-2 py-1.5 text-[11px] text-surface outline-none placeholder:text-muted"
+ @update:model-value="fillCtx.searchTerm.value = String($event)"
+ />
+ <ComboboxContent class="max-h-48 overflow-y-auto p-1">
+ <ComboboxEmpty class="px-2 py-3 text-center text-[11px] text-muted"
+ >No variables found</ComboboxEmpty
+ >
+ <ComboboxItem
+ v-for="v in fillCtx.filteredVariables.value"
+ :key="v.id"
+ :value="v"
+ class="flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-[11px] text-surface data-[highlighted]:bg-hover"
+ >
+ <div
+ class="size-3 shrink-0 rounded-sm border border-border"
+ :style="{
+ background:
+ fillCtx.store.resolveColorVariable(v.id)
+ ? colorToCSS(fillCtx.store.resolveColorVariable(v.id)!)
+ : '#000'
+ }"
+ />
+ <span class="min-w-0 flex-1 truncate">{{ v.name }}</span>
+ </ComboboxItem>
+ </ComboboxContent>
+ </ComboboxRoot>
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
- <button
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="fill.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton()" @click="remove(i)">βˆ’</button>
- </div>
+ <button
+ class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="fill.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton()" @click="remove(i)">βˆ’</button>
</div>
- </PropertyListRoot>
- </FillControlsRoot>
+ </div>
+ </PropertyListRoot>
</template>
diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vue
index daa1667c4..63f4f6985 100644
--- a/src/components/properties/StrokeSection.vue
+++ b/src/components/properties/StrokeSection.vue
@@ -7,7 +7,7 @@ import {
DropdownMenuTrigger
} from 'reka-ui'
-import { PropertyListRoot, StrokeControlsRoot } from '@open-pencil/vue'
+import { PropertyListRoot, useStrokeControls } from '@open-pencil/vue'
import AppSelect from '@/components/ui/AppSelect.vue'
import ColorInput from '@/components/ColorInput.vue'
@@ -18,201 +18,201 @@ import { menu, useMenuUI } from '@/components/ui/menu'
import { sectionLabel, sectionWrapper } from '@/components/ui/section'
import type { SceneNode, Stroke } from '@open-pencil/core'
+
+const strokeCtx = useStrokeControls()
+const sideMenuCls = useMenuUI({
+ content: 'min-w-[140px] rounded-md p-0.5',
+ item: 'relative px-2'
+})
</script>
<template>
- <StrokeControlsRoot v-slot="strokeCtx">
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, patch, toggleVisibility }"
- prop-key="strokes"
- label="Stroke"
- >
- <div data-test-id="stroke-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Stroke</label>
- <button
- data-test-id="stroke-section-add"
- :class="iconButton()"
- @click="add(strokeCtx.defaultStroke)"
- >
- +
- </button>
- </div>
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, add, remove, patch, toggleVisibility }"
+ prop-key="strokes"
+ label="Stroke"
+ >
+ <div data-test-id="stroke-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Stroke</label>
+ <button
+ data-test-id="stroke-section-add"
+ :class="iconButton()"
+ @click="add(strokeCtx.defaultStroke)"
+ >
+ +
+ </button>
+ </div>
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p>
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p>
- <div
- v-for="(stroke, i) in items as Stroke[]"
- :key="i"
- data-test-id="stroke-item"
- :data-test-index="i"
- class="group flex items-center gap-1.5 py-0.5"
+ <div
+ v-for="(stroke, i) in items as Stroke[]"
+ :key="i"
+ data-test-id="stroke-item"
+ :data-test-index="i"
+ class="group flex items-center gap-1.5 py-0.5"
+ >
+ <ColorInput
+ class="min-w-0 flex-1"
+ :color="stroke.color"
+ editable
+ @update="patch(i, { color: $event })"
+ />
+ <button
+ class="shrink-0 cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
>
- <ColorInput
- class="min-w-0 flex-1"
- :color="stroke.color"
- editable
- @update="patch(i, { color: $event })"
- />
- <button
- class="shrink-0 cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="stroke.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton({ ui: { base: 'shrink-0' } })" @click="remove(i)">βˆ’</button>
- </div>
+ <icon-lucide-eye v-if="stroke.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton({ ui: { base: 'shrink-0' } })" @click="remove(i)">βˆ’</button>
+ </div>
- <div v-if="!isMixed && activeNode && activeNode.strokes.length > 0" class="mt-1 flex items-center gap-1.5">
- <AppSelect
- class="w-[72px]"
- :model-value="strokeCtx.currentAlign(activeNode)"
- :options="strokeCtx.alignOptions"
- @update:model-value="strokeCtx.updateAlign($event as Stroke['align'], activeNode)"
- />
- <ScrubInput
- v-if="!activeNode.independentStrokeWeights"
- class="flex-1"
- :model-value="activeNode.strokes[0]?.weight ?? 1"
- :min="0"
- @update:model-value="patch(0, { weight: $event })"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
+ <div v-if="!isMixed && activeNode && activeNode.strokes.length > 0" class="mt-1 flex items-center gap-1.5">
+ <AppSelect
+ class="w-[72px]"
+ :model-value="strokeCtx.currentAlign(activeNode)"
+ :options="strokeCtx.alignOptions"
+ @update:model-value="strokeCtx.updateAlign($event as Stroke['align'], activeNode)"
+ />
+ <ScrubInput
+ v-if="!activeNode.independentStrokeWeights"
+ class="flex-1"
+ :model-value="activeNode.strokes[0]?.weight ?? 1"
+ :min="0"
+ @update:model-value="patch(0, { weight: $event })"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <line x1="1" y1="3" x2="11" y2="3" />
+ <line x1="1" y1="6" x2="11" y2="6" />
+ <line x1="1" y1="9" x2="11" y2="9" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <DropdownMenuRoot v-model:open="strokeCtx.sideMenuOpen.value">
+ <Tip label="Stroke sides">
+ <DropdownMenuTrigger as-child>
+ <button
+ class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
+ :class="{ '!border-accent !text-accent': activeNode.independentStrokeWeights }"
>
- <line x1="1" y1="3" x2="11" y2="3" />
- <line x1="1" y1="6" x2="11" y2="6" />
- <line x1="1" y1="9" x2="11" y2="9" />
- </svg>
- </template>
- </ScrubInput>
- <DropdownMenuRoot v-model:open="strokeCtx.sideMenuOpen">
- <Tip label="Stroke sides">
- <DropdownMenuTrigger as-child>
- <button
- class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
- :class="{ '!border-accent !text-accent': activeNode.independentStrokeWeights }"
- >
- <svg class="size-3.5" viewBox="0 0 14 14" fill="currentColor">
- <rect x="1" y="1" width="5" height="5" rx="1" />
- <rect x="8" y="1" width="5" height="5" rx="1" />
- <rect x="1" y="8" width="5" height="5" rx="1" />
- <rect x="8" y="8" width="5" height="5" rx="1" />
- </svg>
- </button>
- </DropdownMenuTrigger>
- </Tip>
- <DropdownMenuPortal>
- <DropdownMenuContent
- :side-offset="4"
- align="end"
- :class="useMenuUI({ content: 'min-w-[140px] rounded-md p-0.5' }).content"
+ <svg class="size-3.5" viewBox="0 0 14 14" fill="currentColor">
+ <rect x="1" y="1" width="5" height="5" rx="1" />
+ <rect x="8" y="1" width="5" height="5" rx="1" />
+ <rect x="1" y="8" width="5" height="5" rx="1" />
+ <rect x="8" y="8" width="5" height="5" rx="1" />
+ </svg>
+ </button>
+ </DropdownMenuTrigger>
+ </Tip>
+ <DropdownMenuPortal>
+ <DropdownMenuContent :side-offset="4" align="end" :class="sideMenuCls.content">
+ <DropdownMenuItem
+ v-for="opt in strokeCtx.sideOptions"
+ :key="opt.value"
+ :class="menu({ justify: 'start' }).item({ class: sideMenuCls.item })"
+ @click="strokeCtx.selectSide(opt.value, activeNode)"
>
- <DropdownMenuItem
- v-for="opt in strokeCtx.sideOptions"
- :key="opt.value"
- :class="menu({ justify: 'start' }).item({ class: 'relative px-2' })"
- @click="strokeCtx.selectSide(opt.value, activeNode)"
- >
- <icon-lucide-check
- v-if="strokeCtx.currentSides(activeNode) === opt.value"
- class="absolute left-2 size-3 text-accent"
- />
- <span class="flex items-center gap-2 pl-5">
- <svg
- class="size-3.5"
- viewBox="0 0 14 14"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <template v-if="opt.value === 'ALL'">
- <rect x="1" y="1" width="12" height="12" rx="1" />
- </template>
- <template v-else-if="opt.value === 'CUSTOM'">
- <line x1="4" y1="7" x2="10" y2="7" />
- <line x1="7" y1="4" x2="7" y2="10" />
- </template>
- <template v-else>
- <rect
- x="1"
- y="1"
- width="12"
- height="12"
- rx="1"
- stroke-opacity="0.3"
- stroke-dasharray="2 2"
- />
- <line v-if="opt.value === 'TOP'" x1="1" y1="1" x2="13" y2="1" />
- <line v-else-if="opt.value === 'BOTTOM'" x1="1" y1="13" x2="13" y2="13" />
- <line v-else-if="opt.value === 'LEFT'" x1="1" y1="1" x2="1" y2="13" />
- <line v-else-if="opt.value === 'RIGHT'" x1="13" y1="1" x2="13" y2="13" />
- </template>
- </svg>
- <span>{{ opt.label }}</span>
- </span>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenuPortal>
- </DropdownMenuRoot>
- </div>
+ <icon-lucide-check
+ v-if="strokeCtx.currentSides(activeNode) === opt.value"
+ class="absolute left-2 size-3 text-accent"
+ />
+ <span class="flex items-center gap-2 pl-5">
+ <svg
+ class="size-3.5"
+ viewBox="0 0 14 14"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <template v-if="opt.value === 'ALL'">
+ <rect x="1" y="1" width="12" height="12" rx="1" />
+ </template>
+ <template v-else-if="opt.value === 'CUSTOM'">
+ <line x1="4" y1="7" x2="10" y2="7" />
+ <line x1="7" y1="4" x2="7" y2="10" />
+ </template>
+ <template v-else>
+ <rect
+ x="1"
+ y="1"
+ width="12"
+ height="12"
+ rx="1"
+ stroke-opacity="0.3"
+ stroke-dasharray="2 2"
+ />
+ <line v-if="opt.value === 'TOP'" x1="1" y1="1" x2="13" y2="1" />
+ <line v-else-if="opt.value === 'BOTTOM'" x1="1" y1="13" x2="13" y2="13" />
+ <line v-else-if="opt.value === 'LEFT'" x1="1" y1="1" x2="1" y2="13" />
+ <line v-else-if="opt.value === 'RIGHT'" x1="13" y1="1" x2="13" y2="13" />
+ </template>
+ </svg>
+ <span>{{ opt.label }}</span>
+ </span>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenuPortal>
+ </DropdownMenuRoot>
+ </div>
- <div
- v-if="!isMixed && activeNode && activeNode.strokes.length > 0 && activeNode.independentStrokeWeights"
- class="mt-1.5 grid grid-cols-2 gap-1.5"
+ <div
+ v-if="!isMixed && activeNode && activeNode.strokes.length > 0 && activeNode.independentStrokeWeights"
+ class="mt-1.5 grid grid-cols-2 gap-1.5"
+ >
+ <ScrubInput
+ v-for="side in strokeCtx.borderSides"
+ :key="side"
+ :model-value="
+ activeNode[
+ `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
+ ] as number
+ "
+ :min="0"
+ @update:model-value="strokeCtx.updateBorderWeight(side, $event, activeNode)"
>
- <ScrubInput
- v-for="side in strokeCtx.borderSides"
- :key="side"
- :model-value="
- activeNode[
- `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
- ] as number
- "
- :min="0"
- @update:model-value="strokeCtx.updateBorderWeight(side, $event, activeNode)"
- >
- <template #icon>
- <svg class="size-3" viewBox="0 0 12 12" fill="none" stroke-width="1.5">
- <rect
- x="1"
- y="1"
- width="10"
- height="10"
- rx="1"
- stroke="currentColor"
- stroke-opacity="0.3"
- stroke-dasharray="2 2"
- />
- <line v-if="side === 'top'" x1="1" y1="1" x2="11" y2="1" stroke="currentColor" />
- <line
- v-else-if="side === 'right'"
- x1="11"
- y1="1"
- x2="11"
- y2="11"
- stroke="currentColor"
- />
- <line
- v-else-if="side === 'bottom'"
- x1="1"
- y1="11"
- x2="11"
- y2="11"
- stroke="currentColor"
- />
- <line v-else x1="1" y1="1" x2="1" y2="11" stroke="currentColor" />
- </svg>
- </template>
- </ScrubInput>
- </div>
+ <template #icon>
+ <svg class="size-3" viewBox="0 0 12 12" fill="none" stroke-width="1.5">
+ <rect
+ x="1"
+ y="1"
+ width="10"
+ height="10"
+ rx="1"
+ stroke="currentColor"
+ stroke-opacity="0.3"
+ stroke-dasharray="2 2"
+ />
+ <line v-if="side === 'top'" x1="1" y1="1" x2="11" y2="1" stroke="currentColor" />
+ <line
+ v-else-if="side === 'right'"
+ x1="11"
+ y1="1"
+ x2="11"
+ y2="11"
+ stroke="currentColor"
+ />
+ <line
+ v-else-if="side === 'bottom'"
+ x1="1"
+ y1="11"
+ x2="11"
+ y2="11"
+ stroke="currentColor"
+ />
+ <line v-else x1="1" y1="1" x2="1" y2="11" stroke="currentColor" />
+ </svg>
+ </template>
+ </ScrubInput>
</div>
- </PropertyListRoot>
- </StrokeControlsRoot>
+ </div>
+ </PropertyListRoot>
</template>