@particle-academy/fancy-cms-ui 0.0.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/dist/chunk-MRWUUNJR.js +47 -0
- package/dist/chunk-MRWUUNJR.js.map +1 -0
- package/dist/chunk-NWH2AJLH.js +352 -0
- package/dist/chunk-NWH2AJLH.js.map +1 -0
- package/dist/editor.cjs +701 -0
- package/dist/editor.cjs.map +1 -0
- package/dist/editor.d.cts +89 -0
- package/dist/editor.d.ts +89 -0
- package/dist/editor.js +369 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.cjs +407 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/ops-CJenUAsy.d.ts +71 -0
- package/dist/ops-DWgJjAbX.d.cts +71 -0
- package/dist/react.cjs +211 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +55 -0
- package/dist/react.d.ts +55 -0
- package/dist/react.js +21 -0
- package/dist/react.js.map +1 -0
- package/dist/types-DKCl14aV.d.cts +176 -0
- package/dist/types-DKCl14aV.d.ts +176 -0
- package/package.json +102 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @particle-academy/fancy-cms-ui
|
|
2
|
+
|
|
3
|
+
The editor + isomorphic renderer for **fancy-cms** — an extendable inline-WYSIWYG
|
|
4
|
+
website + app-shell builder for Laravel, built on the Fancy UI suite.
|
|
5
|
+
|
|
6
|
+
> **Status: Phase 0 done; Phase 1 in progress.** Ships the foundation the rest
|
|
7
|
+
> of the system types against — the **Stages** document model, the **`PageOp`**
|
|
8
|
+
> op-spine + pure `reduce`, and the **JS style→CSS emitter** (one half of the
|
|
9
|
+
> dual-emitter pair; the other lives in the PHP `particle-academy/fancy-cms`) —
|
|
10
|
+
> the **React renderer** (`./react`: `CmsPage` / `CmsRegion`) shared by the
|
|
11
|
+
> editor and published islands, and the **WYSIWYG editor** (`./editor`: layers ·
|
|
12
|
+
> canvas with select + drag-move · inspector · snapshot undo/redo). Motion
|
|
13
|
+
> engine, addon SDK, file manager, and the opt-in `/collab` + `/agent` layers
|
|
14
|
+
> land in later phases.
|
|
15
|
+
|
|
16
|
+
Architecture & plan: `fancy-ui/docs/fancy-cms.md`.
|
|
17
|
+
|
|
18
|
+
## What's here (Phase 0)
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
src/
|
|
22
|
+
├── document/
|
|
23
|
+
│ ├── types.ts Stages model: PageDoc, Node, Constraints, StyleProps, …
|
|
24
|
+
│ ├── ops.ts PageOp union + envelope
|
|
25
|
+
│ ├── reduce.ts pure/total reduce(doc, op) + invert(doc, op) for undo
|
|
26
|
+
│ └── fractional.ts collab-safe ordering keys (keyBetween)
|
|
27
|
+
├── render/
|
|
28
|
+
│ └── css.ts deterministic style/layout/constraints → CSS (static subset)
|
|
29
|
+
├── react/ the React renderer (the ./react entry)
|
|
30
|
+
│ ├── registry.tsx element registry (text/image/section/stack/grid/…)
|
|
31
|
+
│ ├── RenderNode.tsx recursive node → DOM with data-cms handles + islands
|
|
32
|
+
│ └── CmsPage / CmsRegion full page + embeddable subtree
|
|
33
|
+
└── editor/ the WYSIWYG editor (the ./editor entry)
|
|
34
|
+
├── state.ts pure editor reducer (ops + snapshot undo/redo + selection)
|
|
35
|
+
├── useEditor.ts the editor hook
|
|
36
|
+
└── Editor / Canvas / LayersPanel / Inspector
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The `reduce` function is **pure and total** (an invalid op is a logged no-op),
|
|
40
|
+
which is what makes undo, revisions, collaboration, and agent edits all flow
|
|
41
|
+
through one spine. The CSS emitter is **deterministic** so the PHP emitter can
|
|
42
|
+
produce byte-identical output — verified by the parity harness.
|
|
43
|
+
|
|
44
|
+
## Principles
|
|
45
|
+
|
|
46
|
+
- **Guest, not host** — adopted per-surface (route / region / slot).
|
|
47
|
+
- **Human+ is opt-in** — core works single-user with no websockets or agents.
|
|
48
|
+
- **Zero third-party runtime deps.**
|
|
49
|
+
|
|
50
|
+
MIT © Particle Academy
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { childrenOf, emitDocCss, isBinding } from './chunk-NWH2AJLH.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { Fragment } from 'react';
|
|
4
|
+
|
|
5
|
+
function literal(v) {
|
|
6
|
+
if (v === void 0 || v === null) return "";
|
|
7
|
+
if (isBinding(v)) return "";
|
|
8
|
+
return String(v);
|
|
9
|
+
}
|
|
10
|
+
var defaultRegistry = {
|
|
11
|
+
section: ({ children }) => children,
|
|
12
|
+
stack: ({ children }) => children,
|
|
13
|
+
grid: ({ children }) => children,
|
|
14
|
+
frame: ({ children }) => children,
|
|
15
|
+
shape: ({ children }) => children,
|
|
16
|
+
text: ({ node }) => literal(node.props.content),
|
|
17
|
+
image: ({ node }) => /* @__PURE__ */ jsx(
|
|
18
|
+
"img",
|
|
19
|
+
{
|
|
20
|
+
src: literal(node.props.src),
|
|
21
|
+
alt: literal(node.props.alt),
|
|
22
|
+
style: { width: "100%", height: "100%", objectFit: "cover", display: "block" }
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
};
|
|
26
|
+
function RenderNode({ doc, id, registry = defaultRegistry }) {
|
|
27
|
+
const node = doc.nodes[id];
|
|
28
|
+
if (!node) return null;
|
|
29
|
+
const kids = childrenOf(doc, id).map((child) => /* @__PURE__ */ jsx(RenderNode, { doc, id: child.id, registry }, child.id));
|
|
30
|
+
const renderer = registry[node.type];
|
|
31
|
+
const inner = renderer ? renderer({ node, doc, children: kids }) : node.island ? null : kids;
|
|
32
|
+
return /* @__PURE__ */ jsx("div", { "data-cms": node.id, "data-cms-island": node.island ? node.type : void 0, children: inner });
|
|
33
|
+
}
|
|
34
|
+
function CmsPage({
|
|
35
|
+
doc,
|
|
36
|
+
registry = defaultRegistry,
|
|
37
|
+
includeStyles = true
|
|
38
|
+
}) {
|
|
39
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
40
|
+
includeStyles ? /* @__PURE__ */ jsx("style", { "data-cms-styles": "", children: emitDocCss(doc) }) : null,
|
|
41
|
+
doc.sections.map((id) => /* @__PURE__ */ jsx(RenderNode, { doc, id, registry }, id))
|
|
42
|
+
] });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { CmsPage, RenderNode, defaultRegistry };
|
|
46
|
+
//# sourceMappingURL=chunk-MRWUUNJR.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-MRWUUNJR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/registry.tsx","../src/react/RenderNode.tsx","../src/react/CmsPage.tsx"],"names":["jsx"],"mappings":";;;;AAmBA,SAAS,QAAQ,CAAA,EAAoC;AACnD,EAAA,IAAI,CAAA,KAAM,MAAA,IAAa,CAAA,KAAM,IAAA,EAAM,OAAO,EAAA;AAC1C,EAAA,IAAI,SAAA,CAAU,CAAC,CAAA,EAAG,OAAO,EAAA;AACzB,EAAA,OAAO,OAAO,CAAC,CAAA;AACjB;AAGO,IAAM,eAAA,GAAmC;AAAA,EAC9C,OAAA,EAAS,CAAC,EAAE,QAAA,EAAS,KAAM,QAAA;AAAA,EAC3B,KAAA,EAAO,CAAC,EAAE,QAAA,EAAS,KAAM,QAAA;AAAA,EACzB,IAAA,EAAM,CAAC,EAAE,QAAA,EAAS,KAAM,QAAA;AAAA,EACxB,KAAA,EAAO,CAAC,EAAE,QAAA,EAAS,KAAM,QAAA;AAAA,EACzB,KAAA,EAAO,CAAC,EAAE,QAAA,EAAS,KAAM,QAAA;AAAA,EACzB,IAAA,EAAM,CAAC,EAAE,IAAA,OAAW,OAAA,CAAQ,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,EAC9C,KAAA,EAAO,CAAC,EAAE,IAAA,EAAK,qBACb,GAAA;AAAA,IA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B;AAClB,CAAA,EAA+B;AAC7B,EAAA,4BACG,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,IAAA,aAAA,mBAAgBA,IAAC,OAAA,EAAA,EAAM,iBAAA,EAAgB,IAAI,QAAA,EAAA,UAAA,CAAW,GAAG,GAAE,CAAA,GAAW,IAAA;AAAA,IACtE,GAAA,CAAI,QAAA,CAAS,GAAA,CAAI,CAAC,EAAA,qBACjBA,GAAAA,CAAC,UAAA,EAAA,EAAoB,GAAA,EAAU,EAAA,EAAQ,QAAA,EAAA,EAAtB,EAA0C,CAC5D;AAAA,GAAA,EACH,CAAA;AAEJ","file":"chunk-MRWUUNJR.js","sourcesContent":["import type { ReactNode } from \"react\";\nimport { isBinding, type Bound, type Json, type Node, type PageDoc } from \"../document/types\";\n\nexport interface ElementContext {\n node: Node;\n doc: PageDoc;\n /** Pre-rendered child nodes, in order. */\n children: ReactNode;\n}\n\n/**\n * Renders the INNER content of a node. The outer `[data-cms]` wrapper is added\n * by {@link RenderNode}, so a renderer only returns what goes inside.\n */\nexport type ElementRenderer = (ctx: ElementContext) => ReactNode;\n\nexport type ElementRegistry = Record<string, ElementRenderer>;\n\n/** Resolve a literal prop to a string (bindings resolve in Phase 3). */\nfunction literal(v: Bound<Json> | undefined): string {\n if (v === undefined || v === null) return \"\";\n if (isBinding(v)) return \"\";\n return String(v);\n}\n\n/** Built-in native elements. Containers render their children; leaves render content. */\nexport const defaultRegistry: ElementRegistry = {\n section: ({ children }) => children,\n stack: ({ children }) => children,\n grid: ({ children }) => children,\n frame: ({ children }) => children,\n shape: ({ children }) => children,\n text: ({ node }) => literal(node.props.content),\n image: ({ node }) => (\n <img\n src={literal(node.props.src)}\n alt={literal(node.props.alt)}\n style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\", display: \"block\" }}\n />\n ),\n};\n","import type { ReactElement } from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport { childrenOf } from \"../document/reduce\";\nimport { defaultRegistry, type ElementRegistry } from \"./registry\";\n\nexport interface RenderNodeProps {\n doc: PageDoc;\n id: string;\n registry?: ElementRegistry;\n}\n\n/**\n * Render one node (and its subtree) to a `[data-cms]`-tagged element. The CSS\n * emitted by `emitDocCss` targets these `data-cms` handles. Interactive /\n * 3rd-party **islands** with no registered renderer become an empty, sized\n * placeholder the host hydrates client-side — mirroring the PHP renderer.\n */\nexport function RenderNode({ doc, id, registry = defaultRegistry }: RenderNodeProps): ReactElement | null {\n const node = doc.nodes[id];\n if (!node) return null;\n\n const kids = childrenOf(doc, id).map((child) => (\n <RenderNode key={child.id} doc={doc} id={child.id} registry={registry} />\n ));\n\n const renderer = registry[node.type];\n const inner = renderer ? renderer({ node, doc, children: kids }) : node.island ? null : kids;\n\n return (\n <div data-cms={node.id} data-cms-island={node.island ? node.type : undefined}>\n {inner}\n </div>\n );\n}\n","import { Fragment, type ReactElement } from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport { emitDocCss } from \"../render/css\";\nimport { RenderNode } from \"./RenderNode\";\nimport { defaultRegistry, type ElementRegistry } from \"./registry\";\n\nexport interface CmsPageProps {\n doc: PageDoc;\n registry?: ElementRegistry;\n /** Inject the compiled stylesheet. Set false when the host emits CSS itself. */\n includeStyles?: boolean;\n}\n\n/** Render a full page document: the compiled stylesheet + every section. */\nexport function CmsPage({\n doc,\n registry = defaultRegistry,\n includeStyles = true,\n}: CmsPageProps): ReactElement {\n return (\n <Fragment>\n {includeStyles ? <style data-cms-styles=\"\">{emitDocCss(doc)}</style> : null}\n {doc.sections.map((id) => (\n <RenderNode key={id} doc={doc} id={id} registry={registry} />\n ))}\n </Fragment>\n );\n}\n"]}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
// src/document/types.ts
|
|
2
|
+
function isBinding(v) {
|
|
3
|
+
return typeof v === "object" && v !== null && typeof v.$bind === "string";
|
|
4
|
+
}
|
|
5
|
+
var DEFAULT_BREAKPOINTS = {
|
|
6
|
+
base: 0,
|
|
7
|
+
md: 768,
|
|
8
|
+
lg: 1024
|
|
9
|
+
};
|
|
10
|
+
function emptyDoc(id, slug = "/") {
|
|
11
|
+
return {
|
|
12
|
+
id,
|
|
13
|
+
seq: 0,
|
|
14
|
+
meta: { title: "Untitled", slug, scrollMode: "smooth" },
|
|
15
|
+
theme: { name: "default" },
|
|
16
|
+
breakpoints: ["base", "md", "lg"],
|
|
17
|
+
sections: [],
|
|
18
|
+
nodes: {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/document/reduce.ts
|
|
23
|
+
function childrenOf(doc, parent) {
|
|
24
|
+
if (parent === null) {
|
|
25
|
+
return doc.sections.map((id) => doc.nodes[id]).filter((n) => Boolean(n));
|
|
26
|
+
}
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const id of Object.keys(doc.nodes)) {
|
|
29
|
+
const n = doc.nodes[id];
|
|
30
|
+
if (n.parent === parent) out.push(n);
|
|
31
|
+
}
|
|
32
|
+
out.sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function descendantIds(doc, id) {
|
|
36
|
+
const out = [];
|
|
37
|
+
const stack = [id];
|
|
38
|
+
while (stack.length) {
|
|
39
|
+
const current = stack.pop();
|
|
40
|
+
for (const childId of Object.keys(doc.nodes)) {
|
|
41
|
+
const n = doc.nodes[childId];
|
|
42
|
+
if (n.parent === current) {
|
|
43
|
+
out.push(childId);
|
|
44
|
+
stack.push(childId);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
function patchNode(doc, id, patch) {
|
|
51
|
+
const node = doc.nodes[id];
|
|
52
|
+
return {
|
|
53
|
+
...doc,
|
|
54
|
+
nodes: { ...doc.nodes, [id]: { ...node, ...patch } },
|
|
55
|
+
seq: doc.seq + 1
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function reduce(doc, op, opts = {}) {
|
|
59
|
+
const invalid = (reason) => {
|
|
60
|
+
opts.onInvalid?.(op, reason);
|
|
61
|
+
return doc;
|
|
62
|
+
};
|
|
63
|
+
switch (op.t) {
|
|
64
|
+
case "insert_node": {
|
|
65
|
+
if (doc.nodes[op.node.id]) return invalid("node id already exists");
|
|
66
|
+
if (op.node.parent !== null && !doc.nodes[op.node.parent]) return invalid("parent not found");
|
|
67
|
+
return {
|
|
68
|
+
...doc,
|
|
69
|
+
nodes: { ...doc.nodes, [op.node.id]: op.node },
|
|
70
|
+
sections: op.node.parent === null ? [...doc.sections, op.node.id] : doc.sections,
|
|
71
|
+
seq: doc.seq + 1
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case "remove_node": {
|
|
75
|
+
if (!doc.nodes[op.id]) return invalid("node not found");
|
|
76
|
+
const dead = /* @__PURE__ */ new Set([op.id, ...descendantIds(doc, op.id)]);
|
|
77
|
+
const nodes = {};
|
|
78
|
+
for (const id of Object.keys(doc.nodes)) {
|
|
79
|
+
if (!dead.has(id)) nodes[id] = doc.nodes[id];
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...doc,
|
|
83
|
+
nodes,
|
|
84
|
+
sections: doc.sections.filter((s) => !dead.has(s)),
|
|
85
|
+
seq: doc.seq + 1
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
case "move_node": {
|
|
89
|
+
const node = doc.nodes[op.id];
|
|
90
|
+
if (!node) return invalid("node not found");
|
|
91
|
+
if (op.parent === op.id) return invalid("cannot parent a node to itself");
|
|
92
|
+
if (op.parent !== null && !doc.nodes[op.parent]) return invalid("new parent not found");
|
|
93
|
+
if (op.parent !== null && descendantIds(doc, op.id).includes(op.parent)) {
|
|
94
|
+
return invalid("move would create a cycle");
|
|
95
|
+
}
|
|
96
|
+
const wasTop = node.parent === null;
|
|
97
|
+
const nowTop = op.parent === null;
|
|
98
|
+
let sections = doc.sections;
|
|
99
|
+
if (wasTop && !nowTop) sections = sections.filter((s) => s !== op.id);
|
|
100
|
+
else if (!wasTop && nowTop) sections = [...sections, op.id];
|
|
101
|
+
return {
|
|
102
|
+
...doc,
|
|
103
|
+
nodes: { ...doc.nodes, [op.id]: { ...node, parent: op.parent, order: op.order } },
|
|
104
|
+
sections,
|
|
105
|
+
seq: doc.seq + 1
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
case "set_props": {
|
|
109
|
+
if (!doc.nodes[op.id]) return invalid("node not found");
|
|
110
|
+
return patchNode(doc, op.id, {
|
|
111
|
+
props: { ...doc.nodes[op.id].props, ...op.patch }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
case "set_style": {
|
|
115
|
+
const node = doc.nodes[op.id];
|
|
116
|
+
if (!node) return invalid("node not found");
|
|
117
|
+
const prev = node.style[op.breakpoint] ?? {};
|
|
118
|
+
return patchNode(doc, op.id, {
|
|
119
|
+
style: { ...node.style, [op.breakpoint]: { ...prev, ...op.patch } }
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
case "set_constraints": {
|
|
123
|
+
const node = doc.nodes[op.id];
|
|
124
|
+
if (!node) return invalid("node not found");
|
|
125
|
+
const base = node.constraints ?? { base: { width: "hug", height: "hug" } };
|
|
126
|
+
const prev = base[op.breakpoint] ?? {};
|
|
127
|
+
return patchNode(doc, op.id, {
|
|
128
|
+
constraints: { ...base, [op.breakpoint]: { ...prev, ...op.patch } }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
case "set_animation": {
|
|
132
|
+
const node = doc.nodes[op.id];
|
|
133
|
+
if (!node) return invalid("node not found");
|
|
134
|
+
const list = node.animations ?? [];
|
|
135
|
+
const idx = list.findIndex((a) => a.id === op.anim.id);
|
|
136
|
+
return patchNode(doc, op.id, {
|
|
137
|
+
animations: idx >= 0 ? list.map((a, i) => i === idx ? op.anim : a) : [...list, op.anim]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
case "remove_animation": {
|
|
141
|
+
const node = doc.nodes[op.id];
|
|
142
|
+
if (!node) return invalid("node not found");
|
|
143
|
+
return patchNode(doc, op.id, {
|
|
144
|
+
animations: (node.animations ?? []).filter((a) => a.id !== op.animId)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
case "set_action": {
|
|
148
|
+
const node = doc.nodes[op.id];
|
|
149
|
+
if (!node) return invalid("node not found");
|
|
150
|
+
const list = node.actions ?? [];
|
|
151
|
+
let actions;
|
|
152
|
+
if (op.action === null) actions = list.filter((_, i) => i !== op.index);
|
|
153
|
+
else if (op.index >= list.length) actions = [...list, op.action];
|
|
154
|
+
else actions = list.map((a, i) => i === op.index ? op.action : a);
|
|
155
|
+
return patchNode(doc, op.id, { actions });
|
|
156
|
+
}
|
|
157
|
+
case "set_meta":
|
|
158
|
+
return { ...doc, meta: { ...doc.meta, ...op.patch }, seq: doc.seq + 1 };
|
|
159
|
+
case "set_theme":
|
|
160
|
+
return { ...doc, theme: { ...doc.theme, ...op.patch }, seq: doc.seq + 1 };
|
|
161
|
+
case "reorder_sections": {
|
|
162
|
+
const current = new Set(doc.sections);
|
|
163
|
+
const same = op.order.length === doc.sections.length && op.order.every((id) => current.has(id));
|
|
164
|
+
if (!same) return invalid("reorder must be a permutation of current sections");
|
|
165
|
+
return { ...doc, sections: [...op.order], seq: doc.seq + 1 };
|
|
166
|
+
}
|
|
167
|
+
default:
|
|
168
|
+
return invalid(`unknown op "${op.t}"`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function reduceAll(doc, ops, opts) {
|
|
172
|
+
return ops.reduce((d, op) => reduce(d, op, opts), doc);
|
|
173
|
+
}
|
|
174
|
+
function invert(doc, op) {
|
|
175
|
+
switch (op.t) {
|
|
176
|
+
case "insert_node":
|
|
177
|
+
return [{ t: "remove_node", id: op.node.id }];
|
|
178
|
+
case "remove_node": {
|
|
179
|
+
const node = doc.nodes[op.id];
|
|
180
|
+
if (!node) return [];
|
|
181
|
+
const ids = [op.id, ...descendantIds(doc, op.id)];
|
|
182
|
+
const inserts = ids.map((id) => ({ t: "insert_node", node: doc.nodes[id] }));
|
|
183
|
+
if (node.parent === null) inserts.push({ t: "reorder_sections", order: [...doc.sections] });
|
|
184
|
+
return inserts;
|
|
185
|
+
}
|
|
186
|
+
case "move_node": {
|
|
187
|
+
const node = doc.nodes[op.id];
|
|
188
|
+
if (!node) return [];
|
|
189
|
+
const back = [{ t: "move_node", id: op.id, parent: node.parent, order: node.order }];
|
|
190
|
+
if (node.parent === null) back.push({ t: "reorder_sections", order: [...doc.sections] });
|
|
191
|
+
return back;
|
|
192
|
+
}
|
|
193
|
+
case "set_props": {
|
|
194
|
+
const node = doc.nodes[op.id];
|
|
195
|
+
if (!node) return [];
|
|
196
|
+
const prev = {};
|
|
197
|
+
for (const k of Object.keys(op.patch)) prev[k] = node.props[k];
|
|
198
|
+
return [{ t: "set_props", id: op.id, patch: prev }];
|
|
199
|
+
}
|
|
200
|
+
case "set_style": {
|
|
201
|
+
const node = doc.nodes[op.id];
|
|
202
|
+
if (!node) return [];
|
|
203
|
+
const prevBp = node.style[op.breakpoint] ?? {};
|
|
204
|
+
const prev = {};
|
|
205
|
+
for (const k of Object.keys(op.patch)) prev[k] = prevBp[k];
|
|
206
|
+
return [{ t: "set_style", id: op.id, breakpoint: op.breakpoint, patch: prev }];
|
|
207
|
+
}
|
|
208
|
+
case "set_meta":
|
|
209
|
+
return [{ t: "set_meta", patch: pick(doc.meta, Object.keys(op.patch)) }];
|
|
210
|
+
case "set_theme":
|
|
211
|
+
return [{ t: "set_theme", patch: pick(doc.theme, Object.keys(op.patch)) }];
|
|
212
|
+
case "reorder_sections":
|
|
213
|
+
return [{ t: "reorder_sections", order: [...doc.sections] }];
|
|
214
|
+
default:
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function pick(obj, keys) {
|
|
219
|
+
const out = {};
|
|
220
|
+
for (const k of keys) out[k] = obj[k];
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/render/css.ts
|
|
225
|
+
var selectorFor = (id) => `[data-cms="${id}"]`;
|
|
226
|
+
function lengthToCss(len) {
|
|
227
|
+
return `${len.value}${len.unit}`;
|
|
228
|
+
}
|
|
229
|
+
function sizeToCss(size) {
|
|
230
|
+
if (size === "fill") return "100%";
|
|
231
|
+
if (size === "hug") return "auto";
|
|
232
|
+
return lengthToCss(size);
|
|
233
|
+
}
|
|
234
|
+
var ALIGN = {
|
|
235
|
+
start: "flex-start",
|
|
236
|
+
center: "center",
|
|
237
|
+
end: "flex-end",
|
|
238
|
+
stretch: "stretch"
|
|
239
|
+
};
|
|
240
|
+
var JUSTIFY = {
|
|
241
|
+
start: "flex-start",
|
|
242
|
+
center: "center",
|
|
243
|
+
end: "flex-end",
|
|
244
|
+
between: "space-between",
|
|
245
|
+
around: "space-around"
|
|
246
|
+
};
|
|
247
|
+
function styleDecls(style) {
|
|
248
|
+
const d = {};
|
|
249
|
+
if (style.padding) d["padding"] = lengthToCss(style.padding);
|
|
250
|
+
if (style.margin) d["margin"] = lengthToCss(style.margin);
|
|
251
|
+
if (style.radius) d["border-radius"] = lengthToCss(style.radius);
|
|
252
|
+
if (style.background !== void 0) d["background"] = style.background;
|
|
253
|
+
if (style.color !== void 0) d["color"] = style.color;
|
|
254
|
+
if (style.opacity !== void 0) d["opacity"] = String(style.opacity);
|
|
255
|
+
if (style.fontFamily !== void 0) d["font-family"] = style.fontFamily;
|
|
256
|
+
if (style.fontSize) d["font-size"] = lengthToCss(style.fontSize);
|
|
257
|
+
if (style.fontWeight !== void 0) d["font-weight"] = String(style.fontWeight);
|
|
258
|
+
if (style.lineHeight !== void 0) d["line-height"] = String(style.lineHeight);
|
|
259
|
+
if (style.textAlign !== void 0) d["text-align"] = style.textAlign;
|
|
260
|
+
if (style.letterSpacing) d["letter-spacing"] = lengthToCss(style.letterSpacing);
|
|
261
|
+
if (style.border !== void 0) d["border"] = style.border;
|
|
262
|
+
if (style.boxShadow !== void 0) d["box-shadow"] = style.boxShadow;
|
|
263
|
+
if (style.transform !== void 0) d["transform"] = style.transform;
|
|
264
|
+
if (style.filter !== void 0) d["filter"] = style.filter;
|
|
265
|
+
if (style.gap) d["gap"] = lengthToCss(style.gap);
|
|
266
|
+
if (style.align !== void 0) d["align-items"] = ALIGN[style.align] ?? style.align;
|
|
267
|
+
if (style.justify !== void 0) d["justify-content"] = JUSTIFY[style.justify] ?? style.justify;
|
|
268
|
+
return d;
|
|
269
|
+
}
|
|
270
|
+
function layoutDecls(node) {
|
|
271
|
+
const d = {};
|
|
272
|
+
if (node.layout === "stack") {
|
|
273
|
+
d["display"] = "flex";
|
|
274
|
+
d["flex-direction"] = node.style.base.direction ?? "column";
|
|
275
|
+
} else if (node.layout === "grid") {
|
|
276
|
+
d["display"] = "grid";
|
|
277
|
+
d["grid-template-columns"] = `repeat(${node.style.base.columns ?? 1}, 1fr)`;
|
|
278
|
+
} else if (node.layout === "free") {
|
|
279
|
+
d["position"] = "relative";
|
|
280
|
+
}
|
|
281
|
+
return d;
|
|
282
|
+
}
|
|
283
|
+
function constraintDecls(c, parentFree) {
|
|
284
|
+
const d = {};
|
|
285
|
+
const transforms = [];
|
|
286
|
+
if (parentFree) {
|
|
287
|
+
d["position"] = "absolute";
|
|
288
|
+
if (c.left) d["left"] = lengthToCss(c.left);
|
|
289
|
+
if (c.right) d["right"] = lengthToCss(c.right);
|
|
290
|
+
if (c.top) d["top"] = lengthToCss(c.top);
|
|
291
|
+
if (c.bottom) d["bottom"] = lengthToCss(c.bottom);
|
|
292
|
+
if (c.centerX) {
|
|
293
|
+
d["left"] = "50%";
|
|
294
|
+
transforms.push("translateX(-50%)");
|
|
295
|
+
}
|
|
296
|
+
if (c.centerY) {
|
|
297
|
+
d["top"] = "50%";
|
|
298
|
+
transforms.push("translateY(-50%)");
|
|
299
|
+
}
|
|
300
|
+
if (transforms.length) d["transform"] = transforms.join(" ");
|
|
301
|
+
}
|
|
302
|
+
if (c.width) d["width"] = sizeToCss(c.width);
|
|
303
|
+
if (c.height) d["height"] = sizeToCss(c.height);
|
|
304
|
+
return d;
|
|
305
|
+
}
|
|
306
|
+
function isParentFree(doc, node) {
|
|
307
|
+
if (node.parent === null) return false;
|
|
308
|
+
const parent = doc.nodes[node.parent];
|
|
309
|
+
return !parent || parent.layout === void 0 || parent.layout === "free";
|
|
310
|
+
}
|
|
311
|
+
function serializeRule(selector, decls, indent) {
|
|
312
|
+
const props = Object.keys(decls).sort();
|
|
313
|
+
if (props.length === 0) return "";
|
|
314
|
+
const body = props.map((p) => `${indent} ${p}: ${decls[p]};`).join("\n");
|
|
315
|
+
return `${indent}${selector} {
|
|
316
|
+
${body}
|
|
317
|
+
${indent}}`;
|
|
318
|
+
}
|
|
319
|
+
function emitDocCss(doc) {
|
|
320
|
+
const breakpointPx = DEFAULT_BREAKPOINTS;
|
|
321
|
+
const blocks = [];
|
|
322
|
+
for (const id of Object.keys(doc.nodes).sort()) {
|
|
323
|
+
const node = doc.nodes[id];
|
|
324
|
+
const selector = selectorFor(id);
|
|
325
|
+
const parentFree = isParentFree(doc, node);
|
|
326
|
+
const base = {
|
|
327
|
+
...layoutDecls(node),
|
|
328
|
+
...node.constraints ? constraintDecls(node.constraints.base, parentFree) : {},
|
|
329
|
+
...styleDecls(node.style.base)
|
|
330
|
+
};
|
|
331
|
+
const baseRule = serializeRule(selector, base, "");
|
|
332
|
+
if (baseRule) blocks.push(baseRule);
|
|
333
|
+
for (const bp of doc.breakpoints) {
|
|
334
|
+
if (bp === "base") continue;
|
|
335
|
+
const px = breakpointPx[bp];
|
|
336
|
+
if (px === void 0) continue;
|
|
337
|
+
const decls = {
|
|
338
|
+
...node.constraints?.[bp] ? constraintDecls(node.constraints[bp], parentFree) : {},
|
|
339
|
+
...node.style[bp] ? styleDecls(node.style[bp]) : {}
|
|
340
|
+
};
|
|
341
|
+
const inner = serializeRule(selector, decls, " ");
|
|
342
|
+
if (inner) blocks.push(`@media (min-width: ${px}px) {
|
|
343
|
+
${inner}
|
|
344
|
+
}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return blocks.join("\n\n") + (blocks.length ? "\n" : "");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { DEFAULT_BREAKPOINTS, childrenOf, descendantIds, emitDocCss, emptyDoc, invert, isBinding, reduce, reduceAll };
|
|
351
|
+
//# sourceMappingURL=chunk-NWH2AJLH.js.map
|
|
352
|
+
//# sourceMappingURL=chunk-NWH2AJLH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/document/types.ts","../src/document/reduce.ts","../src/render/css.ts"],"names":[],"mappings":";AAwBO,SAAS,UAAU,CAAA,EAA0B;AAClD,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAY,MAAM,IAAA,IAAQ,OAAQ,EAAc,KAAA,KAAU,QAAA;AAChF;AAqJO,IAAM,mBAAA,GAA8C;AAAA,EACzD,IAAA,EAAM,CAAA;AAAA,EACN,EAAA,EAAI,GAAA;AAAA,EACJ,EAAA,EAAI;AACN;AAGO,SAAS,QAAA,CAAS,EAAA,EAAY,IAAA,GAAO,GAAA,EAAc;AACxD,EAAA,OAAO;AAAA,IACL,EAAA;AAAA,IACA,GAAA,EAAK,CAAA;AAAA,IACL,MAAM,EAAE,KAAA,EAAO,UAAA,EAAY,IAAA,EAAM,YAAY,QAAA,EAAS;AAAA,IACtD,KAAA,EAAO,EAAE,IAAA,EAAM,SAAA,EAAU;AAAA,IACzB,WAAA,EAAa,CAAC,MAAA,EAAQ,IAAA,EAAM,IAAI,CAAA;AAAA,IAChC,UAAU,EAAC;AAAA,IACX,OAAO;AAAC,GACV;AACF;;;AC9KO,SAAS,UAAA,CAAW,KAAc,MAAA,EAA+B;AACtE,EAAA,IAAI,WAAW,IAAA,EAAM;AACnB,IAAA,OAAO,GAAA,CAAI,QAAA,CAAS,GAAA,CAAI,CAAC,OAAO,GAAA,CAAI,KAAA,CAAM,EAAE,CAAC,EAAE,MAAA,CAAO,CAAC,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GAAgC;AAAA,QACpC,GAAI,IAAA,CAAK,WAAA,GAAc,EAAE,CAAA,GAAI,eAAA,CAAgB,IAAA,CAAK,WAAA,CAAY,EAAE,CAAA,EAAI,UAAU,CAAA,GAAI,EAAC;AAAA,QACnF,GAAI,IAAA,CAAK,KAAA,CAAM,EAAE,CAAA,GAAI,UAAA,CAAW,IAAA,CAAK,KAAA,CAAM,EAAE,CAAE,CAAA,GAAI;AAAC,OACtD;AACA,MAAA,MAAM,KAAA,GAAQ,aAAA,CAAc,QAAA,EAAU,KAAA,EAAO,IAAI,CAAA;AACjD,MAAA,IAAI,KAAA,EAAO,MAAA,CAAO,IAAA,CAAK,CAAA,mBAAA,EAAsB,EAAE,CAAA;AAAA,EAAU,KAAK;AAAA,CAAA,CAAK,CAAA;AAAA,IACrE;AAAA,EACF;AAEA,EAAA,OAAO,OAAO,IAAA,CAAK,MAAM,CAAA,IAAK,MAAA,CAAO,SAAS,IAAA,GAAO,EAAA,CAAA;AACvD","file":"chunk-NWH2AJLH.js","sourcesContent":["/**\n * Stages document model — see `fancy-ui/docs/fancy-cms.md` §4.\n *\n * A page is a vertical stack of full-bleed **sections**; inside each, **layers**\n * are positioned by constraints (free + bold stays responsive), with stack/grid\n * containers where structure is wanted. Nodes live in a **flat map** keyed by id\n * (Figma-style) so ops target a stable identity and collab merges stay clean.\n */\n\nexport type NodeId = string;\n\nexport type ScrollMode = \"snap\" | \"smooth\";\n\n/** Ordered, mobile-first. Convention: `\"base\" | \"md\" | \"lg\"`. */\nexport type Breakpoint = string;\n\nexport type Json = string | number | boolean | null | Json[] | { [key: string]: Json };\n\n/** A literal value OR a binding into the page's data context (`{ $bind: \"profile.coins\" }`). */\nexport interface Binding {\n $bind: string;\n}\nexport type Bound<T> = T | Binding;\n\nexport function isBinding(v: unknown): v is Binding {\n return typeof v === \"object\" && v !== null && typeof (v as Binding).$bind === \"string\";\n}\n\n// ── Sizing ────────────────────────────────────────────────────────────────\n\nexport type LengthUnit = \"px\" | \"%\" | \"vw\" | \"vh\" | \"rem\" | \"fr\";\nexport interface Length {\n value: number;\n unit: LengthUnit;\n}\nexport type SizeMode = Length | \"fill\" | \"hug\";\n\nexport interface Constraints {\n /** Pinned offsets within a `free` parent (null = unpinned). */\n left?: Length | null;\n right?: Length | null;\n top?: Length | null;\n bottom?: Length | null;\n centerX?: boolean;\n centerY?: boolean;\n width: SizeMode;\n height: SizeMode;\n}\n\nexport type LayoutMode = \"free\" | \"stack\" | \"grid\";\n\n// ── Style (compiles deterministically to CSS in both emitters) ──────────────\n\nexport interface StyleProps {\n // box\n padding?: Length;\n margin?: Length;\n radius?: Length;\n // color / surface\n background?: string; // color | gradient | url(...)\n color?: string;\n opacity?: number;\n // typography\n fontFamily?: string;\n fontSize?: Length;\n fontWeight?: number;\n lineHeight?: number;\n textAlign?: \"left\" | \"center\" | \"right\" | \"justify\";\n letterSpacing?: Length;\n // border / shadow / effects (static)\n border?: string;\n boxShadow?: string;\n transform?: string;\n filter?: string;\n // container knobs (when layout = stack | grid)\n gap?: Length;\n direction?: \"row\" | \"column\";\n columns?: number;\n align?: \"start\" | \"center\" | \"end\" | \"stretch\";\n justify?: \"start\" | \"center\" | \"end\" | \"between\" | \"around\";\n}\n\n/** Per-breakpoint overrides; `base` is required, others cascade mobile-first. */\nexport type PerBreakpoint<T> = { base: T } & Partial<Record<Breakpoint, Partial<T>>>;\n\n// ── Animation (typed for Phase 2; ignored by the static CSS emitter) ────────\n\nexport type AnimDriver = \"enter\" | \"scroll\" | \"loop\" | \"hover\" | \"click\" | \"drag\";\nexport interface Keyframe {\n at: number; // 0..1\n props: Record<string, number | string>;\n}\nexport interface Anim {\n id: string;\n driver: AnimDriver;\n keyframes: Keyframe[];\n range?: { start: number; end: number };\n ease?: string;\n duration?: number;\n delay?: number;\n stagger?: number;\n once?: boolean;\n emit?: \"css\" | \"js\";\n}\n\n// ── Actions (typed for Phase 3/4) ───────────────────────────────────────────\n\nexport type ActionEvent = \"click\" | \"submit\" | \"change\" | \"load\" | \"timer\" | \"scroll-into\" | \"hover\";\nexport type ActionHandler =\n | { kind: \"navigate\"; href: Bound<string> }\n | { kind: \"submitForm\"; endpoint: string; method?: \"post\" | \"put\" }\n | { kind: \"mutate\"; target: string; value: Bound<Json> }\n | { kind: \"callEndpoint\"; endpoint: string; method?: string }\n | { kind: \"runFlow\"; flow: string }\n | { kind: \"openModal\"; node: NodeId }\n | { kind: \"openDrawer\"; node: NodeId }\n | { kind: \"playTimeline\"; section: NodeId }\n | { kind: \"toggleNode\"; node: NodeId };\nexport interface Action {\n on: ActionEvent;\n do: ActionHandler;\n}\n\n// ── Nodes & document ────────────────────────────────────────────────────────\n\nexport interface Node {\n id: NodeId;\n /** Addon key: `section | text | image | shape | stack | grid | frame | <addon>`. */\n type: string;\n /** `null` = a top-level section. */\n parent: NodeId | null;\n /** Fractional index — collab-safe ordering among siblings. */\n order: string;\n /** Addon-specific props; any value may be a {@link Binding}. */\n props: Record<string, Bound<Json>>;\n /** How this node arranges its children. */\n layout?: LayoutMode;\n /** How this node positions itself within its parent. */\n constraints?: PerBreakpoint<Constraints>;\n style: PerBreakpoint<StyleProps>;\n animations?: Anim[];\n actions?: Action[];\n /** Repeater: render this node once per item of a bound array. */\n repeat?: { each: Binding; as: string };\n /** Derived from the addon manifest — interactive/3rd-party ⇒ hydration island. */\n island?: boolean;\n}\n\nexport interface ThemeTokens {\n name?: string;\n [key: string]: Json | undefined;\n}\n\nexport interface PageMeta {\n title: string;\n slug: string;\n scrollMode: ScrollMode;\n seo?: Record<string, string>;\n}\n\nexport interface PageDoc {\n id: string;\n /** Op counter — collab ordering + revision checkpoints. */\n seq: number;\n meta: PageMeta;\n theme: ThemeTokens;\n /** Ordered, mobile-first. */\n breakpoints: Breakpoint[];\n /** Top-level section order. */\n sections: NodeId[];\n /** Flat map — not a nested tree. */\n nodes: Record<NodeId, Node>;\n}\n\n/** Default breakpoint → min-width (px) map. `base` has no media query. */\nexport const DEFAULT_BREAKPOINTS: Record<string, number> = {\n base: 0,\n md: 768,\n lg: 1024,\n};\n\n/** A minimal empty document. */\nexport function emptyDoc(id: string, slug = \"/\"): PageDoc {\n return {\n id,\n seq: 0,\n meta: { title: \"Untitled\", slug, scrollMode: \"smooth\" },\n theme: { name: \"default\" },\n breakpoints: [\"base\", \"md\", \"lg\"],\n sections: [],\n nodes: {},\n };\n}\n","/**\n * The pure, total reducer. `reduce(doc, op)` returns a new document; an invalid\n * op is a **logged no-op** (returns the same doc, `seq` unchanged). That single\n * property is what makes undo, revisions, collaboration, and agent edits all\n * flow through one spine.\n *\n * Ordering: top-level order is the canonical `sections` array; child order is\n * the fractional `order` field among siblings (see `fractional.ts`).\n */\nimport type { Action, Node, NodeId, PageDoc, StyleProps } from \"./types\";\nimport type { PageOp } from \"./ops\";\n\nexport interface ReduceOptions {\n /** Called when an op can't apply. Default: silent. */\n onInvalid?: (op: PageOp, reason: string) => void;\n}\n\n/** Children of a node (or top-level when `parent` is null), in order. */\nexport function childrenOf(doc: PageDoc, parent: NodeId | null): Node[] {\n if (parent === null) {\n return doc.sections.map((id) => doc.nodes[id]).filter((n): n is Node => Boolean(n));\n }\n const out: Node[] = [];\n for (const id of Object.keys(doc.nodes)) {\n const n = doc.nodes[id]!;\n if (n.parent === parent) out.push(n);\n }\n out.sort((a, b) => (a.order < b.order ? -1 : a.order > b.order ? 1 : 0));\n return out;\n}\n\n/** Every transitive descendant id of `id` (excludes `id`). */\nexport function descendantIds(doc: PageDoc, id: NodeId): NodeId[] {\n const out: NodeId[] = [];\n const stack: NodeId[] = [id];\n while (stack.length) {\n const current = stack.pop()!;\n for (const childId of Object.keys(doc.nodes)) {\n const n = doc.nodes[childId]!;\n if (n.parent === current) {\n out.push(childId);\n stack.push(childId);\n }\n }\n }\n return out;\n}\n\nfunction patchNode(doc: PageDoc, id: NodeId, patch: Partial<Node>): PageDoc {\n const node = doc.nodes[id]!;\n return {\n ...doc,\n nodes: { ...doc.nodes, [id]: { ...node, ...patch } },\n seq: doc.seq + 1,\n };\n}\n\nexport function reduce(doc: PageDoc, op: PageOp, opts: ReduceOptions = {}): PageDoc {\n const invalid = (reason: string): PageDoc => {\n opts.onInvalid?.(op, reason);\n return doc;\n };\n\n switch (op.t) {\n case \"insert_node\": {\n if (doc.nodes[op.node.id]) return invalid(\"node id already exists\");\n if (op.node.parent !== null && !doc.nodes[op.node.parent]) return invalid(\"parent not found\");\n return {\n ...doc,\n nodes: { ...doc.nodes, [op.node.id]: op.node },\n sections: op.node.parent === null ? [...doc.sections, op.node.id] : doc.sections,\n seq: doc.seq + 1,\n };\n }\n\n case \"remove_node\": {\n if (!doc.nodes[op.id]) return invalid(\"node not found\");\n const dead = new Set<NodeId>([op.id, ...descendantIds(doc, op.id)]);\n const nodes: Record<NodeId, Node> = {};\n for (const id of Object.keys(doc.nodes)) {\n if (!dead.has(id)) nodes[id] = doc.nodes[id]!;\n }\n return {\n ...doc,\n nodes,\n sections: doc.sections.filter((s) => !dead.has(s)),\n seq: doc.seq + 1,\n };\n }\n\n case \"move_node\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n if (op.parent === op.id) return invalid(\"cannot parent a node to itself\");\n if (op.parent !== null && !doc.nodes[op.parent]) return invalid(\"new parent not found\");\n if (op.parent !== null && descendantIds(doc, op.id).includes(op.parent)) {\n return invalid(\"move would create a cycle\");\n }\n const wasTop = node.parent === null;\n const nowTop = op.parent === null;\n let sections = doc.sections;\n if (wasTop && !nowTop) sections = sections.filter((s) => s !== op.id);\n else if (!wasTop && nowTop) sections = [...sections, op.id];\n return {\n ...doc,\n nodes: { ...doc.nodes, [op.id]: { ...node, parent: op.parent, order: op.order } },\n sections,\n seq: doc.seq + 1,\n };\n }\n\n case \"set_props\": {\n if (!doc.nodes[op.id]) return invalid(\"node not found\");\n return patchNode(doc, op.id, {\n props: { ...doc.nodes[op.id]!.props, ...op.patch } as unknown as Node[\"props\"],\n });\n }\n\n case \"set_style\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const prev = node.style[op.breakpoint] ?? {};\n return patchNode(doc, op.id, {\n style: { ...node.style, [op.breakpoint]: { ...prev, ...op.patch } } as Node[\"style\"],\n });\n }\n\n case \"set_constraints\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const base = node.constraints ?? { base: { width: \"hug\", height: \"hug\" } };\n const prev = base[op.breakpoint] ?? {};\n return patchNode(doc, op.id, {\n constraints: { ...base, [op.breakpoint]: { ...prev, ...op.patch } } as Node[\"constraints\"],\n });\n }\n\n case \"set_animation\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const list = node.animations ?? [];\n const idx = list.findIndex((a) => a.id === op.anim.id);\n return patchNode(doc, op.id, {\n animations: idx >= 0 ? list.map((a, i) => (i === idx ? op.anim : a)) : [...list, op.anim],\n });\n }\n\n case \"remove_animation\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n return patchNode(doc, op.id, {\n animations: (node.animations ?? []).filter((a) => a.id !== op.animId),\n });\n }\n\n case \"set_action\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const list = node.actions ?? [];\n let actions: Action[];\n if (op.action === null) actions = list.filter((_, i) => i !== op.index);\n else if (op.index >= list.length) actions = [...list, op.action];\n else actions = list.map((a, i) => (i === op.index ? op.action! : a));\n return patchNode(doc, op.id, { actions });\n }\n\n case \"set_meta\":\n return { ...doc, meta: { ...doc.meta, ...op.patch }, seq: doc.seq + 1 };\n\n case \"set_theme\":\n return { ...doc, theme: { ...doc.theme, ...op.patch }, seq: doc.seq + 1 };\n\n case \"reorder_sections\": {\n const current = new Set(doc.sections);\n const same =\n op.order.length === doc.sections.length && op.order.every((id) => current.has(id));\n if (!same) return invalid(\"reorder must be a permutation of current sections\");\n return { ...doc, sections: [...op.order], seq: doc.seq + 1 };\n }\n\n default:\n return invalid(`unknown op \"${(op as PageOp).t}\"`);\n }\n}\n\n/** Apply a sequence of ops, threading the document. */\nexport function reduceAll(doc: PageDoc, ops: PageOp[], opts?: ReduceOptions): PageDoc {\n return ops.reduce((d, op) => reduce(d, op, opts), doc);\n}\n\n/**\n * Inverse op(s) for undo, computed against the **pre-op** document. Structural\n * ops invert cleanly; merge-style ops (`set_props`/`set_style`/`set_constraints`)\n * restore the previous values of the touched keys (keys that did not previously\n * exist can't be deleted via a merge — a known Phase-0 limitation).\n */\nexport function invert(doc: PageDoc, op: PageOp): PageOp[] {\n switch (op.t) {\n case \"insert_node\":\n return [{ t: \"remove_node\", id: op.node.id }];\n\n case \"remove_node\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n // Re-insert the subtree parent-first, then restore section order.\n const ids = [op.id, ...descendantIds(doc, op.id)];\n const inserts: PageOp[] = ids.map((id) => ({ t: \"insert_node\", node: doc.nodes[id]! }));\n if (node.parent === null) inserts.push({ t: \"reorder_sections\", order: [...doc.sections] });\n return inserts;\n }\n\n case \"move_node\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const back: PageOp[] = [{ t: \"move_node\", id: op.id, parent: node.parent, order: node.order }];\n if (node.parent === null) back.push({ t: \"reorder_sections\", order: [...doc.sections] });\n return back;\n }\n\n case \"set_props\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const prev: Record<string, unknown> = {};\n for (const k of Object.keys(op.patch)) prev[k] = node.props[k];\n return [{ t: \"set_props\", id: op.id, patch: prev }];\n }\n\n case \"set_style\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const prevBp = (node.style[op.breakpoint] ?? {}) as Record<string, unknown>;\n const prev: Partial<StyleProps> = {};\n for (const k of Object.keys(op.patch)) (prev as Record<string, unknown>)[k] = prevBp[k];\n return [{ t: \"set_style\", id: op.id, breakpoint: op.breakpoint, patch: prev }];\n }\n\n case \"set_meta\":\n return [{ t: \"set_meta\", patch: pick(doc.meta, Object.keys(op.patch)) }];\n\n case \"set_theme\":\n return [{ t: \"set_theme\", patch: pick(doc.theme, Object.keys(op.patch)) }];\n\n case \"reorder_sections\":\n return [{ t: \"reorder_sections\", order: [...doc.sections] }];\n\n default:\n return [];\n }\n}\n\nfunction pick<T extends object>(obj: T, keys: string[]): Partial<T> {\n const out: Partial<T> = {};\n for (const k of keys) (out as Record<string, unknown>)[k] = (obj as Record<string, unknown>)[k];\n return out;\n}\n","/**\n * The JS style → CSS emitter (one half of the dual-emitter pair; the PHP\n * `particle-academy/fancy-cms` mirrors it byte-for-byte). Output is\n * **deterministic**: declarations are sorted, selectors and media blocks use a\n * fixed format, and nodes are emitted in sorted-id order — so the parity harness\n * can diff the two engines' CSS exactly.\n *\n * Phase 0 covers the static subset (layout / constraints / style). Motion lands\n * in Phase 2.\n */\nimport {\n DEFAULT_BREAKPOINTS,\n type Constraints,\n type Length,\n type Node,\n type PageDoc,\n type SizeMode,\n type StyleProps,\n} from \"../document/types\";\n\nconst selectorFor = (id: string): string => `[data-cms=\"${id}\"]`;\n\nfunction lengthToCss(len: Length): string {\n return `${len.value}${len.unit}`;\n}\n\nfunction sizeToCss(size: SizeMode): string {\n if (size === \"fill\") return \"100%\";\n if (size === \"hug\") return \"auto\";\n return lengthToCss(size);\n}\n\nconst ALIGN: Record<string, string> = {\n start: \"flex-start\",\n center: \"center\",\n end: \"flex-end\",\n stretch: \"stretch\",\n};\nconst JUSTIFY: Record<string, string> = {\n start: \"flex-start\",\n center: \"center\",\n end: \"flex-end\",\n between: \"space-between\",\n around: \"space-around\",\n};\n\n/** Map StyleProps → CSS declarations (property → value). */\nfunction styleDecls(style: Partial<StyleProps>): Record<string, string> {\n const d: Record<string, string> = {};\n if (style.padding) d[\"padding\"] = lengthToCss(style.padding);\n if (style.margin) d[\"margin\"] = lengthToCss(style.margin);\n if (style.radius) d[\"border-radius\"] = lengthToCss(style.radius);\n if (style.background !== undefined) d[\"background\"] = style.background;\n if (style.color !== undefined) d[\"color\"] = style.color;\n if (style.opacity !== undefined) d[\"opacity\"] = String(style.opacity);\n if (style.fontFamily !== undefined) d[\"font-family\"] = style.fontFamily;\n if (style.fontSize) d[\"font-size\"] = lengthToCss(style.fontSize);\n if (style.fontWeight !== undefined) d[\"font-weight\"] = String(style.fontWeight);\n if (style.lineHeight !== undefined) d[\"line-height\"] = String(style.lineHeight);\n if (style.textAlign !== undefined) d[\"text-align\"] = style.textAlign;\n if (style.letterSpacing) d[\"letter-spacing\"] = lengthToCss(style.letterSpacing);\n if (style.border !== undefined) d[\"border\"] = style.border;\n if (style.boxShadow !== undefined) d[\"box-shadow\"] = style.boxShadow;\n if (style.transform !== undefined) d[\"transform\"] = style.transform;\n if (style.filter !== undefined) d[\"filter\"] = style.filter;\n if (style.gap) d[\"gap\"] = lengthToCss(style.gap);\n if (style.align !== undefined) d[\"align-items\"] = ALIGN[style.align] ?? style.align;\n if (style.justify !== undefined) d[\"justify-content\"] = JUSTIFY[style.justify] ?? style.justify;\n return d;\n}\n\n/** Container behaviour from `node.layout`. */\nfunction layoutDecls(node: Node): Record<string, string> {\n const d: Record<string, string> = {};\n if (node.layout === \"stack\") {\n d[\"display\"] = \"flex\";\n d[\"flex-direction\"] = node.style.base.direction ?? \"column\";\n } else if (node.layout === \"grid\") {\n d[\"display\"] = \"grid\";\n d[\"grid-template-columns\"] = `repeat(${node.style.base.columns ?? 1}, 1fr)`;\n } else if (node.layout === \"free\") {\n d[\"position\"] = \"relative\";\n }\n return d;\n}\n\n/** Self-positioning from constraints (absolute pins only inside a `free` parent). */\nfunction constraintDecls(c: Partial<Constraints>, parentFree: boolean): Record<string, string> {\n const d: Record<string, string> = {};\n const transforms: string[] = [];\n if (parentFree) {\n d[\"position\"] = \"absolute\";\n if (c.left) d[\"left\"] = lengthToCss(c.left);\n if (c.right) d[\"right\"] = lengthToCss(c.right);\n if (c.top) d[\"top\"] = lengthToCss(c.top);\n if (c.bottom) d[\"bottom\"] = lengthToCss(c.bottom);\n if (c.centerX) {\n d[\"left\"] = \"50%\";\n transforms.push(\"translateX(-50%)\");\n }\n if (c.centerY) {\n d[\"top\"] = \"50%\";\n transforms.push(\"translateY(-50%)\");\n }\n if (transforms.length) d[\"transform\"] = transforms.join(\" \");\n }\n if (c.width) d[\"width\"] = sizeToCss(c.width);\n if (c.height) d[\"height\"] = sizeToCss(c.height);\n return d;\n}\n\nfunction isParentFree(doc: PageDoc, node: Node): boolean {\n if (node.parent === null) return false; // sections stack in the page flow\n const parent = doc.nodes[node.parent];\n return !parent || parent.layout === undefined || parent.layout === \"free\";\n}\n\nfunction serializeRule(selector: string, decls: Record<string, string>, indent: string): string {\n const props = Object.keys(decls).sort();\n if (props.length === 0) return \"\";\n const body = props.map((p) => `${indent} ${p}: ${decls[p]};`).join(\"\\n\");\n return `${indent}${selector} {\\n${body}\\n${indent}}`;\n}\n\n/** Emit the full stylesheet for a document. Deterministic. */\nexport function emitDocCss(doc: PageDoc): string {\n const breakpointPx = DEFAULT_BREAKPOINTS;\n const blocks: string[] = [];\n\n for (const id of Object.keys(doc.nodes).sort()) {\n const node = doc.nodes[id]!;\n const selector = selectorFor(id);\n const parentFree = isParentFree(doc, node);\n\n // base = style.base + layout + constraints.base\n const base: Record<string, string> = {\n ...layoutDecls(node),\n ...(node.constraints ? constraintDecls(node.constraints.base, parentFree) : {}),\n ...styleDecls(node.style.base),\n };\n const baseRule = serializeRule(selector, base, \"\");\n if (baseRule) blocks.push(baseRule);\n\n // per-breakpoint overrides (mobile-first, in doc order, skipping base)\n for (const bp of doc.breakpoints) {\n if (bp === \"base\") continue;\n const px = breakpointPx[bp];\n if (px === undefined) continue;\n const decls: Record<string, string> = {\n ...(node.constraints?.[bp] ? constraintDecls(node.constraints[bp]!, parentFree) : {}),\n ...(node.style[bp] ? styleDecls(node.style[bp]!) : {}),\n };\n const inner = serializeRule(selector, decls, \" \");\n if (inner) blocks.push(`@media (min-width: ${px}px) {\\n${inner}\\n}`);\n }\n }\n\n return blocks.join(\"\\n\\n\") + (blocks.length ? \"\\n\" : \"\");\n}\n"]}
|