Skip to content

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

More translations

Santos Alarcón5461b38ce5d4
diff --git a/packages/core/src/editor/state.ts b/packages/core/src/editor/state.ts
index 6ee8c1b4b..00554a819 100644
--- a/packages/core/src/editor/state.ts
+++ b/packages/core/src/editor/state.ts
@@ -1,31 +1,33 @@
import { CANVAS_BG_COLOR } from '#core/constants'
import type { EditorState } from '#core/editor/types'
+import { useI18n } from "@open-pencil/vue"
export function createDefaultEditorState(pageId: string): EditorState {
- return {
- activeTool: 'SELECT',
- currentPageId: pageId,
- selectedIds: new Set<string>(),
- marquee: null,
- snapGuides: [],
- rotationPreview: null,
- dropTargetId: null,
- layoutInsertIndicator: null,
- hoveredNodeId: null,
- editingTextId: null,
- penState: null,
- penCursorX: null,
- penCursorY: null,
- remoteCursors: [],
- autoLayoutHover: null,
- documentName: 'Untitled',
- panX: 0,
- pageColor: { ...CANVAS_BG_COLOR },
- panY: 0,
- zoom: 1,
- renderVersion: 0,
- sceneVersion: 0,
- loading: false,
- enteredContainerId: null
- }
+ const { panels } = useI18n();
+ return {
+ activeTool: 'SELECT',
+ currentPageId: pageId,
+ selectedIds: new Set<string>(),
+ marquee: null,
+ snapGuides: [],
+ rotationPreview: null,
+ dropTargetId: null,
+ layoutInsertIndicator: null,
+ hoveredNodeId: null,
+ editingTextId: null,
+ penState: null,
+ penCursorX: null,
+ penCursorY: null,
+ remoteCursors: [],
+ autoLayoutHover: null,
+ documentName: panels.value.untitled || 'Untitled',
+ panX: 0,
+ pageColor: { ...CANVAS_BG_COLOR },
+ panY: 0,
+ zoom: 1,
+ renderVersion: 0,
+ sceneVersion: 0,
+ loading: false,
+ enteredContainerId: null
+ }
}
diff --git a/packages/core/src/editor/tool-registry.ts b/packages/core/src/editor/tool-registry.ts
index 43f5aef8f..b059affc9 100644
--- a/packages/core/src/editor/tool-registry.ts
+++ b/packages/core/src/editor/tool-registry.ts
@@ -1,34 +1,34 @@
-import type { Tool } from './types'
+import type { Tool } from "./types";
export interface EditorToolDef {
- key: Tool
- label: string
- shortcut: string
- flyout?: Tool[]
+ key: Tool;
+ label: string;
+ shortcut: string;
+ flyout?: Tool[];
}
export const EDITOR_TOOLS: EditorToolDef[] = [
- { key: 'SELECT', label: 'Move', shortcut: 'V' },
- { key: 'FRAME', label: 'Frame', shortcut: 'F', flyout: ['FRAME', 'SECTION'] },
- {
- key: 'RECTANGLE',
- label: 'Rectangle',
- shortcut: 'R',
- flyout: ['RECTANGLE', 'LINE', 'ELLIPSE', 'POLYGON', 'STAR']
- },
- { key: 'PEN', label: 'Pen', shortcut: 'P' },
- { key: 'TEXT', label: 'Text', shortcut: 'T' },
- { key: 'HAND', label: 'Hand', shortcut: 'H' }
-]
+ { key: "SELECT", label: "Move", shortcut: "V" },
+ { key: "FRAME", label: "Frame", shortcut: "F", flyout: ["FRAME", "SECTION"] },
+ {
+ key: "RECTANGLE",
+ label: "Rectangle",
+ shortcut: "R",
+ flyout: ["RECTANGLE", "LINE", "ELLIPSE", "POLYGON", "STAR"],
+ },
+ { key: "PEN", label: "Pen", shortcut: "P" },
+ { key: "TEXT", label: "Text", shortcut: "T" },
+ { key: "HAND", label: "Hand", shortcut: "H" },
+];
export const TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {
- KeyV: 'SELECT',
- KeyF: 'FRAME',
- KeyS: 'SECTION',
- KeyR: 'RECTANGLE',
- KeyO: 'ELLIPSE',
- KeyL: 'LINE',
- KeyT: 'TEXT',
- KeyP: 'PEN',
- KeyH: 'HAND'
-}
+ KeyV: "SELECT",
+ KeyF: "FRAME",
+ KeyS: "SECTION",
+ KeyR: "RECTANGLE",
+ KeyO: "ELLIPSE",
+ KeyL: "LINE",
+ KeyT: "TEXT",
+ KeyP: "PEN",
+ KeyH: "HAND",
+};
diff --git a/packages/core/src/io/formats/jsx/export.ts b/packages/core/src/io/formats/jsx/export.ts
index 39064f449..1a24a93c8 100644
--- a/packages/core/src/io/formats/jsx/export.ts
+++ b/packages/core/src/io/formats/jsx/export.ts
@@ -1,366 +1,421 @@
-import { DEFAULT_FONT_FAMILY } from '#core/constants'
-import type { SceneGraph, SceneNode, NodeType } from '#core/scene-graph'
-import { resolveNodeTextDirection } from '#core/text/direction'
+import { DEFAULT_FONT_FAMILY } from "#core/constants";
+import type { SceneGraph, SceneNode, NodeType } from "#core/scene-graph";
+import { resolveNodeTextDirection } from "#core/text/direction";
import {
- collectCornerRadii,
- collectPadding,
- emitPadding,
- escapeJSXText,
- formatProp,
- formatShadow,
- formatTracks,
- getNodeContext,
- solidFillColor,
- solidStroke
-} from './helpers'
-import { collectTailwindClasses } from './tailwind-classes'
-
-export type JSXFormat = 'openpencil' | 'tailwind'
+ collectCornerRadii,
+ collectPadding,
+ emitPadding,
+ escapeJSXText,
+ formatProp,
+ formatShadow,
+ formatTracks,
+ getNodeContext,
+ solidFillColor,
+ solidStroke,
+} from "./helpers";
+import { collectTailwindClasses } from "./tailwind-classes";
+
+export type JSXFormat = "openpencil" | "tailwind";
const NODE_TYPE_TO_TAG: Partial<Record<NodeType, string>> = {
- FRAME: 'Frame',
- RECTANGLE: 'Rectangle',
- ROUNDED_RECTANGLE: 'Rectangle',
- ELLIPSE: 'Ellipse',
- TEXT: 'Text',
- LINE: 'Line',
- STAR: 'Star',
- POLYGON: 'Polygon',
- VECTOR: 'Vector',
- GROUP: 'Group',
- SECTION: 'Section',
- COMPONENT: 'Component',
- COMPONENT_SET: 'Frame',
- INSTANCE: 'Frame'
-}
+ FRAME: "Frame",
+ RECTANGLE: "Rectangle",
+ ROUNDED_RECTANGLE: "Rectangle",
+ ELLIPSE: "Ellipse",
+ TEXT: "Text",
+ LINE: "Line",
+ STAR: "Star",
+ POLYGON: "Polygon",
+ VECTOR: "Vector",
+ GROUP: "Group",
+ SECTION: "Section",
+ COMPONENT: "Component",
+ COMPONENT_SET: "Frame",
+ INSTANCE: "Frame",
+};
const NODE_TYPE_TO_TW_TAG: Partial<Record<NodeType, string>> = {
- FRAME: 'div',
- RECTANGLE: 'div',
- ROUNDED_RECTANGLE: 'div',
- ELLIPSE: 'div',
- TEXT: 'p',
- LINE: 'div',
- STAR: 'div',
- POLYGON: 'div',
- VECTOR: 'div',
- GROUP: 'div',
- SECTION: 'section',
- COMPONENT: 'div',
- COMPONENT_SET: 'div',
- INSTANCE: 'div'
-}
+ FRAME: "div",
+ RECTANGLE: "div",
+ ROUNDED_RECTANGLE: "div",
+ ELLIPSE: "div",
+ TEXT: "p",
+ LINE: "div",
+ STAR: "div",
+ POLYGON: "div",
+ VECTOR: "div",
+ GROUP: "div",
+ SECTION: "section",
+ COMPONENT: "div",
+ COMPONENT_SET: "div",
+ INSTANCE: "div",
+};
// --- OpenPencil format helpers ---
-function collectGridSizingProps(node: SceneNode, props: [string, unknown][]): void {
- props.push(['grid', true])
- if (node.gridTemplateColumns.length > 0)
- props.push(['columns', formatTracks(node.gridTemplateColumns)])
- if (node.gridTemplateRows.length > 0) props.push(['rows', formatTracks(node.gridTemplateRows)])
- if (node.width > 0) props.push(['w', node.width])
- if (node.gridTemplateRows.length > 0 && node.height > 0) props.push(['h', node.height])
- if (node.gridColumnGap > 0) props.push(['columnGap', node.gridColumnGap])
- if (node.gridRowGap > 0) props.push(['rowGap', node.gridRowGap])
+function collectGridSizingProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ props.push(["grid", true]);
+ if (node.gridTemplateColumns.length > 0)
+ props.push(["columns", formatTracks(node.gridTemplateColumns)]);
+ if (node.gridTemplateRows.length > 0)
+ props.push(["rows", formatTracks(node.gridTemplateRows)]);
+ if (node.width > 0) props.push(["w", node.width]);
+ if (node.gridTemplateRows.length > 0 && node.height > 0)
+ props.push(["h", node.height]);
+ if (node.gridColumnGap > 0) props.push(["columnGap", node.gridColumnGap]);
+ if (node.gridRowGap > 0) props.push(["rowGap", node.gridRowGap]);
}
-function collectFlexSizingProps(node: SceneNode, props: [string, unknown][]): void {
- props.push(['flex', node.layoutMode === 'HORIZONTAL' ? 'row' : 'col'])
- if (node.layoutDirection === 'RTL') props.push(['dir', 'rtl'])
- const primaryAxis = node.layoutMode === 'HORIZONTAL' ? 'width' : 'height'
- const crossAxis = node.layoutMode === 'HORIZONTAL' ? 'height' : 'width'
-
- if (node.primaryAxisSizing === 'FILL') props.push([primaryAxis === 'width' ? 'w' : 'h', 'fill'])
- else if (node.primaryAxisSizing !== 'HUG')
- props.push([primaryAxis === 'width' ? 'w' : 'h', node[primaryAxis]])
-
- if (node.counterAxisSizing === 'FILL') props.push([crossAxis === 'width' ? 'w' : 'h', 'fill'])
- else if (node.counterAxisSizing !== 'HUG')
- props.push([crossAxis === 'width' ? 'w' : 'h', node[crossAxis]])
+function collectFlexSizingProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ props.push(["flex", node.layoutMode === "HORIZONTAL" ? "row" : "col"]);
+ if (node.layoutDirection === "RTL") props.push(["dir", "rtl"]);
+ const primaryAxis = node.layoutMode === "HORIZONTAL" ? "width" : "height";
+ const crossAxis = node.layoutMode === "HORIZONTAL" ? "height" : "width";
+
+ if (node.primaryAxisSizing === "FILL")
+ props.push([primaryAxis === "width" ? "w" : "h", "fill"]);
+ else if (node.primaryAxisSizing !== "HUG")
+ props.push([primaryAxis === "width" ? "w" : "h", node[primaryAxis]]);
+
+ if (node.counterAxisSizing === "FILL")
+ props.push([crossAxis === "width" ? "w" : "h", "fill"]);
+ else if (node.counterAxisSizing !== "HUG")
+ props.push([crossAxis === "width" ? "w" : "h", node[crossAxis]]);
}
-function collectGridPositionProps(node: SceneNode, props: [string, unknown][]): void {
- if (!node.gridPosition) return
- const pos = node.gridPosition
- if (pos.column > 0) props.push(['colStart', pos.column])
- if (pos.row > 0) props.push(['rowStart', pos.row])
- if (pos.columnSpan > 1) props.push(['colSpan', pos.columnSpan])
- if (pos.rowSpan > 1) props.push(['rowSpan', pos.rowSpan])
+function collectGridPositionProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ if (!node.gridPosition) return;
+ const pos = node.gridPosition;
+ if (pos.column > 0) props.push(["colStart", pos.column]);
+ if (pos.row > 0) props.push(["rowStart", pos.row]);
+ if (pos.columnSpan > 1) props.push(["colSpan", pos.columnSpan]);
+ if (pos.rowSpan > 1) props.push(["rowSpan", pos.rowSpan]);
}
-function collectFlexAlignmentProps(node: SceneNode, props: [string, unknown][]): void {
- if (node.itemSpacing > 0) props.push(['gap', node.itemSpacing])
-
- if (node.layoutWrap === 'WRAP') {
- props.push(['wrap', true])
- if (node.counterAxisSpacing > 0) props.push(['rowGap', node.counterAxisSpacing])
- }
-
- if (node.primaryAxisAlign === 'CENTER') props.push(['justify', 'center'])
- else if (node.primaryAxisAlign === 'MAX') props.push(['justify', 'end'])
- else if (node.primaryAxisAlign === 'SPACE_BETWEEN') props.push(['justify', 'between'])
-
- if (node.counterAxisAlign === 'CENTER') props.push(['items', 'center'])
- else if (node.counterAxisAlign === 'MAX') props.push(['items', 'end'])
- else if (node.counterAxisAlign === 'STRETCH') props.push(['items', 'stretch'])
+function collectFlexAlignmentProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ if (node.itemSpacing > 0) props.push(["gap", node.itemSpacing]);
+
+ if (node.layoutWrap === "WRAP") {
+ props.push(["wrap", true]);
+ if (node.counterAxisSpacing > 0)
+ props.push(["rowGap", node.counterAxisSpacing]);
+ }
+
+ if (node.primaryAxisAlign === "CENTER") props.push(["justify", "center"]);
+ else if (node.primaryAxisAlign === "MAX") props.push(["justify", "end"]);
+ else if (node.primaryAxisAlign === "SPACE_BETWEEN")
+ props.push(["justify", "between"]);
+
+ if (node.counterAxisAlign === "CENTER") props.push(["items", "center"]);
+ else if (node.counterAxisAlign === "MAX") props.push(["items", "end"]);
+ else if (node.counterAxisAlign === "STRETCH")
+ props.push(["items", "stretch"]);
}
-function collectAutoLayoutPaddingProps(node: SceneNode, props: [string, unknown][]): void {
- const pad = collectPadding(node)
- if (!pad) return
- props.push(
- ...emitPadding(
- pad,
- (v) => ['p', v] as [string, unknown],
- (y, x) =>
- [
- ['py', y],
- ['px', x]
- ] as [string, unknown][],
- ({ pt, pr, pb, pl }) => {
- const r: [string, unknown][] = []
- if (pt > 0) r.push(['pt', pt])
- if (pr > 0) r.push(['pr', pr])
- if (pb > 0) r.push(['pb', pb])
- if (pl > 0) r.push(['pl', pl])
- return r
- }
- )
- )
+function collectAutoLayoutPaddingProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ const pad = collectPadding(node);
+ if (!pad) return;
+ props.push(
+ ...emitPadding(
+ pad,
+ (v) => ["p", v] as [string, unknown],
+ (y, x) =>
+ [
+ ["py", y],
+ ["px", x],
+ ] as [string, unknown][],
+ ({ pt, pr, pb, pl }) => {
+ const r: [string, unknown][] = [];
+ if (pt > 0) r.push(["pt", pt]);
+ if (pr > 0) r.push(["pr", pr]);
+ if (pb > 0) r.push(["pb", pb]);
+ if (pl > 0) r.push(["pl", pl]);
+ return r;
+ },
+ ),
+ );
}
-function collectCornerRadiiProps(node: SceneNode, props: [string, unknown][]): void {
- const corners = collectCornerRadii(node)
- if (!corners) return
- const { tl, tr, br, bl } = corners
- if (tl === tr && tr === br && br === bl) {
- props.push(['rounded', tl])
- } else {
- if (tl > 0) props.push(['roundedTL', tl])
- if (tr > 0) props.push(['roundedTR', tr])
- if (br > 0) props.push(['roundedBR', br])
- if (bl > 0) props.push(['roundedBL', bl])
- }
+function collectCornerRadiiProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ const corners = collectCornerRadii(node);
+ if (!corners) return;
+ const { tl, tr, br, bl } = corners;
+ if (tl === tr && tr === br && br === bl) {
+ props.push(["rounded", tl]);
+ } else {
+ if (tl > 0) props.push(["roundedTL", tl]);
+ if (tr > 0) props.push(["roundedTR", tr]);
+ if (br > 0) props.push(["roundedBR", br]);
+ if (bl > 0) props.push(["roundedBL", bl]);
+ }
}
-function collectAppearanceProps(node: SceneNode, props: [string, unknown][]): void {
- const bg = solidFillColor(node.fills)
- if (bg) props.push(['bg', bg])
-
- const stroke = solidStroke(node.strokes)
- if (stroke) {
- props.push(['stroke', stroke.color])
- if (stroke.weight !== 1) props.push(['strokeWidth', stroke.weight])
- if (stroke.dash) props.push(['strokeDash', stroke.dash])
- }
-
- collectCornerRadiiProps(node, props)
-
- if (node.cornerSmoothing > 0) props.push(['cornerSmoothing', node.cornerSmoothing])
- if (node.opacity < 1) props.push(['opacity', Math.round(node.opacity * 100) / 100])
- if (node.rotation !== 0) props.push(['rotate', Math.round(node.rotation * 100) / 100])
- if (node.blendMode !== 'PASS_THROUGH' && node.blendMode !== 'NORMAL') {
- props.push(['blendMode', node.blendMode.toLowerCase()])
- }
- if (node.clipsContent) props.push(['overflow', 'hidden'])
-
- for (const effect of node.effects) {
- if (!effect.visible) continue
- if (effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW') {
- const shadow = formatShadow(effect)
- if (shadow) props.push(['shadow', shadow])
- } else if (effect.type === 'LAYER_BLUR' || effect.type === 'BACKGROUND_BLUR') {
- props.push(['blur', effect.radius])
- }
- }
+function collectAppearanceProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ const bg = solidFillColor(node.fills);
+ if (bg) props.push(["bg", bg]);
+
+ const stroke = solidStroke(node.strokes);
+ if (stroke) {
+ props.push(["stroke", stroke.color]);
+ if (stroke.weight !== 1) props.push(["strokeWidth", stroke.weight]);
+ if (stroke.dash) props.push(["strokeDash", stroke.dash]);
+ }
+
+ collectCornerRadiiProps(node, props);
+
+ if (node.cornerSmoothing > 0)
+ props.push(["cornerSmoothing", node.cornerSmoothing]);
+ if (node.opacity < 1)
+ props.push(["opacity", Math.round(node.opacity * 100) / 100]);
+ if (node.rotation !== 0)
+ props.push(["rotate", Math.round(node.rotation * 100) / 100]);
+ if (node.blendMode !== "PASS_THROUGH" && node.blendMode !== "NORMAL") {
+ props.push(["blendMode", node.blendMode.toLowerCase()]);
+ }
+ if (node.clipsContent) props.push(["overflow", "hidden"]);
+
+ for (const effect of node.effects) {
+ if (!effect.visible) continue;
+ if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") {
+ const shadow = formatShadow(effect);
+ if (shadow) props.push(["shadow", shadow]);
+ } else if (
+ effect.type === "LAYER_BLUR" ||
+ effect.type === "BACKGROUND_BLUR"
+ ) {
+ props.push(["blur", effect.radius]);
+ }
+ }
}
function collectPositionProps(
- node: SceneNode,
- ctx: ReturnType<typeof getNodeContext>,
- props: [string, unknown][]
+ node: SceneNode,
+ ctx: ReturnType<typeof getNodeContext>,
+ props: [string, unknown][],
): void {
- if (ctx.parentIsAutoLayout || ctx.parentIsGrid) return
- if (node.x !== 0) props.push(['x', node.x])
- if (node.y !== 0) props.push(['y', node.y])
+ if (ctx.parentIsAutoLayout || ctx.parentIsGrid) return;
+ if (node.x !== 0) props.push(["x", node.x]);
+ if (node.y !== 0) props.push(["y", node.y]);
}
function collectSizingProps(
- node: SceneNode,
- ctx: ReturnType<typeof getNodeContext>,
- graph: SceneGraph,
- props: [string, unknown][]
+ node: SceneNode,
+ ctx: ReturnType<typeof getNodeContext>,
+ graph: SceneGraph,
+ props: [string, unknown][],
): void {
- if (ctx.isGrid) collectGridSizingProps(node, props)
- else if (ctx.isFlex) collectFlexSizingProps(node, props)
- else if (node.type === 'TEXT') collectTextSizingProps(node, graph, props)
- else {
- if (node.width > 0) props.push(['w', node.width])
- if (node.height > 0) props.push(['h', node.height])
- }
-
- if (!ctx.parentIsAutoLayout) return
- if (node.layoutGrow > 0) props.push(['grow', node.layoutGrow])
- if (node.layoutAlignSelf === 'STRETCH') {
- const parent = node.parentId ? graph.getNode(node.parentId) : null
- if (parent && (parent.layoutMode === 'HORIZONTAL' || parent.layoutMode === 'VERTICAL')) {
- const crossDim = parent.layoutMode === 'HORIZONTAL' ? 'h' : 'w'
- if (!props.some(([k]) => k === crossDim)) props.push([crossDim, 'fill'])
- }
- }
+ if (ctx.isGrid) collectGridSizingProps(node, props);
+ else if (ctx.isFlex) collectFlexSizingProps(node, props);
+ else if (node.type === "TEXT") collectTextSizingProps(node, graph, props);
+ else {
+ if (node.width > 0) props.push(["w", node.width]);
+ if (node.height > 0) props.push(["h", node.height]);
+ }
+
+ if (!ctx.parentIsAutoLayout) return;
+ if (node.layoutGrow > 0) props.push(["grow", node.layoutGrow]);
+ if (node.layoutAlignSelf === "STRETCH") {
+ const parent = node.parentId ? graph.getNode(node.parentId) : null;
+ if (
+ parent &&
+ (parent.layoutMode === "HORIZONTAL" || parent.layoutMode === "VERTICAL")
+ ) {
+ const crossDim = parent.layoutMode === "HORIZONTAL" ? "h" : "w";
+ if (!props.some(([k]) => k === crossDim)) props.push([crossDim, "fill"]);
+ }
+ }
}
function collectTextSizingProps(
- node: SceneNode,
- graph: SceneGraph,
- props: [string, unknown][]
+ node: SceneNode,
+ graph: SceneGraph,
+ props: [string, unknown][],
): void {
- const autoResize = node.textAutoResize
- const emitH = autoResize === 'NONE' || autoResize === 'TRUNCATE'
- // Don't emit fixed w when text stretches to fill parent — the layoutAlignSelf
- // check below will emit w="fill" instead. Without this guard, w={computedPx}
- // gets emitted first and blocks the fill detection.
- const isFillWidth =
- node.layoutAlignSelf === 'STRETCH' &&
- (() => {
- const parent = node.parentId ? graph.getNode(node.parentId) : null
- return parent?.layoutMode === 'VERTICAL'
- })()
- const isGrowWidth =
- node.layoutGrow > 0 &&
- (() => {
- const parent = node.parentId ? graph.getNode(node.parentId) : null
- return parent?.layoutMode === 'HORIZONTAL'
- })()
- const emitW = autoResize !== 'WIDTH_AND_HEIGHT' && !isFillWidth && !isGrowWidth
- if (emitW && node.width > 0) props.push(['w', node.width])
- if (emitH && node.height > 0) props.push(['h', node.height])
+ const autoResize = node.textAutoResize;
+ const emitH = autoResize === "NONE" || autoResize === "TRUNCATE";
+ // Don't emit fixed w when text stretches to fill parent — the layoutAlignSelf
+ // check below will emit w="fill" instead. Without this guard, w={computedPx}
+ // gets emitted first and blocks the fill detection.
+ const isFillWidth =
+ node.layoutAlignSelf === "STRETCH" &&
+ (() => {
+ const parent = node.parentId ? graph.getNode(node.parentId) : null;
+ return parent?.layoutMode === "VERTICAL";
+ })();
+ const isGrowWidth =
+ node.layoutGrow > 0 &&
+ (() => {
+ const parent = node.parentId ? graph.getNode(node.parentId) : null;
+ return parent?.layoutMode === "HORIZONTAL";
+ })();
+ const emitW =
+ autoResize !== "WIDTH_AND_HEIGHT" && !isFillWidth && !isGrowWidth;
+ if (emitW && node.width > 0) props.push(["w", node.width]);
+ if (emitH && node.height > 0) props.push(["h", node.height]);
}
-function collectTextNodeProps(node: SceneNode, props: [string, unknown][]): void {
- const direction = resolveNodeTextDirection(node)
- if (node.fontSize !== 14) props.push(['size', node.fontSize])
- if (node.fontFamily && node.fontFamily !== DEFAULT_FONT_FAMILY)
- props.push(['font', node.fontFamily])
- if (node.fontWeight !== 400) {
- if (node.fontWeight === 700) props.push(['weight', 'bold'])
- else if (node.fontWeight === 500) props.push(['weight', 'medium'])
- else props.push(['weight', node.fontWeight])
- }
- if (direction === 'RTL') props.push(['dir', 'rtl'])
- if (node.textAlignHorizontal !== 'LEFT') {
- props.push(['textAlign', node.textAlignHorizontal.toLowerCase()])
- }
- if (node.lineHeight != null) props.push(['lineHeight', node.lineHeight])
- if (node.letterSpacing !== 0) props.push(['letterSpacing', node.letterSpacing])
- if (node.textDecoration !== 'NONE')
- props.push(['textDecoration', node.textDecoration.toLowerCase()])
- if (node.textCase !== 'ORIGINAL') props.push(['textCase', node.textCase.toLowerCase()])
- if (node.maxLines != null) props.push(['maxLines', node.maxLines])
- if (node.textTruncation === 'ENDING' && node.maxLines == null) props.push(['truncate', true])
- const textColor = solidFillColor(node.fills)
- if (textColor) {
- const bgIdx = props.findIndex(([k]) => k === 'bg')
- if (bgIdx !== -1) props.splice(bgIdx, 1)
- props.push(['color', textColor])
- }
+function collectTextNodeProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ const direction = resolveNodeTextDirection(node);
+ if (node.fontSize !== 14) props.push(["size", node.fontSize]);
+ if (node.fontFamily && node.fontFamily !== DEFAULT_FONT_FAMILY)
+ props.push(["font", node.fontFamily]);
+ if (node.fontWeight !== 400) {
+ if (node.fontWeight === 700) props.push(["weight", "bold"]);
+ else if (node.fontWeight === 500) props.push(["weight", "medium"]);
+ else props.push(["weight", node.fontWeight]);
+ }
+ if (direction === "RTL") props.push(["dir", "rtl"]);
+ if (node.textAlignHorizontal !== "LEFT") {
+ props.push(["textAlign", node.textAlignHorizontal.toLowerCase()]);
+ }
+ if (node.lineHeight != null) props.push(["lineHeight", node.lineHeight]);
+ if (node.letterSpacing !== 0)
+ props.push(["letterSpacing", node.letterSpacing]);
+ if (node.textDecoration !== "NONE")
+ props.push(["textDecoration", node.textDecoration.toLowerCase()]);
+ if (node.textCase !== "ORIGINAL")
+ props.push(["textCase", node.textCase.toLowerCase()]);
+ if (node.maxLines != null) props.push(["maxLines", node.maxLines]);
+ if (node.textTruncation === "ENDING" && node.maxLines == null)
+ props.push(["truncate", true]);
+ const textColor = solidFillColor(node.fills);
+ if (textColor) {
+ const bgIdx = props.findIndex(([k]) => k === "bg");
+ if (bgIdx !== -1) props.splice(bgIdx, 1);
+ props.push(["color", textColor]);
+ }
}
-function collectShapeNodeProps(node: SceneNode, props: [string, unknown][]): void {
- if (node.type === 'STAR') {
- if (node.pointCount !== 5) props.push(['points', node.pointCount])
- if (node.starInnerRadius !== 0.382) props.push(['innerRadius', node.starInnerRadius])
- }
- if (node.type === 'POLYGON' && node.pointCount !== 3) {
- props.push(['points', node.pointCount])
- }
+function collectShapeNodeProps(
+ node: SceneNode,
+ props: [string, unknown][],
+): void {
+ if (node.type === "STAR") {
+ if (node.pointCount !== 5) props.push(["points", node.pointCount]);
+ if (node.starInnerRadius !== 0.382)
+ props.push(["innerRadius", node.starInnerRadius]);
+ }
+ if (node.type === "POLYGON" && node.pointCount !== 3) {
+ props.push(["points", node.pointCount]);
+ }
}
function collectProps(node: SceneNode, graph: SceneGraph): [string, unknown][] {
- const props: [string, unknown][] = []
- const ctx = getNodeContext(node, graph)
+ const props: [string, unknown][] = [];
+ const ctx = getNodeContext(node, graph);
- if (node.name && node.name !== node.type) props.push(['name', node.name])
+ if (node.name && node.name !== node.type) props.push(["name", node.name]);
- collectPositionProps(node, ctx, props)
- collectSizingProps(node, ctx, graph, props)
- if (ctx.parentIsGrid) collectGridPositionProps(node, props)
- if (ctx.isFlex) collectFlexAlignmentProps(node, props)
- if (ctx.isAutoLayout) collectAutoLayoutPaddingProps(node, props)
- collectAppearanceProps(node, props)
- if (node.type === 'TEXT') collectTextNodeProps(node, props)
- collectShapeNodeProps(node, props)
+ collectPositionProps(node, ctx, props);
+ collectSizingProps(node, ctx, graph, props);
+ if (ctx.parentIsGrid) collectGridPositionProps(node, props);
+ if (ctx.isFlex) collectFlexAlignmentProps(node, props);
+ if (ctx.isAutoLayout) collectAutoLayoutPaddingProps(node, props);
+ collectAppearanceProps(node, props);
+ if (node.type === "TEXT") collectTextNodeProps(node, props);
+ collectShapeNodeProps(node, props);
- return props
+ return props;
}
// --- JSX rendering ---
-function nodeToJSX(node: SceneNode, graph: SceneGraph, indent: number, format: JSXFormat): string {
- const tagMap = format === 'tailwind' ? NODE_TYPE_TO_TW_TAG : NODE_TYPE_TO_TAG
- const tag = tagMap[node.type]
- if (!tag) return ''
-
- const prefix = ' '.repeat(indent)
- let attrsStr: string
-
- if (format === 'tailwind') {
- const classes = collectTailwindClasses(node, graph)
- const nameAttr = node.name && node.name !== node.type ? ` data-name="${node.name}"` : ''
- const classAttr = classes.length > 0 ? ` className="${classes.join(' ')}"` : ''
- attrsStr = `${nameAttr}${classAttr}`.trim()
- } else {
- const props = collectProps(node, graph)
- attrsStr = props.map(([k, v]) => formatProp(k, v)).join(' ')
- }
-
- const opening = attrsStr ? `<${tag} ${attrsStr}` : `<${tag}`
- const children = graph.getChildren(node.id)
-
- if (node.type === 'TEXT') {
- const text = node.text
- if (!text) return `${prefix}${opening} />`
- const escaped = escapeJSXText(text)
- if (!escaped.includes('\n')) {
- return `${prefix}${opening}>${escaped}</${tag}>`
- }
- return [
- `${prefix}${opening}>`,
- ...escaped.split('\n').map((l) => `${prefix} ${l}`),
- `${prefix}</${tag}>`
- ].join('\n')
- }
-
- if (children.length === 0) return `${prefix}${opening} />`
-
- const childJSX = children
- .filter((c) => c.visible)
- .map((c) => nodeToJSX(c, graph, indent + 1, format))
- .filter(Boolean)
-
- if (childJSX.length === 0) return `${prefix}${opening} />`
-
- return [`${prefix}${opening}>`, ...childJSX, `${prefix}</${tag}>`].join('\n')
+function nodeToJSX(
+ node: SceneNode,
+ graph: SceneGraph,
+ indent: number,
+ format: JSXFormat,
+): string {
+ const tagMap = format === "tailwind" ? NODE_TYPE_TO_TW_TAG : NODE_TYPE_TO_TAG;
+ const tag = tagMap[node.type];
+ if (!tag) return "";
+
+ const prefix = " ".repeat(indent);
+ let attrsStr: string;
+
+ if (format === "tailwind") {
+ const classes = collectTailwindClasses(node, graph);
+ const nameAttr =
+ node.name && node.name !== node.type ? ` data-name="${node.name}"` : "";
+ const classAttr =
+ classes.length > 0 ? ` className="${classes.join(" ")}"` : "";
+ attrsStr = `${nameAttr}${classAttr}`.trim();
+ } else {
+ const props = collectProps(node, graph);
+ attrsStr = props.map(([k, v]) => formatProp(k, v)).join(" ");
+ }
+
+ const opening = attrsStr ? `<${tag} ${attrsStr}` : `<${tag}`;
+ const children = graph.getChildren(node.id);
+
+ if (node.type === "TEXT") {
+ const text = node.text;
+ if (!text) return `${prefix}${opening} />`;
+ const escaped = escapeJSXText(text);
+ if (!escaped.includes("\n")) {
+ return `${prefix}${opening}>${escaped}</${tag}>`;
+ }
+ return [
+ `${prefix}${opening}>`,
+ ...escaped.split("\n").map((l) => `${prefix} ${l}`),
+ `${prefix}</${tag}>`,
+ ].join("\n");
+ }
+
+ if (children.length === 0) return `${prefix}${opening} />`;
+
+ const childJSX = children
+ .filter((c) => c.visible)
+ .map((c) => nodeToJSX(c, graph, indent + 1, format))
+ .filter(Boolean);
+
+ if (childJSX.length === 0) return `${prefix}${opening} />`;
+
+ return [`${prefix}${opening}>`, ...childJSX, `${prefix}</${tag}>`].join("\n");
}
export function sceneNodeToJSX(
- nodeId: string,
- graph: SceneGraph,
- format: JSXFormat = 'openpencil'
+ nodeId: string,
+ graph: SceneGraph,
+ format: JSXFormat = "openpencil",
): string {
- const node = graph.getNode(nodeId)
- if (!node) return ''
- return nodeToJSX(node, graph, 0, format)
+ const node = graph.getNode(nodeId);
+ if (!node) return "";
+ return nodeToJSX(node, graph, 0, format);
}
export function selectionToJSX(
- nodeIds: string[],
- graph: SceneGraph,
- format: JSXFormat = 'openpencil'
+ nodeIds: string[],
+ graph: SceneGraph,
+ format: JSXFormat = "openpencil",
): string {
- return nodeIds
- .map((id) => sceneNodeToJSX(id, graph, format))
- .filter(Boolean)
- .join('\n\n')
+ return nodeIds
+ .map((id) => sceneNodeToJSX(id, graph, format))
+ .filter(Boolean)
+ .join("\n\n");
}
diff --git a/packages/vue/src/i18n/messages.ts b/packages/vue/src/i18n/messages.ts
index b348347d0..74b1279f9 100644
--- a/packages/vue/src/i18n/messages.ts
+++ b/packages/vue/src/i18n/messages.ts
@@ -40,6 +40,7 @@ export const menuMessages = i18n("menu", {
saveAs: "Save as…",
exportSelection: "Export selection…",
autosave: "Auto-save to local file",
+ closeTab: "Close tab",
copy: "Copy",
paste: "Paste",
@@ -129,6 +130,7 @@ export const toolMessages = i18n("tools", {
});
export const panelMessages = i18n("panels", {
+ untitled: "Untitled",
nodeCopyString: " copy",
layers: "Layers",
pages: "Pages",
@@ -290,6 +292,7 @@ export const panelMessages = i18n("panels", {
setToCurrentHeight: "Set to current height",
sizingFillFr: "Fill (fr)",
sizingFixedPx: "Fixed (px)",
+ searchFonts: "Search fonts...",
});
export const variableTypeMessages = i18n("variableTypes", {
diff --git a/packages/vue/src/locales/es.json b/packages/vue/src/locales/es.json
index 8f2274696..d8c6ae88f 100644
--- a/packages/vue/src/locales/es.json
+++ b/packages/vue/src/locales/es.json
@@ -93,6 +93,7 @@
"hand": "Mano"
},
"panels": {
+ "untitled": "Sin título",
"nodeCopyString": " copia",
"layers": "Capas",
"pages": "Páginas",
@@ -244,7 +245,8 @@
"effectSettings": "Ajustes del efecto",
"expandEffectSettings": "Expandir ajustes del efecto",
"collapseEffectSettings": "Contraer ajustes del efecto",
- "toggleExportPreview": "Alternar vista previa de exportación"
+ "toggleExportPreview": "Alternar vista previa de exportación",
+ "searchFonts": "Buscar fuentes..."
},
"pages": {
"newPage": "Nueva página",
diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.ts
index d79d18b18..27bb60348 100644
--- a/src/app/shell/menu/app-menu.ts
+++ b/src/app/shell/menu/app-menu.ts
@@ -1,137 +1,151 @@
-import { computed } from 'vue'
-
-import { useEditorCommands, useI18n } from '@open-pencil/vue'
-import type { MenuEntry } from '@open-pencil/vue'
-
-import { useEditorStore } from '@/app/editor/active-store'
-import { createSharedEditorMenuActions } from '@/app/shell/menu/editor-actions'
-import { APP_MENU_SCHEMA } from '@/app/shell/menu/schema'
-import type { AppMenuActionItem, AppMenuEntry, AppMenuGroupSchema } from '@/app/shell/menu/schema'
-import { appMenuShortcutLabel } from '@/app/shell/menu/shortcut'
-import { openFileDialog } from '@/app/shell/menu/use'
-import { useAppTheme } from '@/app/shell/theme'
+import { computed } from "vue";
+
+import { useEditorCommands, useI18n } from "@open-pencil/vue";
+import type { MenuEntry } from "@open-pencil/vue";
+
+import { useEditorStore } from "@/app/editor/active-store";
+import { createSharedEditorMenuActions } from "@/app/shell/menu/editor-actions";
+import { APP_MENU_SCHEMA } from "@/app/shell/menu/schema";
+import type {
+ AppMenuActionItem,
+ AppMenuEntry,
+ AppMenuGroupSchema,
+} from "@/app/shell/menu/schema";
+import { appMenuShortcutLabel } from "@/app/shell/menu/shortcut";
+import { openFileDialog } from "@/app/shell/menu/use";
+import { useAppTheme } from "@/app/shell/theme";
export interface AppMenuGroup {
- label: string
- items: MenuEntry[]
+ label: string;
+ items: MenuEntry[];
}
function isVisible(entry: { target?: string }): boolean {
- return entry.target !== 'native'
+ return entry.target !== "native";
}
-function isSeparator(entry: AppMenuEntry): entry is Extract<AppMenuEntry, { type: 'separator' }> {
- return entry.type === 'separator'
+function isSeparator(
+ entry: AppMenuEntry,
+): entry is Extract<AppMenuEntry, { type: "separator" }> {
+ return entry.type === "separator";
}
export function useAppMenu() {
- const store = useEditorStore()
- const { menuItem: commandMenuItem } = useEditorCommands()
- const { locale, availableLocales, localeLabels, setLocale } = useI18n()
- const { theme, setTheme } = useAppTheme()
-
- const languageMenu = computed<MenuEntry[]>(() =>
- availableLocales.map((code) => ({
- label: localeLabels[code],
- checked: locale.value === code,
- onCheckedChange: (checked: boolean) => {
- if (checked) setLocale(code)
- }
- }))
- )
-
- function exportSelection(format: 'png' | 'svg' | 'fig') {
- if (store.state.selectedIds.size > 0) void store.exportSelection(1, format)
- }
-
- const actions: Partial<Record<string, () => void>> = {
- new: () => {
- void import('@/app/tabs').then((m) => m.createTab())
- },
- open: () => void openFileDialog(),
- save: () => void store.saveFigFile(),
- 'save-as': () => void store.saveFigFileAs(),
- 'export-selection': () => exportSelection('png'),
- cut: () => document.execCommand('cut'),
- 'export-png': () => exportSelection('png'),
- 'export-svg': () => exportSelection('svg'),
- 'export-fig': () => exportSelection('fig'),
- ...createSharedEditorMenuActions(setTheme)
- }
-
- function itemAction(item: AppMenuActionItem): (() => void) | undefined {
- return actions[item.id]
- }
-
- function checked(item: AppMenuActionItem): boolean | undefined {
- switch (item.id) {
- case 'autosave':
- return store.state.autosaveEnabled
- case 'profiler':
- return store.renderer?.profiler.hudVisible ?? false
- case 'theme-light':
- return theme.value === 'light'
- case 'theme-dark':
- return theme.value === 'dark'
- case 'theme-auto':
- return theme.value === 'auto'
- default:
- return undefined
- }
- }
-
- function onCheckedChange(item: AppMenuActionItem): ((checked: boolean) => void) | undefined {
- switch (item.id) {
- case 'autosave':
- return (value: boolean) => {
- store.state.autosaveEnabled = value
- }
- case 'profiler':
- return () => store.toggleProfiler()
- case 'theme-light':
- case 'theme-dark':
- case 'theme-auto':
- return (value: boolean) => {
- if (value) itemAction(item)?.()
- }
- default:
- return undefined
- }
- }
-
- function buildEntry(entry: AppMenuEntry): MenuEntry | null {
- if (!isVisible(entry)) return null
- if (isSeparator(entry)) return { separator: true }
-
- if (entry.id === 'language') {
- return { label: entry.label, sub: languageMenu.value }
- }
-
- if (entry.command) {
- return commandMenuItem(entry.command, appMenuShortcutLabel(entry.id))
- }
-
- return {
- label: entry.label,
- shortcut: appMenuShortcutLabel(entry.id),
- action: itemAction(entry),
- checked: checked(entry),
- onCheckedChange: onCheckedChange(entry),
- sub: entry.sub?.map(buildEntry).filter((item): item is MenuEntry => item !== null)
- }
- }
-
- function buildGroup(group: AppMenuGroupSchema): AppMenuGroup | null {
- if (!isVisible(group)) return null
- return {
- label: group.label,
- items: group.items.map(buildEntry).filter((item): item is MenuEntry => item !== null)
- }
- }
-
- const topMenus = computed<AppMenuGroup[]>(() =>
- APP_MENU_SCHEMA.map(buildGroup).filter((group): group is AppMenuGroup => group !== null)
- )
-
- return { topMenus }
+ const store = useEditorStore();
+ const { menuItem: commandMenuItem } = useEditorCommands();
+ const { locale, availableLocales, localeLabels, setLocale } = useI18n();
+ const { theme, setTheme } = useAppTheme();
+
+ const languageMenu = computed<MenuEntry[]>(() =>
+ availableLocales.map((code) => ({
+ label: localeLabels[code],
+ checked: locale.value === code,
+ onCheckedChange: (checked: boolean) => {
+ if (checked) setLocale(code);
+ },
+ })),
+ );
+
+ function exportSelection(format: "png" | "svg" | "fig") {
+ if (store.state.selectedIds.size > 0) void store.exportSelection(1, format);
+ }
+
+ const actions: Partial<Record<string, () => void>> = {
+ new: () => {
+ void import("@/app/tabs").then((m) => m.createTab());
+ },
+ open: () => void openFileDialog(),
+ save: () => void store.saveFigFile(),
+ "save-as": () => void store.saveFigFileAs(),
+ "export-selection": () => exportSelection("png"),
+ cut: () => document.execCommand("cut"),
+ "export-png": () => exportSelection("png"),
+ "export-svg": () => exportSelection("svg"),
+ "export-fig": () => exportSelection("fig"),
+ ...createSharedEditorMenuActions(setTheme),
+ };
+
+ function itemAction(item: AppMenuActionItem): (() => void) | undefined {
+ return actions[item.id];
+ }
+
+ function checked(item: AppMenuActionItem): boolean | undefined {
+ switch (item.id) {
+ case "autosave":
+ return store.state.autosaveEnabled;
+ case "profiler":
+ return store.renderer?.profiler.hudVisible ?? false;
+ case "theme-light":
+ return theme.value === "light";
+ case "theme-dark":
+ return theme.value === "dark";
+ case "theme-auto":
+ return theme.value === "auto";
+ default:
+ return undefined;
+ }
+ }
+
+ function onCheckedChange(
+ item: AppMenuActionItem,
+ ): ((checked: boolean) => void) | undefined {
+ switch (item.id) {
+ case "autosave":
+ return (value: boolean) => {
+ store.state.autosaveEnabled = value;
+ };
+ case "profiler":
+ return () => store.toggleProfiler();
+ case "theme-light":
+ case "theme-dark":
+ case "theme-auto":
+ return (value: boolean) => {
+ if (value) itemAction(item)?.();
+ };
+ default:
+ return undefined;
+ }
+ }
+
+ function buildEntry(entry: AppMenuEntry): MenuEntry | null {
+ if (!isVisible(entry)) return null;
+ if (isSeparator(entry)) return { separator: true };
+
+ if (entry.id === "language") {
+ return { label: entry.label, sub: languageMenu.value };
+ }
+
+ if (entry.command) {
+ return commandMenuItem(entry.command, appMenuShortcutLabel(entry.id));
+ }
+
+ return {
+ label: entry.label,
+ shortcut: appMenuShortcutLabel(entry.id),
+ action: itemAction(entry),
+ checked: checked(entry),
+ onCheckedChange: onCheckedChange(entry),
+ sub: entry.sub
+ ?.map(buildEntry)
+ .filter((item): item is MenuEntry => item !== null),
+ };
+ }
+
+ function buildGroup(group: AppMenuGroupSchema): AppMenuGroup | null {
+ if (!isVisible(group)) return null;
+ return {
+ label: group.label,
+ items: group.items
+ .map(buildEntry)
+ .filter((item): item is MenuEntry => item !== null),
+ };
+ }
+
+ const topMenus = computed<AppMenuGroup[]>(() =>
+ APP_MENU_SCHEMA.map(buildGroup).filter(
+ (group): group is AppMenuGroup => group !== null,
+ ),
+ );
+
+ return { topMenus };
}
diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema.ts
index 2dc968729..b643bb73e 100644
--- a/src/app/shell/menu/schema.ts
+++ b/src/app/shell/menu/schema.ts
@@ -1,242 +1,255 @@
-import type { EditorCommandId } from '@open-pencil/vue'
+import { type EditorCommandId, useI18n } from "@open-pencil/vue";
+const { menu } = useI18n();
-export type AppMenuTarget = 'all' | 'browser' | 'native'
+export type AppMenuTarget = "all" | "browser" | "native";
export interface AppMenuActionItem {
- type?: 'item'
- id: string
- label: string
- shortcut?: string
- accelerator?: string
- command?: EditorCommandId
- checkbox?: boolean
- target?: AppMenuTarget
- sub?: AppMenuEntry[]
+ type?: "item";
+ id: string;
+ label: string;
+ shortcut?: string;
+ accelerator?: string;
+ command?: EditorCommandId;
+ checkbox?: boolean;
+ target?: AppMenuTarget;
+ sub?: AppMenuEntry[];
}
export interface AppMenuSeparatorItem {
- type: 'separator'
- target?: AppMenuTarget
+ type: "separator";
+ target?: AppMenuTarget;
}
-export type AppMenuEntry = AppMenuActionItem | AppMenuSeparatorItem
+export type AppMenuEntry = AppMenuActionItem | AppMenuSeparatorItem;
export interface AppMenuGroupSchema {
- label: string
- target?: AppMenuTarget
- items: AppMenuEntry[]
+ label: string;
+ target?: AppMenuTarget;
+ items: AppMenuEntry[];
}
export const APP_MENU_SCHEMA = [
- {
- label: 'File',
- items: [
- { id: 'new', label: 'New', shortcut: 'MOD+N' },
- { id: 'open', label: 'Open…', shortcut: 'MOD+O' },
- { type: 'separator' },
- { id: 'save', label: 'Save', shortcut: 'MOD+S' },
- { id: 'save-as', label: 'Save As…', shortcut: 'MOD+SHIFT+S' },
- { type: 'separator' },
- {
- id: 'export-selection',
- label: 'Export Selection',
- shortcut: 'MOD+SHIFT+E',
- sub: [
- { id: 'export-png', label: 'PNG' },
- { id: 'export-svg', label: 'SVG' },
- { id: 'export-fig', label: '.fig' }
- ]
- },
- { type: 'separator' },
- { id: 'autosave', label: 'Autosave', checkbox: true },
- { id: 'close', label: 'Close Tab', shortcut: 'MOD+W' }
- ]
- },
- {
- label: 'Edit',
- items: [
- {
- id: 'edit.undo',
- label: 'Undo',
- command: 'edit.undo'
- },
- {
- id: 'edit.redo',
- label: 'Redo',
- command: 'edit.redo'
- },
- { type: 'separator' },
- { id: 'copy', label: 'Copy', shortcut: 'MOD+C' },
- { id: 'cut', label: 'Cut', shortcut: 'MOD+X' },
- { id: 'paste', label: 'Paste', shortcut: 'MOD+V' },
- { id: 'paste-to-replace', label: 'Paste to replace' },
- {
- id: 'selection.duplicate',
- label: 'Duplicate',
- command: 'selection.duplicate'
- },
- {
- id: 'selection.delete',
- label: 'Delete',
- command: 'selection.delete'
- },
- { type: 'separator' },
- {
- id: 'selection.selectAll',
- label: 'Select All',
- command: 'selection.selectAll'
- }
- ]
- },
- {
- label: 'View',
- items: [
- {
- id: 'view.zoom100',
- label: 'Zoom to 100%',
- command: 'view.zoom100'
- },
- {
- id: 'view.zoomFit',
- label: 'Zoom to Fit',
- command: 'view.zoomFit'
- },
- {
- id: 'view.zoomSelection',
- label: 'Zoom to Selection',
- command: 'view.zoomSelection'
- },
- { id: 'zoom-in', label: 'Zoom In', shortcut: 'MOD+=' },
- { id: 'zoom-out', label: 'Zoom Out', shortcut: 'MOD+-' },
- { type: 'separator' },
- {
- id: 'theme',
- label: 'Theme',
- sub: [
- { id: 'theme-light', label: 'Light', checkbox: true },
- { id: 'theme-dark', label: 'Dark', checkbox: true },
- { id: 'theme-auto', label: 'Auto', checkbox: true }
- ]
- },
- { id: 'language', label: 'Language', target: 'browser' },
- { type: 'separator' },
- { id: 'toggle-ui', label: 'Toggle UI', shortcut: 'MOD+\\' },
- { id: 'profiler', label: 'Profiler', checkbox: true, target: 'browser' },
- {
- id: 'dev-tools',
- label: 'Developer Tools',
- accelerator: 'CmdOrCtrl+Alt+I',
- target: 'native'
- }
- ]
- },
- {
- label: 'Object',
- items: [
- {
- id: 'selection.group',
- label: 'Group Selection',
- command: 'selection.group'
- },
- {
- id: 'selection.frameSelection',
- label: 'Frame Selection',
- command: 'selection.frameSelection'
- },
- {
- id: 'selection.ungroup',
- label: 'Ungroup Selection',
- command: 'selection.ungroup'
- },
- { type: 'separator' },
- {
- id: 'selection.booleanUnion',
- label: 'Union selection',
- command: 'selection.booleanUnion'
- },
- {
- id: 'selection.booleanSubtract',
- label: 'Subtract selection',
- command: 'selection.booleanSubtract'
- },
- {
- id: 'selection.booleanIntersect',
- label: 'Intersect selection',
- command: 'selection.booleanIntersect'
- },
- {
- id: 'selection.booleanExclude',
- label: 'Exclude selection',
- command: 'selection.booleanExclude'
- },
- {
- id: 'selection.flatten',
- label: 'Flatten',
- command: 'selection.flatten'
- },
- {
- id: 'selection.outlineText',
- label: 'Outline text',
- command: 'selection.outlineText'
- },
- {
- id: 'selection.outlineStroke',
- label: 'Outline stroke',
- command: 'selection.outlineStroke'
- },
- { type: 'separator' },
- {
- id: 'selection.createComponent',
- label: 'Create Component',
- command: 'selection.createComponent'
- },
- {
- id: 'selection.createComponentSet',
- label: 'Create Component Set',
- command: 'selection.createComponentSet'
- },
- {
- id: 'selection.detachInstance',
- label: 'Detach Instance',
- command: 'selection.detachInstance'
- },
- { type: 'separator' },
- {
- id: 'selection.bringToFront',
- label: 'Bring to Front',
- command: 'selection.bringToFront'
- },
- {
- id: 'selection.sendToBack',
- label: 'Send to Back',
- command: 'selection.sendToBack'
- }
- ]
- },
- {
- label: 'Text',
- items: [
- { id: 'text.bold', label: 'Bold', shortcut: 'MOD+B' },
- { id: 'text.italic', label: 'Italic', shortcut: 'MOD+I' },
- { id: 'text.underline', label: 'Underline', shortcut: 'MOD+U' }
- ]
- },
- {
- label: 'Arrange',
- items: [
- {
- id: 'selection.wrapInAutoLayout',
- label: 'Wrap in Auto Layout',
- command: 'selection.wrapInAutoLayout'
- },
- { type: 'separator' },
- { id: 'align-left', label: 'Align Left', shortcut: 'ALT+A' },
- { id: 'align-center', label: 'Align Center', shortcut: 'ALT+H' },
- { id: 'align-right', label: 'Align Right', shortcut: 'ALT+D' },
- { type: 'separator' },
- { id: 'align-top', label: 'Align Top', shortcut: 'ALT+W' },
- { id: 'align-middle', label: 'Align Middle', shortcut: 'ALT+V' },
- { id: 'align-bottom', label: 'Align Bottom', shortcut: 'ALT+S' }
- ]
- }
-] satisfies AppMenuGroupSchema[]
+ {
+ label: "File",
+ items: [
+ { id: "new", label: menu.value.new || "New", shortcut: "MOD+N" },
+ { id: "open", label: menu.value.open || "Open…", shortcut: "MOD+O" },
+ { type: "separator" },
+ { id: "save", label: menu.value.save || "Save", shortcut: "MOD+S" },
+ {
+ id: "save-as",
+ label: menu.value.saveAs || "Save As…",
+ shortcut: "MOD+SHIFT+S",
+ },
+ { type: "separator" },
+ {
+ id: "export-selection",
+ label: menu.value.exportSelection || "Export Selection",
+ shortcut: "MOD+SHIFT+E",
+ sub: [
+ { id: "export-png", label: "PNG" },
+ { id: "export-svg", label: "SVG" },
+ { id: "export-fig", label: ".fig" },
+ ],
+ },
+ { type: "separator" },
+ {
+ id: "autosave",
+ label: menu.value.autosave || "Autosave",
+ checkbox: true,
+ },
+ {
+ id: "close",
+ label: menu.value.closeTab || "Close Tab",
+ shortcut: "MOD+W",
+ },
+ ],
+ },
+ {
+ label: "Edit",
+ items: [
+ {
+ id: "edit.undo",
+ label: "Undo",
+ command: "edit.undo",
+ },
+ {
+ id: "edit.redo",
+ label: "Redo",
+ command: "edit.redo",
+ },
+ { type: "separator" },
+ { id: "copy", label: "Copy", shortcut: "MOD+C" },
+ { id: "cut", label: "Cut", shortcut: "MOD+X" },
+ { id: "paste", label: "Paste", shortcut: "MOD+V" },
+ { id: "paste-to-replace", label: "Paste to replace" },
+ {
+ id: "selection.duplicate",
+ label: "Duplicate",
+ command: "selection.duplicate",
+ },
+ {
+ id: "selection.delete",
+ label: "Delete",
+ command: "selection.delete",
+ },
+ { type: "separator" },
+ {
+ id: "selection.selectAll",
+ label: "Select All",
+ command: "selection.selectAll",
+ },
+ ],
+ },
+ {
+ label: "View",
+ items: [
+ {
+ id: "view.zoom100",
+ label: "Zoom to 100%",
+ command: "view.zoom100",
+ },
+ {
+ id: "view.zoomFit",
+ label: "Zoom to Fit",
+ command: "view.zoomFit",
+ },
+ {
+ id: "view.zoomSelection",
+ label: "Zoom to Selection",
+ command: "view.zoomSelection",
+ },
+ { id: "zoom-in", label: "Zoom In", shortcut: "MOD+=" },
+ { id: "zoom-out", label: "Zoom Out", shortcut: "MOD+-" },
+ { type: "separator" },
+ {
+ id: "theme",
+ label: "Theme",
+ sub: [
+ { id: "theme-light", label: "Light", checkbox: true },
+ { id: "theme-dark", label: "Dark", checkbox: true },
+ { id: "theme-auto", label: "Auto", checkbox: true },
+ ],
+ },
+ { id: "language", label: "Language", target: "browser" },
+ { type: "separator" },
+ { id: "toggle-ui", label: "Toggle UI", shortcut: "MOD+\\" },
+ { id: "profiler", label: "Profiler", checkbox: true, target: "browser" },
+ {
+ id: "dev-tools",
+ label: "Developer Tools",
+ accelerator: "CmdOrCtrl+Alt+I",
+ target: "native",
+ },
+ ],
+ },
+ {
+ label: "Object",
+ items: [
+ {
+ id: "selection.group",
+ label: "Group Selection",
+ command: "selection.group",
+ },
+ {
+ id: "selection.frameSelection",
+ label: "Frame Selection",
+ command: "selection.frameSelection",
+ },
+ {
+ id: "selection.ungroup",
+ label: "Ungroup Selection",
+ command: "selection.ungroup",
+ },
+ { type: "separator" },
+ {
+ id: "selection.booleanUnion",
+ label: "Union selection",
+ command: "selection.booleanUnion",
+ },
+ {
+ id: "selection.booleanSubtract",
+ label: "Subtract selection",
+ command: "selection.booleanSubtract",
+ },
+ {
+ id: "selection.booleanIntersect",
+ label: "Intersect selection",
+ command: "selection.booleanIntersect",
+ },
+ {
+ id: "selection.booleanExclude",
+ label: "Exclude selection",
+ command: "selection.booleanExclude",
+ },
+ {
+ id: "selection.flatten",
+ label: "Flatten",
+ command: "selection.flatten",
+ },
+ {
+ id: "selection.outlineText",
+ label: "Outline text",
+ command: "selection.outlineText",
+ },
+ {
+ id: "selection.outlineStroke",
+ label: "Outline stroke",
+ command: "selection.outlineStroke",
+ },
+ { type: "separator" },
+ {
+ id: "selection.createComponent",
+ label: "Create Component",
+ command: "selection.createComponent",
+ },
+ {
+ id: "selection.createComponentSet",
+ label: "Create Component Set",
+ command: "selection.createComponentSet",
+ },
+ {
+ id: "selection.detachInstance",
+ label: "Detach Instance",
+ command: "selection.detachInstance",
+ },
+ { type: "separator" },
+ {
+ id: "selection.bringToFront",
+ label: "Bring to Front",
+ command: "selection.bringToFront",
+ },
+ {
+ id: "selection.sendToBack",
+ label: "Send to Back",
+ command: "selection.sendToBack",
+ },
+ ],
+ },
+ {
+ label: "Text",
+ items: [
+ { id: "text.bold", label: "Bold", shortcut: "MOD+B" },
+ { id: "text.italic", label: "Italic", shortcut: "MOD+I" },
+ { id: "text.underline", label: "Underline", shortcut: "MOD+U" },
+ ],
+ },
+ {
+ label: "Arrange",
+ items: [
+ {
+ id: "selection.wrapInAutoLayout",
+ label: "Wrap in Auto Layout",
+ command: "selection.wrapInAutoLayout",
+ },
+ { type: "separator" },
+ { id: "align-left", label: "Align Left", shortcut: "ALT+A" },
+ { id: "align-center", label: "Align Center", shortcut: "ALT+H" },
+ { id: "align-right", label: "Align Right", shortcut: "ALT+D" },
+ { type: "separator" },
+ { id: "align-top", label: "Align Top", shortcut: "ALT+W" },
+ { id: "align-middle", label: "Align Middle", shortcut: "ALT+V" },
+ { id: "align-bottom", label: "Align Bottom", shortcut: "ALT+S" },
+ ],
+ },
+] satisfies AppMenuGroupSchema[];