mosaic-headless 1.34.9 → 1.36.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.
Files changed (37) hide show
  1. package/SKILL.md +96 -58
  2. package/assets/templates/platforms/claude-ai.json +1 -1
  3. package/assets/templates/platforms/claude-code.json +1 -1
  4. package/assets/templates/platforms/codex-cli.json +1 -1
  5. package/assets/templates/platforms/copilot.json +1 -1
  6. package/assets/templates/platforms/gemini-cli.json +1 -1
  7. package/data/component-wall-verification.csv +2 -1
  8. package/data/data-class-hierarchy.csv +6 -1
  9. package/data/default-children.csv +2 -0
  10. package/data/form-surface-verification.csv +8 -3
  11. package/data/interaction-types.csv +1 -1
  12. package/data/interaction-verification.csv +4 -0
  13. package/data/node-properties.csv +15 -10
  14. package/data/node-types.csv +7 -2
  15. package/data/node-verification.csv +7 -2
  16. package/data/placement-rules.csv +7 -2
  17. package/data/style-properties.csv +4 -4
  18. package/data/style-state-verification.csv +16 -9
  19. package/data/style-states.csv +11 -8
  20. package/data/tutorial-recipes-verification.csv +17 -0
  21. package/package.json +1 -1
  22. package/references/design-system.md +14 -0
  23. package/references/failure-modes.md +12 -4
  24. package/references/interactions.md +91 -48
  25. package/references/placement.md +5 -5
  26. package/references/tutorials.md +57 -0
  27. package/references/upgrading.md +67 -1
  28. package/scripts/check-release.mjs +7 -6
  29. package/sites/_forms.py +53 -11
  30. package/tools/build_page.py +3 -1
  31. package/tools/interactions.py +215 -0
  32. package/tools/probe_accordion.py +1 -1
  33. package/tools/sweep_components.py +1 -1
  34. package/tools/sweep_interactions.py +28 -1
  35. package/tools/sweep_style_states.py +1 -1
  36. package/tools/verify_components.py +57 -2
  37. package/tools/verify_recipes.py +307 -0
