Skip to content

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

feat: open boards on the canvas alone, with floating chat and layer controls (#1629)

Danila Poyarkovcd5fe5d6b04c
diff --git a/changes/1629/added.md b/changes/1629/added.md
new file mode 100644
index 000000000..6fa218ea0
--- /dev/null
+++ b/changes/1629/added.md
@@ -0,0 +1 @@
+- Boards open on the canvas and their tools alone, as FigJam shows them, with no rulers, the panels a click away, and the AI chat floating over the canvas; while the panels are hidden, every selection gets FigJam's selection toolbar, with colour, outline, text, alignment and wrap-in-section menus for sticky notes, shapes, connectors, text, sections and other layers.
diff --git a/changes/1629/breaking.md b/changes/1629/breaking.md
new file mode 100644
index 000000000..95c63fc06
--- /dev/null
+++ b/changes/1629/breaking.md
@@ -0,0 +1 @@
+- `useCanvasVirtualReference` from `@open-pencil/vue/canvas/overlays` takes the view to project through (`{ zoom, panX, panY }`, as a ref or getter) instead of the editor; pass `() => editor.state` for the previous behaviour.
diff --git a/changes/1629/fixed.md b/changes/1629/fixed.md
new file mode 100644
index 000000000..26b592f44
--- /dev/null
+++ b/changes/1629/fixed.md
@@ -0,0 +1 @@
+- A Shift or ratio-locked resize and scaling a sticky note now snap the dragged edge to other layers and to the pixel grid, or a board's 16-unit grid, as Figma does.
diff --git a/packages/core/src/editor/bridges/structure.ts b/packages/core/src/editor/bridges/structure.ts
index 14adba6ba..97ea618a2 100644
--- a/packages/core/src/editor/bridges/structure.ts
+++ b/packages/core/src/editor/bridges/structure.ts
@@ -10,6 +10,9 @@ export function createStructureBridge(structure: StructureActions, selection: Se
wrapInAutoLayout: () => structure.wrapInAutoLayout(selection.getSelectedNodes()),
groupSelected: () => structure.groupSelected(selection.getSelectedNodes()),
frameSelection: () => structure.frameSelection(selection.getSelectedNodes()),
+ /** Wraps the selection in a new section with room around it, as FigJam's toolbar does. */
+ wrapSelectionInSection: () => structure.wrapInSection(selection.getSelectedNodes()),
+ canWrapSelectionInSection: () => structure.canWrapInSection(selection.getSelectedNodes()),
booleanOperationSelected: (operation: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE') =>
structure.booleanOperationSelected(selection.getSelectedNodes(), operation),
flattenSelected: () => structure.flattenSelected(selection.getSelectedNodes()),
diff --git a/packages/core/src/editor/create.ts b/packages/core/src/editor/create.ts
index 4fc77de9a..ca956f08a 100644
--- a/packages/core/src/editor/create.ts
+++ b/packages/core/src/editor/create.ts
@@ -42,6 +42,7 @@ import { createConnectorStyleActions } from './connectors/style'
import { createDesignTokenActions } from './design-tokens'
import { createDocumentSettingsActions } from './document-settings'
import { createFigCompressionActions } from './fig-compression'
+import { createFigJamColorActions } from './figjam/colors'
import { createGraphEventSubscription } from './graph-events'
import { createGraphReadActions } from './graph-reads'
import { createGuideActions } from './guides'
@@ -63,7 +64,7 @@ import { createStructureActions } from './structure'
import { createTextActions } from './text'
import { createPendingTextLayout } from './text/pending-layout'
import { createTextSelectionStyle } from './text/selection-style'
-import { createGeneratedTextActions } from './text/typeface'
+import { createFigJamTextActions } from './text/typeface'
import type {
EditorContext,
EditorEventName,
@@ -310,7 +311,8 @@ export function createEditor(options?: EditorOptions) {
const icons = createIconActions(ctx)
const stickies = createStickyActions(ctx, nodes)
const shapesWithText = createShapeWithTextActions(ctx, nodes)
- const generatedText = createGeneratedTextActions(ctx, nodes)
+ const figJamText = createFigJamTextActions(ctx, nodes, { ...stickies, ...shapesWithText })
+ const figJamColors = createFigJamColorActions(ctx, nodes)
const statuses = createStatusActions(ctx)
const figCompression = createFigCompressionActions(ctx)
createConnectorRouting(ctx)
@@ -496,7 +498,8 @@ export function createEditor(options?: EditorOptions) {
...icons,
...stickies,
...shapesWithText,
- ...generatedText,
+ ...figJamText,
+ ...figJamColors,
statusWorkflow: statuses.statusWorkflow,
getShownStatus: statuses.getShownStatus,
setStatus: statuses.setStatus,
diff --git a/packages/core/src/editor/figjam/colors.ts b/packages/core/src/editor/figjam/colors.ts
new file mode 100644
index 000000000..8bdb7fa53
--- /dev/null
+++ b/packages/core/src/editor/figjam/colors.ts
@@ -0,0 +1,98 @@
+import type { SceneNode } from '@open-pencil/scene-graph'
+import {
+ figJamLayerColorFields,
+ figJamLineColorFields,
+ figJamLineStyleFields,
+ figJamSectionColorFields,
+ figJamSectionColorName,
+ type FigJamColorName,
+ type FigJamLineStyle
+} from '@open-pencil/scene-graph/figjam'
+import { isGeneratedFrame } from '@open-pencil/scene-graph/generated'
+
+import { recordSubtreeEdit } from '#core/editor/components/slots/history'
+import { showsImage } from '#core/editor/figjam/toolbar'
+import type { NodeActions } from '#core/editor/nodes'
+import type { EditorContext } from '#core/editor/types'
+
+/**
+ * FigJam's colour and line menus for the layers that have no menu of their own: sections, text,
+ * and plain shapes, lines, frames and groups. Sticky notes, shapes with text and connectors keep
+ * their own commands.
+ */
+export function createFigJamColorActions(ctx: EditorContext, nodes: NodeActions) {
+ function layersAmong(ids: Iterable<string>, accepts: (node: SceneNode) => boolean) {
+ return [...ids].flatMap((id) => {
+ const node = ctx.graph.getNode(id)
+ return node && accepts(node) ? [node] : []
+ })
+ }
+
+ function edit(label: string, layers: SceneNode[], change: (layer: SceneNode) => void) {
+ if (layers.length === 0) return
+ recordSubtreeEdit(
+ ctx,
+ label,
+ layers.map((layer) => layer.id),
+ () => layers.forEach(change)
+ )
+ }
+
+ /** The layers a colour lands on: a group's contents, as FigJam colours a group. */
+ function painted(layer: SceneNode): SceneNode[] {
+ if (layer.type !== 'GROUP') return [layer]
+ return ctx.graph.getChildren(layer.id).flatMap(painted)
+ }
+
+ /**
+ * Paints the sections and plain layers among `ids` in palette colour `name`, as FigJam's colour
+ * menu does: a section takes a pale tint outlined in the colour, other layers the colour itself.
+ */
+ function setFigJamColor(ids: Iterable<string>, name: FigJamColorName) {
+ const layers = layersAmong(ids, (node) => !isGeneratedFrame(node))
+ edit('Change color', layers, (layer) => {
+ if (layer.type === 'SECTION') {
+ nodes.updateNode(layer.id, figJamSectionColorFields(layer, name))
+ return
+ }
+ // An image in a group keeps its picture, as a lone image has no colour menu.
+ for (const target of painted(layer)) {
+ if (!isGeneratedFrame(target) && !showsImage(target))
+ nodes.updateNode(target.id, figJamLayerColorFields(target, name))
+ }
+ })
+ }
+
+ const isSection = (node: SceneNode) => node.type === 'SECTION'
+
+ /** Gives a section without an outline the one its colour pairs with, so a line menu has one. */
+ function outlined(section: SceneNode): SceneNode {
+ if (section.strokes.length > 0) return section
+ const fields = figJamSectionColorFields(section, figJamSectionColorName(section) ?? 'white')
+ return { ...section, strokes: fields.strokes ?? [], strokeWeight: fields.strokeWeight ?? 0 }
+ }
+
+ /** Draws the sections' outlines solid, dashed, or not at all, as FigJam's line menu does. */
+ function setSectionLineStyle(ids: Iterable<string>, style: FigJamLineStyle) {
+ edit('Change section line', layersAmong(ids, isSection), (section) => {
+ const current = outlined(section)
+ nodes.updateNode(section.id, {
+ strokeWeight: current.strokeWeight,
+ ...figJamLineStyleFields(current, style)
+ })
+ })
+ }
+
+ /** Colours the sections' outlines in palette colour `name`. */
+ function setSectionLineColor(ids: Iterable<string>, name: FigJamColorName) {
+ edit('Change section line color', layersAmong(ids, isSection), (section) => {
+ const current = outlined(section)
+ nodes.updateNode(section.id, {
+ strokeWeight: current.strokeWeight,
+ ...figJamLineColorFields(current, name)
+ })
+ })
+ }
+
+ return { setFigJamColor, setSectionLineStyle, setSectionLineColor }
+}
diff --git a/packages/core/src/editor/figjam/toolbar.ts b/packages/core/src/editor/figjam/toolbar.ts
new file mode 100644
index 000000000..7f0805c8b
--- /dev/null
+++ b/packages/core/src/editor/figjam/toolbar.ts
@@ -0,0 +1,62 @@
+import type { NodeType, SceneNode } from '@open-pencil/scene-graph'
+
+/**
+ * Which of FigJam's selection toolbars a selection gets: one per kind of layer, a text toolbar for
+ * text with sticky notes, and only arranging for any other mix.
+ */
+export type FigJamToolbarKind =
+ | 'sticky'
+ | 'shape'
+ | 'connector'
+ | 'text'
+ | 'section'
+ | 'group'
+ | 'image'
+ | 'layer'
+ | 'mixed'
+
+/** Layers FigJam's colour menu paints as plain layers: one colour as fill, and for most a stroke. */
+const PLAIN_LAYERS: ReadonlySet<NodeType> = new Set([
+ 'RECTANGLE',
+ 'ROUNDED_RECTANGLE',
+ 'ELLIPSE',
+ 'POLYGON',
+ 'STAR',
+ 'LINE',
+ 'VECTOR',
+ 'FRAME',
+ 'BOOLEAN_OPERATION'
+])
+
+const KIND_BY_TYPE: Partial<Record<NodeType, FigJamToolbarKind>> = {
+ STICKY: 'sticky',
+ SHAPE_WITH_TEXT: 'shape',
+ CONNECTOR: 'connector',
+ TEXT: 'text',
+ SECTION: 'section',
+ GROUP: 'group'
+}
+
+/** Whether a layer shows an image, which FigJam's colour menu leaves alone. */
+export function showsImage(node: Pick<SceneNode, 'fills'>): boolean {
+ return node.fills.some((fill) => fill.type === 'IMAGE' && fill.visible)
+}
+
+function layerKind(node: Pick<SceneNode, 'type' | 'fills'>): FigJamToolbarKind {
+ // A section or text keeps its own menus whatever it is filled with.
+ const kind = KIND_BY_TYPE[node.type]
+ if (kind) return kind
+ if (showsImage(node)) return 'image'
+ return PLAIN_LAYERS.has(node.type) ? 'layer' : 'mixed'
+}
+
+/** The toolbar FigJam gives a selection, measured in FigJam; `null` for none selected. */
+export function figJamToolbarKind(
+ layers: readonly Pick<SceneNode, 'type' | 'fills'>[]
+): FigJamToolbarKind | null {
+ const kinds = new Set(layers.map(layerKind))
+ if (kinds.size === 0) return null
+ if (kinds.size === 1) return [...kinds][0] ?? null
+ // Text and sticky notes share their text menus; any other mix only arranges.
+ return [...kinds].every((kind) => kind === 'text' || kind === 'sticky') ? 'text' : 'mixed'
+}
diff --git a/packages/core/src/editor/index.ts b/packages/core/src/editor/index.ts
index 4ce156f7c..70cee2053 100644
--- a/packages/core/src/editor/index.ts
+++ b/packages/core/src/editor/index.ts
@@ -9,6 +9,7 @@ export { DEFAULT_SNAPPING_PREFERENCES } from './preferences'
export type { SnappingPreferences } from './preferences'
export { createDocumentGraph } from './document-settings'
export { gridNudge } from './nudge'
+export { figJamToolbarKind, type FigJamToolbarKind } from './figjam/toolbar'
export { createDefaultEditorSharedState } from './state/shared'
export { editedGradient, editedGradientLayout } from './gradient-edit'
export type { SelectionSpacing } from './alignment'
diff --git a/packages/core/src/editor/shapes.ts b/packages/core/src/editor/shapes.ts
index 417e1e05c..c9d6d7bdd 100644
--- a/packages/core/src/editor/shapes.ts
+++ b/packages/core/src/editor/shapes.ts
@@ -4,7 +4,7 @@ import { createShapeWithText } from '@open-pencil/scene-graph/generated'
import { prepareSlotEdits } from './components/slots'
import { restoreSubtree, snapshotSubtree } from './history/subtree'
import { adoptCoveredLayers } from './shapes/adopt'
-import { newLayerDefaults } from './shapes/defaults'
+import { layerTheme, newLayerDefaults } from './shapes/defaults'
import { createFramePresetActions } from './shapes/frame-presets'
import { createPenActions, type UpdateNodeWithUndo } from './shapes/pen'
import { createPencilActions } from './shapes/pencil'
@@ -44,7 +44,7 @@ export function createShapeActions(ctx: EditorContext, updateNodeWithUndo: Updat
throw new Error('Cannot add a layer to the locked part of an instance')
}
const overrides: Partial<SceneNode> = {
- ...newLayerDefaults(type, ctx.state.theme),
+ ...newLayerDefaults(type, layerTheme(ctx.state)),
x,
y,
width: w,
diff --git a/packages/core/src/editor/shapes/defaults.ts b/packages/core/src/editor/shapes/defaults.ts
index 3cebb28f9..8d97a16df 100644
--- a/packages/core/src/editor/shapes/defaults.ts
+++ b/packages/core/src/editor/shapes/defaults.ts
@@ -13,6 +13,14 @@ import {
SECTION_DEFAULT_STROKE,
type InterfaceTheme
} from '#core/constants'
+import type { EditorState } from '#core/editor/types'
+
+/** The theme a document's new layers are painted for: a FigJam board is always light. */
+export function layerTheme(
+ state: Pick<EditorState, 'documentKind' | 'theme'>
+): InterfaceTheme | undefined {
+ return state.documentKind === 'board' ? 'light' : state.theme
+}
const BLACK_FILL: Fill = { type: 'SOLID', color: BLACK, opacity: 1, visible: true }
const BLACK_STROKE: Stroke = { ...BLACK_FILL, weight: DEFAULT_STROKE_WEIGHT, align: 'CENTER' }
diff --git a/packages/core/src/editor/structure.ts b/packages/core/src/editor/structure.ts
index f3c27646a..f7ced23a1 100644
--- a/packages/core/src/editor/structure.ts
+++ b/packages/core/src/editor/structure.ts
@@ -8,12 +8,16 @@ import { createsComponentCycle } from '@open-pencil/scene-graph/instances'
import { acceptingParent, acceptsChildren, prepareSlotEdits } from '#core/editor/components/slots'
import { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'
+import { layerTheme, newLayerDefaults } from './shapes/defaults'
import { wrapInAutoLayout as wrapInAutoLayoutImpl } from './structure/auto-layout-wrap'
import {
booleanOperationSelected as booleanOperationSelectedImpl,
type BooleanOperation
} from './structure/boolean'
-import { wrapSelectionInContainer as wrapSelectionInContainerImpl } from './structure/container-wrap'
+import {
+ sharedParentId,
+ wrapSelectionInContainer as wrapSelectionInContainerImpl
+} from './structure/container-wrap'
import { flattenSelected as flattenSelectedImpl } from './structure/flatten'
import { ungroupSelected as ungroupImpl } from './structure/group/ungroup'
import { createLayerTypeActions } from './structure/layer-type'
@@ -83,6 +87,30 @@ export function createStructureActions(ctx: EditorContext) {
return wrapSelectionInContainer('FRAME', selectedNodes)
}
+ /**
+ * Whether layers can go in a new section: siblings on a page or in a section, where sections
+ * live. Toolbars ask while they draw, so it reads the parent without claiming anything.
+ */
+ function canWrapInSection(selectedNodes: SceneNode[]) {
+ const parentId = sharedParentId(ctx, selectedNodes)
+ const parent = parentId ? ctx.graph.getNode(parentId) : undefined
+ return parent?.type === 'CANVAS' || parent?.type === 'SECTION'
+ }
+
+ /**
+ * Wraps layers in a new section with room around them, as FigJam's selection toolbar does,
+ * painted as a drawn section is.
+ */
+ function wrapInSection(selectedNodes: SceneNode[]) {
+ if (!canWrapInSection(selectedNodes)) return null
+ return wrapSelectionInContainerImpl(
+ ctx,
+ 'SECTION',
+ selectedNodes,
+ newLayerDefaults('SECTION', layerTheme(ctx.state))
+ )
+ }
+
function booleanOperationSelected(selectedNodes: SceneNode[], operation: BooleanOperation) {
return booleanOperationSelectedImpl(ctx, selectedNodes, operation)
}
@@ -196,6 +224,8 @@ export function createStructureActions(ctx: EditorContext) {
wrapInAutoLayout,
groupSelected,
frameSelection,
+ canWrapInSection,
+ wrapInSection,
...layerTypeActions,
booleanOperationSelected,
ungroupSelected,
diff --git a/packages/core/src/editor/structure/container-wrap.ts b/packages/core/src/editor/structure/container-wrap.ts
index 4e0e94174..b34660adf 100644
--- a/packages/core/src/editor/structure/container-wrap.ts
+++ b/packages/core/src/editor/structure/container-wrap.ts
@@ -12,31 +12,44 @@ export type WrapContainerType =
| 'COMPONENT'
| 'COMPONENT_SET'
| 'BOOLEAN_OPERATION'
+ | 'SECTION'
const CONTAINER_NAMES: Record<WrapContainerType, string> = {
BOOLEAN_OPERATION: 'Boolean',
COMPONENT_SET: 'Component Set',
COMPONENT: 'Component',
GROUP: 'Group',
- FRAME: 'Frame'
+ FRAME: 'Frame',
+ SECTION: 'Section'
}
const NUMBERED_WHEN_WRAPPED: ReadonlySet<WrapContainerType> = new Set([
'GROUP',
'FRAME',
- 'COMPONENT'
+ 'COMPONENT',
+ 'SECTION'
])
+/** The room FigJam leaves around layers it wraps in a new section, in canvas units. */
+const SECTION_WRAP_PADDING = 48
+
+/** The parent these layers share, or null when they are not siblings; it changes nothing. */
+export function sharedParentId(ctx: EditorContext, nodes: readonly SceneNode[]): string | null {
+ const first = nodes.at(0)
+ if (!first) return null
+ const parentId = first.parentId ?? ctx.state.currentPageId
+ return nodes.every((node) => (node.parentId ?? ctx.state.currentPageId) === parentId)
+ ? parentId
+ : null
+}
+
/**
* The parent these layers share when a new container may go there, or null when they are not
- * siblings or sit in the locked part of an instance.
+ * siblings or sit in the locked part of an instance; an instance slot there is claimed for edits.
*/
export function wrapParentId(ctx: EditorContext, nodes: readonly SceneNode[]): string | null {
- const first = nodes.at(0)
- if (!first) return null
- const parentId = first.parentId ?? ctx.state.currentPageId
- if (nodes.some((node) => (node.parentId ?? ctx.state.currentPageId) !== parentId)) return null
- return prepareSlotEdits(ctx, [parentId]) ? parentId : null
+ const parentId = sharedParentId(ctx, nodes)
+ return parentId && prepareSlotEdits(ctx, [parentId]) ? parentId : null
}
/**
@@ -53,11 +66,19 @@ export function wrapNodes(
index: number | undefined,
props: Partial<SceneNode> = {}
): SceneNode {
- // A group spans only the layers it shows, as Figma's does; other containers span them all.
- const bounds =
+ // A group spans only the layers it shows, as Figma's does; other containers span them all, and
+ // a section leaves FigJam's room around them.
+ const spanned =
type === 'GROUP'
? groupBounds(graph, inStackOrder(graph, nodes, parentId), parentId, { x: 0, y: 0 })
: getAxisAlignedBoundsInParent(nodes, parentId, graph)
+ const pad = type === 'SECTION' ? SECTION_WRAP_PADDING : 0
+ const bounds = {
+ x: spanned.x - pad,
+ y: spanned.y - pad,
+ width: spanned.width + pad * 2,
+ height: spanned.height + pad * 2
+ }
const container = graph.createNode(type, parentId, {
name: CONTAINER_NAMES[type],
...bounds,
diff --git a/packages/core/src/editor/text/typeface.ts b/packages/core/src/editor/text/typeface.ts
index fdc5e26eb..73ee13c75 100644
--- a/packages/core/src/editor/text/typeface.ts
+++ b/packages/core/src/editor/text/typeface.ts
@@ -1,6 +1,11 @@
+import type { SceneNode } from '@open-pencil/scene-graph'
import {
FIGJAM_TYPEFACES,
- figJamTypefaceFields,
+ figJamTextSizeFields,
+ figJamTextSize,
+ figJamTypeface,
+ figJamTypefaceFaceFields,
+ type FigJamTextSize,
type FigJamTypeface
} from '@open-pencil/scene-graph/figjam'
import { faceLoadKey } from '@open-pencil/scene-graph/font-style'
@@ -9,33 +14,88 @@ import { generatedFrameText } from '@open-pencil/scene-graph/generated'
import { recordSubtreeEdit } from '#core/editor/components/slots/history'
import type { NodeActions } from '#core/editor/nodes'
import type { EditorContext } from '#core/editor/types'
+import { textStyleChanges } from '#core/text/character-style'
+
+/** How sticky notes and shapes take a FigJam size: each fits itself to its text as it does. */
+interface GeneratedTextSizes {
+ setStickyTextSize: (ids: Iterable<string>, size: FigJamTextSize) => void
+ setShapesWithTextTextSize: (ids: Iterable<string>, size: FigJamTextSize) => void
+}
+
+/**
+ * FigJam's typefaces and text sizes for text layers and for the text generated frames are named
+ * by, such as a sticky note's body or a shape's label, in any mix of them.
+ */
+export function createFigJamTextActions(
+ ctx: EditorContext,
+ nodes: NodeActions,
+ generated: GeneratedTextSizes
+) {
+ /** The layers among `ids` FigJam's text menus change, with the text each one sets. */
+ function textsAmong(ids: Iterable<string>) {
+ return [...ids].flatMap((id) => {
+ const layer = ctx.graph.getNode(id)
+ if (!layer) return []
+ const text = layer.type === 'TEXT' ? layer : generatedFrameText(ctx.graph, layer)
+ return text ? [{ layer, text }] : []
+ })
+ }
+
+ function edit(
+ label: string,
+ targets: { layer: SceneNode; text: SceneNode }[],
+ change: (text: SceneNode) => void
+ ) {
+ if (targets.length === 0) return
+ recordSubtreeEdit(
+ ctx,
+ label,
+ targets.map(({ layer }) => layer.id),
+ () => targets.forEach(({ text }) => change(text))
+ )
+ }
-/** Typefaces for the text generated frames are named by, such as a sticky note's body or a shape's label. */
-export function createGeneratedTextActions(ctx: EditorContext, nodes: NodeActions) {
/**
- * Sets the text that sticky notes and shapes among `ids` are named by in one of FigJam's
- * typefaces, once its face is loaded.
+ * Sets the text layers among `ids`, and the text sticky notes and shapes among them are named
+ * by, in one of FigJam's typefaces, once its face is loaded.
*/
- async function setGeneratedTextTypeface(ids: Iterable<string>, typeface: FigJamTypeface) {
+ async function setFigJamTypeface(ids: Iterable<string>, typeface: FigJamTypeface) {
const { fontFamily, fontWeight } = FIGJAM_TYPEFACES[typeface]
+ const graph = ctx.graph
await ctx.loadFont(fontFamily, faceLoadKey(fontWeight, false))
- const frames = [...ids].flatMap((id) => {
- const node = ctx.graph.getNode(id)
- return node && generatedFrameText(ctx.graph, node) ? [node] : []
- })
- if (frames.length === 0) return
- recordSubtreeEdit(
- ctx,
- 'Change typeface',
- frames.map((frame) => frame.id),
- () => {
- for (const frame of frames) {
- const text = generatedFrameText(ctx.graph, frame)
- if (text) nodes.updateNode(text.id, figJamTypefaceFields(typeface, text))
- }
- }
+ // Another document opened while the face loaded: these ids are not its layers.
+ if (ctx.graph !== graph) return
+ // The face replaces any a range keeps; ranges keep their own sizes, as the size menu sets those.
+ edit('Change typeface', textsAmong(ids), (text) =>
+ nodes.updateNode(text.id, {
+ ...textStyleChanges(text, figJamTypefaceFaceFields(typeface)),
+ ...figJamTextSizeFields(figJamTextSize(text), typeface)
+ })
)
}
- return { setGeneratedTextTypeface }
+ /**
+ * Sets the text of the layers among `ids` to one of FigJam's sizes, in its typeface, in one undo
+ * step: text layers directly, and sticky notes and shapes as their own commands size them.
+ */
+ function setFigJamTextSize(ids: Iterable<string>, size: FigJamTextSize) {
+ const targets = textsAmong(ids)
+ const idsOf = (type: SceneNode['type']) =>
+ targets.filter(({ layer }) => layer.type === type).map(({ layer }) => layer.id)
+ ctx.undo.runBatch('Change text size', () => {
+ edit(
+ 'Change text size',
+ targets.filter(({ layer }) => layer.type === 'TEXT'),
+ (text) =>
+ nodes.updateNode(
+ text.id,
+ textStyleChanges(text, figJamTextSizeFields(size, figJamTypeface(text) ?? 'simple'))
+ )
+ )
+ generated.setStickyTextSize(idsOf('STICKY'), size)
+ generated.setShapesWithTextTextSize(idsOf('SHAPE_WITH_TEXT'), size)
+ })
+ }
+
+ return { setFigJamTypeface, setFigJamTextSize }
}
diff --git a/packages/core/src/editor/views/profile.ts b/packages/core/src/editor/views/profile.ts
index b38d79658..d2f26ec5f 100644
--- a/packages/core/src/editor/views/profile.ts
+++ b/packages/core/src/editor/views/profile.ts
@@ -14,7 +14,16 @@ export const READ_ONLY_TOOLS: ReadonlySet<Tool> = new Set<Tool>(['SELECT', 'HAND
/** What the document's kind decides: its tools and keys, its grids, and how deep a click goes. */
type DocumentBehaviour = Pick<
EditorProfile,
- 'edits' | 'tools' | 'toolKeys' | 'snapGrid' | 'dotGrid' | 'pixelGrid' | 'framesOpen' | 'lint'
+ | 'edits'
+ | 'tools'
+ | 'toolKeys'
+ | 'snapGrid'
+ | 'dotGrid'
+ | 'pixelGrid'
+ | 'framesOpen'
+ | 'lint'
+ | 'rulers'
+ | 'panelsOpen'
>
/** What the canvas's view decides: how the pointer, keys, chrome, and panels behave. */
@@ -29,7 +38,9 @@ const DOCUMENT_BEHAVIOURS: Readonly<Record<DocumentKind, DocumentBehaviour>> = {
dotGrid: null,
pixelGrid: true,
framesOpen: true,
- lint: true
+ lint: true,
+ rulers: true,
+ panelsOpen: true
},
board: {
edits: true,
@@ -39,7 +50,9 @@ const DOCUMENT_BEHAVIOURS: Readonly<Record<DocumentKind, DocumentBehaviour>> = {
dotGrid: BOARD_GRID,
pixelGrid: false,
framesOpen: false,
- lint: false
+ lint: false,
+ rulers: false,
+ panelsOpen: false
}
}
diff --git a/packages/core/src/editor/views/types.ts b/packages/core/src/editor/views/types.ts
index c78877586..7eb2045b7 100644
--- a/packages/core/src/editor/views/types.ts
+++ b/packages/core/src/editor/views/types.ts
@@ -61,6 +61,13 @@ export interface EditorProfile {
framesOpen: boolean
/** Whether design lint checks the document; a FigJam board has none. */
lint: boolean
+ /** Whether the canvas shows rulers, from which guides are dragged; a FigJam board has none. */
+ rulers: boolean
+ /**
+ * Whether the side panels start open: a design's do, while a board starts on the canvas alone,
+ * as FigJam shows it, with the panels a click away.
+ */
+ panelsOpen: boolean
}
/** The state a profile resolves from: the document's kind, the pane's view, and the host's limits. */
diff --git a/packages/core/src/figma-api/index.ts b/packages/core/src/figma-api/index.ts
index 20f56ad62..f5bab7a81 100644
--- a/packages/core/src/figma-api/index.ts
+++ b/packages/core/src/figma-api/index.ts
@@ -10,7 +10,7 @@ import type { SkiaRenderer } from '#core/canvas'
import { groupFitOptions } from '#core/canvas/boolean'
import { IS_BROWSER, type InterfaceTheme } from '#core/constants'
import { invalidateBooleanAncestors } from '#core/editor/graph-events'
-import { newLayerDefaults } from '#core/editor/shapes/defaults'
+import { layerTheme, newLayerDefaults } from '#core/editor/shapes/defaults'
import { booleanOperationPaints, createBooleanOperation } from '#core/editor/structure/boolean'
import { wrapNodes } from '#core/editor/structure/container-wrap'
import { ungroupNode } from '#core/editor/structure/group/ungroup'
@@ -233,7 +233,9 @@ export class FigmaAPI implements NodeProxyHost {
/** New layers start as the editor's tools make them, which is how Figma's plugin API makes them. */
private _createNode(type: NodeType): FigmaNodeProxy {
- const defaults = newLayerDefaults(type, this.theme)
+ // A board's new sections are light under any interface theme, as the editor makes them.
+ const theme = layerTheme({ documentKind: this.graph.documentKind, theme: this.theme })
+ const defaults = newLayerDefaults(type, theme)
// Figma's plugin API makes a line with no height, a 496 px section, and a hugging frame.
if (type === 'LINE') defaults.height = 0
if (type === 'SECTION') Object.assign(defaults, { width: 496, height: 496 })
diff --git a/packages/core/tests/editor/figjam/colors.test.ts b/packages/core/tests/editor/figjam/colors.test.ts
new file mode 100644
index 000000000..71446b778
--- /dev/null
+++ b/packages/core/tests/editor/figjam/colors.test.ts
@@ -0,0 +1,67 @@
+import { describe, expect, test } from 'bun:test'
+
+import { expectDefined } from '#core-tests/helpers/assert'
+
+import { createEditor } from '@open-pencil/core'
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { createSticky } from '@open-pencil/scene-graph/generated'
+
+function setup() {
+ const editor = createEditor({ loadFont: () => Promise.resolve(null) })
+ return { editor, pageId: editor.state.currentPageId }
+}
+
+const hex = (paint: { color: { r: number; g: number; b: number } } | undefined) =>
+ paint ? colorToHex({ ...paint.color, a: 1 }).toLowerCase() : undefined
+
+describe("FigJam's colour menu", () => {
+ test('tints a section, paints a rectangle and text, and is one undo step', () => {
+ const { editor, pageId } = setup()
+ const section = editor.createShape('SECTION', 0, 0, 400, 300, pageId)
+ const rect = editor.createShape('RECTANGLE', 500, 0, 100, 100, pageId)
+ const text = editor.createShape('TEXT', 700, 0, 100, 20, pageId)
+ editor.setFigJamColor([section, rect, text], 'red')
+ const get = (id: string) => expectDefined(editor.graph.getNode(id))
+ expect([hex(get(section).fills[0]), hex(get(section).strokes[0])]).toEqual(['#ffe2e0', '#f24822'])
+ expect([hex(get(rect).fills[0]), hex(get(rect).strokes[0])]).toEqual(['#f24822', '#f24822'])
+ expect(hex(get(text).fills[0])).toBe('#f24822')
+ editor.undo.undo()
+ expect(hex(get(rect).fills[0])).not.toBe('#f24822')
+ expect(hex(get(section).fills[0])).not.toBe('#ffe2e0')
+ expect(hex(get(text).fills[0])).not.toBe('#f24822')
+ })
+
+ test("colours a group's layers and leaves sticky notes and images to their own", () => {
+ const { editor, pageId } = setup()
+ const a = editor.createShape('RECTANGLE', 0, 0, 100, 100, pageId)
+ const b = editor.createShape('ELLIPSE', 200, 0, 100, 100, pageId)
+ const photo = editor.createShape('RECTANGLE', 400, 0, 100, 100, pageId)
+ const image = {
+ type: 'IMAGE' as const,
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ imageHash: 'hash',
+ imageScaleMode: 'FILL' as const,
+ opacity: 1,
+ visible: true
+ }
+ editor.graph.updateNode(photo, { fills: [image] })
+ editor.select([a, b, photo])
+ const group = expectDefined(editor.groupSelected())
+ const sticky = createSticky(editor.graph, pageId, {})
+ const before = hex(sticky.fills[0])
+ editor.setFigJamColor([group, sticky.id], 'blue')
+ expect(hex(editor.graph.getNode(b)?.fills[0])).toBe('#3dadff')
+ expect(editor.graph.getNode(photo)?.fills).toEqual([image])
+ expect(hex(editor.graph.getNode(sticky.id)?.fills[0])).toBe(before)
+ })
+
+ test("dashes a section's outline, giving it one first if it has none", () => {
+ const { editor, pageId } = setup()
+ const section = editor.createShape('SECTION', 0, 0, 400, 300, pageId)
+ editor.graph.updateNode(section, { strokes: [] })
+ editor.setSectionLineStyle([section], 'dashed')
+ const node = expectDefined(editor.graph.getNode(section))
+ expect(node.dashPattern).toEqual([16, 10])
+ expect(node.strokes).toHaveLength(1)
+ })
+})
diff --git a/packages/core/tests/editor/figjam/toolbar.test.ts b/packages/core/tests/editor/figjam/toolbar.test.ts
new file mode 100644
index 000000000..c0d30fc13
--- /dev/null
+++ b/packages/core/tests/editor/figjam/toolbar.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, test } from 'bun:test'
+
+import { figJamToolbarKind } from '@open-pencil/core'
+import type { Fill, NodeType } from '@open-pencil/scene-graph'
+
+const layer = (type: NodeType, fills: Fill[] = []) => ({ type, fills })
+const image: Fill = {
+ type: 'IMAGE',
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ imageHash: 'hash',
+ imageScaleMode: 'FILL',
+ opacity: 1,
+ visible: true
+}
+
+// Measured in FigJam on 2026-10-31: which toolbar each selection gets.
+describe("FigJam's selection toolbars", () => {
+ test('each kind of layer gets its own', () => {
+ expect(figJamToolbarKind([layer('STICKY')])).toBe('sticky')
+ expect(figJamToolbarKind([layer('SECTION')])).toBe('section')
+ expect(figJamToolbarKind([layer('RECTANGLE'), layer('FRAME'), layer('LINE')])).toBe('layer')
+ expect(figJamToolbarKind([layer('RECTANGLE', [image])])).toBe('image')
+ expect(figJamToolbarKind([layer('RECTANGLE', [{ ...image, visible: false }])])).toBe('layer')
+ expect(figJamToolbarKind([layer('SECTION', [image])])).toBe('section')
+ expect(figJamToolbarKind([layer('TEXT', [image])])).toBe('text')
+ expect(figJamToolbarKind([])).toBeNull()
+ })
+
+ test('text with sticky notes shares text menus, and any other mix only arranges', () => {
+ expect(figJamToolbarKind([layer('STICKY'), layer('TEXT')])).toBe('text')
+ expect(figJamToolbarKind([layer('STICKY'), layer('SHAPE_WITH_TEXT')])).toBe('mixed')
+ expect(figJamToolbarKind([layer('SECTION'), layer('STICKY')])).toBe('mixed')
+ })
+})
diff --git a/packages/core/tests/editor/structure/section-wrap.test.ts b/packages/core/tests/editor/structure/section-wrap.test.ts
new file mode 100644
index 000000000..299bfccb2
--- /dev/null
+++ b/packages/core/tests/editor/structure/section-wrap.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, test } from 'bun:test'
+
+import { expectDefined } from '#core-tests/helpers/assert'
+
+import { createEditor } from '@open-pencil/core'
+
+// Measured in FigJam: Wrap in new section leaves 48 units around the layers and numbers the section.
+describe('wrapping layers in a new section', () => {
+ test('spans them with 48 units of room, named and selected, in one undo step', () => {
+ const editor = createEditor()
+ const pageId = editor.state.currentPageId
+ const a = editor.createShape('RECTANGLE', 100, 100, 100, 100, pageId)
+ const b = editor.createShape('RECTANGLE', 400, 140, 100, 100, pageId)
+ editor.select([a, b])
+ const id = editor.wrapSelectionInSection()
+ const section = expectDefined(id ? editor.graph.getNode(id) : undefined)
+ expect(section).toMatchObject({ type: 'SECTION', name: 'Section 1', x: 52, y: 52, width: 496, height: 236 })
+ expect(section.childIds).toEqual([a, b])
+ expect([...editor.state.selectedIds]).toEqual([section.id])
+ editor.undo.undo()
+ expect(editor.graph.getNode(a)?.parentId).toBe(pageId)
+ expect(editor.graph.getNode(b)?.parentId).toBe(pageId)
+ expect(editor.graph.getNode(section.id)).toBeUndefined()
+ expect(editor.graph.getNode(pageId)?.childIds).toEqual([a, b])
+ })
+
+ test('a board paints it as a light section, whatever the interface theme', () => {
+ const editor = createEditor()
+ editor.state.theme = 'dark'
+ editor.setDocumentKind('board')
+ const pageId = editor.state.currentPageId
+ const a = editor.createShape('RECTANGLE', 100, 100, 100, 100, pageId)
+ editor.select([a])
+ const id = editor.wrapSelectionInSection()
+ const drawn = editor.createShape('SECTION', 600, 0, 200, 200, pageId)
+ const light = createEditor()
+ light.state.theme = 'light'
+ const expected = light.graph.getNode(light.createShape('SECTION', 0, 0, 10, 10, light.state.currentPageId))?.fills
+ expect(id ? editor.graph.getNode(id)?.fills : null).toEqual(expected)
+ expect(editor.graph.getNode(drawn)?.fills).toEqual(expected)
+ })
+
+ test('layers inside a frame are not wrapped, as sections live only on pages and in sections', () => {
+ const editor = createEditor()
+ const frame = editor.graph.createNode('FRAME', editor.state.currentPageId, { width: 400, height: 400 })
+ const a = editor.createShape('RECTANGLE', 10, 10, 50, 50, frame.id)
+ editor.select([a])
+ expect(editor.canWrapSelectionInSection()).toBe(false)
+ expect(editor.wrapSelectionInSection()).toBeNull()
+ expect(editor.graph.getNode(a)?.parentId).toBe(frame.id)
+ })
+})
diff --git a/packages/core/tests/editor/text/typeface.test.ts b/packages/core/tests/editor/text/typeface.test.ts
index 7a8587fc1..a53740f31 100644
--- a/packages/core/tests/editor/text/typeface.test.ts
+++ b/packages/core/tests/editor/text/typeface.test.ts
@@ -14,12 +14,12 @@ function setup() {
return { editor, pageId: editor.state.currentPageId }
}
-describe('typefaces of generated text', () => {
+describe('FigJam typefaces and sizes', () => {
test('a typeface sets the text that a shape or a sticky note is named by', async () => {
const { editor, pageId } = setup()
const id = editor.createShape('SHAPE_WITH_TEXT', 0, 0, 176, 176, pageId)
const sticky = createSticky(editor.graph, pageId, {})
- await editor.setGeneratedTextTypeface([id, sticky.id], 'technical')
+ await editor.setFigJamTypeface([id, sticky.id], 'technical')
const shape = expectDefined(editor.graph.getNode(id))
expect(shapeWithTextLabel(editor.graph, shape)?.fontFamily).toBe('Roboto Mono')
expect(stickySublayers(editor.graph, sticky)?.body.fontFamily).toBe('Roboto Mono')
@@ -30,7 +30,43 @@ describe('typefaces of generated text', () => {
const sticky = createSticky(editor.graph, pageId, {})
const body = expectDefined(stickySublayers(editor.graph, sticky)).body
editor.graph.updateNode(body.id, { textStyleId: 'text-style' })
- await editor.setGeneratedTextTypeface([sticky.id], 'technical')
+ await editor.setFigJamTypeface([sticky.id], 'technical')
expect(editor.graph.getNode(body.id)?.textStyleId).toBeNull()
})
+
+ test('a typeface and a FigJam size set a text layer too', async () => {
+ const { editor, pageId } = setup()
+ const id = editor.createShape('TEXT', 0, 0, 100, 20, pageId)
+ await editor.setFigJamTypeface([id], 'bookish')
+ editor.setFigJamTextSize([id], 'large')
+ expect(editor.graph.getNode(id)).toMatchObject({ fontFamily: 'Merriweather', fontSize: 40 })
+ })
+
+ test('a typeface sets every character, and a FigJam size sets every character too', async () => {
+ const { editor, pageId } = setup()
+ const id = editor.createShape('TEXT', 0, 0, 100, 20, pageId)
+ editor.graph.updateNode(id, {
+ text: 'Hello',
+ styleRuns: [{ start: 0, length: 2, style: { fontFamily: 'Roboto', fontSize: 30 } }]
+ })
+ await editor.setFigJamTypeface([id], 'bookish')
+ // The face reaches the range; its own size stays until a size is chosen.
+ expect(editor.graph.getNode(id)?.styleRuns).toEqual([
+ { start: 0, length: 2, style: { fontSize: 30 } }
+ ])
+ editor.setFigJamTextSize([id], 'large')
+ expect(editor.graph.getNode(id)?.styleRuns).toEqual([])
+ })
+
+ test('a FigJam size sets text and sticky notes together, in one undo step', () => {
+ const { editor, pageId } = setup()
+ const text = editor.createShape('TEXT', 0, 0, 100, 20, pageId)
+ const sticky = createSticky(editor.graph, pageId, {})
+ editor.setFigJamTextSize([text, sticky.id], 'huge')
+ const body = expectDefined(stickySublayers(editor.graph, sticky)).body
+ expect([editor.graph.getNode(text)?.fontSize, editor.graph.getNode(body.id)?.fontSize]).toEqual([96, 96])
+ editor.undo.undo()
+ expect(editor.graph.getNode(text)?.fontSize).not.toBe(96)
+ expect(editor.graph.getNode(body.id)?.fontSize).not.toBe(96)
+ })
})
diff --git a/packages/core/tests/editor/views/profile.test.ts b/packages/core/tests/editor/views/profile.test.ts
index 673239401..9db8dac3d 100644
--- a/packages/core/tests/editor/views/profile.test.ts
+++ b/packages/core/tests/editor/views/profile.test.ts
@@ -27,7 +27,9 @@ describe('canvas view profiles', () => {
dotGrid: null,
pixelGrid: true,
framesOpen: true,
- lint: true
+ lint: true,
+ rulers: true,
+ panelsOpen: true
})
})
@@ -48,7 +50,9 @@ describe('canvas view profiles', () => {
dotGrid: null,
pixelGrid: true,
framesOpen: true,
- lint: true
+ lint: true,
+ rulers: true,
+ panelsOpen: true
})
})
@@ -114,7 +118,7 @@ describe('host restrictions', () => {
})
describe('document kinds', () => {
- test('a board offers FigJam\'s tools and keys and snaps to its 16-unit grid', () => {
+ test("a board offers FigJam's tools and keys and snaps to its 16-unit grid", () => {
const editor = createEditor()
editor.setDocumentKind('board')
const profile = resolveEditorProfile(editor.state)
@@ -130,10 +134,13 @@ describe('document kinds', () => {
])
expect([profile.toolKeys, profile.snapGrid]).toEqual([BOARD_TOOL_SHORTCUTS, 16])
// FigJam draws its dots every 16 units and has no pixel grid.
- expect([profile.dotGrid, profile.pixelGrid, profile.framesOpen, profile.lint]).toEqual([
+ const { dotGrid, pixelGrid, framesOpen, lint, rulers, panelsOpen } = profile
+ expect([dotGrid, pixelGrid, framesOpen, lint, rulers, panelsOpen]).toEqual([
16,
false,
false,
+ false,
+ false,
false
])
})
diff --git a/packages/core/tests/figma-api/create/defaults.test.ts b/packages/core/tests/figma-api/create/defaults.test.ts
index ab9305f0a..5db0deda8 100644
--- a/packages/core/tests/figma-api/create/defaults.test.ts
+++ b/packages/core/tests/figma-api/create/defaults.test.ts
@@ -79,6 +79,9 @@ describe('new layer defaults', () => {
// Figma fills a section #444444 in its dark theme.
figma.theme = 'dark'
expect(solid(expectFills(figma.createSection().fills))).toEqual([[0.27, 0.27, 0.27]])
+ // A board is light under either theme.
+ figma.graph.documentKind = 'board'
+ expect(solid(expectFills(figma.createSection().fills))).toEqual([WHITE])
})
test('each layer gets its own copy of the default paints', () => {
diff --git a/packages/design-jsx/src/figjam/text.ts b/packages/design-jsx/src/figjam/text.ts
index 98a872c2e..c49d93cf7 100644
--- a/packages/design-jsx/src/figjam/text.ts
+++ b/packages/design-jsx/src/figjam/text.ts
@@ -19,7 +19,7 @@ export function figJamTextFields(
textSize: FigJamTextSize | undefined,
typeface: FigJamTypeface | undefined
): Partial<SceneNode> {
- const sized = textSize ? figJamTextSizeFields(textSize, typeface) : {}
+ const sized: Partial<SceneNode> = textSize ? figJamTextSizeFields(textSize, typeface) : {}
if (!typeface) return sized
return figJamTypefaceFields(typeface, { fontSize: sized.fontSize ?? text.fontSize })
}
diff --git a/packages/scene-graph/src/figjam/palette.ts b/packages/scene-graph/src/figjam/palette.ts
index 308b69c0e..159140b9b 100644
--- a/packages/scene-graph/src/figjam/palette.ts
+++ b/packages/scene-graph/src/figjam/palette.ts
@@ -1,3 +1,5 @@
+import { omit } from 'es-toolkit'
+
import { parseColor } from '../color'
import { BLACK, WHITE } from '../constants'
import type { Color } from '../primitives'
@@ -6,7 +8,8 @@ import type { Fill, SceneNode, Stroke } from '../types'
/**
* FigJam's board palette, in its menus' order, as its colour menu paints a shape with text: each
* fill pairs with a darker stroke, a light label on the darkest fills, and, made transparent, a
- * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours.
+ * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours, and
+ * a section takes a pale tint of each with the colour itself as its outline.
*/
const PALETTE = {
black: {
@@ -14,147 +17,189 @@ const PALETTE = {
stroke: '#242424',
lightLabel: true,
transparent: 0.5,
- transparentStroke: '#929292'
+ transparentStroke: '#929292',
+ sectionFill: '#dddddd',
+ sectionStroke: '#2c2c2c'
},
darkGray: {
fill: '#757575',
stroke: '#424242',
lightLabel: true,
transparent: 0.5,
- transparentStroke: '#a1a1a1'
+ transparentStroke: '#a1a1a1',
+ sectionFill: '#eaeaea',
+ sectionStroke: '#757575'
},
red: {
fill: '#f24822',
stroke: '#bd2915',
lightLabel: true,
transparent: 0.5,
- transparentStroke: '#c7968f'
+ transparentStroke: '#c7968f',
+ sectionFill: '#ffe2e0',
+ sectionStroke: '#f24822'
},
orange: {
fill: '#ff9e42',
stroke: '#eb7500',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#e9b780'
+ transparentStroke: '#e9b780',
+ sectionFill: '#ffead6',
+ sectionStroke: '#ff9e42'
},
yellow: {
fill: '#ffc943',
stroke: '#e8a302',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#f5d280'
+ transparentStroke: '#f5d280',
+ sectionFill: '#fff3d6',
+ sectionStroke: '#ffc943'
},
green: {
fill: '#66d575',
stroke: '#3e9b4b',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#80c79e'
+ transparentStroke: '#80c79e',
+ sectionFill: '#ddf8e2',
+ sectionStroke: '#66d575'
},
teal: {
fill: '#5ad8cc',
stroke: '#369e94',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#80c9c6'
+ transparentStroke: '#80c9c6',
+ sectionFill: '#defcfa',
+ sectionStroke: '#5ad8cc'
},
blue: {
fill: '#3dadff',
stroke: '#007ad2',
lightLabel: true,
transparent: 0.7,
- transparentStroke: '#4d99d3'
+ transparentStroke: '#4d99d3',
+ sectionFill: '#dbf0ff',
+ sectionStroke: '#3dadff'
},
violet: {
fill: '#874fff',
stroke: '#5427b4',
lightLabel: true,
transparent: 0.5,
- transparentStroke: '#a792d0'
+ transparentStroke: '#a792d0',
+ sectionFill: '#eae1ff',
+ sectionStroke: '#874fff'
},
pink: {
fill: '#f849c1',
stroke: '#b42487',
lightLabel: true,
transparent: 0.5,
- transparentStroke: '#ce92bb'
+ transparentStroke: '#ce92bb',
+ sectionFill: '#ffd6f2',
+ sectionStroke: '#f849c1'
},
white: {
fill: '#ffffff',
stroke: '#757575',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#f1f1f1'
+ transparentStroke: '#f1f1f1',
+ sectionFill: '#ffffff',
+ sectionStroke: '#e6e6e6'
},
gray: {
fill: '#b3b3b3',
stroke: '#797979',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#bcbcbc'
+ transparentStroke: '#bcbcbc',
+ sectionFill: '#f4f4f4',
+ sectionStroke: '#b3b3b3'
},
lightGray: {
fill: '#d9d9d9',
stroke: '#a5a5a5',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#c0c0c0'
+ transparentStroke: '#c0c0c0',
+ sectionFill: '#f9f9f9',
+ sectionStroke: '#d9d9d9'
},
lightRed: {
fill: '#ffc7c2',
stroke: '#f24822',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#ff9d8f'
+ transparentStroke: '#ff9d8f',
+ sectionFill: '#fff5f5',
+ sectionStroke: '#ffc7c2'
},
lightOrange: {
fill: '#ffe0c2',
stroke: '#ff9e42',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#f6c34d'
+ transparentStroke: '#f6c34d',
+ sectionFill: '#fff7f0',
+ sectionStroke: '#ffe0c2'
},
lightYellow: {
fill: '#ffecbd',
stroke: '#ffc943',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#efd54d'
+ transparentStroke: '#efd54d',
+ sectionFill: '#fffbf0',
+ sectionStroke: '#ffecbd'
},
lightGreen: {
fill: '#cdf4d3',
stroke: '#66d575',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#a8d7b4'
+ transparentStroke: '#a8d7b4',
+ sectionFill: '#ebffee',
+ sectionStroke: '#cdf4d3'
},
lightTeal: {
fill: '#c6faf6',
stroke: '#5ad8cc',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#bcebeb'
+ transparentStroke: '#bcebeb',
+ sectionFill: '#f1fefd',
+ sectionStroke: '#c6faf6'
},
lightBlue: {
fill: '#c2e5ff',
stroke: '#3dadff',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#76ccff'
+ transparentStroke: '#76ccff',
+ sectionFill: '#f5fbff',
+ sectionStroke: '#c2e5ff'
},
lightViolet: {
fill: '#dcccff',
stroke: '#874fff',
lightLabel: false,
transparent: 0.7,
- transparentStroke: '#d5a3ff'
+ transparentStroke: '#d5a3ff',
+ sectionFill: '#f8f5ff',
+ sectionStroke: '#dcccff'
},
lightPink: {
fill: '#ffc2ec',
stroke: '#f849c1',
lightLabel: false,
transparent: 0.5,
- transparentStroke: '#ffaaeb'
+ transparentStroke: '#ffaaeb',
+ sectionFill: '#fff0fa',
+ sectionStroke: '#ffc2ec'
}
} as const
@@ -306,3 +351,80 @@ export function figJamLineColorFields(
]
return { strokes }
}
+
+/** How heavy FigJam outlines a coloured section, and a coloured layer that had no stroke. */
+const SECTION_STROKE_WEIGHT = 2
+const LAYER_STROKE_WEIGHT = 1
+
+/** `strokes` recoloured, or a new stroke of `weight` when there are none. */
+function strokesIn(strokes: Stroke[], color: Color, weight: number): Stroke[] {
+ if (strokes.length > 0) return strokes.map((stroke) => ({ ...stroke, type: 'SOLID', color }))
+ return [{ type: 'SOLID', color, opacity: 1, visible: true, weight, align: 'INSIDE' }]
+}
+
+/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */
+export function figJamSectionColorFields(
+ section: Pick<SceneNode, 'strokes'>,
+ name: FigJamColorName
+): Partial<SceneNode> {
+ const { sectionFill, sectionStroke } = PALETTE[name]
+ return {
+ fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],
+ strokes: strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT),
+ strokeWeight: SECTION_STROKE_WEIGHT
+ }
+}
+
+/** The first of `paints` the canvas draws: a hidden or fully transparent one shows nothing. */
+function drawnPaint<P extends Fill>(paints: readonly P[]): P | undefined {
+ return paints.find((paint) => paint.visible && paint.opacity > 0)
+}
+
+/** The palette colour a section is painted, by its tint. */
+export function figJamSectionColorName(section: Pick<SceneNode, 'fills'>): FigJamColorName | null {
+ const fill = drawnPaint(section.fills)?.color
+ return (
+ FIGJAM_COLOR_NAMES.find((name) => sameColor(fill, parseColor(PALETTE[name].sectionFill))) ??
+ null
+ )
+}
+
+/**
+ * Whether a layer takes a palette colour as its stroke alone: a line, or a pen stroke, which is a
+ * vector with nothing filled. A filled vector takes it as any other layer does.
+ */
+function colorsStroke(node: Pick<SceneNode, 'type' | 'fills'>): boolean {
+ if (node.type === 'LINE') return true
+ return node.type === 'VECTOR' && !drawnPaint(node.fills)
+}
+
+/**
+ * A plain layer painted `name`, as FigJam's colour menu paints one: text takes it as its fill, a
+ * line or a pen stroke as its stroke, and any other layer as its fill and a stroke of the same
+ * colour.
+ */
+export function figJamLayerColorFields(
+ node: Pick<SceneNode, 'type' | 'fills' | 'strokes' | 'styleRuns'>,
+ name: FigJamColorName
+): Partial<SceneNode> {
+ const color = figJamColor(name)
+ const fills: Fill[] = [{ type: 'SOLID', color, opacity: 1, visible: true }]
+ if (node.type === 'TEXT') {
+ // The whole text takes the colour, ranges coloured on their own included.
+ const styleRuns = node.styleRuns.map((run) => ({
+ ...run,
+ style: omit(run.style, ['fills', 'fillStyleId'])
+ }))
+ return { fills, styleRuns }
+ }
+ const strokes = strokesIn(node.strokes, color, LAYER_STROKE_WEIGHT)
+ return colorsStroke(node) ? { strokes } : { fills, strokes }
+}
+
+/** The palette colour a plain layer shows, read where {@link figJamLayerColorFields} paints it. */
+export function figJamLayerColorName(
+ node: Pick<SceneNode, 'type' | 'fills' | 'strokes'>
+): FigJamColorName | null {
+ const paints: Fill[] = colorsStroke(node) ? node.strokes : node.fills
+ return figJamColorName(drawnPaint(paints)?.color)
+}
diff --git a/packages/scene-graph/src/figjam/text.ts b/packages/scene-graph/src/figjam/text.ts
index 36a7cbe55..11671d78a 100644
--- a/packages/scene-graph/src/figjam/text.ts
+++ b/packages/scene-graph/src/figjam/text.ts
@@ -36,7 +36,7 @@ export function isFigJamTypeface(value: unknown): value is FigJamTypeface {
export function figJamTextSizeFields(
size: FigJamTextSize,
typeface: FigJamTypeface = 'simple'
-): Partial<SceneNode> {
+): Pick<SceneNode, 'fontSize' | 'lineHeight' | 'letterSpacing'> {
const { fontSize, tracking } = FIGJAM_TEXT_SIZES[size]
const tracked = FIGJAM_TYPEFACES[typeface].tracked
return {
@@ -68,11 +68,16 @@ export function figJamTypefaceFields(
typeface: FigJamTypeface,
text: Pick<SceneNode, 'fontSize'>
): Partial<SceneNode> {
- const { fontFamily, fontWeight } = FIGJAM_TYPEFACES[typeface]
return {
- fontFamily,
- fontWeight,
- italic: false,
+ ...figJamTypefaceFaceFields(typeface),
...figJamTextSizeFields(figJamTextSize(text), typeface)
}
}
+
+/** The face `typeface` sets, without the size and spacing it sets with it. */
+export function figJamTypefaceFaceFields(
+ typeface: FigJamTypeface
+): Pick<SceneNode, 'fontFamily' | 'fontWeight' | 'italic'> {
+ const { fontFamily, fontWeight } = FIGJAM_TYPEFACES[typeface]
+ return { fontFamily, fontWeight, italic: false }
+}
diff --git a/packages/scene-graph/tests/figjam/palette.test.ts b/packages/scene-graph/tests/figjam/palette.test.ts
index cea845171..a4219296c 100644
--- a/packages/scene-graph/tests/figjam/palette.test.ts
+++ b/packages/scene-graph/tests/figjam/palette.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'bun:test'
import { createShapeWithText, shapeWithTextLabel } from '@open-pencil/scene-graph/generated'
-import { figJamColor, figJamColorName, figJamLineColorFields, figJamLineStyle, figJamLineStyleFields, figJamShapePaint } from '@open-pencil/scene-graph/figjam'
+import { figJamColor, figJamColorName, figJamLayerColorFields, figJamLayerColorName, figJamLineColorFields, figJamLineStyle, figJamLineStyleFields, figJamSectionColorFields, figJamSectionColorName, figJamShapePaint } from '@open-pencil/scene-graph/figjam'
import { SceneGraph } from '@open-pencil/scene-graph'
import { colorToHex } from '@open-pencil/scene-graph/color'
@@ -80,4 +80,56 @@ describe("FigJam's shape colours", () => {
const shown = figJamLineColorFields({ ...shape, ...hidden }, 'red')
expect(shown.strokes?.[0]?.opacity).toBe(1)
})
+
+ // Measured in FigJam: a section takes a pale tint outlined in the colour itself, 2 px.
+ test('the colour menu tints a section and outlines it in the colour', () => {
+ const red = figJamSectionColorFields({ strokes: [] }, 'red')
+ expect(hexes(red.fills)).toEqual(['#ffe2e0'])
+ expect(hexes(red.strokes)).toEqual(['#f24822'])
+ expect(red.strokeWeight).toBe(2)
+ expect(hexes(figJamSectionColorFields({ strokes: [] }, 'black').strokes)).toEqual(['#2c2c2c'])
+ expect(hexes(figJamSectionColorFields({ strokes: [] }, 'lightBlue').fills)).toEqual(['#f5fbff'])
+ expect(figJamSectionColorName({ fills: red.fills ?? [] })).toBe('red')
+ const hidden = { type: 'SOLID' as const, color: figJamColor('blue'), opacity: 1, visible: false }
+ expect(figJamSectionColorName({ fills: [hidden, ...(red.fills ?? [])] })).toBe('red')
+ })
+
+ test('the colour menu paints text, a line, and other layers as FigJam does', () => {
+ const text = figJamLayerColorFields({ type: 'TEXT', fills: [], strokes: [], styleRuns: [] }, 'red')
+ expect(hexes(text.fills)).toEqual(['#f24822'])
+ expect(text.strokes).toBeUndefined()
+ const line = figJamLayerColorFields({ type: 'LINE', fills: [], strokes: [], styleRuns: [] }, 'blue')
+ expect(line.fills).toBeUndefined()
+ expect(hexes(line.strokes)).toEqual(['#3dadff'])
+ const rect = figJamLayerColorFields({ type: 'RECTANGLE', fills: [], strokes: [], styleRuns: [] }, 'red')
+ expect(hexes(rect.fills)).toEqual(['#f24822'])
+ expect(rect.strokes?.[0]).toMatchObject({ weight: 1 })
+ expect(figJamLayerColorName({ type: 'RECTANGLE', fills: rect.fills ?? [], strokes: [] })).toBe('red')
+ })
+
+ test('a pen stroke takes the colour as its stroke, a filled vector as its fill and stroke', () => {
+ const pen = figJamLayerColorFields({ type: 'VECTOR', fills: [], strokes: [], styleRuns: [] }, 'blue')
+ expect(pen.fills).toBeUndefined()
+ const filled = { type: 'SOLID' as const, color: figJamColor('black'), opacity: 1, visible: true }
+ const shape = figJamLayerColorFields({ type: 'VECTOR', fills: [filled], strokes: [], styleRuns: [] }, 'blue')
+ expect(hexes(shape.fills)).toEqual(['#3dadff'])
+ expect(hexes(shape.strokes)).toEqual(['#3dadff'])
+ const clear = figJamLayerColorFields({ type: 'VECTOR', fills: [{ ...filled, opacity: 0 }], strokes: [], styleRuns: [] }, 'blue')
+ expect(clear.fills).toBeUndefined()
+ })
+
+ test('a layer shows the colour of its first paint the canvas draws', () => {
+ const paint = (name: 'red' | 'green' | 'blue', visible: boolean, opacity = 1) => ({ type: 'SOLID' as const, color: figJamColor(name), opacity, visible })
+ const fills = [paint('red', false), paint('green', true, 0), paint('blue', true)]
+ expect(figJamLayerColorName({ type: 'RECTANGLE', fills, strokes: [] })).toBe('blue')
+ })
+
+ test('the colour reaches gradient strokes and ranges of text coloured on their own', () => {
+ const gradient = { type: 'GRADIENT_LINEAR' as const, color: figJamColor('black'), opacity: 1, visible: true, weight: 2, align: 'INSIDE' as const }
+ const rect = figJamLayerColorFields({ type: 'RECTANGLE', fills: [], strokes: [gradient], styleRuns: [] }, 'red')
+ expect(rect.strokes?.[0]?.type).toBe('SOLID')
+ const run = { start: 0, length: 2, style: { fills: [{ type: 'SOLID' as const, color: figJamColor('blue'), opacity: 1, visible: true }], fontSize: 30 } }
+ const text = figJamLayerColorFields({ type: 'TEXT', fills: [], strokes: [], styleRuns: [run] }, 'red')
+ expect(text.styleRuns?.[0]?.style).toEqual({ fontSize: 30 })
+ })
})
diff --git a/packages/vue/package.json b/packages/vue/package.json
index 66b9161f6..7dfcd6c53 100644
--- a/packages/vue/package.json
+++ b/packages/vue/package.json
@@ -94,6 +94,11 @@
"import": "./dist/controls/effects/index.js",
"default": "./dist/controls/effects/index.js"
},
+ "./controls/figjam-style": {
+ "types": "./dist/controls/figjam-style/index.d.ts",
+ "import": "./dist/controls/figjam-style/index.js",
+ "default": "./dist/controls/figjam-style/index.js"
+ },
"./controls/fill": {
"types": "./dist/controls/fill/index.d.ts",
"import": "./dist/controls/fill/index.js",
diff --git a/packages/vue/src/canvas/guides/input.ts b/packages/vue/src/canvas/guides/input.ts
index 5356937d3..243f49163 100644
--- a/packages/vue/src/canvas/guides/input.ts
+++ b/packages/vue/src/canvas/guides/input.ts
@@ -1,6 +1,6 @@
import type { Ref } from 'vue'
-import type { Editor } from '@open-pencil/core'
+import { resolveEditorProfile, type Editor } from '@open-pencil/core'
import { computeGuideRedline, hitTestGuides } from '@open-pencil/core/canvas'
import { RULER_SIZE } from '@open-pencil/core/constants'
@@ -63,7 +63,17 @@ export function createGuideInput({
return axis === 'x' ? 'ew-resize' : 'ns-resize'
}
+ /** Whether rulers are drawn, so their strip takes new guides and drops dragged ones. */
+ function rulersShown(): boolean {
+ return (
+ 'showRulers' in editor.state &&
+ editor.state.showRulers === true &&
+ resolveEditorProfile(editor.state).rulers
+ )
+ }
+
function rulerAxis(sx: number, sy: number): DragGuide['axis'] | null {
+ if (!rulersShown()) return null
if (sx < RULER_SIZE && sy < RULER_SIZE) return null
if (sy < RULER_SIZE) return 'y'
if (sx < RULER_SIZE) return 'x'
@@ -107,7 +117,6 @@ export function createGuideInput({
}
function tryStartFromRuler(sx: number, sy: number, cx: number, cy: number): boolean {
- if (!('showRulers' in editor.state) || editor.state.showRulers !== true) return false
const axis = rulerAxis(sx, sy)
if (!axis) return false
const ownerId = ownerAt(cx, cy)
@@ -169,7 +178,7 @@ export function createGuideInput({
function finish(drag: DragGuide): void {
if (drag.dragStarted) {
- if (drag.currentScreenX < RULER_SIZE || drag.currentScreenY < RULER_SIZE) {
+ if (rulersShown() && (drag.currentScreenX < RULER_SIZE || drag.currentScreenY < RULER_SIZE)) {
if (!drag.duplicate && drag.guideId && drag.originalOwnerId) {
editor.removeGuide(drag.originalOwnerId, drag.guideId)
editor.setSelectedGuide(null)
diff --git a/packages/vue/src/canvas/overlays/useCanvasVirtualReference.ts b/packages/vue/src/canvas/overlays/useCanvasVirtualReference.ts
index 41def2178..3f77b0dac 100644
--- a/packages/vue/src/canvas/overlays/useCanvasVirtualReference.ts
+++ b/packages/vue/src/canvas/overlays/useCanvasVirtualReference.ts
@@ -1,15 +1,20 @@
-import { computed, type ComputedRef, type Ref } from 'vue'
+import { computed, toValue, type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue'
-import type { Editor } from '@open-pencil/core'
+import type { ViewportTransform } from '@open-pencil/core/geometry'
import type { Vector } from '@open-pencil/scene-graph/primitives'
type CanvasVirtualReference = {
getBoundingClientRect: () => DOMRect
}
+/**
+ * A popover reference at a canvas point. Pass the pan and zoom of the canvas's last drawn frame
+ * as `view`, so the popover moves with the picture rather than the live view, which runs ahead
+ * of the drawing while panning fast.
+ */
export function useCanvasVirtualReference(
canvasRef: Ref<HTMLElement | null>,
- editor: Editor,
+ view: MaybeRefOrGetter<ViewportTransform>,
anchor: ComputedRef<Vector | null>
) {
return computed<CanvasVirtualReference | null>(() => {
@@ -17,9 +22,7 @@ export function useCanvasVirtualReference(
const canvas = canvasRef.value
if (!point || !canvas) return null
- const zoom = editor.state.zoom
- const panX = editor.state.panX
- const panY = editor.state.panY
+ const { zoom, panX, panY } = toValue(view)
return {
getBoundingClientRect() {
diff --git a/packages/vue/src/canvas/useCanvasInput.ts b/packages/vue/src/canvas/useCanvasInput.ts
index dc87926dc..2c97b80cb 100644
--- a/packages/vue/src/canvas/useCanvasInput.ts
+++ b/packages/vue/src/canvas/useCanvasInput.ts
@@ -386,7 +386,7 @@ export function useCanvasInput(
}
if (d.type === 'sticky-scale') {
- applyStickyScale(d, cx, cy, editor)
+ applyStickyScale(d, cx, cy, editor, e.ctrlKey)
return
}
@@ -596,6 +596,7 @@ export function useCanvasInput(
drag,
cursorOverride,
canvasLabelEdit: canvasLabelEdit.edit,
+ startCanvasLabelEdit: canvasLabelEdit.start,
updateCanvasLabelEdit: canvasLabelEdit.update,
commitCanvasLabelEdit: canvasLabelEdit.commit,
cancelCanvasLabelEdit: canvasLabelEdit.cancel,
diff --git a/packages/vue/src/controls/figjam-style/index.ts b/packages/vue/src/controls/figjam-style/index.ts
new file mode 100644
index 000000000..47ad1fd52
--- /dev/null
+++ b/packages/vue/src/controls/figjam-style/index.ts
@@ -0,0 +1 @@
+export { useFigJamStyle } from './use'
diff --git a/packages/vue/src/controls/figjam-style/use.ts b/packages/vue/src/controls/figjam-style/use.ts
new file mode 100644
index 000000000..ca6686e32
--- /dev/null
+++ b/packages/vue/src/controls/figjam-style/use.ts
@@ -0,0 +1,111 @@
+import { uniq } from 'es-toolkit'
+import { computed } from 'vue'
+
+import type { SceneNode } from '@open-pencil/scene-graph'
+import {
+ figJamColorName,
+ figJamLayerColorName,
+ figJamLineStyle,
+ figJamSectionColorName,
+ figJamTextSize,
+ figJamTypeface,
+ type FigJamColorName,
+ type FigJamLineStyle,
+ type FigJamTextSize,
+ type FigJamTypeface
+} from '@open-pencil/scene-graph/figjam'
+import { generatedFrameText } from '@open-pencil/scene-graph/generated'
+
+import { useEditor } from '#vue/editor/context'
+import { useSelectionState } from '#vue/editor/selection-state/use'
+import { useSceneComputed } from '#vue/internal/scene-computed/use'
+
+/**
+ * Headless state and actions for FigJam's colour and line menus on layers without controls of
+ * their own (text, sections, and plain shapes, lines, frames and groups), and its typeface and
+ * size menus on any text, a sticky note's or shape's included. Sticky notes, shapes with text and
+ * connectors keep their colours in `useStickyNote`, `useShapeWithText` and `useConnector`. A
+ * selection of several reads its first layer and changes them all.
+ */
+export function useFigJamStyle() {
+ const editor = useEditor()
+ const { selectedIds } = useSelectionState()
+
+ const layers = useSceneComputed(() =>
+ [...selectedIds.value].flatMap((id) => {
+ const node = editor.graph.getNode(id)
+ return node ? [node] : []
+ })
+ )
+ const ids = computed(() => layers.value.map((layer) => layer.id))
+
+ /** The layers a group's colour is read from: its contents, as its colour paints them. */
+ function painted(layer: SceneNode): SceneNode[] {
+ if (layer.type !== 'GROUP') return [layer]
+ return editor.graph.getChildren(layer.id).flatMap(painted)
+ }
+
+ /** The palette colour a layer shows, a group's when its contents share one. */
+ function layerColor(layer: SceneNode): FigJamColorName | null {
+ if (layer.type === 'SECTION') return figJamSectionColorName(layer)
+ const names = uniq(painted(layer).map(figJamLayerColorName))
+ return names.length === 1 ? (names[0] ?? null) : null
+ }
+
+ const style = useSceneComputed(() => {
+ const first: SceneNode | undefined = layers.value.at(0)
+ if (!first) return null
+ const text = first.type === 'TEXT' ? first : generatedFrameText(editor.graph, first)
+ return {
+ color: layerColor(first),
+ lineStyle: figJamLineStyle(first),
+ lineColor: figJamColorName(first.strokes.at(0)?.color),
+ textSize: text ? figJamTextSize(text) : null,
+ typeface: text ? figJamTypeface(text) : null,
+ font: text?.fontFamily ?? null
+ }
+ })
+ const color = computed<FigJamColorName | null>(() => style.value?.color ?? null)
+ const lineStyle = computed<FigJamLineStyle | null>(() => style.value?.lineStyle ?? null)
+ const lineColor = computed<FigJamColorName | null>(() => style.value?.lineColor ?? null)
+ const textSize = computed<FigJamTextSize | null>(() => style.value?.textSize ?? null)
+ const typeface = computed<FigJamTypeface | null>(() => style.value?.typeface ?? null)
+ /** The text's font family, which names a face FigJam's typeface menu does not offer. */
+ const font = computed(() => style.value?.font ?? null)
+
+ /** Paints the selected layers in a palette colour: sections in its tint, others in the colour. */
+ function setColor(name: FigJamColorName) {
+ editor.setFigJamColor(ids.value, name)
+ }
+
+ function setLineStyle(value: FigJamLineStyle) {
+ editor.setSectionLineStyle(ids.value, value)
+ }
+
+ function setLineColor(name: FigJamColorName) {
+ editor.setSectionLineColor(ids.value, name)
+ }
+
+ /** Sets the selected text, and sticky notes and shapes among it, to one of FigJam's sizes. */
+ function setTextSize(size: FigJamTextSize) {
+ editor.setFigJamTextSize(ids.value, size)
+ }
+
+ function setTypeface(value: FigJamTypeface) {
+ return editor.setFigJamTypeface(ids.value, value)
+ }
+
+ return {
+ color,
+ lineStyle,
+ lineColor,
+ textSize,
+ typeface,
+ font,
+ setColor,
+ setLineStyle,
+ setLineColor,
+ setTextSize,
+ setTypeface
+ }
+}
diff --git a/packages/vue/src/controls/shape-with-text/use.ts b/packages/vue/src/controls/shape-with-text/use.ts
index 9b5fa5b4e..54ddade09 100644
--- a/packages/vue/src/controls/shape-with-text/use.ts
+++ b/packages/vue/src/controls/shape-with-text/use.ts
@@ -93,7 +93,7 @@ export function useShapeWithText() {
}
function setTypeface(value: FigJamTypeface) {
- return editor.setGeneratedTextTypeface(ids.value, value)
+ return editor.setFigJamTypeface(ids.value, value)
}
/** Picks `value` for the shape tool and arms it, as FigJam's Shapes panel does. */
diff --git a/packages/vue/src/controls/sticky/use.ts b/packages/vue/src/controls/sticky/use.ts
index 98386cabc..c0159ba67 100644
--- a/packages/vue/src/controls/sticky/use.ts
+++ b/packages/vue/src/controls/sticky/use.ts
@@ -59,7 +59,7 @@ export function useStickyNote() {
}
function setTypeface(value: FigJamTypeface) {
- return editor.setGeneratedTextTypeface(ids.value, value)
+ return editor.setFigJamTypeface(ids.value, value)
}
return {
diff --git a/packages/vue/src/controls/typography/actions.ts b/packages/vue/src/controls/typography/actions.ts
index cac84f521..641954476 100644
--- a/packages/vue/src/controls/typography/actions.ts
+++ b/packages/vue/src/controls/typography/actions.ts
@@ -10,7 +10,7 @@ import type {
TextParagraphSpacingField
} from '@open-pencil/scene-graph'
import { faceLoadKey, faceStyleKey } from '@open-pencil/scene-graph/font-style'
-import { shapeWithTextLabel } from '@open-pencil/scene-graph/generated'
+import { generatedFrameText } from '@open-pencil/scene-graph/generated'
import {
createTextListActions,
@@ -51,17 +51,17 @@ function sharedFormatting(nodes: readonly SceneNode[]) {
return result
}
-/** The text a selected layer's typography edits: its own, or a shape with text's label. */
+/** The text a selected layer's typography edits: its own, or the text a sticky note or shape is named by. */
function typographyTargets(editor: Editor): SceneNode[] {
return selectedNodesAsShown(editor).flatMap((n) => {
if (n.type === 'TEXT') return [n]
- const label = shapeWithTextLabel(editor.graph, n)
- return label ? [label] : []
+ const text = generatedFrameText(editor.graph, n)
+ return text ? [text] : []
})
}
/**
- * Typography of the selected text layers and shapes' labels. With other layers selected too,
+ * Typography of the selected text layers and the text of sticky notes and shapes. With other layers selected too,
* Figma shows the text's typography and edits only the text, so `nodes` holds just the text.
*/
export function createTypographyState(editor: Editor) {
diff --git a/packages/vue/src/editor/commands/registry.ts b/packages/vue/src/editor/commands/registry.ts
index aad13f5de..188915cdd 100644
--- a/packages/vue/src/editor/commands/registry.ts
+++ b/packages/vue/src/editor/commands/registry.ts
@@ -31,6 +31,7 @@ export const EDITOR_COMMAND_METADATA = {
keybinding: '$mod+Alt+KeyG',
contextTestId: 'context-frame-selection'
},
+ 'selection.wrapInSection': {},
'selection.ungroup': { shortcut: 'MOD+SHIFT+G', keybinding: '$mod+Shift+KeyG' },
'selection.createComponent': {
shortcut: 'MOD+ALT+K',
diff --git a/packages/vue/src/editor/commands/selection.ts b/packages/vue/src/editor/commands/selection.ts
index 81dabd1e7..75ea0bb23 100644
--- a/packages/vue/src/editor/commands/selection.ts
+++ b/packages/vue/src/editor/commands/selection.ts
@@ -120,6 +120,14 @@ export function createSelectionCommands({
enabled: capabilities.canFrameSelection,
run: () => editor.frameSelection()
},
+ 'selection.wrapInSection': {
+ id: 'selection.wrapInSection',
+ get label() {
+ return t.value.wrapInSection
+ },
+ enabled: capabilities.canWrapInSection,
+ run: () => editor.wrapSelectionInSection()
+ },
'selection.ungroup': {
id: 'selection.ungroup',
get label() {
diff --git a/packages/vue/src/editor/commands/types.ts b/packages/vue/src/editor/commands/types.ts
index d89efdd39..5af5ac5ee 100644
--- a/packages/vue/src/editor/commands/types.ts
+++ b/packages/vue/src/editor/commands/types.ts
@@ -13,6 +13,7 @@ export type EditorCommandId =
| 'selection.delete'
| 'selection.group'
| 'selection.frameSelection'
+ | 'selection.wrapInSection'
| 'selection.ungroup'
| 'selection.createComponent'
| 'selection.createComponentSet'
diff --git a/packages/vue/src/editor/selection-capabilities/use.ts b/packages/vue/src/editor/selection-capabilities/use.ts
index b9521862a..8af055654 100644
--- a/packages/vue/src/editor/selection-capabilities/use.ts
+++ b/packages/vue/src/editor/selection-capabilities/use.ts
@@ -39,6 +39,7 @@ export function useSelectionCapabilities() {
canExportSelection: computed(() => hasSelection.value),
canGroup: computed(() => selectedCount.value >= 2),
canFrameSelection: computed(() => hasSelection.value),
+ canWrapInSection: useSceneComputed(() => editor.canWrapSelectionInSection()),
canUngroup: computed(() => selection.isGroup.value),
canCreateComponent: computed(() => hasSelection.value),
canCreateComponentSet: selection.canCreateComponentSet,
diff --git a/packages/vue/src/i18n/locales/de/commands.json b/packages/vue/src/i18n/locales/de/commands.json
index 742b2f691..64cd82eea 100644
--- a/packages/vue/src/i18n/locales/de/commands.json
+++ b/packages/vue/src/i18n/locales/de/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Vorherige Seite",
"groupSelection": "Gruppieren",
"frameSelection": "Auswahl in Rahmen setzen",
+ "wrapInSection": "In neuen Abschnitt einfügen",
"showHide": "Ein-/Ausblenden",
"lockUnlock": "Sperren/Entsperren",
"unionSelection": "Auswahl vereinen",
diff --git a/packages/vue/src/i18n/locales/de/editor.json b/packages/vue/src/i18n/locales/de/editor.json
index 97dddc704..3110e2434 100644
--- a/packages/vue/src/i18n/locales/de/editor.json
+++ b/packages/vue/src/i18n/locales/de/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Beliebigen Text eingeben, jemanden mit @ erwähnen",
"connectorLabelPlaceholder": "Text hinzufügen",
"showUI": "UI anzeigen ({shortcut})",
+ "openChat": "KI-Chat öffnen",
+ "closeChat": "KI-Chat schließen",
"previewing": "Vorschau",
"resetPreview": "Zurücksetzen",
"leavePreview": "Vorschau verlassen ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/de/figjam.json b/packages/vue/src/i18n/locales/de/figjam.json
index acdef87d2..df4311629 100644
--- a/packages/vue/src/i18n/locales/de/figjam.json
+++ b/packages/vue/src/i18n/locales/de/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Helltürkis",
"colorLightBlue": "Hellblau",
"colorLightViolet": "Hellviolett",
- "colorLightPink": "Hellrosa"
+ "colorLightPink": "Hellrosa",
+ "changeColor": "Farbe ändern",
+ "lineStyle": "Linienstil",
+ "lineShape": "Linienform",
+ "solid": "Durchgezogen",
+ "thin": "Dünn",
+ "renameSection": "Abschnitt umbenennen",
+ "addText": "Text hinzufügen"
}
diff --git a/packages/vue/src/i18n/locales/es/commands.json b/packages/vue/src/i18n/locales/es/commands.json
index 694dc3d28..f02f0dfc8 100644
--- a/packages/vue/src/i18n/locales/es/commands.json
+++ b/packages/vue/src/i18n/locales/es/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Página anterior",
"groupSelection": "Agrupar",
"frameSelection": "Selección de marco",
+ "wrapInSection": "Envolver en una sección nueva",
"showHide": "Visibilidad",
"lockUnlock": "Bloqueo",
"unionSelection": "Selección de unión",
diff --git a/packages/vue/src/i18n/locales/es/editor.json b/packages/vue/src/i18n/locales/es/editor.json
index eda5d8673..5050a0308 100644
--- a/packages/vue/src/i18n/locales/es/editor.json
+++ b/packages/vue/src/i18n/locales/es/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Escribe lo que quieras, @menciona a alguien",
"connectorLabelPlaceholder": "Añadir texto",
"showUI": "Mostrar interfaz ({shortcut})",
+ "openChat": "Abrir chat de IA",
+ "closeChat": "Cerrar chat de IA",
"previewing": "Vista previa",
"resetPreview": "Restablecer",
"leavePreview": "Salir de la vista previa ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/es/figjam.json b/packages/vue/src/i18n/locales/es/figjam.json
index 4d9f91ae2..efc329e8a 100644
--- a/packages/vue/src/i18n/locales/es/figjam.json
+++ b/packages/vue/src/i18n/locales/es/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Verde azulado claro",
"colorLightBlue": "Azul claro",
"colorLightViolet": "Violeta claro",
- "colorLightPink": "Rosa claro"
+ "colorLightPink": "Rosa claro",
+ "changeColor": "Cambiar color",
+ "lineStyle": "Estilo de línea",
+ "lineShape": "Forma de línea",
+ "solid": "Continua",
+ "thin": "Fina",
+ "renameSection": "Cambiar nombre de la sección",
+ "addText": "Añadir texto"
}
diff --git a/packages/vue/src/i18n/locales/fr/commands.json b/packages/vue/src/i18n/locales/fr/commands.json
index 0db988877..54e05526e 100644
--- a/packages/vue/src/i18n/locales/fr/commands.json
+++ b/packages/vue/src/i18n/locales/fr/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Page précédente",
"groupSelection": "Grouper",
"frameSelection": "Mettre la sélection dans un cadre",
+ "wrapInSection": "Placer dans une nouvelle section",
"showHide": "Afficher/Masquer",
"lockUnlock": "Verrouiller/Déverrouiller",
"unionSelection": "Union de la sélection",
diff --git a/packages/vue/src/i18n/locales/fr/editor.json b/packages/vue/src/i18n/locales/fr/editor.json
index 51d758ecb..71e7e6226 100644
--- a/packages/vue/src/i18n/locales/fr/editor.json
+++ b/packages/vue/src/i18n/locales/fr/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Écrivez ce que vous voulez, @mentionnez quelqu’un",
"connectorLabelPlaceholder": "Ajouter du texte",
"showUI": "Afficher l’interface ({shortcut})",
+ "openChat": "Ouvrir le chat IA",
+ "closeChat": "Fermer le chat IA",
"previewing": "Aperçu",
"resetPreview": "Réinitialiser",
"leavePreview": "Quitter l’aperçu ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/fr/figjam.json b/packages/vue/src/i18n/locales/fr/figjam.json
index 83c18c00c..2b44fc15f 100644
--- a/packages/vue/src/i18n/locales/fr/figjam.json
+++ b/packages/vue/src/i18n/locales/fr/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Sarcelle clair",
"colorLightBlue": "Bleu clair",
"colorLightViolet": "Violet clair",
- "colorLightPink": "Rose clair"
+ "colorLightPink": "Rose clair",
+ "changeColor": "Changer la couleur",
+ "lineStyle": "Style de ligne",
+ "lineShape": "Forme de ligne",
+ "solid": "Continue",
+ "thin": "Fine",
+ "renameSection": "Renommer la section",
+ "addText": "Ajouter du texte"
}
diff --git a/packages/vue/src/i18n/locales/it/commands.json b/packages/vue/src/i18n/locales/it/commands.json
index 8a18b8151..324416c3c 100644
--- a/packages/vue/src/i18n/locales/it/commands.json
+++ b/packages/vue/src/i18n/locales/it/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Pagina precedente",
"groupSelection": "Raggruppa",
"frameSelection": "Inserisci selezione in cornice",
+ "wrapInSection": "Racchiudi in una nuova sezione",
"showHide": "Mostra/Nascondi",
"lockUnlock": "Blocca/Sblocca",
"unionSelection": "Unisci selezione",
diff --git a/packages/vue/src/i18n/locales/it/editor.json b/packages/vue/src/i18n/locales/it/editor.json
index 52f842ae3..1ea0bf715 100644
--- a/packages/vue/src/i18n/locales/it/editor.json
+++ b/packages/vue/src/i18n/locales/it/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Scrivi qualsiasi cosa, @menziona qualcuno",
"connectorLabelPlaceholder": "Aggiungi testo",
"showUI": "Mostra interfaccia ({shortcut})",
+ "openChat": "Apri chat IA",
+ "closeChat": "Chiudi chat IA",
"previewing": "Anteprima",
"resetPreview": "Ripristina",
"leavePreview": "Esci dall’anteprima ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/it/figjam.json b/packages/vue/src/i18n/locales/it/figjam.json
index 2fa9ac0d4..573340f02 100644
--- a/packages/vue/src/i18n/locales/it/figjam.json
+++ b/packages/vue/src/i18n/locales/it/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Verde acqua chiaro",
"colorLightBlue": "Blu chiaro",
"colorLightViolet": "Viola chiaro",
- "colorLightPink": "Rosa chiaro"
+ "colorLightPink": "Rosa chiaro",
+ "changeColor": "Cambia colore",
+ "lineStyle": "Stile linea",
+ "lineShape": "Forma linea",
+ "solid": "Continua",
+ "thin": "Sottile",
+ "renameSection": "Rinomina sezione",
+ "addText": "Aggiungi testo"
}
diff --git a/packages/vue/src/i18n/locales/ja/commands.json b/packages/vue/src/i18n/locales/ja/commands.json
index bba430300..84a540df3 100644
--- a/packages/vue/src/i18n/locales/ja/commands.json
+++ b/packages/vue/src/i18n/locales/ja/commands.json
@@ -33,6 +33,7 @@
"previousPage": "前のページ",
"groupSelection": "グループ化",
"frameSelection": "選択範囲をフレーム化",
+ "wrapInSection": "新しいセクションで囲む",
"showHide": "表示/非表示",
"lockUnlock": "ロック/ロック解除",
"unionSelection": "選択範囲を結合 (合体)",
diff --git a/packages/vue/src/i18n/locales/ja/editor.json b/packages/vue/src/i18n/locales/ja/editor.json
index 52bebb75e..dd93d5c11 100644
--- a/packages/vue/src/i18n/locales/ja/editor.json
+++ b/packages/vue/src/i18n/locales/ja/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "自由に入力、@で誰かをメンション",
"connectorLabelPlaceholder": "テキストを追加",
"showUI": "UIを表示 ({shortcut})",
+ "openChat": "AI チャットを開く",
+ "closeChat": "AI チャットを閉じる",
"previewing": "プレビュー中",
"resetPreview": "リセット",
"leavePreview": "プレビューを終了 ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/ja/figjam.json b/packages/vue/src/i18n/locales/ja/figjam.json
index 43e1c1eb5..e16ecb564 100644
--- a/packages/vue/src/i18n/locales/ja/figjam.json
+++ b/packages/vue/src/i18n/locales/ja/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "ライトティール",
"colorLightBlue": "ライトブルー",
"colorLightViolet": "ライトバイオレット",
- "colorLightPink": "ライトピンク"
+ "colorLightPink": "ライトピンク",
+ "changeColor": "色を変更",
+ "lineStyle": "線のスタイル",
+ "lineShape": "線の形",
+ "solid": "実線",
+ "thin": "細い",
+ "renameSection": "セクション名を変更",
+ "addText": "テキストを追加"
}
diff --git a/packages/vue/src/i18n/locales/pl/commands.json b/packages/vue/src/i18n/locales/pl/commands.json
index dd766f00e..315a9fa4e 100644
--- a/packages/vue/src/i18n/locales/pl/commands.json
+++ b/packages/vue/src/i18n/locales/pl/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Poprzednia strona",
"groupSelection": "Grupuj",
"frameSelection": "Umieść zaznaczenie w ramce",
+ "wrapInSection": "Umieść w nowej sekcji",
"showHide": "Pokaż/Ukryj",
"lockUnlock": "Zablokuj/Odblokuj",
"unionSelection": "Połącz zaznaczenie",
diff --git a/packages/vue/src/i18n/locales/pl/editor.json b/packages/vue/src/i18n/locales/pl/editor.json
index e14db5c98..699ceb52b 100644
--- a/packages/vue/src/i18n/locales/pl/editor.json
+++ b/packages/vue/src/i18n/locales/pl/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Wpisz cokolwiek, @wspomnij kogoś",
"connectorLabelPlaceholder": "Dodaj tekst",
"showUI": "Pokaż interfejs ({shortcut})",
+ "openChat": "Otwórz czat AI",
+ "closeChat": "Zamknij czat AI",
"previewing": "Podgląd",
"resetPreview": "Resetuj",
"leavePreview": "Zakończ podgląd ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/pl/figjam.json b/packages/vue/src/i18n/locales/pl/figjam.json
index 35ff32236..00755c3dd 100644
--- a/packages/vue/src/i18n/locales/pl/figjam.json
+++ b/packages/vue/src/i18n/locales/pl/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Jasnomorski",
"colorLightBlue": "Jasnoniebieski",
"colorLightViolet": "Jasnofioletowy",
- "colorLightPink": "Jasnoróżowy"
+ "colorLightPink": "Jasnoróżowy",
+ "changeColor": "Zmień kolor",
+ "lineStyle": "Styl linii",
+ "lineShape": "Kształt linii",
+ "solid": "Ciągła",
+ "thin": "Cienka",
+ "renameSection": "Zmień nazwę sekcji",
+ "addText": "Dodaj tekst"
}
diff --git a/packages/vue/src/i18n/locales/ru/commands.json b/packages/vue/src/i18n/locales/ru/commands.json
index a32779476..34d6bb365 100644
--- a/packages/vue/src/i18n/locales/ru/commands.json
+++ b/packages/vue/src/i18n/locales/ru/commands.json
@@ -33,6 +33,7 @@
"previousPage": "Предыдущая страница",
"groupSelection": "Сгруппировать",
"frameSelection": "Поместить выделение во фрейм",
+ "wrapInSection": "Поместить в новую секцию",
"showHide": "Показать/Скрыть",
"lockUnlock": "Заблокировать/Разблокировать",
"unionSelection": "Объединить выделение",
diff --git a/packages/vue/src/i18n/locales/ru/editor.json b/packages/vue/src/i18n/locales/ru/editor.json
index db46a8715..3a878db8c 100644
--- a/packages/vue/src/i18n/locales/ru/editor.json
+++ b/packages/vue/src/i18n/locales/ru/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "Пишите что угодно, @упоминайте кого угодно",
"connectorLabelPlaceholder": "Добавить текст",
"showUI": "Показать интерфейс ({shortcut})",
+ "openChat": "Открыть чат с ИИ",
+ "closeChat": "Закрыть чат с ИИ",
"previewing": "Просмотр",
"resetPreview": "Сбросить",
"leavePreview": "Выйти из просмотра ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/ru/figjam.json b/packages/vue/src/i18n/locales/ru/figjam.json
index 16004e34f..a2331e3ef 100644
--- a/packages/vue/src/i18n/locales/ru/figjam.json
+++ b/packages/vue/src/i18n/locales/ru/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "Светло-бирюзовый",
"colorLightBlue": "Светло-синий",
"colorLightViolet": "Светло-фиолетовый",
- "colorLightPink": "Светло-розовый"
+ "colorLightPink": "Светло-розовый",
+ "changeColor": "Изменить цвет",
+ "lineStyle": "Стиль линии",
+ "lineShape": "Форма линии",
+ "solid": "Сплошная",
+ "thin": "Тонкая",
+ "renameSection": "Переименовать секцию",
+ "addText": "Добавить текст"
}
diff --git a/packages/vue/src/i18n/locales/zh-cn/commands.json b/packages/vue/src/i18n/locales/zh-cn/commands.json
index 1d5e7d17d..757653525 100644
--- a/packages/vue/src/i18n/locales/zh-cn/commands.json
+++ b/packages/vue/src/i18n/locales/zh-cn/commands.json
@@ -33,6 +33,7 @@
"previousPage": "上一页",
"groupSelection": "编组所选内容",
"frameSelection": "为所选内容添加画框",
+ "wrapInSection": "放入新分区",
"showHide": "显示/隐藏",
"lockUnlock": "锁定/解锁",
"unionSelection": "合并所选内容",
diff --git a/packages/vue/src/i18n/locales/zh-cn/editor.json b/packages/vue/src/i18n/locales/zh-cn/editor.json
index ce0b274d7..985803c21 100644
--- a/packages/vue/src/i18n/locales/zh-cn/editor.json
+++ b/packages/vue/src/i18n/locales/zh-cn/editor.json
@@ -11,6 +11,8 @@
"stickyPlaceholder": "输入任意内容,@提及任何人",
"connectorLabelPlaceholder": "添加文本",
"showUI": "显示界面({shortcut})",
+ "openChat": "打开 AI 聊天",
+ "closeChat": "关闭 AI 聊天",
"previewing": "预览中",
"resetPreview": "重置",
"leavePreview": "退出预览 ({shortcut})",
diff --git a/packages/vue/src/i18n/locales/zh-cn/figjam.json b/packages/vue/src/i18n/locales/zh-cn/figjam.json
index 1c85ab684..d9960e900 100644
--- a/packages/vue/src/i18n/locales/zh-cn/figjam.json
+++ b/packages/vue/src/i18n/locales/zh-cn/figjam.json
@@ -30,5 +30,12 @@
"colorLightTeal": "浅青色",
"colorLightBlue": "浅蓝色",
"colorLightViolet": "浅紫色",
- "colorLightPink": "浅粉色"
+ "colorLightPink": "浅粉色",
+ "changeColor": "更改颜色",
+ "lineStyle": "线条样式",
+ "lineShape": "线条形状",
+ "solid": "实线",
+ "thin": "细",
+ "renameSection": "重命名分区",
+ "addText": "添加文本"
}
diff --git a/packages/vue/src/i18n/messages/commands.ts b/packages/vue/src/i18n/messages/commands.ts
index 14887c3c7..09738170d 100644
--- a/packages/vue/src/i18n/messages/commands.ts
+++ b/packages/vue/src/i18n/messages/commands.ts
@@ -10,6 +10,7 @@ export const commandMessageDefaults = {
group: 'Group',
groupSelection: 'Group selection',
frameSelection: 'Frame selection',
+ wrapInSection: 'Wrap in new section',
ungroup: 'Ungroup',
createComponent: 'Create component',
createSlot: 'Create slot',
diff --git a/packages/vue/src/i18n/messages/editor.ts b/packages/vue/src/i18n/messages/editor.ts
index dc823dd1a..f6bab7e93 100644
--- a/packages/vue/src/i18n/messages/editor.ts
+++ b/packages/vue/src/i18n/messages/editor.ts
@@ -24,6 +24,8 @@ export const editorMessageDefaults = {
/** What an empty connector label shows on the canvas while it is typed into. */
connectorLabelPlaceholder: 'Add text',
showUI: params('Show UI ({shortcut})'),
+ openChat: 'Open AI chat',
+ closeChat: 'Close AI chat',
previewing: 'Previewing',
startPreview: params('Preview ({shortcut})'),
resetPreview: 'Reset',
diff --git a/packages/vue/src/i18n/messages/figjam.ts b/packages/vue/src/i18n/messages/figjam.ts
index 682cd79b2..4adca4ea8 100644
--- a/packages/vue/src/i18n/messages/figjam.ts
+++ b/packages/vue/src/i18n/messages/figjam.ts
@@ -1,6 +1,6 @@
import { i18n } from '#vue/i18n/create'
-/** FigJam's text sizes, typefaces and board palette, shared by sticky notes and shapes. */
+/** FigJam's text sizes, typefaces, board palette and selection toolbar menus. */
export const figJamMessageDefaults = {
textSize: 'Text size',
textSmall: 'Small',
@@ -33,7 +33,14 @@ export const figJamMessageDefaults = {
colorLightTeal: 'Light teal',
colorLightBlue: 'Light blue',
colorLightViolet: 'Light violet',
- colorLightPink: 'Light pink'
+ colorLightPink: 'Light pink',
+ changeColor: 'Change color',
+ lineStyle: 'Line style',
+ lineShape: 'Line shape',
+ solid: 'Solid',
+ thin: 'Thin',
+ renameSection: 'Rename section',
+ addText: 'Add text'
} as const
export const figJamMessages = i18n('figjam', figJamMessageDefaults)
diff --git a/packages/vue/src/shared/input/resize.ts b/packages/vue/src/shared/input/resize.ts
index a087ee836..21284fe74 100644
--- a/packages/vue/src/shared/input/resize.ts
+++ b/packages/vue/src/shared/input/resize.ts
@@ -29,7 +29,7 @@ import { markSourceFieldsEdited } from '@open-pencil/scene-graph/source-metadata
import { calculateResizeRect } from '#vue/shared/input/resize/rect'
import { draggedSizing, layerSizing } from '#vue/shared/input/resize/sizing'
-import { applyResizeSnap } from '#vue/shared/input/resize/snap'
+import { applyResizeSnap, proportionalResizeRect } from '#vue/shared/input/resize/snap'
import { optionalEditorState } from '#vue/shared/input/snap'
import type { DragResize } from '#vue/shared/input/types'
@@ -106,15 +106,12 @@ function resizeChanges(
const aspect = keptAspectRatio(d, shiftKey, ctrlKey)
// Control sets a lock aside even when Shift keeps the same ratio; the commit stores the size.
d.freesLock = d.lockedAspectRatio !== null && ctrlKey
- const calculatedRect = calculateResizeRect(
- d.handle,
- origRect,
- cx - d.startX,
- cy - d.startY,
- aspect
- )
+ const dx = cx - d.startX
+ const dy = cy - d.startY
const newRect =
- aspect !== null ? calculatedRect : applyResizeSnap(d, calculatedRect, editor, ctrlKey)
+ aspect !== null
+ ? proportionalResizeRect(d, origRect, dx, dy, aspect, editor, ctrlKey)
+ : applyResizeSnap(d, calculateResizeRect(d.handle, origRect, dx, dy, null), editor, ctrlKey)
const changes: Partial<SceneNode> = {
...newRect,
diff --git a/packages/vue/src/shared/input/resize/rect.ts b/packages/vue/src/shared/input/resize/rect.ts
index dc4b61782..8027315e6 100644
--- a/packages/vue/src/shared/input/resize/rect.ts
+++ b/packages/vue/src/shared/input/resize/rect.ts
@@ -6,32 +6,52 @@ function atLeast(value: number, min: number): number {
return Math.sign(value || 1) * Math.max(Math.abs(value), min)
}
+export type AspectDriver = 'width' | 'height'
+
+function isEdgeHandle(handle: HandlePosition): boolean {
+ return handle === 'n' || handle === 's' || handle === 'e' || handle === 'w'
+}
+
+/**
+ * The side that sizes a box kept at `aspect`: an edge handle's own axis, or for a corner the axis
+ * the pointer changed most, the width when both changed alike, as FigJam picks.
+ */
+export function aspectDriver(
+ handle: HandlePosition,
+ width: number,
+ height: number,
+ aspect: number
+): AspectDriver {
+ if (isEdgeHandle(handle)) return handle === 'e' || handle === 'w' ? 'width' : 'height'
+ return Math.abs(width) >= Math.abs(height) * aspect ? 'width' : 'height'
+}
+
/**
* Fits a dragged box to `aspect` (width over height), as Figma does: an edge handle sizes the
* other axis around its centre, a corner handle follows the axis the pointer changed most and
* keeps the opposite corner in place. The side that drives stays long enough for the other to
- * keep a whole pixel, so the box keeps its ratio at its smallest.
+ * keep a whole pixel, so the box keeps its ratio at its smallest. `driver` names the side that
+ * drives instead, and `follow` adjusts the size the other side gets, such as rounding it.
*/
export function constrainToAspectRatio(
handle: HandlePosition,
origRect: Rect,
width: number,
height: number,
- aspect: number
+ aspect: number,
+ driver: AspectDriver = aspectDriver(handle, width, height, aspect),
+ follow: (size: number) => number = (size) => size
): Rect {
const minWidth = Math.max(1, aspect)
const minHeight = Math.max(1, 1 / aspect)
const isTop = handle === 'nw' || handle === 'n' || handle === 'ne'
- const isEdge = handle === 'n' || handle === 's' || handle === 'e' || handle === 'w'
- const widthDrives = isEdge
- ? handle === 'e' || handle === 'w'
- : Math.abs(width) > Math.abs(height) * aspect
- if (widthDrives) {
+ const isEdge = isEdgeHandle(handle)
+ if (driver === 'width') {
width = atLeast(width, minWidth)
- height = (Math.abs(width) / aspect) * (isEdge ? 1 : Math.sign(height || 1))
+ height = follow(Math.abs(width) / aspect) * (isEdge ? 1 : Math.sign(height || 1))
} else {
height = atLeast(height, minHeight)
- width = Math.abs(height) * aspect * (isEdge ? 1 : Math.sign(width || 1))
+ width = follow(Math.abs(height) * aspect) * (isEdge ? 1 : Math.sign(width || 1))
}
// Signed sizes: a handle dragged past the opposite edge lands the box on the far side.
diff --git a/packages/vue/src/shared/input/resize/snap.ts b/packages/vue/src/shared/input/resize/snap.ts
index 59a99a463..0c7e7ae00 100644
--- a/packages/vue/src/shared/input/resize/snap.ts
+++ b/packages/vue/src/shared/input/resize/snap.ts
@@ -1,10 +1,16 @@
-import type { Editor } from '@open-pencil/core'
+import { resolveEditorProfile, type Editor } from '@open-pencil/core'
import type { HandlePosition } from '@open-pencil/core/geometry'
import type { SceneNode } from '@open-pencil/scene-graph'
import { getAxisAlignedWorldBounds, getWorldMatrix } from '@open-pencil/scene-graph/coordinate'
import type { Rect } from '@open-pencil/scene-graph/primitives'
import { explicitSnapTargets } from '#vue/shared/input/explicit-snap-targets'
+import {
+ aspectDriver,
+ calculateResizeRect,
+ constrainToAspectRatio,
+ type AspectDriver
+} from '#vue/shared/input/resize/rect'
import {
optionalEditorState,
resolveObjectPixelSnap,
@@ -29,7 +35,10 @@ function movesBottom(handle: HandlePosition): boolean {
return handle === 'sw' || handle === 's' || handle === 'se'
}
-function resizeTargets(drag: DragResize, editor: Editor): SceneNode[] {
+/** What a handle drag snaps: the layer and the handle that moves its edges. */
+type ResizeSnapTarget = Pick<DragResize, 'nodeId' | 'handle'>
+
+function resizeTargets(drag: ResizeSnapTarget, editor: Editor): SceneNode[] {
const node = editor.graph.getNode(drag.nodeId)
const parentId = node?.parentId ?? editor.state.currentPageId
return editor.graph
@@ -76,7 +85,7 @@ function hasAxisAlignedWorldBasis(node: SceneNode, editor: Editor): boolean {
}
export function applyResizeSnap(
- drag: DragResize,
+ drag: ResizeSnapTarget,
rect: Rect,
editor: Editor,
disableSnapping: boolean
@@ -114,3 +123,68 @@ export function applyResizeSnap(
state.snapGuides = snap.guides
return applyEdgeDelta(drag.handle, rect, dx, dy)
}
+
+/** How much a drag along one axis grows the box: by the delta at its far edge, against it at its near one. */
+function edgeGrowth(delta: number, far: boolean, near: boolean): number {
+ if (far) return delta
+ return near ? -delta : 0
+}
+
+/** The edge a proportional drag snaps by: the one its driving side moves. */
+const DRIVING_EDGE: Record<HandlePosition, Record<AspectDriver, HandlePosition>> = {
+ nw: { width: 'w', height: 'n' },
+ ne: { width: 'e', height: 'n' },
+ sw: { width: 'w', height: 's' },
+ se: { width: 'e', height: 's' },
+ n: { width: 'n', height: 'n' },
+ s: { width: 's', height: 's' },
+ e: { width: 'e', height: 'e' },
+ w: { width: 'w', height: 'w' }
+}
+
+/**
+ * Sizes a box kept at `aspect` from a handle drag, snapping as Figma does: the side that drives
+ * lands on the grid and on other layers' edges as a free resize's edge would, and the other side
+ * follows the ratio, rounded to a whole pixel in a design and left as it falls on a board.
+ */
+export function proportionalResizeRect(
+ drag: ResizeSnapTarget,
+ origRect: Rect,
+ dx: number,
+ dy: number,
+ aspect: number,
+ editor: Editor,
+ disableSnapping: boolean
+): Rect {
+ const { handle } = drag
+ const constrained = calculateResizeRect(handle, origRect, dx, dy, aspect)
+ const state = optionalEditorState(editor)
+ const width = origRect.width + edgeGrowth(dx, movesRight(handle), movesLeft(handle))
+ const height = origRect.height + edgeGrowth(dy, movesBottom(handle), movesTop(handle))
+ // A handle dragged past the opposite edge flips the box; it lands where the pointer puts it.
+ if (disableSnapping || !state || width <= 0 || height <= 0) {
+ if (state) state.snapGuides = []
+ return constrained
+ }
+ const driver = aspectDriver(handle, width, height, aspect)
+ const snapped = applyResizeSnap(
+ { nodeId: drag.nodeId, handle: DRIVING_EDGE[handle][driver] },
+ constrained,
+ editor,
+ false
+ )
+ const roundsToPixels =
+ state.snappingPreferences.pixelGrid && resolveEditorProfile(state).pixelGrid
+ const fitted = constrainToAspectRatio(
+ handle,
+ origRect,
+ snapped.width,
+ snapped.height,
+ aspect,
+ driver,
+ roundsToPixels ? (size) => Math.max(1, Math.round(size)) : undefined
+ )
+ // The smallest box the ratio allows moved the snapped side off its guide.
+ if (fitted[driver] !== snapped[driver]) state.snapGuides = []
+ return fitted
+}
diff --git a/packages/vue/src/shared/input/sticky/scale.ts b/packages/vue/src/shared/input/sticky/scale.ts
index aa161ade5..0194bb017 100644
--- a/packages/vue/src/shared/input/sticky/scale.ts
+++ b/packages/vue/src/shared/input/sticky/scale.ts
@@ -11,7 +11,8 @@ import {
import { scaleNodeChanges } from '@open-pencil/scene-graph/scaling'
import { getHitHandleByMatrix } from '#vue/shared/input/geometry'
-import { calculateResizeRect } from '#vue/shared/input/resize/rect'
+import { constrainToAspectRatio } from '#vue/shared/input/resize/rect'
+import { proportionalResizeRect } from '#vue/shared/input/resize/snap'
import type { DragStickyScale } from '#vue/shared/input/types'
/** The smallest scale a corner drag takes a note to, so it never folds away. */
@@ -93,24 +94,50 @@ function applyStickyWide(d: DragStickyScale, cx: number, editor: Editor) {
editor.requestRepaint()
}
-/** Shows the note as the handle has changed it; only the commit records it. */
-export function applyStickyScale(drag: DragStickyScale, cx: number, cy: number, editor: Editor) {
+/**
+ * Shows the note as the handle has changed it; only the commit records it. Control turns snapping
+ * off, as it does for a resize.
+ */
+export function applyStickyScale(
+ drag: DragStickyScale,
+ cx: number,
+ cy: number,
+ editor: Editor,
+ disableSnapping = false
+) {
const d = toRaw(drag)
if (d.mode === 'wide') {
applyStickyWide(d, cx, editor)
return
}
const { origRect } = d
- // The note keeps its proportions, anchored as a resize from the same handle would be.
- const rect = calculateResizeRect(
- d.handle,
+ // The note keeps its proportions, anchored and snapped as a Shift-resize from the same handle.
+ const aspect = origRect.width / origRect.height
+ const rect = proportionalResizeRect(
+ d,
origRect,
cx - d.startX,
cy - d.startY,
- origRect.width / origRect.height
+ aspect,
+ editor,
+ disableSnapping
)
d.scale = Math.max(MIN_STICKY_SCALE, rect.width / origRect.width)
- d.position = { x: rect.x, y: rect.y }
+ const clamped = d.scale !== rect.width / origRect.width
+ // At its smallest the note no longer meets the edge it snapped to, so no guide shows one.
+ if (clamped) editor.setSnapGuides([])
+ // A note scaled down to its smallest stays anchored as the handle anchors it.
+ const placed = !clamped
+ ? rect
+ : constrainToAspectRatio(
+ d.handle,
+ origRect,
+ origRect.width * d.scale,
+ origRect.height * d.scale,
+ aspect,
+ 'width'
+ )
+ d.position = { x: placed.x, y: placed.y }
for (const [id, original] of d.originals) {
const changes = scaleNodeChanges(original, d.scale, id !== d.nodeId)
if (id === d.nodeId) Object.assign(changes, d.position)
@@ -130,6 +157,7 @@ function restoreStickyScale(d: DragStickyScale, editor: Editor) {
function commitStickyScale(drag: DragStickyScale, editor: Editor) {
const d = toRaw(drag)
restoreStickyScale(d, editor)
+ editor.setSnapGuides([])
if (d.mode === 'wide') editor.setStickyWide(d.nodeId, d.wide, d.handle === 'w' ? 'right' : 'left')
else if (d.scale !== 1) editor.scaleStickyNote(d.nodeId, d.scale, d.position)
editor.requestRender()
diff --git a/packages/vue/tests/shared/input/resize/snap.test.ts b/packages/vue/tests/shared/input/resize/snap.test.ts
new file mode 100644
index 000000000..4efc0511d
--- /dev/null
+++ b/packages/vue/tests/shared/input/resize/snap.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, test } from 'bun:test'
+
+import { createEditor } from '@open-pencil/core'
+import type { Rect } from '@open-pencil/scene-graph/primitives'
+
+import { applyResize, commitResizePreview } from '#vue/shared/input/resize'
+import { tryStartResize } from '#vue/shared/input/resize/start'
+
+// Shift-drags of the south-east corner recorded in live Figma, 2026-10-31.
+function shiftDrag(
+ kind: 'design' | 'board',
+ rect: Rect,
+ dx: number,
+ dy: number,
+ obstacle?: Rect
+) {
+ const editor = createEditor()
+ editor.setDocumentKind(kind)
+ editor.state.snappingPreferences = { geometry: true, objects: true, pixelGrid: true }
+ const pageId = editor.state.currentPageId
+ const node = editor.graph.createNode('RECTANGLE', pageId, rect)
+ if (obstacle) editor.graph.createNode('RECTANGLE', pageId, obstacle)
+ editor.select([node.id])
+ const startX = rect.x + rect.width
+ const startY = rect.y + rect.height
+ const drag = tryStartResize(startX, startY, editor)
+ if (!drag) throw new Error('No south-east handle')
+ applyResize(drag, startX + dx, startY + dy, true, editor)
+ commitResizePreview(drag, editor)
+ const resized = editor.graph.getNode(node.id)
+ return { editor, width: resized?.width, height: resized?.height }
+}
+
+describe('a resize that keeps the ratio snaps its driving edge', () => {
+ test('on a board, the wider drag lands its right edge on the grid and the height follows', () => {
+ const { width, height } = shiftDrag('board', { x: 1264, y: 400, width: 160, height: 96 }, 37, 21)
+ expect(width).toBe(192)
+ expect(height).toBeCloseTo(115.2)
+ })
+
+ test('on a board, the taller drag lands its bottom edge on the grid', () => {
+ const square = { x: 1264, y: 400, width: 176, height: 176 }
+ expect(shiftDrag('board', square, 23, 60)).toMatchObject({ width: 240, height: 240 })
+ })
+
+ test('in a design, both sides end on whole pixels', () => {
+ const rect = { x: -200, y: -200, width: 160, height: 96 }
+ expect(shiftDrag('design', rect, 37, 21)).toMatchObject({ width: 197, height: 118 })
+ })
+
+ test("another layer's edge takes the driving edge before the grid", () => {
+ const rect = { x: -200, y: -200, width: 160, height: 96 }
+ const edge = { x: 0, y: -250, width: 20, height: 300 }
+ expect(shiftDrag('design', rect, 37, 21, edge)).toMatchObject({ width: 200, height: 120 })
+ })
+})
diff --git a/packages/vue/tests/shared/input/sticky/scale.test.ts b/packages/vue/tests/shared/input/sticky/scale.test.ts
new file mode 100644
index 000000000..43c3b79ab
--- /dev/null
+++ b/packages/vue/tests/shared/input/sticky/scale.test.ts
@@ -0,0 +1,88 @@
+import { describe, expect, test } from 'bun:test'
+
+import { createEditor } from '@open-pencil/core'
+import type { HandlePosition } from '@open-pencil/core/geometry'
+import type { Rect, Vector } from '@open-pencil/scene-graph/primitives'
+
+import { applyStickyScale, tryStartStickyScale } from '#vue/shared/input/sticky/scale'
+
+// Corner drags of a 240² note on a FigJam board, recorded in live Figma, 2026-10-31.
+function scaleNote(
+ at: Vector,
+ handle: HandlePosition,
+ dx: number,
+ dy: number,
+ obstacle?: Rect,
+ disableSnapping = false
+) {
+ const editor = createEditor()
+ editor.setDocumentKind('board')
+ editor.state.snappingPreferences = { geometry: true, objects: true, pixelGrid: true }
+ const pageId = editor.state.currentPageId
+ const note = editor.createStickyNote(pageId, { x: 0, y: 0 })
+ editor.graph.updateNode(note.id, at)
+ if (obstacle) editor.graph.createNode('RECTANGLE', pageId, obstacle)
+ editor.select([note.id])
+ let startX = at.x + 120
+ if (handle.includes('e')) startX = at.x + 240
+ if (handle.includes('w')) startX = at.x
+ const startY = at.y + (handle.includes('s') ? 240 : 0)
+ const drag = tryStartStickyScale(startX, startY, editor)
+ if (!drag) throw new Error(`No ${handle} handle`)
+ applyStickyScale(drag, startX + dx, startY + dy, editor, disableSnapping)
+ drag.commit()
+ const scaled = editor.graph.getNode(note.id)
+ return { x: scaled?.x, y: scaled?.y, width: scaled?.width, height: scaled?.height }
+}
+
+describe('scaling a sticky note by a corner on a board', () => {
+ test('lands the dragged edge on the 16-unit grid', () => {
+ expect(scaleNote({ x: 1264, y: 400 }, 'se', 37, 37)).toMatchObject({ width: 272, height: 272 })
+ expect(scaleNote({ x: 1264, y: 400 }, 'nw', -23, -23)).toMatchObject({
+ x: 1248,
+ y: 384,
+ width: 256
+ })
+ })
+
+ test('snaps the edge, not the size, for a note off the grid', () => {
+ expect(scaleNote({ x: 1269, y: 407 }, 'se', 37, 37)).toMatchObject({ width: 283 })
+ })
+
+ test('scales from the bottom edge around its centre, with the bottom on the grid', () => {
+ expect(scaleNote({ x: 1264, y: 400 }, 's', 0, 37)).toMatchObject({ x: 1248, y: 400, width: 272 })
+ })
+
+ test("takes another layer's edge before the grid", () => {
+ const edge = { x: 1523, y: 400, width: 20, height: 280 }
+ expect(scaleNote({ x: 1264, y: 400 }, 'se', 21, 21, edge)).toMatchObject({ width: 259 })
+ })
+
+ test('shows no snap guide once the note stops at its smallest', () => {
+ const editor = createEditor()
+ editor.setDocumentKind('board')
+ editor.state.snappingPreferences = { geometry: true, objects: true, pixelGrid: true }
+ const note = editor.createStickyNote(editor.state.currentPageId, { x: 0, y: 0 })
+ editor.graph.updateNode(note.id, { x: 1264, y: 400 })
+ editor.graph.createNode('RECTANGLE', editor.state.currentPageId, {
+ x: 1523,
+ y: 400,
+ width: 20,
+ height: 280
+ })
+ editor.select([note.id])
+ const drag = tryStartStickyScale(1504, 640, editor)
+ if (!drag) throw new Error('No se handle')
+ applyStickyScale(drag, 1504 + 21, 640 + 21, editor)
+ expect(editor.state.snapGuides.length).toBeGreaterThan(0)
+ // Nearly to the opposite corner: the note stops at a tenth of its size, short of any edge.
+ applyStickyScale(drag, 1504 - 230, 640 - 230, editor)
+ expect(editor.state.snapGuides).toEqual([])
+ drag.commit()
+ expect(editor.graph.getNode(note.id)?.width).toBe(24)
+ })
+
+ test('Control scales it freely, off the grid', () => {
+ expect(scaleNote({ x: 1264, y: 400 }, 'se', 37, 37, undefined, true)).toMatchObject({ width: 277 })
+ })
+})
diff --git a/packages/vue/tsdown.config.ts b/packages/vue/tsdown.config.ts
index f4e746e44..63b6999ee 100644
--- a/packages/vue/tsdown.config.ts
+++ b/packages/vue/tsdown.config.ts
@@ -74,6 +74,7 @@ export default defineConfig({
'controls/connector/index': './src/controls/connector/index.ts',
'controls/constraints/index': './src/controls/constraints/index.ts',
'controls/effects/index': './src/controls/effects/index.ts',
+ 'controls/figjam-style/index': './src/controls/figjam-style/index.ts',
'controls/fill/index': './src/controls/fill/index.ts',
'controls/icon/index': './src/controls/icon/index.ts',
'controls/layout/index': './src/controls/layout/index.ts',
diff --git a/src/app/document/io/create.ts b/src/app/document/io/create.ts
index fd0272b4f..d07150710 100644
--- a/src/app/document/io/create.ts
+++ b/src/app/document/io/create.ts
@@ -15,6 +15,7 @@ import type { EditorPreparationController } from '@/app/editor/preparation/contr
type DocumentIOState = EditorState & {
documentName: string
autosaveEnabled: boolean
+ showUI: boolean
}
export function createDocumentIOActions(
diff --git a/src/app/document/io/dom.ts b/src/app/document/io/dom.ts
index fd7710aaa..ea6ec1436 100644
--- a/src/app/document/io/dom.ts
+++ b/src/app/document/io/dom.ts
@@ -1,4 +1,4 @@
-import type { Editor, EditorState } from '@open-pencil/core'
+import { resolveEditorProfile, type Editor, type EditorState } from '@open-pencil/core'
import { sceneGraphFromStyledHTML } from '@open-pencil/core/io/formats/html/layers'
import { browserHTMLToDesignDocument } from '@open-pencil/dom-css/browser'
@@ -12,6 +12,8 @@ import { toast } from '@/app/shell/ui'
type OpenDOMDocumentState = EditorState & {
documentName: string
+ /** Whether the side panels show, which a document opens with as its kind starts it. */
+ showUI: boolean
}
type OpenDOMFileOptions = {
@@ -70,6 +72,8 @@ export function createDOMOpenActions({
const graph = sceneGraphFromStyledHTML(styled, { pageName })
await yieldToUI()
await applyImportedDocument(editor, graph, load)
+ // Into a reused tab too, the document opens with the panels its kind starts with.
+ state.showUI = resolveEditorProfile(editor.state).panelsOpen
state.documentName = pageName
await fitCurrentPageToViewport()
editor.requestRender()
diff --git a/src/app/document/io/read.ts b/src/app/document/io/read.ts
index 69145f013..90204b8a7 100644
--- a/src/app/document/io/read.ts
+++ b/src/app/document/io/read.ts
@@ -1,6 +1,6 @@
import { filename } from 'pathe/utils'
-import type { Editor, EditorState } from '@open-pencil/core'
+import { resolveEditorProfile, type Editor, type EditorState } from '@open-pencil/core'
import { describeDiagnosticError, recordDocumentFailure } from '@/app/diagnostics'
import { viewDiagnosticsAction } from '@/app/diagnostics/view'
@@ -15,6 +15,8 @@ import { toast } from '@/app/shell/ui'
type OpenDocumentState = EditorState & {
documentName: string
+ /** Whether the side panels show, which a document opens with as its kind starts it. */
+ showUI: boolean
}
type ReloadDocumentState = EditorState & { documentName: string }
@@ -59,6 +61,8 @@ export function createOpenActions({
await yieldToUI()
load.update({ phase: 'materializing', detail: file.name })
await applyImportedDocument(editor, imported, load)
+ // Into a reused tab too, the document opens with the panels its kind starts with.
+ state.showUI = resolveEditorProfile(editor.state).panelsOpen
state.documentName = filename(file.name) ?? file.name
setDocumentSource(file.name, 'fig', handle, path)
await fitCurrentPageToViewport()
diff --git a/src/app/editor/session/modules.ts b/src/app/editor/session/modules.ts
index 40053afa6..de6b41dda 100644
--- a/src/app/editor/session/modules.ts
+++ b/src/app/editor/session/modules.ts
@@ -1,6 +1,6 @@
-import { computed } from 'vue'
+import { computed, watch } from 'vue'
-import type { Editor } from '@open-pencil/core'
+import { resolveEditorProfile, type Editor } from '@open-pencil/core'
import type { IORegistry } from '@open-pencil/core/io'
import { createSelectedNodeState } from '@open-pencil/vue/editor/selection-state'
@@ -67,6 +67,14 @@ export function createEditorStoreModules(
const mobileClipboard = createMobileClipboardActions(editor)
const profiler = createProfilerActions(editor)
const designCheck = createDesignCheck(editor, state)
+ // A document opens with the panels its kind starts with: a board on the canvas alone.
+ watch(
+ () => state.documentKind,
+ () => {
+ state.showUI = resolveEditorProfile(state).panelsOpen
+ },
+ { immediate: true }
+ )
return {
...flash,
diff --git a/src/components/DesignPanel.vue b/src/components/DesignPanel.vue
index 34f2e1c63..db19f50e7 100644
--- a/src/components/DesignPanel.vue
+++ b/src/components/DesignPanel.vue
@@ -12,6 +12,9 @@ import { useSceneComputed } from '@open-pencil/vue/internal/scene-computed'
import { useEditorStore } from '@/app/editor/active-store'
import { openVariablesDialog } from '@/app/editor/tokens/dialog'
import { openLibraryReview, useLibraryService } from '@/app/libraries'
+import ConnectorSection from '@/components/figjam/connector/ConnectorSection.vue'
+import ShapeWithTextSection from '@/components/figjam/shape-with-text/ShapeWithTextSection.vue'
+import StickySection from '@/components/figjam/sticky/StickySection.vue'
import { COMPONENT_TYPES, sceneNodeIcon } from '@/components/icons'
import IconButton from '@/components/ui/button/IconButton.vue'
import Tip from '@/components/ui/overlay/Tip.vue'
@@ -27,7 +30,6 @@ import PropertyBoundField from './properties/component-properties/PropertyBoundF
import SlotAuthoringSection from './properties/component-properties/slot/SlotAuthoringSection.vue'
import { usePropertyBinding } from './properties/component-properties/usePropertyBinding'
import VariantAuthoringSection from './properties/component-properties/variant/VariantAuthoringSection.vue'
-import ConnectorSection from './properties/connector/ConnectorSection.vue'
import ConstraintsSection from './properties/constraints/ConstraintsSection.vue'
import DocumentSection from './properties/DocumentSection.vue'
import EffectsSection from './properties/EffectsSection.vue'
@@ -46,10 +48,8 @@ import PositionSection from './properties/PositionSection.vue'
import SelectionColorsSection from './properties/selection/SelectionColorsSection.vue'
import SelectionLayoutSection from './properties/selection/SelectionLayoutSection.vue'
import SelectionActionsControl from './properties/SelectionActionsControl.vue'
-import ShapeWithTextSection from './properties/shape-with-text/ShapeWithTextSection.vue'
import StatusesSection from './properties/status/StatusesSection.vue'
import StatusSection from './properties/status/StatusSection.vue'
-import StickySection from './properties/sticky/StickySection.vue'
import StrokeSection from './properties/stroke/StrokeSection.vue'
import TextContentControl from './properties/text-content/TextContentControl.vue'
import TextContentSection from './properties/text-content/TextContentSection.vue'
diff --git a/src/components/EditorCanvas.vue b/src/components/EditorCanvas.vue
index 1dffce866..318422e86 100644
--- a/src/components/EditorCanvas.vue
+++ b/src/components/EditorCanvas.vue
@@ -46,6 +46,7 @@ import { appRuntimeConfig } from '@/app/runtime/config'
import { appPreferences } from '@/app/settings/preferences/store'
import CommentsLayer from '@/components/comments/CommentsLayer.vue'
import IssueMarkerTooltip from '@/components/design-check/IssueMarkerTooltip.vue'
+import SelectionToolbar from '@/components/figjam/SelectionToolbar.vue'
import PreparationOverlay from '@/components/preparation/canvas/PreparationOverlay.vue'
import FollowFrame from '@/components/presence/FollowFrame.vue'
import StatusLabelMenu from '@/components/statuses/StatusLabelMenu.vue'
@@ -96,6 +97,8 @@ const shouldSuspendRender = () =>
/** The pan and zoom of the scene's last drawn frame, which preview islands follow. */
const drawnView = shallowRef<ViewportTransform | null>(null)
+/** Where popovers on the canvas are placed: the drawn frame, or the live view before one is drawn. */
+const overlayView = computed(() => drawnView.value ?? paneView.value)
// The tab's scene is presented only here once the canvas can draw, so waiting for it times out
// only while it is shown and drawing, not while the renderer and its fonts download.
@@ -137,7 +140,12 @@ const {
// The scene canvas reports a canvas that cannot start.
onFailed: () => undefined,
get showRulers() {
- return appRuntimeConfig.showRulers && store.state.showRulers && paneProfile.value.editChrome
+ return (
+ appRuntimeConfig.showRulers &&
+ store.state.showRulers &&
+ paneProfile.value.editChrome &&
+ paneProfile.value.rulers
+ )
},
getOverlayObstacles: () => canvasOverlayObstacles(canvasRef.value),
shouldSuspendRender,
@@ -145,8 +153,10 @@ const {
onViewportResize
})
const {
+ drag,
cursorOverride,
canvasLabelEdit,
+ startCanvasLabelEdit,
updateCanvasLabelEdit,
commitCanvasLabelEdit,
cancelCanvasLabelEdit,
@@ -216,7 +226,8 @@ const canvasLabelEditAnchor = computed(() => {
const node = canvasLabelEditNode.value
if (!node) return null
const origin = store.graph.getAbsolutePosition(node.id)
- const { zoom, panX, panY } = store.state
+ // The view the reference projects through, so screen-sized offsets match the drawn frame.
+ const { zoom, panX, panY } = overlayView.value
const kind = canvasLabelEdit.value?.kind
// The canvas starts an upright label on a whole screen pixel; the field starts on the same one.
const abs = {
@@ -237,16 +248,37 @@ const canvasLabelEditAnchor = computed(() => {
}
return { x: abs.x, y: abs.y }
})
-const canvasLabelEditReference = useCanvasVirtualReference(canvasRef, store, canvasLabelEditAnchor)
+const canvasLabelEditReference = useCanvasVirtualReference(
+ canvasRef,
+ overlayView,
+ canvasLabelEditAnchor
+)
const canvasLabelEditPresentation = computed(() =>
canvasLabelPresentation(store, canvasLabelEditNode.value ?? null, canvasLabelEdit.value?.kind)
)
+/** Names the selected section on the canvas, as its title does on a double-click. */
+function renameSelectedSection() {
+ const [id] = store.state.selectedIds
+ const section = id ? store.graph.getNode(id) : undefined
+ if (section?.type === 'SECTION') startCanvasLabelEdit('section-title', section)
+}
+
+// With the side panels away, a sticky, shape, or connector shows its controls over the canvas,
+// as FigJam does.
+const selectionToolbar = computed(
+ () =>
+ isActivePane.value &&
+ !store.state.showUI &&
+ paneProfile.value.edits &&
+ paneProfile.value.editChrome
+)
+
const valueEditorAnchor = computed(() => {
const edit = autoLayoutValueEdit.value
return edit ? autoLayoutValueAnchor(store, edit.nodeId, edit.field, edit.gap) : null
})
-const valueEditorReference = useCanvasVirtualReference(canvasRef, store, valueEditorAnchor)
+const valueEditorReference = useCanvasVirtualReference(canvasRef, overlayView, valueEditorAnchor)
const valueEditorIcon = computed(() => {
const edit = autoLayoutValueEdit.value
if (!edit) return IconLucidePanelTop
@@ -309,6 +341,13 @@ const cursor = computed(() =>
@commit="commitCanvasLabelEdit"
@cancel="cancelCanvasLabelEdit"
/>
+ <SelectionToolbar
+ v-if="selectionToolbar"
+ :canvas="canvasRef"
+ :view="overlayView"
+ :hidden="!!drag || !!canvasLabelEdit"
+ @rename-section="renameSelectedSection"
+ />
<PopoverRoot :open="!!autoLayoutValueEdit">
<PopoverPortal>
<PopoverContent
diff --git a/src/components/chat/FloatingChat.vue b/src/components/chat/FloatingChat.vue
new file mode 100644
index 000000000..371d63739
--- /dev/null
+++ b/src/components/chat/FloatingChat.vue
@@ -0,0 +1,36 @@
+<script setup lang="ts">
+import { useI18n } from '@open-pencil/vue/i18n'
+
+import ChatPanel from '@/components/chat/ChatPanel.vue'
+import IconButton from '@/components/ui/button/IconButton.vue'
+
+/**
+ * The AI chat over the canvas while it is shown alone, as on a board: the same chat the right
+ * panel holds once the panels are open.
+ */
+const emit = defineEmits<{ close: [] }>()
+const { editor, panels } = useI18n()
+</script>
+
+<template>
+ <section
+ data-test-id="floating-chat"
+ :aria-label="panels.ai"
+ class="absolute top-7 right-7 bottom-20 z-10 flex min-h-[min(16rem,calc(100%-1.75rem))] w-[min(360px,calc(100%-3.5rem))] flex-col overflow-hidden rounded-lg border border-border bg-panel shadow-lg"
+ >
+ <header class="flex h-9 shrink-0 items-center justify-between border-b border-border px-2">
+ <span class="flex items-center gap-1.5 text-xs font-medium text-surface">
+ <icon-lucide-sparkles class="size-3.5" aria-hidden="true" />
+ {{ panels.ai }}
+ </span>
+ <IconButton
+ :label="editor.closeChat"
+ data-test-id="floating-chat-close"
+ @click="emit('close')"
+ >
+ <icon-lucide-x class="size-3.5" />
+ </IconButton>
+ </header>
+ <ChatPanel />
+ </section>
+</template>
diff --git a/src/components/editor/EditorWorkspace.vue b/src/components/editor/EditorWorkspace.vue
index 4d379a574..ddbbb2fbf 100644
--- a/src/components/editor/EditorWorkspace.vue
+++ b/src/components/editor/EditorWorkspace.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { SplitterGroup, SplitterPanel, SplitterResizeHandle } from 'reka-ui'
import { tv } from 'tailwind-variants'
-import { computed } from 'vue'
+import { computed, ref } from 'vue'
import { resolveEditorProfile } from '@open-pencil/core'
import { formatShortcut } from '@open-pencil/vue/editor/commands'
@@ -14,6 +14,7 @@ import { loadEditorLayout, saveEditorLayout } from '@/app/shell/layout-storage'
import { appMenuShortcut } from '@/app/shell/menu/shortcut'
import type { Tab } from '@/app/tabs'
import CanvasSplitRoot from '@/components/canvas/CanvasSplitRoot.vue'
+import FloatingChat from '@/components/chat/FloatingChat.vue'
import CollabPanel from '@/components/collab-panel/CollabPanel.vue'
import ActiveRoomOverlay from '@/components/collab-room/ActiveRoomOverlay.vue'
import { useRoomActions } from '@/components/collab-room/useRoomActions'
@@ -41,6 +42,8 @@ const { tab } = defineProps<{ tab: Tab }>()
const store = tab.store
provideTabEditorStore(store)
const { isMobile } = useViewportKind()
+/** Whether the AI chat floats over the canvas shown alone; the right panel holds it otherwise. */
+const floatingChat = ref(false)
/**
* The layout the panels have. The splitter opens with it, also when showing the panels again
* remounts it, so its opening report matches and only a resize differs.
@@ -66,6 +69,12 @@ const horizontalSplitterStyles = tv(splitterTheme)({ direction: 'horizontal' })
const canvasAlone = computed(
() => !resolveEditorProfile(store.state).panels && store.visiblePaneCount.value <= 1
)
+// A board keeps its tools when its panels are away, as FigJam always shows them, while they
+// draw: a pan-only preview has none. A phone keeps its drawer, which holds the panels and chat.
+const toolsStay = computed(() => {
+ const profile = resolveEditorProfile(store.state)
+ return !profile.panelsOpen && profile.pointer === 'tools'
+})
const { editor } = useI18n()
// Until a room's document arrives there is nothing to edit, so its screen replaces the editor.
const { pending: roomPending } = useRoomActions()
@@ -137,7 +146,7 @@ const { pending: roomPending } = useRoomActions()
</SplitterGroup>
<div
- v-else-if="isMobile && showChrome && store.state.showUI"
+ v-else-if="isMobile && showChrome"
:key="'mobile-' + tab.id"
class="flex flex-1 overflow-hidden"
>
@@ -154,6 +163,7 @@ const { pending: roomPending } = useRoomActions()
<div class="relative flex min-w-0 flex-1">
<EditorCanvas />
<ActiveRoomOverlay />
+ <EditorToolbar v-if="toolsStay && !canvasAlone" />
<WorkspacePill
v-if="!isMobile && canvasAlone"
mode="preview"
@@ -167,7 +177,13 @@ const { pending: roomPending } = useRoomActions()
mode="collapsed"
:document-name="store.state.documentName"
:shortcut="formatShortcut(appMenuShortcut('toggle-ui')) ?? ''"
+ :chat-open="floatingChat"
@show-ui="store.state.showUI = true"
+ @toggle-chat="floatingChat = !floatingChat"
+ />
+ <FloatingChat
+ v-if="!isMobile && !canvasAlone && floatingChat"
+ @close="floatingChat = false"
/>
</div>
</div>
diff --git a/src/components/editor/WorkspacePill.vue b/src/components/editor/WorkspacePill.vue
index 66a1c11eb..4293f325c 100644
--- a/src/components/editor/WorkspacePill.vue
+++ b/src/components/editor/WorkspacePill.vue
@@ -10,13 +10,20 @@ import IconButton from '@/components/ui/button/IconButton.vue'
* The pill of the canvas-only layout: the document name and the way back. In preview it says
* so, resets the controls, and leaves preview.
*/
-const { documentName, mode, shortcut } = defineProps<{
+const {
+ documentName,
+ mode,
+ shortcut,
+ chatOpen = false
+} = defineProps<{
documentName: string
mode: 'collapsed' | 'preview'
/** The shortcut of the way back: Toggle UI, or leaving preview. */
shortcut: string
+ /** Whether the AI chat floats over the canvas, which the pill opens and closes. */
+ chatOpen?: boolean
}>()
-const emit = defineEmits<{ showUi: []; reset: []; leave: [] }>()
+const emit = defineEmits<{ showUi: []; toggleChat: []; reset: []; leave: [] }>()
const { editor } = useI18n()
</script>
@@ -36,6 +43,16 @@ const { editor } = useI18n()
>
<icon-lucide-sidebar class="size-3.5" />
</IconButton>
+ <IconButton
+ v-if="mode === 'collapsed'"
+ toggle
+ :active="chatOpen"
+ :label="chatOpen ? editor.closeChat : editor.openChat"
+ data-test-id="editor-toggle-chat"
+ @click="emit('toggleChat')"
+ >
+ <icon-lucide-sparkles class="size-3.5" />
+ </IconButton>
<template v-else>
<span
class="ml-1 flex h-5 items-center gap-1 rounded bg-accent/15 px-1.5 text-[10px] font-medium text-primary"
diff --git a/src/components/figjam/FigJamPalette.vue b/src/components/figjam/FigJamPalette.vue
index 50438e8e7..f580c38fb 100644
--- a/src/components/figjam/FigJamPalette.vue
+++ b/src/components/figjam/FigJamPalette.vue
@@ -19,13 +19,16 @@ const {
label,
selected,
noneLabel,
- none = false
+ none = false,
+ keepsMenuOpen = false
} = defineProps<{
label: string
selected: FigJamColorName | null
noneLabel?: string
/** Whether no colour is shown, which the none swatch marks. */
none?: boolean
+ /** Whether a pick leaves the toolbar menu open, as a line menu's palette does in FigJam. */
+ keepsMenuOpen?: boolean
}>()
const emit = defineEmits<{ select: [name: FigJamColorName]; none: [] }>()
const figjam = useFigJamMessages()
@@ -71,6 +74,7 @@ const swatches = computed(() =>
:swatches="swatches"
:selected="selected"
:none="noneLabel ? { label: noneLabel, active: none } : undefined"
+ :keeps-menu-open="keepsMenuOpen"
@select="emit('select', $event)"
@none="emit('none')"
/>
diff --git a/src/components/figjam/FigJamSwatches.vue b/src/components/figjam/FigJamSwatches.vue
index 5eac005a0..a916a5c67 100644
--- a/src/components/figjam/FigJamSwatches.vue
+++ b/src/components/figjam/FigJamSwatches.vue
@@ -1,6 +1,7 @@
<script setup lang="ts" generic="T extends string">
import { tv } from 'tailwind-variants'
+import { useCloseToolbarMenu } from '@/components/figjam/toolbar/menu'
import theme from '@/theme/figjam/swatches'
/** A swatch for one colour of a palette, as sticky notes and shapes pick theirs. */
@@ -14,14 +15,33 @@ export interface Swatch<T extends string> {
* A palette as a row of round swatches, eleven to a line as in FigJam's colour menus, and,
* when `none` is given, a last swatch for no colour at all.
*/
-const { label, swatches, selected, none } = defineProps<{
+const {
+ label,
+ swatches,
+ selected,
+ none,
+ keepsMenuOpen = false
+} = defineProps<{
label: string
swatches: Swatch<T>[]
selected: T | null
none?: { label: string; active: boolean }
+ /** Whether a pick leaves the toolbar menu open, as a line menu's palette does in FigJam. */
+ keepsMenuOpen?: boolean
}>()
const emit = defineEmits<{ select: [value: T]; none: [] }>()
const styles = tv(theme)
+const closeMenu = useCloseToolbarMenu()
+
+function pick(value: T) {
+ emit('select', value)
+ if (!keepsMenuOpen) closeMenu()
+}
+
+function pickNone() {
+ emit('none')
+ if (!keepsMenuOpen) closeMenu()
+}
</script>
<template>
@@ -36,7 +56,7 @@ const styles = tv(theme)
:data-swatch="swatch.value"
:class="styles({ active: !none?.active && swatch.value === selected }).swatch()"
:style="{ backgroundColor: swatch.hex }"
- @click="emit('select', swatch.value)"
+ @click="pick(swatch.value)"
/>
<button
v-if="none"
@@ -46,7 +66,7 @@ const styles = tv(theme)
:aria-label="none.label"
data-swatch="none"
:class="styles({ active: none.active }).swatch({ class: styles().none() })"
- @click="emit('none')"
+ @click="pickNone"
>
<icon-lucide-ban class="size-3.5" />
</button>
diff --git a/src/components/figjam/SelectionToolbar.vue b/src/components/figjam/SelectionToolbar.vue
new file mode 100644
index 000000000..7ae268b40
--- /dev/null
+++ b/src/components/figjam/SelectionToolbar.vue
@@ -0,0 +1,125 @@
+<script setup lang="ts">
+import { PopoverContent, PopoverPortal, PopoverRoot } from 'reka-ui'
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+
+import { figJamToolbarKind } from '@open-pencil/core'
+import type { ViewportTransform } from '@open-pencil/core/geometry'
+import { useCanvasVirtualReference } from '@open-pencil/vue/canvas/overlays'
+
+import { useEditorStore } from '@/app/editor/active-store'
+import theme from '@/theme/figjam/toolbar'
+import { motionStyles } from '@/theme/motion/styles'
+import { floatingSurface } from '@/theme/overlay'
+
+import ArrangeTools from './toolbar/ArrangeTools.vue'
+import ConnectorTools from './toolbar/ConnectorTools.vue'
+import LayerTools from './toolbar/LayerTools.vue'
+import SectionTools from './toolbar/SectionTools.vue'
+import ShapeTools from './toolbar/ShapeTools.vue'
+import StickyTools from './toolbar/StickyTools.vue'
+import TextTools from './toolbar/TextTools.vue'
+
+/**
+ * FigJam's selection toolbar: a bar centred above the selection with the menus its kind of layer
+ * has, and for several layers a way to align them and wrap them in a section.
+ */
+const { canvas, view, hidden } = defineProps<{
+ canvas: HTMLCanvasElement | null
+ /** The pan and zoom the canvas was last drawn with, which the toolbar follows. */
+ view: ViewportTransform
+ /** Whether something else owns the selection's surroundings now, such as a drag. */
+ hidden: boolean
+}>()
+const emit = defineEmits<{ renameSection: [] }>()
+
+/** Measured in FigJam: the bar's room above a selection, and above layers with handles there. */
+const TOOLBAR_GAP = 16
+const TOOLBAR_GAP_OVER_HANDLES = 40
+
+const store = useEditorStore()
+const styles = tv(theme)()
+
+/** The top centre of the selection. */
+const anchor = computed(() => {
+ void store.state.sceneVersion
+ const ids = [...store.state.selectedIds]
+ if (ids.length === 0 || ids.some((id) => !store.graph.getNode(id))) return null
+ const bounds = ids.map((id) => store.graph.getAbsoluteBounds(id))
+ const left = Math.min(...bounds.map((b) => b.x))
+ const right = Math.max(...bounds.map((b) => b.x + b.width))
+ return { x: (left + right) / 2, y: Math.min(...bounds.map((b) => b.y)) }
+})
+const reference = useCanvasVirtualReference(
+ computed(() => canvas),
+ () => view,
+ anchor
+)
+/** The selected layers, read again as the scene changes. */
+const layers = computed(() => {
+ void store.state.sceneVersion
+ return [...store.state.selectedIds].flatMap((id) => store.graph.getNode(id) ?? [])
+})
+const kind = computed(() => figJamToolbarKind(layers.value))
+const several = computed(() => layers.value.length > 1)
+const gap = computed(() =>
+ kind.value === 'sticky' || kind.value === 'shape' || kind.value === 'section'
+ ? TOOLBAR_GAP_OVER_HANDLES
+ : TOOLBAR_GAP
+)
+/** Whether only text is selected, which takes a colour; text with sticky notes shares text menus. */
+const textOnly = computed(() => layers.value.every((layer) => layer.type === 'TEXT'))
+const hasTools = computed(
+ () => kind.value !== null && ((kind.value !== 'mixed' && kind.value !== 'image') || several.value)
+)
+const open = computed(
+ () => !hidden && store.state.editingTextId === null && !!reference.value && hasTools.value
+)
+</script>
+
+<template>
+ <PopoverRoot :open="open">
+ <PopoverPortal>
+ <PopoverContent
+ v-if="open && reference"
+ :reference="reference"
+ side="top"
+ align="center"
+ :side-offset="gap"
+ :collision-padding="8"
+ :class="['z-40', styles.bar(), floatingSurface, motionStyles.floating]"
+ role="toolbar"
+ data-test-id="selection-toolbar"
+ :data-kind="kind"
+ @open-auto-focus.prevent
+ @close-auto-focus.prevent
+ @interact-outside.prevent
+ >
+ <StickyTools v-if="kind === 'sticky'" />
+ <ShapeTools v-else-if="kind === 'shape'" />
+ <ConnectorTools v-else-if="kind === 'connector'" />
+ <SectionTools
+ v-else-if="kind === 'section'"
+ :single="!several"
+ :locked="layers.every((layer) => layer.locked)"
+ @rename="emit('renameSection')"
+ />
+ <template v-else-if="kind === 'text'">
+ <template v-if="textOnly">
+ <LayerTools />
+ <span :class="styles.divider()" />
+ </template>
+ <TextTools :align="!several" />
+ </template>
+ <LayerTools
+ v-else-if="kind === 'layer' || kind === 'group'"
+ :ungroup="kind === 'group' && !several"
+ />
+ <template v-if="several">
+ <span v-if="kind !== 'mixed' && kind !== 'image'" :class="styles.divider()" />
+ <ArrangeTools />
+ </template>
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
+</template>
diff --git a/src/components/properties/connector/ConnectorControls.stories.ts b/src/components/figjam/connector/ConnectorControls.stories.ts
similarity index 100%
rename from src/components/properties/connector/ConnectorControls.stories.ts
rename to src/components/figjam/connector/ConnectorControls.stories.ts
diff --git a/src/components/properties/connector/ConnectorControls.vue b/src/components/figjam/connector/ConnectorControls.vue
similarity index 85%
rename from src/components/properties/connector/ConnectorControls.vue
rename to src/components/figjam/connector/ConnectorControls.vue
index 7d7a58abf..dc99098ef 100644
--- a/src/components/properties/connector/ConnectorControls.vue
+++ b/src/components/figjam/connector/ConnectorControls.vue
@@ -6,6 +6,7 @@ import type { ConnectorLineType, StrokeCap } from '@open-pencil/scene-graph'
import type { FigJamColorName } from '@open-pencil/scene-graph/figjam'
import { useI18n } from '@open-pencil/vue/i18n'
+import { useConnectorOptions } from '@/components/figjam/connector/options'
import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
import { CONNECTOR_LINE_TYPE_ICONS, connectorCapIcon } from '@/components/icons/connectors'
import IconButton from '@/components/ui/button/IconButton.vue'
@@ -45,21 +46,7 @@ const emit = defineEmits<{
const { panels } = useI18n()
const styles = tv(theme)()
-const lineOptions = computed<Array<{ value: ConnectorLineType; label: string }>>(() => [
- { value: 'ELBOWED', label: panels.value.connectorElbowed },
- { value: 'STRAIGHT', label: panels.value.connectorStraight },
- { value: 'CURVED', label: panels.value.connectorCurved }
-])
-
-/** The caps FigJam offers at a connector's ends. */
-const capOptions = computed<Array<{ value: StrokeCap; label: string }>>(() => [
- { value: 'NONE', label: panels.value.strokeCapNone },
- { value: 'ARROW_LINES', label: panels.value.strokeCapArrowLines },
- { value: 'ARROW_EQUILATERAL', label: panels.value.strokeCapArrowEquilateral },
- { value: 'TRIANGLE_FILLED', label: panels.value.strokeCapTriangleFilled },
- { value: 'DIAMOND_FILLED', label: panels.value.strokeCapDiamondFilled },
- { value: 'CIRCLE_FILLED', label: panels.value.strokeCapCircleFilled }
-])
+const { lineOptions, capOptions } = useConnectorOptions()
const selectedLine = computed<ConnectorLineType>({
get: () => lineType ?? 'ELBOWED',
diff --git a/src/components/properties/connector/ConnectorSection.vue b/src/components/figjam/connector/ConnectorSection.vue
similarity index 100%
rename from src/components/properties/connector/ConnectorSection.vue
rename to src/components/figjam/connector/ConnectorSection.vue
diff --git a/src/components/figjam/connector/options.ts b/src/components/figjam/connector/options.ts
new file mode 100644
index 000000000..b3f201608
--- /dev/null
+++ b/src/components/figjam/connector/options.ts
@@ -0,0 +1,23 @@
+import { computed } from 'vue'
+
+import type { ConnectorLineType, StrokeCap } from '@open-pencil/scene-graph'
+import { useI18n } from '@open-pencil/vue/i18n'
+
+/** A connector's line types and the caps FigJam offers at its ends, as menu options. */
+export function useConnectorOptions() {
+ const { panels } = useI18n()
+ const lineOptions = computed<Array<{ value: ConnectorLineType; label: string }>>(() => [
+ { value: 'ELBOWED', label: panels.value.connectorElbowed },
+ { value: 'STRAIGHT', label: panels.value.connectorStraight },
+ { value: 'CURVED', label: panels.value.connectorCurved }
+ ])
+ const capOptions = computed<Array<{ value: StrokeCap; label: string }>>(() => [
+ { value: 'NONE', label: panels.value.strokeCapNone },
+ { value: 'ARROW_LINES', label: panels.value.strokeCapArrowLines },
+ { value: 'ARROW_EQUILATERAL', label: panels.value.strokeCapArrowEquilateral },
+ { value: 'TRIANGLE_FILLED', label: panels.value.strokeCapTriangleFilled },
+ { value: 'DIAMOND_FILLED', label: panels.value.strokeCapDiamondFilled },
+ { value: 'CIRCLE_FILLED', label: panels.value.strokeCapCircleFilled }
+ ])
+ return { lineOptions, capOptions }
+}
diff --git a/src/components/properties/shape-with-text/ShapeWithTextControls.stories.ts b/src/components/figjam/shape-with-text/ShapeWithTextControls.stories.ts
similarity index 100%
rename from src/components/properties/shape-with-text/ShapeWithTextControls.stories.ts
rename to src/components/figjam/shape-with-text/ShapeWithTextControls.stories.ts
diff --git a/src/components/properties/shape-with-text/ShapeWithTextControls.vue b/src/components/figjam/shape-with-text/ShapeWithTextControls.vue
similarity index 100%
rename from src/components/properties/shape-with-text/ShapeWithTextControls.vue
rename to src/components/figjam/shape-with-text/ShapeWithTextControls.vue
diff --git a/src/components/properties/shape-with-text/ShapeWithTextSection.vue b/src/components/figjam/shape-with-text/ShapeWithTextSection.vue
similarity index 100%
rename from src/components/properties/shape-with-text/ShapeWithTextSection.vue
rename to src/components/figjam/shape-with-text/ShapeWithTextSection.vue
diff --git a/src/components/properties/sticky/StickyControls.stories.ts b/src/components/figjam/sticky/StickyControls.stories.ts
similarity index 100%
rename from src/components/properties/sticky/StickyControls.stories.ts
rename to src/components/figjam/sticky/StickyControls.stories.ts
diff --git a/src/components/properties/sticky/StickyControls.vue b/src/components/figjam/sticky/StickyControls.vue
similarity index 77%
rename from src/components/properties/sticky/StickyControls.vue
rename to src/components/figjam/sticky/StickyControls.vue
index ba7c093be..b01f18f46 100644
--- a/src/components/properties/sticky/StickyControls.vue
+++ b/src/components/figjam/sticky/StickyControls.vue
@@ -2,21 +2,19 @@
import { tv } from 'tailwind-variants'
import { computed } from 'vue'
-import { colorToHex } from '@open-pencil/scene-graph/color'
import type { FigJamTextSize, FigJamTypeface } from '@open-pencil/scene-graph/figjam'
import { STICKY_COLORS } from '@open-pencil/scene-graph/generated'
import type { Color } from '@open-pencil/scene-graph/primitives'
import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
import FigJamSwatches from '@/components/figjam/FigJamSwatches.vue'
+import { useStickySwatches } from '@/components/figjam/sticky/swatches'
import { typefaceModel, useFigJamTextOptions } from '@/components/figjam/text-options'
import PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'
import AppSelect from '@/components/ui/select/AppSelect.vue'
import AppSwitch from '@/components/ui/toggle/AppSwitch.vue'
import stickyControlsTheme from '@/theme/sticky-controls'
-type StickyColorName = keyof typeof STICKY_COLORS
-
const { color, textSize, authorVisible, typeface, bodyFont } = defineProps<{
color: Color | null
textSize: FigJamTextSize | null
@@ -37,31 +35,7 @@ const { panels } = useI18n()
const figjam = useFigJamMessages()
const styles = tv(stickyControlsTheme)
-const COLOR_LABEL_KEYS = {
- white: 'stickyColorWhite',
- gray: 'stickyColorGray',
- red: 'stickyColorRed',
- orange: 'stickyColorOrange',
- yellow: 'stickyColorYellow',
- green: 'stickyColorGreen',
- teal: 'stickyColorTeal',
- blue: 'stickyColorBlue',
- violet: 'stickyColorViolet',
- pink: 'stickyColorPink'
-} as const satisfies Record<StickyColorName, string>
-
-const swatches = computed(() =>
- (Object.entries(STICKY_COLORS) as [StickyColorName, Color][]).map(([name, value]) => ({
- value: name,
- hex: colorToHex(value),
- label: panels.value[COLOR_LABEL_KEYS[name]]
- }))
-)
-const selectedColor = computed(
- () =>
- swatches.value.find((swatch) => color !== null && swatch.hex === colorToHex(color))?.value ??
- null
-)
+const { swatches, selected: selectedColor } = useStickySwatches(() => color)
const { sizeOptions, typefaceOptions } = useFigJamTextOptions()
diff --git a/src/components/properties/sticky/StickySection.vue b/src/components/figjam/sticky/StickySection.vue
similarity index 100%
rename from src/components/properties/sticky/StickySection.vue
rename to src/components/figjam/sticky/StickySection.vue
diff --git a/src/components/figjam/sticky/swatches.ts b/src/components/figjam/sticky/swatches.ts
new file mode 100644
index 000000000..bf8fae20f
--- /dev/null
+++ b/src/components/figjam/sticky/swatches.ts
@@ -0,0 +1,40 @@
+import { computed } from 'vue'
+
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { STICKY_COLORS } from '@open-pencil/scene-graph/generated'
+import type { Color } from '@open-pencil/scene-graph/primitives'
+import { useI18n } from '@open-pencil/vue/i18n'
+
+export type StickyColorName = keyof typeof STICKY_COLORS
+
+const COLOR_LABEL_KEYS = {
+ white: 'stickyColorWhite',
+ gray: 'stickyColorGray',
+ red: 'stickyColorRed',
+ orange: 'stickyColorOrange',
+ yellow: 'stickyColorYellow',
+ green: 'stickyColorGreen',
+ teal: 'stickyColorTeal',
+ blue: 'stickyColorBlue',
+ violet: 'stickyColorViolet',
+ pink: 'stickyColorPink'
+} as const satisfies Record<StickyColorName, string>
+
+/** FigJam's ten sticky note colours as swatches, and the one a note's colour is. */
+export function useStickySwatches(color: () => Color | null) {
+ const { panels } = useI18n()
+ const swatches = computed(() =>
+ (Object.entries(STICKY_COLORS) as [StickyColorName, Color][]).map(([name, value]) => ({
+ value: name,
+ hex: colorToHex(value),
+ label: panels.value[COLOR_LABEL_KEYS[name]]
+ }))
+ )
+ const selected = computed(() => {
+ const current = color()
+ return (
+ swatches.value.find((swatch) => current && swatch.hex === colorToHex(current))?.value ?? null
+ )
+ })
+ return { swatches, selected }
+}
diff --git a/src/components/figjam/toolbar/ArrangeTools.vue b/src/components/figjam/toolbar/ArrangeTools.vue
new file mode 100644
index 000000000..f917c2143
--- /dev/null
+++ b/src/components/figjam/toolbar/ArrangeTools.vue
@@ -0,0 +1,84 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+import IconAlignCenterHorizontal from '~icons/lucide/align-center-horizontal'
+import IconAlignCenterVertical from '~icons/lucide/align-center-vertical'
+import IconAlignEndHorizontal from '~icons/lucide/align-end-horizontal'
+import IconAlignEndVertical from '~icons/lucide/align-end-vertical'
+import IconAlignStartHorizontal from '~icons/lucide/align-start-horizontal'
+import IconAlignStartVertical from '~icons/lucide/align-start-vertical'
+
+import { usePosition } from '@open-pencil/vue/controls/position'
+import { useEditorCommands } from '@open-pencil/vue/editor/commands'
+import { useI18n } from '@open-pencil/vue/i18n'
+
+import { toolIcons } from '@/components/icons'
+import IconButton from '@/components/ui/button/IconButton.vue'
+
+import ToolbarMenu from './ToolbarMenu.vue'
+import ToolbarOptions, { type ToolbarOption } from './ToolbarOptions.vue'
+
+/** What FigJam's toolbar offers any several layers: aligning them, and wrapping them in a section. */
+const position = usePosition()
+const { getCommand, runCommand } = useEditorCommands()
+const { panels } = useI18n()
+
+type Alignment =
+ | 'left'
+ | 'centerX'
+ | 'right'
+ | 'top'
+ | 'centerY'
+ | 'bottom'
+ | 'tidyUp'
+ | 'distributeHorizontal'
+ | 'distributeVertical'
+
+const ALIGNMENTS = {
+ left: ['horizontal', 'min'],
+ centerX: ['horizontal', 'center'],
+ right: ['horizontal', 'max'],
+ top: ['vertical', 'min'],
+ centerY: ['vertical', 'center'],
+ bottom: ['vertical', 'max']
+} as const
+
+const options = computed<ToolbarOption<Alignment>[]>(() => [
+ { value: 'left', label: panels.value.alignLeft, icon: IconAlignStartVertical },
+ { value: 'centerX', label: panels.value.alignCenterHorizontally, icon: IconAlignCenterVertical },
+ { value: 'right', label: panels.value.alignRight, icon: IconAlignEndVertical },
+ { value: 'top', label: panels.value.alignTop, icon: IconAlignStartHorizontal },
+ { value: 'centerY', label: panels.value.alignCenterVertically, icon: IconAlignCenterHorizontal },
+ { value: 'bottom', label: panels.value.alignBottom, icon: IconAlignEndHorizontal },
+ ...(['tidyUp', 'distributeHorizontal', 'distributeVertical'] as const).flatMap((id) => {
+ const command = getCommand(`selection.${id}`)
+ return command.enabled ? [{ value: id, label: command.label }] : []
+ })
+])
+
+function align(value: Alignment) {
+ if (value === 'tidyUp' || value === 'distributeHorizontal' || value === 'distributeVertical') {
+ runCommand(`selection.${value}`)
+ return
+ }
+ const [axis, to] = ALIGNMENTS[value]
+ position.align(axis, to)
+}
+</script>
+
+<template>
+ <ToolbarMenu :label="panels.alignment" property="toolbar-alignment">
+ <template #trigger>
+ <icon-lucide-align-start-vertical class="size-4" />
+ </template>
+ <ToolbarOptions :label="panels.alignment" :options="options" :selected="null" @select="align" />
+ </ToolbarMenu>
+ <IconButton
+ v-if="getCommand('selection.wrapInSection').enabled"
+ size="md"
+ :label="getCommand('selection.wrapInSection').label"
+ data-property="toolbar-wrap-section"
+ @click="runCommand('selection.wrapInSection')"
+ >
+ <component :is="toolIcons.SECTION" class="size-4" />
+ </IconButton>
+</template>
diff --git a/src/components/figjam/toolbar/ConnectorTools.vue b/src/components/figjam/toolbar/ConnectorTools.vue
new file mode 100644
index 000000000..63175bbac
--- /dev/null
+++ b/src/components/figjam/toolbar/ConnectorTools.vue
@@ -0,0 +1,145 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+import IconCircleDashed from '~icons/lucide/circle-dashed'
+import IconMinus from '~icons/lucide/minus'
+
+import type { ConnectorLineType, StrokeCap } from '@open-pencil/scene-graph'
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { figJamColor } from '@open-pencil/scene-graph/figjam'
+import { generatedFrameText } from '@open-pencil/scene-graph/generated'
+import { useConnector } from '@open-pencil/vue/controls/connector'
+import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
+
+import { useEditorStore } from '@/app/editor/active-store'
+import { useConnectorOptions } from '@/components/figjam/connector/options'
+import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
+import { CONNECTOR_LINE_TYPE_ICONS, connectorCapIcon } from '@/components/icons/connectors'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import ToolbarMenu from './ToolbarMenu.vue'
+import ToolbarOptions, { type ToolbarOption } from './ToolbarOptions.vue'
+
+/** FigJam's connector toolbar: colour, line weight and dash, a label, its ends and its shape. */
+const store = useEditorStore()
+const connector = useConnector()
+const figjam = useFigJamMessages()
+const { panels } = useI18n()
+const { lineOptions, capOptions } = useConnectorOptions()
+const styles = tv(theme)()
+
+const hex = computed(() =>
+ connector.color.value ? colorToHex(figJamColor(connector.color.value)) : undefined
+)
+type Weight = 'thin' | 'thick'
+type Dash = 'solid' | 'dashed'
+const weightOptions = computed<ToolbarOption<Weight>[]>(() => [
+ { value: 'thin', label: figjam.value.thin },
+ { value: 'thick', label: panels.value.connectorThick }
+])
+const dashOptions = computed<ToolbarOption<Dash>[]>(() => [
+ { value: 'solid', label: figjam.value.solid, icon: IconMinus },
+ { value: 'dashed', label: panels.value.connectorDashed, icon: IconCircleDashed }
+])
+const lineTypeOptions = computed<ToolbarOption<ConnectorLineType>[]>(() =>
+ lineOptions.value.map((option) => ({ ...option, icon: CONNECTOR_LINE_TYPE_ICONS[option.value] }))
+)
+function capMenu(end: 'start' | 'end') {
+ return computed<ToolbarOption<StrokeCap>[]>(() =>
+ capOptions.value.map((option) => ({ ...option, icon: connectorCapIcon(option.value, end) }))
+ )
+}
+const startOptions = capMenu('start')
+const endOptions = capMenu('end')
+const lineType = computed(() => connector.lineType.value ?? 'ELBOWED')
+const startCap = computed(() => connector.startCap.value ?? 'NONE')
+const endCap = computed(() => connector.endCap.value ?? 'NONE')
+
+/** Types into the connector's label, as FigJam's Add text does. */
+function addText() {
+ const [id] = store.state.selectedIds
+ const node = id ? store.graph.getNode(id) : undefined
+ const label = node && generatedFrameText(store.graph, node)
+ if (!label) return
+ store.startTextEditing(label.id)
+ store.textEditor?.selectAll()
+ store.textSelectionChanged()
+}
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.changeColor" property="toolbar-color">
+ <template #trigger>
+ <span :class="styles.dot()" :style="{ backgroundColor: hex }" />
+ </template>
+ <FigJamPalette
+ :label="panels.connectorColor"
+ :selected="connector.color.value"
+ @select="connector.setColor($event)"
+ />
+ </ToolbarMenu>
+ <ToolbarMenu :label="figjam.lineStyle" property="toolbar-line-style">
+ <template #trigger>
+ <icon-lucide-menu class="size-4" />
+ </template>
+ <div :class="styles.group()">
+ <ToolbarOptions
+ :label="figjam.lineStyle"
+ :options="weightOptions"
+ :selected="connector.thick.value ? 'thick' : 'thin'"
+ @select="connector.setThick($event === 'thick')"
+ />
+ <ToolbarOptions
+ :label="panels.connectorDashed"
+ :options="dashOptions"
+ :selected="connector.dashed.value ? 'dashed' : 'solid'"
+ @select="connector.setDashed($event === 'dashed')"
+ />
+ </div>
+ </ToolbarMenu>
+ <span :class="styles.divider()" />
+ <IconButton
+ v-if="store.state.selectedIds.size === 1"
+ size="md"
+ :label="figjam.addText"
+ data-property="toolbar-add-text"
+ @click="addText"
+ >
+ <icon-lucide-type class="size-4" />
+ </IconButton>
+ <span :class="styles.divider()" />
+ <ToolbarMenu :label="panels.connectorStart" property="toolbar-start-cap">
+ <template #trigger>
+ <component :is="connectorCapIcon(startCap, 'start')" class="size-4" />
+ </template>
+ <ToolbarOptions
+ :label="panels.connectorStart"
+ :options="startOptions"
+ :selected="startCap"
+ @select="connector.setStartCap($event)"
+ />
+ </ToolbarMenu>
+ <ToolbarMenu :label="figjam.lineShape" property="toolbar-line-shape">
+ <template #trigger>
+ <component :is="CONNECTOR_LINE_TYPE_ICONS[lineType]" class="size-4" />
+ </template>
+ <ToolbarOptions
+ :label="figjam.lineShape"
+ :options="lineTypeOptions"
+ :selected="lineType"
+ @select="connector.setLineType($event)"
+ />
+ </ToolbarMenu>
+ <ToolbarMenu :label="panels.connectorEnd" property="toolbar-end-cap">
+ <template #trigger>
+ <component :is="connectorCapIcon(endCap, 'end')" class="size-4" />
+ </template>
+ <ToolbarOptions
+ :label="panels.connectorEnd"
+ :options="endOptions"
+ :selected="endCap"
+ @select="connector.setEndCap($event)"
+ />
+ </ToolbarMenu>
+</template>
diff --git a/src/components/figjam/toolbar/LayerTools.vue b/src/components/figjam/toolbar/LayerTools.vue
new file mode 100644
index 000000000..d95589a8c
--- /dev/null
+++ b/src/components/figjam/toolbar/LayerTools.vue
@@ -0,0 +1,58 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { figJamColor } from '@open-pencil/scene-graph/figjam'
+import { useFigJamStyle } from '@open-pencil/vue/controls/figjam-style'
+import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
+
+import { useEditorStore } from '@/app/editor/active-store'
+import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import ToolbarMenu from './ToolbarMenu.vue'
+
+/**
+ * FigJam's toolbar for text and plain layers: their colour, and for a group a way to ungroup it.
+ * Text adds its text menus beside this.
+ */
+const { ungroup = false } = defineProps<{
+ /** Whether a single group is selected, which the toolbar offers to ungroup. */
+ ungroup?: boolean
+}>()
+const store = useEditorStore()
+const toolbar = useFigJamStyle()
+const figjam = useFigJamMessages()
+const { commands } = useI18n()
+const styles = tv(theme)()
+
+const hex = computed(() =>
+ toolbar.color.value ? colorToHex(figJamColor(toolbar.color.value)) : undefined
+)
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.changeColor" property="toolbar-color">
+ <template #trigger>
+ <span :class="styles.dot()" :style="{ backgroundColor: hex }" />
+ </template>
+ <FigJamPalette
+ :label="figjam.changeColor"
+ :selected="toolbar.color.value"
+ @select="toolbar.setColor($event)"
+ />
+ </ToolbarMenu>
+ <template v-if="ungroup">
+ <span :class="styles.divider()" />
+ <IconButton
+ size="md"
+ :label="commands.ungroup"
+ data-property="toolbar-ungroup"
+ @click="store.ungroupSelected()"
+ >
+ <icon-lucide-ungroup class="size-4" />
+ </IconButton>
+ </template>
+</template>
diff --git a/src/components/figjam/toolbar/LineStyleMenu.vue b/src/components/figjam/toolbar/LineStyleMenu.vue
new file mode 100644
index 000000000..def856d59
--- /dev/null
+++ b/src/components/figjam/toolbar/LineStyleMenu.vue
@@ -0,0 +1,60 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+import IconBan from '~icons/lucide/ban'
+import IconMinus from '~icons/lucide/minus'
+import IconSeparator from '~icons/lucide/separator-horizontal'
+
+import type { FigJamColorName, FigJamLineStyle } from '@open-pencil/scene-graph/figjam'
+import { useFigJamMessages, useShapeMessages } from '@open-pencil/vue/i18n'
+
+import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import ToolbarMenu from './ToolbarMenu.vue'
+import ToolbarOptions, { type ToolbarOption } from './ToolbarOptions.vue'
+
+/**
+ * FigJam's line menu for a shape's or section's outline: solid, dashed, or none, over the palette
+ * its colour comes from. A style closes it; a colour leaves it open to try another, as in FigJam.
+ */
+const { style, color } = defineProps<{
+ style: FigJamLineStyle | null
+ color: FigJamColorName | null
+}>()
+const emit = defineEmits<{
+ 'update:style': [value: FigJamLineStyle]
+ 'update:color': [value: FigJamColorName]
+}>()
+const figjam = useFigJamMessages()
+const shapes = useShapeMessages()
+const styles = tv(theme)()
+
+const options = computed<ToolbarOption<FigJamLineStyle>[]>(() => [
+ { value: 'solid', label: figjam.value.solid, icon: IconMinus },
+ { value: 'dashed', label: shapes.value.lineDashed, icon: IconSeparator },
+ { value: 'none', label: shapes.value.lineNone, icon: IconBan }
+])
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.lineStyle" property="toolbar-line-style">
+ <template #trigger>
+ <icon-lucide-menu class="size-4" />
+ </template>
+ <div :class="styles.group()">
+ <ToolbarOptions
+ :label="figjam.lineStyle"
+ :options="options"
+ :selected="style"
+ @select="emit('update:style', $event)"
+ />
+ <FigJamPalette
+ :label="shapes.line"
+ :selected="style === 'none' ? null : color"
+ keeps-menu-open
+ @select="emit('update:color', $event)"
+ />
+ </div>
+ </ToolbarMenu>
+</template>
diff --git a/src/components/figjam/toolbar/SectionTools.vue b/src/components/figjam/toolbar/SectionTools.vue
new file mode 100644
index 000000000..26e5ece5d
--- /dev/null
+++ b/src/components/figjam/toolbar/SectionTools.vue
@@ -0,0 +1,85 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { figJamColor } from '@open-pencil/scene-graph/figjam'
+import { useFigJamStyle } from '@open-pencil/vue/controls/figjam-style'
+import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
+
+import { useEditorStore } from '@/app/editor/active-store'
+import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import LineStyleMenu from './LineStyleMenu.vue'
+import ToolbarMenu from './ToolbarMenu.vue'
+
+/** FigJam's section toolbar: its colour, its outline, renaming it, and locking it. */
+const { single, locked } = defineProps<{
+ /** Whether one section is selected, which can be renamed. */
+ single: boolean
+ /** Whether every selected section is locked. */
+ locked: boolean
+}>()
+const emit = defineEmits<{ rename: [] }>()
+const store = useEditorStore()
+const toolbar = useFigJamStyle()
+const figjam = useFigJamMessages()
+const { menu } = useI18n()
+const styles = tv(theme)()
+
+/** Locks or unlocks every selected section alike, a mixed selection included. */
+function setLocked(value: boolean) {
+ const changing = [...store.state.selectedIds].filter(
+ (id) => store.graph.getNode(id)?.locked !== value
+ )
+ store.undo.runBatch(value ? 'Lock' : 'Unlock', () =>
+ changing.forEach((id) => store.toggleNodeLock(id))
+ )
+}
+
+const hex = computed(() =>
+ toolbar.color.value ? colorToHex(figJamColor(toolbar.color.value)) : undefined
+)
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.changeColor" property="toolbar-color">
+ <template #trigger>
+ <span :class="styles.dot()" :style="{ backgroundColor: hex }" />
+ </template>
+ <FigJamPalette
+ :label="figjam.changeColor"
+ :selected="toolbar.color.value"
+ @select="toolbar.setColor($event)"
+ />
+ </ToolbarMenu>
+ <LineStyleMenu
+ :style="toolbar.lineStyle.value"
+ :color="toolbar.lineColor.value"
+ @update:style="toolbar.setLineStyle($event)"
+ @update:color="toolbar.setLineColor($event)"
+ />
+ <span :class="styles.divider()" />
+ <IconButton
+ v-if="single"
+ size="md"
+ :label="figjam.renameSection"
+ data-property="toolbar-rename"
+ @click="emit('rename')"
+ >
+ <icon-lucide-text-cursor-input class="size-4" />
+ </IconButton>
+ <IconButton
+ size="md"
+ toggle
+ :label="locked ? menu.unlock : menu.lock"
+ :active="locked"
+ data-property="toolbar-lock"
+ @click="setLocked(!locked)"
+ >
+ <icon-lucide-lock v-if="locked" class="size-4" />
+ <icon-lucide-lock-open v-else class="size-4" />
+ </IconButton>
+</template>
diff --git a/src/components/figjam/toolbar/ShapeTools.vue b/src/components/figjam/toolbar/ShapeTools.vue
new file mode 100644
index 000000000..3bee7a671
--- /dev/null
+++ b/src/components/figjam/toolbar/ShapeTools.vue
@@ -0,0 +1,91 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import { figJamColor } from '@open-pencil/scene-graph/figjam'
+import { useShapeWithText } from '@open-pencil/vue/controls/shape-with-text'
+import { useFigJamMessages, useShapeMessages } from '@open-pencil/vue/i18n'
+
+import FigJamPalette from '@/components/figjam/FigJamPalette.vue'
+import { SHAPE_KIND_ICONS } from '@/components/icons/shapes'
+import ShapeKindPicker from '@/components/shapes/ShapeKindPicker.vue'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import LineStyleMenu from './LineStyleMenu.vue'
+import TextTools from './TextTools.vue'
+import ToolbarMenu from './ToolbarMenu.vue'
+
+/**
+ * FigJam's shape toolbar: the shape switcher, its colour with see-through and empty fills, its
+ * outline, and, once the shape has a label, its text menus.
+ */
+const shape = useShapeWithText()
+const shapes = useShapeMessages()
+const figjam = useFigJamMessages()
+const styles = tv(theme)()
+
+const fillHex = computed(() =>
+ shape.color.value ? colorToHex(figJamColor(shape.color.value)) : undefined
+)
+const kind = computed(() => shape.kind.value ?? 'SQUARE')
+</script>
+
+<template>
+ <ShapeKindPicker
+ :heading="shapes.kind"
+ :selected="kind"
+ side="top"
+ align="start"
+ @select="shape.setKind($event)"
+ >
+ <template #trigger>
+ <button
+ type="button"
+ aria-haspopup="listbox"
+ :aria-label="shapes.kind"
+ data-property="toolbar-shape-kind"
+ :class="styles.trigger()"
+ >
+ <component :is="SHAPE_KIND_ICONS[kind]" class="size-4" />
+ <icon-lucide-chevron-down :class="styles.chevron()" />
+ </button>
+ </template>
+ </ShapeKindPicker>
+ <span :class="styles.divider()" />
+ <ToolbarMenu :label="figjam.changeColor" property="toolbar-color">
+ <template #trigger>
+ <span :class="styles.dot()" :style="{ backgroundColor: fillHex }" />
+ </template>
+ <div :class="styles.group()">
+ <IconButton
+ toggle
+ :label="shapes.fillTransparent"
+ :active="shape.fillMode.value === 'transparent'"
+ data-property="toolbar-fill-transparent"
+ @click="shape.setFillMode(shape.fillMode.value === 'transparent' ? 'fill' : 'transparent')"
+ >
+ <icon-lucide-contrast class="size-3.5" />
+ </IconButton>
+ <FigJamPalette
+ :label="shapes.fill"
+ :selected="shape.color.value"
+ :none-label="shapes.fillNone"
+ :none="shape.fillMode.value === 'none'"
+ @select="shape.setColor($event)"
+ @none="shape.setFillMode('none')"
+ />
+ </div>
+ </ToolbarMenu>
+ <LineStyleMenu
+ :style="shape.lineStyle.value"
+ :color="shape.lineColor.value"
+ @update:style="shape.setLineStyle($event)"
+ @update:color="shape.setLineColor($event)"
+ />
+ <template v-if="shape.textSize.value">
+ <span :class="styles.divider()" />
+ <TextTools align />
+ </template>
+</template>
diff --git a/src/components/figjam/toolbar/StickyTools.vue b/src/components/figjam/toolbar/StickyTools.vue
new file mode 100644
index 000000000..26f620d6f
--- /dev/null
+++ b/src/components/figjam/toolbar/StickyTools.vue
@@ -0,0 +1,50 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+
+import { STICKY_COLORS } from '@open-pencil/scene-graph/generated'
+import { useStickyNote } from '@open-pencil/vue/controls/sticky'
+import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
+
+import FigJamSwatches from '@/components/figjam/FigJamSwatches.vue'
+import { useStickySwatches } from '@/components/figjam/sticky/swatches'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import TextTools from './TextTools.vue'
+import ToolbarMenu from './ToolbarMenu.vue'
+
+/** FigJam's sticky note toolbar: its ten colours, its text menus, and its author line. */
+const sticky = useStickyNote()
+const figjam = useFigJamMessages()
+const { panels } = useI18n()
+const styles = tv(theme)()
+const { swatches, selected } = useStickySwatches(() => sticky.color.value)
+const hex = computed(() => swatches.value.find((swatch) => swatch.value === selected.value)?.hex)
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.changeColor" property="toolbar-color">
+ <template #trigger>
+ <span :class="styles.dot()" :style="{ backgroundColor: hex }" />
+ </template>
+ <FigJamSwatches
+ :label="panels.stickyColor"
+ :swatches="swatches"
+ :selected="selected"
+ @select="sticky.setColor(STICKY_COLORS[$event])"
+ />
+ </ToolbarMenu>
+ <span :class="styles.divider()" />
+ <TextTools />
+ <IconButton
+ size="md"
+ toggle
+ :label="panels.stickyShowAuthor"
+ :active="sticky.authorVisible.value"
+ data-property="toolbar-author"
+ @click="sticky.setAuthorVisible(!sticky.authorVisible.value)"
+ >
+ <icon-lucide-user-round class="size-4" />
+ </IconButton>
+</template>
diff --git a/src/components/figjam/toolbar/TextTools.vue b/src/components/figjam/toolbar/TextTools.vue
new file mode 100644
index 000000000..3342e4f2e
--- /dev/null
+++ b/src/components/figjam/toolbar/TextTools.vue
@@ -0,0 +1,135 @@
+<script setup lang="ts">
+import { tv } from 'tailwind-variants'
+import { computed } from 'vue'
+import IconAlignCenter from '~icons/lucide/align-center'
+import IconAlignLeft from '~icons/lucide/align-left'
+import IconAlignRight from '~icons/lucide/align-right'
+
+import type { SceneNode } from '@open-pencil/scene-graph'
+import type { FigJamTextSize, FigJamTypeface } from '@open-pencil/scene-graph/figjam'
+import { useFigJamStyle } from '@open-pencil/vue/controls/figjam-style'
+import { MIXED } from '@open-pencil/vue/controls/node-props'
+import { useTypography } from '@open-pencil/vue/controls/typography'
+import { useFigJamMessages, useI18n } from '@open-pencil/vue/i18n'
+
+import { loadFont } from '@/app/editor/fonts'
+import { useFigJamTextOptions } from '@/components/figjam/text-options'
+import IconButton from '@/components/ui/button/IconButton.vue'
+import theme from '@/theme/figjam/toolbar'
+
+import ToolbarMenu from './ToolbarMenu.vue'
+import ToolbarOptions, { type ToolbarOption } from './ToolbarOptions.vue'
+
+/**
+ * The text menus of FigJam's selection toolbar: typeface, size, bold, strikethrough and bullets,
+ * and with `align` the text's alignment, for text and for the text of sticky notes and shapes.
+ */
+const { align = false } = defineProps<{ align?: boolean }>()
+
+const toolbar = useFigJamStyle()
+const typography = useTypography({ fontLoader: { load: loadFont } })
+const figjam = useFigJamMessages()
+const { menu, panels } = useI18n()
+const { sizeOptions, typefaceOptions } = useFigJamTextOptions()
+const styles = tv(theme)()
+
+const sizeLabel = computed(
+ () => sizeOptions.value.find((option) => option.value === toolbar.textSize.value)?.label ?? ''
+)
+const bold = computed(() => typography.activeFormatting.value.includes('bold'))
+const strikethrough = computed(() => typography.activeFormatting.value.includes('strikethrough'))
+const bulleted = computed(() => typography.listType.value === 'UNORDERED')
+
+type TextAlign = SceneNode['textAlignHorizontal']
+
+const alignOptions = computed<ToolbarOption<TextAlign>[]>(() => [
+ { value: 'LEFT', label: panels.value.alignLeft, icon: IconAlignLeft },
+ { value: 'CENTER', label: panels.value.alignCenter, icon: IconAlignCenter },
+ { value: 'RIGHT', label: panels.value.alignRight, icon: IconAlignRight }
+])
+const textAlign = computed(() => {
+ const value = typography.merged('textAlignHorizontal')
+ return value === MIXED ? null : value
+})
+const alignIcon = computed(
+ () => alignOptions.value.find((option) => option.value === textAlign.value)?.icon ?? IconAlignLeft
+)
+
+function setTypeface(value: FigJamTypeface) {
+ void toolbar.setTypeface(value)
+}
+
+function setSize(value: FigJamTextSize) {
+ toolbar.setTextSize(value)
+}
+</script>
+
+<template>
+ <ToolbarMenu :label="figjam.typeface" property="toolbar-typeface">
+ <template #trigger>
+ <icon-lucide-type class="size-4" />
+ </template>
+ <ToolbarOptions
+ :label="figjam.typeface"
+ :options="typefaceOptions"
+ :selected="toolbar.typeface.value"
+ @select="setTypeface"
+ />
+ </ToolbarMenu>
+ <ToolbarMenu :label="figjam.textSize" property="toolbar-text-size">
+ <template #trigger>
+ <span :class="styles.triggerText()">{{ sizeLabel || toolbar.font.value }}</span>
+ </template>
+ <ToolbarOptions
+ :label="figjam.textSize"
+ :options="sizeOptions"
+ :selected="toolbar.textSize.value"
+ @select="setSize"
+ />
+ </ToolbarMenu>
+ <span :class="styles.divider()" />
+ <IconButton
+ size="md"
+ toggle
+ :label="menu.bold"
+ :active="bold"
+ data-property="toolbar-bold"
+ @click="typography.toggleBold()"
+ >
+ <icon-lucide-bold class="size-4" />
+ </IconButton>
+ <IconButton
+ size="md"
+ toggle
+ :label="menu.strikethrough"
+ :active="strikethrough"
+ data-property="toolbar-strikethrough"
+ @click="typography.toggleDecoration('STRIKETHROUGH')"
+ >
+ <icon-lucide-strikethrough class="size-4" />
+ </IconButton>
+ <IconButton
+ size="md"
+ toggle
+ :label="panels.listBulleted"
+ :active="bulleted"
+ data-property="toolbar-bullets"
+ @click="typography.setListType(bulleted ? 'NONE' : 'UNORDERED')"
+ >
+ <icon-lucide-list class="size-4" />
+ </IconButton>
+ <template v-if="align">
+ <span :class="styles.divider()" />
+ <ToolbarMenu :label="panels.textAlignment" property="toolbar-text-align">
+ <template #trigger>
+ <component :is="alignIcon" class="size-4" />
+ </template>
+ <ToolbarOptions
+ :label="panels.textAlignment"
+ :options="alignOptions"
+ :selected="textAlign"
+ @select="typography.setAlign($event)"
+ />
+ </ToolbarMenu>
+ </template>
+</template>
diff --git a/src/components/figjam/toolbar/ToolbarMenu.vue b/src/components/figjam/toolbar/ToolbarMenu.vue
new file mode 100644
index 000000000..86bfd8c98
--- /dev/null
+++ b/src/components/figjam/toolbar/ToolbarMenu.vue
@@ -0,0 +1,53 @@
+<script setup lang="ts">
+import { PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
+import { tv } from 'tailwind-variants'
+import { provide } from 'vue'
+
+import Tip from '@/components/ui/overlay/Tip.vue'
+import theme from '@/theme/figjam/toolbar'
+import { motionStyles } from '@/theme/motion/styles'
+import { floatingSurface } from '@/theme/overlay'
+
+import { CLOSE_TOOLBAR_MENU } from './menu'
+
+/**
+ * A button of FigJam's selection toolbar that opens a menu above it: its trigger shows the current
+ * choice and a chevron, as FigJam's colour, line and text menus do.
+ */
+const { label, property } = defineProps<{
+ /** Accessible name and tooltip. */
+ label: string
+ /** The `data-property` tests find the trigger by. */
+ property?: string
+}>()
+const open = defineModel<boolean>('open', { default: false })
+const styles = tv(theme)()
+provide(CLOSE_TOOLBAR_MENU, () => {
+ open.value = false
+})
+
+/** How far a menu opens above its button. */
+const MENU_GAP = 8
+</script>
+
+<template>
+ <PopoverRoot v-model:open="open">
+ <Tip as-child :label="label" :disabled="open">
+ <PopoverTrigger :aria-label="label" :data-property="property" :class="styles.trigger()">
+ <slot name="trigger" />
+ <icon-lucide-chevron-down :class="styles.chevron()" />
+ </PopoverTrigger>
+ </Tip>
+ <PopoverPortal>
+ <PopoverContent
+ side="top"
+ :side-offset="MENU_GAP"
+ :collision-padding="8"
+ :class="[styles.popover(), floatingSurface, motionStyles.floating]"
+ :data-menu="property"
+ >
+ <slot />
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
+</template>
diff --git a/src/components/figjam/toolbar/ToolbarOptions.vue b/src/components/figjam/toolbar/ToolbarOptions.vue
new file mode 100644
index 000000000..e2d1a8e58
--- /dev/null
+++ b/src/components/figjam/toolbar/ToolbarOptions.vue
@@ -0,0 +1,61 @@
+<script setup lang="ts" generic="T extends string">
+import { tv } from 'tailwind-variants'
+import type { Component } from 'vue'
+
+import theme from '@/theme/figjam/toolbar'
+
+import { useCloseToolbarMenu } from './menu'
+
+/** One choice of a toolbar menu: its value, name, and icon. */
+export interface ToolbarOption<T extends string> {
+ value: T
+ label: string
+ icon?: Component
+}
+
+/** A toolbar menu's choices as a list, the current one marked, as FigJam lists them. */
+const { label, options, selected } = defineProps<{
+ label: string
+ options: ToolbarOption<T>[]
+ selected: T | null
+}>()
+const emit = defineEmits<{ select: [value: T] }>()
+const styles = tv(theme)()
+const closeMenu = useCloseToolbarMenu()
+
+function choose(value: T) {
+ emit('select', value)
+ closeMenu()
+}
+
+const ARROW_STEPS: Readonly<Record<string, number>> = { ArrowDown: 1, ArrowUp: -1 }
+
+/** Up and Down move between the choices, wrapping around, as a menu's arrow keys do. */
+function moveFocus(event: KeyboardEvent) {
+ const step = ARROW_STEPS[event.key]
+ if (!step || !(event.currentTarget instanceof HTMLElement)) return
+ event.preventDefault()
+ const items = [...event.currentTarget.querySelectorAll<HTMLElement>('[role=menuitemradio]')]
+ const current = items.indexOf(document.activeElement as HTMLElement)
+ items.at((current + step) % items.length)?.focus()
+}
+</script>
+
+<template>
+ <div role="menu" :aria-label="label" :class="styles.options()" @keydown="moveFocus">
+ <button
+ v-for="option in options"
+ :key="option.value"
+ type="button"
+ role="menuitemradio"
+ :aria-checked="option.value === selected"
+ :data-state="option.value === selected ? 'on' : 'off'"
+ :data-option="option.value"
+ :class="styles.option()"
+ @click="choose(option.value)"
+ >
+ <component :is="option.icon" v-if="option.icon" :class="styles.optionIcon()" />
+ {{ option.label }}
+ </button>
+ </div>
+</template>
diff --git a/src/components/figjam/toolbar/menu.ts b/src/components/figjam/toolbar/menu.ts
new file mode 100644
index 000000000..e9b331432
--- /dev/null
+++ b/src/components/figjam/toolbar/menu.ts
@@ -0,0 +1,13 @@
+import { noop } from 'es-toolkit'
+import { inject, type InjectionKey } from 'vue'
+
+/** Closes the toolbar menu a choice sits in. */
+export const CLOSE_TOOLBAR_MENU: InjectionKey<() => void> = Symbol('close toolbar menu')
+
+/**
+ * Closes the enclosing toolbar menu once a choice in it is made, as FigJam's menus do; outside a
+ * menu, such as in a panel, it does nothing.
+ */
+export function useCloseToolbarMenu(): () => void {
+ return inject(CLOSE_TOOLBAR_MENU, noop)
+}
diff --git a/src/components/toolbar/EditorToolbar.vue b/src/components/toolbar/EditorToolbar.vue
index 08e018e04..da8869eca 100644
--- a/src/components/toolbar/EditorToolbar.vue
+++ b/src/components/toolbar/EditorToolbar.vue
@@ -70,7 +70,8 @@ function onActionTap(item: ToolbarActionItem) {
<template>
<ToolbarRoot v-slot="{ activeTool, flyoutSelections, actions }" :tools="tools">
- <ToolbarContextMenu>
+ <!-- A profile that fixes the tools, as a board's does, has nothing to customize, as in FigJam. -->
+ <ToolbarContextMenu :disabled="profile.tools !== null">
<DesktopToolbar
v-if="!isMobile"
:items="items"
diff --git a/src/components/toolbar/ToolbarContextMenu.vue b/src/components/toolbar/ToolbarContextMenu.vue
index 58a14bf4c..2aa9b957d 100644
--- a/src/components/toolbar/ToolbarContextMenu.vue
+++ b/src/components/toolbar/ToolbarContextMenu.vue
@@ -13,14 +13,18 @@ import { openSettingsDialog } from '@/app/settings/dialog'
import { useMenuUI } from '@/components/ui/menu/menu'
import MenuScrollArea from '@/components/ui/menu/MenuScrollArea.vue'
-/** Right-clicking the toolbar offers its Settings page. */
+/**
+ * Right-clicking the toolbar offers its Settings page, unless the toolbar is `disabled` for
+ * customizing, as a board's fixed one is.
+ */
+const { disabled = false } = defineProps<{ disabled?: boolean }>()
const { settings } = useI18n()
const menu = useMenuUI({ content: 'w-48', item: 'justify-start gap-2' })
</script>
<template>
<ContextMenuRoot>
- <ContextMenuTrigger as-child>
+ <ContextMenuTrigger as-child :disabled="disabled">
<slot />
</ContextMenuTrigger>
<ContextMenuPortal>
diff --git a/src/theme/figjam/toolbar.ts b/src/theme/figjam/toolbar.ts
new file mode 100644
index 000000000..f325ab307
--- /dev/null
+++ b/src/theme/figjam/toolbar.ts
@@ -0,0 +1,22 @@
+const figJamToolbarTheme = {
+ slots: {
+ bar: 'flex h-10 max-w-[calc(100vw-16px)] items-center gap-0.5 overflow-x-auto px-1',
+ divider: 'mx-1 h-6 w-px shrink-0 bg-border',
+ trigger:
+ 'flex h-8 shrink-0 cursor-pointer items-center gap-0.5 rounded-md px-1.5 text-muted outline-none hover:bg-hover hover:text-surface focus-visible:ring-2 focus-visible:ring-accent/50 data-[state=open]:bg-hover data-[state=open]:text-surface',
+ triggerText: 'max-w-24 truncate text-xs text-surface',
+ chevron: 'size-3 shrink-0',
+ dot: 'size-4 shrink-0 rounded-full border border-border',
+ popover: 'z-50 p-2',
+ options: 'flex min-w-36 flex-col gap-0.5',
+ option:
+ 'flex h-7 cursor-pointer items-center gap-2 rounded px-2 text-left text-xs text-surface outline-none hover:bg-hover focus-visible:bg-hover data-[state=on]:bg-accent/15 data-[state=on]:text-primary',
+ optionIcon: 'size-4 shrink-0 text-muted',
+ group: 'grid gap-2',
+ groupLabel: 'text-[11px] text-muted',
+ segments: 'flex gap-1'
+ }
+}
+
+export type FigJamToolbarTheme = typeof figJamToolbarTheme
+export default figJamToolbarTheme
diff --git a/tests/e2e/canvas/board-chrome.spec.ts b/tests/e2e/canvas/board-chrome.spec.ts
new file mode 100644
index 000000000..220f4cae1
--- /dev/null
+++ b/tests/e2e/canvas/board-chrome.spec.ts
@@ -0,0 +1,122 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { boardDriver } from '#tests/helpers/canvas/board-driver'
+import { stickyDriver } from '#tests/helpers/canvas/sticky-driver'
+
+const editor = useEditorSetupWithClear()
+const board = boardDriver(() => editor.page)
+const sticky = stickyDriver(() => editor.page)
+
+test.beforeEach(async () => {
+ await editor.page.keyboard.press('Escape')
+ await board.open()
+ await sticky.showOrigin()
+})
+
+test.afterEach(() => board.close())
+
+const toolbar = () => editor.page.getByTestId('selection-toolbar')
+/** The toolbar menu that is open, not one still closing. */
+const openMenu = () => editor.page.locator('[data-menu][data-state=open]')
+
+async function lastNote() {
+ const note = (await sticky.notes()).at(-1)
+ if (!note) throw new Error('Missing sticky note')
+ return note
+}
+
+async function selectNoteAt(x: number, y: number) {
+ const point = sticky.point(x, y)
+ await editor.canvas.click(point.x, point.y)
+ await editor.canvas.waitForRender()
+}
+
+test('a board opens on the canvas and its tools, with the panels one click away', async () => {
+ await expect(editor.page.getByTestId('editor-show-ui')).toBeVisible()
+ await expect(editor.page.getByTestId('toolbar')).toBeVisible()
+ await expect(editor.page.getByRole('region', { name: 'Sticky note' })).toHaveCount(0)
+})
+
+// Live-checked in FigJam: its toolbar has no context menu, and a board's tools are fixed.
+test("a board's toolbar offers no customizing", async () => {
+ await editor.page.getByTestId('toolbar').click({ button: 'right' })
+ await expect(editor.page.getByRole('menu')).toHaveCount(0)
+})
+
+test("a selected note offers FigJam's choices over the canvas", async () => {
+ await sticky.add([{ x: 300, y: 200, text: 'Toolbar', author: 'Ada' }])
+ await selectNoteAt(320, 220)
+
+ await toolbar().locator('[data-property=toolbar-color]').click()
+ await openMenu().getByRole('radio', { name: 'Yellow', exact: true }).click()
+ await expect.poll(async () => (await lastNote()).fill).toBe('#ffe299')
+})
+
+// Measured in FigJam: text takes a palette colour as is, a section a pale tint of it.
+test('text and sections take their colour from the toolbar', async () => {
+ await board.addSelected('TEXT', 300, 200, 200, 40)
+ await toolbar().locator('[data-property=toolbar-color]').click()
+ await openMenu().getByRole('radio', { name: 'Red', exact: true }).click()
+ await expect.poll(board.selectedFill).toEqual([242, 72, 34])
+
+ await board.addSelected('SECTION', 300, 300, 400, 300)
+ await expect(toolbar()).toHaveAttribute('data-kind', 'section')
+ await toolbar().locator('[data-property=toolbar-color]').click()
+ await openMenu().getByRole('radio', { name: 'Red', exact: true }).click()
+ await expect.poll(board.selectedFill).toEqual([255, 226, 224])
+})
+
+// Measured in FigJam: a pick closes its menu, but a line colour leaves the line menu open.
+test('a toolbar menu closes on a pick, and the line menu stays for its colours', async () => {
+ await board.addSelected('SECTION', 300, 200, 400, 300)
+ await toolbar().locator('[data-property=toolbar-color]').click()
+ await openMenu().getByRole('radio', { name: 'Blue', exact: true }).click()
+ await expect(openMenu()).toHaveCount(0)
+
+ await toolbar().locator('[data-property=toolbar-line-style]').click()
+ await openMenu().getByRole('radio', { name: 'Red', exact: true }).click()
+ await expect(openMenu()).toHaveCount(1)
+ await openMenu().getByRole('menuitemradio', { name: 'Dashed' }).click()
+ await expect(openMenu()).toHaveCount(0)
+})
+
+test('several layers wrap into a new section from the toolbar', async () => {
+ await sticky.add([
+ { x: 300, y: 200, text: 'One', author: 'Ada' },
+ { x: 600, y: 200, text: 'Two', author: 'Ada' }
+ ])
+ await board.selectAll()
+ await toolbar().locator('[data-property=toolbar-wrap-section]').click()
+ await expect.poll(board.layerTypes).toEqual(['SECTION'])
+})
+
+test('the controls step aside while a note is dragged', async () => {
+ await sticky.add([{ x: 300, y: 200, text: 'Drag', author: 'Ada' }])
+ await selectNoteAt(320, 220)
+ await expect(toolbar()).toBeVisible()
+
+ const box = await editor.canvas.canvas.boundingBox()
+ if (!box) throw new Error('Missing canvas')
+ const start = sticky.point(320, 220)
+ await editor.page.mouse.move(box.x + start.x, box.y + start.y)
+ await editor.page.mouse.down()
+ await editor.page.mouse.move(box.x + start.x + 80, box.y + start.y + 40, { steps: 4 })
+ await expect(toolbar()).toHaveCount(0)
+ await editor.page.mouse.up()
+ await expect(toolbar()).toBeVisible()
+})
+
+test('with the panels open, the note is edited from them instead', async () => {
+ await sticky.add([{ x: 300, y: 200, text: 'Panels', author: 'Ada' }])
+ await editor.page.getByTestId('editor-show-ui').click()
+ await selectNoteAt(320, 220)
+
+ await expect(editor.page.getByRole('region', { name: 'Sticky note' })).toBeVisible()
+ await expect(toolbar()).toHaveCount(0)
+})
+
+test('the AI chat floats over the canvas alone', async () => {
+ await editor.page.getByTestId('editor-toggle-chat').click()
+ await expect(editor.page.getByTestId('floating-chat')).toBeVisible()
+ await editor.page.getByTestId('floating-chat-close').click()
+ await expect(editor.page.getByTestId('floating-chat')).toHaveCount(0)
+})
diff --git a/tests/e2e/canvas/board-dots-visual.spec.ts b/tests/e2e/canvas/board-dots-visual.spec.ts
index 1da43615a..74acbea8a 100644
--- a/tests/e2e/canvas/board-dots-visual.spec.ts
+++ b/tests/e2e/canvas/board-dots-visual.spec.ts
@@ -4,6 +4,8 @@ import { boardDriver } from '#tests/helpers/canvas/board-driver'
const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
const board = boardDriver(() => editor.page)
+test.afterEach(() => board.close())
+
// Figma desktop, FigJam board: #C4C4C4 dots, 2 units across, every 16 units from 50% and
// every 32 at 25%, under the layers.
for (const zoom of [1, 0.25]) {
diff --git a/tests/e2e/tools/shape-with-text.spec.ts b/tests/e2e/tools/shape-with-text.spec.ts
index 0619031e7..a73da7980 100644
--- a/tests/e2e/tools/shape-with-text.spec.ts
+++ b/tests/e2e/tools/shape-with-text.spec.ts
@@ -15,6 +15,8 @@ test.beforeEach(async () => {
await shapes.showOrigin()
})
+test.afterEach(() => board.close())
+
async function lastShape() {
const shape = (await shapes.shapes()).at(-1)
if (!shape) throw new Error('Missing shape with text')
diff --git a/tests/helpers/canvas/board-driver.ts b/tests/helpers/canvas/board-driver.ts
index 81041e3d9..defe87c43 100644
--- a/tests/helpers/canvas/board-driver.ts
+++ b/tests/helpers/canvas/board-driver.ts
@@ -14,6 +14,13 @@ export function boardDriver(page: () => Page) {
})
},
+ /** Makes the open document a design again, which reopens its panels, for the tests after. */
+ async close() {
+ await page().evaluate(() => {
+ window.openPencil?.getStore?.().setDocumentKind('design')
+ })
+ },
+
/** Shows the board at `zoom` with the canvas origin at the view's top-left corner. */
async showAt(zoom: number) {
await page().evaluate((zoom) => {
@@ -34,6 +41,54 @@ export function boardDriver(page: () => Page) {
},
{ x, y, width, height }
)
+ },
+
+ /** Adds a text layer or a section at canvas `x`,`y` and selects it. */
+ async addSelected(
+ type: 'TEXT' | 'SECTION',
+ x: number,
+ y: number,
+ width: number,
+ height: number
+ ) {
+ await page().evaluate(
+ ({ type, x, y, width, height }) => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const id = store.createShape(type, x, y, width, height)
+ if (type === 'TEXT') store.graph.updateNode(id, { text: 'Board text' })
+ store.select([id])
+ store.requestRender()
+ },
+ { type, x, y, width, height }
+ )
+ },
+
+ /** Selects every layer on the board's page. */
+ async selectAll() {
+ await page().evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ store.select(store.graph.getChildren(store.state.currentPageId).map((node) => node.id))
+ })
+ },
+
+ /** The first fill of the selected layer as 0–255 RGB, or null when it has none. */
+ async selectedFill() {
+ return page().evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ const id = store ? [...store.state.selectedIds][0] : undefined
+ const color = id ? store?.graph.getNode(id)?.fills[0]?.color : undefined
+ return color ? [color.r, color.g, color.b].map((c) => Math.round(c * 255)) : null
+ })
+ },
+
+ /** The types of the layers directly on the board's page, in order. */
+ async layerTypes() {
+ return page().evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ return store?.graph.getChildren(store.state.currentPageId).map((node) => node.type)
+ })
}
}
}
diff --git a/tools/checks/i18n/mixed-script-baseline.txt b/tools/checks/i18n/mixed-script-baseline.txt
index a38283264..26a02d1dd 100644
--- a/tools/checks/i18n/mixed-script-baseline.txt
+++ b/tools/checks/i18n/mixed-script-baseline.txt
@@ -159,6 +159,8 @@ ja:diagnostics.sharingUnofficialBuild
ja:diagnostics.sharingDisabledByEnvironment
ja:diagnostics.sharingQuestionTitle
ja:diagnostics.sharingQuestionDescription
+ja:editor.closeChat
+ja:editor.openChat
ja:editor.showUI
ja:editor.wideGamutUnavailable
ja:files.browserFileAPINotSupported
@@ -380,6 +382,8 @@ zh-cn:diagnostics.sharingUnofficialBuild
zh-cn:diagnostics.sharingDisabledByEnvironment
zh-cn:diagnostics.sharingQuestionTitle
zh-cn:diagnostics.sharingQuestionDescription
+zh-cn:editor.closeChat
+zh-cn:editor.openChat
zh-cn:editor.wideGamutUnavailable
zh-cn:files.browserFileAPINotSupported
zh-cn:files.clipboardImageFetchFailed