Skip to content

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

feat(demo): rebuild the first page as a component library with staged loading (#717)

Danila Poyarkov81a07c0c9ac2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93d47cd4c..716498407 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- Create new documents with the sRGB colour profile, so Display P3 is reserved for documents that declare it.
- Export diagnostics from Settings only. AI requests and tool activity now carry conversation and request identifiers, while chat no longer offers a separate diagnostic log or includes transcript content.
+- Replace the demo's legacy reference page with a component library on the first page, including component sets, linked instances, component properties, and the variable collections.
### Fixed
@@ -26,6 +27,7 @@
- Point Homebrew installation instructions to the official `openpencil` cask and document separate CLI installation.
- Let the desktop app use an MCP server you started yourself by allowing the app's own origin by default, instead of requiring `OPENPENCIL_MCP_CORS_ORIGIN`.
- Reach the custom model option in the model picker for providers with large model catalogs instead of requiring a search for it.
+- Show the standard canvas loading overlay and tab indicator while the demo document is generated, instead of an empty canvas.
### Performance
diff --git a/src/app/demo/document.ts b/src/app/demo/document.ts
index 3a6aa94f8..386b3257c 100644
--- a/src/app/demo/document.ts
+++ b/src/app/demo/document.ts
@@ -1,53 +1,189 @@
import { computeAllLayouts } from '@open-pencil/core/layout'
+import type { SceneGraph } from '@open-pencil/scene-graph'
+import { yieldToUI } from '@/app/document/io/browser'
import type { EditorStore } from '@/app/editor/session'
import { createAnnouncementSection } from './announcement/section'
import { loadDemoFonts } from './fonts'
import { createPaintSection } from './paint/section'
-import { createReferenceExamples } from './reference'
+import { createComponentsSection } from './sections/components'
+import { createDemoVariables } from './sections/variables'
import { createTypographySection } from './typography/section'
import { fitDemoPagesOnFirstVisit } from './viewport'
-export async function createDemoShapes(store: EditorStore) {
- const { graph } = store
- const referencePageId = store.state.currentPageId
- await store.canvasReady
- await loadDemoFonts()
- // A file opened while the canvas was loading must not receive demo content.
- if (
- store.graph !== graph ||
- store.state.currentPageId !== referencePageId ||
- graph.getPages().length !== 1 ||
- graph.getChildren(referencePageId).length > 0
- )
- return
-
- graph.updateNode(referencePageId, { name: 'Reference · original examples' })
- await createReferenceExamples(store)
- if (store.graph !== graph) return
+const PAGE_ORIGIN = 60
+const PAGE_GAP = 64
- const announcements = graph.addPage('01 · Components & variables')
- const typography = graph.addPage('02 · Typography')
- const paint = graph.addPage('03 · Paint & effects')
- await createAnnouncementSection(graph, announcements.id)
- await createTypographySection(graph, typography.id)
- await createPaintSection(graph, paint.id)
+type DemoPreparation = ReturnType<EditorStore['preparationController']['begin']>
- for (const page of graph.getPages()) {
- await store.loadFontsForNodes(page.childIds)
- computeAllLayouts(graph, page.id)
- }
- if (store.graph !== graph) return
- store.movePage(referencePageId, graph.getPages().length - 1)
- store.undo.clear()
- fitDemoPagesOnFirstVisit(
- store,
- graph.getPages().map((page) => page.id)
- )
- await store.switchPage(announcements.id)
+interface DemoBuildState {
+ initialPageId: string
+ initialPageName: string | null
+ preexistingCollections: ReadonlySet<string>
+ createdRootIds: string[]
+ createdPageIds: string[]
+}
+
+interface DemoBuild {
+ graph: SceneGraph
+ state: DemoBuildState
+ /** Resolves false when the build was abandoned before it finished. */
+ run: () => Promise<boolean>
+}
+
+/**
+ * A superseded or failed build must not leave a half-built document behind, so the pages,
+ * sections, and variables it added are removed again. Guarded by graph identity because node
+ * and page IDs are only unique within one graph.
+ */
+function rollbackBuild(store: EditorStore, graph: SceneGraph, state: DemoBuildState): void {
if (store.graph !== graph) return
+ for (const rootId of state.createdRootIds) {
+ if (graph.getNode(rootId)) graph.deleteNode(rootId)
+ }
+ for (const pageId of state.createdPageIds) {
+ if (graph.getNode(pageId)) store.deletePage(pageId)
+ }
+ for (const collectionId of Array.from(graph.variableCollections.keys())) {
+ if (!state.preexistingCollections.has(collectionId)) graph.removeCollection(collectionId)
+ }
+ if (state.initialPageName !== null) {
+ graph.updateNode(state.initialPageId, { name: state.initialPageName })
+ }
store.clearSelection()
- store.zoomToFit()
- store.requestRender()
+}
+
+function reportDemoFailure(preparation: DemoPreparation, error: unknown): void {
+ if (preparation.signal.aborted) return
+ preparation.fail({
+ code: 'layout-failed',
+ message: error instanceof Error ? error.message : String(error),
+ retryable: true
+ })
+ console.warn('[Demo] Failed to prepare the demo document:', error)
+}
+
+/**
+ * Builds the demo document while reporting the same preparation phases as a document open, so
+ * the canvas overlay and tab indicator cover generation instead of an empty canvas.
+ */
+function createDemoBuild(store: EditorStore, preparation: DemoPreparation): DemoBuild {
+ const graph = store.graph
+ const state: DemoBuildState = {
+ initialPageId: store.state.currentPageId,
+ initialPageName: graph.getNode(store.state.currentPageId)?.name ?? null,
+ preexistingCollections: new Set(graph.variableCollections.keys()),
+ createdRootIds: [],
+ createdPageIds: []
+ }
+ const abandoned = () => store.graph !== graph || preparation.signal.aborted
+ const step = (completed: number) =>
+ preparation.update({ phase: 'materializing', completed, total: 4, unit: 'pages' })
+
+ async function run(): Promise<boolean> {
+ await store.canvasReady
+ // A file opened while the canvas was loading must not receive demo content.
+ if (
+ abandoned() ||
+ store.state.currentPageId !== state.initialPageId ||
+ graph.getPages().length !== 1 ||
+ graph.getChildren(state.initialPageId).length > 0
+ )
+ return false
+
+ step(0)
+ await yieldToUI()
+ await loadDemoFonts()
+
+ graph.updateNode(state.initialPageId, { name: '01 · Components & variables' })
+ const typography = graph.addPage('02 · Typography')
+ const paint = graph.addPage('03 · Paint & effects')
+ state.createdPageIds.push(typography.id, paint.id)
+
+ // Build page 01 while it is still the current page, so shape creation inside
+ // the section helpers lands here rather than on a leftover empty page.
+ const announcement = await createAnnouncementSection(graph, state.initialPageId)
+ state.createdRootIds.push(announcement.rootId)
+ graph.updateNode(announcement.rootId, { x: PAGE_ORIGIN, y: PAGE_ORIGIN })
+ step(1)
+ if (abandoned()) return false
+
+ computeAllLayouts(graph, state.initialPageId)
+ const components = await createComponentsSection(graph, state.initialPageId, {
+ x: PAGE_ORIGIN,
+ y: PAGE_ORIGIN + (graph.getNode(announcement.rootId)?.height ?? 0) + PAGE_GAP
+ })
+ state.createdRootIds.push(components.rootId)
+ createDemoVariables(store)
+ step(2)
+ if (abandoned()) return false
+
+ await createTypographySection(graph, typography.id)
+ step(3)
+ if (abandoned()) return false
+
+ await createPaintSection(graph, paint.id)
+ step(4)
+ if (abandoned()) return false
+
+ const pages = graph.getPages()
+ preparation.update({
+ phase: 'resolving-fonts',
+ completed: 0,
+ total: pages.length,
+ unit: 'pages'
+ })
+ for (const [index, page] of pages.entries()) {
+ await store.loadFontsForNodes(page.childIds)
+ if (abandoned()) return false
+ preparation.update({
+ phase: 'resolving-fonts',
+ completed: index + 1,
+ total: pages.length,
+ unit: 'pages'
+ })
+ }
+
+ preparation.update({ phase: 'layout' })
+ await yieldToUI()
+ for (const page of pages) computeAllLayouts(graph, page.id)
+ if (abandoned()) return false
+
+ store.undo.clear()
+ fitDemoPagesOnFirstVisit(
+ store,
+ graph.getPages().map((page) => page.id)
+ )
+ await store.switchPage(state.initialPageId, { preparation })
+ if (abandoned()) return false
+
+ store.clearSelection()
+ store.zoomToFit()
+ preparation.update({ phase: 'preparing-render' })
+ store.requestRender()
+ await store.preparationController.waitForPresentation(preparation.id, store.state.sceneVersion)
+ return true
+ }
+
+ return { graph, state, run }
+}
+
+export async function createDemoShapes(store: EditorStore) {
+ const preparation = store.preparationController.begin({
+ kind: 'demo-load',
+ phase: 'materializing'
+ })
+ const build = createDemoBuild(store, preparation)
+ try {
+ if (await build.run()) {
+ preparation.complete()
+ return
+ }
+ } catch (error) {
+ reportDemoFailure(preparation, error)
+ }
+ rollbackBuild(store, build.graph, build.state)
+ // A failed or superseded handle has already cleared itself, so this is a no-op then.
+ preparation.cancel('superseded')
}
diff --git a/src/app/demo/paint/section.ts b/src/app/demo/paint/section.ts
index 9efbb27f3..3ae6c75ff 100644
--- a/src/app/demo/paint/section.ts
+++ b/src/app/demo/paint/section.ts
@@ -1,6 +1,7 @@
import { Frame, Text, renderTree } from '@open-pencil/core/design-jsx'
import type { SceneGraph } from '@open-pencil/scene-graph'
+import { createArtworkTile, createExampleColumn } from '../sections/example'
import { createPaintGroups } from './samples'
export function createPaintSection(graph: SceneGraph, parentId: string) {
@@ -34,27 +35,12 @@ export function createPaintSection(graph: SceneGraph, parentId: string) {
h: 'hug',
gap: 24,
children: group.examples.map((example) =>
- Frame({
- name: example.title,
- flex: 'col',
- w: 'fill',
- h: 'hug',
- gap: 8,
- children: [
- Frame({
- name: `${example.title} / artwork`,
- flex: 'row',
- w: 'fill',
- h: 'hug',
- p: 16,
- justify: 'center',
- rounded: 12,
- bg: '#EEF2FF',
- children: example.artwork
- }),
- Text({ ...text, size: 14, weight: 600, children: example.title }),
- Text({ ...label, w: 'fill', lineHeight: 18, children: example.caption })
- ]
+ createExampleColumn({
+ title: example.title,
+ caption: example.caption,
+ artwork: createArtworkTile(`${example.title} / artwork`, {
+ children: [example.artwork]
+ })
})
)
})
diff --git a/src/app/demo/reference.ts b/src/app/demo/reference.ts
deleted file mode 100644
index ca49fdd8c..000000000
--- a/src/app/demo/reference.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { computeAllLayouts } from '@open-pencil/core/layout'
-
-import { createAppPreviewSection } from '@/app/demo/sections/app-preview'
-import { createComponentsSection } from '@/app/demo/sections/components'
-import { createEffectsSection } from '@/app/demo/sections/effects'
-import { createStandaloneShapes } from '@/app/demo/sections/standalone'
-import { createDemoVariables } from '@/app/demo/sections/variables'
-import type { EditorStore } from '@/app/editor/session'
-
-export async function createReferenceExamples(store: EditorStore) {
- const { graph } = store
-
- const { btnCompId, badgeCompId } = createComponentsSection(store)
- computeAllLayouts(store.graph)
- const { sidebarId, headerId, frameId, headerTitle, chartTitle } = createAppPreviewSection(
- store,
- btnCompId,
- badgeCompId
- )
-
- createStandaloneShapes(store)
- createDemoVariables(store)
- createEffectsSection(store)
-
- graph.bindVariable(sidebarId, 'fills/0/color', 'var-bg')
- graph.bindVariable(headerId, 'fills/0/color', 'var-bg')
- graph.bindVariable(frameId, 'fills/0/color', 'var-bg-secondary')
- graph.bindVariable(headerTitle, 'fills/0/color', 'var-text-primary')
- graph.bindVariable(chartTitle, 'fills/0/color', 'var-text-primary')
-
- computeAllLayouts(store.graph)
- store.clearSelection()
- await store.loadFontsForNodes(graph.getPages().flatMap((page) => page.childIds))
-}
diff --git a/src/app/demo/sections/app-preview.ts b/src/app/demo/sections/app-preview.ts
deleted file mode 100644
index 1d0e561b2..000000000
--- a/src/app/demo/sections/app-preview.ts
+++ /dev/null
@@ -1,191 +0,0 @@
-import { DEMO_COLORS, gradient, solid, thinStroke } from '@/app/demo/colors'
-import type { EditorStore } from '@/app/editor/session'
-
-export function createAppPreviewSection(
- store: EditorStore,
- btnCompId: string,
- badgeCompId: string
-) {
- const { graph } = store
-
- const appSectionId = store.createShape('SECTION', 1040, 60, 560, 540)
- graph.updateNode(appSectionId, { name: 'App Preview' })
-
- const frameId = store.createShape('FRAME', 20, 48, 520, 460, appSectionId)
- graph.updateNode(frameId, {
- name: 'Dashboard',
- fills: [solid(DEMO_COLORS.gray50)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- clipsContent: true
- })
-
- const sidebarId = store.createShape('RECTANGLE', 0, 0, 56, 460, frameId)
- graph.updateNode(sidebarId, {
- name: 'Sidebar',
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200)
- })
-
- for (let i = 0; i < 5; i++) {
- const dotId = store.createShape('ELLIPSE', 18, 20 + i * 40, 20, 20, frameId)
- graph.updateNode(dotId, {
- name: `Nav ${i + 1}`,
- fills: [solid(i === 0 ? DEMO_COLORS.blue : DEMO_COLORS.gray200)]
- })
- }
-
- const headerId = store.createShape('FRAME', 56, 0, 464, 52, frameId)
- graph.updateNode(headerId, {
- name: 'Header',
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'FIXED',
- counterAxisAlign: 'CENTER',
- primaryAxisAlign: 'SPACE_BETWEEN',
- paddingLeft: 20,
- paddingRight: 20,
- itemSpacing: 8
- })
- const headerTitle = store.createShape('TEXT', 0, 0, 120, 20, headerId)
- graph.updateNode(headerTitle, {
- name: 'Page Title',
- text: 'Dashboard',
- fontSize: 16,
- fontWeight: 600,
- textAutoResize: 'WIDTH_AND_HEIGHT' as const,
- fills: [solid(DEMO_COLORS.black)]
- })
-
- const badgeInstance = graph.createInstance(badgeCompId, headerId)
- if (badgeInstance) graph.updateNode(badgeInstance.id, { x: 264, y: 15 })
- const buttonInstance = graph.createInstance(btnCompId, headerId)
- if (buttonInstance) graph.updateNode(buttonInstance.id, { x: 324, y: 6 })
-
- const stats = [
- { title: 'Revenue', value: '$12,480', badge: '+14%', color: DEMO_COLORS.green },
- { title: 'Users', value: '3,842', badge: '+8%', color: DEMO_COLORS.blue },
- { title: 'Orders', value: '1,249', badge: '-3%', color: DEMO_COLORS.red }
- ]
-
- for (let i = 0; i < stats.length; i++) {
- const s = stats[i]
- const cx = 76 + i * 152
- const cId = store.createShape('FRAME', cx, 72, 140, 88, frameId)
- graph.updateNode(cId, {
- name: s.title,
- cornerRadius: 10,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'VERTICAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'FIXED',
- itemSpacing: 4,
- paddingTop: 14,
- paddingBottom: 14,
- paddingLeft: 16,
- paddingRight: 16
- })
- const labelId = store.createShape('TEXT', 0, 0, 108, 14, cId)
- graph.updateNode(labelId, {
- name: 'Label',
- text: s.title,
- fontSize: 11,
- fontWeight: 500,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.gray500)]
- })
- const valId = store.createShape('TEXT', 0, 0, 108, 24, cId)
- graph.updateNode(valId, {
- name: 'Value',
- text: s.value,
- fontSize: 22,
- fontWeight: 700,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.black)]
- })
- const bId = store.createShape('TEXT', 0, 0, 108, 14, cId)
- graph.updateNode(bId, {
- name: 'Badge',
- text: s.badge,
- fontSize: 11,
- fontWeight: 600,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(s.color)]
- })
- }
-
- const chartBg = store.createShape('FRAME', 76, 180, 424, 200, frameId)
- graph.updateNode(chartBg, {
- name: 'Chart',
- cornerRadius: 10,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200)
- })
- const chartTitle = store.createShape('TEXT', 16, 16, 120, 18, chartBg)
- graph.updateNode(chartTitle, {
- name: 'Chart Title',
- text: 'Revenue over time',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.black)]
- })
-
- const barHeights = [60, 90, 72, 110, 95, 130, 100, 80, 120, 140, 115, 88]
- const barW = 24
- const barGap = 10
- const barStartX = 16
- const barBaseY = 180
-
- for (let i = 0; i < barHeights.length; i++) {
- const h = barHeights[i]
- const bx = barStartX + i * (barW + barGap)
- const by = barBaseY - h
- const barId = store.createShape('RECTANGLE', bx, by, barW, h, chartBg)
- graph.updateNode(barId, {
- name: `Bar ${i + 1}`,
- cornerRadius: 4,
- fills: [
- gradient([
- { color: DEMO_COLORS.blue, position: 0 },
- { color: DEMO_COLORS.indigo, position: 1 }
- ])
- ]
- })
- }
-
- const tableId = store.createShape('FRAME', 76, 400, 424, 40, frameId)
- graph.updateNode(tableId, {
- name: 'Table Header',
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'SPACE_BETWEEN',
- counterAxisAlign: 'CENTER',
- paddingTop: 10,
- paddingBottom: 10,
- paddingLeft: 16,
- paddingRight: 16,
- itemSpacing: 16
- })
- const cols = ['Name', 'Status', 'Amount', 'Date']
- for (const col of cols) {
- const colId = store.createShape('TEXT', 0, 0, 80, 16, tableId)
- graph.updateNode(colId, {
- name: col,
- text: col,
- fontSize: 12,
- fontWeight: 600,
- textAutoResize: 'WIDTH_AND_HEIGHT',
- fills: [solid(DEMO_COLORS.gray500)]
- })
- }
-
- return { sidebarId, headerId, frameId, headerTitle, chartTitle }
-}
diff --git a/src/app/demo/sections/components.ts b/src/app/demo/sections/components.ts
index 0d57eba4e..a426230de 100644
--- a/src/app/demo/sections/components.ts
+++ b/src/app/demo/sections/components.ts
@@ -1,253 +1,452 @@
-import { DEMO_COLORS, gradient, solid, thinStroke } from '@/app/demo/colors'
-import { makeComponent } from '@/app/demo/helpers'
-import type { EditorStore } from '@/app/editor/session'
-
-export function createComponentsSection(store: EditorStore) {
- const { graph } = store
-
- const compSectionId = store.createShape('SECTION', 60, 60, 920, 540)
- graph.updateNode(compSectionId, { name: 'Components' })
-
- const btnId = store.createShape('FRAME', 32, 76, 120, 40, compSectionId)
- graph.updateNode(btnId, {
- name: 'Button/Primary',
- fills: [],
- strokes: [],
- clipsContent: false
- })
- const btnSurfaceId = store.createShape('FRAME', 0, 0, 120, 40, btnId)
- graph.updateNode(btnSurfaceId, {
- name: 'Surface',
- cornerRadius: 8,
- fills: [solid(DEMO_COLORS.blue)],
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'HUG',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'CENTER',
- counterAxisAlign: 'CENTER',
- paddingTop: 10,
- paddingBottom: 10,
- paddingLeft: 20,
- paddingRight: 20
- })
- const btnTextId = store.createShape('TEXT', 0, 0, 80, 20, btnSurfaceId)
- graph.updateNode(btnTextId, {
- name: 'Label',
- text: 'Get Started',
- fontSize: 14,
- fontWeight: 600,
- textAutoResize: 'WIDTH_AND_HEIGHT',
- fills: [solid(DEMO_COLORS.white)]
- })
- const btnCompId = makeComponent(store, [btnId])
-
- const btn2Id = store.createShape('FRAME', 216, 76, 100, 40, compSectionId)
- graph.updateNode(btn2Id, {
- name: 'Button/Secondary',
- fills: [],
- strokes: [],
- clipsContent: false
- })
- const btn2SurfaceId = store.createShape('FRAME', 0, 0, 100, 40, btn2Id)
- graph.updateNode(btn2SurfaceId, {
- name: 'Surface',
- cornerRadius: 8,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'HUG',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'CENTER',
- counterAxisAlign: 'CENTER',
- paddingTop: 10,
- paddingBottom: 10,
- paddingLeft: 20,
- paddingRight: 20
- })
- const btn2TextId = store.createShape('TEXT', 0, 0, 60, 20, btn2SurfaceId)
- graph.updateNode(btn2TextId, {
- name: 'Label',
- text: 'Cancel',
- fontSize: 14,
- fontWeight: 500,
- textAutoResize: 'WIDTH_AND_HEIGHT',
- fills: [solid(DEMO_COLORS.black)]
- })
- const btn2CompId = makeComponent(store, [btn2Id])
-
- store.select([btnCompId, btn2CompId])
- store.createComponentSetFromComponents()
- const buttonSetId = [...store.state.selectedIds][0]
- graph.updateNode(buttonSetId, { x: 32, y: 44, width: 400, height: 136, fills: [] })
- graph.updateNode(btnCompId, { x: 40, y: 64 })
- graph.updateNode(btn2CompId, { x: 224, y: 64 })
-
- const chipId = store.createShape('FRAME', 500, 72, 80, 28, compSectionId)
- graph.updateNode(chipId, {
- name: 'Tag',
- cornerRadius: 14,
- fills: [solid({ r: 0.93, g: 0.94, b: 1, a: 1 })],
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'HUG',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'CENTER',
- counterAxisAlign: 'CENTER',
- paddingTop: 4,
- paddingBottom: 4,
- paddingLeft: 12,
- paddingRight: 12
- })
- const chipTextId = store.createShape('TEXT', 0, 0, 56, 16, chipId)
- graph.updateNode(chipTextId, {
+import {
+ Component,
+ ComponentSet,
+ Ellipse,
+ Frame,
+ Instance,
+ Rectangle,
+ Text,
+ linearGradient,
+ renderTree
+} from '@open-pencil/core/design-jsx'
+import type { TreeNode } from '@open-pencil/core/design-jsx'
+import type { ComponentPropertyDefinition, SceneGraph, Vector } from '@open-pencil/scene-graph'
+
+import { createArtworkTile, createExampleColumn } from './example'
+
+const INK = '#172554'
+const MUTED = '#536487'
+const ACCENT = '#4F46E5'
+const TILE = '#EEF2FF'
+const SURFACE = '#FFFFFF'
+const BORDER = '#DCE3F5'
+
+const text = { font: 'Inter', color: INK }
+const label = { ...text, size: 12, color: MUTED }
+const caption = { ...label, size: 10 }
+
+export const COMPONENT_PROPERTIES = {
+ buttonLabel: {
+ id: 'demo-button-label',
name: 'Label',
- text: 'Design',
- fontSize: 12,
- fontWeight: 500,
- textAutoResize: 'WIDTH_AND_HEIGHT',
- fills: [solid(DEMO_COLORS.indigo)]
- })
- makeComponent(store, [chipId])
-
- const avatarId = store.createShape('ELLIPSE', 640, 68, 40, 40, compSectionId)
- graph.updateNode(avatarId, {
- name: 'Avatar',
- fills: [
- gradient([
- { color: DEMO_COLORS.purple, position: 0 },
- { color: DEMO_COLORS.blue, position: 1 }
- ])
- ]
- })
- const avatarCompId = makeComponent(store, [avatarId])
- graph.updateNode(avatarCompId, { name: 'Avatar' })
-
- const cardId = store.createShape('FRAME', 32, 216, 280, 160, compSectionId)
- graph.updateNode(cardId, {
- name: 'Card',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'VERTICAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'FIXED',
- itemSpacing: 8,
- paddingTop: 20,
- paddingBottom: 20,
- paddingLeft: 20,
- paddingRight: 20
- })
- const cardTitleId = store.createShape('TEXT', 0, 0, 240, 22, cardId)
- graph.updateNode(cardTitleId, {
+ type: 'TEXT',
+ defaultValue: 'Get started'
+ },
+ cardTitle: {
+ id: 'demo-card-title',
name: 'Title',
- text: 'Analytics Overview',
- fontSize: 16,
- fontWeight: 600,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.black)]
- })
- const cardDescId = store.createShape('TEXT', 0, 0, 240, 36, cardId)
- graph.updateNode(cardDescId, {
+ type: 'TEXT',
+ defaultValue: 'Analytics overview'
+ },
+ cardDescription: {
+ id: 'demo-card-description',
name: 'Description',
- text: 'Track your key metrics and performance indicators in real time.',
- fontSize: 13,
- fontWeight: 400,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.gray500)]
- })
- const cardBarBg = store.createShape('RECTANGLE', 0, 0, 240, 8, cardId)
- graph.updateNode(cardBarBg, {
- name: 'Progress BG',
- cornerRadius: 4,
- fills: [solid(DEMO_COLORS.gray100)]
- })
- const cardBar = store.createShape('RECTANGLE', 0, 0, 168, 8, cardId)
- graph.updateNode(cardBar, {
- name: 'Progress',
- cornerRadius: 4,
- fills: [
- gradient([
- { color: DEMO_COLORS.blue, position: 0 },
- { color: DEMO_COLORS.teal, position: 1 }
- ])
- ]
- })
- makeComponent(store, [cardId])
-
- const inputId = store.createShape('FRAME', 344, 216, 240, 40, compSectionId)
- graph.updateNode(inputId, {
- name: 'Input',
- cornerRadius: 8,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'MIN',
- counterAxisAlign: 'CENTER',
- paddingTop: 10,
- paddingBottom: 10,
- paddingLeft: 12,
- paddingRight: 12
- })
- const inputPlaceholder = store.createShape('TEXT', 0, 0, 200, 18, inputId)
- graph.updateNode(inputPlaceholder, {
- name: 'Placeholder',
- text: 'Search...',
- fontSize: 14,
- fontWeight: 400,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.gray500)]
- })
- makeComponent(store, [inputId])
-
- const badgeId = store.createShape('FRAME', 344, 284, 48, 24, compSectionId)
- graph.updateNode(badgeId, {
- name: 'Badge',
- cornerRadius: 12,
- fills: [solid({ r: 0.93, g: 1, b: 0.95, a: 1 })],
- layoutMode: 'HORIZONTAL',
- primaryAxisSizing: 'HUG',
- counterAxisSizing: 'HUG',
- primaryAxisAlign: 'CENTER',
- counterAxisAlign: 'CENTER',
- itemSpacing: 4,
- paddingTop: 4,
- paddingBottom: 4,
- paddingLeft: 8,
- paddingRight: 8
- })
- const badgeDot = store.createShape('ELLIPSE', 0, 0, 6, 6, badgeId)
- graph.updateNode(badgeDot, {
- name: 'Dot',
- fills: [solid(DEMO_COLORS.green)]
- })
- const badgeText = store.createShape('TEXT', 0, 0, 28, 14, badgeId)
- graph.updateNode(badgeText, {
+ type: 'TEXT',
+ defaultValue: 'Track your key metrics and performance indicators in real time.'
+ },
+ badgeLabel: {
+ id: 'demo-badge-label',
name: 'Label',
- text: 'Live',
- fontSize: 11,
- fontWeight: 600,
- textAutoResize: 'WIDTH_AND_HEIGHT',
- fills: [solid(DEMO_COLORS.green)]
- })
- const badgeCompId = makeComponent(store, [badgeId])
-
- const swatches = [
- { name: 'Blue', color: DEMO_COLORS.blue, x: 32 },
- { name: 'Indigo', color: DEMO_COLORS.indigo, x: 88 },
- { name: 'Purple', color: DEMO_COLORS.purple, x: 144 },
- { name: 'Green', color: DEMO_COLORS.green, x: 200 },
- { name: 'Teal', color: DEMO_COLORS.teal, x: 256 },
- { name: 'Orange', color: DEMO_COLORS.orange, x: 312 },
- { name: 'Red', color: DEMO_COLORS.red, x: 368 }
- ]
- for (const swatch of swatches) {
- const id = store.createShape('ELLIPSE', swatch.x, 460, 44, 44, compSectionId)
- graph.updateNode(id, { name: swatch.name, fills: [solid(swatch.color)] })
+ type: 'TEXT',
+ defaultValue: 'Live'
+ },
+ badgeDot: {
+ id: 'demo-badge-dot',
+ name: 'Show dot',
+ type: 'BOOLEAN',
+ defaultValue: 'true'
}
+} satisfies Record<string, ComponentPropertyDefinition>
+
+interface ComponentExample {
+ title: string
+ caption: string
+}
+
+const EXAMPLE_GROUPS: readonly { title: string; examples: readonly ComponentExample[] }[] = [
+ {
+ title: '01 / ACTIONS · ONE BUTTON, TWO VARIANTS',
+ examples: [
+ { title: 'Primary', caption: 'Filled with the accent variable.' },
+ { title: 'Secondary', caption: 'Outline treatment for lower emphasis.' }
+ ]
+ },
+ {
+ title: '02 / IDENTITY · AVATAR, BADGE, TAG',
+ examples: [
+ { title: 'Avatar', caption: 'Gradient identity mark.' },
+ { title: 'Badge', caption: 'Status label with a live dot.' },
+ { title: 'Tag', caption: 'Quiet category chip.' }
+ ]
+ },
+ {
+ title: '03 / SURFACES · CARD AND INPUT',
+ examples: [
+ { title: 'Card', caption: 'Titled surface with a progress bar.' },
+ { title: 'Input', caption: 'Search field with a placeholder.' }
+ ]
+ }
+]
+
+export async function createComponentsSection(
+ graph: SceneGraph,
+ parentId: string,
+ options: Partial<Vector> = {}
+) {
+ const root = await renderTree(
+ graph,
+ Frame({
+ name: 'Components',
+ flex: 'col',
+ w: 1056,
+ h: 'hug',
+ p: 32,
+ gap: 32,
+ bg: SURFACE,
+ children: [
+ Text({
+ ...text,
+ size: 20,
+ weight: 600,
+ children: 'One library. Every screen stays in sync.'
+ })
+ ]
+ }),
+ { parentId, ...options }
+ )
+
+ // Instance slots come first so the sources below can fill them afterwards.
+ const slots: Record<string, string> = {}
+ for (const group of EXAMPLE_GROUPS) {
+ const groupFrame = await renderTree(
+ graph,
+ Frame({
+ name: group.title,
+ flex: 'col',
+ w: 'fill',
+ h: 'hug',
+ gap: 16,
+ children: [Text({ ...label, children: group.title })]
+ }),
+ { parentId: root.id }
+ )
+ const row = await renderTree(
+ graph,
+ Frame({ name: 'Linked instances', flex: 'row', w: 'fill', h: 'hug', gap: 24 }),
+ { parentId: groupFrame.id }
+ )
+ for (const example of group.examples) {
+ const column = await renderTree(
+ graph,
+ createExampleColumn({
+ title: example.title,
+ caption: example.caption,
+ artwork: createArtworkTile(`${example.title} / artwork`, { padding: 24, center: true })
+ }),
+ { parentId: row.id }
+ )
+ const artworkId = graph.getNode(column.id)?.childIds[0]
+ if (!artworkId) throw new Error(`Missing component example artwork for ${example.title}`)
+ slots[example.title] = artworkId
+ }
+ }
+
+ const sources = await renderTree(
+ graph,
+ Frame({
+ name: '04 / SOURCES · EDIT THESE TO UPDATE EVERY EXAMPLE',
+ flex: 'col',
+ w: 'fill',
+ h: 'hug',
+ gap: 16,
+ children: [Text({ ...label, children: '04 / SOURCES · EDIT THESE TO UPDATE EVERY EXAMPLE' })]
+ }),
+ { parentId: root.id }
+ )
+ const sourceRow = async (name: string) => {
+ const row = await renderTree(
+ graph,
+ Frame({ name, flex: 'row', w: 'fill', h: 'hug', gap: 24, items: 'start' }),
+ { parentId: sources.id }
+ )
+ return row.id
+ }
+ const controlsRow = await sourceRow('Component sources / controls')
+ const surfacesRow = await sourceRow('Component sources / identity and surfaces')
+ const sourceTile = async (name: string, hint: string, rowId: string) => {
+ const tile = await renderTree(
+ graph,
+ Frame({
+ name,
+ flex: 'col',
+ w: 'fill',
+ h: 'hug',
+ p: 20,
+ gap: 12,
+ items: 'center',
+ rounded: 12,
+ bg: TILE,
+ children: [
+ Frame({
+ name: `${name} / source`,
+ flex: 'row',
+ w: 'fill',
+ h: 'hug',
+ p: 16,
+ justify: 'center',
+ items: 'center'
+ }),
+ Text({ ...caption, children: hint })
+ ]
+ }),
+ { parentId: rowId }
+ )
+ const artworkId = graph.getNode(tile.id)?.childIds[0]
+ if (!artworkId) throw new Error(`Missing source artwork for ${name}`)
+ return artworkId
+ }
+
+ const buttonVariant = (variant: string, fill: string, color: string, outline: boolean) =>
+ Component({
+ name: `Variant=${variant}`,
+ properties: [COMPONENT_PROPERTIES.buttonLabel],
+ flex: 'row',
+ px: 20,
+ py: 10,
+ rounded: 8,
+ justify: 'center',
+ items: 'center',
+ bg: fill,
+ stroke: outline ? BORDER : undefined,
+ strokeWidth: outline ? 1 : undefined,
+ children: [
+ Text({
+ ...text,
+ name: 'Label',
+ size: 14,
+ weight: 600,
+ color,
+ children: COMPONENT_PROPERTIES.buttonLabel.defaultValue,
+ propertyRefs: [{ propertyId: COMPONENT_PROPERTIES.buttonLabel.id, field: 'TEXT' }]
+ })
+ ]
+ })
+ const buttonSet = await renderTree(
+ graph,
+ ComponentSet({
+ name: 'Button',
+ flex: 'row',
+ w: 'hug',
+ h: 'hug',
+ gap: 16,
+ children: [
+ buttonVariant('Primary', ACCENT, SURFACE, false),
+ buttonVariant('Secondary', SURFACE, INK, true)
+ ]
+ }),
+ { parentId: await sourceTile('Button variants', 'Two variants of one set.', controlsRow) }
+ )
+ const variantIds = graph.getNode(buttonSet.id)?.childIds ?? []
+
+ const avatar = await renderTree(
+ graph,
+ Component({
+ name: 'Avatar',
+ flex: 'row',
+ w: 48,
+ h: 48,
+ justify: 'center',
+ items: 'center',
+ rounded: 24,
+ fills: [
+ linearGradient([
+ ['#7C3AED', 0],
+ ['#3B82F6', 1]
+ ])
+ ]
+ }),
+ { parentId: await sourceTile('Avatar', 'Gradient identity mark.', controlsRow) }
+ )
+
+ const badge = await renderTree(
+ graph,
+ Component({
+ name: 'Badge',
+ properties: [COMPONENT_PROPERTIES.badgeDot, COMPONENT_PROPERTIES.badgeLabel],
+ flex: 'row',
+ gap: 4,
+ px: 8,
+ py: 4,
+ rounded: 12,
+ justify: 'center',
+ items: 'center',
+ bg: '#ECFDF5',
+ children: [
+ Ellipse({
+ name: 'Dot',
+ w: 6,
+ h: 6,
+ bg: '#22C55E',
+ propertyRefs: [{ propertyId: COMPONENT_PROPERTIES.badgeDot.id, field: 'VISIBLE' }]
+ }),
+ Text({
+ ...text,
+ name: 'Label',
+ size: 11,
+ weight: 600,
+ color: '#16A34A',
+ children: COMPONENT_PROPERTIES.badgeLabel.defaultValue,
+ propertyRefs: [{ propertyId: COMPONENT_PROPERTIES.badgeLabel.id, field: 'TEXT' }]
+ })
+ ]
+ }),
+ { parentId: await sourceTile('Badge', 'Label plus a toggleable dot.', controlsRow) }
+ )
+
+ const tag = await renderTree(
+ graph,
+ Component({
+ name: 'Tag',
+ flex: 'row',
+ px: 12,
+ py: 4,
+ rounded: 14,
+ justify: 'center',
+ items: 'center',
+ bg: TILE,
+ children: [Text({ ...text, size: 12, weight: 500, color: ACCENT, children: 'Design' })]
+ }),
+ { parentId: await sourceTile('Tag', 'Quiet category chip.', surfacesRow) }
+ )
+
+ const card = await renderTree(
+ graph,
+ Component({
+ name: 'Card',
+ properties: [COMPONENT_PROPERTIES.cardTitle, COMPONENT_PROPERTIES.cardDescription],
+ flex: 'col',
+ w: 280,
+ h: 'hug',
+ p: 20,
+ gap: 8,
+ rounded: 12,
+ bg: SURFACE,
+ stroke: BORDER,
+ strokeWidth: 1,
+ children: [
+ Text({
+ ...text,
+ name: 'Title',
+ w: 'fill',
+ size: 16,
+ weight: 600,
+ children: COMPONENT_PROPERTIES.cardTitle.defaultValue,
+ propertyRefs: [{ propertyId: COMPONENT_PROPERTIES.cardTitle.id, field: 'TEXT' }]
+ }),
+ Text({
+ ...text,
+ name: 'Description',
+ w: 'fill',
+ size: 13,
+ lineHeight: 18,
+ color: MUTED,
+ children: COMPONENT_PROPERTIES.cardDescription.defaultValue,
+ propertyRefs: [{ propertyId: COMPONENT_PROPERTIES.cardDescription.id, field: 'TEXT' }]
+ }),
+ Rectangle({ name: 'Progress track', w: 'fill', h: 8, rounded: 4, bg: '#EEF0F6' }),
+ Rectangle({
+ name: 'Progress',
+ w: 168,
+ h: 8,
+ rounded: 4,
+ fills: [
+ linearGradient([
+ ['#3B82F6', 0],
+ ['#14B8A6', 1]
+ ])
+ ]
+ })
+ ]
+ }),
+ { parentId: await sourceTile('Card', 'Titled surface with progress.', surfacesRow) }
+ )
+
+ const input = await renderTree(
+ graph,
+ Component({
+ name: 'Input',
+ flex: 'row',
+ w: 240,
+ px: 12,
+ py: 10,
+ rounded: 8,
+ items: 'center',
+ bg: SURFACE,
+ stroke: BORDER,
+ strokeWidth: 1,
+ children: [
+ Text({
+ ...text,
+ name: 'Placeholder',
+ w: 'fill',
+ size: 14,
+ color: MUTED,
+ children: 'Search…'
+ })
+ ]
+ }),
+ { parentId: await sourceTile('Input', 'Search field with placeholder.', surfacesRow) }
+ )
+
+ const place = async (name: string, node: TreeNode) => {
+ const artworkId = slots[name]
+ if (!artworkId) throw new Error(`Missing component example slot for ${name}`)
+ return renderTree(graph, node, { parentId: artworkId })
+ }
+
+ const primaryId = variantIds[0]
+ const secondaryId = variantIds[1]
+ if (!primaryId || !secondaryId) throw new Error('Button variants were not created')
+ await place('Primary', Instance({ of: primaryId }))
+ await place(
+ 'Secondary',
+ Instance({
+ of: secondaryId,
+ properties: { [COMPONENT_PROPERTIES.buttonLabel.id]: 'Cancel' }
+ })
+ )
+ await place('Avatar', Instance({ of: avatar.id }))
+ await place(
+ 'Badge',
+ Instance({
+ of: badge.id,
+ properties: { [COMPONENT_PROPERTIES.badgeLabel.id]: 'Live' }
+ })
+ )
+ await place('Tag', Instance({ of: tag.id }))
+ await place(
+ 'Card',
+ Instance({
+ of: card.id,
+ properties: {
+ [COMPONENT_PROPERTIES.cardTitle.id]: 'Analytics overview',
+ [COMPONENT_PROPERTIES.cardDescription.id]: 'Every value here is a component property.'
+ }
+ })
+ )
+ await place('Input', Instance({ of: input.id }))
+
+ await renderTree(
+ graph,
+ Text({
+ ...label,
+ w: 'fill',
+ lineHeight: 18,
+ children:
+ 'Edit any source below and every linked instance above updates. Text and visibility stay editable per instance.'
+ }),
+ { parentId: root.id }
+ )
- return { btnCompId, badgeCompId }
+ return { rootId: root.id }
}
diff --git a/src/app/demo/sections/effects.ts b/src/app/demo/sections/effects.ts
deleted file mode 100644
index 4de4e820c..000000000
--- a/src/app/demo/sections/effects.ts
+++ /dev/null
@@ -1,429 +0,0 @@
-import { DEMO_COLORS, gradient, solid, thinStroke } from '@/app/demo/colors'
-import { blurEffect, dropShadow, innerShadow } from '@/app/demo/effects'
-import type { EditorStore } from '@/app/editor/session'
-
-export function createEffectsSection(store: EditorStore) {
- const { graph } = store
-
- const effectsSectionId = store.createShape('SECTION', 60, 840, 920, 780)
- graph.updateNode(effectsSectionId, {
- name: 'Effects',
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const shadowLabel = store.createShape('TEXT', 32, 48, 200, 20, effectsSectionId)
- graph.updateNode(shadowLabel, {
- name: 'Label',
- text: 'Drop Shadow',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const shadowCard1 = store.createShape('FRAME', 32, 76, 160, 100, effectsSectionId)
- graph.updateNode(shadowCard1, {
- name: 'Subtle Shadow',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- effects: [dropShadow(0, 2, 8, 0, { r: 0, g: 0, b: 0, a: 0.08 })]
- })
- const s1Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard1)
- graph.updateNode(s1Text, {
- name: 'Label',
- text: 'Subtle',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const shadowCard2 = store.createShape('FRAME', 220, 76, 160, 100, effectsSectionId)
- graph.updateNode(shadowCard2, {
- name: 'Medium Shadow',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- effects: [dropShadow(0, 4, 16, 0, { r: 0, g: 0, b: 0, a: 0.15 })]
- })
- const s2Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard2)
- graph.updateNode(s2Text, {
- name: 'Label',
- text: 'Medium',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const shadowCard3 = store.createShape('FRAME', 408, 76, 160, 100, effectsSectionId)
- graph.updateNode(shadowCard3, {
- name: 'Heavy Shadow',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- effects: [dropShadow(0, 8, 24, 0, { r: 0, g: 0, b: 0, a: 0.2 })]
- })
- const s3Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard3)
- graph.updateNode(s3Text, {
- name: 'Label',
- text: 'Heavy',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const shadowCard4 = store.createShape('FRAME', 596, 76, 160, 100, effectsSectionId)
- graph.updateNode(shadowCard4, {
- name: 'Spread Shadow',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- effects: [dropShadow(0, 4, 12, 8, { r: 0.23, g: 0.51, b: 0.96, a: 0.3 })]
- })
- const s4Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard4)
- graph.updateNode(s4Text, {
- name: 'Label',
- text: 'With Spread',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.blue)]
- })
-
- const innerLabel = store.createShape('TEXT', 32, 208, 200, 20, effectsSectionId)
- graph.updateNode(innerLabel, {
- name: 'Label',
- text: 'Inner Shadow',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const innerCard1 = store.createShape('FRAME', 32, 236, 160, 100, effectsSectionId)
- graph.updateNode(innerCard1, {
- name: 'Inset Light',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.gray100)],
- effects: [innerShadow(0, 2, 6, 0, { r: 0, g: 0, b: 0, a: 0.12 })]
- })
- const i1Text = store.createShape('TEXT', 16, 40, 128, 20, innerCard1)
- graph.updateNode(i1Text, {
- name: 'Label',
- text: 'Inset',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const innerCard2 = store.createShape('FRAME', 220, 236, 160, 100, effectsSectionId)
- graph.updateNode(innerCard2, {
- name: 'Inset with Spread',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.gray100)],
- effects: [innerShadow(0, 2, 8, 4, { r: 0, g: 0, b: 0, a: 0.15 })]
- })
- const i2Text = store.createShape('TEXT', 16, 40, 128, 20, innerCard2)
- graph.updateNode(i2Text, {
- name: 'Label',
- text: 'Inset + Spread',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const innerEllipse = store.createShape('ELLIPSE', 408, 236, 100, 100, effectsSectionId)
- graph.updateNode(innerEllipse, {
- name: 'Inset Circle',
- fills: [
- gradient([
- { color: { r: 0.93, g: 0.94, b: 1, a: 1 }, position: 0 },
- { color: { r: 0.85, g: 0.86, b: 0.95, a: 1 }, position: 1 }
- ])
- ],
- effects: [innerShadow(0, 4, 12, 0, { r: 0.38, g: 0.35, b: 0.95, a: 0.3 })]
- })
-
- const comboCard = store.createShape('FRAME', 536, 236, 160, 100, effectsSectionId)
- graph.updateNode(comboCard, {
- name: 'Combined',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- effects: [
- dropShadow(0, 4, 16, 0, { r: 0, g: 0, b: 0, a: 0.12 }),
- innerShadow(0, 1, 2, 0, { r: 0, g: 0, b: 0, a: 0.06 })
- ]
- })
- const comboText = store.createShape('TEXT', 16, 40, 128, 20, comboCard)
- graph.updateNode(comboText, {
- name: 'Label',
- text: 'Drop + Inner',
- fontSize: 13,
- fontWeight: 500,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const textFxLabel = store.createShape('TEXT', 32, 368, 200, 20, effectsSectionId)
- graph.updateNode(textFxLabel, {
- name: 'Label',
- text: 'Text Shadow & Blur',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const textShadow = store.createShape('TEXT', 32, 400, 200, 36, effectsSectionId)
- graph.updateNode(textShadow, {
- name: 'Text Shadow',
- text: 'Glyph Shadow',
- fontSize: 28,
- fontWeight: 700,
- fills: [solid(DEMO_COLORS.black)],
- effects: [dropShadow(2, 2, 4, 0, { r: 0.23, g: 0.51, b: 0.96, a: 0.5 })]
- })
-
- const textInner = store.createShape('TEXT', 260, 400, 200, 36, effectsSectionId)
- graph.updateNode(textInner, {
- name: 'Text Inner',
- text: 'Inner Glow',
- fontSize: 28,
- fontWeight: 700,
- fills: [solid(DEMO_COLORS.indigo)],
- effects: [innerShadow(0, -1, 3, 0, { r: 1, g: 1, b: 1, a: 0.6 })]
- })
-
- const blurRect = store.createShape('RECTANGLE', 500, 392, 120, 50, effectsSectionId)
- graph.updateNode(blurRect, {
- name: 'Layer Blur',
- cornerRadius: 10,
- fills: [
- gradient([
- { color: DEMO_COLORS.purple, position: 0 },
- { color: DEMO_COLORS.blue, position: 1 }
- ])
- ],
- effects: [blurEffect('LAYER_BLUR', 4)]
- })
-
- const glassBg = store.createShape('FRAME', 652, 368, 200, 80, effectsSectionId)
- graph.updateNode(glassBg, {
- name: 'Glass Card',
- cornerRadius: 16,
- fills: [solid({ r: 1, g: 1, b: 1, a: 0.3 })],
- strokes: thinStroke({ r: 1, g: 1, b: 1, a: 0.4 }),
- effects: [blurEffect('BACKGROUND_BLUR', 16)]
- })
- const glassText = store.createShape('TEXT', 20, 30, 160, 20, glassBg)
- graph.updateNode(glassText, {
- name: 'Label',
- text: 'Glassmorphism',
- fontSize: 14,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.black)]
- })
-
- const blendMaskLabel = store.createShape('TEXT', 32, 488, 240, 20, effectsSectionId)
- graph.updateNode(blendMaskLabel, {
- name: 'Label',
- text: 'Blend modes & masks',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const blendCard = store.createShape('FRAME', 32, 520, 256, 92, effectsSectionId)
- graph.updateNode(blendCard, {
- name: 'Blend Mode Stack',
- cornerRadius: 16,
- fills: [solid(DEMO_COLORS.gray50)],
- strokes: thinStroke(DEMO_COLORS.gray200)
- })
- const blendBase = store.createShape('ELLIPSE', 24, 18, 72, 72, blendCard)
- graph.updateNode(blendBase, {
- name: 'Multiply Blue',
- fills: [solid({ r: 0.16, g: 0.46, b: 1, a: 0.8 })],
- blendMode: 'MULTIPLY'
- })
- const blendMiddle = store.createShape('ELLIPSE', 70, 18, 72, 72, blendCard)
- graph.updateNode(blendMiddle, {
- name: 'Multiply Red',
- fills: [solid({ r: 1, g: 0.22, b: 0.34, a: 0.8 })],
- blendMode: 'MULTIPLY'
- })
- const blendTop = store.createShape('ELLIPSE', 116, 18, 72, 72, blendCard)
- graph.updateNode(blendTop, {
- name: 'Screen Gold',
- fills: [solid({ r: 1, g: 0.72, b: 0.16, a: 0.72 })],
- blendMode: 'SCREEN'
- })
- const blendText = store.createShape('TEXT', 168, 32, 72, 32, blendCard)
- graph.updateNode(blendText, {
- name: 'Label',
- text: 'Multiply\n+ Screen',
- fontSize: 12,
- fontWeight: 600,
- lineHeight: 16,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const fillBlendCard = store.createShape('FRAME', 312, 520, 204, 92, effectsSectionId)
- graph.updateNode(fillBlendCard, {
- name: 'Fill Blend Card',
- cornerRadius: 16,
- fills: [
- gradient([
- { color: DEMO_COLORS.purple, position: 0 },
- { color: DEMO_COLORS.blue, position: 1 }
- ]),
- { ...solid(DEMO_COLORS.orange, 0.7), blendMode: 'OVERLAY' }
- ],
- effects: [dropShadow(0, 6, 18, 0, { r: 0.23, g: 0.51, b: 0.96, a: 0.2 })]
- })
- const fillBlendText = store.createShape('TEXT', 20, 32, 164, 24, fillBlendCard)
- graph.updateNode(fillBlendText, {
- name: 'Label',
- text: 'Overlay fill',
- fontSize: 16,
- fontWeight: 700,
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const maskCard = store.createShape('FRAME', 540, 520, 300, 92, effectsSectionId)
- graph.updateNode(maskCard, {
- name: 'Mask Stack Card',
- cornerRadius: 16,
- fills: [solid(DEMO_COLORS.gray50)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- clipsContent: true
- })
- const maskBg = store.createShape('RECTANGLE', 0, 0, 300, 92, maskCard)
- graph.updateNode(maskBg, {
- name: 'Backdrop',
- fills: [solid({ r: 0.08, g: 0.1, b: 0.18, a: 1 })]
- })
- const maskText = store.createShape('TEXT', 104, 26, 172, 36, maskCard)
- graph.updateNode(maskText, {
- name: 'Label',
- text: 'Sibling mask stack\nfrom imported files',
- fontSize: 13,
- fontWeight: 600,
- lineHeight: 17,
- fills: [solid(DEMO_COLORS.white)]
- })
- const maskShape = store.createShape('ELLIPSE', 22, 16, 60, 60, maskCard)
- graph.updateNode(maskShape, {
- name: 'Avatar Mask',
- fills: [solid(DEMO_COLORS.white)],
- isMask: true,
- maskType: 'ALPHA'
- })
- const stripeA = store.createShape('RECTANGLE', 14, 12, 84, 28, maskCard)
- graph.updateNode(stripeA, {
- name: 'Masked Stripe A',
- rotation: -20,
- fills: [solid(DEMO_COLORS.blue)]
- })
- const stripeB = store.createShape('RECTANGLE', 14, 36, 84, 28, maskCard)
- graph.updateNode(stripeB, {
- name: 'Masked Stripe B',
- rotation: -20,
- fills: [solid(DEMO_COLORS.purple)]
- })
- const stripeC = store.createShape('RECTANGLE', 14, 60, 84, 28, maskCard)
- graph.updateNode(stripeC, {
- name: 'Masked Stripe C',
- rotation: -20,
- fills: [solid(DEMO_COLORS.teal)]
- })
-
- const smoothingLabel = store.createShape('TEXT', 32, 644, 280, 20, effectsSectionId)
- graph.updateNode(smoothingLabel, {
- name: 'Label',
- text: 'Corner smoothing & effect blends',
- fontSize: 13,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const smoothingCard = store.createShape('FRAME', 32, 676, 256, 104, effectsSectionId)
- graph.updateNode(smoothingCard, {
- name: 'Smooth Corner Comparison',
- cornerRadius: 16,
- fills: [solid(DEMO_COLORS.gray50)],
- strokes: thinStroke(DEMO_COLORS.gray200)
- })
- const regularCorner = store.createShape('RECTANGLE', 24, 18, 58, 58, smoothingCard)
- graph.updateNode(regularCorner, {
- name: 'Regular Radius',
- cornerRadius: 18,
- fills: [solid(DEMO_COLORS.blue)]
- })
- const smoothCorner = store.createShape('RECTANGLE', 102, 18, 58, 58, smoothingCard)
- graph.updateNode(smoothCorner, {
- name: 'Smoothed Radius',
- cornerRadius: 18,
- cornerSmoothing: 0.9,
- fills: [solid(DEMO_COLORS.purple)]
- })
- const cornerLabel = store.createShape('TEXT', 176, 26, 56, 36, smoothingCard)
- graph.updateNode(cornerLabel, {
- name: 'Label',
- text: 'Radius\n+ smooth',
- fontSize: 12,
- fontWeight: 600,
- lineHeight: 16,
- fills: [solid(DEMO_COLORS.gray500)]
- })
-
- const independentCard = store.createShape('FRAME', 312, 676, 204, 104, effectsSectionId)
- graph.updateNode(independentCard, {
- name: 'Independent Smooth Corners',
- cornerRadius: 28,
- cornerSmoothing: 1,
- independentCorners: true,
- topLeftRadius: 36,
- topRightRadius: 10,
- bottomRightRadius: 36,
- bottomLeftRadius: 10,
- fills: [
- gradient([
- { color: DEMO_COLORS.teal, position: 0 },
- { color: DEMO_COLORS.blue, position: 1 }
- ])
- ],
- effects: [dropShadow(0, 8, 20, 0, { r: 0.08, g: 0.73, b: 0.73, a: 0.24 })]
- })
- const independentText = store.createShape('TEXT', 20, 34, 164, 24, independentCard)
- graph.updateNode(independentText, {
- name: 'Label',
- text: 'Independent corners',
- fontSize: 15,
- fontWeight: 700,
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const effectBlendCard = store.createShape('FRAME', 540, 676, 300, 104, effectsSectionId)
- graph.updateNode(effectBlendCard, {
- name: 'Effect Blend Card',
- cornerRadius: 18,
- fills: [solid({ r: 0.08, g: 0.1, b: 0.18, a: 1 })],
- clipsContent: true
- })
- const glowBase = store.createShape('ELLIPSE', 22, 14, 76, 76, effectBlendCard)
- graph.updateNode(glowBase, {
- name: 'Glow Base',
- fills: [solid({ r: 0.24, g: 0.46, b: 1, a: 1 })]
- })
- const glowShape = store.createShape('RECTANGLE', 70, 22, 96, 60, effectBlendCard)
- graph.updateNode(glowShape, {
- name: 'Screen Shadow Blend',
- cornerRadius: 22,
- cornerSmoothing: 0.85,
- fills: [solid({ r: 0.58, g: 0.27, b: 0.95, a: 0.7 })],
- effects: [
- { ...dropShadow(0, 0, 28, 0, { r: 0.56, g: 0.33, b: 1, a: 0.72 }), blendMode: 'SCREEN' }
- ]
- })
- const effectBlendText = store.createShape('TEXT', 184, 34, 88, 34, effectBlendCard)
- graph.updateNode(effectBlendText, {
- name: 'Label',
- text: 'Screen\nshadow',
- fontSize: 13,
- fontWeight: 700,
- lineHeight: 17,
- fills: [solid(DEMO_COLORS.white)]
- })
-}
diff --git a/src/app/demo/sections/example.ts b/src/app/demo/sections/example.ts
new file mode 100644
index 000000000..641aa52a7
--- /dev/null
+++ b/src/app/demo/sections/example.ts
@@ -0,0 +1,52 @@
+import { Frame, Text } from '@open-pencil/core/design-jsx'
+import type { TreeNode } from '@open-pencil/core/design-jsx'
+
+const INK = '#172554'
+const MUTED = '#536487'
+const TILE = '#EEF2FF'
+
+/** The framed artwork panel shared by the demo's specimen sections. */
+export function createArtworkTile(
+ name: string,
+ options: { padding?: number; center?: boolean; children?: TreeNode[] } = {}
+): TreeNode {
+ const props = {
+ name,
+ flex: 'row' as const,
+ w: 'fill' as const,
+ h: 'hug' as const,
+ p: options.padding ?? 16,
+ justify: 'center' as const,
+ rounded: 12,
+ bg: TILE,
+ children: options.children ?? []
+ }
+ return Frame(options.center ? { ...props, items: 'center' as const } : props)
+}
+
+/** A labelled specimen column: artwork panel, title, and caption. */
+export function createExampleColumn(options: {
+ title: string
+ caption: string
+ artwork: TreeNode
+}): TreeNode {
+ return Frame({
+ name: options.title,
+ flex: 'col',
+ w: 'fill',
+ h: 'hug',
+ gap: 8,
+ children: [
+ options.artwork,
+ Text({ font: 'Inter', color: INK, size: 14, weight: 600, children: options.title }),
+ Text({
+ font: 'Inter',
+ color: MUTED,
+ size: 12,
+ w: 'fill',
+ lineHeight: 18,
+ children: options.caption
+ })
+ ]
+ })
+}
diff --git a/src/app/demo/sections/standalone.ts b/src/app/demo/sections/standalone.ts
deleted file mode 100644
index 256b8fd8e..000000000
--- a/src/app/demo/sections/standalone.ts
+++ /dev/null
@@ -1,173 +0,0 @@
-import { DEMO_COLORS, gradient, solid, thinStroke } from '@/app/demo/colors'
-import type { EditorStore } from '@/app/editor/session'
-
-export function createStandaloneShapes(store: EditorStore) {
- const { graph } = store
-
- const grad1 = store.createShape('FRAME', 60, 660, 180, 120)
- graph.updateNode(grad1, {
- name: 'Gradient Card',
- cornerRadius: 16,
- fills: [
- gradient([
- { color: { r: 0.99, g: 0.37, b: 0.33, a: 1 }, position: 0 },
- { color: { r: 0.93, g: 0.18, b: 0.65, a: 1 }, position: 0.5 },
- { color: { r: 0.55, g: 0.28, b: 0.96, a: 1 }, position: 1 }
- ])
- ]
- })
- const gradText = store.createShape('TEXT', 20, 80, 140, 20, grad1)
- graph.updateNode(gradText, {
- name: 'Label',
- text: 'Linear Gradient',
- fontSize: 14,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const grad2 = store.createShape('FRAME', 260, 660, 180, 120)
- graph.updateNode(grad2, {
- name: 'Ocean',
- cornerRadius: 16,
- fills: [
- gradient([
- { color: { r: 0.04, g: 0.82, b: 0.67, a: 1 }, position: 0 },
- { color: { r: 0.13, g: 0.45, b: 0.96, a: 1 }, position: 1 }
- ])
- ]
- })
- const grad2Text = store.createShape('TEXT', 20, 80, 140, 20, grad2)
- graph.updateNode(grad2Text, {
- name: 'Label',
- text: 'Ocean Breeze',
- fontSize: 14,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const grad3 = store.createShape('FRAME', 460, 660, 180, 120)
- graph.updateNode(grad3, {
- name: 'Sunset',
- cornerRadius: 16,
- fills: [
- gradient([
- { color: { r: 1, g: 0.6, b: 0.2, a: 1 }, position: 0 },
- { color: { r: 0.96, g: 0.26, b: 0.21, a: 1 }, position: 1 }
- ])
- ]
- })
- const grad3Text = store.createShape('TEXT', 20, 80, 140, 20, grad3)
- graph.updateNode(grad3Text, {
- name: 'Label',
- text: 'Warm Sunset',
- fontSize: 14,
- fontWeight: 600,
- fills: [solid(DEMO_COLORS.white)]
- })
-
- const typoFrame = store.createShape('FRAME', 700, 660, 320, 210)
- graph.updateNode(typoFrame, {
- name: 'Typography, OpenType & Decorations',
- cornerRadius: 12,
- fills: [solid(DEMO_COLORS.white)],
- strokes: thinStroke(DEMO_COLORS.gray200),
- layoutMode: 'VERTICAL',
- primaryAxisSizing: 'FIXED',
- counterAxisSizing: 'FIXED',
- itemSpacing: 6,
- paddingTop: 16,
- paddingBottom: 16,
- paddingLeft: 20,
- paddingRight: 20
- })
- const typoItems = [
- { text: 'Heading', size: 24, weight: 700 },
- { text: 'Subheading', size: 16, weight: 600 },
- { text: 'Body text — The quick brown fox jumps.', size: 13, weight: 400 },
- {
- text: 'Ligatures off — office affine',
- size: 13,
- weight: 500,
- features: [{ tag: 'LIGA', enabled: false }]
- },
- {
- text: 'Raw OT tags — DLIG on · KERN off',
- size: 11,
- weight: 500,
- features: [
- { tag: 'DLIG', enabled: true },
- { tag: 'KERN', enabled: false }
- ]
- },
- {
- text: 'Wavy underline from imported .fig',
- size: 13,
- weight: 500,
- decoration: 'UNDERLINE' as const,
- decorationStyle: 'WAVY' as const,
- decorationFills: [solid(DEMO_COLORS.red)],
- decorationThickness: 1.6
- },
- {
- text: 'Dotted underline + custom thickness',
- size: 13,
- weight: 500,
- decoration: 'UNDERLINE' as const,
- decorationStyle: 'DOTTED' as const,
- decorationFills: [solid(DEMO_COLORS.blue)],
- decorationThickness: 2
- }
- ]
- for (const t of typoItems) {
- const tid = store.createShape('TEXT', 0, 0, 280, t.size + 4, typoFrame)
- graph.updateNode(tid, {
- name: t.text.split(' ')[0],
- text: t.text,
- fontSize: t.size,
- fontWeight: t.weight,
- fontFeatures: t.features ?? [],
- textDecoration: t.decoration ?? 'NONE',
- textDecorationStyle: t.decorationStyle ?? 'SOLID',
- textDecorationFills: t.decorationFills ?? [],
- textDecorationThickness: t.decorationThickness ?? null,
- textAutoResize: 'HEIGHT',
- layoutAlignSelf: 'STRETCH',
- fills: [solid(DEMO_COLORS.black)]
- })
- }
-
- const shapes = [
- {
- type: 'ELLIPSE' as const,
- x: 1060,
- fill: gradient([
- { color: DEMO_COLORS.purple, position: 0 },
- { color: DEMO_COLORS.blue, position: 1 }
- ])
- },
- {
- type: 'RECTANGLE' as const,
- x: 1160,
- fill: gradient([
- { color: DEMO_COLORS.green, position: 0 },
- { color: DEMO_COLORS.teal, position: 1 }
- ])
- },
- {
- type: 'ELLIPSE' as const,
- x: 1260,
- fill: gradient([
- { color: DEMO_COLORS.orange, position: 0 },
- { color: DEMO_COLORS.red, position: 1 }
- ])
- }
- ]
- for (const s of shapes) {
- const id = store.createShape(s.type, s.x, 680, 80, 80)
- graph.updateNode(id, {
- name: s.type === 'ELLIPSE' ? 'Circle' : 'Square',
- cornerRadius: s.type === 'RECTANGLE' ? 16 : 0,
- fills: [s.fill]
- })
- }
-}
diff --git a/src/app/editor/preparation/types.ts b/src/app/editor/preparation/types.ts
index bc69a41cc..1cd9a9164 100644
--- a/src/app/editor/preparation/types.ts
+++ b/src/app/editor/preparation/types.ts
@@ -6,6 +6,7 @@ export type EditorPreparationKind =
| 'page-switch'
| 'font-retry'
| 'dom-import'
+ | 'demo-load'
export type EditorPreparationPhase =
| 'reading'
diff --git a/tests/e2e/canvas/demo-workspace.spec.ts b/tests/e2e/canvas/demo-workspace.spec.ts
index 6aeb96efc..59dae823b 100644
--- a/tests/e2e/canvas/demo-workspace.spec.ts
+++ b/tests/e2e/canvas/demo-workspace.spec.ts
@@ -14,7 +14,7 @@ async function openDemo(page: Page) {
test.use({ viewport: { width: 1200, height: 1300 } })
for (const [name, snapshot] of [
- ['01 · Components & variables', 'demo-announcements'],
+ ['01 · Components & variables', 'demo-components-and-variables'],
['02 · Typography', 'demo-typography'],
['03 · Paint & effects', 'demo-paint']
] as const) {
@@ -48,6 +48,61 @@ for (const [name, snapshot] of [
})
}
+test('demo generation reports canvas preparation until the document is ready', async ({ page }) => {
+ const canvas = new CanvasHelper(page)
+ await page.goto('/demo?no-chrome&no-rulers')
+ const loader = page.getByTestId('canvas-loading')
+ await expect(loader).toBeVisible()
+ await expect(loader).toContainText(
+ /Preparing layers|Resolving fonts|Computing layout|Preparing canvas/
+ )
+ await canvas.waitForInit()
+ await waitForDemo(page)
+ await expect(loader).toBeHidden()
+})
+
+test('an abandoned demo build leaves the document as it was', async ({ page }) => {
+ const canvas = new CanvasHelper(page)
+ await page.goto('/demo?no-chrome&no-rulers')
+
+ const documentState = () =>
+ page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ const pages = store.graph.getPages()
+ return {
+ pages: pages.length,
+ name: pages[0]?.name ?? null,
+ children: pages[0] ? store.graph.getChildren(pages[0].id).length : -1,
+ collections: store.graph.variableCollections.size,
+ preparing: store.state.preparation !== null
+ }
+ })
+
+ await page.waitForFunction(
+ () => window.openPencil?.getStore?.()?.state.preparation?.kind === 'demo-load'
+ )
+ const pristine = await documentState()
+ // Wait until generation has touched the document (it has added its extra pages), so the
+ // interruption exercises the rollback rather than a build that never started mutating.
+ await page.waitForFunction(() => {
+ const store = window.openPencil?.getStore?.()
+ return store?.state.preparation?.kind === 'demo-load' && store.graph.getPages().length > 1
+ })
+ await page.evaluate(async () => {
+ const store = window.openPencil?.getStore?.()
+ await store.switchPage(store.graph.getPages()[0].id)
+ })
+
+ // The abandoned build must roll its pages, sections, and variables back.
+ await expect
+ .poll(async () => {
+ const state = await documentState()
+ return state.preparing ? null : state
+ })
+ .toEqual({ ...pristine, preparing: false })
+ canvas.assertNoErrors()
+})
+
test('demo completion preserves a document replaced during its final page switch', async ({
page
}) => {
diff --git a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-announcements-openpencil-darwin.png b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-announcements-openpencil-darwin.png
deleted file mode 100644
index 7bc2ac784..000000000
Binary files a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-announcements-openpencil-darwin.png and /dev/null differ
diff --git a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png
new file mode 100644
index 000000000..a6d0d054a
Binary files /dev/null and b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png differ
diff --git a/tests/e2e/layers/panel.spec.ts b/tests/e2e/layers/panel.spec.ts
index 61a6bc7b1..d7e1ccf68 100644
--- a/tests/e2e/layers/panel.spec.ts
+++ b/tests/e2e/layers/panel.spec.ts
@@ -53,27 +53,48 @@ async function getSelectedCount(): Promise<number> {
test('demo layers visible in panel', async () => {
const names = await getLayerNames()
+ expect(names).toContain('Announcement system')
expect(names).toContain('Components')
- expect(names).toContain('App Preview')
})
test('clicking a node inside a frame does not reparent it', async () => {
- const beforeTree = await getSceneTree()
- const section = beforeTree.children.find((c) => c.name === 'App Preview')
- const dashboard = section?.children.find((c) => c.name === 'Dashboard')
- expect(dashboard).toBeTruthy()
- const sidebarBefore = dashboard?.children.find((c) => c.name === 'Sidebar')
- expect(sidebarBefore).toBeTruthy()
-
- // Click inside the App Preview section area
- await editor.canvas.click(350, 310)
+ const target = await editor.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const nodes = [...store.graph.nodes.values()]
+ const root = nodes.find((node) => node.name === 'Announcement system')
+ const nested = nodes.find((node) => node.name === 'Source components')
+ if (!root || !nested?.parentId) throw new Error('Demo announcement structure not found')
+ const origin = store.graph.getAbsolutePosition(nested.id)
+ return {
+ id: nested.id,
+ parentId: nested.parentId,
+ rootId: root.id,
+ x: (origin.x + nested.width / 2) * store.state.zoom + store.state.panX,
+ y: (origin.y + nested.height / 2) * store.state.zoom + store.state.panY
+ }
+ })
+
+ // Click inside the nested frame hierarchy.
+ await editor.canvas.click(target.x, target.y)
await editor.canvas.waitForRender()
- // Sidebar should still be a child of Dashboard
- const afterTree = await getSceneTree()
- const afterSection = afterTree.children.find((c) => c.name === 'App Preview')
- const afterDashboard = afterSection?.children.find((c) => c.name === 'Dashboard')
- expect(afterDashboard?.children.find((c) => c.name === 'Sidebar')).toBeTruthy()
+ const after = await editor.page.evaluate(
+ ({ id, rootId }) => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ return {
+ parentId: store.graph.getNode(id)?.parentId ?? null,
+ rootParentId: store.graph.getNode(rootId)?.parentId ?? null,
+ pageId: store.state.currentPageId
+ }
+ },
+ { id: target.id, rootId: target.rootId }
+ )
+
+ // The clicked node and its section must keep their place in the hierarchy.
+ expect(after.parentId).toBe(target.parentId)
+ expect(after.rootParentId).toBe(after.pageId)
editor.canvas.assertNoErrors()
})
diff --git a/tests/engine/app/demo.test.ts b/tests/engine/app/demo.test.ts
index c4d4e1478..a8f0a51b8 100644
--- a/tests/engine/app/demo.test.ts
+++ b/tests/engine/app/demo.test.ts
@@ -1,36 +1,41 @@
import { describe, expect, test } from 'bun:test'
-import { createStandaloneShapes } from '@/app/demo/sections/standalone'
+import { createTypographySection } from '@/app/demo/typography/section'
import { createEditorStore } from '@/app/editor/session'
describe('demo document', () => {
- test('showcases imported OpenType and text decoration features', () => {
+ test('showcases OpenType features and native text decorations', async () => {
const store = createEditorStore()
+ const page = store.graph.addPage('Typography')
- createStandaloneShapes(store)
+ await createTypographySection(store.graph, page.id)
const nodes = [...store.graph.getAllNodes()]
- const ligatures = nodes.find((node) => node.name === 'Ligatures')
- const rawTags = nodes.find((node) => node.name === 'Raw')
- const wavy = nodes.find((node) => node.name === 'Wavy')
- const dotted = nodes.find((node) => node.name === 'Dotted')
+ const sample = (name: string) =>
+ nodes.find((node) => node.name === name && node.type === 'TEXT')
- expect(ligatures?.fontFeatures).toEqual([{ tag: 'LIGA', enabled: false }])
- expect(rawTags?.fontFeatures).toEqual([
- { tag: 'DLIG', enabled: true },
- { tag: 'KERN', enabled: false }
+ expect(sample('Discretionary ligatures / DLIG ON')?.fontFeatures).toEqual([
+ { tag: 'DLIG', enabled: true }
])
- expect(wavy).toMatchObject({
+ expect(sample('Discretionary ligatures / DLIG OFF')?.fontFeatures).toEqual([
+ { tag: 'DLIG', enabled: false }
+ ])
+ expect(sample('Tabular and proportional figures / TNUM ON · PNUM OFF')?.fontFeatures).toEqual([
+ { tag: 'TNUM', enabled: true },
+ { tag: 'PNUM', enabled: false }
+ ])
+
+ expect(sample('Wavy underline')).toMatchObject({
textDecoration: 'UNDERLINE',
textDecorationStyle: 'WAVY',
textDecorationThickness: 1.6
})
- expect(wavy?.textDecorationFills[0]?.type).toBe('SOLID')
- expect(dotted).toMatchObject({
+ expect(sample('Wavy underline')?.textDecorationFills[0]?.type).toBe('SOLID')
+ expect(sample('Dotted underline')).toMatchObject({
textDecoration: 'UNDERLINE',
textDecorationStyle: 'DOTTED',
textDecorationThickness: 2
})
- expect(dotted?.textDecorationFills[0]?.type).toBe('SOLID')
+ expect(sample('Dotted underline')?.textDecorationFills[0]?.type).toBe('SOLID')
})
})