@@ -0,0 +1,307 @@
1
+ #!/usr/bin/env python3
2
+ """Build Mosaic's four official tutorials headlessly and drive each one in Chromium.
3
+
4
+ python tools/verify_recipes.py --config c.json --post 292 --slug probe-recipes \
5
+ --csv data/tutorial-recipes-verification.csv
6
+
7
+ https://mosaicbuilder.com/docs/tutorials/ shows four things built with no custom
8
+ code: a dark/light mode switcher, a loading animation, reusable (class-driven)
9
+ animations and an animation loop. Each is a different corner of the interaction
10
+ system, and until the editor's own stored shape was read back (tools/interactions.py)
11
+ none of them could be written headlessly - every animation stored its timing and lost
12
+ its values. This builds all four on one page from tools/interactions.py and checks
13
+ what a visitor gets, not what the payload says:
14
+
15
+ DARK Dark/Light buttons switch the colour collection on the `document` node and
16
+ set a cookie; a pageLoad on `document`, gated on the cookie, re-applies it.
17
+ Asserted: the computed background before, after Dark, after a reload, and
18
+ after Light, plus the cookie each time.
19
+ OVERLAY a fixed full-page div that fades out on pageLoad and ends `display:none`,
20
+ marked hidden in the editor. Asserted: gone, and the page under it clickable.
21
+ REVEAL one elementScrollIntoView interaction on the first section, triggered by a
22
+ universal class, empty target, `children` modifier. Asserted: the second
23
+ section - which carries no interaction of its own - stays hidden until it is
24
+ scrolled to, then reveals.
25
+ LOOP a pageLoad translate that loops, `outOfView` suspend, an Interaction ID, and
26
+ a hover that suspends / resumes it by that ID. Asserted: it moves on its
27
+ own, it holds still while hovered, it moves again on leaving.
28
+
29
+ The Dark mode is created on the theme's first collection if it has none
30
+ (`ensure_mode`), so the run leaves a second mode behind; the first mode stays the
31
+ default and nothing else on the site changes.
32
+ """
33
+ from __future__ import annotations
34
+
35
+ import mosaic_config
36
+ import argparse
37
+ import csv
38
+ import os
39
+ import sys
40
+ import time
41
+ import uuid
42
+
43
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
44
+ import interactions as ix # noqa: E402
45
+ from build_page import Surface # noqa: E402
46
+ from build_site import bind_page, build_page_document, build_shell, commit # noqa: E402
47
+ from sweep_node_types import Client, unwrap # noqa: E402
48
+
49
+ NS = uuid.UUID("6d6f7361-6963-4865-6164-6c657373ff0b")
50
+
51
+
52
+ def det(name):
53
+ return str(uuid.uuid5(NS, name))
54
+
55
+
56
+ def ensure_mode(client, inst, doc, name):
57
+ """The mode called `name` on the theme's first collection, created if missing."""
58
+ coll = doc["collection"][0]["ID"]
59
+ for m in doc.get("collectionMode") or []:
60
+ if m.get("parentID") == coll and (m.get("data") or {}).get("name") == name:
61
+ return coll, m["ID"]
62
+ mid = det("mode-" + name)
63
+ commit(client, inst, doc, {"collectionMode": [{"newRevisionRecord": {
64
+ "ID": mid, "parentType": "collection", "parentID": coll, "ordering": "a5",
65
+ "status": "publish", "revision": "", "version": "",
66
+ "data": {"name": name, "icon": ""}}, "originalRevisionRecord": None}]}, "mode")
67
+ return coll, mid
68
+
69
+
70
+ def build(client, cfg, post, slug):
71
+ surface = Surface()
72
+ master, _h, _f = build_shell(client, cfg, {"pages": [], "shell": {}}, surface)
73
+ inst, key = "masterDocumentInstance/%s" % master, "node/master/%s" % master
74
+ doc = unwrap(client.get(inst), "masterDocumentInstance")
75
+ coll, dark = ensure_mode(client, inst, doc, "Dark")
76
+ doc = unwrap(client.get(inst), "masterDocumentInstance")
77
+ light = next(m["ID"] for m in doc["collectionMode"] if m.get("parentID") == coll)
78
+ skin = doc["collectionSkin"][0]["ID"]
79
+
80
+ bg, fg = det("var-bg"), det("var-fg")
81
+ commit(client, inst, doc, {"collectionVariable": [{"newRevisionRecord": {
82
+ "ID": vid, "parentType": "collection", "parentID": coll, "ordering": "a0",
83
+ "status": "publish", "revision": "", "version": "",
84
+ "data": {"name": cp.lstrip("-"), "type": "color", "customProperty": cp,
85
+ "skinsData": {skin: {light: {"value": lv}, dark: {"value": dv}}}}},
86
+ "originalRevisionRecord": None}
87
+ for vid, cp, lv, dv in ((bg, "--rx-bg", "rgb(250, 250, 245)", "rgb(20, 22, 28)"),
88
+ (fg, "--rx-fg", "rgb(20, 22, 28)", "rgb(240, 240, 235)"))]},
89
+ "variables")
90
+
91
+ sec, child = det("cls-rx-section"), det("cls-rx-child")
92
+ commit(client, inst, doc, {"universalClass": [{"newRevisionRecord": {
93
+ "ID": cid, "parentType": "", "parentID": "", "ordering": "a0", "status": "publish",
94
+ "revision": "", "version": "", "data": {"name": n, "label": n, "states": {}}},
95
+ "originalRevisionRecord": None} for cid, n in ((sec, "rx-section"), (child, "rx-child"))]},
96
+ "classes")
97
+
98
+ document = next(n for n in doc[key] if n["type"] == "document")
99
+ to_doc = ix.element(document["ID"])
100
+ gate = [ix.on("pageLoad", [ix.mode_switch(coll, dark, to_doc)],
101
+ conditions=[ix.cookie_is("rx-mode", "dark")])]
102
+ commit(client, inst, doc, {key: [{"newRevisionRecord": dict(
103
+ document, data=dict(document.get("data") or {}, interactions=gate)),
104
+ "originalRevisionRecord": document}]}, "document gate")
105
+
106
+ def button(attr, label, mode, value):
107
+ return {"type": "div", "data": {"attrID": attr, "interactions": [ix.on("click", [
108
+ ix.mode_switch(coll, mode, to_doc), ix.set_cookie("rx-mode", value)])]},
109
+ "style": {"&": {"_": {"paddingTop": "8px", "paddingBottom": "8px"}}},
110
+ "children": [{"type": "text", "data": {"tagName": "p"}, "text": label}]}
111
+
112
+ def section(attr, interactions=None):
113
+ data = {"attrID": attr, "style": {"universalClasses": {sec: sec}}}
114
+ if interactions:
115
+ data["interactions"] = interactions
116
+ return {"type": "div", "data": data,
117
+ "style": {"&": {"_": {"paddingTop": "40px", "marginBottom": "1200px"}}},
118
+ "children": [{"type": "div", "data": {
119
+ "attrID": "%s-c%d" % (attr, i), "style": {"universalClasses": {child: child}}},
120
+ "style": {"&": {"_": {"height": "50px", "marginBottom": "8px",
121
+ "backgroundColor": "rgb(9, 99, 199)"}}}}
122
+ for i in (1, 2)]}
123
+
124
+ reveal = [ix.on("elementScrollIntoView",
125
+ [ix.tween([("translateY", "40px", "0px"), ("opacity", "0%", "100%")],
126
+ children=ix.class_target(child))],
127
+ trigger=ix.class_target(sec), slot="in")]
128
+ overlay = [ix.on("pageLoad", [ix.tween([("opacity", "100%", "0%")], 400),
129
+ ix.hide_at_end(400)])]
130
+ hover = ix.on("hover", [ix.suspend("rx_loop")], slot="in")
131
+ hover["hoverOptions"]["actionSlots"]["out"] = {"actions": [ix.resume("rx_loop")]}
132
+ loop = [ix.on("pageLoad", [ix.tween([("translateX", "0px", "200px")], 4000)],
133
+ ix_id="rx_loop", loop=True, out_of_view="1"), hover]
134
+
135
+ panel_id, bar_id = str(uuid.uuid4()), str(uuid.uuid4())
136
+ toggle = ix.on("click", [ix.display(start="flex", target=ix.element(panel_id)),
137
+ ix.tween([("translateX", "100%", "0%")], 400,
138
+ target=ix.element(panel_id))], slot="odd")
139
+ ix.add_slot(toggle, "even", [ix.tween([("translateX", "0%", "100%")], 400,
140
+ target=ix.element(panel_id)),
141
+ ix.display(end="none", duration=400,
142
+ target=ix.element(panel_id))])
143
+ progress = [ix.on("scrollIntoView", [ix.tween([("translateX", "-100%", "0%")], 100,
144
+ progress=True, easing="linear",
145
+ target=ix.element(bar_id))])]
146
+
147
+ tree = {"type": "div", "data": {"attrID": "rx-root"},
148
+ "style": {"&": {"_": {"backgroundColor": {"var": bg}, "color": {"var": fg},
149
+ "paddingTop": "20px"}}},
150
+ "children": [
151
+ {"type": "div", "data": {"attrID": "rx-overlay", "hidden": True,
152
+ "interactions": overlay},
153
+ "style": {"&": {"_": {"position": "fixed", "zIndex": "100", "top": "0px",
154
+ "right": "0px", "bottom": "0px", "left": "0px",
155
+ "backgroundColor": "rgb(255, 255, 255)"}}}},
156
+ button("rx-dark", "Dark", dark, "dark"),
157
+ button("rx-light", "Light", light, "light"),
158
+ {"type": "div", "data": {"attrID": "rx-loop", "interactions": loop},
159
+ "style": {"&": {"_": {"width": "60px", "height": "60px",
160
+ "backgroundColor": "rgb(200, 60, 40)"}}}},
161
+ {"type": "div", "data": {"attrID": "rx-oc-toggle", "interactions": [toggle]},
162
+ "style": {"&": {"_": {"width": "40px", "height": "40px",
163
+ "backgroundColor": "rgb(40, 40, 40)"}}}},
164
+ {"type": "div", "nodeID": panel_id, "data": {"attrID": "rx-oc-panel"},
165
+ "style": {"&": {"_": {"display": "none", "position": "fixed", "zIndex": "50",
166
+ "top": "0px", "right": "0px", "bottom": "0px",
167
+ "width": "300px",
168
+ "backgroundColor": "rgb(240, 240, 240)"}}}},
169
+ {"type": "div", "data": {"attrID": "rx-bar-outer"},
170
+ "style": {"&": {"_": {"position": "sticky", "top": "0px", "zIndex": "40",
171
+ "overflow": "hidden", "height": "8px"}}},
172
+ "children": [{"type": "div", "nodeID": bar_id, "data": {"attrID": "rx-bar"},
173
+ "style": {"&": {"_": {"height": "8px", "width": "100%",
174
+ "backgroundColor": "rgb(9, 99, 199)"}}}}]},
175
+ {"type": "div", "data": {"attrID": "rx-article", "interactions": progress},
176
+ "style": {"&": {"_": {"height": "2400px"}}}},
177
+ {"type": "div", "data": {"attrID": "rx-gap"},
178
+ "style": {"&": {"_": {"height": "1200px"}}}},
179
+ section("rx-s1", reveal), section("rx-s2")]}
180
+ template = bind_page(client, cfg, master, slug, post)
181
+ build_page_document(client, cfg, master, template, tree, surface)
182
+ return master
183
+
184
+
185
+ def drive(url):
186
+ from playwright.sync_api import sync_playwright
187
+ rows = []
188
+
189
+ def row(recipe, check, ok, evidence):
190
+ rows.append([recipe, check, "PASS" if ok else "FAIL", evidence])
191
+ print(" %-8s %-34s %-4s %s" % (recipe, check, "PASS" if ok else "FAIL", evidence))
192
+
193
+ css = ("id => { const s = getComputedStyle(document.getElementById(id));"
194
+ " return {bg: s.backgroundColor, op: s.opacity, d: s.display, tr: s.translate}; }")
195
+ with sync_playwright() as pw:
196
+ b = pw.chromium.launch()
197
+ page = b.new_page(viewport={"width": 1280, "height": 800})
198
+ bust = lambda: "%s?_v=%d" % (url, time.time() * 1000) # noqa: E731
199
+ page.goto(bust(), wait_until="networkidle")
200
+ page.wait_for_timeout(900)
201
+ cookie = lambda: next((c["value"] for c in page.context.cookies() # noqa: E731
202
+ if c["name"] == "rx-mode"), None)
203
+
204
+ bg0 = page.evaluate(css, "rx-root")["bg"]
205
+ row("OVERLAY", "faded and display:none after load",
206
+ page.evaluate(css, "rx-overlay")["d"] == "none", str(page.evaluate(css, "rx-overlay")))
207
+ try:
208
+ page.click("#rx-dark", timeout=3000)
209
+ clickable = True
210
+ except Exception as exc: # noqa: BLE001
211
+ clickable, bg0 = False, "%s (%s)" % (bg0, exc.__class__.__name__)
212
+ row("OVERLAY", "page underneath takes a real click", clickable, "clicked #rx-dark")
213
+ page.wait_for_timeout(400)
214
+ bg1 = page.evaluate(css, "rx-root")["bg"]
215
+ row("DARK", "Dark switches the page", bg1 != bg0, "%s -> %s" % (bg0, bg1))
216
+ row("DARK", "Dark sets the cookie", cookie() == "dark", "rx-mode=%s" % cookie())
217
+ page.goto(bust(), wait_until="networkidle")
218
+ page.wait_for_timeout(900)
219
+ bg2 = page.evaluate(css, "rx-root")["bg"]
220
+ row("DARK", "a reload keeps Dark", bg2 == bg1, bg2)
221
+ page.click("#rx-light")
222
+ page.wait_for_timeout(400)
223
+ bg3 = page.evaluate(css, "rx-root")["bg"]
224
+ row("DARK", "Light switches back", bg3 == bg0, "%s, rx-mode=%s" % (bg3, cookie()))
225
+
226
+ t = [page.evaluate(css, "rx-loop")["tr"]]
227
+ page.wait_for_timeout(700)
228
+ t.append(page.evaluate(css, "rx-loop")["tr"])
229
+ row("LOOP", "moves on its own", t[0] != t[1], " -> ".join(t))
230
+ # a moving element is never "stable" for page.hover; put the pointer on it
231
+ box = page.locator("#rx-loop").bounding_box()
232
+ page.mouse.move(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
233
+ page.wait_for_timeout(300)
234
+ h = [page.evaluate(css, "rx-loop")["tr"]]
235
+ page.wait_for_timeout(700)
236
+ h.append(page.evaluate(css, "rx-loop")["tr"])
237
+ row("LOOP", "hover suspends it by Interaction ID", h[0] == h[1], " = ".join(h))
238
+ page.mouse.move(900, 700)
239
+ page.wait_for_timeout(700)
240
+ r = page.evaluate(css, "rx-loop")["tr"]
241
+ row("LOOP", "leaving resumes it", r != h[1], "%s -> %s" % (h[1], r))
242
+ page.wait_for_timeout(4200)
243
+ lp = [page.evaluate(css, "rx-loop")["tr"]]
244
+ page.wait_for_timeout(500)
245
+ lp.append(page.evaluate(css, "rx-loop")["tr"])
246
+ row("LOOP", "still moving past one 4s cycle", lp[0] != lp[1], " -> ".join(lp))
247
+
248
+ page.mouse.move(5, 5)
249
+ page.click("#rx-oc-toggle")
250
+ page.wait_for_timeout(700)
251
+ op = page.evaluate(css, "rx-oc-panel")
252
+ row("OFFCANV", "odd click opens: display flex, slid in",
253
+ op["d"] == "flex" and op["tr"] in ("0%", "0px", "none"), str(op))
254
+ page.click("#rx-oc-toggle", position={"x": 2, "y": 2}, force=True)
255
+ page.wait_for_timeout(900)
256
+ cl = page.evaluate(css, "rx-oc-panel")
257
+ row("OFFCANV", "even click closes: display none at the end", cl["d"] == "none", str(cl))
258
+
259
+ ys = []
260
+ top = page.evaluate("document.getElementById('rx-article').getBoundingClientRect().top + scrollY")
261
+ for f in (0.0, 0.5, 1.0):
262
+ page.evaluate("y => scrollTo(0, y)", top - 400 + f * 2400)
263
+ page.wait_for_timeout(500)
264
+ ys.append(page.evaluate(css, "rx-bar")["tr"])
265
+ nums = [float(str(t).split()[0].rstrip("px%") or 0) if t != "none" else 0.0 for t in ys]
266
+ row("PROGRESS", "bar fills as the article scrolls", nums[0] < nums[1] < nums[2] or
267
+ (nums[0] < nums[2] and nums[1] <= nums[2]), " -> ".join(ys))
268
+
269
+ before = page.evaluate(css, "rx-s2-c1")
270
+ page.evaluate("document.getElementById('rx-s1').scrollIntoView({block:'center'})")
271
+ page.wait_for_timeout(1200)
272
+ s1, s2_still = page.evaluate(css, "rx-s1-c1"), page.evaluate(css, "rx-s2-c1")
273
+ row("REVEAL", "first section reveals on scroll", s1["op"] == "1", str(s1))
274
+ row("REVEAL", "second stays hidden until reached",
275
+ s2_still["op"] == "0" and before["op"] == "0", str(s2_still))
276
+ page.evaluate("document.getElementById('rx-s2').scrollIntoView({block:'center'})")
277
+ page.wait_for_timeout(1200)
278
+ s2 = [page.evaluate(css, "rx-s2-c%d" % i) for i in (1, 2)]
279
+ row("REVEAL", "second reveals by class alone", all(x["op"] == "1" for x in s2),
280
+ str(s2[0]))
281
+ b.close()
282
+ return rows
283
+
284
+
285
+ def main():
286
+ ap = argparse.ArgumentParser()
287
+ ap.add_argument("--config")
288
+ ap.add_argument("--post", type=int, required=True)
289
+ ap.add_argument("--slug", required=True)
290
+ ap.add_argument("--csv")
291
+ a = ap.parse_args()
292
+ cfg = mosaic_config.load(a.config)
293
+ master = build(Client(cfg), cfg, a.post, a.slug)
294
+ print("built on master %s" % master[:8])
295
+ rows = drive("%s/%s/" % (cfg["base"].rstrip("/"), a.slug))
296
+ fails = sum(r[2] == "FAIL" for r in rows)
297
+ print("%d of %d checks passed" % (len(rows) - fails, len(rows)))
298
+ if a.csv:
299
+ with open(a.csv, "w", newline="", encoding="utf-8") as fh:
300
+ w = csv.writer(fh)
301
+ w.writerow(["recipe", "check", "status", "evidence"])
302
+ w.writerows(rows)
303
+ sys.exit(1 if fails else 0)
304
+
305
+
306
+ if __name__ == "__main__":
307
+ main()