AI-native design editor. Open-source Figma alternative.
fix: show bound variables as neutral chips and steady tooltips (#1052)
Danila Poyarkov20f74f720312
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6fe2fd46d..2782277c5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -115,6 +115,7 @@- Choose an accent color in **Settings → General → Appearance**: one of eight presets or any custom color. Buttons, toggles, selected layers, focus rings, the active tool, and the canvas selection, handles, size labels, and ruler badges follow it in both themes, and text on accent surfaces turns dark when the color is too light for white. The CLI and MCP `settings` commands read and set it as `appearance.accent`.### Changed+- Bound variables show as a neutral chip in the properties panel instead of purple text, so they no longer read as components.- Import SVG as editable layers, as pasting it into Figma does, from `import_svg`, dropped files, and pasted markup ([#734](https://github.com/open-pencil/open-pencil/issues/734)). Each `<g>` becomes a group, each shape its own vector, and each `<text>` a text layer with its fonts, `<tspan>` styles, alignment, and rotation, named after its `id`, element opacity is kept, and clipped content sits in a clip path group whose mask is drawn from the clip's shapes. The imported frame is white, clips its content, and is named after the root `<svg>` `id`; an SVG without a size imports as a group. Shapes are no longer merged into one multi-color vector.- With **Snap to Pixel Grid** on, moved layers and resized edges land on whole pixels at any zoom, and drawn layers start and end on whole pixels, as in Figma; zoomed in, moves and resizes could leave fractions before, and drawing was not snapped.- Layers inside components and instances are outlined in purple when hovered or selected, with a purple size label, as in Figma; they were blue.@@ -163,6 +164,7 @@### Fixed+- Tooltips no longer appear when a popover such as the colour picker focuses its first control on open; they still show for keyboard focus. Moving the pointer along a row of buttons switches tooltips at once instead of blinking out, and tooltips centre on their control instead of sitting a few pixels off.- Polygons and stars draw and export to SVG with their corner radius and smoothing as Figma rounds them, inner star corners included, and copy to and from Figma with their point count and a star's inner ratio; they were drawn with sharp corners, also from `.fig` files, and pasted into Figma as empty shapes.- The font picker opens at the current font instead of the top of the list.- Undo after adding, switching, or removing auto layout, or wrapping layers in it with <kbd>⇧</kbd><kbd>A</kbd>, puts back every layer the layout moved or resized, and the new frame takes the place of the topmost layer it wraps, as in Figma. Setting the layout a frame already has, or aligning layers that auto layout places, no longer records an undo step, and undoing a drag out of an auto layout frame puts the layer back in its slot.diff --git a/bun.lock b/bun.lockindex 130473f90..9fce1c935 100644--- a/bun.lock+++ b/bun.lock@@ -27,6 +27,7 @@"@codemirror/search": "^6.7.2","@codemirror/state": "^6.7.6","@codemirror/view": "^6.43.9",+ "@floating-ui/vue": "^1.1.11","@lezer/highlight": "^1.2.3","@nanostores/i18n": "^1.3.3","@nanostores/vue": "^1.1.0",diff --git a/package.json b/package.jsonindex 8d3803eb3..e45669a1b 100644--- a/package.json+++ b/package.json@@ -124,6 +124,7 @@"@codemirror/search": "^6.7.2","@codemirror/state": "^6.7.6","@codemirror/view": "^6.43.9",+ "@floating-ui/vue": "^1.1.11","@lezer/highlight": "^1.2.3","@nanostores/i18n": "^1.3.3","@nanostores/vue": "^1.1.0",diff --git a/src/components/fill-picker/FillPicker.vue b/src/components/fill-picker/FillPicker.vueindex 0227283ec..a06d690cb 100644--- a/src/components/fill-picker/FillPicker.vue+++ b/src/components/fill-picker/FillPicker.vue@@ -99,6 +99,7 @@ function cancelFromEscape(event: KeyboardEvent) {<button:data-active="root.category === 'SOLID' || undefined":class="tabClass(root.category === 'SOLID')"+ :aria-label="panels.solid"data-test-id="fill-picker-tab-solid"@click="root.actions.toSolid">@@ -109,6 +110,7 @@ function cancelFromEscape(event: KeyboardEvent) {<button:data-active="root.category === 'GRADIENT' || undefined":class="tabClass(root.category === 'GRADIENT')"+ :aria-label="panels.linearGradient"data-test-id="fill-picker-tab-gradient"@click="root.actions.toGradient">@@ -119,6 +121,7 @@ function cancelFromEscape(event: KeyboardEvent) {<button:data-active="root.category === 'IMAGE' || undefined":class="tabClass(root.category === 'IMAGE')"+ :aria-label="panels.image"data-test-id="fill-picker-tab-image"@click="root.actions.toImage">diff --git a/src/components/ui/binding/VariablePicker.vue b/src/components/ui/binding/VariablePicker.vueindex c9b5dc835..da06eb560 100644--- a/src/components/ui/binding/VariablePicker.vue+++ b/src/components/ui/binding/VariablePicker.vue@@ -113,7 +113,7 @@ defineOptions({ inheritAttrs: false })}":ui="{ root: 'size-3.5 shrink-0 rounded-sm' }"/>- <icon-lucide-diamond v-else class="size-3.5 text-component" />+ <icon-lucide-diamond v-else class="size-3.5 text-muted" /></template><template #footer><AppButtondiff --git a/src/components/ui/overlay/Tip.vue b/src/components/ui/overlay/Tip.vueindex d9c1151b5..e6313c926 100644--- a/src/components/ui/overlay/Tip.vue+++ b/src/components/ui/overlay/Tip.vue@@ -1,18 +1,20 @@<script setup lang="ts">-import {- defaultDocument,- defaultWindow,- unrefElement,- useEventListener,- useTimeoutFn-} from '@vueuse/core'+/**+ * A tooltip around any control. It is not Reka's Tooltip: Reka shares one unscoped popper context,+ * so a popover or menu trigger wrapped in a `TooltipRoot` anchors its own content to the tooltip.+ * Positioning comes from floating-ui, which Reka uses as well.+ */+import { autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/vue'+import { defaultDocument, unrefElement, useEventListener, useTimeoutFn } from '@vueuse/core'import { Primitive } from 'reka-ui'import type { ComponentPublicInstance } from 'vue'-import { computed, nextTick, onDeactivated, ref, watch } from 'vue'--import { useRetainedPopup } from '@open-pencil/vue'+import { computed, onDeactivated, ref, shallowRef, watch } from 'vue'-import { useTooltipUI } from '@/components/ui/overlay/tooltip'+import {+ TOOLTIP_SKIP_DELAY_MS,+ useTooltipUI,+ useTooltipWarmth+} from '@/components/ui/overlay/tooltip'import { motionStyles } from '@/theme/motion/styles'const TOOLTIP_OPEN_DELAY_MS = 400@@ -20,9 +22,8 @@ const TOOLTIP_SIDE_OFFSET = 4const TOOLTIP_VIEWPORT_PADDING = 8const TOOLTIP_CLAIM_EVENT = 'open-pencil:tooltip-claim'-type TooltipSide = 'top' | 'bottom' | 'left' | 'right'-const cls = useTooltipUI({ content: motionStyles.popup })+const lastClosedAt = useTooltipWarmth()const {asChild = false,@@ -32,96 +33,54 @@ const {} = defineProps<{asChild?: booleanlabel?: string- side?: TooltipSide+ side?: 'top' | 'bottom' | 'left' | 'right'disabled?: boolean}>()-const triggerRef = ref<HTMLElement>()+const trigger = shallowRef<HTMLElement>()function setTrigger(value: Element | ComponentPublicInstance | null) {const element = value instanceof Element ? value : unrefElement(value)- triggerRef.value = element instanceof HTMLElement ? element : undefined+ trigger.value = element instanceof HTMLElement ? element : undefined}-const contentRef = ref<HTMLElement>()+/** A wrapper is `display: contents`, so the tooltip anchors to the control inside it. */+const anchor = computed(() => {+ const child = asChild ? trigger.value : trigger.value?.firstElementChild+ return child instanceof HTMLElement ? child : trigger.value+})+const content = shallowRef<HTMLElement>()const open = ref(false)-const { portalActive } = useRetainedPopup(open)-const activeWindow = computed(() => (portalActive.value ? defaultWindow : undefined))-const activeDocument = computed(() => (portalActive.value ? defaultDocument : undefined))-const position = ref({ x: 0, y: 0 })--const canOpen = computed(() => Boolean(label) && !disabled)-const contentStyle = computed(() => ({- left: `${position.value.x}px`,- top: `${position.value.y}px`-}))--const { start: startOpenTimer, stop: stopOpenTimer } = useTimeoutFn(+const { floatingStyles } = useFloating(anchor, content, {+ open,+ placement: () => side,+ strategy: 'fixed',+ // Position with left and top: the grow-in animation owns transform.+ transform: false,+ middleware: [+ offset(TOOLTIP_SIDE_OFFSET),+ flip({ padding: TOOLTIP_VIEWPORT_PADDING }),+ shift({ padding: TOOLTIP_VIEWPORT_PADDING })+ ],+ whileElementsMounted: autoUpdate+})++const {+ isPending,+ start: startOpenTimer,+ stop: stopOpenTimer+} = useTimeoutFn(() => {open.value = true- void nextTick(refreshPosition)},TOOLTIP_OPEN_DELAY_MS,{ immediate: false })-function anchorElement() {- const root = triggerRef.value- if (asChild) return root- const child = root?.firstElementChild- return child instanceof HTMLElement ? child : root-}--function clamp(value: number, min: number, max: number) {- return Math.min(Math.max(value, min), max)-}--function refreshPosition() {- if (!open.value) return-- const anchor = anchorElement()- const content = contentRef.value- if (!anchor || !content) return-- const anchorRect = anchor.getBoundingClientRect()- const contentRect = content.getBoundingClientRect()- const centerX = anchorRect.left + anchorRect.width / 2- const centerY = anchorRect.top + anchorRect.height / 2-- let x = centerX - contentRect.width / 2- let y = anchorRect.top - contentRect.height - TOOLTIP_SIDE_OFFSET-- if (side === 'bottom') y = anchorRect.bottom + TOOLTIP_SIDE_OFFSET- if (side === 'left') {- x = anchorRect.left - contentRect.width - TOOLTIP_SIDE_OFFSET- y = centerY - contentRect.height / 2- }- if (side === 'right') {- x = anchorRect.right + TOOLTIP_SIDE_OFFSET- y = centerY - contentRect.height / 2- }-- position.value = {- x: clamp(- x,- TOOLTIP_VIEWPORT_PADDING,- window.innerWidth - contentRect.width - TOOLTIP_VIEWPORT_PADDING- ),- y: clamp(- y,- TOOLTIP_VIEWPORT_PADDING,- window.innerHeight - contentRect.height - TOOLTIP_VIEWPORT_PADDING- )- }-}-function show() {- if (!canOpen.value) return- document.dispatchEvent(- new CustomEvent(TOOLTIP_CLAIM_EVENT, {- detail: triggerRef.value- })- )+ if (!label || disabled) return+ document.dispatchEvent(new CustomEvent(TOOLTIP_CLAIM_EVENT, { detail: trigger.value }))stopOpenTimer()- startOpenTimer()+ if (performance.now() - lastClosedAt.value < TOOLTIP_SKIP_DELAY_MS) open.value = true+ else startOpenTimer()}function hide() {@@ -129,63 +88,61 @@ function hide() {open.value = false}-function isNestedTooltipEvent(event: PointerEvent | FocusEvent) {- const target = event.target- return target instanceof Element && target.closest('[data-tooltip-trigger]') !== triggerRef.value+/** Closes as the pointer or focus moves on, so a neighbouring tooltip opens without the delay. */+function leave() {+ if (open.value) lastClosedAt.value = performance.now()+ hide()+}++/** A tooltip nested inside this one, such as a field's variable button, speaks for itself. */+function isNested(event: Event) {+ return (+ event.target instanceof Element &&+ event.target.closest('[data-tooltip-trigger]') !== trigger.value+ )}-function containsRelatedTarget(event: PointerEvent | FocusEvent) {- const relatedTarget = event.relatedTarget- return relatedTarget instanceof Node && triggerRef.value?.contains(relatedTarget)+function staysInside(event: PointerEvent | FocusEvent) {+ return (+ event.relatedTarget instanceof Node && Boolean(trigger.value?.contains(event.relatedTarget))+ )}function onPointerOver(event: PointerEvent) {- if (isNestedTooltipEvent(event)) {- hide()- return- }- if (containsRelatedTarget(event)) return- show()+ if (isNested(event)) hide()+ else if (!staysInside(event)) show()}function onPointerOut(event: PointerEvent) {- if (containsRelatedTarget(event)) return- hide()+ if (!staysInside(event)) leave()}function onFocusIn(event: FocusEvent) {- if (isNestedTooltipEvent(event)) {- hide()- return- }- if (containsRelatedTarget(event)) return- show()+ if (isNested(event)) hide()+ // Popovers focus their first control on open; only keyboard focus asks for a tooltip.+ else if (+ !staysInside(event) &&+ event.target instanceof Element &&+ event.target.matches(':focus-visible')+ )+ show()}function onFocusOut(event: FocusEvent) {- if (containsRelatedTarget(event)) return- hide()-}--function onPointerDown() {- hide()+ if (!staysInside(event)) leave()}-function onTooltipClaim(event: Event) {- if (!(event instanceof CustomEvent) || event.detail === triggerRef.value) return- hide()-}--useEventListener(activeWindow, 'resize', refreshPosition)-useEventListener(activeWindow, 'scroll', refreshPosition, { capture: true, passive: true })-useEventListener(activeDocument, 'pointerdown', hide, { capture: true })-useEventListener(activeDocument, 'click', hide, { capture: true })-useEventListener(activeDocument, TOOLTIP_CLAIM_EVENT, onTooltipClaim)-onDeactivated(hide)--watch(canOpen, (value) => {- if (!value) hide()+const claimTarget = computed(() => (open.value || isPending.value ? defaultDocument : undefined))+useEventListener(claimTarget, TOOLTIP_CLAIM_EVENT, (event: Event) => {+ if (event instanceof CustomEvent && event.detail !== trigger.value) leave()})+onDeactivated(hide)+watch(+ () => !label || disabled,+ (off) => {+ if (off) hide()+ }+)</script><template>@@ -196,23 +153,22 @@ watch(canOpen, (value) => {data-tooltip-trigger:data-as-child="asChild"class="data-[as-child=false]:contents"- @focusin="onFocusIn"- @focusout="onFocusOut"@pointerover="onPointerOver"@pointerout="onPointerOut"- @pointerdown="onPointerDown"+ @focusin="onFocusIn"+ @focusout="onFocusOut"+ @pointerdown="hide"@click="hide"><slot /></Primitive>- <Teleport v-if="portalActive" to="body">+ <Teleport v-if="open && label" to="body"><div- v-if="open && label"- ref="contentRef"+ ref="content"role="tooltip":class="cls.content"- class="pointer-events-none fixed"- :style="contentStyle"+ class="pointer-events-none"+ :style="floatingStyles">{{ label }}</div>diff --git a/src/components/ui/overlay/tooltip.ts b/src/components/ui/overlay/tooltip.tsindex e137e47f2..d989ccda5 100644--- a/src/components/ui/overlay/tooltip.ts+++ b/src/components/ui/overlay/tooltip.ts@@ -1,4 +1,6 @@+import { createGlobalState } from '@vueuse/core'import { tv } from 'tailwind-variants'+import { shallowRef } from 'vue'import { tooltipSurface } from '@/theme/overlay'@@ -18,3 +20,9 @@ export function useTooltipUI(ui?: TooltipUI) {content: cls.content({ class: ui?.content })}}++/** After one tooltip closes, the next opens at once for this long, as the pointer moves along a row. */+export const TOOLTIP_SKIP_DELAY_MS = 300++/** When a tooltip last closed because the pointer or focus moved on, shared by every tooltip. */+export const useTooltipWarmth = createGlobalState(() => shallowRef(Number.NEGATIVE_INFINITY))diff --git a/src/theme/binding/field.ts b/src/theme/binding/field.tsindex 2211abe62..61c322fbb 100644--- a/src/theme/binding/field.ts+++ b/src/theme/binding/field.ts@@ -1,10 +1,11 @@const bindingFieldTheme = {slots: {root: 'min-w-0',- pill: 'flex min-w-0 flex-1 items-center overflow-hidden rounded-sm px-1 text-component outline-none',+ // A tint of the text colour reads as a chip on the field in both themes.+ pill: 'flex h-[18px] min-w-0 flex-1 items-center overflow-hidden rounded-sm bg-surface/10 px-1 text-surface outline-none',pillLabel: 'min-w-0 flex-1 truncate text-[11px] font-medium',trigger:- 'flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border border-transparent bg-transparent text-muted outline-none transition-colors hover:text-surface focus-visible:border-panel-focus data-[open]:bg-hover data-[open]:text-component disabled:opacity-0 data-[disabled]:opacity-0',+ 'flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border border-transparent bg-transparent text-muted outline-none transition-colors hover:text-surface focus-visible:border-panel-focus data-[open]:bg-hover data-[open]:text-surface disabled:opacity-0 data-[disabled]:opacity-0',createForm: 'flex items-center gap-1.5 p-1',createInput:'h-6 min-w-0 flex-1 rounded border border-transparent bg-panel-field px-2 text-[11px] text-surface outline-none placeholder:text-muted focus:border-panel-focus'@@ -13,27 +14,27 @@ const bindingFieldTheme = {state: {unbound: {},bound: {- trigger: 'text-component opacity-100'+ trigger: 'text-surface opacity-100'},- unresolved: { trigger: 'text-error opacity-100', pill: 'text-error' },+ unresolved: { trigger: 'text-error opacity-100', pill: 'bg-error-bg text-error' },mixed: {}},open: {true: {- trigger: 'bg-hover text-component opacity-100'+ trigger: 'bg-hover text-surface opacity-100'},false: {}},disabled: {true: {- pill: 'text-muted opacity-60',+ pill: 'bg-surface/5 text-muted opacity-60',trigger: 'pointer-events-none opacity-0'},false: {}},derived: {true: {- pill: 'text-muted'+ pill: 'bg-surface/5 text-muted'},false: {}}diff --git a/src/theme/panel/field.ts b/src/theme/panel/field.tsindex fdf48559e..7a68534ae 100644--- a/src/theme/panel/field.ts+++ b/src/theme/panel/field.ts@@ -4,7 +4,7 @@ export const panelFieldBase =export const panelFieldState = {idle: '',mixed: 'text-muted placeholder:text-muted',- bound: 'text-component',+ bound: 'text-surface',invalid: 'border-error focus:border-error focus-visible:border-error'} as constdiff --git a/tests/e2e/properties/panel.spec.ts b/tests/e2e/properties/panel.spec.tsindex 6d6f464d1..178050b4f 100644--- a/tests/e2e/properties/panel.spec.ts+++ b/tests/e2e/properties/panel.spec.ts@@ -160,6 +160,54 @@ test('independent corners toggle shows four corner inputs', async () => {editor.canvas.assertNoErrors()})+test('moving to a neighbouring control shows its tooltip without the delay', async () => {+ await editor.canvas.clearCanvas()+ await editor.canvas.drawRect(200, 200, 80, 80)++ const fillItem = propertyItems(editor.page, 'fills').first()+ const tooltips = editor.page.getByRole('tooltip')+ await expect(fillItem).toBeVisible()+ await editor.page.clock.install()+ await editor.page.clock.pauseAt(Date.now() + 1_000)++ await fillItem.getByRole('button', { name: 'Toggle visibility' }).hover()+ await editor.page.clock.runFor(500)+ await expect(tooltips).toHaveText('Toggle visibility')++ await fillItem.getByRole('button', { name: 'Remove fill' }).hover()+ await editor.page.clock.runFor(50)+ await expect(tooltips).toHaveText('Remove fill')++ await editor.page.mouse.move(500, 400)+ await editor.page.clock.runFor(1_000)+ await fillItem.getByRole('button', { name: 'Toggle visibility' }).hover()+ await editor.page.clock.runFor(50)+ await expect(tooltips).toHaveCount(0)+ await editor.page.clock.resume()+})++test('a picker focusing its first control on open shows no tooltip until keyboard focus', async () => {+ await editor.canvas.clearCanvas()+ await editor.canvas.drawRect(200, 200, 80, 80)++ const fillSwatch = propertyItems(editor.page, 'fills').first().getByTestId('fill-picker-swatch')+ await expect(fillSwatch).toBeVisible()+ await editor.page.clock.install()+ await editor.page.clock.pauseAt(Date.now() + 1_000)++ await fillSwatch.click()+ await expect(editor.page.getByTestId('fill-picker-tab-solid')).toBeFocused()+ await editor.page.clock.runFor(1_000)+ await expect(editor.page.getByRole('tooltip')).toHaveCount(0)++ await editor.page.keyboard.press('Tab')+ await expect(editor.page.getByTestId('fill-picker-tab-gradient')).toBeFocused()+ await editor.page.clock.runFor(1_000)+ await expect(editor.page.getByRole('tooltip')).toHaveText('Linear')+ await editor.page.keyboard.press('Escape')+ await editor.page.clock.resume()+})+test('fill gradient switch changes fill type', async () => {await editor.canvas.clearCanvas()await editor.canvas.pressKey('Escape')