Skip to content

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

refactor: remove duplicated implementation blocks

Danila Poyarkove94323ee29aa
diff --git a/packages/core/src/canvas/effects.ts b/packages/core/src/canvas/effects.ts
index 4a3a996fe..041662b71 100644
--- a/packages/core/src/canvas/effects.ts
+++ b/packages/core/src/canvas/effects.ts
@@ -73,164 +73,3 @@ export function applyClippedBlur(
r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)
canvas.restore()
}
-
-import { nodeHasRadius } from './shapes'
-export { nodeHasRadius }
-
-function drawShapeDropShadow(
- r: SkiaRenderer,
- canvas: Canvas,
- node: SceneNode,
- effect: SceneNode['effects'][number],
- hasRadius: boolean,
- shadowShapeChild?: SceneNode | null
-): void {
- const sp = effect.spread
- const shapeNode = shadowShapeChild ?? node
- const shapeHasRadius = shadowShapeChild ? nodeHasRadius(shadowShapeChild) : hasRadius
- const strokeShadow =
- !shadowShapeChild && !node.fills.some((fill) => fill.visible) && node.strokeGeometry.length > 0
- ? r.getStrokeGeometry(node)
- : null
-
- r.auxFill.setColor(r.color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a))
- r.auxFill.setMaskFilter(r.getCachedMaskBlur(effect.radius / 2))
- r.auxFill.setImageFilter(null)
- canvas.save()
- canvas.translate(
- effect.offset.x + (shadowShapeChild?.x ?? 0),
- effect.offset.y + (shadowShapeChild?.y ?? 0)
- )
- if (strokeShadow) {
- for (const path of strokeShadow) canvas.drawPath(path, r.auxFill)
- } else if (shapeNode.type === 'ELLIPSE') {
- canvas.drawOval(r.ltrb(-sp, -sp, shapeNode.width + sp, shapeNode.height + sp), r.auxFill)
- } else if (shapeHasRadius) {
- canvas.drawRRect(r.makeRRectWithSpread(shapeNode, sp), r.auxFill)
- } else {
- canvas.drawRect(r.ltrb(-sp, -sp, shapeNode.width + sp, shapeNode.height + sp), r.auxFill)
- }
- canvas.restore()
- r.auxFill.setMaskFilter(null)
-}
-
-function renderDropShadow(
- r: SkiaRenderer,
- canvas: Canvas,
- node: SceneNode,
- effect: SceneNode['effects'][number],
- hasRadius: boolean,
- shadowShapeChild?: SceneNode | null
-): void {
- if (node.type !== 'TEXT') {
- drawShapeDropShadow(r, canvas, node, effect, hasRadius, shadowShapeChild)
- return
- }
-
- const shadowColor = r.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)
- const dropFilter = r.getCachedDropShadow(
- effect.offset.x,
- effect.offset.y,
- effect.radius / 2,
- shadowColor
- )
- r.effectLayerPaint.setImageFilter(dropFilter)
- canvas.saveLayer(r.effectLayerPaint)
- r.renderText(canvas, node)
- canvas.restore()
-}
-
-export function renderEffects(
- r: SkiaRenderer,
- canvas: Canvas,
- node: SceneNode,
- rect: Float32Array,
- hasRadius: boolean,
- pass: 'behind' | 'front',
- shadowShapeChild?: SceneNode | null
-): void {
- for (const effect of node.effects) {
- if (!effect.visible) continue
-
- if (pass === 'behind' && effect.type === 'DROP_SHADOW') {
- renderDropShadow(r, canvas, node, effect, hasRadius, shadowShapeChild)
- }
-
- if (pass === 'behind' && effect.type === 'BACKGROUND_BLUR') {
- r.applyClippedBlur(canvas, node, rect, hasRadius, effect.radius / 2)
- }
-
- if (pass === 'front' && effect.type === 'INNER_SHADOW') {
- if (node.type === 'TEXT') {
- r.effectLayerPaint.setImageFilter(r.getCachedDecalBlur(effect.radius / 2))
- r.effectLayerPaint.setColorFilter(
- r.ck.ColorFilter.MakeBlend(
- r.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a),
- r.ck.BlendMode.SrcIn
- )
- )
- canvas.saveLayer(r.effectLayerPaint)
- canvas.save()
- canvas.translate(effect.offset.x, effect.offset.y)
- r.renderText(canvas, node)
- canvas.restore()
- canvas.restore()
- r.effectLayerPaint.setColorFilter(null)
- continue
- }
- const sp = effect.spread
- r.auxFill.setColor(
- r.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)
- )
- r.auxFill.setImageFilter(r.getCachedDecalBlur(effect.radius / 2))
-
- canvas.save()
- r.clipNodeShape(canvas, node, rect, hasRadius)
-
- const expand = effect.radius * 2
- const big = r.ck.LTRBRect(
- -expand + effect.offset.x,
- -expand + effect.offset.y,
- node.width + expand + effect.offset.x,
- node.height + expand + effect.offset.y
- )
- const bigPath = new r.ck.Path()
- bigPath.addRect(big)
- if (node.type === 'ELLIPSE') {
- const innerPath = new r.ck.Path()
- const offsetRect = r.ck.LTRBRect(
- effect.offset.x + sp,
- effect.offset.y + sp,
- node.width + effect.offset.x - sp,
- node.height + effect.offset.y - sp
- )
- innerPath.addOval(offsetRect)
- bigPath.op(innerPath, r.ck.PathOp.Difference)
- innerPath.delete()
- } else if (hasRadius) {
- const innerPath = new r.ck.Path()
- innerPath.addRRect(
- r.makeRRectWithOffset(node, effect.offset.x + sp, effect.offset.y + sp, -sp)
- )
- bigPath.op(innerPath, r.ck.PathOp.Difference)
- innerPath.delete()
- } else {
- const innerPath = new r.ck.Path()
- innerPath.addRect(
- r.ck.LTRBRect(
- effect.offset.x + sp,
- effect.offset.y + sp,
- node.width + effect.offset.x - sp,
- node.height + effect.offset.y - sp
- )
- )
- bigPath.op(innerPath, r.ck.PathOp.Difference)
- innerPath.delete()
- }
- canvas.drawPath(bigPath, r.auxFill)
- bigPath.delete()
- canvas.restore()
- r.auxFill.setImageFilter(null)
- }
- }
-}
diff --git a/packages/core/src/canvas/scene.ts b/packages/core/src/canvas/scene.ts
index c260b1e00..18bd8a367 100644
--- a/packages/core/src/canvas/scene.ts
+++ b/packages/core/src/canvas/scene.ts
@@ -5,7 +5,7 @@ import type { SceneNode, SceneGraph, Fill } from '#core/scene-graph'
import type { Color } from '#core/types'
import { vectorNetworkToCenterlinePath } from '#core/vector'
-import { nodeHasRadius } from './effects'
+import { nodeHasRadius } from './shapes'
import type { SkiaRenderer, RenderOverlays } from './renderer'
function drawVisibleFills(
diff --git a/packages/core/src/canvas/shadows.ts b/packages/core/src/canvas/shadows.ts
index 584e549d4..e8a1a6304 100644
--- a/packages/core/src/canvas/shadows.ts
+++ b/packages/core/src/canvas/shadows.ts
@@ -5,8 +5,8 @@ import type { SceneNode } from '#core/scene-graph'
import type { SkiaRenderer } from './renderer'
import { nodeHasRadius } from './shapes'
-function drawChildTransform(canvas: Canvas, child: SceneNode): void {
- canvas.translate(child.x, child.y)
+function drawChildTransform(canvas: Canvas, child: SceneNode, offset = { x: 0, y: 0 }): void {
+ canvas.translate(child.x + offset.x, child.y + offset.y)
if (child.rotation !== 0) {
canvas.rotate(child.rotation, child.width / 2, child.height / 2)
}
@@ -16,6 +16,25 @@ function drawChildTransform(canvas: Canvas, child: SceneNode): void {
}
}
+function localEffectOffset(effect: SceneNode['effects'][number], child?: SceneNode | null) {
+ let x = effect.offset.x
+ let y = effect.offset.y
+ if (!child) return { x, y }
+
+ if (child.rotation !== 0) {
+ const rad = (-child.rotation * Math.PI) / 180
+ const cos = Math.cos(rad)
+ const sin = Math.sin(rad)
+ const nx = x * cos - y * sin
+ const ny = x * sin + y * cos
+ x = nx
+ y = ny
+ }
+ if (child.flipX) x = -x
+ if (child.flipY) y = -y
+ return { x, y }
+}
+
function drawShapeDropShadow(
r: SkiaRenderer,
canvas: Canvas,
@@ -37,25 +56,8 @@ function drawShapeDropShadow(
r.auxFill.setImageFilter(null)
canvas.save()
- if (shadowShapeChild) {
- canvas.translate(shadowShapeChild.x + effect.offset.x, shadowShapeChild.y + effect.offset.y)
- if (shadowShapeChild.rotation !== 0) {
- canvas.rotate(
- shadowShapeChild.rotation,
- shadowShapeChild.width / 2,
- shadowShapeChild.height / 2
- )
- }
- if (shadowShapeChild.flipX || shadowShapeChild.flipY) {
- canvas.translate(
- shadowShapeChild.flipX ? shadowShapeChild.width : 0,
- shadowShapeChild.flipY ? shadowShapeChild.height : 0
- )
- canvas.scale(shadowShapeChild.flipX ? -1 : 1, shadowShapeChild.flipY ? -1 : 1)
- }
- } else {
- canvas.translate(effect.offset.x, effect.offset.y)
- }
+ if (shadowShapeChild) drawChildTransform(canvas, shadowShapeChild, effect.offset)
+ else canvas.translate(effect.offset.x, effect.offset.y)
if (strokeShadow) {
for (const path of strokeShadow) canvas.drawPath(path, r.auxFill)
@@ -97,25 +99,8 @@ function renderDropShadow(
const dropFilter = r.getCachedDropShadow(0, 0, effect.radius / 2, shadowColor)
canvas.save()
- if (shadowShapeChild) {
- canvas.translate(shadowShapeChild.x + effect.offset.x, shadowShapeChild.y + effect.offset.y)
- if (shadowShapeChild.rotation !== 0) {
- canvas.rotate(
- shadowShapeChild.rotation,
- shadowShapeChild.width / 2,
- shadowShapeChild.height / 2
- )
- }
- if (shadowShapeChild.flipX || shadowShapeChild.flipY) {
- canvas.translate(
- shadowShapeChild.flipX ? shadowShapeChild.width : 0,
- shadowShapeChild.flipY ? shadowShapeChild.height : 0
- )
- canvas.scale(shadowShapeChild.flipX ? -1 : 1, shadowShapeChild.flipY ? -1 : 1)
- }
- } else {
- canvas.translate(effect.offset.x, effect.offset.y)
- }
+ if (shadowShapeChild) drawChildTransform(canvas, shadowShapeChild, effect.offset)
+ else canvas.translate(effect.offset.x, effect.offset.y)
r.effectLayerPaint.setImageFilter(dropFilter)
canvas.saveLayer(r.effectLayerPaint)
@@ -164,22 +149,7 @@ function drawTextInnerShadow(
r.effectLayerPaint.setColorFilter(tintFilter)
canvas.saveLayer(r.effectLayerPaint)
- // 4. Calculate local offset for parent-space parity
- let localOffsetX = effect.offset.x
- let localOffsetY = effect.offset.y
- if (shadowShapeChild) {
- if (shadowShapeChild.rotation !== 0) {
- const rad = (-shadowShapeChild.rotation * Math.PI) / 180
- const cos = Math.cos(rad)
- const sin = Math.sin(rad)
- const nx = localOffsetX * cos - localOffsetY * sin
- const ny = localOffsetX * sin + localOffsetY * cos
- localOffsetX = nx
- localOffsetY = ny
- }
- if (shadowShapeChild.flipX) localOffsetX = -localOffsetX
- if (shadowShapeChild.flipY) localOffsetY = -localOffsetY
- }
+ const { x: localOffsetX, y: localOffsetY } = localEffectOffset(effect, shadowShapeChild)
// 5. Apply Transform: Move the canvas by the local offset
canvas.save()
@@ -267,21 +237,7 @@ function drawShapeInnerShadow(
}
const expand = effect.radius * 2
- let localOffsetX = effect.offset.x
- let localOffsetY = effect.offset.y
- if (shadowShapeChild) {
- if (shadowShapeChild.rotation !== 0) {
- const rad = (-shadowShapeChild.rotation * Math.PI) / 180
- const cos = Math.cos(rad)
- const sin = Math.sin(rad)
- const nx = localOffsetX * cos - localOffsetY * sin
- const ny = localOffsetX * sin + localOffsetY * cos
- localOffsetX = nx
- localOffsetY = ny
- }
- if (shadowShapeChild.flipX) localOffsetX = -localOffsetX
- if (shadowShapeChild.flipY) localOffsetY = -localOffsetY
- }
+ const { x: localOffsetX, y: localOffsetY } = localEffectOffset(effect, shadowShapeChild)
const spreadPadding = sp < 0 ? -sp : 0
const big = r.ck.LTRBRect(
diff --git a/packages/core/src/editor/clipboard.ts b/packages/core/src/editor/clipboard.ts
index 53f51180a..ed406a242 100644
--- a/packages/core/src/editor/clipboard.ts
+++ b/packages/core/src/editor/clipboard.ts
@@ -59,6 +59,29 @@ export function createClipboardActions(ctx: EditorContext) {
}
}
+ function pushPasteUndo(created: string[], prevSelection: Set<string>) {
+ const allNodes = collectSubtrees(ctx.graph, created)
+ const pageId = ctx.state.currentPageId
+ ctx.undo.push({
+ label: 'Paste',
+ forward: () => {
+ for (const snapshot of allNodes) {
+ ctx.graph.createNode(snapshot.type, snapshot.parentId ?? pageId, {
+ ...snapshot,
+ childIds: []
+ })
+ }
+ computeAllLayouts(ctx.graph, pageId)
+ ctx.setSelectedIds(new Set(created))
+ },
+ inverse: () => {
+ for (const id of [...created].reverse()) ctx.graph.deleteNode(id)
+ computeAllLayouts(ctx.graph, pageId)
+ ctx.setSelectedIds(prevSelection)
+ }
+ })
+ }
+
async function pasteFromHTML(html: string, cursorPos?: Vector) {
const openPencil = parseOpenPencilClipboard(html)
if (openPencil) {
@@ -79,26 +102,7 @@ export function createClipboardActions(ctx: EditorContext) {
computeAllLayouts(ctx.graph, ctx.state.currentPageId)
ctx.setSelectedIds(new Set(created))
- const allNodes = collectSubtrees(ctx.graph, created)
- const pageId = ctx.state.currentPageId
- ctx.undo.push({
- label: 'Paste',
- forward: () => {
- for (const snapshot of allNodes) {
- ctx.graph.createNode(snapshot.type, snapshot.parentId ?? pageId, {
- ...snapshot,
- childIds: []
- })
- }
- computeAllLayouts(ctx.graph, pageId)
- ctx.setSelectedIds(new Set(created))
- },
- inverse: () => {
- for (const id of [...created].reverse()) ctx.graph.deleteNode(id)
- computeAllLayouts(ctx.graph, pageId)
- ctx.setSelectedIds(prevSelection)
- }
- })
+ pushPasteUndo(created, prevSelection)
void fontActions.loadFontsForNodes(created)
warnMissingImages(created)
ctx.requestRender()
@@ -135,26 +139,7 @@ export function createClipboardActions(ctx: EditorContext) {
computeAllLayouts(ctx.graph, ctx.state.currentPageId)
ctx.setSelectedIds(new Set(created))
- const allNodes = collectSubtrees(ctx.graph, created)
- const pageId = ctx.state.currentPageId
- ctx.undo.push({
- label: 'Paste',
- forward: () => {
- for (const snapshot of allNodes) {
- ctx.graph.createNode(snapshot.type, snapshot.parentId ?? pageId, {
- ...snapshot,
- childIds: []
- })
- }
- computeAllLayouts(ctx.graph, pageId)
- ctx.setSelectedIds(new Set(created))
- },
- inverse: () => {
- for (const id of [...created].reverse()) ctx.graph.deleteNode(id)
- computeAllLayouts(ctx.graph, pageId)
- ctx.setSelectedIds(prevSelection)
- }
- })
+ pushPasteUndo(created, prevSelection)
}
function warnMissingImages(nodeIds: string[]) {
diff --git a/packages/core/src/editor/components/variants.ts b/packages/core/src/editor/components/variants.ts
index 1a66f7af4..45e21331d 100644
--- a/packages/core/src/editor/components/variants.ts
+++ b/packages/core/src/editor/components/variants.ts
@@ -1,5 +1,6 @@
import type { EditorContext } from '#core/editor/types'
import { randomHex } from '#core/random'
+import { buildVariantName, parseVariantName } from '#core/scene-graph/variant-name'
import type {
ComponentPropertyDefinition,
ComponentPropertyType,
@@ -130,50 +131,24 @@ export function createVariantActions(ctx: EditorContext) {
ctx.graph.updateNode(childId, { componentPropertyValues: values })
}
}
+ const renamePropertyDef = (name: string) => {
+ const n = ctx.graph.getNode(componentSetId)
+ if (!n) return
+ ctx.graph.updateNode(componentSetId, {
+ componentPropertyDefinitions: n.componentPropertyDefinitions.map((d) =>
+ d.id === propertyId ? { ...d, name } : d
+ )
+ })
+ ctx.requestRender()
+ }
ctx.undo.push({
label: 'Rename property',
- forward: () => {
- const n = ctx.graph.getNode(componentSetId)
- if (n) {
- ctx.graph.updateNode(componentSetId, {
- componentPropertyDefinitions: n.componentPropertyDefinitions.map((d) =>
- d.id === propertyId ? { ...d, name: newName } : d
- )
- })
- }
- ctx.requestRender()
- },
- inverse: () => {
- const n = ctx.graph.getNode(componentSetId)
- if (n) {
- ctx.graph.updateNode(componentSetId, {
- componentPropertyDefinitions: n.componentPropertyDefinitions.map((d) =>
- d.id === propertyId ? { ...d, name: prevName } : d
- )
- })
- }
- ctx.requestRender()
- }
+ forward: () => renamePropertyDef(newName),
+ inverse: () => renamePropertyDef(prevName)
})
ctx.requestRender()
}
- function parseVariantName(name: string): Record<string, string> {
- const values: Record<string, string> = {}
- for (const part of name.split(',').map((s) => s.trim())) {
- const eqIdx = part.indexOf('=')
- if (eqIdx === -1) continue
- values[part.slice(0, eqIdx).trim()] = part.slice(eqIdx + 1).trim()
- }
- return values
- }
-
- function buildVariantName(values: Record<string, string>): string {
- return Object.entries(values)
- .map(([k, v]) => `${k}=${v}`)
- .join(', ')
- }
-
function collectVariantOptions(componentSetId: string): Map<string, Set<string>> {
const node = ctx.graph.getNode(componentSetId)
if (node?.type !== 'COMPONENT_SET') return new Map()
diff --git a/packages/core/src/editor/types.ts b/packages/core/src/editor/types.ts
index da5d52b5c..f7910bb26 100644
--- a/packages/core/src/editor/types.ts
+++ b/packages/core/src/editor/types.ts
@@ -2,7 +2,13 @@ import type { CanvasKit } from 'canvaskit-wasm'
import type { RulerTheme, SkiaRenderer } from '#core/canvas/renderer'
import type { RenderOverlays } from '#core/canvas/renderer/types'
-import type { SceneGraph, SceneNode, VectorSegment, VectorVertex } from '#core/scene-graph'
+import type {
+ SceneGraph,
+ SceneGraphEvents,
+ SceneNode,
+ VectorSegment,
+ VectorVertex
+} from '#core/scene-graph'
import type { SnapGuide } from '#core/scene-graph/snap'
import type { UndoManager } from '#core/scene-graph/undo'
import type { TextEditor } from '#core/text/editor'
@@ -80,15 +86,10 @@ export interface EditorState {
cursorCanvasY?: number | null
}
-export interface EditorEvents {
+export interface EditorEvents extends SceneGraphEvents {
'render:requested': (versions: { renderVersion: number; sceneVersion: number }) => void
'repaint:requested': (versions: { renderVersion: number; sceneVersion: number }) => void
'graph:replaced': (graph: SceneGraph) => void
- 'node:created': (node: SceneNode) => void
- 'node:updated': (id: string, changes: Partial<SceneNode>) => void
- 'node:deleted': (id: string) => void
- 'node:reparented': (nodeId: string, oldParentId: string | null, newParentId: string) => void
- 'node:reordered': (nodeId: string, parentId: string, index: number) => void
'selection:changed': (selectedIds: string[], previousIds: string[]) => void
'tool:changed': (tool: Tool, previousTool: Tool) => void
'page:changed': (pageId: string, previousPageId: string) => void
diff --git a/packages/core/src/icons/path-style.ts b/packages/core/src/icons/path-style.ts
new file mode 100644
index 000000000..33e698339
--- /dev/null
+++ b/packages/core/src/icons/path-style.ts
@@ -0,0 +1,31 @@
+import type { SceneNode, Stroke } from '#core/scene-graph'
+import type { Color } from '#core/types'
+
+const STROKE_CAP_MAP: Record<string, SceneNode['strokeCap']> = {
+ butt: 'NONE',
+ round: 'ROUND',
+ square: 'SQUARE'
+}
+
+const STROKE_JOIN_MAP: Record<string, SceneNode['strokeJoin']> = {
+ miter: 'MITER',
+ round: 'ROUND',
+ bevel: 'BEVEL'
+}
+
+export function createPathStroke(
+ color: Color,
+ weight: number,
+ strokeCap: string,
+ strokeJoin: string
+): Stroke {
+ return {
+ color,
+ weight,
+ opacity: 1,
+ visible: true,
+ align: 'CENTER',
+ cap: STROKE_CAP_MAP[strokeCap] ?? 'NONE',
+ join: STROKE_JOIN_MAP[strokeJoin] ?? 'MITER'
+ }
+}
diff --git a/packages/core/src/icons/render.ts b/packages/core/src/icons/render.ts
index 47fc8fba8..81f1e49ce 100644
--- a/packages/core/src/icons/render.ts
+++ b/packages/core/src/icons/render.ts
@@ -1,21 +1,10 @@
import { parseColor } from '#core/color'
-import type { SceneGraph, SceneNode, Stroke } from '#core/scene-graph'
+import { createPathStroke } from '#core/icons/path-style'
+import type { SceneGraph, SceneNode } from '#core/scene-graph'
import type { Color } from '#core/types'
import type { IconData } from './types'
-const STROKE_CAP_MAP: Record<string, SceneNode['strokeCap']> = {
- butt: 'NONE',
- round: 'ROUND',
- square: 'SQUARE'
-}
-
-const STROKE_JOIN_MAP: Record<string, SceneNode['strokeJoin']> = {
- miter: 'MITER',
- round: 'ROUND',
- bevel: 'BEVEL'
-}
-
export function createIconFromPaths(
graph: SceneGraph,
icon: IconData,
@@ -54,16 +43,9 @@ export function createIconFromPaths(
if (path.stroke) {
const strokeColor = path.stroke === 'currentColor' ? color : parseColor(path.stroke)
- const stroke: Stroke = {
- color: strokeColor,
- weight: path.strokeWidth,
- opacity: 1,
- visible: true,
- align: 'CENTER',
- cap: STROKE_CAP_MAP[path.strokeCap] ?? 'NONE',
- join: STROKE_JOIN_MAP[path.strokeJoin] ?? 'MITER'
- }
- graph.updateNode(vector.id, { strokes: [stroke] })
+ graph.updateNode(vector.id, {
+ strokes: [createPathStroke(strokeColor, path.strokeWidth, path.strokeCap, path.strokeJoin)]
+ })
}
}
diff --git a/packages/core/src/io/formats/svg/paths.ts b/packages/core/src/io/formats/svg/paths.ts
index e4ca9c178..85d7f9a5a 100644
--- a/packages/core/src/io/formats/svg/paths.ts
+++ b/packages/core/src/io/formats/svg/paths.ts
@@ -1,4 +1,5 @@
import { polygonVertices } from '#core/geometry'
+import { nodeHasRadius } from '#core/canvas/shapes'
import type { SceneNode, VectorNetwork, VectorSegment, VectorVertex } from '#core/scene-graph'
const CMD_CLOSE = 0
@@ -113,16 +114,7 @@ export function makePolygonPoints(node: SceneNode): string {
.join(' ')
}
-export function hasRadius(node: SceneNode): boolean {
- return (
- node.cornerRadius > 0 ||
- (node.independentCorners &&
- (node.topLeftRadius > 0 ||
- node.topRightRadius > 0 ||
- node.bottomRightRadius > 0 ||
- node.bottomLeftRadius > 0))
- )
-}
+export const hasRadius = nodeHasRadius
export function roundedRectPath(node: SceneNode): string {
const w = node.width
diff --git a/packages/core/src/kiwi/node-change/convert.ts b/packages/core/src/kiwi/node-change/convert.ts
index fcc79df41..c4df4608f 100644
--- a/packages/core/src/kiwi/node-change/convert.ts
+++ b/packages/core/src/kiwi/node-change/convert.ts
@@ -1,5 +1,6 @@
/* eslint-disable max-lines -- kiwi↔scene conversion helpers are tightly coupled */
import { DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT } from '#core/constants'
+import { parseVariantName } from '#core/scene-graph/variant-name'
import { styleToWeight } from '#core/text/fonts'
import { guidToString } from './guid'
@@ -505,13 +506,7 @@ function extractComponentPropertyValues(nc: NodeChange): Record<string, string>
const name = nc.name
if (!name?.includes('=')) return {}
- const values: Record<string, string> = {}
- for (const part of name.split(',').map((s) => s.trim())) {
- const eqIdx = part.indexOf('=')
- if (eqIdx === -1) continue
- values[part.slice(0, eqIdx).trim()] = part.slice(eqIdx + 1).trim()
- }
- return values
+ return parseVariantName(name)
}
type ComponentMetadataProps = Pick<
diff --git a/packages/core/src/scene-graph/variant-name.ts b/packages/core/src/scene-graph/variant-name.ts
new file mode 100644
index 000000000..619360ca8
--- /dev/null
+++ b/packages/core/src/scene-graph/variant-name.ts
@@ -0,0 +1,15 @@
+export function parseVariantName(name: string): Record<string, string> {
+ const values: Record<string, string> = {}
+ for (const part of name.split(',').map((s) => s.trim())) {
+ const eqIdx = part.indexOf('=')
+ if (eqIdx === -1) continue
+ values[part.slice(0, eqIdx).trim()] = part.slice(eqIdx + 1).trim()
+ }
+ return values
+}
+
+export function buildVariantName(values: Record<string, string>): string {
+ return Object.entries(values)
+ .map(([k, v]) => `${k}=${v}`)
+ .join(', ')
+}
diff --git a/packages/core/src/tools/create/svg.ts b/packages/core/src/tools/create/svg.ts
index b931d5056..70e82f1cc 100644
--- a/packages/core/src/tools/create/svg.ts
+++ b/packages/core/src/tools/create/svg.ts
@@ -1,22 +1,10 @@
import { parseColor } from '#core/color'
+import { createPathStroke } from '#core/icons/path-style'
import { extractPaths } from '#core/icons/svg'
import type { IconPathInfo } from '#core/icons/types'
import { parseSVGPath } from '#core/io/formats/svg/parse-path'
-import type { SceneNode, Stroke } from '#core/scene-graph'
import { defineTool } from '#core/tools/schema'
-const STROKE_CAP_MAP: Record<string, SceneNode['strokeCap']> = {
- butt: 'NONE',
- round: 'ROUND',
- square: 'SQUARE'
-}
-
-const STROKE_JOIN_MAP: Record<string, SceneNode['strokeJoin']> = {
- miter: 'MITER',
- round: 'ROUND',
- bevel: 'BEVEL'
-}
-
import type { Rect } from '#core/types'
function parseSvgViewBox(svg: string): Rect | null {
@@ -79,16 +67,9 @@ function createVectorFromPath(
if (path.stroke && path.stroke !== 'none') {
const strokeColor =
path.stroke === 'currentColor' ? parseColor(defaultColor) : parseColor(path.stroke)
- const stroke: Stroke = {
- color: strokeColor,
- weight: path.strokeWidth,
- opacity: 1,
- visible: true,
- align: 'CENTER',
- cap: STROKE_CAP_MAP[path.strokeCap] ?? 'NONE',
- join: STROKE_JOIN_MAP[path.strokeJoin] ?? 'MITER'
- }
- figma.graph.updateNode(vector.id, { strokes: [stroke] })
+ figma.graph.updateNode(vector.id, {
+ strokes: [createPathStroke(strokeColor, path.strokeWidth, path.strokeCap, path.strokeJoin)]
+ })
}
return vector
diff --git a/packages/core/src/vector/centerline.ts b/packages/core/src/vector/centerline.ts
index d5834fdf9..02951f3e2 100644
--- a/packages/core/src/vector/centerline.ts
+++ b/packages/core/src/vector/centerline.ts
@@ -1,6 +1,8 @@
import type { CanvasKit, Path } from 'canvaskit-wasm'
-import type { VectorNetwork, VectorSegment, VectorVertex } from '#core/scene-graph'
+import { addOpenSegmentsToPath } from './path-helpers'
+
+import type { VectorNetwork } from '#core/scene-graph'
import type { Vector } from '#core/types'
export function fitCircleArc(
@@ -184,75 +186,6 @@ function buildCenterlineFromCrescent(
return path
}
-function addSegmentDirected(
- path: Path,
- seg: VectorSegment,
- vertices: VectorVertex[],
- forward: boolean
-): void {
- const p0 = forward ? vertices[seg.start] : vertices[seg.end]
- const p3 = forward ? vertices[seg.end] : vertices[seg.start]
- const ts = seg.tangentStart
- const te = seg.tangentEnd
- const isLine = ts.x === 0 && ts.y === 0 && te.x === 0 && te.y === 0
- if (isLine) {
- path.lineTo(p3.x, p3.y)
- } else if (forward) {
- path.cubicTo(p0.x + ts.x, p0.y + ts.y, p3.x + te.x, p3.y + te.y, p3.x, p3.y)
- } else {
- path.cubicTo(p0.x + te.x, p0.y + te.y, p3.x + ts.x, p3.y + ts.y, p3.x, p3.y)
- }
-}
-
-function findChainStart(chain: number[], segments: VectorSegment[]): number {
- if (chain.length < 2) return segments[chain[0]].start
- const first = segments[chain[0]]
- const second = segments[chain[1]]
- if (first.start === second.start || first.start === second.end) return first.end
- return first.start
-}
-
-function buildChains(segments: VectorSegment[]): number[][] {
- if (segments.length === 0) return []
- const adj = new Map<number, number[]>()
- for (let i = 0; i < segments.length; i++) {
- const s = segments[i]
- let startList = adj.get(s.start)
- if (!startList) {
- startList = []
- adj.set(s.start, startList)
- }
- startList.push(i)
- let endList = adj.get(s.end)
- if (!endList) {
- endList = []
- adj.set(s.end, endList)
- }
- endList.push(i)
- }
- const visited = new Set<number>()
- const chains: number[][] = []
- const degree1 = [...adj.entries()].filter(([, segs]) => segs.length === 1).map(([v]) => v)
- const startVertices = degree1.length > 0 ? degree1 : [segments[0].start]
- for (const startVertex of startVertices) {
- let current = startVertex
- const chain: number[] = []
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- while (true) {
- const segs = adj.get(current)
- if (!segs) break
- const nextSeg = segs.find((s) => !visited.has(s))
- if (nextSeg === undefined) break
- visited.add(nextSeg)
- chain.push(nextSeg)
- const seg = segments[nextSeg]
- current = seg.start === current ? seg.end : seg.start
- }
- if (chain.length > 0) chains.push(chain)
- }
- return chains
-}
-
export function vectorNetworkToCenterlinePath(ck: CanvasKit, network: VectorNetwork): Path {
const { vertices, segments } = network
@@ -263,28 +196,6 @@ export function vectorNetworkToCenterlinePath(ck: CanvasKit, network: VectorNetw
}
const path = new ck.Path()
- const visited = new Set<number>()
- const chains = buildChains(segments)
-
- for (const chain of chains) {
- if (chain.length === 0) continue
- let current = findChainStart(chain, segments)
- path.moveTo(vertices[current].x, vertices[current].y)
- for (const segIdx of chain) {
- visited.add(segIdx)
- const seg = segments[segIdx]
- const forward = seg.start === current
- addSegmentDirected(path, seg, vertices, forward)
- current = forward ? seg.end : seg.start
- }
- }
-
- for (let i = 0; i < segments.length; i++) {
- if (visited.has(i)) continue
- const seg = segments[i]
- path.moveTo(vertices[seg.start].x, vertices[seg.start].y)
- addSegmentDirected(path, seg, vertices, true)
- }
-
+ addOpenSegmentsToPath(path, segments, vertices)
return path
}
diff --git a/packages/core/src/vector/index.ts b/packages/core/src/vector/index.ts
index f3246bdb5..6097a9467 100644
--- a/packages/core/src/vector/index.ts
+++ b/packages/core/src/vector/index.ts
@@ -12,6 +12,8 @@ export {
import type { CanvasKit, Path } from 'canvaskit-wasm'
+import { addOpenSegmentsToPath, addSegmentDirected } from './path-helpers'
+
import type {
HandleMirroring,
VectorNetwork,
@@ -236,33 +238,8 @@ export function vectorNetworkToPath(ck: CanvasKit, network: VectorNetwork): Path
return paths
}
- // No regions — draw all segments as open paths, tracking direction
const path = new ck.Path()
- const visited = new Set<number>()
- const chains = buildChains(segments, vertices.length)
-
- for (const chain of chains) {
- if (chain.length === 0) continue
- // Determine starting vertex by tracing chain direction
- let current = findChainStart(chain, segments)
- path.moveTo(vertices[current].x, vertices[current].y)
-
- for (const segIdx of chain) {
- visited.add(segIdx)
- const seg = segments[segIdx]
- const forward = seg.start === current
- addSegmentDirected(path, seg, vertices, forward)
- current = forward ? seg.end : seg.start
- }
- }
-
- for (let i = 0; i < segments.length; i++) {
- if (visited.has(i)) continue
- const seg = segments[i]
- path.moveTo(vertices[seg.start].x, vertices[seg.start].y)
- addSegmentDirected(path, seg, vertices, true)
- }
-
+ addOpenSegmentsToPath(path, segments, vertices)
return [path]
}
@@ -303,85 +280,6 @@ function addLoopToPath(
path.close()
}
-function addSegmentDirected(
- path: Path,
- seg: VectorSegment,
- vertices: VectorVertex[],
- forward: boolean
-): void {
- const p0 = forward ? vertices[seg.start] : vertices[seg.end]
- const p3 = forward ? vertices[seg.end] : vertices[seg.start]
- const ts = seg.tangentStart
- const te = seg.tangentEnd
-
- const isLine = ts.x === 0 && ts.y === 0 && te.x === 0 && te.y === 0
- if (isLine) {
- path.lineTo(p3.x, p3.y)
- } else if (forward) {
- path.cubicTo(p0.x + ts.x, p0.y + ts.y, p3.x + te.x, p3.y + te.y, p3.x, p3.y)
- } else {
- // Reversed cubic: swap control points
- path.cubicTo(p0.x + te.x, p0.y + te.y, p3.x + ts.x, p3.y + ts.y, p3.x, p3.y)
- }
-}
-
-function findChainStart(chain: number[], segments: VectorSegment[]): number {
- if (chain.length < 2) return segments[chain[0]].start
-
- const first = segments[chain[0]]
- const second = segments[chain[1]]
- // The shared vertex between first and second is the "end" of the first
- // segment in this chain — so the start is the other vertex.
- if (first.start === second.start || first.start === second.end) return first.end
- return first.start
-}
-
-function buildChains(segments: VectorSegment[], _vertexCount: number): number[][] {
- if (segments.length === 0) return []
-
- // Build adjacency: for each vertex, which segments connect to it
- const adj = new Map<number, number[]>()
- for (let i = 0; i < segments.length; i++) {
- const s = segments[i]
- if (!adj.has(s.start)) adj.set(s.start, [])
- if (!adj.has(s.end)) adj.set(s.end, [])
- adj.get(s.start)?.push(i)
- adj.get(s.end)?.push(i)
- }
-
- const visited = new Set<number>()
- const chains: number[][] = []
-
- // Start from degree-1 vertices (endpoints) or any unvisited
- const degree1 = [...adj.entries()].filter(([, segs]) => segs.length === 1).map(([v]) => v)
-
- const startVertices = degree1.length > 0 ? degree1 : [segments[0].start]
-
- for (const startVertex of startVertices) {
- let current = startVertex
- const chain: number[] = []
-
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- while (true) {
- const segs = adj.get(current)
- if (!segs) break
-
- const nextSeg = segs.find((s) => !visited.has(s))
- if (nextSeg === undefined) break
-
- visited.add(nextSeg)
- chain.push(nextSeg)
-
- const seg = segments[nextSeg]
- current = seg.start === current ? seg.end : seg.start
- }
-
- if (chain.length > 0) chains.push(chain)
- }
-
- return chains
-}
-
export function computeVectorBounds(network: VectorNetwork): Rect {
return computeAccurateBounds(network)
}
diff --git a/packages/core/src/vector/path-helpers.ts b/packages/core/src/vector/path-helpers.ts
new file mode 100644
index 000000000..c28294f61
--- /dev/null
+++ b/packages/core/src/vector/path-helpers.ts
@@ -0,0 +1,106 @@
+import type { Path } from 'canvaskit-wasm'
+
+import type { VectorSegment, VectorVertex } from '#core/scene-graph'
+
+export function addSegmentDirected(
+ path: Path,
+ seg: VectorSegment,
+ vertices: VectorVertex[],
+ forward: boolean
+): void {
+ const p0 = forward ? vertices[seg.start] : vertices[seg.end]
+ const p3 = forward ? vertices[seg.end] : vertices[seg.start]
+ const ts = seg.tangentStart
+ const te = seg.tangentEnd
+
+ const isLine = ts.x === 0 && ts.y === 0 && te.x === 0 && te.y === 0
+ if (isLine) {
+ path.lineTo(p3.x, p3.y)
+ } else if (forward) {
+ path.cubicTo(p0.x + ts.x, p0.y + ts.y, p3.x + te.x, p3.y + te.y, p3.x, p3.y)
+ } else {
+ path.cubicTo(p0.x + te.x, p0.y + te.y, p3.x + ts.x, p3.y + ts.y, p3.x, p3.y)
+ }
+}
+
+export function findChainStart(chain: number[], segments: VectorSegment[]): number {
+ if (chain.length < 2) return segments[chain[0]].start
+
+ const first = segments[chain[0]]
+ const second = segments[chain[1]]
+ if (first.start === second.start || first.start === second.end) return first.end
+ return first.start
+}
+
+export function addOpenSegmentsToPath(
+ path: Path,
+ segments: VectorSegment[],
+ vertices: VectorVertex[]
+): void {
+ const visited = new Set<number>()
+ const chains = buildChains(segments)
+
+ for (const chain of chains) {
+ if (chain.length === 0) continue
+ let current = findChainStart(chain, segments)
+ path.moveTo(vertices[current].x, vertices[current].y)
+ for (const segIdx of chain) {
+ visited.add(segIdx)
+ const seg = segments[segIdx]
+ const forward = seg.start === current
+ addSegmentDirected(path, seg, vertices, forward)
+ current = forward ? seg.end : seg.start
+ }
+ }
+
+ for (let i = 0; i < segments.length; i++) {
+ if (visited.has(i)) continue
+ const seg = segments[i]
+ path.moveTo(vertices[seg.start].x, vertices[seg.start].y)
+ addSegmentDirected(path, seg, vertices, true)
+ }
+}
+
+export function buildChains(segments: VectorSegment[]): number[][] {
+ if (segments.length === 0) return []
+
+ const adj = new Map<number, number[]>()
+ for (let i = 0; i < segments.length; i++) {
+ const s = segments[i]
+ const startList = adj.get(s.start) ?? []
+ startList.push(i)
+ adj.set(s.start, startList)
+
+ const endList = adj.get(s.end) ?? []
+ endList.push(i)
+ adj.set(s.end, endList)
+ }
+
+ const visited = new Set<number>()
+ const chains: number[][] = []
+ const degree1 = [...adj.entries()].filter(([, segs]) => segs.length === 1).map(([v]) => v)
+ const startVertices = degree1.length > 0 ? degree1 : [segments[0].start]
+
+ for (const startVertex of startVertices) {
+ let current = startVertex
+ const chain: number[] = []
+
+ for (;;) {
+ const segs = adj.get(current)
+ if (!segs) break
+
+ const nextSeg = segs.find((s) => !visited.has(s))
+ if (nextSeg === undefined) break
+
+ visited.add(nextSeg)
+ chain.push(nextSeg)
+
+ const seg = segments[nextSeg]
+ current = seg.start === current ? seg.end : seg.start
+ }
+
+ if (chain.length > 0) chains.push(chain)
+ }
+
+ return chains
+}
diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.ts
index 65159e682..615c7e51e 100644
--- a/src/app/shell/menu/app-menu.ts
+++ b/src/app/shell/menu/app-menu.ts
@@ -4,6 +4,7 @@ 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 { openFileDialog } from '@/app/shell/menu/use'
@@ -46,24 +47,6 @@ export function useAppMenu(mod: string) {
if (store.state.selectedIds.size > 0) void store.exportSelection(1, format)
}
- function alignSelected(axis: 'horizontal' | 'vertical', align: 'min' | 'center' | 'max') {
- store.alignNodes([...store.state.selectedIds], axis, align)
- }
-
- function updateSelectedText(updates: {
- fontWeight?: number
- italic?: boolean
- textDecoration?: 'NONE' | 'UNDERLINE'
- }) {
- for (const node of store.selectedNodes.value) {
- if (node.type === 'TEXT') store.updateNodeWithUndo(node.id, updates, 'Format text')
- }
- }
-
- function selectedTextNode() {
- return store.selectedNodes.value.find((item) => item.type === 'TEXT')
- }
-
const actions: Partial<Record<string, () => void>> = {
new: () => {
void import('@/app/tabs').then((m) => m.createTab())
@@ -75,34 +58,7 @@ export function useAppMenu(mod: string) {
'export-png': () => exportSelection('png'),
'export-svg': () => exportSelection('svg'),
'export-fig': () => exportSelection('fig'),
- 'zoom-in': () => store.applyZoom(-100, window.innerWidth / 2, window.innerHeight / 2),
- 'zoom-out': () => store.applyZoom(100, window.innerWidth / 2, window.innerHeight / 2),
- 'toggle-ui': () => {
- store.state.showUI = !store.state.showUI
- },
- 'theme-light': () => setTheme('light'),
- 'theme-dark': () => setTheme('dark'),
- 'theme-auto': () => setTheme('auto'),
- 'text.bold': () => {
- const node = selectedTextNode()
- updateSelectedText({ fontWeight: node && node.fontWeight >= 700 ? 400 : 700 })
- },
- 'text.italic': () => {
- const node = selectedTextNode()
- updateSelectedText({ italic: node ? !node.italic : true })
- },
- 'text.underline': () => {
- const node = selectedTextNode()
- updateSelectedText({
- textDecoration: node?.textDecoration === 'UNDERLINE' ? 'NONE' : 'UNDERLINE'
- })
- },
- 'align-left': () => alignSelected('horizontal', 'min'),
- 'align-center': () => alignSelected('horizontal', 'center'),
- 'align-right': () => alignSelected('horizontal', 'max'),
- 'align-top': () => alignSelected('vertical', 'min'),
- 'align-middle': () => alignSelected('vertical', 'center'),
- 'align-bottom': () => alignSelected('vertical', 'max')
+ ...createSharedEditorMenuActions(setTheme)
}
function itemAction(item: AppMenuActionItem): (() => void) | undefined {
diff --git a/src/app/shell/menu/editor-actions.ts b/src/app/shell/menu/editor-actions.ts
new file mode 100644
index 000000000..0994b417f
--- /dev/null
+++ b/src/app/shell/menu/editor-actions.ts
@@ -0,0 +1,64 @@
+import type { SceneNode } from '@open-pencil/core/scene-graph'
+
+import { useEditorStore } from '@/app/editor/active-store'
+
+type TextFormatUpdates = {
+ fontWeight?: number
+ italic?: boolean
+ textDecoration?: 'NONE' | 'UNDERLINE'
+}
+
+const store = useEditorStore()
+
+export function alignSelected(axis: 'horizontal' | 'vertical', align: 'min' | 'center' | 'max'): void {
+ store.alignNodes([...store.state.selectedIds], axis, align)
+}
+
+export function updateSelectedText(updates: TextFormatUpdates): void {
+ for (const node of store.selectedNodes.value) {
+ if (node.type === 'TEXT') store.updateNodeWithUndo(node.id, updates, 'Format text')
+ }
+}
+
+export function selectedTextNode(): SceneNode | undefined {
+ return store.selectedNodes.value.find((item) => item.type === 'TEXT')
+}
+
+export function toggleSelectedTextBold(): void {
+ const node = selectedTextNode()
+ updateSelectedText({ fontWeight: node && node.fontWeight >= 700 ? 400 : 700 })
+}
+
+export function toggleSelectedTextItalic(): void {
+ const node = selectedTextNode()
+ updateSelectedText({ italic: node ? !node.italic : true })
+}
+
+export function toggleSelectedTextUnderline(): void {
+ const node = selectedTextNode()
+ updateSelectedText({
+ textDecoration: node?.textDecoration === 'UNDERLINE' ? 'NONE' : 'UNDERLINE'
+ })
+}
+
+export function createSharedEditorMenuActions(setTheme: (theme: 'light' | 'dark' | 'auto') => void) {
+ return {
+ 'zoom-in': () => store.applyZoom(-100, window.innerWidth / 2, window.innerHeight / 2),
+ 'zoom-out': () => store.applyZoom(100, window.innerWidth / 2, window.innerHeight / 2),
+ 'toggle-ui': () => {
+ store.state.showUI = !store.state.showUI
+ },
+ 'theme-light': () => setTheme('light'),
+ 'theme-dark': () => setTheme('dark'),
+ 'theme-auto': () => setTheme('auto'),
+ 'text.bold': toggleSelectedTextBold,
+ 'text.italic': toggleSelectedTextItalic,
+ 'text.underline': toggleSelectedTextUnderline,
+ 'align-left': () => alignSelected('horizontal', 'min'),
+ 'align-center': () => alignSelected('horizontal', 'center'),
+ 'align-right': () => alignSelected('horizontal', 'max'),
+ 'align-top': () => alignSelected('vertical', 'min'),
+ 'align-middle': () => alignSelected('vertical', 'center'),
+ 'align-bottom': () => alignSelected('vertical', 'max')
+ }
+}
diff --git a/src/app/shell/menu/use.ts b/src/app/shell/menu/use.ts
index 340cf6fc4..69e81f62d 100644
--- a/src/app/shell/menu/use.ts
+++ b/src/app/shell/menu/use.ts
@@ -4,6 +4,7 @@ import { useEditorCommands, useI18n } from '@open-pencil/vue'
import type { EditorCommandId } from '@open-pencil/vue'
import { useEditorStore } from '@/app/editor/active-store'
+import { createSharedEditorMenuActions } from '@/app/shell/menu/editor-actions'
import { importFileDialog, openFileDialog } from '@/app/shell/menu/files'
import { useAppTheme } from '@/app/shell/theme'
import { checkForAppUpdate } from '@/app/shell/updater'
@@ -37,20 +38,6 @@ function execBrowserCommand(command: 'copy' | 'paste'): void {
document.execCommand(command)
}
-function alignSelected(axis: 'horizontal' | 'vertical', align: 'min' | 'center' | 'max'): void {
- store.alignNodes([...store.state.selectedIds], axis, align)
-}
-
-function updateSelectedText(updates: {
- fontWeight?: number
- italic?: boolean
- textDecoration?: 'NONE' | 'UNDERLINE'
-}): void {
- for (const node of store.selectedNodes.value) {
- if (node.type === 'TEXT') store.updateNodeWithUndo(node.id, updates, 'Format text')
- }
-}
-
export function useMenu() {
if (!isTauri()) return
@@ -84,35 +71,8 @@ export function useMenu() {
},
copy: () => execBrowserCommand('copy'),
paste: () => execBrowserCommand('paste'),
- 'zoom-in': () => store.applyZoom(-100, window.innerWidth / 2, window.innerHeight / 2),
- 'zoom-out': () => store.applyZoom(100, window.innerWidth / 2, window.innerHeight / 2),
- 'theme-light': () => setTheme('light'),
- 'theme-dark': () => setTheme('dark'),
- 'theme-auto': () => setTheme('auto'),
- 'toggle-ui': () => {
- store.state.showUI = !store.state.showUI
- },
'check-updates': () => void checkForAppUpdate({ messages: dialogs }),
- 'text.bold': () => {
- const node = store.selectedNodes.value.find((item) => item.type === 'TEXT')
- updateSelectedText({ fontWeight: node && node.fontWeight >= 700 ? 400 : 700 })
- },
- 'text.italic': () => {
- const node = store.selectedNodes.value.find((item) => item.type === 'TEXT')
- updateSelectedText({ italic: node ? !node.italic : true })
- },
- 'text.underline': () => {
- const node = store.selectedNodes.value.find((item) => item.type === 'TEXT')
- updateSelectedText({
- textDecoration: node?.textDecoration === 'UNDERLINE' ? 'NONE' : 'UNDERLINE'
- })
- },
- 'align-left': () => alignSelected('horizontal', 'min'),
- 'align-center': () => alignSelected('horizontal', 'center'),
- 'align-right': () => alignSelected('horizontal', 'max'),
- 'align-top': () => alignSelected('vertical', 'min'),
- 'align-middle': () => alignSelected('vertical', 'center'),
- 'align-bottom': () => alignSelected('vertical', 'max')
+ ...createSharedEditorMenuActions(setTheme)
}
void import('@tauri-apps/api/event').then(({ listen }) => {