Skip to content

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

SDK rewrite: delete 15 useless wrappers, replace with composables

Danila Poyarkovfb2bfb58272e
diff --git a/packages/vue/example/src/App.vue b/packages/vue/example/src/App.vue
index ae1c7a798..2403cfa46 100644
--- a/packages/vue/example/src/App.vue
+++ b/packages/vue/example/src/App.vue
@@ -4,7 +4,6 @@ import {
OpenPencilProvider,
CanvasRoot,
CanvasSurface,
- PageListRoot,
LayerTree,
ToolbarRoot,
ToolbarItem,
@@ -12,6 +11,8 @@ import {
} from '@open-pencil/vue'
const editor = createEditor()
+const pages = () => editor.graph.getPages()
+const currentPageId = () => editor.state.currentPageId
editor.createShape('FRAME', 100, 100, 400, 300)
editor.createShape('RECTANGLE', 150, 150, 120, 80)
@@ -38,20 +39,18 @@ const TOOL_LIST: Tool[] = [
<div class="main">
<div class="panel left">
- <PageListRoot v-slot="{ pages, currentPageId, switchPage }">
- <div class="section">
- <h3>Pages</h3>
- <div
- v-for="page in pages"
- :key="page.id"
- :class="{ active: page.id === currentPageId }"
- class="list-item"
- @click="switchPage(page.id)"
- >
- {{ page.name }}
- </div>
+ <div class="section">
+ <h3>Pages</h3>
+ <div
+ v-for="page in pages()"
+ :key="page.id"
+ :class="{ active: page.id === currentPageId() }"
+ class="list-item"
+ @click="editor.switchPage(page.id)"
+ >
+ {{ page.name }}
</div>
- </PageListRoot>
+ </div>
<LayerTree v-slot="{ layers, selectedIds, select }">
<div class="section">
diff --git a/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue b/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
deleted file mode 100644
index 52acdbe7d..000000000
--- a/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
+++ /dev/null
@@ -1,157 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { MIXED } from '../shared/useNodeProps'
-import { usePropScrub } from '../shared/usePropScrub'
-
-import type { SceneNode } from '@open-pencil/core'
-import type { MixedValue } from '../shared/useNodeProps'
-
-const editor = useEditor()
-
-const nodes = computed(() => editor.getSelectedNodes())
-const node = computed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
-const active = computed(() => nodes.value.length > 0)
-const isMulti = computed(() => nodes.value.length > 1)
-
-function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {
- const all = nodes.value
- if (all.length === 0) return MIXED
- const first = all[0][key]
- for (let i = 1; i < all.length; i++) {
- if (all[i][key] !== first) return MIXED
- }
- return first
-}
-
-const CORNER_RADIUS_TYPES = new Set([
- 'RECTANGLE',
- 'ROUNDED_RECTANGLE',
- 'FRAME',
- 'COMPONENT',
- 'INSTANCE'
-])
-
-const hasCornerRadius = computed(() => {
- if (isMulti.value) return nodes.value.every((n) => CORNER_RADIUS_TYPES.has(n.type))
- return node.value ? CORNER_RADIUS_TYPES.has(node.value.type) : false
-})
-
-const independentCorners = computed(() => {
- if (isMulti.value) return merged('independentCorners')
- return node.value?.independentCorners ?? false
-})
-
-const cornerRadiusValue = computed(() => {
- if (isMulti.value) return merged('cornerRadius')
- return node.value?.cornerRadius ?? 0
-})
-
-const opacityPercent = computed(() => {
- const v = merged('opacity')
- return v === MIXED ? MIXED : Math.round((v as number) * 100)
-})
-
-const visibilityState = computed<'visible' | 'hidden' | 'mixed'>(() => {
- const v = merged('visible')
- if (v === MIXED) return 'mixed'
- return v ? 'visible' : 'hidden'
-})
-
-const { updateProp: _updateProp, commitProp: _commitProp } = usePropScrub(editor)
-
-function updateProp(key: string, value: number | string) {
- _updateProp(nodes.value, key, value)
-}
-
-function commitProp(key: string, _value: number | string, previous: number | string) {
- _commitProp(nodes.value, key, _value, previous)
-}
-
-function toggleVisibility() {
- if (isMulti.value) {
- const allVisible = nodes.value.every((n) => n.visible)
- for (const n of nodes.value) {
- editor.updateNodeWithUndo(n.id, { visible: !allVisible }, 'Toggle visibility')
- }
- } else {
- const n = node.value
- if (!n) return
- editor.updateNodeWithUndo(n.id, { visible: !n.visible }, 'Toggle visibility')
- }
-}
-
-function toggleIndependentCorners() {
- const targets = isMulti.value ? nodes.value : node.value ? [node.value] : []
- for (const n of targets) {
- if (n.independentCorners) {
- const uniform = n.topLeftRadius
- editor.updateNodeWithUndo(
- n.id,
- {
- independentCorners: false,
- cornerRadius: uniform,
- topLeftRadius: uniform,
- topRightRadius: uniform,
- bottomRightRadius: uniform,
- bottomLeftRadius: uniform
- } as Partial<SceneNode>,
- 'Uniform corner radius'
- )
- } else {
- editor.updateNodeWithUndo(
- n.id,
- {
- independentCorners: true,
- topLeftRadius: n.cornerRadius,
- topRightRadius: n.cornerRadius,
- bottomRightRadius: n.cornerRadius,
- bottomLeftRadius: n.cornerRadius
- } as Partial<SceneNode>,
- 'Independent corner radii'
- )
- }
- }
-}
-
-function updateCornerProp(key: string, value: number) {
- if (isMulti.value) {
- for (const n of nodes.value) editor.updateNode(n.id, { [key]: value })
- } else {
- const n = node.value
- if (n) editor.updateNode(n.id, { [key]: value })
- }
-}
-
-function commitCornerProp(key: string, _value: number, previous: number) {
- if (isMulti.value) {
- for (const n of nodes.value) {
- editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
- }
- } else {
- const n = node.value
- if (n) editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
- }
-}
-</script>
-
-<template>
- <slot
- v-if="active"
- :node="node"
- :nodes="nodes"
- :is-multi="isMulti"
- :has-corner-radius="hasCornerRadius"
- :independent-corners="independentCorners"
- :corner-radius-value="cornerRadiusValue"
- :opacity-percent="opacityPercent"
- :visibility-state="visibilityState"
- :update-prop="updateProp"
- :commit-prop="commitProp"
- :toggle-visibility="toggleVisibility"
- :toggle-independent-corners="toggleIndependentCorners"
- :update-corner-prop="updateCornerProp"
- :commit-corner-prop="commitCornerProp"
- />
-</template>
diff --git a/packages/vue/src/AppearanceControls/index.ts b/packages/vue/src/AppearanceControls/index.ts
deleted file mode 100644
index 0a795c6ab..000000000
--- a/packages/vue/src/AppearanceControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as AppearanceControlsRoot } from './AppearanceControlsRoot.vue'
diff --git a/packages/vue/src/ColorInput/ColorInputRoot.vue b/packages/vue/src/ColorInput/ColorInputRoot.vue
deleted file mode 100644
index 443bef56d..000000000
--- a/packages/vue/src/ColorInput/ColorInputRoot.vue
+++ /dev/null
@@ -1,20 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-import { colorToHexRaw, parseColor } from '@open-pencil/core'
-
-import type { Color } from '@open-pencil/core'
-
-const { color } = defineProps<{ color: Color }>()
-const emit = defineEmits<{ update: [color: Color] }>()
-
-const hex = computed(() => colorToHexRaw(color))
-
-function updateFromHex(value: string) {
- const parsed = parseColor(value.startsWith('#') ? value : `#${value}`)
- emit('update', { ...parsed, a: color.a })
-}
-</script>
-
-<template>
- <slot :color="color" :hex="hex" :update-from-hex="updateFromHex" :update="(c: Color) => emit('update', c)" />
-</template>
diff --git a/packages/vue/src/ColorInput/index.ts b/packages/vue/src/ColorInput/index.ts
deleted file mode 100644
index a9d7ce228..000000000
--- a/packages/vue/src/ColorInput/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as ColorInputRoot } from './ColorInputRoot.vue'
diff --git a/packages/vue/src/ColorPicker/ColorPickerRoot.vue b/packages/vue/src/ColorPicker/ColorPickerRoot.vue
deleted file mode 100644
index 75e6a9f14..000000000
--- a/packages/vue/src/ColorPicker/ColorPickerRoot.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-import { colorToCSS } from '@open-pencil/core'
-
-import type { Color } from '@open-pencil/core'
-
-const { color } = defineProps<{ color: Color }>()
-const emit = defineEmits<{ update: [color: Color] }>()
-
-const swatchBg = computed(() => colorToCSS(color))
-
-function onUpdate(c: Color) {
- emit('update', c)
-}
-</script>
-
-<template>
- <slot :color="color" :swatch-bg="swatchBg" :update="onUpdate" />
-</template>
diff --git a/packages/vue/src/ColorPicker/index.ts b/packages/vue/src/ColorPicker/index.ts
deleted file mode 100644
index 660815af3..000000000
--- a/packages/vue/src/ColorPicker/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as ColorPickerRoot } from './ColorPickerRoot.vue'
diff --git a/packages/vue/src/EditorMenu/EditorMenuRoot.vue b/packages/vue/src/EditorMenu/EditorMenuRoot.vue
deleted file mode 100644
index e6caea531..000000000
--- a/packages/vue/src/EditorMenu/EditorMenuRoot.vue
+++ /dev/null
@@ -1,71 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from '../shared/useSceneComputed'
-
-import type { SceneNode } from '@open-pencil/core'
-
-const editor = useEditor()
-
-const selectedIds = useSceneComputed(() => editor.state.selectedIds)
-
-const hasSelection = computed(() => selectedIds.value.size > 0)
-const selectedCount = computed(() => selectedIds.value.size)
-
-const selectedNode = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
-
-const selectedType = computed(() => selectedNode.value?.type ?? null)
-const isInstance = computed(() => selectedType.value === 'INSTANCE')
-const isComponent = computed(() => selectedType.value === 'COMPONENT')
-const isGroup = computed(() => selectedType.value === 'GROUP')
-const isVisible = computed(() => selectedNode.value?.visible ?? true)
-const isLocked = computed(() => selectedNode.value?.locked ?? false)
-
-const canCreateComponentSet = computed(() => {
- if (selectedIds.value.size < 2) return false
- for (const id of selectedIds.value) {
- if (editor.graph.getNode(id)?.type !== 'COMPONENT') return false
- }
- return true
-})
-
-const otherPages = computed(() =>
- editor.graph.getPages().filter((p) => p.id !== editor.state.currentPageId)
-)
-
-function ids() {
- return [...selectedIds.value]
-}
-
-function copyAsText() {
- return editor.copySelectionAsText(ids())
-}
-
-function copyAsSVG() {
- return editor.copySelectionAsSVG(ids())
-}
-
-function copyAsJSX() {
- return editor.copySelectionAsJSX(ids())
-}
-</script>
-
-<template>
- <slot
- :editor="editor"
- :has-selection="hasSelection"
- :selected-count="selectedCount"
- :selected-node="selectedNode"
- :is-instance="isInstance"
- :is-component="isComponent"
- :is-group="isGroup"
- :is-visible="isVisible"
- :is-locked="isLocked"
- :can-create-component-set="canCreateComponentSet"
- :other-pages="otherPages"
- :copy-as-text="copyAsText"
- :copy-as-s-v-g="copyAsSVG"
- :copy-as-j-s-x="copyAsJSX"
- />
-</template>
diff --git a/packages/vue/src/EditorMenu/index.ts b/packages/vue/src/EditorMenu/index.ts
deleted file mode 100644
index 602f2605d..000000000
--- a/packages/vue/src/EditorMenu/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as EditorMenuRoot } from './EditorMenuRoot.vue'
diff --git a/packages/vue/src/ExportControls/ExportControlsRoot.vue b/packages/vue/src/ExportControls/ExportControlsRoot.vue
deleted file mode 100644
index 786204e87..000000000
--- a/packages/vue/src/ExportControls/ExportControlsRoot.vue
+++ /dev/null
@@ -1,63 +0,0 @@
-<script setup lang="ts">
-import { ref } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from '../shared/useSceneComputed'
-
-import type { ExportFormat } from '@open-pencil/core'
-
-interface ExportSetting {
- scale: number
- format: ExportFormat
-}
-
-const SCALES = [0.5, 0.75, 1, 1.5, 2, 3, 4] as const
-const FORMATS: ExportFormat[] = ['PNG', 'JPG', 'WEBP', 'SVG']
-
-const editor = useEditor()
-
-const settings = ref<ExportSetting[]>([{ scale: 1, format: 'PNG' }])
-
-const selectedIds = useSceneComputed(() => [...editor.state.selectedIds])
-
-const nodeName = useSceneComputed(() => {
- const ids = editor.state.selectedIds
- if (ids.size === 1) {
- const id = [...ids][0]
- return editor.graph.getNode(id)?.name ?? 'Export'
- }
- return `${ids.size} layers`
-})
-
-function addSetting() {
- const last = settings.value[settings.value.length - 1]
- const nextScale = SCALES.find((s) => s > (last?.scale ?? 1)) ?? 2
- settings.value.push({ scale: nextScale, format: last?.format ?? 'PNG' })
-}
-
-function removeSetting(index: number) {
- settings.value.splice(index, 1)
-}
-
-function updateScale(index: number, scale: number) {
- settings.value[index] = { ...settings.value[index], scale }
-}
-
-function updateFormat(index: number, format: ExportFormat) {
- settings.value[index] = { ...settings.value[index], format }
-}
-</script>
-
-<template>
- <slot
- :settings="settings"
- :selected-ids="selectedIds"
- :node-name="nodeName"
- :scales="SCALES"
- :formats="FORMATS"
- :add-setting="addSetting"
- :remove-setting="removeSetting"
- :update-scale="updateScale"
- :update-format="updateFormat"
- />
-</template>
diff --git a/packages/vue/src/ExportControls/index.ts b/packages/vue/src/ExportControls/index.ts
deleted file mode 100644
index 0787402bd..000000000
--- a/packages/vue/src/ExportControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as ExportControlsRoot } from './ExportControlsRoot.vue'
diff --git a/packages/vue/src/FillPicker/FillPickerRoot.vue b/packages/vue/src/FillPicker/FillPickerRoot.vue
deleted file mode 100644
index ea8bf27fa..000000000
--- a/packages/vue/src/FillPicker/FillPickerRoot.vue
+++ /dev/null
@@ -1,71 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-import { colorToCSS } from '@open-pencil/core'
-
-import type { Fill, GradientStop } from '@open-pencil/core'
-
-type FillCategory = 'SOLID' | 'GRADIENT' | 'IMAGE'
-
-const FILL_CATEGORY: Record<string, FillCategory> = {
- SOLID: 'SOLID',
- GRADIENT_LINEAR: 'GRADIENT',
- GRADIENT_RADIAL: 'GRADIENT',
- GRADIENT_ANGULAR: 'GRADIENT',
- GRADIENT_DIAMOND: 'GRADIENT',
- IMAGE: 'IMAGE'
-}
-
-const { fill } = defineProps<{ fill: Fill }>()
-const emit = defineEmits<{ update: [fill: Fill] }>()
-
-const category = computed(() => FILL_CATEGORY[fill.type] ?? 'SOLID')
-
-function toSolid() {
- if (category.value === 'SOLID') return
- const color = fill.gradientStops?.[0]?.color ?? fill.color
- emit('update', { ...fill, type: 'SOLID', color: { ...color } })
-}
-
-function toGradient() {
- if (category.value === 'GRADIENT') return
- const stops: GradientStop[] = fill.gradientStops?.length
- ? fill.gradientStops
- : [
- { color: { ...fill.color }, position: 0 },
- { color: { r: 1, g: 1, b: 1, a: 1 }, position: 1 }
- ]
- emit('update', {
- ...fill,
- type: 'GRADIENT_LINEAR',
- gradientStops: stops,
- gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 0, m12: 0.5 }
- })
-}
-
-function toImage() {
- if (category.value === 'IMAGE') return
- emit('update', { ...fill, type: 'IMAGE' })
-}
-
-function gradientCSS(stops: GradientStop[]): string {
- return stops.map((s) => `${colorToCSS(s.color)} ${s.position * 100}%`).join(', ')
-}
-
-const swatchBg = computed(() => {
- if (category.value === 'GRADIENT' && fill.gradientStops?.length)
- return `linear-gradient(to right, ${gradientCSS(fill.gradientStops)})`
- return colorToCSS(fill.color)
-})
-
-</script>
-
-<template>
- <slot
- :fill="fill"
- :category="category"
- :swatch-bg="swatchBg"
- :to-solid="toSolid"
- :to-gradient="toGradient"
- :to-image="toImage"
- />
-</template>
diff --git a/packages/vue/src/FillPicker/index.ts b/packages/vue/src/FillPicker/index.ts
deleted file mode 100644
index 554f42ad9..000000000
--- a/packages/vue/src/FillPicker/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as FillPickerRoot } from './FillPickerRoot.vue'
diff --git a/packages/vue/src/FontPicker/FontPickerRoot.vue b/packages/vue/src/FontPicker/FontPickerRoot.vue
deleted file mode 100644
index 1c57ad799..000000000
--- a/packages/vue/src/FontPicker/FontPickerRoot.vue
+++ /dev/null
@@ -1,48 +0,0 @@
-<script setup lang="ts">
-import { computed, onMounted, ref, watch } from 'vue'
-import { useFilter } from 'reka-ui'
-
-const modelValue = defineModel<string>({ required: true })
-const emit = defineEmits<{ select: [family: string] }>()
-
-const { listFamilies } = defineProps<{
- listFamilies: () => Promise<string[]>
-}>()
-
-const families = ref<string[]>([])
-const searchTerm = ref('')
-const open = ref(false)
-
-const { contains } = useFilter({ sensitivity: 'base' })
-const filtered = computed(() => {
- if (!searchTerm.value) return families.value
- return families.value.filter((f) => contains(f, searchTerm.value))
-})
-
-onMounted(async () => {
- families.value = await listFamilies()
-})
-
-watch(open, (isOpen) => {
- if (isOpen) searchTerm.value = ''
-})
-
-function select(family: string) {
- modelValue.value = family
- emit('select', family)
- open.value = false
-}
-</script>
-
-<template>
- <slot
- :families="families"
- :filtered="filtered"
- :search-term="searchTerm"
- :open="open"
- :model-value="modelValue"
- :select="select"
- :set-search-term="(v: string) => (searchTerm = v)"
- :set-open="(v: boolean) => (open = v)"
- />
-</template>
diff --git a/packages/vue/src/FontPicker/index.ts b/packages/vue/src/FontPicker/index.ts
deleted file mode 100644
index 1195a355f..000000000
--- a/packages/vue/src/FontPicker/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as FontPickerRoot } from './FontPickerRoot.vue'
diff --git a/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue b/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue
deleted file mode 100644
index afda50180..000000000
--- a/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue
+++ /dev/null
@@ -1,70 +0,0 @@
-<script setup lang="ts">
-import { computed, shallowRef, watch } from 'vue'
-import { useFileDialog, useObjectUrl } from '@vueuse/core'
-
-import type { Fill, ImageScaleMode } from '@open-pencil/core'
-
-const IMAGE_SCALE_MODES: { value: ImageScaleMode; label: string }[] = [
- { value: 'FILL', label: 'Fill' },
- { value: 'FIT', label: 'Fit' },
- { value: 'CROP', label: 'Crop' },
- { value: 'TILE', label: 'Tile' }
-]
-
-const { fill, resolveImage, storeImage } = defineProps<{
- fill: Fill
- resolveImage: (hash: string) => Uint8Array | undefined
- storeImage: (bytes: Uint8Array) => string
-}>()
-const emit = defineEmits<{ update: [fill: Fill] }>()
-
-const imageBlob = shallowRef<Blob | null>(null)
-const imagePreviewUrl = useObjectUrl(imageBlob)
-
-watch(
- () => fill.imageHash,
- (hash) => {
- if (!hash) {
- imageBlob.value = null
- return
- }
- const data = resolveImage(hash)
- imageBlob.value = data ? new Blob([data]) : null
- },
- { immediate: true }
-)
-
-const { open: pickImage, onChange: onFileChange } = useFileDialog({
- accept: 'image/png,image/jpeg,image/webp',
- multiple: false
-})
-
-onFileChange(async (files) => {
- const file = files?.[0]
- if (!file) return
- const bytes = new Uint8Array(await file.arrayBuffer())
- const hash = storeImage(bytes)
- emit('update', {
- ...fill,
- type: 'IMAGE',
- imageHash: hash,
- imageScaleMode: fill.imageScaleMode ?? 'FILL'
- })
-})
-
-const scaleMode = computed({
- get: () => fill.imageScaleMode ?? ('FILL' as ImageScaleMode),
- set: (mode: ImageScaleMode) => emit('update', { ...fill, imageScaleMode: mode })
-})
-</script>
-
-<template>
- <slot
- :fill="fill"
- :image-preview-url="imagePreviewUrl"
- :scale-mode="scaleMode"
- :scale-modes="IMAGE_SCALE_MODES"
- :pick-image="() => pickImage()"
- :set-scale-mode="(m: ImageScaleMode) => (scaleMode = m)"
- />
-</template>
diff --git a/packages/vue/src/ImageFillControls/index.ts b/packages/vue/src/ImageFillControls/index.ts
deleted file mode 100644
index e0cecb289..000000000
--- a/packages/vue/src/ImageFillControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as ImageFillControlsRoot } from './ImageFillControlsRoot.vue'
diff --git a/packages/vue/src/LayoutControls/LayoutControlsRoot.vue b/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
deleted file mode 100644
index e9d806d6e..000000000
--- a/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
+++ /dev/null
@@ -1,189 +0,0 @@
-<script setup lang="ts">
-import { computed, ref } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-
-import type {
- SceneNode,
- LayoutSizing,
- LayoutAlign,
- LayoutCounterAlign,
- GridTrack
-} from '@open-pencil/core'
-
-const editor = useEditor()
-
-const node = computed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
-
-const isInAutoLayout = computed(() => {
- const n = node.value
- if (!n?.parentId) return false
- const parent = editor.getNode(n.parentId)
- return parent ? parent.layoutMode !== 'NONE' : false
-})
-
-const isGrid = computed(() => node.value?.layoutMode === 'GRID')
-const isFlex = computed(
- () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'
-)
-
-const widthSizing = computed<LayoutSizing>(() => {
- const n = node.value
- if (!n) return 'FIXED'
- if (isFlex.value) return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
- if (isInAutoLayout.value && n.layoutGrow > 0) return 'FILL'
- return 'FIXED'
-})
-
-const heightSizing = computed<LayoutSizing>(() => {
- const n = node.value
- if (!n) return 'FIXED'
- if (isFlex.value) return n.layoutMode === 'VERTICAL' ? n.primaryAxisSizing : n.counterAxisSizing
- if (isInAutoLayout.value && n.layoutAlignSelf === 'STRETCH') return 'FILL'
- return 'FIXED'
-})
-
-const widthSizingOptions = computed(() => {
- const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
- if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
- if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
- return options
-})
-
-const heightSizingOptions = computed(() => {
- const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
- if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
- if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
- return options
-})
-
-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' }
-]
-
-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' }
-]
-
-const alignGrid = computed(() =>
- node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL
-)
-
-const showIndividualPadding = ref(false)
-
-const hasUniformPadding = computed(() => {
- const n = node.value
- if (!n) return true
- return n.paddingTop === n.paddingRight && n.paddingRight === n.paddingBottom && n.paddingBottom === n.paddingLeft
-})
-
-function updateProp(key: string, value: number | string) {
- if (node.value) editor.updateNode(node.value.id, { [key]: value })
-}
-
-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}`)
-}
-
-function setWidthSizing(sizing: LayoutSizing) {
- if (!node.value) return
- if (isFlex.value) {
- const key = node.value.layoutMode === 'HORIZONTAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
- updateProp(key, sizing)
- } else if (isInAutoLayout.value) {
- updateProp('layoutGrow', sizing === 'FILL' ? 1 : 0)
- }
-}
-
-function setHeightSizing(sizing: LayoutSizing) {
- if (!node.value) return
- if (isFlex.value) {
- const key = node.value.layoutMode === 'VERTICAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
- updateProp(key, sizing)
- } else if (isInAutoLayout.value) {
- updateProp('layoutAlignSelf', sizing === 'FILL' ? 'STRETCH' : 'AUTO')
- }
-}
-
-function setUniformPadding(v: number) {
- if (!node.value) return
- 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')
-}
-
-function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
- if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { primaryAxisAlign: primary, counterAxisAlign: counter }, 'Change alignment')
-}
-
-function updateGridTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number, updates: Partial<GridTrack>) {
- if (!node.value) return
- const tracks = [...node.value[prop]]
- tracks[index] = { ...tracks[index], ...updates }
- editor.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')
-}
-
-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')
-}
-
-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')
-}
-
-function trackLabel(track: GridTrack): string {
- if (track.sizing === 'FR') return `${track.value}fr`
- if (track.sizing === 'FIXED') return `${track.value}px`
- return 'Auto'
-}
-
-const TRACK_SIZING_OPTIONS = [
- { value: 'FR' as const, label: 'Fill (fr)' },
- { value: 'FIXED' as const, label: 'Fixed (px)' },
- { value: 'AUTO' as const, label: 'Auto' }
-]
-</script>
-
-<template>
- <slot
- v-if="node"
- :node="node"
- :is-in-auto-layout="isInAutoLayout"
- :is-grid="isGrid"
- :is-flex="isFlex"
- :width-sizing="widthSizing"
- :height-sizing="heightSizing"
- :width-sizing-options="widthSizingOptions"
- :height-sizing-options="heightSizingOptions"
- :align-grid="alignGrid"
- :show-individual-padding="showIndividualPadding"
- :has-uniform-padding="hasUniformPadding"
- :track-sizing-options="TRACK_SIZING_OPTIONS"
- :update-prop="updateProp"
- :commit-prop="commitProp"
- :set-width-sizing="setWidthSizing"
- :set-height-sizing="setHeightSizing"
- :set-uniform-padding="setUniformPadding"
- :commit-uniform-padding="commitUniformPadding"
- :set-alignment="setAlignment"
- :update-grid-track="updateGridTrack"
- :add-track="addTrack"
- :remove-track="removeTrack"
- :track-label="trackLabel"
- :toggle-individual-padding="() => { showIndividualPadding = !showIndividualPadding }"
- />
-</template>
diff --git a/packages/vue/src/LayoutControls/index.ts b/packages/vue/src/LayoutControls/index.ts
deleted file mode 100644
index b6899b659..000000000
--- a/packages/vue/src/LayoutControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as LayoutControlsRoot } from './LayoutControlsRoot.vue'
diff --git a/packages/vue/src/PageControls/PageControlsRoot.vue b/packages/vue/src/PageControls/PageControlsRoot.vue
deleted file mode 100644
index 5c41a2325..000000000
--- a/packages/vue/src/PageControls/PageControlsRoot.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-
-import type { Color } from '@open-pencil/core'
-
-const editor = useEditor()
-
-const pageColor = computed(() => editor.state.pageColor)
-
-function setPageColor(color: Color) {
- editor.setPageColor(color)
-}
-</script>
-
-<template>
- <slot :page-color="pageColor" :set-page-color="setPageColor" />
-</template>
diff --git a/packages/vue/src/PageControls/index.ts b/packages/vue/src/PageControls/index.ts
deleted file mode 100644
index 86dff4164..000000000
--- a/packages/vue/src/PageControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as PageControlsRoot } from './PageControlsRoot.vue'
diff --git a/packages/vue/src/PageList/PageListRoot.vue b/packages/vue/src/PageList/PageListRoot.vue
deleted file mode 100644
index 1641d43b5..000000000
--- a/packages/vue/src/PageList/PageListRoot.vue
+++ /dev/null
@@ -1,22 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from '../shared/useSceneComputed'
-
-const editor = useEditor()
-
-const pages = useSceneComputed(() => editor.graph.getPages())
-const currentPageId = computed(() => editor.state.currentPageId)
-</script>
-
-<template>
- <slot
- :pages="pages"
- :current-page-id="currentPageId"
- :switch-page="editor.switchPage"
- :add-page="editor.addPage"
- :delete-page="editor.deletePage"
- :rename-page="editor.renamePage"
- />
-</template>
diff --git a/packages/vue/src/PageList/index.ts b/packages/vue/src/PageList/index.ts
deleted file mode 100644
index abb1df0a1..000000000
--- a/packages/vue/src/PageList/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as PageListRoot } from './PageListRoot.vue'
diff --git a/packages/vue/src/PositionControls/PositionControlsRoot.vue b/packages/vue/src/PositionControls/PositionControlsRoot.vue
deleted file mode 100644
index 802de5db0..000000000
--- a/packages/vue/src/PositionControls/PositionControlsRoot.vue
+++ /dev/null
@@ -1,63 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { usePropScrub } from '../shared/usePropScrub'
-
-import type { SceneNode } from '@open-pencil/core'
-
-const editor = useEditor()
-
-const nodes = computed(() => editor.getSelectedNodes())
-const node = computed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
-const active = computed(() => nodes.value.length > 0)
-const isMulti = computed(() => nodes.value.length > 1)
-const ids = computed(() => nodes.value.map((n) => n.id))
-
-const x = computed(() => Math.round(node.value?.x ?? 0))
-const y = computed(() => Math.round(node.value?.y ?? 0))
-const width = computed(() => node.value?.width ?? 0)
-const height = computed(() => node.value?.height ?? 0)
-const rotation = computed(() => Math.round(node.value?.rotation ?? 0))
-
-const { updateProp: _updateProp, commitProp: _commitProp } = usePropScrub(editor)
-
-function updateProp(key: string, value: number) {
- _updateProp(nodes.value, key, value)
-}
-
-function commitProp(key: string, _value: number, previous: number) {
- _commitProp(nodes.value, key, _value, previous)
-}
-
-function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {
- editor.alignNodes(ids.value, axis, pos)
-}
-
-function flip(axis: 'horizontal' | 'vertical') {
- editor.flipNodes(ids.value, axis)
-}
-
-function rotate(degrees: number) {
- editor.rotateNodes(ids.value, degrees)
-}
-</script>
-
-<template>
- <slot
- v-if="active"
- :node="node"
- :nodes="nodes"
- :is-multi="isMulti"
- :x="x"
- :y="y"
- :width="width"
- :height="height"
- :rotation="rotation"
- :update-prop="updateProp"
- :commit-prop="commitProp"
- :align="align"
- :flip="flip"
- :rotate="rotate"
- />
-</template>
diff --git a/packages/vue/src/PositionControls/index.ts b/packages/vue/src/PositionControls/index.ts
deleted file mode 100644
index 9fb0f748a..000000000
--- a/packages/vue/src/PositionControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as PositionControlsRoot } from './PositionControlsRoot.vue'
diff --git a/packages/vue/src/TypographyControls/TypographyControlsRoot.vue b/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
deleted file mode 100644
index 85d7fb983..000000000
--- a/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
+++ /dev/null
@@ -1,133 +0,0 @@
-<script setup lang="ts">
-import { computed, onMounted } from 'vue'
-
-import { FONT_WEIGHT_NAMES, weightToStyle } from '@open-pencil/core'
-
-import type { SceneNode, TextDecoration } from '@open-pencil/core'
-
-import { useEditor } from '../shared/editorContext'
-import { useNodeFontStatus } from '../shared/useFontStatus'
-
-type TextAlign = 'LEFT' | 'CENTER' | 'RIGHT'
-
-const WEIGHTS = Object.entries(FONT_WEIGHT_NAMES).map(([value, label]) => ({
- value: Number(value),
- label
-}))
-
-const props = defineProps<{
- loadFont?: (family: string, style: string) => Promise<unknown>
-}>()
-
-const editor = useEditor()
-
-const node = computed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
-
-const { missingFonts, hasMissingFonts } = useNodeFontStatus(() => node.value)
-
-const currentWeightLabel = computed(() =>
- FONT_WEIGHT_NAMES[node.value?.fontWeight ?? 400] ?? 'Regular'
-)
-
-const activeFormatting = computed(() => {
- const n = node.value
- if (!n) return []
- const result: string[] = []
- if (n.fontWeight >= 700) result.push('bold')
- if (n.italic) result.push('italic')
- if (n.textDecoration === 'UNDERLINE') result.push('underline')
- if (n.textDecoration === 'STRIKETHROUGH') result.push('strikethrough')
- return result
-})
-
-async function doLoadFont(family: string, style: string) {
- if (props.loadFont) await props.loadFont(family, style)
-}
-
-async function setFamily(family: string) {
- if (!node.value) return
- await doLoadFont(family, currentWeightLabel.value)
- editor.updateNodeWithUndo(node.value.id, { fontFamily: family }, 'Change font')
-}
-
-async function setWeight(weight: number) {
- if (!node.value) return
- const style = weightToStyle(weight)
- await doLoadFont(node.value.fontFamily, style)
- editor.updateNodeWithUndo(node.value.id, { fontWeight: weight }, 'Change font weight')
-}
-
-function setAlign(align: TextAlign) {
- if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { textAlignHorizontal: align }, 'Change text alignment')
-}
-
-function toggleBold() {
- if (!node.value) return
- setWeight(node.value.fontWeight >= 700 ? 400 : 700)
-}
-
-function toggleItalic() {
- if (!node.value) return
- editor.updateNodeWithUndo(node.value.id, { italic: !node.value.italic }, 'Toggle italic')
-}
-
-function toggleDecoration(deco: 'UNDERLINE' | 'STRIKETHROUGH') {
- if (!node.value) return
- const current = node.value.textDecoration
- editor.updateNodeWithUndo(
- node.value.id,
- { textDecoration: (current === deco ? 'NONE' : deco) as TextDecoration },
- `Toggle ${deco.toLowerCase()}`
- )
-}
-
-function onFormattingChange(values: string[]) {
- if (!node.value) return
- const prev = activeFormatting.value
- const added = values.filter((v) => !prev.includes(v))
- const removed = prev.filter((v) => !values.includes(v))
- for (const item of [...added, ...removed]) {
- if (item === 'bold') toggleBold()
- else if (item === 'italic') toggleItalic()
- else if (item === 'underline') toggleDecoration('UNDERLINE')
- else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')
- }
-}
-
-function updateProp(key: string, value: number | string) {
- if (node.value) editor.updateNode(node.value.id, { [key]: value })
-}
-
-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}`)
- }
-}
-
-onMounted(async () => {
- if (!node.value) return
- await doLoadFont(node.value.fontFamily, currentWeightLabel.value)
-})
-</script>
-
-<template>
- <slot
- v-if="node"
- :node="node"
- :weights="WEIGHTS"
- :current-weight-label="currentWeightLabel"
- :active-formatting="activeFormatting"
- :missing-fonts="missingFonts"
- :has-missing-fonts="hasMissingFonts"
- :set-family="setFamily"
- :set-weight="setWeight"
- :set-align="setAlign"
- :toggle-bold="toggleBold"
- :toggle-italic="toggleItalic"
- :toggle-decoration="toggleDecoration"
- :on-formatting-change="onFormattingChange"
- :update-prop="updateProp"
- :commit-prop="commitProp"
- />
-</template>
diff --git a/packages/vue/src/TypographyControls/index.ts b/packages/vue/src/TypographyControls/index.ts
deleted file mode 100644
index 1c2ea0745..000000000
--- a/packages/vue/src/TypographyControls/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as TypographyControlsRoot } from './TypographyControlsRoot.vue'
diff --git a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
deleted file mode 100644
index 014a9a04b..000000000
--- a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
+++ /dev/null
@@ -1,139 +0,0 @@
-<script setup lang="ts">
-import { ref, computed, watch } from 'vue'
-import { colorToHexRaw, parseColor, randomHex } from '@open-pencil/core'
-
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from '../shared/useSceneComputed'
-
-import type { Color, Variable, VariableCollection, VariableValue } from '@open-pencil/core'
-
-const editor = useEditor()
-const searchTerm = ref('')
-
-function setSearchTerm(term: string) {
- searchTerm.value = term
-}
-
-const collections = useSceneComputed(() => editor.getCollections())
-
-const activeCollectionId = ref(collections.value[0]?.id ?? '')
-watch(collections, (cols) => {
- if (!activeCollectionId.value && cols[0]) activeCollectionId.value = cols[0].id
-})
-
-const activeCollection = computed(() => editor.getCollection(activeCollectionId.value) ?? null)
-
-const activeModes = computed(() => activeCollection.value?.modes ?? [])
-
-const variables = useSceneComputed(() => {
- if (!activeCollectionId.value) return [] as Variable[]
- const all = editor.getVariablesForCollection(activeCollectionId.value)
- if (!searchTerm.value) return all
- const q = searchTerm.value.toLowerCase()
- return all.filter((v) => v.name.toLowerCase().includes(q))
-})
-
-function setActiveCollection(id: string) {
- activeCollectionId.value = id
-}
-
-function addCollection() {
- const id = `col:${randomHex(8)}`
- const collection: VariableCollection = {
- id,
- name: 'New collection',
- modes: [{ modeId: 'default', name: 'Mode 1' }],
- defaultModeId: 'default',
- variableIds: []
- }
- editor.addCollection(collection)
- activeCollectionId.value = id
-}
-
-function renameCollection(id: string, newName: string) {
- editor.renameCollection(id, newName)
-}
-
-function addVariable() {
- const col = activeCollection.value
- if (!col) return
-
- const id = `var:${randomHex(8)}`
- const valuesByMode: Record<string, VariableValue> = {}
- for (const mode of col.modes) {
- valuesByMode[mode.modeId] = { r: 0, g: 0, b: 0, a: 1 }
- }
-
- editor.addVariable({
- id,
- name: 'New variable',
- type: 'COLOR',
- collectionId: col.id,
- valuesByMode,
- description: '',
- hiddenFromPublishing: false
- })
-}
-
-function removeVariable(id: string) {
- editor.removeVariable(id)
-}
-
-function renameVariable(id: string, newName: string) {
- editor.renameVariable(id, newName)
-}
-
-function updateVariableValue(id: string, modeId: string, value: VariableValue) {
- editor.updateVariableValue(id, modeId, value)
-}
-
-function formatModeValue(variable: Variable, modeId: string): string {
- const value = variable.valuesByMode[modeId]
- if (value === undefined) return '—'
- if (typeof value === 'object' && 'r' in value) return colorToHexRaw(value as Color)
- if (typeof value === 'object' && 'aliasId' in value) {
- const aliased = editor.getVariable(value.aliasId)
- return aliased ? `→ ${aliased.name}` : '→ ?'
- }
- return String(value)
-}
-
-function parseVariableValue(variable: Variable, raw: string): VariableValue | undefined {
- if (variable.type === 'COLOR') {
- return parseColor(raw.startsWith('#') ? raw : `#${raw}`) ?? undefined
- }
- if (variable.type === 'FLOAT') {
- const num = parseFloat(raw)
- return isNaN(num) ? undefined : num
- }
- if (variable.type === 'BOOLEAN') return raw === 'true'
- return raw
-}
-
-function shortName(variable: Variable): string {
- const parts = variable.name.split('/')
- return parts[parts.length - 1] ?? variable.name
-}
-</script>
-
-<template>
- <slot
- :collections="collections"
- :active-collection-id="activeCollectionId"
- :active-collection="activeCollection"
- :active-modes="activeModes"
- :variables="variables"
- :search-term="searchTerm"
- :set-search-term="setSearchTerm"
- :set-active-collection="setActiveCollection"
- :add-collection="addCollection"
- :rename-collection="renameCollection"
- :add-variable="addVariable"
- :remove-variable="removeVariable"
- :rename-variable="renameVariable"
- :update-variable-value="updateVariableValue"
- :format-mode-value="formatModeValue"
- :parse-variable-value="parseVariableValue"
- :short-name="shortName"
- />
-</template>
diff --git a/packages/vue/src/VariablesEditor/index.ts b/packages/vue/src/VariablesEditor/index.ts
deleted file mode 100644
index da6554126..000000000
--- a/packages/vue/src/VariablesEditor/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as VariablesEditorRoot } from './VariablesEditorRoot.vue'
diff --git a/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue b/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue
deleted file mode 100644
index 722fbc640..000000000
--- a/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue
+++ /dev/null
@@ -1,20 +0,0 @@
-<script setup lang="ts">
-import { computed } from 'vue'
-
-import { useEditor } from '../shared/editorContext'
-import { useSceneComputed } from '../shared/useSceneComputed'
-
-const editor = useEditor()
-
-const collectionCount = useSceneComputed(() => editor.getCollectionCount())
-const variableCount = useSceneComputed(() => editor.getVariableCount())
-const hasVariables = computed(() => variableCount.value > 0)
-</script>
-
-<template>
- <slot
- :collection-count="collectionCount"
- :variable-count="variableCount"
- :has-variables="hasVariables"
- />
-</template>
diff --git a/packages/vue/src/VariablesIndicator/index.ts b/packages/vue/src/VariablesIndicator/index.ts
deleted file mode 100644
index fbdb4b6ec..000000000
--- a/packages/vue/src/VariablesIndicator/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as VariablesIndicatorRoot } from './VariablesIndicatorRoot.vue'
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index 05320363f..006e5e72f 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -17,25 +17,20 @@ export { useInlineRename } from './shared/useInlineRename'
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 { useFillPicker } from './shared/useFillPicker'
+export { useGradientStops } from './shared/useGradientStops'
+export { usePageList } from './shared/usePageList'
-export * from './AppearanceControls'
export * from './Canvas'
-export * from './ColorInput'
-export * from './ColorPicker'
-export * from './EditorMenu'
-export * from './ExportControls'
-export * from './FillPicker'
-export * from './FontPicker'
export * from './GradientEditor'
-export * from './ImageFillControls'
export * from './LayerTree'
-export * from './LayoutControls'
-export * from './PageControls'
-export * from './PageList'
-export * from './PositionControls'
export * from './PropertyList'
export * from './ScrubInput'
export * from './Toolbar'
-export * from './TypographyControls'
-export * from './VariablesEditor'
-export * from './VariablesIndicator'
diff --git a/packages/vue/src/shared/useAppearance.ts b/packages/vue/src/shared/useAppearance.ts
new file mode 100644
index 000000000..76e6b6cb1
--- /dev/null
+++ b/packages/vue/src/shared/useAppearance.ts
@@ -0,0 +1,157 @@
+import { computed } from 'vue'
+
+import { useEditor } from './editorContext'
+import { MIXED } from './useNodeProps'
+import { usePropScrub } from './usePropScrub'
+import { useSceneComputed } from './useSceneComputed'
+
+import type { SceneNode } from '@open-pencil/core'
+import type { MixedValue } from './useNodeProps'
+
+const CORNER_RADIUS_TYPES = new Set([
+ 'RECTANGLE',
+ 'ROUNDED_RECTANGLE',
+ 'FRAME',
+ 'COMPONENT',
+ 'INSTANCE'
+])
+
+export function useAppearance() {
+ const editor = useEditor()
+
+ const nodes = useSceneComputed(() => editor.getSelectedNodes())
+ const node = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
+ const active = computed(() => nodes.value.length > 0)
+ const isMulti = computed(() => nodes.value.length > 1)
+
+ function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {
+ const all = nodes.value
+ if (all.length === 0) return MIXED
+ const first = all[0][key]
+ for (let i = 1; i < all.length; i++) {
+ if (all[i][key] !== first) return MIXED
+ }
+ return first
+ }
+
+ const hasCornerRadius = computed(() => {
+ if (isMulti.value) return nodes.value.every((n) => CORNER_RADIUS_TYPES.has(n.type))
+ return node.value ? CORNER_RADIUS_TYPES.has(node.value.type) : false
+ })
+
+ const independentCorners = computed(() => {
+ if (isMulti.value) return merged('independentCorners')
+ return node.value?.independentCorners ?? false
+ })
+
+ const cornerRadiusValue = computed(() => {
+ if (isMulti.value) return merged('cornerRadius')
+ return node.value?.cornerRadius ?? 0
+ })
+
+ const opacityPercent = computed(() => {
+ const v = merged('opacity')
+ return v === MIXED ? MIXED : Math.round((v as number) * 100)
+ })
+
+ const visibilityState = computed<'visible' | 'hidden' | 'mixed'>(() => {
+ const v = merged('visible')
+ if (v === MIXED) return 'mixed'
+ return v ? 'visible' : 'hidden'
+ })
+
+ const { updateProp: _updateProp, commitProp: _commitProp } = usePropScrub(editor)
+
+ function updateProp(key: string, value: number | string) {
+ _updateProp(nodes.value, key, value)
+ }
+
+ function commitProp(key: string, value: number | string, previous: number | string) {
+ _commitProp(nodes.value, key, value, previous)
+ }
+
+ function toggleVisibility() {
+ if (isMulti.value) {
+ const allVisible = nodes.value.every((n) => n.visible)
+ for (const n of nodes.value) {
+ editor.updateNodeWithUndo(n.id, { visible: !allVisible }, 'Toggle visibility')
+ }
+ } else {
+ const n = node.value
+ if (!n) return
+ editor.updateNodeWithUndo(n.id, { visible: !n.visible }, 'Toggle visibility')
+ }
+ }
+
+ function toggleIndependentCorners() {
+ const targets = isMulti.value ? nodes.value : node.value ? [node.value] : []
+ for (const n of targets) {
+ if (n.independentCorners) {
+ const uniform = n.topLeftRadius
+ editor.updateNodeWithUndo(
+ n.id,
+ {
+ independentCorners: false,
+ cornerRadius: uniform,
+ topLeftRadius: uniform,
+ topRightRadius: uniform,
+ bottomRightRadius: uniform,
+ bottomLeftRadius: uniform
+ } as Partial<SceneNode>,
+ 'Uniform corner radius'
+ )
+ } else {
+ editor.updateNodeWithUndo(
+ n.id,
+ {
+ independentCorners: true,
+ topLeftRadius: n.cornerRadius,
+ topRightRadius: n.cornerRadius,
+ bottomRightRadius: n.cornerRadius,
+ bottomLeftRadius: n.cornerRadius
+ } as Partial<SceneNode>,
+ 'Independent corner radii'
+ )
+ }
+ }
+ }
+
+ function updateCornerProp(key: string, value: number) {
+ if (isMulti.value) {
+ for (const n of nodes.value) editor.updateNode(n.id, { [key]: value })
+ } else {
+ const n = node.value
+ if (n) editor.updateNode(n.id, { [key]: value })
+ }
+ }
+
+ function commitCornerProp(key: string, _value: number, previous: number) {
+ if (isMulti.value) {
+ for (const n of nodes.value) {
+ editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ }
+ } else {
+ const n = node.value
+ if (n) editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ }
+ }
+
+ return {
+ editor,
+ nodes,
+ node,
+ active,
+ isMulti,
+ hasCornerRadius,
+ independentCorners,
+ cornerRadiusValue,
+ opacityPercent,
+ visibilityState,
+ updateProp,
+ commitProp,
+ toggleVisibility,
+ toggleIndependentCorners,
+ updateCornerProp,
+ commitCornerProp
+ }
+}
diff --git a/packages/vue/src/shared/useExport.ts b/packages/vue/src/shared/useExport.ts
new file mode 100644
index 000000000..a14330f0d
--- /dev/null
+++ b/packages/vue/src/shared/useExport.ts
@@ -0,0 +1,62 @@
+import { ref } from 'vue'
+
+import { useEditor } from './editorContext'
+import { useSceneComputed } from './useSceneComputed'
+
+import type { ExportFormat } from '@open-pencil/core'
+
+interface ExportSetting {
+ scale: number
+ format: ExportFormat
+}
+
+const SCALES = [0.5, 0.75, 1, 1.5, 2, 3, 4] as const
+const FORMATS: ExportFormat[] = ['PNG', 'JPG', 'WEBP', 'SVG']
+
+export function useExport() {
+ const editor = useEditor()
+
+ const settings = ref<ExportSetting[]>([{ scale: 1, format: 'PNG' }])
+
+ const selectedIds = useSceneComputed(() => [...editor.state.selectedIds])
+
+ const nodeName = useSceneComputed(() => {
+ const ids = editor.state.selectedIds
+ if (ids.size === 1) {
+ const id = [...ids][0]
+ return editor.graph.getNode(id)?.name ?? 'Export'
+ }
+ return `${ids.size} layers`
+ })
+
+ function addSetting() {
+ const last = settings.value[settings.value.length - 1]
+ const nextScale = SCALES.find((s) => s > (last?.scale ?? 1)) ?? 2
+ settings.value.push({ scale: nextScale, format: last?.format ?? 'PNG' })
+ }
+
+ function removeSetting(index: number) {
+ settings.value.splice(index, 1)
+ }
+
+ function updateScale(index: number, scale: number) {
+ settings.value[index] = { ...settings.value[index], scale }
+ }
+
+ function updateFormat(index: number, format: ExportFormat) {
+ settings.value[index] = { ...settings.value[index], format }
+ }
+
+ return {
+ editor,
+ settings,
+ selectedIds,
+ nodeName,
+ scales: SCALES,
+ formats: FORMATS,
+ addSetting,
+ removeSetting,
+ updateScale,
+ updateFormat
+ }
+}
diff --git a/packages/vue/src/shared/useFillPicker.ts b/packages/vue/src/shared/useFillPicker.ts
new file mode 100644
index 000000000..2b9e58376
--- /dev/null
+++ b/packages/vue/src/shared/useFillPicker.ts
@@ -0,0 +1,67 @@
+import { computed, type Ref } from 'vue'
+import { colorToCSS } from '@open-pencil/core'
+
+import type { Fill, GradientStop } from '@open-pencil/core'
+
+type FillCategory = 'SOLID' | 'GRADIENT' | 'IMAGE'
+
+const FILL_CATEGORY: Record<string, FillCategory> = {
+ SOLID: 'SOLID',
+ GRADIENT_LINEAR: 'GRADIENT',
+ GRADIENT_RADIAL: 'GRADIENT',
+ GRADIENT_ANGULAR: 'GRADIENT',
+ GRADIENT_DIAMOND: 'GRADIENT',
+ IMAGE: 'IMAGE'
+}
+
+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
+) {
+ const category = computed(() => FILL_CATEGORY[fill.value.type] ?? 'SOLID')
+
+ function toSolid() {
+ if (category.value === 'SOLID') return
+ const color = fill.value.gradientStops?.[0]?.color ?? fill.value.color
+ onUpdate({ ...fill.value, type: 'SOLID', color: { ...color } })
+ }
+
+ function toGradient() {
+ if (category.value === 'GRADIENT') return
+ const stops: GradientStop[] = fill.value.gradientStops?.length
+ ? fill.value.gradientStops
+ : [
+ { color: { ...fill.value.color }, position: 0 },
+ { color: { r: 1, g: 1, b: 1, a: 1 }, position: 1 }
+ ]
+ onUpdate({
+ ...fill.value,
+ type: 'GRADIENT_LINEAR',
+ gradientStops: stops,
+ gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 0, m12: 0.5 }
+ })
+ }
+
+ function toImage() {
+ if (category.value === 'IMAGE') return
+ onUpdate({ ...fill.value, type: 'IMAGE' })
+ }
+
+ const swatchBg = computed(() => {
+ if (category.value === 'GRADIENT' && fill.value.gradientStops?.length)
+ return `linear-gradient(to right, ${gradientCSS(fill.value.gradientStops)})`
+ return colorToCSS(fill.value.color)
+ })
+
+ return {
+ category,
+ swatchBg,
+ toSolid,
+ toGradient,
+ toImage
+ }
+}
diff --git a/packages/vue/src/shared/useGradientStops.ts b/packages/vue/src/shared/useGradientStops.ts
new file mode 100644
index 000000000..b83802871
--- /dev/null
+++ b/packages/vue/src/shared/useGradientStops.ts
@@ -0,0 +1,124 @@
+import { computed, ref, type Ref } from 'vue'
+import { colorToCSS, parseColor } from '@open-pencil/core'
+
+import type { Color, Fill, GradientStop, GradientTransform } from '@open-pencil/core'
+
+type GradientSubtype =
+ | 'GRADIENT_LINEAR'
+ | 'GRADIENT_RADIAL'
+ | 'GRADIENT_ANGULAR'
+ | 'GRADIENT_DIAMOND'
+
+const SUBTYPES: { value: GradientSubtype; label: string }[] = [
+ { value: 'GRADIENT_LINEAR', label: 'Linear' },
+ { value: 'GRADIENT_RADIAL', label: 'Radial' },
+ { value: 'GRADIENT_ANGULAR', label: 'Angular' },
+ { value: 'GRADIENT_DIAMOND', label: 'Diamond' }
+]
+
+const DEFAULT_TRANSFORMS: Record<GradientSubtype, GradientTransform> = {
+ GRADIENT_LINEAR: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 0, m12: 0.5 },
+ GRADIENT_RADIAL: { m00: 0.5, m01: 0, m02: 0.5, m10: 0, m11: 0.5, m12: 0.5 },
+ GRADIENT_ANGULAR: { m00: 0.5, m01: 0, m02: 0.5, m10: 0, m11: 0.5, m12: 0.5 },
+ 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
+) {
+ const activeStopIndex = ref(0)
+ const stops = computed(() => fill.value.gradientStops ?? [])
+ const subtype = computed(() => fill.value.type as GradientSubtype)
+
+ const activeColor = computed(() => {
+ const s = stops.value
+ if (!s.length) return fill.value.color
+ return s[Math.min(activeStopIndex.value, s.length - 1)].color
+ })
+
+ const barBackground = computed(() =>
+ stops.value.length
+ ? `linear-gradient(to right, ${stops.value.map((s) => `${colorToCSS(s.color)} ${s.position * 100}%`).join(', ')})`
+ : ''
+ )
+
+ function emitStops(newStops: GradientStop[]) {
+ onUpdate({ ...fill.value, gradientStops: newStops })
+ }
+
+ function setSubtype(type: GradientSubtype) {
+ if (type === fill.value.type) return
+ onUpdate({ ...fill.value, type, gradientTransform: DEFAULT_TRANSFORMS[type] })
+ }
+
+ function selectStop(index: number) {
+ activeStopIndex.value = index
+ }
+
+ function addStop() {
+ const s = [...stops.value]
+ const pos = s.length >= 2 ? (s[s.length - 2].position + s[s.length - 1].position) / 2 : 0.5
+ s.push({ color: { ...activeColor.value }, position: pos })
+ s.sort((a, b) => a.position - b.position)
+ activeStopIndex.value = s.findIndex((stop) => stop.position === pos)
+ emitStops(s)
+ }
+
+ function removeStop(index: number) {
+ if (stops.value.length <= 2) return
+ emitStops(stops.value.filter((_, i) => i !== index))
+ activeStopIndex.value = Math.min(activeStopIndex.value, stops.value.length - 2)
+ }
+
+ function updateStopPosition(index: number, position: number) {
+ const s = [...stops.value]
+ s[index] = { ...s[index], position: Math.max(0, Math.min(1, position / 100)) }
+ emitStops(s)
+ }
+
+ function updateStopColor(index: number, hex: string) {
+ const color = parseColor(hex.startsWith('#') ? hex : `#${hex}`)
+ if (!color) return
+ const s = [...stops.value]
+ s[index] = { ...s[index], color: { ...color, a: s[index].color.a } }
+ emitStops(s)
+ }
+
+ 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)) } }
+ emitStops(s)
+ }
+
+ function updateActiveColor(color: Color) {
+ const s = [...stops.value]
+ const idx = Math.min(activeStopIndex.value, s.length - 1)
+ s[idx] = { ...s[idx], color }
+ emitStops(s)
+ }
+
+ function dragStop(index: number, position: number) {
+ const s = [...stops.value]
+ s[index] = { ...s[index], position }
+ emitStops(s)
+ }
+
+ return {
+ activeStopIndex,
+ stops,
+ subtype,
+ subtypes: SUBTYPES,
+ activeColor,
+ barBackground,
+ setSubtype,
+ selectStop,
+ addStop,
+ removeStop,
+ updateStopPosition,
+ updateStopColor,
+ updateStopOpacity,
+ updateActiveColor,
+ dragStop
+ }
+}
diff --git a/packages/vue/src/shared/useLayout.ts b/packages/vue/src/shared/useLayout.ts
new file mode 100644
index 000000000..5e4546221
--- /dev/null
+++ b/packages/vue/src/shared/useLayout.ts
@@ -0,0 +1,193 @@
+import { computed, ref } from 'vue'
+
+import { useEditor } from './editorContext'
+import { useSceneComputed } from './useSceneComputed'
+
+import type {
+ SceneNode,
+ LayoutSizing,
+ LayoutAlign,
+ LayoutCounterAlign,
+ GridTrack,
+ GridTrackSizing
+} from '@open-pencil/core'
+
+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' }
+]
+
+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' }
+]
+
+const TRACK_SIZING_OPTIONS: { value: GridTrackSizing; label: string }[] = [
+ { value: 'FR', label: 'Fill (fr)' },
+ { value: 'FIXED', label: 'Fixed (px)' },
+ { value: 'AUTO', label: 'Auto' }
+]
+
+export function useLayout() {
+ const editor = useEditor()
+
+ const node = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
+
+ const isInAutoLayout = computed(() => {
+ const n = node.value
+ if (!n?.parentId) return false
+ const parent = editor.getNode(n.parentId)
+ return parent ? parent.layoutMode !== 'NONE' : false
+ })
+
+ const isGrid = computed(() => node.value?.layoutMode === 'GRID')
+ const isFlex = computed(
+ () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'
+ )
+
+ const widthSizing = computed<LayoutSizing>(() => {
+ const n = node.value
+ if (!n) return 'FIXED'
+ if (isFlex.value) return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
+ if (isInAutoLayout.value && n.layoutGrow > 0) return 'FILL'
+ return 'FIXED'
+ })
+
+ const heightSizing = computed<LayoutSizing>(() => {
+ const n = node.value
+ if (!n) return 'FIXED'
+ if (isFlex.value) return n.layoutMode === 'VERTICAL' ? n.primaryAxisSizing : n.counterAxisSizing
+ if (isInAutoLayout.value && n.layoutAlignSelf === 'STRETCH') return 'FILL'
+ return 'FIXED'
+ })
+
+ const widthSizingOptions = computed(() => {
+ const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
+ if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
+ if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
+ return options
+ })
+
+ const heightSizingOptions = computed(() => {
+ const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
+ if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
+ if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
+ return options
+ })
+
+ const alignGrid = computed(() =>
+ node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL
+ )
+
+ const showIndividualPadding = ref(false)
+
+ const hasUniformPadding = computed(() => {
+ const n = node.value
+ if (!n) return true
+ return n.paddingTop === n.paddingRight && n.paddingRight === n.paddingBottom && n.paddingBottom === n.paddingLeft
+ })
+
+ function updateProp(key: string, value: number | string) {
+ if (node.value) editor.updateNode(node.value.id, { [key]: value })
+ }
+
+ 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}`)
+ }
+
+ function setWidthSizing(sizing: LayoutSizing) {
+ if (!node.value) return
+ if (isFlex.value) {
+ const key = node.value.layoutMode === 'HORIZONTAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
+ updateProp(key, sizing)
+ } else if (isInAutoLayout.value) {
+ updateProp('layoutGrow', sizing === 'FILL' ? 1 : 0)
+ }
+ }
+
+ function setHeightSizing(sizing: LayoutSizing) {
+ if (!node.value) return
+ if (isFlex.value) {
+ const key = node.value.layoutMode === 'VERTICAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
+ updateProp(key, sizing)
+ } else if (isInAutoLayout.value) {
+ updateProp('layoutAlignSelf', sizing === 'FILL' ? 'STRETCH' : 'AUTO')
+ }
+ }
+
+ function setUniformPadding(v: number) {
+ if (!node.value) return
+ 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')
+ }
+
+ function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { primaryAxisAlign: primary, counterAxisAlign: counter }, 'Change alignment')
+ }
+
+ function updateGridTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number, updates: Partial<GridTrack>) {
+ if (!node.value) return
+ const tracks = [...node.value[prop]]
+ tracks[index] = { ...tracks[index], ...updates }
+ editor.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')
+ }
+
+ 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')
+ }
+
+ 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')
+ }
+
+ function trackLabel(track: GridTrack): string {
+ if (track.sizing === 'FR') return `${track.value}fr`
+ if (track.sizing === 'FIXED') return `${track.value}px`
+ return 'Auto'
+ }
+
+ function toggleIndividualPadding() {
+ showIndividualPadding.value = !showIndividualPadding.value
+ }
+
+ return {
+ editor,
+ node,
+ isInAutoLayout,
+ isGrid,
+ isFlex,
+ widthSizing,
+ heightSizing,
+ widthSizingOptions,
+ heightSizingOptions,
+ alignGrid,
+ showIndividualPadding,
+ hasUniformPadding,
+ trackSizingOptions: TRACK_SIZING_OPTIONS,
+ updateProp,
+ commitProp,
+ setWidthSizing,
+ setHeightSizing,
+ setUniformPadding,
+ commitUniformPadding,
+ setAlignment,
+ updateGridTrack,
+ addTrack,
+ removeTrack,
+ trackLabel,
+ toggleIndividualPadding
+ }
+}
diff --git a/packages/vue/src/shared/usePageList.ts b/packages/vue/src/shared/usePageList.ts
new file mode 100644
index 000000000..ce858c91d
--- /dev/null
+++ b/packages/vue/src/shared/usePageList.ts
@@ -0,0 +1,21 @@
+import { computed } from 'vue'
+
+import { useEditor } from './editorContext'
+import { useSceneComputed } from './useSceneComputed'
+
+export function usePageList() {
+ const editor = useEditor()
+
+ const pages = useSceneComputed(() => editor.graph.getPages())
+ const currentPageId = computed(() => editor.state.currentPageId)
+
+ return {
+ editor,
+ pages,
+ currentPageId,
+ switchPage: editor.switchPage,
+ addPage: editor.addPage,
+ deletePage: editor.deletePage,
+ renamePage: editor.renamePage
+ }
+}
diff --git a/packages/vue/src/shared/usePosition.ts b/packages/vue/src/shared/usePosition.ts
new file mode 100644
index 000000000..9244e8af2
--- /dev/null
+++ b/packages/vue/src/shared/usePosition.ts
@@ -0,0 +1,64 @@
+import { computed } from 'vue'
+
+import { useEditor } from './editorContext'
+import { usePropScrub } from './usePropScrub'
+import { useSceneComputed } from './useSceneComputed'
+
+import type { SceneNode } from '@open-pencil/core'
+
+export function usePosition() {
+ const editor = useEditor()
+
+ const nodes = useSceneComputed(() => editor.getSelectedNodes())
+ const node = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
+ const active = computed(() => nodes.value.length > 0)
+ const isMulti = computed(() => nodes.value.length > 1)
+ const ids = computed(() => nodes.value.map((n) => n.id))
+
+ const x = computed(() => Math.round(node.value?.x ?? 0))
+ const y = computed(() => Math.round(node.value?.y ?? 0))
+ const width = computed(() => node.value?.width ?? 0)
+ const height = computed(() => node.value?.height ?? 0)
+ const rotation = computed(() => Math.round(node.value?.rotation ?? 0))
+
+ const { updateProp: _updateProp, commitProp: _commitProp } = usePropScrub(editor)
+
+ function updateProp(key: string, value: number) {
+ _updateProp(nodes.value, key, value)
+ }
+
+ function commitProp(key: string, value: number, previous: number) {
+ _commitProp(nodes.value, key, value, previous)
+ }
+
+ function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {
+ editor.alignNodes(ids.value, axis, pos)
+ }
+
+ function flip(axis: 'horizontal' | 'vertical') {
+ editor.flipNodes(ids.value, axis)
+ }
+
+ function rotate(degrees: number) {
+ editor.rotateNodes(ids.value, degrees)
+ }
+
+ return {
+ editor,
+ nodes,
+ node,
+ active,
+ isMulti,
+ ids,
+ x,
+ y,
+ width,
+ height,
+ rotation,
+ updateProp,
+ commitProp,
+ align,
+ flip,
+ rotate
+ }
+}
diff --git a/packages/vue/src/shared/useTypography.ts b/packages/vue/src/shared/useTypography.ts
new file mode 100644
index 000000000..ddfe8f11f
--- /dev/null
+++ b/packages/vue/src/shared/useTypography.ts
@@ -0,0 +1,133 @@
+import { computed } from 'vue'
+import { FONT_WEIGHT_NAMES, weightToStyle } from '@open-pencil/core'
+
+import type { SceneNode, TextDecoration } from '@open-pencil/core'
+
+import { useEditor } from './editorContext'
+import { useNodeFontStatus } from './useFontStatus'
+import { useSceneComputed } from './useSceneComputed'
+
+type TextAlign = 'LEFT' | 'CENTER' | 'RIGHT'
+
+const WEIGHTS = Object.entries(FONT_WEIGHT_NAMES).map(([value, label]) => ({
+ value: Number(value),
+ label
+}))
+
+export interface UseTypographyOptions {
+ loadFont?: (family: string, style: string) => Promise<unknown>
+}
+
+export function useTypography(options: UseTypographyOptions = {}) {
+ const editor = useEditor()
+
+ const node = useSceneComputed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
+
+ const { missingFonts, hasMissingFonts } = useNodeFontStatus(() => node.value)
+
+ const fontFamily = computed(() => node.value?.fontFamily ?? '')
+ 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 activeFormatting = computed(() => {
+ const n = node.value
+ if (!n) return []
+ const result: string[] = []
+ if (n.fontWeight >= 700) result.push('bold')
+ if (n.italic) result.push('italic')
+ if (n.textDecoration === 'UNDERLINE') result.push('underline')
+ if (n.textDecoration === 'STRIKETHROUGH') result.push('strikethrough')
+ return result
+ })
+
+ async function doLoadFont(family: string, style: string) {
+ if (options.loadFont) await options.loadFont(family, style)
+ }
+
+ async function setFamily(family: string) {
+ if (!node.value) return
+ await doLoadFont(family, currentWeightLabel.value)
+ editor.updateNodeWithUndo(node.value.id, { fontFamily: family }, 'Change font')
+ }
+
+ async function setWeight(weight: number) {
+ if (!node.value) return
+ const style = weightToStyle(weight)
+ await doLoadFont(node.value.fontFamily, style)
+ editor.updateNodeWithUndo(node.value.id, { fontWeight: weight }, 'Change font weight')
+ }
+
+ function setAlign(align: TextAlign) {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { textAlignHorizontal: align }, 'Change text alignment')
+ }
+
+ function toggleBold() {
+ if (!node.value) return
+ setWeight(node.value.fontWeight >= 700 ? 400 : 700)
+ }
+
+ function toggleItalic() {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { italic: !node.value.italic }, 'Toggle italic')
+ }
+
+ function toggleDecoration(deco: 'UNDERLINE' | 'STRIKETHROUGH') {
+ if (!node.value) return
+ const current = node.value.textDecoration
+ editor.updateNodeWithUndo(
+ node.value.id,
+ { textDecoration: (current === deco ? 'NONE' : deco) as TextDecoration },
+ `Toggle ${deco.toLowerCase()}`
+ )
+ }
+
+ function onFormattingChange(values: string[]) {
+ if (!node.value) return
+ const prev = activeFormatting.value
+ const added = values.filter((v) => !prev.includes(v))
+ const removed = prev.filter((v) => !values.includes(v))
+ for (const item of [...added, ...removed]) {
+ if (item === 'bold') toggleBold()
+ else if (item === 'italic') toggleItalic()
+ else if (item === 'underline') toggleDecoration('UNDERLINE')
+ else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')
+ }
+ }
+
+ function updateProp(key: string, value: number | string) {
+ if (node.value) editor.updateNode(node.value.id, { [key]: value })
+ }
+
+ 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}`)
+ }
+ }
+
+ return {
+ editor,
+ node,
+ fontFamily,
+ fontWeight,
+ fontSize,
+ weights: WEIGHTS,
+ currentWeightLabel,
+ activeFormatting,
+ missingFonts,
+ hasMissingFonts,
+ setFamily,
+ setWeight,
+ setAlign,
+ toggleBold,
+ toggleItalic,
+ toggleDecoration,
+ onFormattingChange,
+ updateProp,
+ commitProp
+ }
+}
diff --git a/packages/vue/src/shared/useVariables.ts b/packages/vue/src/shared/useVariables.ts
new file mode 100644
index 000000000..057363703
--- /dev/null
+++ b/packages/vue/src/shared/useVariables.ts
@@ -0,0 +1,137 @@
+import { ref, computed, watch } from 'vue'
+import { colorToHexRaw, parseColor, randomHex } from '@open-pencil/core'
+
+import { useEditor } from './editorContext'
+import { useSceneComputed } from './useSceneComputed'
+
+import type { Color, Variable, VariableCollection, VariableValue } from '@open-pencil/core'
+
+export function useVariables() {
+ const editor = useEditor()
+ const searchTerm = ref('')
+
+ function setSearchTerm(term: string) {
+ searchTerm.value = term
+ }
+
+ const collections = useSceneComputed(() => editor.getCollections())
+
+ const activeCollectionId = ref(collections.value[0]?.id ?? '')
+ watch(collections, (cols) => {
+ if (!activeCollectionId.value && cols[0]) activeCollectionId.value = cols[0].id
+ })
+
+ const activeCollection = computed(() => editor.getCollection(activeCollectionId.value) ?? null)
+ const activeModes = computed(() => activeCollection.value?.modes ?? [])
+
+ const variables = useSceneComputed(() => {
+ if (!activeCollectionId.value) return [] as Variable[]
+ const all = editor.getVariablesForCollection(activeCollectionId.value)
+ if (!searchTerm.value) return all
+ const q = searchTerm.value.toLowerCase()
+ return all.filter((v) => v.name.toLowerCase().includes(q))
+ })
+
+ function setActiveCollection(id: string) {
+ activeCollectionId.value = id
+ }
+
+ function addCollection() {
+ const id = `col:${randomHex(8)}`
+ const collection: VariableCollection = {
+ id,
+ name: 'New collection',
+ modes: [{ modeId: 'default', name: 'Mode 1' }],
+ defaultModeId: 'default',
+ variableIds: []
+ }
+ editor.addCollection(collection)
+ activeCollectionId.value = id
+ }
+
+ function renameCollection(id: string, newName: string) {
+ editor.renameCollection(id, newName)
+ }
+
+ function addVariable() {
+ const col = activeCollection.value
+ if (!col) return
+
+ const id = `var:${randomHex(8)}`
+ const valuesByMode: Record<string, VariableValue> = {}
+ for (const mode of col.modes) {
+ valuesByMode[mode.modeId] = { r: 0, g: 0, b: 0, a: 1 }
+ }
+
+ editor.addVariable({
+ id,
+ name: 'New variable',
+ type: 'COLOR',
+ collectionId: col.id,
+ valuesByMode,
+ description: '',
+ hiddenFromPublishing: false
+ })
+ }
+
+ function removeVariable(id: string) {
+ editor.removeVariable(id)
+ }
+
+ function renameVariable(id: string, newName: string) {
+ editor.renameVariable(id, newName)
+ }
+
+ function updateVariableValue(id: string, modeId: string, value: VariableValue) {
+ editor.updateVariableValue(id, modeId, value)
+ }
+
+ function formatModeValue(variable: Variable, modeId: string): string {
+ const value = variable.valuesByMode[modeId]
+ if (value === undefined) return '—'
+ if (typeof value === 'object' && 'r' in value) return colorToHexRaw(value as Color)
+ if (typeof value === 'object' && 'aliasId' in value) {
+ const aliased = editor.getVariable(value.aliasId)
+ return aliased ? `→ ${aliased.name}` : '→ ?'
+ }
+ return String(value)
+ }
+
+ function parseVariableValue(variable: Variable, raw: string): VariableValue | undefined {
+ if (variable.type === 'COLOR') {
+ return parseColor(raw.startsWith('#') ? raw : `#${raw}`) ?? undefined
+ }
+ if (variable.type === 'FLOAT') {
+ const num = parseFloat(raw)
+ return isNaN(num) ? undefined : num
+ }
+ if (variable.type === 'BOOLEAN') return raw === 'true'
+ return raw
+ }
+
+ function shortName(variable: Variable): string {
+ const parts = variable.name.split('/')
+ return parts[parts.length - 1] ?? variable.name
+ }
+
+ return {
+ editor,
+ collections,
+ activeCollectionId,
+ activeCollection,
+ activeModes,
+ variables,
+ searchTerm,
+ setSearchTerm,
+ setActiveCollection,
+ addCollection,
+ renameCollection,
+ addVariable,
+ removeVariable,
+ renameVariable,
+ updateVariableValue,
+ formatModeValue,
+ parseVariableValue,
+ shortName
+ }
+}
diff --git a/src/components/CanvasMenu.vue b/src/components/CanvasMenu.vue
index 89c2677ea..e7086c62b 100644
--- a/src/components/CanvasMenu.vue
+++ b/src/components/CanvasMenu.vue
@@ -1,4 +1,5 @@
<script setup lang="ts">
+import { computed } from 'vue'
import {
ContextMenuContent,
ContextMenuItem,
@@ -9,7 +10,7 @@ import {
ContextMenuPortal
} from 'reka-ui'
import { useClipboard } from '@vueuse/core'
-import { EditorMenuRoot } from '@open-pencil/vue'
+import { useSelectionState } from '@open-pencil/vue'
import { toast } from '@/utils/toast'
import { useEditorStore } from '@/stores/editor'
@@ -18,6 +19,41 @@ import { menuContent, menuItem, menuSeparator } from '@/components/ui/menu'
const store = useEditorStore()
const { copy } = useClipboard()
+const {
+ editor,
+ selectedIds,
+ hasSelection,
+ selectedCount,
+ selectedNode,
+ isInstance,
+ isComponent,
+ isGroup,
+ canCreateComponentSet
+} = useSelectionState()
+
+const isVisible = computed(() => selectedNode.value?.visible ?? true)
+const isLocked = computed(() => selectedNode.value?.locked ?? false)
+
+const otherPages = computed(() =>
+ editor.graph.getPages().filter((p) => p.id !== editor.state.currentPageId)
+)
+
+function ids() {
+ return [...selectedIds.value]
+}
+
+function copyAsText() {
+ return editor.copySelectionAsText(ids())
+}
+
+function copyAsSVG() {
+ return editor.copySelectionAsSVG(ids())
+}
+
+function copyAsJSX() {
+ return editor.copySelectionAsJSX(ids())
+}
+
function execCommand(cmd: string) {
window.document.execCommand(cmd)
}
@@ -47,162 +83,135 @@ const cls = {
</script>
<template>
- <EditorMenuRoot
- v-slot="{
- editor,
- hasSelection,
- selectedCount,
- selectedNode,
- isInstance,
- isComponent,
- isGroup,
- isVisible,
- isLocked,
- canCreateComponentSet,
- otherPages,
- copyAsText,
- copyAsSVG,
- copyAsJSX
- }"
- >
- <ContextMenuContent :class="cls.menu" :side-offset="2" align="start">
- <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="execCommand('copy')">
- <span>Copy</span><span class="text-[11px] text-muted">⌘C</span>
- </ContextMenuItem>
- <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="execCommand('cut')">
- <span>Cut</span><span class="text-[11px] text-muted">⌘X</span>
- </ContextMenuItem>
- <ContextMenuItem :class="cls.item" @select="execCommand('paste')">
- <span>Paste here</span><span class="text-[11px] text-muted">⌘V</span>
- </ContextMenuItem>
- <ContextMenuItem
- :class="cls.item"
- :disabled="!hasSelection"
- @select="editor.duplicateSelected()"
- >
- <span>Duplicate</span><span class="text-[11px] text-muted">⌘D</span>
+ <ContextMenuContent :class="cls.menu" :side-offset="2" align="start">
+ <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="execCommand('copy')">
+ <span>Copy</span><span class="text-[11px] text-muted">⌘C</span>
+ </ContextMenuItem>
+ <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="execCommand('cut')">
+ <span>Cut</span><span class="text-[11px] text-muted">⌘X</span>
+ </ContextMenuItem>
+ <ContextMenuItem :class="cls.item" @select="execCommand('paste')">
+ <span>Paste here</span><span class="text-[11px] text-muted">⌘V</span>
+ </ContextMenuItem>
+ <ContextMenuItem
+ :class="cls.item"
+ :disabled="!hasSelection"
+ @select="editor.duplicateSelected()"
+ >
+ <span>Duplicate</span><span class="text-[11px] text-muted">⌘D</span>
+ </ContextMenuItem>
+ <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="editor.deleteSelected()">
+ <span>Delete</span><span class="text-[11px] text-muted">⌫</span>
+ </ContextMenuItem>
+
+ <ContextMenuSeparator :class="cls.sep" />
+
+ <ContextMenuSub v-if="otherPages.length > 0 && hasSelection">
+ <ContextMenuSubTrigger :class="cls.item">
+ <span>Move to page</span><span class="text-sm text-muted">›</span>
+ </ContextMenuSubTrigger>
+ <ContextMenuPortal>
+ <ContextMenuSubContent :class="cls.menu">
+ <ContextMenuItem
+ v-for="page in otherPages"
+ :key="page.id"
+ :class="cls.item"
+ @select="editor.moveToPage(page.id)"
+ >
+ {{ page.name }}
+ </ContextMenuItem>
+ </ContextMenuSubContent>
+ </ContextMenuPortal>
+ </ContextMenuSub>
+
+ <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="editor.bringToFront()">
+ <span>Bring to front</span><span class="text-[11px] text-muted">]</span>
+ </ContextMenuItem>
+ <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="editor.sendToBack()">
+ <span>Send to back</span><span class="text-[11px] text-muted">[</span>
+ </ContextMenuItem>
+
+ <ContextMenuSeparator :class="cls.sep" />
+
+ <ContextMenuItem
+ :class="cls.item"
+ :disabled="selectedCount < 2"
+ @select="editor.groupSelected()"
+ >
+ <span>Group</span><span class="text-[11px] text-muted">⌘G</span>
+ </ContextMenuItem>
+ <ContextMenuItem v-if="isGroup" :class="cls.item" @select="editor.ungroupSelected()">
+ <span>Ungroup</span><span class="text-[11px] text-muted">⇧⌘G</span>
+ </ContextMenuItem>
+ <ContextMenuItem v-if="hasSelection" :class="cls.item" @select="editor.wrapInAutoLayout()">
+ <span>Add auto layout</span><span class="text-[11px] text-muted">⇧A</span>
+ </ContextMenuItem>
+
+ <ContextMenuSeparator :class="cls.sep" />
+
+ <ContextMenuItem
+ :class="cls.component"
+ :disabled="!hasSelection"
+ @select="editor.createComponentFromSelection()"
+ >
+ <span>Create component</span><span class="text-[11px] text-component/60">⌥⌘K</span>
+ </ContextMenuItem>
+ <ContextMenuItem
+ v-if="canCreateComponentSet"
+ :class="cls.component"
+ @select="editor.createComponentSetFromComponents()"
+ >
+ <span>Create component set</span><span class="text-[11px] text-component/60">⇧⌘K</span>
+ </ContextMenuItem>
+ <ContextMenuItem
+ v-if="isComponent && selectedNode"
+ :class="cls.component"
+ @select="editor.createInstanceFromComponent(selectedNode.id)"
+ >
+ <span>Create instance</span>
+ </ContextMenuItem>
+ <ContextMenuItem v-if="isInstance" :class="cls.component" @select="editor.goToMainComponent()">
+ <span>Go to main component</span>
+ </ContextMenuItem>
+ <ContextMenuItem v-if="isInstance" :class="cls.item" @select="editor.detachInstance()">
+ <span>Detach instance</span><span class="text-[11px] text-muted">⌥⌘B</span>
+ </ContextMenuItem>
+
+ <template v-if="hasSelection">
+ <ContextMenuSeparator :class="cls.sep" />
+
+ <ContextMenuItem :class="cls.item" @select="editor.toggleVisibility()">
+ <span>{{ isVisible ? 'Hide' : 'Show' }}</span
+ ><span class="text-[11px] text-muted">⇧⌘H</span>
</ContextMenuItem>
- <ContextMenuItem
- :class="cls.item"
- :disabled="!hasSelection"
- @select="editor.deleteSelected()"
- >
- <span>Delete</span><span class="text-[11px] text-muted">⌫</span>
+ <ContextMenuItem :class="cls.item" @select="editor.toggleLock()">
+ <span>{{ isLocked ? 'Unlock' : 'Lock' }}</span
+ ><span class="text-[11px] text-muted">⇧⌘L</span>
</ContextMenuItem>
<ContextMenuSeparator :class="cls.sep" />
- <ContextMenuSub v-if="otherPages.length > 0 && hasSelection">
+ <ContextMenuSub>
<ContextMenuSubTrigger :class="cls.item">
- <span>Move to page</span><span class="text-sm text-muted">›</span>
+ <span>Copy/Paste as</span><span class="text-sm text-muted">›</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent :class="cls.menu">
- <ContextMenuItem
- v-for="page in otherPages"
- :key="page.id"
- :class="cls.item"
- @select="editor.moveToPage(page.id)"
+ <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsText(), 'text')"
+ >Copy as text</ContextMenuItem
>
- {{ page.name }}
+ <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsSVG(), 'SVG')"
+ >Copy as SVG</ContextMenuItem
+ >
+ <ContextMenuItem :class="cls.item" @select="copyAsPNG">
+ <span>Copy as PNG</span><span class="text-[11px] text-muted">⇧⌘C</span>
</ContextMenuItem>
+ <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsJSX(), 'JSX')"
+ >Copy as JSX</ContextMenuItem
+ >
</ContextMenuSubContent>
</ContextMenuPortal>
</ContextMenuSub>
-
- <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="editor.bringToFront()">
- <span>Bring to front</span><span class="text-[11px] text-muted">]</span>
- </ContextMenuItem>
- <ContextMenuItem :class="cls.item" :disabled="!hasSelection" @select="editor.sendToBack()">
- <span>Send to back</span><span class="text-[11px] text-muted">[</span>
- </ContextMenuItem>
-
- <ContextMenuSeparator :class="cls.sep" />
-
- <ContextMenuItem
- :class="cls.item"
- :disabled="selectedCount < 2"
- @select="editor.groupSelected()"
- >
- <span>Group</span><span class="text-[11px] text-muted">⌘G</span>
- </ContextMenuItem>
- <ContextMenuItem v-if="isGroup" :class="cls.item" @select="editor.ungroupSelected()">
- <span>Ungroup</span><span class="text-[11px] text-muted">⇧⌘G</span>
- </ContextMenuItem>
- <ContextMenuItem v-if="hasSelection" :class="cls.item" @select="editor.wrapInAutoLayout()">
- <span>Add auto layout</span><span class="text-[11px] text-muted">⇧A</span>
- </ContextMenuItem>
-
- <ContextMenuSeparator :class="cls.sep" />
-
- <ContextMenuItem
- :class="cls.component"
- :disabled="!hasSelection"
- @select="editor.createComponentFromSelection()"
- >
- <span>Create component</span><span class="text-[11px] text-component/60">⌥⌘K</span>
- </ContextMenuItem>
- <ContextMenuItem
- v-if="canCreateComponentSet"
- :class="cls.component"
- @select="editor.createComponentSetFromComponents()"
- >
- <span>Create component set</span><span class="text-[11px] text-component/60">⇧⌘K</span>
- </ContextMenuItem>
- <ContextMenuItem
- v-if="isComponent && selectedNode"
- :class="cls.component"
- @select="editor.createInstanceFromComponent(selectedNode.id)"
- >
- <span>Create instance</span>
- </ContextMenuItem>
- <ContextMenuItem
- v-if="isInstance"
- :class="cls.component"
- @select="editor.goToMainComponent()"
- >
- <span>Go to main component</span>
- </ContextMenuItem>
- <ContextMenuItem v-if="isInstance" :class="cls.item" @select="editor.detachInstance()">
- <span>Detach instance</span><span class="text-[11px] text-muted">⌥⌘B</span>
- </ContextMenuItem>
-
- <template v-if="hasSelection">
- <ContextMenuSeparator :class="cls.sep" />
-
- <ContextMenuItem :class="cls.item" @select="editor.toggleVisibility()">
- <span>{{ isVisible ? 'Hide' : 'Show' }}</span
- ><span class="text-[11px] text-muted">⇧⌘H</span>
- </ContextMenuItem>
- <ContextMenuItem :class="cls.item" @select="editor.toggleLock()">
- <span>{{ isLocked ? 'Unlock' : 'Lock' }}</span
- ><span class="text-[11px] text-muted">⇧⌘L</span>
- </ContextMenuItem>
-
- <ContextMenuSeparator :class="cls.sep" />
-
- <ContextMenuSub>
- <ContextMenuSubTrigger :class="cls.item">
- <span>Copy/Paste as</span><span class="text-sm text-muted">›</span>
- </ContextMenuSubTrigger>
- <ContextMenuPortal>
- <ContextMenuSubContent :class="cls.menu">
- <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsText(), 'text')"
- >Copy as text</ContextMenuItem
- >
- <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsSVG(), 'SVG')"
- >Copy as SVG</ContextMenuItem
- >
- <ContextMenuItem :class="cls.item" @select="copyAsPNG">
- <span>Copy as PNG</span><span class="text-[11px] text-muted">⇧⌘C</span>
- </ContextMenuItem>
- <ContextMenuItem :class="cls.item" @select="clipboardWrite(copyAsJSX(), 'JSX')"
- >Copy as JSX</ContextMenuItem
- >
- </ContextMenuSubContent>
- </ContextMenuPortal>
- </ContextMenuSub>
- </template>
- </ContextMenuContent>
- </EditorMenuRoot>
+ </template>
+ </ContextMenuContent>
</template>
diff --git a/src/components/ColorInput.vue b/src/components/ColorInput.vue
index 30940730e..1bde550d4 100644
--- a/src/components/ColorInput.vue
+++ b/src/components/ColorInput.vue
@@ -1,35 +1,38 @@
<script setup lang="ts">
-import type { Color } from '@open-pencil/core'
-import { ColorInputRoot } from '@open-pencil/vue'
+import { computed } from 'vue'
+import { colorToHexRaw, parseColor } from '@open-pencil/core'
import ColorPicker from './ColorPicker.vue'
-const { editable = false } = defineProps<{
+import type { Color } from '@open-pencil/core'
+
+const { editable = false, color } = defineProps<{
color: Color
editable?: boolean
}>()
const emit = defineEmits<{ update: [color: Color] }>()
+
+const hex = computed(() => colorToHexRaw(color))
+
+function updateFromHex(value: string) {
+ const parsed = parseColor(value.startsWith('#') ? value : `#${value}`)
+ emit('update', { ...parsed, a: color.a })
+}
</script>
<template>
- <ColorInputRoot
- :color="color"
- @update="emit('update', $event)"
- v-slot="{ hex, updateFromHex, update }"
- >
- <div class="flex items-center gap-1.5">
- <ColorPicker :color="color" @update="update" />
- <input
- v-if="editable"
- data-test-id="color-hex-input"
- class="min-w-0 flex-1 border-none bg-transparent font-mono text-xs text-surface outline-none"
- :value="hex"
- maxlength="6"
- @change="updateFromHex(($event.target as HTMLInputElement).value)"
- />
- <span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
- {{ hex }}
- </span>
- </div>
- </ColorInputRoot>
+ <div class="flex items-center gap-1.5">
+ <ColorPicker :color="color" @update="emit('update', $event)" />
+ <input
+ v-if="editable"
+ data-test-id="color-hex-input"
+ class="min-w-0 flex-1 border-none bg-transparent font-mono text-xs text-surface outline-none"
+ :value="hex"
+ maxlength="6"
+ @change="updateFromHex(($event.target as HTMLInputElement).value)"
+ />
+ <span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
+ {{ hex }}
+ </span>
+ </div>
</template>
diff --git a/src/components/ColorPicker.vue b/src/components/ColorPicker.vue
index 1c8095fca..676ebca7e 100644
--- a/src/components/ColorPicker.vue
+++ b/src/components/ColorPicker.vue
@@ -1,35 +1,37 @@
<script setup lang="ts">
-import type { Color } from '@open-pencil/core'
+import { computed } from 'vue'
import { PopoverRoot, PopoverTrigger, PopoverPortal, PopoverContent } from 'reka-ui'
-import { ColorPickerRoot } from '@open-pencil/vue'
+import { colorToCSS } from '@open-pencil/core'
import HsvColorArea from './HsvColorArea.vue'
+import type { Color } from '@open-pencil/core'
+
const { color } = defineProps<{ color: Color }>()
const emit = defineEmits<{ update: [color: Color] }>()
+
+const swatchBg = computed(() => colorToCSS(color))
</script>
<template>
- <ColorPickerRoot :color="color" @update="emit('update', $event)" v-slot="{ swatchBg, update }">
- <PopoverRoot>
- <PopoverTrigger as-child>
- <button
- data-test-id="color-picker-swatch"
- class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
- :style="{ background: swatchBg }"
- />
- </PopoverTrigger>
+ <PopoverRoot>
+ <PopoverTrigger as-child>
+ <button
+ data-test-id="color-picker-swatch"
+ class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
+ :style="{ background: swatchBg }"
+ />
+ </PopoverTrigger>
- <PopoverPortal>
- <PopoverContent
- data-test-id="color-picker-popover"
- class="z-[100] w-56 rounded-lg border border-border bg-panel p-2 shadow-xl"
- :side-offset="4"
- side="left"
- >
- <HsvColorArea :color="color" @update="update" />
- </PopoverContent>
- </PopoverPortal>
- </PopoverRoot>
- </ColorPickerRoot>
+ <PopoverPortal>
+ <PopoverContent
+ data-test-id="color-picker-popover"
+ class="z-[100] w-56 rounded-lg border border-border bg-panel p-2 shadow-xl"
+ :side-offset="4"
+ side="left"
+ >
+ <HsvColorArea :color="color" @update="emit('update', $event)" />
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
</template>
diff --git a/src/components/FontPicker.vue b/src/components/FontPicker.vue
index 93b0b7155..0fd65f847 100644
--- a/src/components/FontPicker.vue
+++ b/src/components/FontPicker.vue
@@ -1,16 +1,17 @@
<script setup lang="ts">
-import { nextTick, ref } from 'vue'
-import type { AcceptableValue, ListboxFilter } from 'reka-ui'
+import { computed, nextTick, onMounted, ref, watch } from 'vue'
import {
+ type AcceptableValue,
+ type ListboxFilter,
ListboxContent,
ListboxItem,
ListboxRoot,
ListboxVirtualizer,
PopoverAnchor,
PopoverContent,
- PopoverRoot
+ PopoverRoot,
+ useFilter
} from 'reka-ui'
-import { FontPickerRoot } from '@open-pencil/vue'
import { selectItem, selectTrigger } from '@/components/ui/select'
import { panelSurface } from '@/components/ui/surface'
@@ -19,100 +20,115 @@ import { listFamilies } from '@/engine/fonts'
const modelValue = defineModel<string>({ required: true })
const emit = defineEmits<{ select: [family: string] }>()
+const families = ref<string[]>([])
+const searchTerm = ref('')
+const open = ref(false)
const filterRef = ref<InstanceType<typeof ListboxFilter> | null>(null)
+
+const { contains } = useFilter({ sensitivity: 'base' })
+const filtered = computed(() => {
+ if (!searchTerm.value) return families.value
+ return families.value.filter((f) => contains(f, searchTerm.value))
+})
+
+onMounted(async () => {
+ families.value = await listFamilies()
+})
+
+watch(open, (isOpen) => {
+ if (isOpen) searchTerm.value = ''
+})
+
+function select(family: string) {
+ modelValue.value = family
+ emit('select', family)
+ open.value = false
+}
</script>
<template>
- <FontPickerRoot
- :model-value="modelValue"
- :list-families="listFamilies"
- @update:model-value="modelValue = $event"
- @select="emit('select', $event)"
- v-slot="{ filtered, searchTerm, open, modelValue: selected, select, setSearchTerm, setOpen }"
- >
- <PopoverRoot :open="open" @update:open="setOpen">
- <PopoverAnchor>
- <button
- data-test-id="font-picker-trigger"
- :class="selectTrigger({ class: 'w-full rounded px-2 py-1 text-xs' })"
- @click="setOpen(!open)"
- >
- <span class="truncate">{{ selected }}</span>
- <icon-lucide-chevron-down class="size-3 shrink-0 text-muted" />
- </button>
- </PopoverAnchor>
- <PopoverContent
- :side-offset="2"
- align="start"
- :class="
- panelSurface({
- radius: 'md',
- padding: 'none',
- class: 'z-50 flex w-[var(--reka-popper-anchor-width)] min-w-56 flex-col overflow-hidden'
- })
+ <PopoverRoot :open="open" @update:open="(v) => (open = v)">
+ <PopoverAnchor>
+ <button
+ data-test-id="font-picker-trigger"
+ :class="selectTrigger({ class: 'w-full rounded px-2 py-1 text-xs' })"
+ @click="open = !open"
+ >
+ <span class="truncate">{{ modelValue }}</span>
+ <icon-lucide-chevron-down class="size-3 shrink-0 text-muted" />
+ </button>
+ </PopoverAnchor>
+ <PopoverContent
+ :side-offset="2"
+ align="start"
+ :class="
+ panelSurface({
+ radius: 'md',
+ padding: 'none',
+ class: 'z-50 flex w-[var(--reka-popper-anchor-width)] min-w-56 flex-col overflow-hidden'
+ })
+ "
+ @open-auto-focus.prevent
+ @vue:mounted="nextTick(() => filterRef?.$el?.focus())"
+ >
+ <ListboxRoot
+ :model-value="modelValue"
+ @update:model-value="
+ (v: AcceptableValue) => {
+ if (typeof v === 'string') select(v)
+ }
"
- @open-auto-focus.prevent
- @vue:mounted="nextTick(() => filterRef?.$el?.focus())"
>
- <ListboxRoot
- :model-value="selected"
- @update:model-value="
- (v: AcceptableValue) => {
- if (typeof v === 'string') select(v)
- }
- "
- >
- <div class="flex items-center gap-1 border-b border-border px-2 py-1">
- <icon-lucide-search class="size-3 shrink-0 text-muted" />
- <input
- ref="filterRef"
- :value="searchTerm"
- data-test-id="font-picker-search"
- class="min-w-0 flex-1 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
- placeholder="Search fonts…"
- autocomplete="off"
- autocorrect="off"
- autocapitalize="off"
- spellcheck="false"
- @input="setSearchTerm(($event.target as HTMLInputElement).value)"
- />
- </div>
- <ListboxContent class="h-72 overflow-y-auto">
- <ListboxVirtualizer
- v-slot="{ option }"
- :options="filtered"
- :text-content="(f: string) => f"
- :estimate-size="36"
+ <div class="flex items-center gap-1 border-b border-border px-2 py-1">
+ <icon-lucide-search class="size-3 shrink-0 text-muted" />
+ <input
+ ref="filterRef"
+ :value="searchTerm"
+ data-test-id="font-picker-search"
+ class="min-w-0 flex-1 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
+ placeholder="Search fonts…"
+ autocomplete="off"
+ autocorrect="off"
+ autocapitalize="off"
+ spellcheck="false"
+ @input="searchTerm = ($event.target as HTMLInputElement).value"
+ />
+ </div>
+ <ListboxContent class="h-72 overflow-y-auto">
+ <ListboxVirtualizer
+ v-slot="{ option }"
+ :options="filtered"
+ :text-content="(f: string) => f"
+ :estimate-size="36"
+ >
+ <ListboxItem
+ :value="option"
+ data-test-id="font-picker-item"
+ :class="selectItem({ class: 'w-full gap-2 px-2 py-2 text-sm' })"
+ :style="{ fontFamily: `'${option}', sans-serif` }"
>
- <ListboxItem
- :value="option"
- data-test-id="font-picker-item"
- :class="selectItem({ class: 'w-full gap-2 px-2 py-2 text-sm' })"
- :style="{ fontFamily: `'${option}', sans-serif` }"
- >
- <icon-lucide-check v-if="option === selected" class="size-3 shrink-0 text-accent" />
- <span v-else class="size-3 shrink-0" />
- <span class="truncate">{{ option }}</span>
- </ListboxItem>
- </ListboxVirtualizer>
- <div
- v-if="filtered.length === 0 && searchTerm"
- class="px-2 py-3 text-center text-xs text-muted"
- >
- No fonts found
- </div>
- <div
- v-else-if="filtered.length === 0"
- class="flex h-full items-center justify-center px-3 text-center text-xs text-muted"
- >
- <div>
- <p>No local fonts available.</p>
- <p class="mt-1">Use the desktop app or Chrome/Edge to access system fonts.</p>
- </div>
+ <icon-lucide-check v-if="option === modelValue" class="size-3 shrink-0 text-accent" />
+ <span v-else class="size-3 shrink-0" />
+ <span class="truncate">{{ option }}</span>
+ </ListboxItem>
+ </ListboxVirtualizer>
+ <div
+ v-if="filtered.length === 0 && searchTerm"
+ class="px-2 py-3 text-center text-xs text-muted"
+ >
+ No fonts found
+ </div>
+ <div
+ v-else-if="filtered.length === 0"
+ class="flex h-full items-center justify-center px-3 text-center text-xs text-muted"
+ >
+ <div>
+ <p>No local fonts available.</p>
+ <p class="mt-1">Use the desktop app or Chrome/Edge to access system fonts.</p>
</div>
- </ListboxContent>
- </ListboxRoot>
- </PopoverContent>
- </PopoverRoot>
- </FontPickerRoot>
+ </div>
+ </ListboxContent>
+ </ListboxRoot>
+ </PopoverContent>
+ </PopoverRoot>
</template>
diff --git a/src/components/ImageFillPicker.vue b/src/components/ImageFillPicker.vue
index 795c522ff..49f5b0a34 100644
--- a/src/components/ImageFillPicker.vue
+++ b/src/components/ImageFillPicker.vue
@@ -1,47 +1,84 @@
<script setup lang="ts">
-import type { Fill } from '@open-pencil/core'
-import { ImageFillControlsRoot, useEditor } from '@open-pencil/vue'
+import { computed, shallowRef, watch } from 'vue'
+import { useFileDialog, useObjectUrl } from '@vueuse/core'
import AppSelect from './AppSelect.vue'
+import { useEditor } from '@open-pencil/vue'
+
+import type { Fill, ImageScaleMode } from '@open-pencil/core'
+
+const IMAGE_SCALE_MODES: { value: ImageScaleMode; label: string }[] = [
+ { value: 'FILL', label: 'Fill' },
+ { value: 'FIT', label: 'Fit' },
+ { value: 'CROP', label: 'Crop' },
+ { value: 'TILE', label: 'Tile' }
+]
const { fill } = defineProps<{ fill: Fill }>()
const emit = defineEmits<{ update: [fill: Fill] }>()
const store = useEditor()
-function resolveImage(hash: string) {
- return store.getImage(hash)
-}
+const imageBlob = shallowRef<Blob | null>(null)
+const imagePreviewUrl = useObjectUrl(imageBlob)
+
+watch(
+ () => fill.imageHash,
+ (hash) => {
+ if (!hash) {
+ imageBlob.value = null
+ return
+ }
+ const data = store.getImage(hash)
+ imageBlob.value = data ? new Blob([data]) : null
+ },
+ { immediate: true }
+)
+
+const { open: pickImage, onChange: onFileChange } = useFileDialog({
+ accept: 'image/png,image/jpeg,image/webp',
+ multiple: false
+})
+
+onFileChange(async (files) => {
+ const file = files?.[0]
+ if (!file) return
+ const bytes = new Uint8Array(await file.arrayBuffer())
+ const hash = store.storeImage(bytes)
+ emit('update', {
+ ...fill,
+ type: 'IMAGE',
+ imageHash: hash,
+ imageScaleMode: fill.imageScaleMode ?? 'FILL'
+ })
+})
+
+const scaleMode = computed({
+ get: () => fill.imageScaleMode ?? ('FILL' as ImageScaleMode),
+ set: (mode: ImageScaleMode) => emit('update', { ...fill, imageScaleMode: mode })
+})
</script>
<template>
- <ImageFillControlsRoot
- :fill="fill"
- :resolve-image="resolveImage"
- :store-image="store.storeImage"
- @update="emit('update', $event)"
- v-slot="{ imagePreviewUrl, scaleModes, scaleMode, pickImage, setScaleMode }"
- >
- <div class="space-y-2">
- <div
- v-if="imagePreviewUrl"
- class="flex h-24 items-center justify-center overflow-hidden rounded border border-border"
- >
- <img :src="imagePreviewUrl" class="max-h-full max-w-full object-contain" />
- </div>
- <button
- class="flex h-7 w-full cursor-pointer items-center justify-center gap-1 rounded border border-border bg-input text-xs text-surface hover:bg-hover"
- data-test-id="fill-picker-choose-image"
- @click="pickImage"
- >
- <icon-lucide-image class="size-3" />
- {{ fill.imageHash ? 'Replace' : 'Choose image' }}
- </button>
- <AppSelect
- :model-value="scaleMode"
- :options="scaleModes"
- @update:model-value="setScaleMode"
- />
+ <div class="space-y-2">
+ <div
+ v-if="imagePreviewUrl"
+ class="flex h-24 items-center justify-center overflow-hidden rounded border border-border"
+ >
+ <img :src="imagePreviewUrl" class="max-h-full max-w-full object-contain" />
</div>
- </ImageFillControlsRoot>
+ <button
+ class="flex h-7 w-full cursor-pointer items-center justify-center gap-1 rounded border border-border bg-input text-xs text-surface hover:bg-hover"
+ data-test-id="fill-picker-choose-image"
+ @click="pickImage()"
+ >
+ <icon-lucide-image class="size-3" />
+ {{ fill.imageHash ? 'Replace' : 'Choose image' }}
+ </button>
+ <AppSelect
+ :model-value="scaleMode"
+ :options="IMAGE_SCALE_MODES"
+ @update:model-value="(m) => (scaleMode = m as ImageScaleMode)"
+ />
+ </div>
</template>
diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vue
index 115f4001a..52e0b566a 100644
--- a/src/components/properties/AppearanceSection.vue
+++ b/src/components/properties/AppearanceSection.vue
@@ -2,162 +2,76 @@
import ScrubInput from '@/components/ScrubInput.vue'
import Tip from '@/components/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { AppearanceControlsRoot } from '@open-pencil/vue'
+import { useAppearance } from '@open-pencil/vue'
+
+const {
+ node,
+ isMulti,
+ active,
+ hasCornerRadius,
+ independentCorners,
+ cornerRadiusValue,
+ opacityPercent,
+ visibilityState,
+ updateProp,
+ commitProp,
+ toggleVisibility,
+ toggleIndependentCorners,
+ updateCornerProp,
+ commitCornerProp
+} = useAppearance()
</script>
<template>
- <AppearanceControlsRoot
- v-slot="{
- node,
- isMulti,
- hasCornerRadius,
- independentCorners,
- cornerRadiusValue,
- opacityPercent,
- visibilityState,
- updateProp,
- commitProp,
- toggleVisibility,
- toggleIndependentCorners,
- updateCornerProp,
- commitCornerProp
- }"
- >
- <div data-test-id="appearance-section" :class="sectionWrapper()">
- <div class="mb-1.5 flex items-center justify-between">
- <label class="text-[11px] text-muted">Appearance</label>
- <Tip label="Toggle visibility">
- <button
- data-test-id="appearance-visibility"
- class="flex cursor-pointer items-center justify-center rounded border-none bg-transparent p-0.5 text-muted hover:bg-hover hover:text-surface"
- :class="{ 'text-accent': visibilityState === 'hidden' }"
- @click="toggleVisibility"
- >
- <icon-lucide-eye v-if="visibilityState === 'visible'" class="size-3.5" />
- <icon-lucide-eye-off v-else-if="visibilityState === 'hidden'" class="size-3.5" />
- <icon-lucide-eye class="size-3.5 opacity-50" v-else />
- </button>
- </Tip>
- </div>
- <div class="flex gap-1.5">
- <ScrubInput
- suffix="%"
- :model-value="opacityPercent"
- :min="0"
- :max="100"
- @update:model-value="updateProp('opacity', $event / 100)"
- @commit="(v: number, p: number) => commitProp('opacity', v / 100, p / 100)"
+ <div v-if="active" data-test-id="appearance-section" :class="sectionWrapper()">
+ <div class="mb-1.5 flex items-center justify-between">
+ <label class="text-[11px] text-muted">Appearance</label>
+ <Tip label="Toggle visibility">
+ <button
+ data-test-id="appearance-visibility"
+ class="flex cursor-pointer items-center justify-center rounded border-none bg-transparent p-0.5 text-muted hover:bg-hover hover:text-surface"
+ :class="{ 'text-accent': visibilityState === 'hidden' }"
+ @click="toggleVisibility"
>
- <template #icon>
- <icon-lucide-blend class="size-3" />
- </template>
- </ScrubInput>
- <template v-if="hasCornerRadius">
- <ScrubInput
- v-if="independentCorners !== true"
- data-test-id="corner-radius-input"
- :model-value="cornerRadiusValue"
- :min="0"
- @update:model-value="updateProp('cornerRadius', $event)"
- @commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"
- >
- <template #icon>
- <icon-lucide-radius class="size-3" />
- </template>
- </ScrubInput>
- <Tip label="Independent corner radii">
- <button
- data-test-id="independent-corners-toggle"
- 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': independentCorners === true }"
- @click="toggleIndependentCorners"
- >
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M1 4V2.5A1.5 1.5 0 0 1 2.5 1H4" />
- <path d="M8 1h1.5A2.5 2.5 0 0 1 11 3.5V5" />
- <path d="M11 8v1a2 2 0 0 1-2 2H8" />
- <path d="M4 11H3a2 2 0 0 1-2-2V8" />
- </svg>
- </button>
- </Tip>
- </template>
- </div>
-
- <div
- v-if="hasCornerRadius && independentCorners === true && !isMulti"
- class="mt-1.5 grid grid-cols-2 gap-1.5"
+ <icon-lucide-eye v-if="visibilityState === 'visible'" class="size-3.5" />
+ <icon-lucide-eye-off v-else-if="visibilityState === 'hidden'" class="size-3.5" />
+ <icon-lucide-eye class="size-3.5 opacity-50" v-else />
+ </button>
+ </Tip>
+ </div>
+ <div class="flex gap-1.5">
+ <ScrubInput
+ suffix="%"
+ :model-value="opacityPercent"
+ :min="0"
+ :max="100"
+ @update:model-value="updateProp('opacity', $event / 100)"
+ @commit="(v: number, p: number) => commitProp('opacity', v / 100, p / 100)"
>
+ <template #icon>
+ <icon-lucide-blend class="size-3" />
+ </template>
+ </ScrubInput>
+ <template v-if="hasCornerRadius">
<ScrubInput
- data-test-id="corner-tl-input"
- :model-value="node!.topLeftRadius"
- :min="0"
- @update:model-value="updateCornerProp('topLeftRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M1 11V4a3 3 0 0 1 3-3h7" />
- </svg>
- </template>
- </ScrubInput>
- <ScrubInput
- data-test-id="corner-tr-input"
- :model-value="node!.topRightRadius"
- :min="0"
- @update:model-value="updateCornerProp('topRightRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('topRightRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M11 11V4a3 3 0 0 0-3-3H1" />
- </svg>
- </template>
- </ScrubInput>
- <ScrubInput
- data-test-id="corner-bl-input"
- :model-value="node!.bottomLeftRadius"
+ v-if="independentCorners !== true"
+ data-test-id="corner-radius-input"
+ :model-value="cornerRadiusValue"
:min="0"
- @update:model-value="updateCornerProp('bottomLeftRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('bottomLeftRadius', v, p)"
+ @update:model-value="updateProp('cornerRadius', $event)"
+ @commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"
>
<template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M1 1v7a3 3 0 0 0 3 3h7" />
- </svg>
+ <icon-lucide-radius class="size-3" />
</template>
</ScrubInput>
- <ScrubInput
- data-test-id="corner-br-input"
- :model-value="node!.bottomRightRadius"
- :min="0"
- @update:model-value="updateCornerProp('bottomRightRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('bottomRightRadius', v, p)"
- >
- <template #icon>
+ <Tip label="Independent corner radii">
+ <button
+ data-test-id="independent-corners-toggle"
+ 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': independentCorners === true }"
+ @click="toggleIndependentCorners"
+ >
<svg
class="size-3"
viewBox="0 0 12 12"
@@ -165,11 +79,96 @@ import { AppearanceControlsRoot } from '@open-pencil/vue'
stroke="currentColor"
stroke-width="1.5"
>
- <path d="M11 1v7a3 3 0 0 1-3 3H1" />
+ <path d="M1 4V2.5A1.5 1.5 0 0 1 2.5 1H4" />
+ <path d="M8 1h1.5A2.5 2.5 0 0 1 11 3.5V5" />
+ <path d="M11 8v1a2 2 0 0 1-2 2H8" />
+ <path d="M4 11H3a2 2 0 0 1-2-2V8" />
</svg>
- </template>
- </ScrubInput>
- </div>
+ </button>
+ </Tip>
+ </template>
+ </div>
+
+ <div
+ v-if="hasCornerRadius && independentCorners === true && !isMulti"
+ class="mt-1.5 grid grid-cols-2 gap-1.5"
+ >
+ <ScrubInput
+ data-test-id="corner-tl-input"
+ :model-value="node!.topLeftRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('topLeftRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M1 11V4a3 3 0 0 1 3-3h7" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ data-test-id="corner-tr-input"
+ :model-value="node!.topRightRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('topRightRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('topRightRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M11 11V4a3 3 0 0 0-3-3H1" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ data-test-id="corner-bl-input"
+ :model-value="node!.bottomLeftRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('bottomLeftRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('bottomLeftRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M1 1v7a3 3 0 0 0 3 3h7" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ data-test-id="corner-br-input"
+ :model-value="node!.bottomRightRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('bottomRightRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('bottomRightRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M11 1v7a3 3 0 0 1-3 3H1" />
+ </svg>
+ </template>
+ </ScrubInput>
</div>
- </AppearanceControlsRoot>
+ </div>
</template>
diff --git a/src/components/properties/ExportSection.vue b/src/components/properties/ExportSection.vue
index 3d589ce0e..9578c2548 100644
--- a/src/components/properties/ExportSection.vue
+++ b/src/components/properties/ExportSection.vue
@@ -5,11 +5,12 @@ import AppSelect from '@/components/AppSelect.vue'
import { iconButton } from '@/components/ui/icon-button'
import { sectionLabel, sectionWrapper } from '@/components/ui/section'
import { useEditorStore } from '@/stores/editor'
-import { ExportControlsRoot } from '@open-pencil/vue'
+import { useExport } from '@open-pencil/vue'
import type { ExportFormat } from '@open-pencil/core'
-const store = useEditorStore()
+const editorStore = useEditorStore()
+const { settings, nodeName, addSetting, removeSetting, updateScale, updateFormat } = useExport()
const SCALE_OPTIONS = [0.5, 0.75, 1, 1.5, 2, 3, 4].map((s) => ({ value: s, label: `${s}x` }))
const FORMAT_OPTIONS: { value: ExportFormat; label: string }[] = [
@@ -25,10 +26,10 @@ const exporting = ref(false)
const PREVIEW_WIDTH = 480
-async function doExport(settings: Array<{ scale: number; format: ExportFormat }>) {
+async function doExport(exportSettings: Array<{ scale: number; format: ExportFormat }>) {
exporting.value = true
try {
- for (const s of settings) await store.exportSelection(s.scale, s.format)
+ for (const s of exportSettings) await editorStore.exportSelection(s.scale, s.format)
} finally {
exporting.value = false
}
@@ -36,7 +37,7 @@ async function doExport(settings: Array<{ scale: number; format: ExportFormat }>
async function updatePreview() {
if (!showPreview.value) return
- const ids = [...store.state.selectedIds]
+ const ids = [...editorStore.state.selectedIds]
if (ids.length === 0) {
if (previewUrl.value) URL.revokeObjectURL(previewUrl.value)
previewUrl.value = null
@@ -44,11 +45,11 @@ async function updatePreview() {
}
let maxW = 0
for (const id of ids) {
- const node = store.getNode(id)
+ const node = editorStore.getNode(id)
if (node) maxW = Math.max(maxW, node.width)
}
const scale = maxW > 0 ? Math.min(PREVIEW_WIDTH / maxW, 2) : 1
- const data = await store.renderExportImage(ids, scale, 'PNG')
+ const data = await editorStore.renderExportImage(ids, scale, 'PNG')
if (data) {
const prev = previewUrl.value
previewUrl.value = URL.createObjectURL(new Blob([data], { type: 'image/png' }))
@@ -57,7 +58,7 @@ async function updatePreview() {
}
const previewKey = computed(
- () => `${store.state.sceneVersion}:${[...store.state.selectedIds].sort().join(',')}`
+ () => `${editorStore.state.sceneVersion}:${[...editorStore.state.selectedIds].sort().join(',')}`
)
watch(() => showPreview.value, updatePreview, { flush: 'post' })
@@ -69,78 +70,69 @@ onScopeDispose(() => {
</script>
<template>
- <ExportControlsRoot
- v-slot="{ settings, nodeName, addSetting, removeSetting, updateScale, updateFormat }"
- >
- <div data-test-id="export-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Export</label>
- <button data-test-id="export-section-add" :class="iconButton()" @click="addSetting">
- +
- </button>
- </div>
-
- <div
- v-for="(setting, i) in settings"
- :key="i"
- data-test-id="export-item"
- :data-test-index="i"
- class="flex items-center gap-1.5 py-0.5"
- >
- <AppSelect
- v-if="setting.format !== 'SVG'"
- :model-value="setting.scale"
- :options="SCALE_OPTIONS"
- @update:model-value="updateScale(i, Number($event))"
- />
- <AppSelect
- :model-value="setting.format"
- :options="FORMAT_OPTIONS"
- @update:model-value="updateFormat(i, $event as ExportFormat)"
- />
- <button :class="iconButton({ class: 'shrink-0' })" @click="removeSetting(i)">−</button>
- </div>
-
- <button
- v-if="settings.length > 0"
- data-test-id="export-button"
- class="mt-1.5 w-full cursor-pointer truncate rounded bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700 disabled:cursor-default disabled:opacity-50"
- :disabled="exporting"
- @click="doExport(settings)"
- >
- Export {{ nodeName }}
- </button>
-
- <button
- v-if="settings.length > 0"
- data-test-id="export-preview-toggle"
- class="mt-1 flex w-full cursor-pointer items-center gap-1 rounded border-none bg-transparent px-0 py-1 text-[11px] text-muted hover:text-surface"
- @click="showPreview = !showPreview"
- >
- <icon-lucide-chevron-down v-if="showPreview" class="size-3" />
- <icon-lucide-chevron-right v-else class="size-3" />
- Preview
- </button>
-
- <div
- v-if="showPreview && previewUrl"
- class="mt-1 overflow-hidden rounded border border-border"
- >
- <img
- :src="previewUrl"
- class="block w-full"
- style="
- image-rendering: auto;
- background: repeating-conic-gradient(#808080 0% 25%, transparent 0% 50%) 50% / 16px 16px;
- "
- />
- </div>
- <div
- v-else-if="showPreview"
- class="mt-1 rounded border border-border px-3 py-2 text-[11px] text-muted"
- >
- Rendering preview…
- </div>
+ <div data-test-id="export-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Export</label>
+ <button data-test-id="export-section-add" :class="iconButton()" @click="addSetting">+</button>
</div>
- </ExportControlsRoot>
+
+ <div
+ v-for="(setting, i) in settings"
+ :key="i"
+ data-test-id="export-item"
+ :data-test-index="i"
+ class="flex items-center gap-1.5 py-0.5"
+ >
+ <AppSelect
+ v-if="setting.format !== 'SVG'"
+ :model-value="setting.scale"
+ :options="SCALE_OPTIONS"
+ @update:model-value="updateScale(i, Number($event))"
+ />
+ <AppSelect
+ :model-value="setting.format"
+ :options="FORMAT_OPTIONS"
+ @update:model-value="updateFormat(i, $event as ExportFormat)"
+ />
+ <button :class="iconButton({ class: 'shrink-0' })" @click="removeSetting(i)">−</button>
+ </div>
+
+ <button
+ v-if="settings.length > 0"
+ data-test-id="export-button"
+ class="mt-1.5 w-full cursor-pointer truncate rounded bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700 disabled:cursor-default disabled:opacity-50"
+ :disabled="exporting"
+ @click="doExport(settings)"
+ >
+ Export {{ nodeName }}
+ </button>
+
+ <button
+ v-if="settings.length > 0"
+ data-test-id="export-preview-toggle"
+ class="mt-1 flex w-full cursor-pointer items-center gap-1 rounded border-none bg-transparent px-0 py-1 text-[11px] text-muted hover:text-surface"
+ @click="showPreview = !showPreview"
+ >
+ <icon-lucide-chevron-down v-if="showPreview" class="size-3" />
+ <icon-lucide-chevron-right v-else class="size-3" />
+ Preview
+ </button>
+
+ <div v-if="showPreview && previewUrl" class="mt-1 overflow-hidden rounded border border-border">
+ <img
+ :src="previewUrl"
+ class="block w-full"
+ style="
+ image-rendering: auto;
+ background: repeating-conic-gradient(#808080 0% 25%, transparent 0% 50%) 50% / 16px 16px;
+ "
+ />
+ </div>
+ <div
+ v-else-if="showPreview"
+ class="mt-1 rounded border border-border px-3 py-2 text-[11px] text-muted"
+ >
+ Rendering preview…
+ </div>
+ </div>
</template>
diff --git a/src/components/properties/LayoutSection.vue b/src/components/properties/LayoutSection.vue
index 99760d388..bbd155f12 100644
--- a/src/components/properties/LayoutSection.vue
+++ b/src/components/properties/LayoutSection.vue
@@ -3,40 +3,39 @@ import AppSelect from '@/components/AppSelect.vue'
import ScrubInput from '@/components/ScrubInput.vue'
import Tip from '@/components/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { LayoutControlsRoot, useEditor } from '@open-pencil/vue'
+import { useLayout } from '@open-pencil/vue'
-const store = useEditor()
+const {
+ editor: store,
+ node,
+ isInAutoLayout,
+ isGrid,
+ isFlex,
+ widthSizing,
+ heightSizing,
+ widthSizingOptions,
+ heightSizingOptions,
+ alignGrid,
+ showIndividualPadding,
+ hasUniformPadding,
+ trackSizingOptions,
+ updateProp,
+ commitProp,
+ setWidthSizing,
+ setHeightSizing,
+ setUniformPadding,
+ commitUniformPadding,
+ setAlignment,
+ updateGridTrack,
+ addTrack,
+ removeTrack,
+ trackLabel,
+ toggleIndividualPadding
+} = useLayout()
</script>
<template>
- <LayoutControlsRoot
- v-slot="{
- node,
- isInAutoLayout,
- isGrid,
- isFlex,
- widthSizing,
- heightSizing,
- widthSizingOptions,
- heightSizingOptions,
- alignGrid,
- showIndividualPadding,
- hasUniformPadding,
- trackSizingOptions,
- updateProp,
- commitProp,
- setWidthSizing,
- setHeightSizing,
- setUniformPadding,
- commitUniformPadding,
- setAlignment,
- updateGridTrack,
- addTrack,
- removeTrack,
- trackLabel,
- toggleIndividualPadding
- }"
- >
+ <template v-if="node">
<div data-test-id="layout-section" :class="sectionWrapper()">
<label class="mb-1.5 block text-[11px] text-muted">Layout</label>
<div class="flex gap-1.5">
@@ -297,5 +296,5 @@ const store = useEditor()
</label>
</div>
</template>
- </LayoutControlsRoot>
+ </template>
</template>
diff --git a/src/components/properties/PageSection.vue b/src/components/properties/PageSection.vue
index 26428ee25..bc7770f6b 100644
--- a/src/components/properties/PageSection.vue
+++ b/src/components/properties/PageSection.vue
@@ -1,14 +1,17 @@
<script setup lang="ts">
+import { computed } from 'vue'
+
import ColorInput from '@/components/ColorInput.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { PageControlsRoot } from '@open-pencil/vue'
+import { useEditor } from '@open-pencil/vue'
+
+const editor = useEditor()
+const pageColor = computed(() => editor.state.pageColor)
</script>
<template>
- <PageControlsRoot v-slot="{ pageColor, setPageColor }">
- <div data-test-id="page-section" :class="sectionWrapper()">
- <label class="mb-1.5 block text-[11px] text-muted">Page</label>
- <ColorInput :color="pageColor" editable @update="setPageColor" />
- </div>
- </PageControlsRoot>
+ <div data-test-id="page-section" :class="sectionWrapper()">
+ <label class="mb-1.5 block text-[11px] text-muted">Page</label>
+ <ColorInput :color="pageColor" editable @update="editor.setPageColor($event)" />
+ </div>
</template>
diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vue
index 086afe6d4..fb336baaf 100644
--- a/src/components/properties/TypographySection.vue
+++ b/src/components/properties/TypographySection.vue
@@ -5,148 +5,150 @@ import ScrubInput from '@/components/ScrubInput.vue'
import Tip from '@/components/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
import { loadFont } from '@/engine/fonts'
-import { TypographyControlsRoot } from '@open-pencil/vue'
+import { useTypography } from '@open-pencil/vue'
import { ToggleGroupItem, ToggleGroupRoot, type AcceptableValue } from 'reka-ui'
+
+const ctx = useTypography({ loadFont })
</script>
<template>
- <TypographyControlsRoot v-slot="ctx" :load-font="loadFont">
- <div data-test-id="typography-section" :class="sectionWrapper()">
- <label class="mb-1.5 block text-[11px] text-muted">Typography</label>
+ <div v-if="ctx.node.value" data-test-id="typography-section" :class="sectionWrapper()">
+ <label class="mb-1.5 block text-[11px] text-muted">Typography</label>
- <div class="mb-1.5 flex items-center gap-1.5">
- <FontPicker
- class="min-w-0 flex-1"
- :model-value="ctx.node.fontFamily"
- @select="ctx.setFamily"
+ <div class="mb-1.5 flex items-center gap-1.5">
+ <FontPicker
+ class="min-w-0 flex-1"
+ :model-value="ctx.node.value.fontFamily"
+ @select="ctx.setFamily"
+ />
+ <Tip
+ v-if="ctx.hasMissingFonts.value"
+ :label="
+ 'Missing font' +
+ (ctx.missingFonts.value.length > 1 ? 's' : '') +
+ ': ' +
+ ctx.missingFonts.value.join(', ')
+ "
+ >
+ <icon-lucide-alert-triangle
+ data-test-id="typography-missing-font"
+ class="size-3.5 shrink-0 text-amber-400"
/>
- <Tip
- v-if="ctx.hasMissingFonts"
- :label="
- 'Missing font' +
- (ctx.missingFonts.length > 1 ? 's' : '') +
- ': ' +
- ctx.missingFonts.join(', ')
- "
- >
- <icon-lucide-alert-triangle
- data-test-id="typography-missing-font"
- class="size-3.5 shrink-0 text-amber-400"
- />
- </Tip>
- </div>
+ </Tip>
+ </div>
- <!-- Weight + Size -->
- <div class="mb-1.5 flex gap-1.5">
- <AppSelect
- :model-value="ctx.node.fontWeight"
- :options="ctx.weights"
- @update:model-value="ctx.setWeight(+$event)"
- />
- <ScrubInput
- class="flex-1"
- :model-value="ctx.node.fontSize"
- :min="1"
- :max="1000"
- @update:model-value="ctx.updateProp('fontSize', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('fontSize', v, p)"
- />
- </div>
+ <!-- Weight + Size -->
+ <div class="mb-1.5 flex gap-1.5">
+ <AppSelect
+ :model-value="ctx.node.value.fontWeight"
+ :options="ctx.weights"
+ @update:model-value="ctx.setWeight(+$event)"
+ />
+ <ScrubInput
+ class="flex-1"
+ :model-value="ctx.node.value.fontSize"
+ :min="1"
+ :max="1000"
+ @update:model-value="ctx.updateProp('fontSize', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('fontSize', v, p)"
+ />
+ </div>
- <!-- Line height + Letter spacing -->
- <div class="mb-1.5 flex gap-1.5">
- <ScrubInput
- class="flex-1"
- :model-value="ctx.node.lineHeight ?? Math.round((ctx.node.fontSize || 14) * 1.2)"
- :min="0"
- @update:model-value="ctx.updateProp('lineHeight', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('lineHeight', v, p)"
- >
- <template #icon>
- <icon-lucide-baseline class="size-3" />
- </template>
- </ScrubInput>
- <ScrubInput
- class="flex-1"
- suffix="%"
- :model-value="ctx.node.letterSpacing"
- @update:model-value="ctx.updateProp('letterSpacing', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('letterSpacing', v, p)"
- >
- <template #icon>
- <icon-lucide-a-large-small class="size-3" />
- </template>
- </ScrubInput>
- </div>
+ <!-- Line height + Letter spacing -->
+ <div class="mb-1.5 flex gap-1.5">
+ <ScrubInput
+ class="flex-1"
+ :model-value="
+ ctx.node.value.lineHeight ?? Math.round((ctx.node.value.fontSize || 14) * 1.2)
+ "
+ :min="0"
+ @update:model-value="ctx.updateProp('lineHeight', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('lineHeight', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-baseline class="size-3" />
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ class="flex-1"
+ suffix="%"
+ :model-value="ctx.node.value.letterSpacing"
+ @update:model-value="ctx.updateProp('letterSpacing', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('letterSpacing', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-a-large-small class="size-3" />
+ </template>
+ </ScrubInput>
+ </div>
- <!-- Text alignment + formatting -->
- <div class="flex items-center gap-3">
- <ToggleGroupRoot
- type="single"
- class="flex gap-0.5"
- :model-value="ctx.node.textAlignHorizontal"
- @update:model-value="
- (val: AcceptableValue) => {
- if (val) ctx.setAlign(val as 'LEFT' | 'CENTER' | 'RIGHT')
- }
- "
+ <!-- Text alignment + formatting -->
+ <div class="flex items-center gap-3">
+ <ToggleGroupRoot
+ type="single"
+ class="flex gap-0.5"
+ :model-value="ctx.node.value.textAlignHorizontal"
+ @update:model-value="
+ (val: AcceptableValue) => {
+ if (val) ctx.setAlign(val as 'LEFT' | 'CENTER' | 'RIGHT')
+ }
+ "
+ >
+ <ToggleGroupItem
+ v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as const"
+ :key="align"
+ :value="align"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
>
+ <icon-lucide-align-left v-if="align === 'LEFT'" class="size-3.5" />
+ <icon-lucide-align-center v-else-if="align === 'CENTER'" class="size-3.5" />
+ <icon-lucide-align-right v-else class="size-3.5" />
+ </ToggleGroupItem>
+ </ToggleGroupRoot>
+ <ToggleGroupRoot
+ type="multiple"
+ class="flex gap-0.5"
+ :model-value="ctx.activeFormatting.value"
+ @update:model-value="
+ (val: AcceptableValue | AcceptableValue[]) => {
+ if (Array.isArray(val)) ctx.onFormattingChange(val as string[])
+ }
+ "
+ >
+ <Tip label="Bold (⌘B)">
+ <ToggleGroupItem
+ value="bold"
+ data-test-id="typography-bold-button"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 font-bold text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-bold class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ <Tip label="Italic (⌘I)">
<ToggleGroupItem
- v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as const"
- :key="align"
- :value="align"
+ value="italic"
class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
>
- <icon-lucide-align-left v-if="align === 'LEFT'" class="size-3.5" />
- <icon-lucide-align-center v-else-if="align === 'CENTER'" class="size-3.5" />
- <icon-lucide-align-right v-else class="size-3.5" />
+ <icon-lucide-italic class="size-3.5" />
</ToggleGroupItem>
- </ToggleGroupRoot>
- <ToggleGroupRoot
- type="multiple"
- class="flex gap-0.5"
- :model-value="ctx.activeFormatting"
- @update:model-value="
- (val: AcceptableValue | AcceptableValue[]) => {
- if (Array.isArray(val)) ctx.onFormattingChange(val as string[])
- }
- "
- >
- <Tip label="Bold (⌘B)">
- <ToggleGroupItem
- value="bold"
- data-test-id="typography-bold-button"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 font-bold text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-bold class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- <Tip label="Italic (⌘I)">
- <ToggleGroupItem
- value="italic"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-italic class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- <Tip label="Underline (⌘U)">
- <ToggleGroupItem
- value="underline"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-underline class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- <Tip label="Strikethrough">
- <ToggleGroupItem
- value="strikethrough"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-strikethrough class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- </ToggleGroupRoot>
- </div>
+ </Tip>
+ <Tip label="Underline (⌘U)">
+ <ToggleGroupItem
+ value="underline"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-underline class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ <Tip label="Strikethrough">
+ <ToggleGroupItem
+ value="strikethrough"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-strikethrough class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ </ToggleGroupRoot>
</div>
- </TypographyControlsRoot>
+ </div>
</template>
diff --git a/src/components/properties/VariablesSection.vue b/src/components/properties/VariablesSection.vue
index 929d8ed99..c69bf7915 100644
--- a/src/components/properties/VariablesSection.vue
+++ b/src/components/properties/VariablesSection.vue
@@ -1,31 +1,36 @@
<script setup lang="ts">
+import { computed } from 'vue'
+
import Tip from '@/components/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { VariablesIndicatorRoot } from '@open-pencil/vue'
+import { useEditor, useSceneComputed } from '@open-pencil/vue'
const emit = defineEmits<{ openDialog: [] }>()
+
+const editor = useEditor()
+const collectionCount = useSceneComputed(() => editor.getCollectionCount())
+const variableCount = useSceneComputed(() => editor.getVariableCount())
+const hasVariables = computed(() => variableCount.value > 0)
</script>
<template>
- <VariablesIndicatorRoot v-slot="{ variableCount, collectionCount, hasVariables }">
- <div data-test-id="variables-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label class="text-[11px] font-medium text-surface">Variables</label>
- <Tip label="Open variables">
- <button
- data-test-id="variables-section-open"
- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"
- @click="emit('openDialog')"
- >
- <icon-lucide-settings-2 class="size-3.5" />
- </button>
- </Tip>
- </div>
- <div v-if="hasVariables" class="mt-1 text-[11px] text-muted">
- {{ variableCount }} variable{{ variableCount !== 1 ? 's' : '' }} in
- {{ collectionCount }} collection{{ collectionCount !== 1 ? 's' : '' }}
- </div>
- <div v-else class="mt-1 text-[11px] text-muted">No local variables</div>
+ <div data-test-id="variables-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label class="text-[11px] font-medium text-surface">Variables</label>
+ <Tip label="Open variables">
+ <button
+ data-test-id="variables-section-open"
+ class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"
+ @click="emit('openDialog')"
+ >
+ <icon-lucide-settings-2 class="size-3.5" />
+ </button>
+ </Tip>
+ </div>
+ <div v-if="hasVariables" class="mt-1 text-[11px] text-muted">
+ {{ variableCount }} variable{{ variableCount !== 1 ? 's' : '' }} in
+ {{ collectionCount }} collection{{ collectionCount !== 1 ? 's' : '' }}
</div>
- </VariablesIndicatorRoot>
+ <div v-else class="mt-1 text-[11px] text-muted">No local variables</div>
+ </div>
</template>