Skip to content

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

Complete SDK plan: all 21 component families built

Danila Poyarkovced083439e56
diff --git a/packages/vue/src/ColorInput/ColorInputRoot.vue b/packages/vue/src/ColorInput/ColorInputRoot.vue
new file mode 100644
index 000000000..443bef56d
--- /dev/null
+++ b/packages/vue/src/ColorInput/ColorInputRoot.vue
@@ -0,0 +1,20 @@
+<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
new file mode 100644
index 000000000..a9d7ce228
--- /dev/null
+++ b/packages/vue/src/ColorInput/index.ts
@@ -0,0 +1 @@
+export { default as ColorInputRoot } from './ColorInputRoot.vue'
diff --git a/packages/vue/src/ColorPicker/ColorPickerRoot.vue b/packages/vue/src/ColorPicker/ColorPickerRoot.vue
new file mode 100644
index 000000000..75e6a9f14
--- /dev/null
+++ b/packages/vue/src/ColorPicker/ColorPickerRoot.vue
@@ -0,0 +1,19 @@
+<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
new file mode 100644
index 000000000..660815af3
--- /dev/null
+++ b/packages/vue/src/ColorPicker/index.ts
@@ -0,0 +1 @@
+export { default as ColorPickerRoot } from './ColorPickerRoot.vue'
diff --git a/packages/vue/src/FontPicker/FontPickerRoot.vue b/packages/vue/src/FontPicker/FontPickerRoot.vue
new file mode 100644
index 000000000..1c57ad799
--- /dev/null
+++ b/packages/vue/src/FontPicker/FontPickerRoot.vue
@@ -0,0 +1,48 @@
+<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
new file mode 100644
index 000000000..1195a355f
--- /dev/null
+++ b/packages/vue/src/FontPicker/index.ts
@@ -0,0 +1 @@
+export { default as FontPickerRoot } from './FontPickerRoot.vue'
diff --git a/packages/vue/src/GradientEditor/GradientEditorBar.vue b/packages/vue/src/GradientEditor/GradientEditorBar.vue
new file mode 100644
index 000000000..68e30d071
--- /dev/null
+++ b/packages/vue/src/GradientEditor/GradientEditorBar.vue
@@ -0,0 +1,56 @@
+<script setup lang="ts">
+import { ref } from 'vue'
+
+import type { GradientStop } from '@open-pencil/core'
+
+const { stops } = defineProps<{
+ stops: GradientStop[]
+ activeStopIndex: number
+ barBackground: string
+}>()
+
+const emit = defineEmits<{
+ selectStop: [index: number]
+ dragStop: [index: number, position: number]
+}>()
+
+const barRef = ref<HTMLElement | null>(null)
+const draggingIndex = ref<number | null>(null)
+
+function onStopPointerDown(index: number, e: PointerEvent) {
+ emit('selectStop', index)
+ draggingIndex.value = index
+ barRef.value?.setPointerCapture(e.pointerId)
+}
+
+function onPointerMove(e: PointerEvent) {
+ const el = barRef.value
+ if (!el || draggingIndex.value === null || !el.hasPointerCapture(e.pointerId)) return
+ const rect = el.getBoundingClientRect()
+ const pos = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width))
+ emit('dragStop', draggingIndex.value, pos)
+}
+
+function onPointerUp() {
+ draggingIndex.value = null
+}
+
+function setBarRef(el: unknown) {
+ barRef.value = el instanceof HTMLElement ? el : null
+}
+
+defineExpose({ barRef })
+</script>
+
+<template>
+ <slot
+ :stops="stops"
+ :active-stop-index="activeStopIndex"
+ :bar-background="barBackground"
+ :bar-ref="setBarRef"
+ :on-stop-pointer-down="onStopPointerDown"
+ :on-pointer-move="onPointerMove"
+ :on-pointer-up="onPointerUp"
+ :dragging-index="draggingIndex"
+ />
+</template>
diff --git a/packages/vue/src/GradientEditor/GradientEditorStop.vue b/packages/vue/src/GradientEditor/GradientEditorStop.vue
new file mode 100644
index 000000000..dee41c25e
--- /dev/null
+++ b/packages/vue/src/GradientEditor/GradientEditorStop.vue
@@ -0,0 +1,42 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+import { colorToCSS, colorToHexRaw } from '@open-pencil/core'
+
+import type { GradientStop } from '@open-pencil/core'
+
+const props = defineProps<{
+ stop: GradientStop
+ index: number
+ active: boolean
+}>()
+
+const emit = defineEmits<{
+ select: [index: number]
+ updatePosition: [index: number, position: number]
+ updateColor: [index: number, hex: string]
+ updateOpacity: [index: number, opacity: number]
+ remove: [index: number]
+}>()
+
+const positionPercent = computed(() => Math.round(props.stop.position * 100))
+const opacityPercent = computed(() => Math.round(props.stop.color.a * 100))
+const hex = computed(() => colorToHexRaw(props.stop.color))
+const css = computed(() => colorToCSS(props.stop.color))
+</script>
+
+<template>
+ <slot
+ :stop="stop"
+ :index="index"
+ :active="active"
+ :position-percent="positionPercent"
+ :opacity-percent="opacityPercent"
+ :hex="hex"
+ :css="css"
+ :select="() => emit('select', index)"
+ :update-position="(pos: number) => emit('updatePosition', index, pos)"
+ :update-color="(h: string) => emit('updateColor', index, h)"
+ :update-opacity="(o: number) => emit('updateOpacity', index, o)"
+ :remove="() => emit('remove', index)"
+ />
+</template>
diff --git a/packages/vue/src/GradientEditor/index.ts b/packages/vue/src/GradientEditor/index.ts
index c6212dbd7..748fd39ee 100644
--- a/packages/vue/src/GradientEditor/index.ts
+++ b/packages/vue/src/GradientEditor/index.ts
@@ -1 +1,3 @@
export { default as GradientEditorRoot } from './GradientEditorRoot.vue'
+export { default as GradientEditorBar } from './GradientEditorBar.vue'
+export { default as GradientEditorStop } from './GradientEditorStop.vue'
diff --git a/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue b/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue
new file mode 100644
index 000000000..afda50180
--- /dev/null
+++ b/packages/vue/src/ImageFillControls/ImageFillControlsRoot.vue
@@ -0,0 +1,70 @@
+<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
new file mode 100644
index 000000000..e0cecb289
--- /dev/null
+++ b/packages/vue/src/ImageFillControls/index.ts
@@ -0,0 +1 @@
+export { default as ImageFillControlsRoot } from './ImageFillControlsRoot.vue'
diff --git a/packages/vue/src/PageControls/PageControlsRoot.vue b/packages/vue/src/PageControls/PageControlsRoot.vue
new file mode 100644
index 000000000..ef233d93d
--- /dev/null
+++ b/packages/vue/src/PageControls/PageControlsRoot.vue
@@ -0,0 +1,19 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+
+import { useEditor } from '../context'
+
+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
new file mode 100644
index 000000000..86dff4164
--- /dev/null
+++ b/packages/vue/src/PageControls/index.ts
@@ -0,0 +1 @@
+export { default as PageControlsRoot } from './PageControlsRoot.vue'
diff --git a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
new file mode 100644
index 000000000..7b03042af
--- /dev/null
+++ b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
@@ -0,0 +1,139 @@
+<script setup lang="ts">
+import { ref, computed, watch } from 'vue'
+import { colorToHexRaw, parseColor, randomHex } from '@open-pencil/core'
+
+import { useEditor } from '../context'
+import { useSceneComputed } from '../composables/use-scene-reactive'
+
+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
new file mode 100644
index 000000000..da6554126
--- /dev/null
+++ b/packages/vue/src/VariablesEditor/index.ts
@@ -0,0 +1 @@
+export { default as VariablesEditorRoot } from './VariablesEditorRoot.vue'
diff --git a/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue b/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue
new file mode 100644
index 000000000..1e791242c
--- /dev/null
+++ b/packages/vue/src/VariablesIndicator/VariablesIndicatorRoot.vue
@@ -0,0 +1,20 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+
+import { useEditor } from '../context'
+import { useSceneComputed } from '../composables/use-scene-reactive'
+
+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
new file mode 100644
index 000000000..fbdb4b6ec
--- /dev/null
+++ b/packages/vue/src/VariablesIndicator/index.ts
@@ -0,0 +1 @@
+export { default as VariablesIndicatorRoot } from './VariablesIndicatorRoot.vue'
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index 4d8917368..0de64bf75 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -39,8 +39,13 @@ export { LayerTreeRoot, LayerTreeItem, useLayerTree } from './LayerTree'
export { EditorMenuRoot } from './EditorMenu'
+export { ColorPickerRoot } from './ColorPicker'
+export { ColorInputRoot } from './ColorInput'
+export { FontPickerRoot } from './FontPicker'
+export { ImageFillControlsRoot } from './ImageFillControls'
+
export { FillPickerRoot } from './FillPicker'
-export { GradientEditorRoot } from './GradientEditor'
+export { GradientEditorRoot, GradientEditorBar, GradientEditorStop } from './GradientEditor'
export { ExportControlsRoot } from './ExportControls'
export { TypographyControlsRoot } from './TypographyControls'
@@ -59,4 +64,8 @@ export { default as LayerTree } from './components/LayerTree.vue'
export { default as ToolSelector } from './components/ToolSelector.vue'
export { default as NodeProperties } from './components/NodeProperties.vue'
+export { PageControlsRoot } from './PageControls'
+export { VariablesIndicatorRoot } from './VariablesIndicator'
+export { VariablesEditorRoot } from './VariablesEditor'
+
export { toolCursor } from './utils/tool-cursor'
diff --git a/src/components/ColorInput.vue b/src/components/ColorInput.vue
index f143e0a19..30940730e 100644
--- a/src/components/ColorInput.vue
+++ b/src/components/ColorInput.vue
@@ -1,37 +1,35 @@
<script setup lang="ts">
-import ColorPicker from './ColorPicker.vue'
import type { Color } from '@open-pencil/core'
-import { colorToHexRaw, parseColor } from '@open-pencil/core'
+import { ColorInputRoot } from '@open-pencil/vue'
+
+import ColorPicker from './ColorPicker.vue'
-const { color, editable = false } = defineProps<{
+const { editable = false } = defineProps<{
color: Color
editable?: boolean
}>()
-
-const emit = defineEmits<{
- update: [color: Color]
-}>()
-
-function onHexChange(e: Event) {
- const hex = (e.target as HTMLInputElement).value
- const parsed = parseColor(hex.startsWith('#') ? hex : `#${hex}`)
- emit('update', { ...parsed, a: color.a })
-}
+const emit = defineEmits<{ update: [color: Color] }>()
</script>
<template>
- <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="colorToHexRaw(color)"
- maxlength="6"
- @change="onHexChange"
- />
- <span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
- {{ colorToHexRaw(color) }}
- </span>
- </div>
+ <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>
</template>
diff --git a/src/components/ColorPicker.vue b/src/components/ColorPicker.vue
index 14e359e19..1c8095fca 100644
--- a/src/components/ColorPicker.vue
+++ b/src/components/ColorPicker.vue
@@ -1,41 +1,35 @@
<script setup lang="ts">
import type { Color } from '@open-pencil/core'
-import { colorToCSS } from '@open-pencil/core'
-import { computed } from 'vue'
import { PopoverRoot, PopoverTrigger, PopoverPortal, PopoverContent } from 'reka-ui'
+import { ColorPickerRoot } from '@open-pencil/vue'
import HsvColorArea from './HsvColorArea.vue'
-const { color } = defineProps<{
- color: Color
-}>()
-
-const emit = defineEmits<{
- update: [color: Color]
-}>()
-
-const swatchColor = computed(() => colorToCSS(color))
+const { color } = defineProps<{ color: Color }>()
+const emit = defineEmits<{ update: [color: Color] }>()
</script>
<template>
- <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: swatchColor }"
- />
- </PopoverTrigger>
+ <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>
- <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>
+ <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>
</template>
diff --git a/src/components/FontPicker.vue b/src/components/FontPicker.vue
index 6977e038d..89e8f79e1 100644
--- a/src/components/FontPicker.vue
+++ b/src/components/FontPicker.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { computed, nextTick, onMounted, ref, watch } from 'vue'
+import { nextTick, ref } from 'vue'
import type { AcceptableValue, ListboxFilter } from 'reka-ui'
import {
ListboxContent,
@@ -8,118 +8,110 @@ import {
ListboxVirtualizer,
PopoverAnchor,
PopoverContent,
- PopoverRoot,
- useFilter
+ PopoverRoot
} from 'reka-ui'
+import { FontPickerRoot } from '@open-pencil/vue'
import { selectItem, selectTrigger } from '@/components/ui/select'
import { panelSurface } from '@/components/ui/surface'
import { listFamilies } from '@/engine/fonts'
-const modelValue = defineModel<string>({ required: true })
-const emit = defineEmits<{ select: [family: string] }>()
+defineModel<string>({ required: true })
+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 = ''
- nextTick(() => filterRef.value?.$el?.focus())
- }
-})
-
-function onSelect(val: AcceptableValue) {
- if (typeof val !== 'string') return
- modelValue.value = val
- emit('select', val)
- open.value = false
-}
</script>
<template>
- <PopoverRoot v-model:open="open">
- <PopoverAnchor>
- <button
- data-test-id="font-picker-trigger"
- :class="selectTrigger({ class: 'w-full rounded px-2 py-1 text-xs' })"
- @click="open = !open"
+ <FontPickerRoot
+ v-model="modelValue"
+ :list-families="listFamilies"
+ @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'
+ })
+ "
+ @open-auto-focus.prevent
+ @vue:mounted="nextTick(() => filterRef?.$el?.focus())"
>
- <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
- >
- <ListboxRoot :model-value="modelValue" @update:model-value="onSelect">
- <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" />
- <ListboxFilter
- ref="filterRef"
- v-model="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"
- />
- </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` }"
+ <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"
>
- <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="families.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>
+ <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>
- <div v-else-if="filtered.length === 0" class="px-2 py-3 text-center text-xs text-muted">
- No fonts found
- </div>
- </ListboxContent>
- </ListboxRoot>
- </PopoverContent>
- </PopoverRoot>
+ <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>
+ </div>
+ </ListboxContent>
+ </ListboxRoot>
+ </PopoverContent>
+ </PopoverRoot>
+ </FontPickerRoot>
</template>
diff --git a/src/components/GradientEditor.vue b/src/components/GradientEditor.vue
index 965b454a0..531698882 100644
--- a/src/components/GradientEditor.vue
+++ b/src/components/GradientEditor.vue
@@ -1,228 +1,128 @@
<script setup lang="ts">
-import { computed, ref } from 'vue'
-
import AppSelect from './AppSelect.vue'
import Tip from './Tip.vue'
import HsvColorArea from './HsvColorArea.vue'
import ScrubInput from './ScrubInput.vue'
-import { colorToCSS, colorToHexRaw, 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'
+import { colorToCSS } from '@open-pencil/core'
+import { GradientEditorRoot, GradientEditorBar, GradientEditorStop } from '@open-pencil/vue'
-const GRADIENT_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_GRADIENT_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 }
-}
+import type { Fill } from '@open-pencil/core'
const { fill } = defineProps<{ fill: Fill }>()
-
const emit = defineEmits<{ update: [fill: Fill] }>()
-
-const activeStopIndex = ref(0)
-const gradientStopBarRef = ref<HTMLDivElement | null>(null)
-const draggingStopIndex = ref<number | null>(null)
-
-const stops = computed(() => fill.gradientStops ?? [])
-
-const subtype = computed({
- get: () => fill.type as GradientSubtype,
- set: (type: GradientSubtype) => {
- if (type === fill.type) return
- emit('update', {
- ...fill,
- type,
- gradientTransform: DEFAULT_GRADIENT_TRANSFORMS[type]
- })
- }
-})
-
-const activeColor = computed(() => {
- const s = stops.value
- if (!s.length) return fill.color
- return s[Math.min(activeStopIndex.value, s.length - 1)].color
-})
-
-function emitStops(newStops: GradientStop[]) {
- emit('update', { ...fill, gradientStops: newStops })
-}
-
-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
- const s = stops.value.filter((_, i) => i !== index)
- activeStopIndex.value = Math.min(activeStopIndex.value, s.length - 1)
- emitStops(s)
-}
-
-function updateStopPosition(index: number, value: number) {
- const s = [...stops.value]
- s[index] = { ...s[index], position: Math.max(0, Math.min(1, value / 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, value: number) {
- const s = [...stops.value]
- s[index] = { ...s[index], color: { ...s[index].color, a: Math.max(0, Math.min(1, value / 100)) } }
- emitStops(s)
-}
-
-function onActiveColorUpdate(color: Color) {
- const s = [...stops.value]
- const idx = Math.min(activeStopIndex.value, s.length - 1)
- s[idx] = { ...s[idx], color }
- emitStops(s)
-}
-
-function onStopPointerDown(index: number, e: PointerEvent) {
- selectStop(index)
- draggingStopIndex.value = index
- gradientStopBarRef.value?.setPointerCapture(e.pointerId)
-}
-
-function onStopBarPointerMove(e: PointerEvent) {
- const el = gradientStopBarRef.value
- if (!el || draggingStopIndex.value === null || !el.hasPointerCapture(e.pointerId)) return
- const rect = el.getBoundingClientRect()
- const pos = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width))
- const s = [...stops.value]
- s[draggingStopIndex.value] = { ...s[draggingStopIndex.value], position: pos }
- emitStops(s)
-}
-
-function onStopBarPointerUp() {
- draggingStopIndex.value = null
-}
-
-function gradientCSS(stopsArr: GradientStop[]): string {
- return stopsArr.map((s) => `${colorToCSS(s.color)} ${s.position * 100}%`).join(', ')
-}
-
-const barBackground = computed(() =>
- stops.value.length ? `linear-gradient(to right, ${gradientCSS(stops.value)})` : ''
-)
</script>
<template>
- <div>
- <div class="mb-2 w-28">
- <AppSelect v-model="subtype" :options="GRADIENT_SUBTYPES" />
- </div>
-
- <!-- Stop bar -->
- <div
- ref="gradientStopBarRef"
- data-test-id="fill-picker-gradient-bar"
- class="relative mb-2 h-6 rounded"
- :style="{ background: barBackground }"
- @pointermove="onStopBarPointerMove"
- @pointerup="onStopBarPointerUp"
- >
- <div
- v-for="(stop, idx) in stops"
- :key="idx"
- class="absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-sm border-2 shadow-sm"
- :class="idx === activeStopIndex ? 'border-white' : 'border-white/60'"
- :style="{ left: `${stop.position * 100}%`, background: colorToCSS(stop.color) }"
- @pointerdown.stop="onStopPointerDown(idx, $event)"
- />
- </div>
-
- <!-- Stop list -->
- <div class="mb-2">
- <div class="mb-1 flex items-center justify-between">
- <span class="text-[11px] text-muted">Stops</span>
- <Tip label="Add stop">
- <button
- class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
- data-test-id="fill-picker-add-stop"
- @click="addStop"
- >
- <icon-lucide-plus class="size-3" />
- </button>
- </Tip>
+ <GradientEditorRoot :fill="fill" @update="emit('update', $event)" v-slot="root">
+ <div>
+ <div class="mb-2 w-28">
+ <AppSelect
+ :model-value="root.subtype"
+ :options="root.subtypes"
+ @update:model-value="root.setSubtype($event)"
+ />
</div>
- <div
- v-for="(stop, idx) in stops"
- :key="idx"
- class="flex items-center gap-1 py-0.5"
- :class="{ 'rounded bg-hover/50': idx === activeStopIndex }"
- @click="selectStop(idx)"
+
+ <GradientEditorBar
+ :stops="root.stops"
+ :active-stop-index="root.activeStopIndex"
+ :bar-background="root.barBackground"
+ @select-stop="root.selectStop"
+ @drag-stop="root.dragStop"
+ v-slot="bar"
>
- <ScrubInput
- class="w-11"
- suffix="%"
- :model-value="Math.round(stop.position * 100)"
- :min="0"
- :max="100"
- @update:model-value="updateStopPosition(idx, Number($event))"
- @click.stop
- />
- <button
- class="size-4 shrink-0 cursor-pointer rounded border border-border p-0"
- :style="{ background: colorToCSS(stop.color) }"
- @click.stop="selectStop(idx)"
- />
- <input
- class="min-w-0 flex-1 rounded border border-border bg-input px-1 py-0.5 font-mono text-[11px] text-surface"
- :value="colorToHexRaw(stop.color)"
- maxlength="6"
- @change="updateStopColor(idx, ($event.target as HTMLInputElement).value)"
- @click.stop
- />
- <ScrubInput
- class="w-9"
- suffix="%"
- :model-value="Math.round(stop.color.a * 100)"
- :min="0"
- :max="100"
- @update:model-value="updateStopOpacity(idx, Number($event))"
- @click.stop
- />
- <button
- v-if="stops.length > 2"
- class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
- @click.stop="removeStop(idx)"
+ <div
+ :ref="bar.barRef"
+ data-test-id="fill-picker-gradient-bar"
+ class="relative mb-2 h-6 rounded"
+ :style="{ background: bar.barBackground }"
+ @pointermove="bar.onPointerMove"
+ @pointerup="bar.onPointerUp"
>
- −
- </button>
+ <div
+ v-for="(stop, idx) in bar.stops"
+ :key="idx"
+ class="absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-sm border-2 shadow-sm"
+ :class="idx === bar.activeStopIndex ? 'border-white' : 'border-white/60'"
+ :style="{ left: `${stop.position * 100}%`, background: colorToCSS(stop.color) }"
+ @pointerdown.stop="bar.onStopPointerDown(idx, $event)"
+ />
+ </div>
+ </GradientEditorBar>
+
+ <div class="mb-2">
+ <div class="mb-1 flex items-center justify-between">
+ <span class="text-[11px] text-muted">Stops</span>
+ <Tip label="Add stop">
+ <button
+ class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
+ data-test-id="fill-picker-add-stop"
+ @click="root.addStop"
+ >
+ <icon-lucide-plus class="size-3" />
+ </button>
+ </Tip>
+ </div>
+ <GradientEditorStop
+ v-for="(stop, idx) in root.stops"
+ :key="idx"
+ :stop="stop"
+ :index="idx"
+ :active="idx === root.activeStopIndex"
+ @select="root.selectStop"
+ @update-position="root.updateStopPosition"
+ @update-color="root.updateStopColor"
+ @update-opacity="root.updateStopOpacity"
+ @remove="root.removeStop"
+ v-slot="s"
+ >
+ <div
+ class="flex items-center gap-1 py-0.5"
+ :class="{ 'rounded bg-hover/50': s.active }"
+ @click="s.select"
+ >
+ <ScrubInput
+ class="w-11"
+ suffix="%"
+ :model-value="s.positionPercent"
+ :min="0"
+ :max="100"
+ @update:model-value="s.updatePosition(Number($event))"
+ @click.stop
+ />
+ <button
+ class="size-4 shrink-0 cursor-pointer rounded border border-border p-0"
+ :style="{ background: s.css }"
+ @click.stop="s.select"
+ />
+ <input
+ class="min-w-0 flex-1 rounded border border-border bg-input px-1 py-0.5 font-mono text-[11px] text-surface"
+ :value="s.hex"
+ maxlength="6"
+ @change="s.updateColor(($event.target as HTMLInputElement).value)"
+ @click.stop
+ />
+ <ScrubInput
+ class="w-9"
+ suffix="%"
+ :model-value="s.opacityPercent"
+ :min="0"
+ :max="100"
+ @update:model-value="s.updateOpacity(Number($event))"
+ @click.stop
+ />
+ <button
+ v-if="root.stops.length > 2"
+ class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click.stop="s.remove"
+ >
+ −
+ </button>
+ </div>
+ </GradientEditorStop>
</div>
- </div>
- <HsvColorArea :color="activeColor" @update="onActiveColorUpdate" />
- </div>
+ <HsvColorArea :color="root.activeColor" @update="root.updateActiveColor" />
+ </div>
+ </GradientEditorRoot>
</template>
diff --git a/src/components/ImageFillPicker.vue b/src/components/ImageFillPicker.vue
index b31f8a428..63eaf77e0 100644
--- a/src/components/ImageFillPicker.vue
+++ b/src/components/ImageFillPicker.vue
@@ -1,79 +1,47 @@
<script setup lang="ts">
-import { computed, shallowRef, watch } from 'vue'
-import { useFileDialog, useObjectUrl } from '@vueuse/core'
+import type { Fill } from '@open-pencil/core'
+import { ImageFillControlsRoot, useEditor } from '@open-pencil/vue'
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()
-
-const imageBlob = shallowRef<Blob | null>(null)
-const imagePreviewUrl = useObjectUrl(imageBlob)
-watch(
- () => fill.imageHash,
- (hash) => {
- if (!hash) {
- imageBlob.value = null
- return
- }
- const data = store.graph.images.get(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 store = useEditor()
-const scaleMode = computed({
- get: () => fill.imageScaleMode ?? ('FILL' as ImageScaleMode),
- set: (mode: ImageScaleMode) => emit('update', { ...fill, imageScaleMode: mode })
-})
+function resolveImage(hash: string) {
+ return store.graph.images.get(hash)
+}
</script>
<template>
- <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" />
+ <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>
- <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 v-model="scaleMode" :options="IMAGE_SCALE_MODES" />
- </div>
+ </ImageFillControlsRoot>
</template>
diff --git a/src/components/VariablesDialog.vue b/src/components/VariablesDialog.vue
index 332aefa92..e490c0a66 100644
--- a/src/components/VariablesDialog.vue
+++ b/src/components/VariablesDialog.vue
@@ -166,6 +166,13 @@ function removeVariable(id: string) {
store.removeVariable(id)
}
+const VARIABLE_TYPE_ICONS: Record<string, Component> = {
+ COLOR: IconPalette,
+ FLOAT: IconHash,
+ STRING: IconType,
+ BOOLEAN: IconToggleLeft
+}
+
const columns = computed<ColumnDef<Variable>[]>(() => {
const nameCol: ColumnDef<Variable> = {
id: 'name',
@@ -176,12 +183,6 @@ const columns = computed<ColumnDef<Variable>[]>(() => {
cell: ({ row }) => {
const v = row.original
const iconClass = 'size-3.5 shrink-0 text-muted'
- const VARIABLE_TYPE_ICONS: Record<string, Component> = {
- COLOR: IconPalette,
- FLOAT: IconHash,
- STRING: IconType,
- BOOLEAN: IconToggleLeft
- }
const iconComponent = VARIABLE_TYPE_ICONS[v.type] ?? IconToggleLeft
const icon = h(iconComponent, { class: iconClass })
@@ -455,4 +456,3 @@ const table = useVueTable({
</DialogPortal>
</DialogRoot>
</template>
-emplate>
diff --git a/src/components/properties/PageSection.vue b/src/components/properties/PageSection.vue
index 21ddcb74d..894f9823a 100644
--- a/src/components/properties/PageSection.vue
+++ b/src/components/properties/PageSection.vue
@@ -1,19 +1,13 @@
<script setup lang="ts">
import ColorInput from '@/components/ColorInput.vue'
-import { useEditor } from '@open-pencil/vue'
-
-import type { Color } from '@open-pencil/core'
-
-const store = useEditor()
-
-function updateColor(color: Color) {
- store.setPageColor(color)
-}
+import { PageControlsRoot } from '@open-pencil/vue'
</script>
<template>
- <div data-test-id="page-section" class="border-b border-border px-3 py-2">
- <label class="mb-1.5 block text-[11px] text-muted">Page</label>
- <ColorInput :color="store.state.pageColor" editable @update="updateColor" />
- </div>
+ <PageControlsRoot v-slot="{ pageColor, setPageColor }">
+ <div data-test-id="page-section" class="border-b border-border px-3 py-2">
+ <label class="mb-1.5 block text-[11px] text-muted">Page</label>
+ <ColorInput :color="pageColor" editable @update="setPageColor" />
+ </div>
+ </PageControlsRoot>
</template>
diff --git a/src/components/properties/VariablesSection.vue b/src/components/properties/VariablesSection.vue
index b9d792195..9414c9e9b 100644
--- a/src/components/properties/VariablesSection.vue
+++ b/src/components/properties/VariablesSection.vue
@@ -1,33 +1,30 @@
<script setup lang="ts">
import Tip from '@/components/Tip.vue'
-import { useEditor, useSceneComputed } from '@open-pencil/vue'
+import { VariablesIndicatorRoot } from '@open-pencil/vue'
-const store = useEditor()
const emit = defineEmits<{ openDialog: [] }>()
-
-const collectionCount = useSceneComputed(() => store.getCollectionCount())
-
-const variableCount = useSceneComputed(() => store.getVariableCount())
</script>
<template>
- <div data-test-id="variables-section" class="border-b border-border px-3 py-2">
- <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="variableCount > 0" class="mt-1 text-[11px] text-muted">
- {{ variableCount }} variable{{ variableCount !== 1 ? 's' : '' }} in
- {{ collectionCount }} collection{{ collectionCount !== 1 ? 's' : '' }}
+ <VariablesIndicatorRoot v-slot="{ variableCount, collectionCount, hasVariables }">
+ <div data-test-id="variables-section" class="border-b border-border px-3 py-2">
+ <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>
- <div v-else class="mt-1 text-[11px] text-muted">No local variables</div>
- </div>
+ </VariablesIndicatorRoot>
</template>