Skip to content

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

SDK: AppearanceControls, TypographyControls, EffectsSection via PropertyListRoot

Danila Poyarkov2a69ef956f71
diff --git a/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue b/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
new file mode 100644
index 000000000..02b25463c
--- /dev/null
+++ b/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
@@ -0,0 +1,186 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+
+import { useEditor } from '../context'
+import { MIXED } from '../composables/use-node-props'
+
+import type { SceneNode } from '@open-pencil/core'
+import type { MixedValue } from '../composables/use-node-props'
+
+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 previousValues = new Map<string, Record<string, number | string>>()
+
+function storePreviousValues(key: string) {
+ for (const n of editor.getSelectedNodes()) {
+ let rec = previousValues.get(n.id)
+ if (!rec) {
+ rec = {}
+ previousValues.set(n.id, rec)
+ }
+ if (!(key in rec)) {
+ rec[key] = n[key as keyof SceneNode] as number | string
+ }
+ }
+}
+
+function updateProp(key: string, value: number | string) {
+ if (editor.getSelectedNodes().length > 1) {
+ storePreviousValues(key)
+ for (const n of editor.getSelectedNodes()) {
+ editor.updateNode(n.id, { [key]: value })
+ }
+ } else {
+ const n = editor.getSelectedNode()
+ if (n) editor.updateNode(n.id, { [key]: value })
+ }
+}
+
+function commitProp(key: string, _value: number | string, previous: number | string) {
+ if (editor.getSelectedNodes().length > 1) {
+ for (const n of editor.getSelectedNodes()) {
+ const prev = previousValues.get(n.id)?.[key] ?? previous
+ editor.commitNodeUpdate(n.id, { [key]: prev } as Partial<SceneNode>, `Change ${key}`)
+ }
+ previousValues.clear()
+ } else {
+ const n = editor.getSelectedNode()
+ if (n) editor.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+ }
+}
+
+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
new file mode 100644
index 000000000..0a795c6ab
--- /dev/null
+++ b/packages/vue/src/AppearanceControls/index.ts
@@ -0,0 +1 @@
+export { default as AppearanceControlsRoot } from './AppearanceControlsRoot.vue'
diff --git a/packages/vue/src/TypographyControls/TypographyControlsRoot.vue b/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
new file mode 100644
index 000000000..dcb0307e6
--- /dev/null
+++ b/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
@@ -0,0 +1,133 @@
+<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 '../context'
+import { useNodeFontStatus } from '../composables/use-font-status'
+
+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
new file mode 100644
index 000000000..1c2ea0745
--- /dev/null
+++ b/packages/vue/src/TypographyControls/index.ts
@@ -0,0 +1 @@
+export { default as TypographyControlsRoot } from './TypographyControlsRoot.vue'
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index b1f361c27..4d8917368 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -42,6 +42,9 @@ export { EditorMenuRoot } from './EditorMenu'
export { FillPickerRoot } from './FillPicker'
export { GradientEditorRoot } from './GradientEditor'
export { ExportControlsRoot } from './ExportControls'
+export { TypographyControlsRoot } from './TypographyControls'
+
+export { AppearanceControlsRoot } from './AppearanceControls'
export type { LayerTreeContext, LayerNode } from './LayerTree'
export type { CanvasContext } from './Canvas'
diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vue
index 422d916a9..9876bcf98 100644
--- a/src/components/properties/AppearanceSection.vue
+++ b/src/components/properties/AppearanceSection.vue
@@ -1,201 +1,124 @@
<script setup lang="ts">
-import { computed } from 'vue'
-
import ScrubInput from '@/components/ScrubInput.vue'
-import { MIXED, useNodeProps } from '@open-pencil/vue'
-
import Tip from '@/components/Tip.vue'
-
-import type { SceneNode } from '@open-pencil/core'
-
-const { store, node, nodes, isMulti, active, merged, updateAllWithUndo, updateProp, commitProp } =
- useNodeProps()
-
-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)
-})
-
-const visibilityState = computed(() => {
- const v = merged('visible')
- if (v === MIXED) return 'mixed'
- return v ? 'visible' : 'hidden'
-})
-
-function toggleVisibility() {
- if (isMulti.value) {
- const allVisible = nodes.value.every((n) => n.visible)
- updateAllWithUndo({ visible: !allVisible }, 'Toggle visibility')
- } else {
- const n = node.value
- if (!n) return
- store.updateNodeWithUndo(n.id, { visible: !n.visible }, 'Toggle visibility')
- }
-}
-
-function toggleIndependentCorners() {
- const target = isMulti.value ? nodes.value[0] : node.value
- if (!target) return
-
- if (isMulti.value) {
- for (const n of nodes.value) {
- if (n.independentCorners) {
- const uniform = n.topLeftRadius
- store.updateNodeWithUndo(
- n.id,
- {
- independentCorners: false,
- cornerRadius: uniform,
- topLeftRadius: uniform,
- topRightRadius: uniform,
- bottomRightRadius: uniform,
- bottomLeftRadius: uniform
- } as Partial<SceneNode>,
- 'Uniform corner radius'
- )
- } else {
- store.updateNodeWithUndo(
- n.id,
- {
- independentCorners: true,
- topLeftRadius: n.cornerRadius,
- topRightRadius: n.cornerRadius,
- bottomRightRadius: n.cornerRadius,
- bottomLeftRadius: n.cornerRadius
- } as Partial<SceneNode>,
- 'Independent corner radii'
- )
- }
- }
- } else {
- const n = node.value
- if (!n) return
- if (n.independentCorners) {
- const uniform = n.topLeftRadius
- store.updateNodeWithUndo(
- n.id,
- {
- independentCorners: false,
- cornerRadius: uniform,
- topLeftRadius: uniform,
- topRightRadius: uniform,
- bottomRightRadius: uniform,
- bottomLeftRadius: uniform
- } as Partial<SceneNode>,
- 'Uniform corner radius'
- )
- } else {
- store.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) store.updateNode(n.id, { [key]: value })
- } else {
- const n = node.value
- if (n) store.updateNode(n.id, { [key]: value })
- }
-}
-
-function commitCornerProp(key: string, _value: number, previous: number) {
- if (isMulti.value) {
- for (const n of nodes.value) {
- store.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
- }
- } else {
- const n = node.value
- if (n) store.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
- }
-}
-
-const independentCorners = computed(() => {
- if (isMulti.value) return merged('independentCorners')
- return node.value?.independentCorners ?? false
-})
-
-const opacityValue = computed(() => {
- const v = merged('opacity')
- return v === MIXED ? MIXED : Math.round((v as number) * 100)
-})
-
-const cornerRadiusValue = computed(() => {
- if (isMulti.value) return merged('cornerRadius')
- return node.value?.cornerRadius ?? 0
-})
+import { AppearanceControlsRoot } from '@open-pencil/vue'
</script>
<template>
- <div v-if="active" data-test-id="appearance-section" class="border-b border-border px-3 py-2">
- <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"
+ <AppearanceControlsRoot
+ v-slot="{
+ node,
+ isMulti,
+ hasCornerRadius,
+ independentCorners,
+ cornerRadiusValue,
+ opacityPercent,
+ visibilityState,
+ updateProp,
+ commitProp,
+ toggleVisibility,
+ toggleIndependentCorners,
+ updateCornerProp,
+ commitCornerProp
+ }"
+ >
+ <div data-test-id="appearance-section" class="border-b border-border px-3 py-2">
+ <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)"
>
- <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="opacityValue"
- :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 #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>
- </ScrubInput>
- <template v-if="hasCornerRadius">
+ </div>
+
+ <div
+ v-if="hasCornerRadius && independentCorners === true && !isMulti"
+ class="mt-1.5 grid grid-cols-2 gap-1.5"
+ >
<ScrubInput
- v-if="independentCorners !== true"
- data-test-id="corner-radius-input"
- :model-value="cornerRadiusValue"
+ data-test-id="corner-tl-input"
+ :model-value="node!.topLeftRadius"
:min="0"
- @update:model-value="updateProp('cornerRadius', $event)"
- @commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"
+ @update:model-value="updateCornerProp('topLeftRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"
>
<template #icon>
- <icon-lucide-radius class="size-3" />
+ <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>
- <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"
- >
+ <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"
@@ -203,96 +126,49 @@ const cornerRadiusValue = computed(() => {
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" />
+ <path d="M11 11V4a3 3 0 0 0-3-3H1" />
</svg>
- </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>
+ </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>
</div>
- </div>
+ </AppearanceControlsRoot>
</template>
diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vue
index 1d84f977a..3ea22f29c 100644
--- a/src/components/properties/EffectsSection.vue
+++ b/src/components/properties/EffectsSection.vue
@@ -1,17 +1,15 @@
<script setup lang="ts">
-import { computed, ref } from 'vue'
+import { ref } from 'vue'
import AppSelect from '@/components/AppSelect.vue'
import ColorInput from '@/components/ColorInput.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import { useNodeProps } from '@open-pencil/vue'
+import { PropertyListRoot, useEditor } from '@open-pencil/vue'
import { colorToCSS } from '@open-pencil/core'
-import type { Color, Effect } from '@open-pencil/core'
+import type { Color, Effect, SceneNode } from '@open-pencil/core'
-const { store, node, nodes, isMulti, active, isArrayMixed } = useNodeProps()
-
-const effectsAreMixed = computed(() => isArrayMixed('effects'))
+const editor = useEditor()
const expandedIndex = ref<number | null>(null)
const effectsBeforeScrub = ref<Effect[] | null>(null)
@@ -44,89 +42,62 @@ function defaultEffect(): Effect {
}
}
-function scrubEffect(index: number, changes: Partial<Effect>) {
- const n = node.value
- if (!n) return
+function scrubEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
if (!effectsBeforeScrub.value) {
- effectsBeforeScrub.value = n.effects.map((e) => ({
+ effectsBeforeScrub.value = node.effects.map((e) => ({
...e,
color: { ...e.color },
offset: { ...e.offset }
}))
}
- const effects = [...n.effects]
+ const effects = [...node.effects]
effects[index] = { ...effects[index], ...changes }
- store.updateNode(n.id, { effects })
- store.requestRender()
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
}
-function commitEffect(index: number, changes: Partial<Effect>) {
- const n = node.value
- if (!n) return
+function commitEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
const previous = effectsBeforeScrub.value
effectsBeforeScrub.value = null
- const effects = [...n.effects]
+ const effects = [...node.effects]
effects[index] = { ...effects[index], ...changes }
- store.updateNode(n.id, { effects })
- store.requestRender()
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
if (previous) {
- store.commitNodeUpdate(n.id, { effects: previous }, 'Change effect')
+ editor.commitNodeUpdate(node.id, { effects: previous }, 'Change effect')
}
}
-function updateEffect(index: number, changes: Partial<Effect>) {
- const n = node.value
- if (!n) return
- const effects = [...n.effects]
- effects[index] = { ...effects[index], ...changes }
- store.updateNodeWithUndo(n.id, { effects }, 'Change effect')
-}
-
-function updateColor(index: number, color: Color) {
- updateEffect(index, { color })
-}
-
-function toggleVisibility(index: number) {
- const n = node.value
- if (!n) return
- updateEffect(index, { visible: !n.effects[index].visible })
-}
-
-function updateType(index: number, type: EffectType) {
- const n = node.value
- if (!n) return
+function updateType(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ node: SceneNode | null,
+ index: number,
+ type: EffectType
+) {
+ if (!node) return
const changes: Partial<Effect> = { type }
if (!isShadow(type)) {
changes.offset = { x: 0, y: 0 }
changes.spread = 0
- } else if (!isShadow(n.effects[index].type)) {
+ } else if (!isShadow(node.effects[index].type)) {
changes.offset = { x: 0, y: 4 }
changes.spread = 0
}
- updateEffect(index, changes)
+ patch(index, changes)
}
-function add() {
- if (isMulti.value) {
- for (const n of nodes.value) {
- store.updateNodeWithUndo(n.id, { effects: [defaultEffect()] }, 'Set effect')
- }
- return
- }
- const n = node.value
- if (!n) return
- const effects = [...n.effects, defaultEffect()]
- store.updateNodeWithUndo(n.id, { effects }, 'Add effect')
+function updateColor(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ index: number,
+ color: Color
+) {
+ patch(index, { color })
}
-function remove(index: number) {
- const n = node.value
- if (!n) return
- store.updateNodeWithUndo(
- n.id,
- { effects: n.effects.filter((_, i) => i !== index) },
- 'Remove effect'
- )
+function handleRemove(removeFn: (index: number) => void, index: number) {
+ removeFn(index)
if (expandedIndex.value === index) expandedIndex.value = null
else if (expandedIndex.value !== null && expandedIndex.value > index) expandedIndex.value--
}
@@ -137,129 +108,139 @@ function toggleExpand(index: number) {
</script>
<template>
- <div v-if="active" data-test-id="effects-section" class="border-b border-border px-3 py-2">
- <div class="flex items-center justify-between">
- <label class="mb-1 block text-[11px] text-muted">Effects</label>
- <button
- data-test-id="effects-section-add"
- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"
- @click="add"
- >
- +
- </button>
- </div>
-
- <p v-if="effectsAreMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
-
- <div
- v-for="(effect, i) in effectsAreMixed ? [] : ((node ?? nodes[0])?.effects ?? [])"
- :key="i"
- data-test-id="effects-item"
- :data-test-index="i"
- >
- <!-- Collapsed row: color swatch | type dropdown | eye | minus -->
- <div class="group flex items-center gap-1.5 py-0.5">
- <button
- v-if="isShadow(effect.type)"
- class="size-5 shrink-0 cursor-pointer rounded border border-border"
- :style="{ background: colorToCSS(effect.color) }"
- @click="toggleExpand(i)"
- />
- <button
- v-else
- class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
- @click="toggleExpand(i)"
- >
- <icon-lucide-blend class="size-3 text-muted" />
- </button>
-
- <AppSelect
- :model-value="effect.type"
- :options="EFFECT_OPTIONS"
- @update:model-value="updateType(i, $event as EffectType)"
- />
-
- <button
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
+ prop-key="effects"
+ label="Effects"
+ >
+ <div data-test-id="effects-section" class="border-b border-border px-3 py-2">
+ <div class="flex items-center justify-between">
+ <label class="mb-1 block text-[11px] text-muted">Effects</label>
<button
+ data-test-id="effects-section-add"
class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"
- @click="remove(i)"
+ @click="add(defaultEffect())"
>
- −
+ +
</button>
</div>
- <!-- Expanded controls inline -->
- <div v-if="expandedIndex === i" class="flex flex-col gap-1.5 py-1.5">
- <template v-if="isShadow(effect.type)">
- <div class="flex items-center gap-1.5">
- <ScrubInput
- icon="X"
- :model-value="effect.offset.x"
- @update:model-value="scrubEffect(i, { offset: { ...effect.offset, x: $event } })"
- @commit="commitEffect(i, { offset: { ...effect.offset, x: $event } })"
- />
- <ScrubInput
- icon="Y"
- :model-value="effect.offset.y"
- @update:model-value="scrubEffect(i, { offset: { ...effect.offset, y: $event } })"
- @commit="commitEffect(i, { offset: { ...effect.offset, y: $event } })"
- />
- </div>
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
- <div class="flex items-center gap-1.5">
+ <div
+ v-for="(effect, i) in items as Effect[]"
+ :key="i"
+ data-test-id="effects-item"
+ :data-test-index="i"
+ >
+ <!-- Collapsed row: color swatch | type dropdown | eye | minus -->
+ <div class="group flex items-center gap-1.5 py-0.5">
+ <button
+ v-if="isShadow(effect.type)"
+ class="size-5 shrink-0 cursor-pointer rounded border border-border"
+ :style="{ background: colorToCSS(effect.color) }"
+ @click="toggleExpand(i)"
+ />
+ <button
+ v-else
+ class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
+ @click="toggleExpand(i)"
+ >
+ <icon-lucide-blend class="size-3 text-muted" />
+ </button>
+
+ <AppSelect
+ :model-value="effect.type"
+ :options="EFFECT_OPTIONS"
+ @update:model-value="updateType(patch, activeNode, i, $event as EffectType)"
+ />
+
+ <button
+ class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button
+ class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"
+ @click="handleRemove(remove, i)"
+ >
+ −
+ </button>
+ </div>
+
+ <!-- Expanded controls inline -->
+ <div v-if="expandedIndex === i" class="flex flex-col gap-1.5 py-1.5">
+ <template v-if="isShadow(effect.type)">
+ <div class="flex items-center gap-1.5">
+ <ScrubInput
+ icon="X"
+ :model-value="effect.offset.x"
+ @update:model-value="
+ scrubEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
+ "
+ @commit="commitEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })"
+ />
+ <ScrubInput
+ icon="Y"
+ :model-value="effect.offset.y"
+ @update:model-value="
+ scrubEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
+ "
+ @commit="commitEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })"
+ />
+ </div>
+
+ <div class="flex items-center gap-1.5">
+ <ScrubInput
+ icon="B"
+ :model-value="effect.radius"
+ :min="0"
+ @update:model-value="scrubEffect(activeNode, i, { radius: $event })"
+ @commit="commitEffect(activeNode, i, { radius: $event })"
+ />
+ <ScrubInput
+ icon="S"
+ :model-value="effect.spread"
+ @update:model-value="scrubEffect(activeNode, i, { spread: $event })"
+ @commit="commitEffect(activeNode, i, { spread: $event })"
+ />
+ </div>
+
+ <div class="flex items-center gap-1.5">
+ <ColorInput :color="effect.color" editable @update="updateColor(patch, i, $event)" />
+ <ScrubInput
+ class="w-14"
+ suffix="%"
+ :model-value="Math.round(effect.color.a * 100)"
+ :min="0"
+ :max="100"
+ @update:model-value="
+ scrubEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ @commit="
+ commitEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ />
+ </div>
+ </template>
+
+ <template v-else>
<ScrubInput
icon="B"
:model-value="effect.radius"
:min="0"
- @update:model-value="scrubEffect(i, { radius: $event })"
- @commit="commitEffect(i, { radius: $event })"
- />
- <ScrubInput
- icon="S"
- :model-value="effect.spread"
- @update:model-value="scrubEffect(i, { spread: $event })"
- @commit="commitEffect(i, { spread: $event })"
+ @update:model-value="scrubEffect(activeNode, i, { radius: $event })"
+ @commit="commitEffect(activeNode, i, { radius: $event })"
/>
- </div>
-
- <div class="flex items-center gap-1.5">
- <ColorInput :color="effect.color" editable @update="updateColor(i, $event)" />
- <ScrubInput
- class="w-14"
- suffix="%"
- :model-value="Math.round(effect.color.a * 100)"
- :min="0"
- :max="100"
- @update:model-value="
- scrubEffect(i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- @commit="
- commitEffect(i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- />
- </div>
- </template>
-
- <template v-else>
- <ScrubInput
- icon="B"
- :model-value="effect.radius"
- :min="0"
- @update:model-value="scrubEffect(i, { radius: $event })"
- @commit="commitEffect(i, { radius: $event })"
- />
- </template>
+ </template>
+ </div>
</div>
</div>
- </div>
+ </PropertyListRoot>
</template>
diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vue
index 91ebec11d..faea6d13c 100644
--- a/src/components/properties/TypographySection.vue
+++ b/src/components/properties/TypographySection.vue
@@ -1,234 +1,151 @@
<script setup lang="ts">
-import { computed, onMounted } from 'vue'
-
import AppSelect from '@/components/AppSelect.vue'
import FontPicker from '@/components/FontPicker.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import { useNodeFontStatus, useNodeProps } from '@open-pencil/vue'
+import Tip from '@/components/Tip.vue'
import { loadFont } from '@/engine/fonts'
+import { TypographyControlsRoot } from '@open-pencil/vue'
import { ToggleGroupItem, ToggleGroupRoot, type AcceptableValue } from 'reka-ui'
-import Tip from '@/components/Tip.vue'
-
-const { store, node, updateProp, commitProp } = useNodeProps()
-const { missingFonts, hasMissingFonts } = useNodeFontStatus(() => node.value)
-
-const WEIGHTS = [
- { value: 100, label: 'Thin' },
- { value: 200, label: 'ExtraLight' },
- { value: 300, label: 'Light' },
- { value: 400, label: 'Regular' },
- { value: 500, label: 'Medium' },
- { value: 600, label: 'SemiBold' },
- { value: 700, label: 'Bold' },
- { value: 800, label: 'ExtraBold' },
- { value: 900, label: 'Black' }
-]
-
-const currentWeightLabel = computed(
- () => WEIGHTS.find((w) => w.value === node.value?.fontWeight)?.label ?? 'Regular'
-)
-
-type TextAlign = 'LEFT' | 'CENTER' | 'RIGHT'
-
-async function selectFamily(family: string) {
- if (!node.value) return
- await loadFont(family, currentWeightLabel.value)
- store.updateNodeWithUndo(node.value.id, { fontFamily: family }, 'Change font')
-}
-
-async function selectWeight(weight: number) {
- if (!node.value) return
- const label = WEIGHTS.find((w) => w.value === weight)?.label ?? 'Regular'
- await loadFont(node.value.fontFamily, label)
- store.updateNodeWithUndo(node.value.id, { fontWeight: weight }, 'Change font weight')
-}
-
-function setAlign(align: TextAlign) {
- if (!node.value) return
- store.updateNodeWithUndo(node.value.id, { textAlignHorizontal: align }, 'Change text alignment')
-}
-
-function toggleBold() {
- if (!node.value) return
- selectWeight(node.value.fontWeight >= 700 ? 400 : 700)
-}
-
-function toggleItalic() {
- if (!node.value) return
- store.updateNodeWithUndo(node.value.id, { italic: !node.value.italic }, 'Toggle italic')
-}
-
-function toggleDecoration(deco: 'UNDERLINE' | 'STRIKETHROUGH') {
- if (!node.value) return
- const current = node.value.textDecoration
- store.updateNodeWithUndo(
- node.value.id,
- { textDecoration: current === deco ? 'NONE' : deco },
- `Toggle ${deco.toLowerCase()}`
- )
-}
-
-const activeFormatting = computed(() => {
- if (!node.value) return []
- const result: string[] = []
- if (node.value.fontWeight >= 700) result.push('bold')
- if (node.value.italic) result.push('italic')
- if (node.value.textDecoration === 'UNDERLINE') result.push('underline')
- if (node.value.textDecoration === 'STRIKETHROUGH') result.push('strikethrough')
- return result
-})
-
-function onFormattingChange(next: AcceptableValue | AcceptableValue[]) {
- if (!node.value || !Array.isArray(next)) return
- const prev = activeFormatting.value
- const values = next as string[]
- const added = values.filter((v) => !prev.includes(v))
- const removed = prev.filter((v) => !values.includes(v))
- for (const item of added) {
- if (item === 'bold') toggleBold()
- else if (item === 'italic') toggleItalic()
- else if (item === 'underline') toggleDecoration('UNDERLINE')
- else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')
- }
- for (const item of removed) {
- if (item === 'bold') toggleBold()
- else if (item === 'italic') toggleItalic()
- else if (item === 'underline') toggleDecoration('UNDERLINE')
- else if (item === 'strikethrough') toggleDecoration('STRIKETHROUGH')
- }
-}
-
-onMounted(async () => {
- if (!node.value) return
- await loadFont(node.value.fontFamily, currentWeightLabel.value)
-})
</script>
<template>
- <div v-if="node" data-test-id="typography-section" class="border-b border-border px-3 py-2">
- <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="node.fontFamily" @select="selectFamily" />
- <Tip
- v-if="hasMissingFonts"
- :label="
- 'Missing font' + (missingFonts.length > 1 ? 's' : '') + ': ' + missingFonts.join(', ')
- "
- >
- <icon-lucide-alert-triangle
- data-test-id="typography-missing-font"
- class="size-3.5 shrink-0 text-amber-400"
+ <TypographyControlsRoot v-slot="ctx" :load-font="loadFont">
+ <div data-test-id="typography-section" class="border-b border-border px-3 py-2">
+ <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"
/>
- </Tip>
- </div>
-
- <!-- Weight + Size -->
- <div class="mb-1.5 flex gap-1.5">
- <AppSelect
- :model-value="node.fontWeight"
- :options="WEIGHTS"
- @update:model-value="selectWeight(+$event)"
- />
- <ScrubInput
- class="flex-1"
- :model-value="node.fontSize"
- :min="1"
- :max="1000"
- @update:model-value="updateProp('fontSize', $event)"
- @commit="(v: number, p: number) => commitProp('fontSize', v, p)"
- />
- </div>
-
- <!-- Line height + Letter spacing -->
- <div class="mb-1.5 flex gap-1.5">
- <ScrubInput
- class="flex-1"
- :model-value="node.lineHeight ?? Math.round((node.fontSize || 14) * 1.2)"
- :min="0"
- @update:model-value="updateProp('lineHeight', $event)"
- @commit="(v: number, p: number) => commitProp('lineHeight', v, p)"
- >
- <template #icon>
- <icon-lucide-baseline class="size-3" />
- </template>
- </ScrubInput>
- <ScrubInput
- class="flex-1"
- suffix="%"
- :model-value="node.letterSpacing"
- @update:model-value="updateProp('letterSpacing', $event)"
- @commit="(v: number, p: number) => 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="node.textAlignHorizontal"
- @update:model-value="
- (val: AcceptableValue) => {
- if (val) setAlign(val as TextAlign)
- }
- "
- >
- <ToggleGroupItem
- v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as TextAlign[]"
- :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"
+ <Tip
+ v-if="ctx.hasMissingFonts"
+ :label="
+ 'Missing font' +
+ (ctx.missingFonts.length > 1 ? 's' : '') +
+ ': ' +
+ ctx.missingFonts.join(', ')
+ "
>
- <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="activeFormatting"
- @update:model-value="onFormattingChange"
- >
- <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>
+ <icon-lucide-alert-triangle
+ data-test-id="typography-missing-font"
+ class="size-3.5 shrink-0 text-amber-400"
+ />
</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">
+ </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>
+
+ <!-- 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>
+
+ <!-- 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')
+ }
+ "
+ >
<ToggleGroupItem
- value="strikethrough"
+ 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-strikethrough class="size-3.5" />
+ <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>
- </Tip>
- </ToggleGroupRoot>
+ </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>
</div>
- </div>
+ </TypographyControlsRoot>
</template>