AI-native design editor. Open-source Figma alternative.
feat: colour, thicken, and dash connectors as FigJam's line menu does (#1329)
Danila Poyarkovc01ae0f213a0
diff --git a/changes/1235/added.md b/changes/1235/added.mdindex fe49899c6..184825a80 100644--- a/changes/1235/added.md+++ b/changes/1235/added.md@@ -1,2 +1,2 @@-- A connector tool, shown from Customize toolbar, draws connectors between layers or points. Their end handles reattach them, double-click types a label, the Design panel sets line type and end caps, and scripts and agents create and edit them through `figma.createConnector()` and `create_connector` (#616).+- A connector tool, shown from Customize toolbar, draws connectors between layers or points. Their end handles reattach them, double-click types a label, the Design panel sets their line type, end caps, and FigJam colour, weight, and dash, and scripts and agents create and edit them through `figma.createConnector()` and `create_connector` (#616).- Figma's filled triangle, diamond, and circle line caps draw instead of showing no head.diff --git a/packages/core/src/canvas/scene.ts b/packages/core/src/canvas/scene.tsindex 7d93d8372..3b341bb2e 100644--- a/packages/core/src/canvas/scene.ts+++ b/packages/core/src/canvas/scene.ts@@ -893,7 +893,7 @@ function paintNodeStrokes(node.type === 'VECTOR' &&node.vectorNetwork) {- const centerline = vectorNetworkToCenterlinePath(r.ck, node.vectorNetwork)+ const centerline = vectorNetworkToCenterlinePath(r.ck, node.vectorNetwork, node.cornerRadius)drawVectorPathStrokes(r, canvas, [centerline], stroke, color, node.strokeMiterLimit)centerline.delete()drawNodeArrowHeads(r, canvas, node, stroke, color)diff --git a/packages/core/src/editor/connectors/style.ts b/packages/core/src/editor/connectors/style.tsindex 9b651281e..a67ca5199 100644--- a/packages/core/src/editor/connectors/style.ts+++ b/packages/core/src/editor/connectors/style.ts@@ -1,6 +1,13 @@import {+ CONNECTOR_STROKE_WEIGHT,+ CONNECTOR_THICK_STROKE_WEIGHT,+ connectorLineStyleFields,+ connectorSublayers,+ figJamColor,layoutConnector,type ConnectorEndpoint,+ type ConnectorLineStyle,+ type FigJamColorName,type ConnectorLineType,type SceneNode,type StrokeCap@@ -16,7 +23,8 @@ function straightEnd(endpoint: ConnectorEndpoint | null): ConnectorEndpoint | nu}/**- * Connector commands from the Design panel: line type and caps. Each change records the+ * Connector commands from the Design panel: line type, caps, and the line's colour, weight and+ * dash, as FigJam's selection toolbar sets them. Each change records the* connectors' whole subtrees as one step, and the connectors route again.*/export function createConnectorStyleActions(ctx: EditorContext) {@@ -61,5 +69,35 @@ export function createConnectorStyleActions(ctx: EditorContext) {)}- return { setConnectorLineType, setConnectorCap }+ function restyleLine(label: string, ids: Iterable<string>, style: Partial<ConnectorLineStyle>) {+ edit(label, ids, (connector) => {+ const line = connectorSublayers(ctx.graph, connector)?.line+ if (line) ctx.graph.updateNode(line.id, connectorLineStyleFields(line, style))+ })+ }++ /** Draws the connectors' lines in palette colour `name`. */+ function setConnectorColor(ids: Iterable<string>, name: FigJamColorName) {+ restyleLine('Change connector color', ids, { color: figJamColor(name) })+ }++ /** Draws the connectors' lines Thick or Thin, as FigJam's line menu does. */+ function setConnectorThick(ids: Iterable<string>, thick: boolean) {+ restyleLine('Change connector weight', ids, {+ weight: thick ? CONNECTOR_THICK_STROKE_WEIGHT : CONNECTOR_STROKE_WEIGHT+ })+ }++ /** Dashes the connectors' lines or draws them solid. */+ function setConnectorDashed(ids: Iterable<string>, dashed: boolean) {+ restyleLine(dashed ? 'Dash connector' : 'Draw connector solid', ids, { dashed })+ }++ return {+ setConnectorLineType,+ setConnectorCap,+ setConnectorColor,+ setConnectorThick,+ setConnectorDashed+ }}diff --git a/packages/core/src/vector/centerline.ts b/packages/core/src/vector/centerline.tsindex 5cefc09b4..1f9fe9967 100644--- a/packages/core/src/vector/centerline.ts+++ b/packages/core/src/vector/centerline.ts@@ -186,7 +186,15 @@ function buildCenterlineFromCrescent(return path.detachAndDelete()}-export function vectorNetworkToCenterlinePath(ck: CanvasKit, network: VectorNetwork): Path {+/**+ * The path a dashed stroke runs along: a thin crescent's centre line, or the open segments with+ * their corners rounded by `cornerRadius`, as the solid stroke draws them.+ */+export function vectorNetworkToCenterlinePath(+ ck: CanvasKit,+ network: VectorNetwork,+ cornerRadius = 0+): Path {const { vertices, segments } = networkconst crescent = isClosedThinCrescent(network)@@ -196,6 +204,6 @@ export function vectorNetworkToCenterlinePath(ck: CanvasKit, network: VectorNetw}const path = new ck.PathBuilder()- addOpenSegmentsToPath(path, segments, vertices)+ addOpenSegmentsToPath(path, segments, vertices, cornerRadius)return path.detachAndDelete()}diff --git a/packages/core/tests/design-jsx/connectors.test.ts b/packages/core/tests/design-jsx/connectors.test.tsindex 5ce339c86..d58d120aa 100644--- a/packages/core/tests/design-jsx/connectors.test.ts+++ b/packages/core/tests/design-jsx/connectors.test.ts@@ -216,6 +216,8 @@ return <Frame name="Flow" w={800} h={400}>color: { r: 1, g: 0, b: 0 }})expect(dashedLine?.dashPattern).toEqual([6, 4])+ // The stroke draws with the dash too, or the line would stay solid on the canvas.+ expect(dashedLine?.strokes[0]?.dashPattern).toEqual([6, 4])const jsx = sceneNodeToJSX(result.id, graph)expect(jsx).toContain('<Connector from="A" to="B" strokeWidth={8} />')expect(jsx).toContain('<Connector from="A" to="B" stroke="#FF0000" dashPattern={[6, 4]} />')diff --git a/packages/core/tests/editor/connectors/style.test.ts b/packages/core/tests/editor/connectors/style.test.tsnew file mode 100644index 000000000..1240f157b--- /dev/null+++ b/packages/core/tests/editor/connectors/style.test.ts@@ -0,0 +1,51 @@+import { describe, expect, test } from 'bun:test'++import { expectDefined } from '#core-tests/helpers/assert'++import { createEditor } from '@open-pencil/core/editor'+import {+ boundEndpoint,+ buildConnectorSublayers,+ connectorSublayers,+ figJamColor+} from '@open-pencil/scene-graph'++function setup() {+ const editor = createEditor()+ const page = editor.state.currentPageId+ const from = editor.graph.createNode('RECTANGLE', page, { x: 0, y: 0, width: 100, height: 100 })+ const to = editor.graph.createNode('RECTANGLE', page, { x: 400, y: 0, width: 100, height: 100 })+ const connector = editor.graph.createNode('CONNECTOR', page, {+ connectorStart: boundEndpoint(from.id),+ connectorEnd: boundEndpoint(to.id)+ })+ buildConnectorSublayers(editor.graph, connector)+ const line = () =>+ expectDefined(+ connectorSublayers(editor.graph, expectDefined(editor.graph.getNode(connector.id)))+ ).line+ return { editor, connector, line }+}++// Values measured in FigJam's connector colour and line menus.+describe("FigJam's connector line menu", () => {+ test('a palette colour draws the line in it, as one step', () => {+ const { editor, connector, line } = setup()+ editor.setConnectorColor([connector.id], 'red')+ expect(line().strokes[0]?.color).toEqual(figJamColor('red'))+ editor.undo.undo()+ expect(line().strokes[0]?.color).not.toEqual(figJamColor('red'))+ })++ test('a dash follows the weight: 16/10 thin, 40/24 thick, on the stroke and the line', () => {+ const { editor, connector, line } = setup()+ editor.setConnectorDashed([connector.id], true)+ expect(line().strokes[0]).toMatchObject({ weight: 4, dashPattern: [16, 10] })+ expect(line().dashPattern).toEqual([16, 10])+ editor.setConnectorThick([connector.id], true)+ expect(line().strokes[0]).toMatchObject({ weight: 8, dashPattern: [40, 24] })+ editor.setConnectorDashed([connector.id], false)+ expect(line().strokes[0]?.dashPattern).toEqual([])+ expect(line().strokeWeight).toBe(8)+ })+})diff --git a/packages/design-jsx/src/connectors.ts b/packages/design-jsx/src/connectors.tsindex 99756f237..16f71e50d 100644--- a/packages/design-jsx/src/connectors.ts+++ b/packages/design-jsx/src/connectors.ts@@ -104,10 +104,12 @@ function styleLine(graph: SceneGraph, line: SceneNode, props: ConnectorPropValueconst [stroke = connectorStroke()] = line.strokesconst color = props.stroke ?? stroke.colorconst weight = props.strokeWidth ?? stroke.weight+ const dashPattern = props.dashPattern ?? line.dashPatterngraph.updateNode(line.id, {- strokes: [{ ...stroke, color, weight }],+ // The stroke draws with its own dash, and files keep the line's.+ strokes: [{ ...stroke, color, weight, dashPattern: [...dashPattern] }],strokeWeight: weight,- dashPattern: props.dashPattern ?? line.dashPattern+ dashPattern})}diff --git a/packages/design-jsx/src/elements.ts b/packages/design-jsx/src/elements.tsindex e98647cdd..86784b0f5 100644--- a/packages/design-jsx/src/elements.ts+++ b/packages/design-jsx/src/elements.ts@@ -274,6 +274,24 @@ export function elementProps(runtimeType: string): ReadonlySet<string> {return PROPS_BY_RUNTIME_TYPE.get(runtimeType) ?? LAYER_PROPS}+const BY_NAME = new Map(+ DESIGN_JSX_ELEMENTS.map((element): [string, DesignJSXElementDefinition] => [+ element.name,+ element+ ])+)++/**+ * The props an element written `<name>` takes, as the renderer checks them, for an editor that+ * checks them as they are typed; null for a name that is no element, and for an instance, which+ * also takes its component's properties by name.+ */+export function elementPropsByName(name: string): ReadonlySet<string> | null {+ const element = BY_NAME.get(name)+ if (!element) return Object.hasOwn(INTRINSIC_ELEMENTS, name) ? elementProps(name) : null+ return element.runtimeType === 'instance' ? null : elementProps(element.runtimeType)+}+/** The schema an element of `runtimeType` reads its props by, if it has one. */export function elementSchema(runtimeType: string): ElementPropsSchema | undefined {return BY_RUNTIME_TYPE.get(runtimeType)?.schemadiff --git a/packages/design-jsx/src/index.ts b/packages/design-jsx/src/index.tsindex 3ca9a6740..00c0e0b37 100644--- a/packages/design-jsx/src/index.ts+++ b/packages/design-jsx/src/index.ts@@ -89,7 +89,11 @@ export { createElement } from './mini-react'export { buildComponent, createDesignJSXRenderer, type DesignJSXRenderer } from './render'export type { ArtworkPlacement, DesignJSXServices, SVGSource } from './services'export type { RenderOptions } from './types'-export { DESIGN_JSX_ELEMENTS, type DesignJSXElementDefinition } from './elements'+export {+ DESIGN_JSX_ELEMENTS,+ elementPropsByName,+ type DesignJSXElementDefinition+} from './elements'export {DESIGN_JSX_HELPERS,DESIGN_JSX_PROPERTIES,diff --git a/packages/design-jsx/tests/elements.test.ts b/packages/design-jsx/tests/elements.test.tsindex e1ac6d876..dae6dbf9a 100644--- a/packages/design-jsx/tests/elements.test.ts+++ b/packages/design-jsx/tests/elements.test.ts@@ -1,6 +1,11 @@import { describe, expect, test } from 'bun:test'-import { DESIGN_JSX_ELEMENTS, elementSchema, elementTag } from '#design-jsx/elements'+import {+ DESIGN_JSX_ELEMENTS,+ elementPropsByName,+ elementSchema,+ elementTag+} from '#design-jsx/elements'import { createDesignJSXRenderer } from '#design-jsx/index'import { elementPropWarnings } from '#design-jsx/validation'@@ -52,4 +57,15 @@ describe('design JSX elements', () => {for (const type of element.writes ?? []) expect(elementTag(type)).toBe(element.name)}})++ test("an editor checks each element's own props, as the renderer does", () => {+ expect(elementPropsByName('Connector')?.has('from')).toBe(true)+ expect(elementPropsByName('Shape')?.has('kind')).toBe(true)+ expect(elementPropsByName('Sticky')?.has('author')).toBe(true)+ expect(elementPropsByName('Frame')?.has('from')).toBe(false)+ expect(elementPropsByName('div')?.has('bg')).toBe(true)+ // An instance also sets its component's properties, and a local component is no element.+ expect(elementPropsByName('Instance')).toBeNull()+ expect(elementPropsByName('Card')).toBeNull()+ })})diff --git a/packages/scene-graph/src/connectors/sublayers.ts b/packages/scene-graph/src/connectors/sublayers.tsindex ee205e840..bb5c11e73 100644--- a/packages/scene-graph/src/connectors/sublayers.ts+++ b/packages/scene-graph/src/connectors/sublayers.ts@@ -10,8 +10,57 @@ import type { ConnectorEndpoint, Fill, SceneNode, Stroke, VectorNetwork } from '*/export const CONNECTOR_COLOR: Color = { r: 117 / 255, g: 117 / 255, b: 117 / 255, a: 1 }export const CONNECTOR_STROKE_WEIGHT = 4+/** FigJam's line menu draws a connector Thin, at its default weight, or Thick, at twice it. */+export const CONNECTOR_THICK_STROKE_WEIGHT = 8export const CONNECTOR_CORNER_RADIUS = 24+/** The dash FigJam's line menu draws a connector with, longer for a thick line. Measured in FigJam. */+export function connectorDash(weight: number): number[] {+ return weight >= CONNECTOR_THICK_STROKE_WEIGHT ? [40, 24] : [16, 10]+}++/** How a connector's line is drawn: its colour, weight, and whether it is dashed. */+export interface ConnectorLineStyle {+ color: Color+ weight: number+ dashed: boolean+}++/** The style a connector's line is drawn in. */+export function connectorLineStyle(line: Pick<SceneNode, 'strokes'>): ConnectorLineStyle {+ const stroke = line.strokes.at(0) ?? connectorStroke()+ return {+ color: { ...stroke.color },+ weight: stroke.weight,+ dashed: (stroke.dashPattern?.length ?? 0) > 0+ }+}++/**+ * A connector's line restyled by `style`, each part left out kept, as FigJam's colour and line+ * menus set it. A new weight or dash takes FigJam's dash for the weight, while a new colour alone+ * keeps the dash the line has, even one of its own. The dash goes on the stroke, which draws with+ * it, and on the line, which files keep.+ */+export function connectorLineStyleFields(+ line: Pick<SceneNode, 'strokes'>,+ style: Partial<ConnectorLineStyle>+): Partial<SceneNode> {+ const current = connectorLineStyle(line)+ const color = style.color ?? current.color+ const weight = style.weight ?? current.weight+ const dashed = style.dashed ?? current.dashed+ const [stroke = connectorStroke()] = line.strokes+ const restyled = style.weight !== undefined || style.dashed !== undefined+ const kept = stroke.dashPattern?.length ? [...stroke.dashPattern] : connectorDash(weight)+ const dashPattern = dashed ? (restyled ? connectorDash(weight) : kept) : []+ return {+ strokes: [{ ...stroke, color: { ...color }, weight, dashPattern: [...dashPattern] }],+ strokeWeight: weight,+ dashPattern+ }+}+export function connectorStroke(color: Color = CONNECTOR_COLOR): Stroke {return {type: 'SOLID',diff --git a/packages/scene-graph/tests/connectors/sublayers.test.ts b/packages/scene-graph/tests/connectors/sublayers.test.tsnew file mode 100644index 000000000..6692db052--- /dev/null+++ b/packages/scene-graph/tests/connectors/sublayers.test.ts@@ -0,0 +1,33 @@+import { describe, expect, test } from 'bun:test'++import {+ connectorDash,+ connectorLineStyle,+ connectorLineStyleFields,+ connectorStroke+} from '@open-pencil/scene-graph'++describe('connector line style', () => {+ test("FigJam's dash is longer for a thick line", () => {+ expect(connectorDash(4)).toEqual([16, 10])+ expect(connectorDash(8)).toEqual([40, 24])+ })++ test('a restyle keeps what it leaves out and reads back as set', () => {+ const line = { strokes: [connectorStroke()] }+ const thick = { ...line, ...connectorLineStyleFields(line, { weight: 8, dashed: true }) }+ expect(connectorLineStyle(thick)).toMatchObject({ weight: 8, dashed: true })+ expect(thick.strokes[0]).toMatchObject({ cap: 'ROUND', join: 'ROUND' })+ const solid = connectorLineStyleFields(thick, { dashed: false })+ expect(solid).toMatchObject({ strokeWeight: 8, dashPattern: [] })+ })++ test('a new colour alone keeps a dash of its own', () => {+ const line = { strokes: [{ ...connectorStroke(), dashPattern: [6, 4] }] }+ const red = connectorLineStyleFields(line, { color: { r: 1, g: 0, b: 0, a: 1 } })+ expect(red.dashPattern).toEqual([6, 4])+ expect(red.strokes?.[0]?.dashPattern).toEqual([6, 4])+ // A new weight takes FigJam's dash for it.+ expect(connectorLineStyleFields(line, { weight: 8 }).dashPattern).toEqual([40, 24])+ })+})diff --git a/packages/vue/src/controls/connector/use.ts b/packages/vue/src/controls/connector/use.tsindex 6502a708d..544941446 100644--- a/packages/vue/src/controls/connector/use.ts+++ b/packages/vue/src/controls/connector/use.ts@@ -1,14 +1,25 @@import { computed } from 'vue'-import type { ConnectorLineType, SceneNode, StrokeCap } from '@open-pencil/scene-graph'+import {+ CONNECTOR_THICK_STROKE_WEIGHT,+ connectorLineStyle,+ connectorSublayers,+ figJamColorName+} from '@open-pencil/scene-graph'+import type {+ ConnectorLineType,+ FigJamColorName,+ SceneNode,+ StrokeCap+} from '@open-pencil/scene-graph'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 selected connectors: their line type and the caps at their- * ends. A selection of several connectors reads its first and edits them all.+ * Headless state and actions for selected connectors: their line type, the caps at their ends,+ * and their line's FigJam colour, weight and dash. A selection of several connectors reads its first and edits them all.*/export function useConnector() {const editor = useEditor()@@ -30,6 +41,14 @@ export function useConnector() {() => connectors.value.at(0)?.connectorStartCap ?? null)const endCap = computed<StrokeCap | null>(() => connectors.value.at(0)?.connectorEndCap ?? null)+ const lineStyle = useSceneComputed(() => {+ const first = connectors.value.at(0)+ const line = first && connectorSublayers(editor.graph, first)?.line+ return line ? connectorLineStyle(line) : null+ })+ const color = computed<FigJamColorName | null>(() => figJamColorName(lineStyle.value?.color))+ const thick = computed(() => (lineStyle.value?.weight ?? 0) >= CONNECTOR_THICK_STROKE_WEIGHT)+ const dashed = computed(() => lineStyle.value?.dashed ?? false)function setLineType(value: ConnectorLineType) {editor.setConnectorLineType(ids.value, value)@@ -43,5 +62,31 @@ export function useConnector() {editor.setConnectorCap(ids.value, 'end', value)}- return { active, lineType, startCap, endCap, setLineType, setStartCap, setEndCap }+ function setColor(value: FigJamColorName) {+ editor.setConnectorColor(ids.value, value)+ }++ function setThick(value: boolean) {+ editor.setConnectorThick(ids.value, value)+ }++ function setDashed(value: boolean) {+ editor.setConnectorDashed(ids.value, value)+ }++ return {+ active,+ lineType,+ startCap,+ endCap,+ color,+ thick,+ dashed,+ setLineType,+ setStartCap,+ setEndCap,+ setColor,+ setThick,+ setDashed+ }}diff --git a/packages/vue/src/i18n/locales/de/panels.json b/packages/vue/src/i18n/locales/de/panels.jsonindex 248589cbc..d627ce5d7 100644--- a/packages/vue/src/i18n/locales/de/panels.json+++ b/packages/vue/src/i18n/locales/de/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "Kreispfeil","connector": "Verbinder","connectorLine": "Linie",+ "connectorColor": "Farbe",+ "connectorThick": "Dick",+ "connectorDashed": "Gestrichelt","connectorElbowed": "Gewinkelt","connectorStraight": "Gerade","connectorCurved": "Gebogen",diff --git a/packages/vue/src/i18n/locales/es/panels.json b/packages/vue/src/i18n/locales/es/panels.jsonindex c3c1dc0bb..490ab0557 100644--- a/packages/vue/src/i18n/locales/es/panels.json+++ b/packages/vue/src/i18n/locales/es/panels.json@@ -245,6 +245,9 @@"strokeCapCircleFilled": "Flecha circular","connector": "Conector","connectorLine": "Línea",+ "connectorColor": "Color",+ "connectorThick": "Gruesa",+ "connectorDashed": "Discontinua","connectorElbowed": "En ángulo","connectorStraight": "Recta","connectorCurved": "Curva",diff --git a/packages/vue/src/i18n/locales/fr/panels.json b/packages/vue/src/i18n/locales/fr/panels.jsonindex 66d42d623..eff6310c5 100644--- a/packages/vue/src/i18n/locales/fr/panels.json+++ b/packages/vue/src/i18n/locales/fr/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "Flèche cercle","connector": "Connecteur","connectorLine": "Ligne",+ "connectorColor": "Couleur",+ "connectorThick": "Épais",+ "connectorDashed": "Tirets","connectorElbowed": "Coudée","connectorStraight": "Droite","connectorCurved": "Courbe",diff --git a/packages/vue/src/i18n/locales/it/panels.json b/packages/vue/src/i18n/locales/it/panels.jsonindex bf03af46d..cb5e85b35 100644--- a/packages/vue/src/i18n/locales/it/panels.json+++ b/packages/vue/src/i18n/locales/it/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "Freccia a cerchio","connector": "Connettore","connectorLine": "Linea",+ "connectorColor": "Colore",+ "connectorThick": "Spessa",+ "connectorDashed": "Tratteggiata","connectorElbowed": "Ad angolo","connectorStraight": "Dritta","connectorCurved": "Curva",diff --git a/packages/vue/src/i18n/locales/ja/panels.json b/packages/vue/src/i18n/locales/ja/panels.jsonindex beac08144..099810aff 100644--- a/packages/vue/src/i18n/locales/ja/panels.json+++ b/packages/vue/src/i18n/locales/ja/panels.json@@ -245,6 +245,9 @@"strokeCapCircleFilled": "円矢印","connector": "コネクタ","connectorLine": "線",+ "connectorColor": "色",+ "connectorThick": "太線",+ "connectorDashed": "破線","connectorElbowed": "折れ線","connectorStraight": "直線","connectorCurved": "曲線",diff --git a/packages/vue/src/i18n/locales/pl/panels.json b/packages/vue/src/i18n/locales/pl/panels.jsonindex 1cdb4597a..ebda5ba1b 100644--- a/packages/vue/src/i18n/locales/pl/panels.json+++ b/packages/vue/src/i18n/locales/pl/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "Strzałka okrągła","connector": "Łącznik","connectorLine": "Linia",+ "connectorColor": "Kolor",+ "connectorThick": "Gruba",+ "connectorDashed": "Przerywana","connectorElbowed": "Łamana","connectorStraight": "Prosta","connectorCurved": "Zakrzywiona",diff --git a/packages/vue/src/i18n/locales/ru/panels.json b/packages/vue/src/i18n/locales/ru/panels.jsonindex 6b2904f8a..0eafdb71c 100644--- a/packages/vue/src/i18n/locales/ru/panels.json+++ b/packages/vue/src/i18n/locales/ru/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "Круглая стрелка","connector": "Соединитель","connectorLine": "Линия",+ "connectorColor": "Цвет",+ "connectorThick": "Толстая",+ "connectorDashed": "Пунктирная","connectorElbowed": "Ломаная","connectorStraight": "Прямая","connectorCurved": "Изогнутая",diff --git a/packages/vue/src/i18n/locales/zh-cn/panels.json b/packages/vue/src/i18n/locales/zh-cn/panels.jsonindex 6e2eb0978..b6cb5b4d7 100644--- a/packages/vue/src/i18n/locales/zh-cn/panels.json+++ b/packages/vue/src/i18n/locales/zh-cn/panels.json@@ -227,6 +227,9 @@"strokeCapCircleFilled": "圆形箭头","connector": "连接线","connectorLine": "线条",+ "connectorColor": "颜色",+ "connectorThick": "粗",+ "connectorDashed": "虚线","connectorElbowed": "折线","connectorStraight": "直线","connectorCurved": "曲线",diff --git a/packages/vue/src/i18n/messages/panels.ts b/packages/vue/src/i18n/messages/panels.tsindex bbf4333ab..37ee0d0ab 100644--- a/packages/vue/src/i18n/messages/panels.ts+++ b/packages/vue/src/i18n/messages/panels.ts@@ -448,6 +448,9 @@ export const panelMessageDefaults = {strokeCapCircleFilled: 'Circle arrow',connector: 'Connector',connectorLine: 'Line',+ connectorColor: 'Color',+ connectorThick: 'Thick',+ connectorDashed: 'Dashed',connectorElbowed: 'Elbowed',connectorStraight: 'Straight',connectorCurved: 'Curved',diff --git a/src/components/DesignPanel.vue b/src/components/DesignPanel.vueindex ae27093f9..10fc642c6 100644--- a/src/components/DesignPanel.vue+++ b/src/components/DesignPanel.vue@@ -6,9 +6,9 @@ import { layerResizes, readIcon } from '@open-pencil/scene-graph'import { useI18n, useSceneComputed, useSelectionState, useEditorCommands } from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'-import { COMPONENT_TYPES, sceneNodeIcon } from '@/app/editor/icons'import { openVariablesDialog } from '@/app/editor/tokens/dialog'import { openLibraryReview, useLibraryService } from '@/app/libraries'+import { COMPONENT_TYPES, sceneNodeIcon } from '@/components/icons'import IconButton from '@/components/ui/button/IconButton.vue'import Tip from '@/components/ui/overlay/Tip.vue'import PanelHeader from '@/components/ui/panel/PanelHeader.vue'diff --git a/src/components/LayerTree/LayerTreeNodeRow.vue b/src/components/LayerTree/LayerTreeNodeRow.vueindex 1a206b500..7821793b7 100644--- a/src/components/LayerTree/LayerTreeNodeRow.vue+++ b/src/components/LayerTree/LayerTreeNodeRow.vue@@ -6,8 +6,8 @@ import type { LayerNode } from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'import type { LayerIssueMark as LayerIssueMarkData } from '@/app/editor/design-check/layers'-import { COMPONENT_TYPES, nodeIcon } from '@/app/editor/icons'import LayerIssueMark from '@/components/design-check/LayerIssueMark.vue'+import { COMPONENT_TYPES, nodeIcon } from '@/components/icons'import layerTreeTheme from '@/theme/layer-tree'import LayerTreeActions from './LayerTreeActions.vue'diff --git a/src/components/LayerTree/LayerTreeRenameRow.vue b/src/components/LayerTree/LayerTreeRenameRow.vueindex f88bed5bb..ba3e27fef 100644--- a/src/components/LayerTree/LayerTreeRenameRow.vue+++ b/src/components/LayerTree/LayerTreeRenameRow.vue@@ -4,7 +4,7 @@ import { computed, useTemplateRef, watch } from 'vue'import { useI18n, type LayerNode } from '@open-pencil/vue'-import { nodeIcon } from '@/app/editor/icons'+import { nodeIcon } from '@/components/icons'import layerTreeTheme from '@/theme/layer-tree'import LayerTreeDisclosure from './LayerTreeDisclosure.vue'diff --git a/src/components/MobileHud/context.ts b/src/components/MobileHud/context.tsindex ceda51f91..d0b7d9fb6 100644--- a/src/components/MobileHud/context.ts+++ b/src/components/MobileHud/context.ts@@ -11,7 +11,6 @@ import { useEditorCommands, useI18n } from '@open-pencil/vue'import { isCloudBinding, openCloudShare } from '@/app/cloud/integration'import { DEFAULT_COLLAB_STATE, useCollabInjected } from '@/app/collab/use'import { useActiveEditorStoreRef, useEditorStore } from '@/app/editor/active-store'-import { toolIcons } from '@/app/editor/icons'import { useNotificationMessages } from '@/app/i18n/notifications'import { presenceOf, renameAgent as renameLocalAgent } from '@/app/presence/registry'import type { FollowTarget } from '@/app/presence/types'@@ -19,6 +18,7 @@ import { openFileDialog } from '@/app/shell/menu/use'import { useSendLink } from '@/app/shell/share/link'import { toast } from '@/app/shell/ui'import { roomStatusText } from '@/components/collab-room/statusText'+import { toolIcons } from '@/components/icons'import { presenceRows } from '@/components/presence/rows'import type { ToolbarActionItem } from '@/components/toolbar/types'import { getShareURL } from '@/constants'diff --git a/src/components/assets-panel/AssetsPanel.vue b/src/components/assets-panel/AssetsPanel.vueindex 44c5f262f..6299ec227 100644--- a/src/components/assets-panel/AssetsPanel.vue+++ b/src/components/assets-panel/AssetsPanel.vue@@ -16,11 +16,11 @@ import { createDefaultNode } from '@open-pencil/scene-graph/node-defaults'import { useI18n } from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'-import { nodeIcon } from '@/app/editor/icons'import { useLibraryService } from '@/app/libraries'import { openExternalLink } from '@/app/shell/ui'import AssetThumbnail from '@/components/assets-panel/AssetThumbnail.vue'import { findAssetPage } from '@/components/assets-panel/page'+import { nodeIcon } from '@/components/icons'import LibraryManagerDialog from '@/components/libraries/LibraryManagerDialog.vue'import { useLibraryEntry } from '@/components/libraries/useLibraryEntry'import AppButton from '@/components/ui/button/AppButton.vue'diff --git a/src/components/code-editor/extensions.ts b/src/components/code-editor/extensions.tsindex 11a336f08..30d43171f 100644--- a/src/components/code-editor/extensions.ts+++ b/src/components/code-editor/extensions.ts@@ -8,7 +8,8 @@ import type { EditorView } from '@codemirror/view'import {DESIGN_JSX_ELEMENTS,DESIGN_JSX_HELPERS,- DESIGN_JSX_PROPERTIES+ DESIGN_JSX_PROPERTIES,+ elementPropsByName} from '@open-pencil/design-jsx'const ELEMENTS = DESIGN_JSX_ELEMENTS.map(({ name }) => name)@@ -51,6 +52,42 @@ function localComponentNames(view: EditorView): Set<string> {return names}+/** A node of the parsed JSX. */+type SyntaxNode = ReturnType<typeof syntaxTree>['topNode']++/** Props the JSX runtime takes on any element rather than passing them on. */+const RUNTIME_PROPS: ReadonlySet<string> = new Set(['key', 'ref'])++const TAG_NAME_NODES: ReadonlySet<string> = new Set([+ 'JSXIdentifier',+ 'JSXBuiltin',+ 'JSXMemberExpression',+ 'JSXNamespacedName'+])++/** The name of the tag an attribute is written on, such as `Connector` or `Switch.Root`. */+function attributeTagName(view: EditorView, attribute: SyntaxNode | null): string | null {+ for (let child = attribute?.parent?.firstChild; child; child = child.nextSibling) {+ if (child.name === 'JSXAttribute') return null+ if (TAG_NAME_NODES.has(child.name)) return view.state.doc.sliceString(child.from, child.to)+ }+ return null+}++/**+ * Whether the element an attribute is written on takes it, as the renderer checks it: each+ * element its own props, and an instance or a local component whatever it is given.+ */+function knownAttribute(view: EditorView, name: string, attribute: SyntaxNode | null): boolean {+ if (RUNTIME_PROPS.has(name)) return true+ const tag = attributeTagName(view, attribute)+ if (!tag) return PROPERTY_SET.has(name)+ const props = elementPropsByName(tag)+ if (props) return props.has(name)+ // An instance's or a local component's props are its own to name.+ return !/^[a-z]/.test(tag) || PROPERTY_SET.has(name)+}+function semanticDiagnostics(view: EditorView): Diagnostic[] {const diagnostics: Diagnostic[] = []const knownElements = new Set([...BUILTIN_ELEMENTS, ...localComponentNames(view)])@@ -60,7 +97,7 @@ function semanticDiagnostics(view: EditorView): Diagnostic[] {if (node.name !== 'JSXIdentifier') returnconst parentName = node.node.parent?.nameconst name = view.state.doc.sliceString(node.from, node.to)- if (parentName === 'JSXAttribute' && !PROPERTY_SET.has(name)) {+ if (parentName === 'JSXAttribute' && !knownAttribute(view, name, node.node.parent)) {diagnostics.push({from: node.from,to: node.to,diff --git a/src/components/design-check/IssueMarkerTooltip.vue b/src/components/design-check/IssueMarkerTooltip.vueindex e127ec807..e0e0e695c 100644--- a/src/components/design-check/IssueMarkerTooltip.vue+++ b/src/components/design-check/IssueMarkerTooltip.vue@@ -15,7 +15,7 @@ import { useDesignCheckMessages } from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'import { issueDetail, ruleTitle } from '@/app/editor/design-check/format'import { compareIssueSeverity, type DesignIssue } from '@/app/editor/design-check/issues'-import { sceneNodeIcon } from '@/app/editor/icons'+import { sceneNodeIcon } from '@/components/icons'import SeverityIcon from '@/components/ui/feedback/SeverityIcon.vue'import { issueTooltip } from '@/theme/design-check'diff --git a/src/components/design-check/rows.ts b/src/components/design-check/rows.tsindex 65e052e1d..b3468cd23 100644--- a/src/components/design-check/rows.ts+++ b/src/components/design-check/rows.ts@@ -9,7 +9,7 @@ import {type DesignCheckMessages} from '@/app/editor/design-check/format'import type { DesignIssue, DesignIssueGroup } from '@/app/editor/design-check/issues'-import { IconFrame, sceneNodeIcon } from '@/app/editor/icons'+import { IconFrame, sceneNodeIcon } from '@/components/icons'import type { IssueGroupView, IssueRowView } from './types'diff --git a/src/components/figjam/FigJamPalette.vue b/src/components/figjam/FigJamPalette.vueindex 10e8cbb53..e96cc3d3e 100644--- a/src/components/figjam/FigJamPalette.vue+++ b/src/components/figjam/FigJamPalette.vue@@ -7,13 +7,21 @@ import { useFigJamMessages } from '@open-pencil/vue'import Swatches from './Swatches.vue'-/** FigJam's board palette in its menus' order, closed by a swatch for no colour at all. */-const { label, selected, noneLabel, none } = defineProps<{+/**+ * FigJam's board palette in its menus' order, closed, when `noneLabel` is given, by a swatch for+ * no colour at all.+ */+const {+ label,+ selected,+ noneLabel,+ none = false+} = defineProps<{label: stringselected: FigJamColorName | null- noneLabel: string+ noneLabel?: string/** Whether no colour is shown, which the none swatch marks. */- none: boolean+ none?: boolean}>()const emit = defineEmits<{ select: [name: FigJamColorName]; none: [] }>()const figjam = useFigJamMessages()@@ -58,7 +66,7 @@ const swatches = computed(() =>:label="label":swatches="swatches":selected="selected"- :none="{ label: noneLabel, active: none }"+ :none="noneLabel ? { label: noneLabel, active: none } : undefined"@select="emit('select', $event)"@none="emit('none')"/>diff --git a/src/components/icons/connectors.ts b/src/components/icons/connectors.tsnew file mode 100644index 000000000..685940016--- /dev/null+++ b/src/components/icons/connectors.ts@@ -0,0 +1,99 @@+import type { FunctionalComponent } from 'vue'++import type { ConnectorLineType, StrokeCap } from '@open-pencil/scene-graph'+import {+ arrowLinesSegments,+ circleCapRadius,+ diamondCapPoints,+ equilateralArrowPoints,+ triangleCapPoints+} from '@open-pencil/scene-graph/arrow-caps'+import type { Vector } from '@open-pencil/scene-graph/primitives'++import { maskIcon } from './mask'++/** The icon box, and the weight its line is drawn at, as lucide draws its icons. */+const BOX = 24+const WEIGHT = 1.5+/** The weight the heads are sized by: larger than the line's, so they read at icon size. */+const HEAD_WEIGHT = 2+/** Where the line's capped end sits, leaving room for the largest head. */+const TIP = 18+const TAIL = 3++const round = (value: number) => Math.round(value * 100) / 100++function polygon(points: readonly Vector[]): string {+ return `<path d="M${points.map((point) => `${round(point.x)} ${round(point.y)}`).join('L')}Z"/>`+}++/** A cap's head at the line's right end, drawn from the geometry the canvas draws it from. */+function head(cap: StrokeCap): string {+ const y = BOX / 2+ switch (cap) {+ case 'ARROW_LINES': {+ const [first, second] = arrowLinesSegments(TIP, y, 0, HEAD_WEIGHT)+ const d = `M${round(first.to.x)} ${round(first.to.y)}L${TIP} ${y}L${round(second.to.x)} ${round(second.to.y)}`+ return `<path d="${d}" fill="none" stroke="black" stroke-width="${WEIGHT}" stroke-linecap="round" stroke-linejoin="round"/>`+ }+ case 'ARROW_EQUILATERAL':+ return polygon(equilateralArrowPoints(TIP, y, 0, HEAD_WEIGHT))+ case 'TRIANGLE_FILLED':+ return polygon(triangleCapPoints(TIP, y, 0, HEAD_WEIGHT))+ case 'DIAMOND_FILLED':+ return polygon(diamondCapPoints(TIP, y, 0, HEAD_WEIGHT))+ case 'CIRCLE_FILLED':+ return `<circle cx="${TIP}" cy="${y}" r="${round(circleCapRadius(HEAD_WEIGHT))}"/>`+ default:+ return ''+ }+}++/** A short line ending in `cap`, pointing right, or left for a start point. */+function capSVG(cap: StrokeCap, side: 'start' | 'end'): string {+ const y = BOX / 2+ const shaft = `<path d="M${TAIL} ${y}H${TIP}" fill="none" stroke="black" stroke-width="${WEIGHT}" stroke-linecap="round"/>`+ const flip = side === 'start' ? ` transform="matrix(-1 0 0 1 ${BOX} 0)"` : ''+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${BOX} ${BOX}"><g${flip}>${shaft}${head(cap)}</g></svg>`+}++/** Each line type as FigJam's line shape menu draws it. */+const LINE_TYPE_PATHS: Record<ConnectorLineType, string> = {+ ELBOWED: 'M3 6H9A3 3 0 0 1 12 9V15A3 3 0 0 0 15 18H21',+ CURVED: 'M3 6C13 6 11 18 21 18',+ STRAIGHT: 'M3 18L21 6'+}++function lineTypeSVG(type: ConnectorLineType): string {+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${BOX} ${BOX}"><path d="${LINE_TYPE_PATHS[type]}" fill="none" stroke="black" stroke-width="${WEIGHT}" stroke-linecap="round" stroke-linejoin="round"/></svg>`+}++const CAPS: readonly StrokeCap[] = [+ 'NONE',+ 'ARROW_LINES',+ 'ARROW_EQUILATERAL',+ 'TRIANGLE_FILLED',+ 'DIAMOND_FILLED',+ 'CIRCLE_FILLED'+]++const CAP_ICONS = {+ start: new Map(CAPS.map((cap) => [cap, maskIcon(capSVG(cap, 'start'))])),+ end: new Map(CAPS.map((cap) => [cap, maskIcon(capSVG(cap, 'end'))]))+}++/** The icon for a connector's cap at its start or end, drawn as the canvas draws the head. */+export function connectorCapIcon(+ cap: StrokeCap,+ side: 'start' | 'end'+): FunctionalComponent | undefined {+ return CAP_ICONS[side].get(cap)+}++/** Each line type's icon. */+export const CONNECTOR_LINE_TYPE_ICONS = Object.fromEntries(+ (Object.keys(LINE_TYPE_PATHS) as ConnectorLineType[]).map((type) => [+ type,+ maskIcon(lineTypeSVG(type))+ ])+) as Record<ConnectorLineType, FunctionalComponent>diff --git a/src/app/editor/icons.ts b/src/components/icons/index.tssimilarity index 96%rename from src/app/editor/icons.tsrename to src/components/icons/index.tsindex 2673e356e..cb840cfed 100644--- a/src/app/editor/icons.ts+++ b/src/components/icons/index.ts@@ -26,9 +26,9 @@ import IconType from '~icons/lucide/type'import { readIcon, slotPropertyId, type SceneNode } from '@open-pencil/scene-graph'import type { ShapeWithTextType } from '@open-pencil/scene-graph/shape-with-text'+import type { Tool } from '@open-pencil/vue'-import type { Tool } from '@/app/editor/session'-import { SHAPE_KIND_ICONS } from '@/app/editor/shape-icons'+import { SHAPE_KIND_ICONS } from './shapes'export const toolIcons: Record<Tool, Component> = {SELECT: IconMousePointer,diff --git a/src/components/icons/mask.ts b/src/components/icons/mask.tsnew file mode 100644index 000000000..1eb57acf3--- /dev/null+++ b/src/components/icons/mask.ts@@ -0,0 +1,20 @@+import { h, type FunctionalComponent } from 'vue'++/**+ * An icon drawn from `svg` in the text color through a mask, so the markup never runs in the+ * page; the caller's class sizes it. For icons drawn from scene geometry, such as a shape's+ * outline or a connector's cap, that no icon set has.+ */+export function maskIcon(svg: string): FunctionalComponent {+ const mask = `url("data:image/svg+xml,${encodeURIComponent(svg)}")`+ return (_props, { attrs }) =>+ h('span', {+ ...attrs,+ 'aria-hidden': 'true',+ class: [+ 'inline-block shrink-0 bg-current mask-(--mask-icon) mask-contain mask-center mask-no-repeat',+ attrs.class+ ],+ style: { '--mask-icon': mask }+ })+}diff --git a/src/app/editor/shape-icons.ts b/src/components/icons/shapes.tssimilarity index 70%rename from src/app/editor/shape-icons.tsrename to src/components/icons/shapes.tsindex 04473668c..ffadda18b 100644--- a/src/app/editor/shape-icons.ts+++ b/src/components/icons/shapes.ts@@ -1,4 +1,4 @@-import { h, type FunctionalComponent } from 'vue'+import type { FunctionalComponent } from 'vue'import { outlineSVGPath, type PolygonOutlineCommand } from '@open-pencil/scene-graph/polygon'import {@@ -7,6 +7,8 @@ import {type ShapeWithTextType} from '@open-pencil/scene-graph/shape-with-text'+import { maskIcon } from './mask'+/** The icon box, and the outline inside it, as lucide draws its icons. */const BOX = 24const INSET = 3@@ -41,23 +43,10 @@ export function shapeKindIconSVG(kind: ShapeWithTextType): string {return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${BOX} ${BOX}" fill="none" stroke="black" stroke-width="${STROKE}" stroke-linejoin="round">${paths}</svg>`}-/**- * Each kind's outline as an icon component, drawn in the text color through a mask so the- * markup never runs in the page; the caller's class sizes it.- */+/** Each kind's outline as an icon component. */export const SHAPE_KIND_ICONS = Object.fromEntries(- SHAPE_WITH_TEXT_TYPES.map((kind): [ShapeWithTextType, FunctionalComponent] => {- const mask = `url("data:image/svg+xml,${encodeURIComponent(shapeKindIconSVG(kind))}")`- const icon: FunctionalComponent = (_props, { attrs }) =>- h('span', {- ...attrs,- 'aria-hidden': 'true',- class: [- 'inline-block shrink-0 bg-current mask-(--shape-kind) mask-contain mask-center mask-no-repeat',- attrs.class- ],- style: { '--shape-kind': mask }- })- return [kind, icon]- })+ SHAPE_WITH_TEXT_TYPES.map((kind): [ShapeWithTextType, FunctionalComponent] => [+ kind,+ maskIcon(shapeKindIconSVG(kind))+ ])) as Record<ShapeWithTextType, FunctionalComponent>diff --git a/src/components/properties/LayerTypeMenu.vue b/src/components/properties/LayerTypeMenu.vueindex c045e6609..e096ff6df 100644--- a/src/components/properties/LayerTypeMenu.vue+++ b/src/components/properties/LayerTypeMenu.vue@@ -15,7 +15,7 @@ import type { SceneNode } from '@open-pencil/scene-graph'import { useI18n, useRetainedPopup } from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'-import { NODE_ICONS } from '@/app/editor/icons'+import { NODE_ICONS } from '@/components/icons'import { menuItem, useMenuUI } from '@/components/ui/menu/menu'import MenuScrollArea from '@/components/ui/menu/MenuScrollArea.vue'import Tip from '@/components/ui/overlay/Tip.vue'diff --git a/src/components/properties/component-properties/PropertyBindingRow.vue b/src/components/properties/component-properties/PropertyBindingRow.vueindex 543b1e0f7..0414a623f 100644--- a/src/components/properties/component-properties/PropertyBindingRow.vue+++ b/src/components/properties/component-properties/PropertyBindingRow.vue@@ -2,7 +2,7 @@import type { ComponentBinding } from '@open-pencil/vue'import { usePanelMessages } from '@open-pencil/vue'-import { sceneNodeIcon } from '@/app/editor/icons'+import { sceneNodeIcon } from '@/components/icons'import AppButton from '@/components/ui/button/AppButton.vue'import IconButton from '@/components/ui/button/IconButton.vue'diff --git a/src/components/properties/component-properties/PropertyBindings.vue b/src/components/properties/component-properties/PropertyBindings.vueindex 9d359b640..ad5f70dff 100644--- a/src/components/properties/component-properties/PropertyBindings.vue+++ b/src/components/properties/component-properties/PropertyBindings.vue@@ -7,7 +7,7 @@ import {type ComponentBindingGroup} from '@open-pencil/vue'-import { sceneNodeIcon } from '@/app/editor/icons'+import { sceneNodeIcon } from '@/components/icons'import AppButton from '@/components/ui/button/AppButton.vue'import { collapsibleContentMotion } from '@/theme/collapsible/collapsible'diff --git a/src/components/properties/connector/ConnectorControls.vue b/src/components/properties/connector/ConnectorControls.vueindex a44ce7b4e..3280c477d 100644--- a/src/components/properties/connector/ConnectorControls.vue+++ b/src/components/properties/connector/ConnectorControls.vue@@ -1,25 +1,48 @@<script setup lang="ts">+import { tv } from 'tailwind-variants'import { computed } from 'vue'-import type { ConnectorLineType, StrokeCap } from '@open-pencil/scene-graph'+import type { ConnectorLineType, FigJamColorName, StrokeCap } from '@open-pencil/scene-graph'import { useI18n } from '@open-pencil/vue'+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 PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'import AppSelect from '@/components/ui/select/AppSelect.vue'+import theme from '@/theme/figjam/controls'-const { lineType, startCap, endCap } = defineProps<{+/**+ * A connector's line, as FigJam's selection toolbar sets it: its colour from FigJam's palette,+ * Thick and Dashed as toggles, its line type, and the caps at its ends.+ */+const {+ lineType,+ startCap,+ endCap,+ color = null,+ thick = false,+ dashed = false+} = defineProps<{lineType: ConnectorLineType | nullstartCap: StrokeCap | nullendCap: StrokeCap | null+ color?: FigJamColorName | null+ thick?: boolean+ dashed?: boolean}>()const emit = defineEmits<{'update:lineType': [value: ConnectorLineType]'update:startCap': [value: StrokeCap]'update:endCap': [value: StrokeCap]+ 'update:color': [value: FigJamColorName]+ 'update:thick': [value: boolean]+ 'update:dashed': [value: boolean]}>()const { panels } = useI18n()+const styles = tv(theme)()const lineOptions = computed<Array<{ value: ConnectorLineType; label: string }>>(() => [{ value: 'ELBOWED', label: panels.value.connectorElbowed },@@ -52,14 +75,54 @@ const selectedEnd = computed<StrokeCap>({</script><template>- <div class="grid gap-2.5">+ <div :class="styles.root()">+ <div>+ <div :class="styles.header()">+ <span :class="styles.label()">{{ panels.connectorColor }}</span>+ <div class="flex items-center gap-0.5">+ <IconButton+ toggle+ :label="panels.connectorThick"+ :active="thick"+ data-property="connector-thick"+ @click="emit('update:thick', !thick)"+ >+ <icon-lucide-minus class="size-3.5 [stroke-width:4]" />+ </IconButton>+ <IconButton+ toggle+ :label="panels.connectorDashed"+ :active="dashed"+ data-property="connector-dashed"+ @click="emit('update:dashed', !dashed)"+ >+ <icon-lucide-circle-dashed class="size-3.5" />+ </IconButton>+ </div>+ </div>+ <FigJamPalette+ :label="panels.connectorColor"+ :selected="color"+ @select="emit('update:color', $event)"+ />+ </div><PanelFieldGroup :label="panels.connectorLine"><AppSelectv-model="selectedLine":label="panels.connectorLine":options="lineOptions"data-property="connector-line"- />+ >+ <template #leading>+ <component :is="CONNECTOR_LINE_TYPE_ICONS[selectedLine]" :class="styles.leadingIcon()" />+ </template>+ <template #option="{ option }">+ <span :class="styles.option()">+ <component :is="CONNECTOR_LINE_TYPE_ICONS[option.value]" :class="styles.optionIcon()" />+ {{ option.label }}+ </span>+ </template>+ </AppSelect></PanelFieldGroup><PanelFieldGroup :label="panels.connectorStart"><AppSelect@@ -67,7 +130,17 @@ const selectedEnd = computed<StrokeCap>({:label="panels.connectorStart":options="capOptions"data-property="connector-start-cap"- />+ >+ <template #leading>+ <component :is="connectorCapIcon(selectedStart, 'start')" :class="styles.leadingIcon()" />+ </template>+ <template #option="{ option }">+ <span :class="styles.option()">+ <component :is="connectorCapIcon(option.value, 'start')" :class="styles.optionIcon()" />+ {{ option.label }}+ </span>+ </template>+ </AppSelect></PanelFieldGroup><PanelFieldGroup :label="panels.connectorEnd"><AppSelect@@ -75,7 +148,17 @@ const selectedEnd = computed<StrokeCap>({:label="panels.connectorEnd":options="capOptions"data-property="connector-end-cap"- />+ >+ <template #leading>+ <component :is="connectorCapIcon(selectedEnd, 'end')" :class="styles.leadingIcon()" />+ </template>+ <template #option="{ option }">+ <span :class="styles.option()">+ <component :is="connectorCapIcon(option.value, 'end')" :class="styles.optionIcon()" />+ {{ option.label }}+ </span>+ </template>+ </AppSelect></PanelFieldGroup></div></template>diff --git a/src/components/properties/connector/ConnectorSection.vue b/src/components/properties/connector/ConnectorSection.vueindex b2dd71df4..9636b4af9 100644--- a/src/components/properties/connector/ConnectorSection.vue+++ b/src/components/properties/connector/ConnectorSection.vue@@ -6,7 +6,21 @@ import PanelSection from '@/components/ui/panel/PanelSection.vue'import ConnectorControls from './ConnectorControls.vue'const { panels } = useI18n()-const { active, lineType, startCap, endCap, setLineType, setStartCap, setEndCap } = useConnector()+const {+ active,+ lineType,+ startCap,+ endCap,+ color,+ thick,+ dashed,+ setLineType,+ setStartCap,+ setEndCap,+ setColor,+ setThick,+ setDashed+} = useConnector()</script><template>@@ -15,9 +29,15 @@ const { active, lineType, startCap, endCap, setLineType, setStartCap, setEndCap:line-type="lineType":start-cap="startCap":end-cap="endCap"+ :color="color"+ :thick="thick"+ :dashed="dashed"@update:line-type="setLineType"@update:start-cap="setStartCap"@update:end-cap="setEndCap"+ @update:color="setColor"+ @update:thick="setThick"+ @update:dashed="setDashed"/></PanelSection></template>diff --git a/src/components/properties/shape-with-text/ShapeWithTextControls.vue b/src/components/properties/shape-with-text/ShapeWithTextControls.vueindex 4e554b46c..8b0fbd380 100644--- a/src/components/properties/shape-with-text/ShapeWithTextControls.vue+++ b/src/components/properties/shape-with-text/ShapeWithTextControls.vue@@ -12,16 +12,16 @@ import type {import type { ShapeWithTextType } from '@open-pencil/scene-graph/shape-with-text'import { useFigJamMessages, useShapeMessages } from '@open-pencil/vue'-import { SHAPE_KIND_ICONS } from '@/app/editor/shape-icons'import FigJamPalette from '@/components/figjam/FigJamPalette.vue'import { typefaceModel, useFigJamTextOptions } from '@/components/figjam/text-options'+import { SHAPE_KIND_ICONS } from '@/components/icons/shapes'import { useShapeKindLabels } from '@/components/shapes/labels'import ShapeKindPicker from '@/components/shapes/ShapeKindPicker.vue'import IconButton from '@/components/ui/button/IconButton.vue'import PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'import AppSelect from '@/components/ui/select/AppSelect.vue'+import theme from '@/theme/figjam/controls'import selectTheme from '@/theme/select/app'-import theme from '@/theme/shape-with-text-controls'/*** A shape with text's kind, colour, outline and text, as FigJam's selection toolbar sets them:diff --git a/src/components/shapes/ShapeKindPicker.stories.ts b/src/components/shapes/ShapeKindPicker.stories.tsindex ee94d0f28..7fce24796 100644--- a/src/components/shapes/ShapeKindPicker.stories.ts+++ b/src/components/shapes/ShapeKindPicker.stories.ts@@ -4,7 +4,7 @@ import { ref } from 'vue'import type { ShapeWithTextType } from '@open-pencil/scene-graph/shape-with-text'-import { SHAPE_KIND_ICONS } from '@/app/editor/shape-icons'+import { SHAPE_KIND_ICONS } from '@/components/icons/shapes'import ShapeKindPicker from './ShapeKindPicker.vue'diff --git a/src/components/shapes/ShapeKindPicker.vue b/src/components/shapes/ShapeKindPicker.vueindex e36c3c55c..420262d12 100644--- a/src/components/shapes/ShapeKindPicker.vue+++ b/src/components/shapes/ShapeKindPicker.vue@@ -8,7 +8,7 @@ import {} from '@open-pencil/scene-graph/shape-with-text'import { useCommonMessages, useShapeMessages } from '@open-pencil/vue'-import { SHAPE_KIND_ICONS } from '@/app/editor/shape-icons'+import { SHAPE_KIND_ICONS } from '@/components/icons/shapes'import AppPicker from '@/components/ui/select/AppPicker.vue'import type { AppPickerItem } from '@/components/ui/select/AppPicker.vue'diff --git a/src/components/toolbar/ShapeToolButton.vue b/src/components/toolbar/ShapeToolButton.vueindex 02c29aac6..b04589c6b 100644--- a/src/components/toolbar/ShapeToolButton.vue+++ b/src/components/toolbar/ShapeToolButton.vue@@ -4,7 +4,7 @@ import { ref } from 'vue'import type { ShapeWithTextType } from '@open-pencil/scene-graph/shape-with-text'import { toolbarToolTestId, useShapeWithText, useToolMessages } from '@open-pencil/vue'-import { SHAPE_KIND_ICONS } from '@/app/editor/shape-icons'+import { SHAPE_KIND_ICONS } from '@/components/icons/shapes'import ShapeKindPicker from '@/components/shapes/ShapeKindPicker.vue'import ToolButton from '@/components/toolbar/ToolButton.vue'import type { ToolbarUI } from '@/components/toolbar/types'diff --git a/src/components/toolbar/Toolbar.vue b/src/components/toolbar/Toolbar.vueindex b6bd79839..0f530072b 100644--- a/src/components/toolbar/Toolbar.vue+++ b/src/components/toolbar/Toolbar.vue@@ -10,12 +10,12 @@ import {} from '@open-pencil/vue'import { useEditorStore } from '@/app/editor/active-store'-import { toolIcons } from '@/app/editor/icons'import { readOnlyToolbarLayout, toolbarItems } from '@/app/editor/toolbar/layout'import { toolShortcutLabels } from '@/app/editor/toolbar/shortcuts'import { appPreferences } from '@/app/settings/preferences/store'import { useActionToast } from '@/app/shell/toast/action'import InsertIconButton from '@/components/icon-picker/InsertIconButton.vue'+import { toolIcons } from '@/components/icons'import { useToolbarActions } from '@/components/toolbar/actions'import DesktopToolbar from '@/components/toolbar/DesktopToolbar.vue'import { useToolLabels } from '@/components/toolbar/labels'diff --git a/src/components/toolbar/labels.ts b/src/components/toolbar/labels.tsindex 86ba042d9..a9b971d4b 100644--- a/src/components/toolbar/labels.ts+++ b/src/components/toolbar/labels.ts@@ -4,8 +4,8 @@ import IconSmilePlus from '~icons/lucide/smile-plus'import { useI18n, usePanelMessages } from '@open-pencil/vue'import type { Tool } from '@open-pencil/vue'-import { toolIcons } from '@/app/editor/icons'import type { ToolbarEntry } from '@/app/editor/toolbar/layout'+import { toolIcons } from '@/components/icons'export function useToolLabels() {const { tools } = useI18n()diff --git a/src/components/ui/select/AppSelect.vue b/src/components/ui/select/AppSelect.vueindex 20d49a688..313c0697e 100644--- a/src/components/ui/select/AppSelect.vue+++ b/src/components/ui/select/AppSelect.vue@@ -90,6 +90,8 @@ const itemUI = computed(() => ({ item: ui?.item, indicator: ui?.indicator }))v-bind="$attrs":class="styles.trigger({ class: ui?.trigger })">+ <!-- An icon before the chosen option, such as the glyph its menu row shows. -->+ <slot name="leading" /><SelectValue :placeholder="placeholder" :class="styles.value({ class: ui?.value })">{{ displayLabel ?? selectedLabel ?? placeholder }}</SelectValue>diff --git a/src/theme/figjam/controls.ts b/src/theme/figjam/controls.tsnew file mode 100644index 000000000..16bd8989f--- /dev/null+++ b/src/theme/figjam/controls.ts@@ -0,0 +1,13 @@+const figJamControlsTheme = {+ slots: {+ root: 'grid gap-3',+ header: 'mb-1 flex items-center justify-between',+ label: 'text-[11px] text-muted',+ leadingIcon: 'mr-1.5 size-4 shrink-0 text-muted',+ option: 'flex items-center gap-2',+ optionIcon: 'size-4 shrink-0 text-muted'+ }+}++export type FigJamControlsTheme = typeof figJamControlsTheme+export default figJamControlsThemediff --git a/src/theme/shape-with-text-controls.ts b/src/theme/shape-with-text-controls.tsdeleted file mode 100644index 76a1d88f6..000000000--- a/src/theme/shape-with-text-controls.ts+++ /dev/null@@ -1,10 +0,0 @@-const shapeWithTextControlsTheme = {- slots: {- root: 'grid gap-3',- header: 'mb-1 flex items-center justify-between',- label: 'text-[11px] text-muted'- }-}--export type ShapeWithTextControlsTheme = typeof shapeWithTextControlsTheme-export default shapeWithTextControlsThemediff --git a/tests/e2e/canvas/connectors-visual.spec.ts b/tests/e2e/canvas/connectors-visual.spec.tsindex 0d483ad03..5857a331f 100644--- a/tests/e2e/canvas/connectors-visual.spec.ts+++ b/tests/e2e/canvas/connectors-visual.spec.ts@@ -40,6 +40,13 @@ test('connectors draw their filled caps, the end handles of a selected one, and)})+test("connectors draw FigJam's line styles, dashes rounding the elbows as the solid line does", async () => {+ await connectors.showLineStyles()+ await editor.canvas.waitForRender()+ editor.canvas.assertNoErrors()+ expect(await editor.canvas.screenshotCanvasRegion()).toMatchSnapshot('connector-line-styles.png')+})+test('connector ends pinned to points of a section stop short of them, reached along the longer axis', async () => {await connectors.showPinnedEnds()await editor.canvas.waitForRender()diff --git a/tests/e2e/canvas/connectors-visual.spec.ts-snapshots/connector-line-styles-openpencil-darwin.png b/tests/e2e/canvas/connectors-visual.spec.ts-snapshots/connector-line-styles-openpencil-darwin.pngnew file mode 100644index 000000000..c7aeb1068Binary files /dev/null and b/tests/e2e/canvas/connectors-visual.spec.ts-snapshots/connector-line-styles-openpencil-darwin.png differdiff --git a/tests/e2e/code/diagnostics.spec.ts b/tests/e2e/code/diagnostics.spec.tsnew file mode 100644index 000000000..61f7f7541--- /dev/null+++ b/tests/e2e/code/diagnostics.spec.ts@@ -0,0 +1,25 @@+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'++const editor = useEditorSetupWithClear()++test("the Design JSX editor flags props an element does not take, and accepts each element's own", async () => {+ const page = editor.page+ await page.getByTestId('properties-tab-code').click()+ const writeJSX = page.getByTestId('code-panel-root').getByRole('button', { name: 'Write JSX' })+ const content = page.locator('[data-slot="code-editor"] .cm-content')+ await expect(content.or(writeJSX)).toBeVisible()+ if (await writeJSX.isVisible()) await writeJSX.click()+ await content.click()+ await page.keyboard.press('ControlOrMeta+a')+ await page.keyboard.insertText(+ [+ '<Frame w={400} h={300}>',+ ' <Shape name="a" kind="diamond" textSize="large" typeface="bookish">A</Shape>',+ ' <Sticky color="yellow" author="Ada">Hi</Sticky>',+ ' <Connector from="a" to="a" line="curved" startCap="none" />',+ ' <Frame from="x" bogus={1} />',+ '</Frame>'+ ].join('\n')+ )+ await expect(page.locator('.cm-lintRange-warning')).toHaveText(['from', 'bogus'])+})diff --git a/tests/e2e/tools/connector.spec.ts b/tests/e2e/tools/connector.spec.tsindex 032a89b98..db9cfe9b8 100644--- a/tests/e2e/tools/connector.spec.ts+++ b/tests/e2e/tools/connector.spec.ts@@ -137,3 +137,28 @@ test('the Connector section sets the line type and end caps', async () => {endCap: 'CIRCLE_FILLED'})})++test("the Connector section draws the line in FigJam's palette, thick, and dashed", async () => {+ await connectors.showTool()+ await connectors.pickTool()+ await drag([100, 100], [600, 200])+ await editor.page.keyboard.press('v')+ const connector = await lastConnector()+ await connectors.select(connector.id)+ const section = editor.page.getByRole('region', { name: 'Connector' })+ await section+ .getByRole('radiogroup', { name: 'Color' })+ .getByRole('radio', { name: 'Blue', exact: true })+ .click()+ await section.locator('[data-property="connector-dashed"]').click()+ await section.locator('[data-property="connector-thick"]').click()+ await expect(section.locator('[data-property="connector-thick"]')).toHaveAttribute(+ 'aria-pressed',+ 'true'+ )+ expect(await connectors.lineStroke(connector.id)).toEqual({+ color: '#3dadff',+ weight: 8,+ dash: [40, 24]+ })+})diff --git a/tests/helpers/canvas/connector-driver.ts b/tests/helpers/canvas/connector-driver.tsindex 26ead4669..ee50b71e1 100644--- a/tests/helpers/canvas/connector-driver.ts+++ b/tests/helpers/canvas/connector-driver.ts@@ -158,6 +158,58 @@ export function connectorDriver(page: () => Page) {})},+ /**+ * Setup: three elbowed connectors at 100%, styled as FigJam's line menu styles them: thin and+ * dashed, thick and dashed, and thick and solid, each in a palette colour.+ */+ showLineStyles() {+ return page().evaluate(() => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ const page = store.state.currentPageId+ const box = (x: number, y: number) =>+ store.graph.createNode('RECTANGLE', page, {+ x,+ y,+ width: 120,+ height: 80,+ fills: [+ {+ type: 'SOLID',+ color: { r: 0.85, g: 0.88, b: 0.95, a: 1 },+ opacity: 1,+ visible: true+ }+ ]+ })+ const styles = [+ { color: 'violet', thick: false, dashed: true },+ { color: 'red', thick: true, dashed: true },+ { color: 'blue', thick: true, dashed: false }+ ] as const+ styles.forEach((style, row) => {+ const from = box(40, 40 + row * 180)+ const to = box(480, 120 + row * 180)+ store.setTool('CONNECTOR')+ store.connectorBegin(from.x + 60, from.y + 40)+ store.connectorRelease(to.x + 60, to.y + 40, true)+ const connector = store.graph+ .getChildren(page)+ .findLast((node) => node.type === 'CONNECTOR')+ if (!connector) throw new Error('No connector')+ store.setConnectorColor([connector.id], style.color)+ store.setConnectorThick([connector.id], style.thick)+ store.setConnectorDashed([connector.id], style.dashed)+ })+ store.setTool('SELECT')+ store.clearSelection()+ store.state.zoom = 1+ store.state.panX = 0+ store.state.panY = 0+ store.requestRender()+ })+ },+/*** Setup: a section with connectors drawn into it from boxes left of it, below it, and right* of it, dropped away from its outline and centre so each end is pinned where it was dropped.@@ -220,6 +272,25 @@ export function connectorDriver(page: () => Page) {}, id)},+ /** Probe: how a connector's line is stroked: its colour as `#rrggbb`, weight and dash. */+ lineStroke(id: string) {+ return page().evaluate((connectorId) => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ const [line] = store.graph.getChildren(connectorId)+ const stroke = line?.strokes[0]+ if (!stroke) throw new Error(`No line stroke on ${connectorId}`)+ const hex = [stroke.color.r, stroke.color.g, stroke.color.b]+ .map((value) =>+ Math.round(value * 255)+ .toString(16)+ .padStart(2, '0')+ )+ .join('')+ return { color: `#${hex}`, weight: stroke.weight, dash: stroke.dashPattern ?? [] }+ }, id)+ },+/** Canvas coordinates of a page point, under `showOrigin`. */point(x: number, y: number) {return { x: ORIGIN + x, y: ORIGIN + y }diff --git a/tools/checks/i18n/translation-baseline.txt b/tools/checks/i18n/translation-baseline.txtindex 3484b232c..98ef2dd5e 100644--- a/tools/checks/i18n/translation-baseline.txt+++ b/tools/checks/i18n/translation-baseline.txt@@ -447,6 +447,7 @@ it:settings.cloudes:cloud.productNamees:cloud.roleEditores:cloud.homeCloudOnHost+es:panels.connectorColorit:cloud.productNameit:cloud.serverit:cloud.roleEditor