mosaic-headless 1.36.0 → 1.36.2

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/SKILL.md CHANGED
@@ -5,7 +5,7 @@ description: |
5
5
  license: "MIT"
6
6
  metadata:
7
7
  author: "moksa (https://moksaweb.com)"
8
- version: "1.36.0"
8
+ version: "1.36.2"
9
9
  homepage: "https://github.com/Moksa1123/mosaic-headless"
10
10
  ---
11
11
 
@@ -148,6 +148,8 @@ them headlessly, measured.
148
148
  | a loading screen, a cookie bar | a fixed div + `pageLoad` + `hide_at_end`, `data.hidden: true` so it does not block editing | recipe in references/interactions.md |
149
149
  | a block repeated on several pages | a component, one definition, overrides per instance | references/design-system.md (components) |
150
150
  | a popup, a drawer, a tour | the `modal` / `popover` nodes and their actions | references/dialog-and-triggers.md |
151
+ | a site menu: desktop hover dropdown + phone drawer | `dropdown` / `dropdown-wide` with `openOn: hover`; a `modal` drawer opened by `modalOpen` (there is no off-canvas node) | references/design-system.md (site menus), `tools/verify_menus.py` |
152
+ | a typeface, site-wide | a `fontFamily` collection variable, `{"var": id}` in styles; Settings: `saveGoogleFontsLocally` on and `fontDisplay: swap` (unset is `block`) | references/styling.md (fonts) - saving Google fonts locally took a CJK page from 68 to 96 on mobile |
151
153
  | remembering a visitor's choice | `setCookie`, `remember` / `forget`, cookie conditions | references/interactions.md |
152
154
  | text that comes from the post, the user, a field | a dynamic `{"v": "@VAR(...)"}` value | references/dynamic-content.md |
153
155
  | a colour, a size used twice | a collection variable | references/design-system.md |
@@ -632,6 +634,7 @@ variable's `customProperty` is optional.
632
634
  | `data/node-type-notes.csv` | 8 | where a sweep outcome is true but misleading on its own, why. Surfaced by `mo.py type` |
633
635
  | `data/interaction-verification.csv` | 11 | **probed live** - interaction animation shapes, with negative controls and the stored row beside the payload; the editor's shape binds, the six older candidates and two one-field-apart controls do not |
634
636
  | `data/tutorial-recipes-verification.csv` | 16 | **driven live** - Mosaic's four docs tutorials (dark/light switcher, loading overlay, class-driven reveal, loop with hover pause) plus the off-canvas toggle and the reading progress bar, built from `tools/interactions.py` and checked in Chromium |
637
+ | `data/menu-verification.csv` | 34 | **driven live** - every way to build a site menu on one page: hover dropdown and mega panel (mouse, keyboard, touch tablet), and three phone menus (modal drawer, navbar, the tutorial's click panel) on a 390px touch phone - Esc, focus trap and return, aria, scroll lock, a sticky header over the close button |
635
638
  | `data/intro-verification.csv` | 8 + 15 | **sampled live** - the entrance sequence over fifteen timestamps on a monotonic clock, plus the eight assertions about it |
636
639
  | `data/variants.csv` | 157 | **live** — the variant catalog (Mosaic's built-in element classes); their IDs are what a `variant` record must use, and `class_name` is what the element emits |
637
640
  | `data/dynamic-variables.csv` | 75 | source — every `@VAR('ns/name')` expression, by namespace |
@@ -1003,6 +1006,7 @@ with `tools/prune_unbound.php` (dry run by default) after a batch of rebuilds.
1003
1006
  | `verify_rwd.py` | does every `_t`/`_m` declaration reach the served stylesheet? |
1004
1007
  | `verify_browser.py` | does the **browser** compute what the stylesheet promised - and does the result pass a design audit? |
1005
1008
  | `verify_intro.py` | does the page-load animation play, and - the part that matters - does it END and hand the page back? |
1009
+ | `verify_menus.py` | build and drive every site-menu option: does hover hold, do the keyboard and a touch tablet work, does the phone drawer trap focus, close on Esc and stay above a sticky header? |
1006
1010
  | `verify_loop.py` | a decoration that runs forever: does it loop (paused-timeline scrub), does it bury text or controls anywhere a reader can rest, does it open by pointer and by keyboard, is it still under reduced motion? |
1007
1011
  | `probe_accordion.py` | the accordion family nested as its factory requires, plus the guard's refusal of the bare node - the probe that corrected two rows of this skill's own tables |
1008
1012
  | `from_elementor.py` | an Elementor `_elementor_data` tree -> a Mosaic page spec, with every element it cannot convert reported by name and reason (`--strict` to refuse a lossy spec) |
@@ -1109,7 +1113,9 @@ python tools/sweep_style_properties.py --config sweep.json --page moksa --csv da
1109
1113
  python tools/sweep_node_properties.py --config sweep.json --page moksa --csv data/node-property-verification.csv
1110
1114
  python tools/sweep_style_states.py --config sweep.json --post 20 --slug probe-lab --csv data/style-state-verification.csv
1111
1115
  python tools/sweep_interactions.py --config sweep.json --post 20 --slug probe-lab --csv data/interaction-verification.csv
1112
- python tools/verify_recipes.py --config sweep.json --post <ID of the probe-recipes page> --slug probe-recipes \n --csv data/tutorial-recipes-verification.csv # --post REBINDS that post's template: check the ID first
1116
+ python tools/verify_recipes.py --config sweep.json --post <ID of the probe-recipes page> --slug probe-recipes \
1117
+ --csv data/tutorial-recipes-verification.csv # --post REBINDS that post's template: check the ID first
1118
+ python tools/verify_menus.py --config sweep.json --post <ID of the menu-lab page> --slug menu-lab --csv data/menu-verification.csv
1113
1119
  python tools/verify_loop.py --url https://site/ --window mk-loop --toggle mk-plate-title --panel mk-plate-item \
1114
1120
  --parts ukw-sky,ukw-sun,ukw-fuji,ukw-mist,ukw-sea,ukw-crest,ukw-boat,ukw-wave,ukw-claw,ukw-swell,ukw-key,mk-loop-seal \
1115
1121
  --period 14000 --csv data/loop-verification.csv
@@ -20,7 +20,7 @@
20
20
  "description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
21
21
  "license": "MIT",
22
22
  "author": "moksa (https://moksaweb.com)",
23
- "version": "1.36.0"
23
+ "version": "1.36.2"
24
24
  },
25
25
  "loaderBehaviour": "Upload via Settings -> Skills -> Upload. Claude.ai parses SKILL.md frontmatter and surfaces the skill in your library. The extraction tool (extract-block-schema.php) needs a live WP-CLI connection and won't run in the sandbox; use it from a local terminal against your own site instead.",
26
26
  "uploadSteps": [
@@ -20,7 +20,7 @@
20
20
  "description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
21
21
  "license": "MIT",
22
22
  "author": "moksa (https://moksaweb.com)",
23
- "version": "1.36.0"
23
+ "version": "1.36.2"
24
24
  },
25
25
  "loaderBehaviour": "Auto-loads on session start when SKILL.md frontmatter parses successfully.",
26
26
  "verified": true,
@@ -20,7 +20,7 @@
20
20
  "description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
21
21
  "license": "MIT",
22
22
  "author": "moksa (https://moksaweb.com)",
23
- "version": "1.36.0"
23
+ "version": "1.36.2"
24
24
  },
25
25
  "loaderBehaviour": "Confirmed (2026-07-11): Codex CLI natively supports the SKILL.md spec. Place SKILL.md under .codex/skills/<name>/ (project) or ~/.codex/skills/<name>/ (personal) and Codex loads the name+description at session start, then the full body on demand. A parallel, broader convention .agents/skills/ (searched from cwd up to repo root, then ~/.agents/skills/) also exists across multiple tools - if your Codex CLI version prioritizes that path instead, mirror the same SKILL.md there.",
26
26
  "verified": true,
@@ -20,7 +20,7 @@
20
20
  "description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
21
21
  "license": "MIT",
22
22
  "author": "moksa (https://moksaweb.com)",
23
- "version": "1.36.0"
23
+ "version": "1.36.2"
24
24
  },
25
25
  "loaderBehaviour": "CHANGED as of 2026-07-11: GitHub Copilot added a proper '.github/skills/' Agent Skills directory (December 2025), alongside the older single-file .github/copilot-instructions.md convention. This config targets the new skills-directory form. If your Copilot version predates this (pre Dec 2025), use the instructions-append fallback instead (see fallback below).",
26
26
  "fallback": {
@@ -20,7 +20,7 @@
20
20
  "description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
21
21
  "license": "MIT",
22
22
  "author": "moksa (https://moksaweb.com)",
23
- "version": "1.36.0"
23
+ "version": "1.36.2"
24
24
  },
25
25
  "loaderBehaviour": "CHANGED as of 2026-07-11: Gemini CLI now natively supports the same SKILL.md standard as Claude Code and Codex CLI - the same directory-based skill works unmodified. Gemini CLI discovers skills in this precedence order: built-in, extension skills, ~/.gemini/skills/ (personal), .gemini/skills/ (project, shared via version control). At session start Gemini injects each discovered skill's name+description into the system prompt and calls activate_skill when a task matches.",
26
26
  "verified": true,
@@ -0,0 +1,35 @@
1
+ group,check,result,evidence
2
+ SEO,panel links are <a href> in the server HTML,PASS,"18 links: ml-d1, ml-d2, ml-d3, ml-d4, ml-dd-l1, ml-dd-l2, ml-dd-l3, ml-mega-l1, ml-mega-l2, ml-mega-l3, ml-mega-l4, ml-mega-l5, ml-mega-l6, ml-nb-l1, ml-nb-l2, ml-nb-l3, ml-oc-l1, ml-oc-l2"
3
+ SEO,a dropdown-toggle with a url renders as,INFO,"<a class=""m-dropdown-toggle _l"" id=""ml-dd-toggle"" href=""/components/"" aria-haspopup=""true"" aria-expanded=""false"">"
4
+ DESKTOP,panels closed at rest,PASS,"dd False, mega False"
5
+ DESKTOP,hover opens the dropdown,PASS,"visible after 58 ms, aria-expanded=true"
6
+ DESKTOP,moving down into the panel keeps it open,PASS,still shown 500 ms after entering the panel
7
+ DESKTOP,leaving closes it,PASS,hidden after 159 ms
8
+ DESKTOP,mega panel opens on hover,PASS,x=0 w=1280 (viewport 1280)
9
+ KEYS,Enter on a toggle that has a url,INFO,navigated to https://mosaic.moksaweb.com/components/
10
+ KEYS,ArrowDown opens it,PASS,"shown=True, focus on ml-dd-toggle"
11
+ KEYS,ArrowDown moves into the links,INFO,focus on ml-dd-toggle
12
+ KEYS,Escape closes it and returns focus,PASS,"shown=False, focus on ml-dd-toggle"
13
+ KEYS,Space opens the mega panel (toggle without url),PASS,shown=True aria-expanded=true
14
+ KEYS,Tab from the open toggle goes to,INFO,ml-mega-l1
15
+ TOUCH,first tap on a linked toggle,PASS,"url stays=True, panel shown=True"
16
+ TOUCH,second tap on the same toggle,INFO,stayed; shown=False
17
+ TOUCH,tap opens the mega panel,PASS,
18
+ TOUCH,tap outside closes it,PASS,
19
+ PHONE,"desktop menu hidden, burger shown",PASS,
20
+ DRAWER,burger opens the modal drawer,PASS,"{'open': True, 'role': None, 'label': '主選單', 'modal': 'true', 'tag': 'dialog', 'scroll': 'clip/clip'}"
21
+ DRAWER,focus moves into the drawer,PASS,focus on ml-drawer-win
22
+ DRAWER,close button inside the viewport,PASS,x=314 y=16 w=60 h=40
23
+ DRAWER,close button not covered by the z-1000 sticky header,PASS,element at its centre: self
24
+ DRAWER,Tab stays inside the drawer,PASS,"focus visited ['ml-close', 'ml-d1', 'ml-d2', 'ml-d3', 'ml-d4']"
25
+ DRAWER,Escape closes it,PASS,
26
+ DRAWER,focus returns to the burger,PASS,focus on ml-burger
27
+ DRAWER,the close button closes it,PASS,
28
+ DRAWER,a tap on the overlay closes it,PASS,
29
+ NAVBAR,collapsed below _t,PASS,"{'mode': True, 'tag': 'mosaic-navbar-toggle', 'expanded': 'false', 'controls': None}"
30
+ NAVBAR,toggle opens the links,PASS,"aria-expanded=true, focus on ml-nb-toggle"
31
+ NAVBAR,Escape closes it,PASS,shown=False
32
+ PANEL,click interaction opens the panel,PASS,
33
+ PANEL,its close control is covered by the sticky header,INFO,element at its centre: ml-burger
34
+ PANEL,Escape closes it,FAIL,shown=True
35
+ PANEL,focus moved into it,FAIL,focus on None
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mosaic-headless",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
4
4
  "description": "AI-agent skill: build Mosaic Pro (Nextend) WordPress sites by writing the underlying data model directly - 23 custom tables, no visual editor, no DOM. Every node type, style property and node property swept against a live install and asserted on the delivered HTML and compiled CSS. Installs into Claude Code, Cursor, Codex CLI, Gemini CLI, Copilot, Continue, Windsurf and Claude.ai.",
5
5
  "keywords": [
6
6
  "wordpress",
@@ -235,6 +235,47 @@ work; set `openOn:"hover"` if hover is what you want. Style the open look throug
235
235
  the `___dropdown--opened` state. Menus support one submenu level only - no
236
236
  sub-submenus.
237
237
 
238
+ ### Site menus: what each way of building one does, measured
239
+
240
+ There is **no off-canvas node** - not in 1.0.11, not in 1.0.12 (134 types; the
241
+ 1.0.12 package searched for offcanvas / off-canvas / drawer), and not on the roadmap.
242
+ Mosaic's "off-canvas menu" is a tutorial (a div and click interactions). The menu
243
+ lab, `tools/verify_menus.py` (`data/menu-verification.csv`, 34 checks on 1.0.12),
244
+ builds every option on one page under a z-index 1000 sticky header and drives it
245
+ with a mouse, the keyboard, a touch tablet and a 390px touch phone:
246
+
247
+ | | desktop `dropdown` / `dropdown-wide`, `openOn: hover` |
248
+ |---|---|
249
+ | hover | opens in ~65 ms (fadeDown), closes ~150 ms after leaving - moving down into the panel does not drop it |
250
+ | keyboard | Space / ArrowDown open it; ArrowDown does NOT move into the links, Tab does; Escape closes and leaves focus on the toggle |
251
+ | toggle with a `url` | renders as `<a href>`; Enter navigates |
252
+ | touch | first tap on a linked toggle opens without navigating; the second tap closes it, still without navigating - so the parent page must be a link INSIDE the panel ("overview" as the first item); a tap outside closes |
253
+ | SEO | every panel link is an `<a href>` in the server HTML, before any script |
254
+ | mega | `dropdown-wide`'s panel spans the viewport (x 0, full width); one submenu level only |
255
+
256
+ | phone menu | Esc | focus | aria | close button vs sticky header |
257
+ |---|---|---|---|---|
258
+ | **(b) Pro `modal` as a drawer** | closes | moves in, Tab is trapped, returns to the opener | `<dialog aria-modal="true" aria-label>` from `accessibleLabel` | top layer: never covered; html/body `overflow: clip` while open |
259
+ | (a) `navbar` below `buttonBreakpoint` | closes | stays on the toggle, no trap | `aria-expanded`, no `aria-controls` | in flow inside the header |
260
+ | (c) div + click odd/even (the tutorial) | **does nothing** | never moves | none | **covered** when its z-index is under the header's |
261
+
262
+ The drawer the lab measures, and the recommendation:
263
+
264
+ ```
265
+ modal closedby: everything, accessibleLabel, padding 0 (the browser's dialog padding)
266
+ modal-overlay backgroundColor with alpha
267
+ modal-window position absolute, top 0, right 0, height 100dvh (the NATIVE field), width 86%,
268
+ maxWidth 360px, overflow auto; first child: a button with modalClose
269
+ opener a button with click -> modalOpen, target = the modal's pinned nodeID. The pin
270
+ only makes the two agree within one build: build_page and fill_shell re-key
271
+ it every run (refresh_node_ids), since (ID, themeID) is the primary key and
272
+ the previous master keeps its rows until pruned. Any uuid will do.
273
+ ```
274
+
275
+ A notch inset: `paddingTop: "max(16px, env(safe-area-inset-top))"` and the `calc()`
276
+ form are dropped by the native field; the same in `customDeclarations` survives. Mosaic's
277
+ viewport meta has no `viewport-fit=cover`, so `env()` is 0 unless a site adds it.
278
+
238
279
  `dropdown-wrapper` used to read as a leaf in `placement-rules.csv`. Its
239
280
  `canBeParentFor()` returns `true`, but on `DropdownWrapperElementTypeFactoryAbstract`,
240
281
  and the extractor never read the abstract files, so it saw no override and wrote
@@ -495,3 +495,33 @@ end reads the loop name out of any function call; the editor only out of `@VAR`.
495
495
  Write `@VAR('post/<loop>')`. No server-side check can see this - the page is 200 and
496
496
  complete - so it is only caught by opening the editor. Details in
497
497
  `references/custom-fields.md`.
498
+
499
+ ## The editor canvas does not load a plugin's front-end CSS
500
+
501
+ The canvas is a srcdoc iframe whose `<head>` comes from
502
+ `ThemeMResource::getHead()`: a fresh `WP_Styles`, `do_action('enqueue_block_assets')`,
503
+ Mosaic's own `style.css` and `AppWebPageEditorPreview.css`. `wp_enqueue_scripts`
504
+ never runs there. Measured with a probe mu-plugin on 1.0.12: a style enqueued on
505
+ `wp_enqueue_scripts` reached the front end and not the canvas; the same style on
506
+ `enqueue_block_assets` reached both. A code node whose decoration is styled by a
507
+ companion plugin therefore shows unstyled in the editor - on sharho a full-width
508
+ black disc over the whole canvas. Enqueue that CSS on `enqueue_block_assets` (it
509
+ also fires in the block editor, so scope the selectors), or ship an editor-only
510
+ sheet there that gives the element a static look; front-end scripts do not run in
511
+ the canvas either.
512
+
513
+ ## Inline editing re-serialises a text's runs (client report, 1.0.11)
514
+
515
+ On sharho, a heading built as `text > wysiwyg-span > wysiwyg-span` (a visually-hidden
516
+ and a no-wrap span nested inside another) came back from double-click -> Done -
517
+ with no character typed - as two flat spans, and the undo button lit. The front end
518
+ renders the nested structure fine (measured: `<span><span>` delivered), so the loss
519
+ is the editor's serialiser. The editor's own bold and italic are not spans: they are
520
+ `wysiwyg-text` `format: ["bold"]` / `["italic"]`, delivered as `<strong>` / `<em>`
521
+ (`<strong><em>` for both, measured). Keep runs in shapes the editor itself writes,
522
+ and tell a client not to edit a heading that needs nesting.
523
+
524
+ Mosaic also keeps unsaved edits in the browser: reopening that template offered
525
+ "a backup of this post stored in the browser differs from the version below" with
526
+ Restore / Cancel. Restore brings the flattened version back, and the next save
527
+ writes it. When reproducing an editor problem, press Cancel.
@@ -280,6 +280,52 @@ dropped, which is the only reason they cost minutes instead of a debugging sessi
280
280
  — a property that is not in the registry cannot be set at all, and Mosaic's own
281
281
  API accepts the write and discards it.
282
282
 
283
+ ## Fonts: what Mosaic loads, and what makes a CJK site slow (measured, 1.0.12)
284
+
285
+ A font is a collection variable of type `fontFamily` (not `font` - an unknown type
286
+ is a PHP fatal on commit), referenced from a style as `fontFamily: {"var": id}`. Its
287
+ value per mode is one of two providers:
288
+
289
+ ```
290
+ {"provider": "google", "fallbacks": "sans-serif",
291
+ "googleOptions": {"fontFamily": "Noto Sans TC", "fontVariants": ["400", "700"]}}
292
+ {"provider": "custom", "fallbacks": "sans-serif",
293
+ "customOptions": {"fontFamily": "\"PingFang TC\", \"Microsoft JhengHei\", sans-serif",
294
+ "fontFaces": "@font-face { ... }"}} # fontFaces may be ""
295
+ ```
296
+
297
+ - `google` loads only the ticked weights, one css2 URL for every Google font.
298
+ - `custom` inlines its `@font-face` rules in the page (no extra request). The
299
+ validator keeps `font-family`, `src` (url / local + format), `font-weight`,
300
+ `font-style`, `font-stretch`, `unicode-range` and `font-display`, and drops the
301
+ rest (`size-adjust`, the overrides). There is no upload UI: the woff2 is yours to
302
+ host. An empty `fontFaces` makes a system-font variable the client can still swap.
303
+ - **Every published font variable is loaded on every page**, used or not
304
+ (`FontRenderingManager::enqueueFontFamilies`). Delete the ones nothing uses.
305
+ - Site settings (Mosaic -> Settings, `settingsEditorInstance`): `fontDisplay`
306
+ (auto | block | swap | fallback | optional; **unset means `block`**, so text is
307
+ invisible until the font arrives), `saveGoogleFontsLocally` (CSS and woff2
308
+ copied to `wp-content/cache/mosaic/web/googlefonts/`), `criticalPreload` (an HTTP
309
+ preload of the font CSS, not of font files). There is no font-file preload.
310
+
311
+ Lighthouse mobile, median of three, a Chinese page (h1 700, body 400 + 500, a
312
+ Poppins 600 label) on the demo site:
313
+
314
+ | set-up | score | FCP | LCP | font bytes |
315
+ |---|---|---|---|---|
316
+ | Google Noto Sans TC 400/500/700 + Poppins, `fontDisplay` unset | 68-69 | 3.7-4.0 s | 6.2 s | 649 KB |
317
+ | the same, `fontDisplay: swap` only | 63-72 | 4.6-6.0 s | 4.7-6.1 s | 649 KB |
318
+ | the same + `saveGoogleFontsLocally` | 96 | 2.1 s | 2.1 s | 666 KB |
319
+ | 400/700 only + swap + local | 97 | 1.9 s | 1.9 s | 627 KB |
320
+ | CJK on a system stack (custom, no @font-face), Poppins from Google | 93 | 2.5 s | 2.5 s | 17 KB |
321
+ | the same, Poppins saved locally | 99 | 1.4 s | 1.5 s | 17 KB |
322
+
323
+ What costs the time is the render-blocking stylesheet on fonts.googleapis.com, not
324
+ the size of the CJK files - Google already slices them by `unicode-range` and the
325
+ browser fetches only the slices the page uses. `swap` alone does not help; saving
326
+ locally does. Hand-subsetting a CJK font is not worth it: the slices already do
327
+ that, and text a client adds later falls outside a hand-made subset.
328
+
283
329
  ## `fontFamily` takes a plain family list, nothing else
284
330
 
285
331
  `ValidatorStyleFontFamily` (NEXT-5841) accepts quoted names and unquoted identifier
@@ -130,6 +130,7 @@ const counts = {
130
130
  "data/style-state-verification.csv": 59,
131
131
  "data/interaction-verification.csv": 11,
132
132
  "data/tutorial-recipes-verification.csv": 16,
133
+ "data/menu-verification.csv": 34,
133
134
  "data/data-class-hierarchy.csv": 131,
134
135
  "data/custom-fields-verification.csv": 62,
135
136
  "data/dialog-verification.csv": 19,
@@ -130,7 +130,12 @@ def fill_shell(client, cfg, site, surface, master_id, header_id, footer_id, comp
130
130
  leaves an extra master behind on every build."""
131
131
  instance = "masterDocumentInstance/%s" % master_id
132
132
  key = "node/master/%s" % master_id
133
- shell = site.get("shell") or {}
133
+ # Re-key pinned nodeIDs here too, as build_page_document does: an old master
134
+ # keeps its rows until it is pruned and the key is (ID, themeID), so a pinned
135
+ # id is single-use. Both regions in one pass, so a header button whose
136
+ # modalOpen names a modal in the footer keeps pointing at it.
137
+ shell = refresh_node_ids({k: v for k, v in (site.get("shell") or {}).items()
138
+ if k in ("header", "footer")})
134
139
  COMPONENT_USES.clear()
135
140
  records = []
136
141
  for region, parent in (("header", header_id), ("footer", footer_id)):
package/tools/mo.py CHANGED
@@ -652,10 +652,22 @@ def cmd_placement(a):
652
652
  emit(payload, lambda: (
653
653
  head("placement: %s" % a.name),
654
654
  print("rule : %s" % payload["rule"]),
655
- print("accepts children: %s" % (", ".join(payload["allowed_children"])
656
- or "none")),
655
+ # canBeParentFor() is checked only on the editor's drop / paste path
656
+ # (PlacementValidatorRaw), never on a REST commit - so "none" with heal
657
+ # children (navbar, dropdown) means: its own children exist, and the
658
+ # client cannot drag anything else into it in the editor.
659
+ print("editor drop-in : %s" % (", ".join(payload["allowed_children"])
660
+ or ("any type" if payload["rule"] == "any"
661
+ else "refused - nothing can be dragged in"))),
657
662
  print("heal() inserts : %s" % (", ".join(payload["default_children"])
658
663
  or "nothing")),
664
+ payload["rule"] == "none" and print(
665
+ " (editor-only: a REST commit does not check this rule, so\n"
666
+ " children written over REST still render - but a client\n"
667
+ " cannot drag anything into it in the editor. navbar is\n"
668
+ " navbar > navbar-toggle + navigation and dropdown is\n"
669
+ " dropdown > toggle + wrapper by their factories; put\n"
670
+ " anything else INSIDE navigation / the wrapper)"),
659
671
  print("named parents : %s" % (", ".join(payload["named_parents"])
660
672
  or "none - no type asks for it by name")),
661
673
  print("also accepted by: %d permissive containers (rule=any / deny-list)"
@@ -0,0 +1,430 @@
1
+ #!/usr/bin/env python3
2
+ """Build every way Mosaic can make a site menu on one page, then drive each one.
3
+
4
+ python tools/verify_menus.py --config c.json --post <ID of menu-lab> --slug menu-lab \
5
+ --csv data/menu-verification.csv
6
+
7
+ Mosaic has no off-canvas node. A desktop menu is a `dropdown` / `dropdown-wide`; a
8
+ phone menu is one of three assemblies, and they differ on exactly what a visitor
9
+ notices - whether Esc closes it, where focus goes, whether a sticky header can sit
10
+ on top of its close button:
11
+
12
+ DESKTOP a sticky header (z-index 1000) with a `dropdown` (openOn hover, its toggle
13
+ carrying a url), a `dropdown-wide` mega panel and a plain `menu-link`.
14
+ Asserted with a mouse, with the keyboard, and on a touch tablet: open and
15
+ close timing, aria-expanded, Esc, what a tap on a linked toggle does, and
16
+ whether the panel links are in the HTML before any script runs.
17
+ DRAWER (b) a Pro `modal` as a right-hand drawer: overlay + window, opened by a
18
+ hamburger's modalOpen, closed by a modalClose button inside, Esc and the
19
+ overlay. Asserted at 390px on a touch phone.
20
+ NAVBAR (a) `navbar` > `navbar-toggle` + `navigation`, collapsing below `_t`.
21
+ PANEL (c) Mosaic's off-canvas tutorial: a fixed div opened by click odd/even
22
+ interactions - z-index 50, under the sticky header, on purpose.
23
+ """
24
+ from __future__ import annotations
25
+
26
+ import mosaic_config
27
+ import argparse
28
+ import csv
29
+ import os
30
+ import re
31
+ import sys
32
+ import time
33
+ import urllib.request
34
+ import uuid
35
+
36
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
37
+ import interactions as ix # noqa: E402
38
+ from build_page import Surface # noqa: E402
39
+ from build_site import bind_page, build_page_document, build_shell # noqa: E402
40
+ from sweep_node_types import Client # noqa: E402
41
+
42
+ NS = uuid.UUID("6d6f7361-6963-4865-6164-6c657373ff0c")
43
+ INK, PAPER = "rgb(22, 24, 28)", "rgb(250, 250, 247)"
44
+
45
+
46
+ def det(name):
47
+ return str(uuid.uuid5(NS, name))
48
+
49
+
50
+ def link(attr, label, url, **style):
51
+ st = {"paddingTop": "10px", "paddingBottom": "10px", "paddingLeft": "14px",
52
+ "paddingRight": "14px", "color": INK, "fontSize": "15px"}
53
+ st.update(style)
54
+ return {"type": "menu-link", "data": {"attrID": attr, "url": url},
55
+ "style": {"&": {"_": st}, "focus-visible": {"_": {
56
+ "customDeclarations": "outline:2px solid rgb(9,99,199);outline-offset:2px;"}}},
57
+ "children": [{"type": "wysiwyg-text", "data": {"text": label}}]}
58
+
59
+
60
+ def button(attr, label, actions, **style):
61
+ st = {"paddingTop": "10px", "paddingBottom": "10px", "paddingLeft": "14px",
62
+ "paddingRight": "14px", "backgroundColor": INK, "color": PAPER,
63
+ "cursor": "pointer"}
64
+ st.update(style)
65
+ return {"type": "button", "data": {"attrID": attr, "interactions": [ix.on("click", actions)]},
66
+ "style": {"&": {"_": st}},
67
+ "children": [{"type": "wysiwyg-text", "data": {"text": label}}]}
68
+
69
+
70
+ def act(kind, node_id):
71
+ return {"type": kind, "uuid": str(uuid.uuid4()),
72
+ "settings": {"target": {"type": "element", "uuid": node_id}}}
73
+
74
+
75
+ PANEL = {"backgroundColor": PAPER, "paddingTop": "8px", "paddingBottom": "8px",
76
+ "minWidth": "220px",
77
+ "customDeclarations": "border:1px solid rgb(22,24,28);box-shadow:0 18px 40px rgba(22,24,28,.16);"}
78
+
79
+
80
+ def tree():
81
+ drawer, panel = det("drawer"), det("panel")
82
+ desktop = {"type": "div", "data": {"attrID": "ml-desk"},
83
+ "style": {"&": {"_": {"display": "flex", "alignItems": "center", "columnGap": "8px"},
84
+ "_t": {"display": "none"}}},
85
+ "children": [
86
+ {"type": "dropdown", "data": {"attrID": "ml-dd", "openOn": "hover", "animation": "fadeDown"},
87
+ "style": {"&": {"_": {"position": "relative"}}},
88
+ "children": [
89
+ {"type": "dropdown-toggle", "data": {"attrID": "ml-dd-toggle", "url": "/components/"},
90
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
91
+ "paddingLeft": "14px", "paddingRight": "14px",
92
+ "color": INK, "cursor": "pointer"}}},
93
+ "children": [{"type": "wysiwyg-text", "data": {"text": "服務"}}]},
94
+ {"type": "dropdown-wrapper", "data": {"attrID": "ml-dd-menu"},
95
+ "style": {"&": {"_": dict(PANEL, flexDirection="column")}},
96
+ "children": [link("ml-dd-l%d" % i, t, u) for i, (t, u) in enumerate(
97
+ [("服務總覽", "/components/"), ("表單", "/forms/"), ("輪播", "/sliders/")], 1)]}]},
98
+ {"type": "dropdown-wide", "data": {"attrID": "ml-mega", "openOn": "hover", "animation": "fadeDown"},
99
+ "children": [
100
+ {"type": "dropdown-toggle", "data": {"attrID": "ml-mega-toggle"},
101
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
102
+ "paddingLeft": "14px", "paddingRight": "14px",
103
+ "color": INK, "cursor": "pointer"}}},
104
+ "children": [{"type": "wysiwyg-text", "data": {"text": "全部功能"}}]},
105
+ {"type": "dropdown-wrapper-wide", "data": {"attrID": "ml-mega-menu"},
106
+ "style": {"&": {"_": dict(PANEL, display="grid", gridCols="repeat(3, 1fr)",
107
+ paddingLeft="24px", paddingRight="24px")}},
108
+ "children": [link("ml-mega-l%d" % i, t, u) for i, (t, u) in enumerate(
109
+ [("元件牆", "/components/"), ("表單", "/forms/"), ("內容", "/content/"),
110
+ ("輪播", "/sliders/"), ("彈出層", "/popovers/"), ("對話框", "/dialogs/")], 1)]}]},
111
+ link("ml-contact", "聯絡", "/forms/")]}
112
+
113
+ header = {"type": "div", "data": {"attrID": "ml-header"},
114
+ "style": {"&": {"_": {"position": "sticky", "top": "0px", "zIndex": "1000",
115
+ "height": "64px", "display": "flex", "alignItems": "center",
116
+ "justifyContent": "space-between",
117
+ "paddingLeft": "20px", "paddingRight": "20px",
118
+ "backgroundColor": PAPER,
119
+ "customDeclarations": "border-bottom:1px solid rgb(22,24,28);"}}},
120
+ "children": [
121
+ {"type": "text", "data": {"attrID": "ml-logo", "tagName": "p"}, "text": "MENU LAB"},
122
+ desktop,
123
+ {"type": "div", "data": {"attrID": "ml-mob"},
124
+ "style": {"&": {"_": {"display": "none"}, "_t": {"display": "flex", "columnGap": "8px"}}},
125
+ "children": [
126
+ button("ml-burger", "選單", [act("modalOpen", drawer)]),
127
+ {"type": "div", "data": {"attrID": "ml-oc-btn", "interactions": [_panel_toggle(panel)]},
128
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
129
+ "paddingLeft": "14px", "paddingRight": "14px",
130
+ "cursor": "pointer",
131
+ "customDeclarations": "border:1px solid rgb(22,24,28);"}}},
132
+ "text": "面板"}]}]}
133
+
134
+ modal = {"type": "modal", "nodeID": drawer,
135
+ "data": {"attrID": "ml-drawer", "closedby": "everything", "accessibleLabel": "主選單"},
136
+ "style": {"&": {"_": {"paddingTop": "0px", "paddingBottom": "0px",
137
+ "paddingLeft": "0px", "paddingRight": "0px"}}},
138
+ "children": [
139
+ {"type": "modal-overlay", "data": {"attrID": "ml-drawer-ov"},
140
+ "style": {"&": {"_": {"backgroundColor": "rgba(22, 24, 28, 0.5)"}}}},
141
+ {"type": "modal-window", "data": {"attrID": "ml-drawer-win"},
142
+ "style": {"&": {"_": {"position": "absolute", "top": "0px", "right": "0px",
143
+ "height": "100dvh", "width": "86%", "maxWidth": "360px",
144
+ "backgroundColor": PAPER, "overflow": "auto",
145
+ "display": "flex", "flexDirection": "column",
146
+ "paddingTop": "16px", "paddingLeft": "16px",
147
+ "paddingRight": "16px", "paddingBottom": "24px"}}},
148
+ "children": [
149
+ button("ml-close", "關閉", [act("modalClose", drawer)], alignSelf="flex-end"),
150
+ link("ml-d1", "服務總覽", "/components/"), link("ml-d2", "表單", "/forms/"),
151
+ link("ml-d3", "輪播", "/sliders/"), link("ml-d4", "聯絡", "/forms/")]}]}
152
+
153
+ navbar = {"type": "navbar", "data": {"attrID": "ml-nb", "buttonBreakpoint": "_t",
154
+ "animation": "fadeDown", "disableScroll": "1"},
155
+ "style": {"&": {"_": {"display": "flex", "alignItems": "center",
156
+ "justifyContent": "space-between", "paddingTop": "12px",
157
+ "paddingBottom": "12px", "paddingLeft": "20px", "paddingRight": "20px",
158
+ "customDeclarations": "border-bottom:1px solid rgb(22,24,28);"}}},
159
+ "children": [
160
+ {"type": "navbar-toggle", "data": {"attrID": "ml-nb-toggle"},
161
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px",
162
+ "paddingLeft": "14px", "paddingRight": "14px", "cursor": "pointer",
163
+ "customDeclarations": "border:1px solid rgb(22,24,28);"}}},
164
+ "children": [{"type": "wysiwyg-text", "data": {"text": "NAVBAR"}}]},
165
+ {"type": "navigation", "data": {"attrID": "ml-nb-nav"},
166
+ "style": {"&": {"_": {"display": "flex", "columnGap": "8px"}}},
167
+ "children": [link("ml-nb-l1", "服務", "/components/"), link("ml-nb-l2", "表單", "/forms/"),
168
+ link("ml-nb-l3", "聯絡", "/forms/")]}]}
169
+
170
+ oc_panel = {"type": "div", "nodeID": panel, "data": {"attrID": "ml-oc-panel"},
171
+ "style": {"&": {"_": {"display": "none", "position": "fixed", "zIndex": "50",
172
+ "top": "0px", "right": "0px", "bottom": "0px", "width": "300px",
173
+ "flexDirection": "column", "paddingTop": "16px",
174
+ "paddingLeft": "16px", "paddingRight": "16px",
175
+ "backgroundColor": "rgb(240, 240, 235)"}}},
176
+ "children": [
177
+ {"type": "div", "data": {"attrID": "ml-oc-close", "interactions": [_panel_toggle(panel)]},
178
+ "style": {"&": {"_": {"paddingTop": "10px", "paddingBottom": "10px", "cursor": "pointer"}}},
179
+ "text": "關閉面板"},
180
+ link("ml-oc-l1", "服務總覽", "/components/"), link("ml-oc-l2", "表單", "/forms/")]}
181
+
182
+ return {"type": "div", "data": {"attrID": "ml-root"},
183
+ "children": [header, modal, navbar, oc_panel,
184
+ {"type": "div", "data": {"attrID": "ml-body"},
185
+ "style": {"&": {"_": {"height": "2400px", "paddingTop": "40px",
186
+ "paddingLeft": "20px", "paddingRight": "20px"}}},
187
+ "children": [{"type": "text", "data": {"attrID": "ml-copy", "tagName": "p"},
188
+ "text": "選單實驗頁:桌機 hover 下拉、mega 下拉、modal 抽屜、navbar 收合、互動面板。"},
189
+ # probe: native run formats vs nested spans (sharho report)
190
+ {"type": "text", "data": {"attrID": "ml-fmt", "tagName": "p"}, "children": [
191
+ {"type": "wysiwyg-text", "data": {"text": "B", "format": ["bold"]}},
192
+ {"type": "wysiwyg-text", "data": {"text": "I", "format": ["italic"]}},
193
+ {"type": "wysiwyg-text", "data": {"text": "BI", "format": ["italic", "bold"]}},
194
+ {"type": "wysiwyg-span", "data": {"attrID": "ml-sp-out"}, "children": [
195
+ {"type": "wysiwyg-text", "data": {"text": "outer "}},
196
+ {"type": "wysiwyg-span", "data": {"attrID": "ml-sp-in"}, "children": [
197
+ {"type": "wysiwyg-text", "data": {"text": "inner"}}]}]}]},
198
+ # which spelling of a notch inset survives the style validator
199
+ {"type": "div", "data": {"attrID": "ml-safe-native"},
200
+ "style": {"&": {"_": {"paddingTop": "max(16px, env(safe-area-inset-top))"}}}},
201
+ {"type": "div", "data": {"attrID": "ml-safe-custom"},
202
+ "style": {"&": {"_": {"customDeclarations":
203
+ "padding-top:max(16px, env(safe-area-inset-top));"}}}},
204
+ {"type": "div", "data": {"attrID": "ml-safe-calc"},
205
+ "style": {"&": {"_": {"paddingTop": "calc(16px + env(safe-area-inset-top))"}}}}]}]}
206
+
207
+
208
+ def _panel_toggle(panel):
209
+ t = ix.on("click", [ix.display(start="flex", target=ix.element(panel)),
210
+ ix.tween([("translateX", "100%", "0%")], 300, target=ix.element(panel))],
211
+ slot="odd")
212
+ return ix.add_slot(t, "even", [ix.tween([("translateX", "0%", "100%")], 300, target=ix.element(panel)),
213
+ ix.display(end="none", duration=300, target=ix.element(panel))])
214
+
215
+
216
+ def build(client, cfg, post, slug):
217
+ surface = Surface()
218
+ master, _h, _f = build_shell(client, cfg, {"pages": [], "shell": {}}, surface)
219
+ template = bind_page(client, cfg, master, slug, post)
220
+ build_page_document(client, cfg, master, template, tree(), surface)
221
+ return master
222
+
223
+
224
+ # ---------------------------------------------------------------- the drive
225
+
226
+ INFO = """id => { const e = document.getElementById(id); if (!e) return null;
227
+ const r = e.getBoundingClientRect(), s = getComputedStyle(e);
228
+ return {shown: r.width > 2 && r.height > 2 && s.display !== 'none' && s.visibility !== 'hidden'
229
+ && parseFloat(s.opacity) > 0.05,
230
+ x: r.x, y: r.y, w: r.width, h: r.height, tag: e.tagName.toLowerCase(),
231
+ expanded: e.getAttribute('aria-expanded')}; }"""
232
+ ON_TOP = """id => { const e = document.getElementById(id); const r = e.getBoundingClientRect();
233
+ const t = document.elementFromPoint(r.x + r.width / 2, r.y + Math.min(r.height / 2, 12));
234
+ return t ? (e.contains(t) ? 'self' : (t.id || t.className || t.tagName)) : 'nothing'; }"""
235
+ ACTIVE = """() => { let a = document.activeElement; while (a && !a.id) a = a.parentElement;
236
+ return a ? a.id : null; }"""
237
+ IN_DRAWER = """() => !!document.activeElement && !!document.activeElement.closest('#ml-drawer')"""
238
+
239
+
240
+ def drive(url, rows):
241
+ from playwright.sync_api import sync_playwright
242
+
243
+ def row(group, check, ok, evidence):
244
+ rows.append([group, check, "PASS" if ok else ("INFO" if ok is None else "FAIL"), evidence])
245
+ print(" %-8s %-46s %-4s %s" % (group, check, rows[-1][2], evidence))
246
+
247
+ bust = lambda: "%s?_v=%d" % (url, time.time() * 1000) # noqa: E731
248
+
249
+ # the HTML before any script: are the panel links crawlable?
250
+ raw = urllib.request.urlopen(urllib.request.Request(bust(), headers={"User-Agent": "Mozilla/5.0"})).read().decode("utf-8")
251
+ hrefs = re.findall(r'id="(ml-(?:dd|mega|d|nb|oc)-?l?\d+)"[^>]*href="([^"]*)"|href="([^"]*)"[^>]*id="(ml-(?:dd|mega|d|nb|oc)-?l?\d+)"', raw)
252
+ ids = sorted({a or d for a, _b, _c, d in hrefs})
253
+ row("SEO", "panel links are <a href> in the server HTML", len(ids) >= 15,
254
+ "%d links: %s" % (len(ids), ", ".join(ids)))
255
+ dt = re.search(r'<[a-z-]+[^>]*id="ml-dd-toggle"[^>]*>', raw)
256
+ row("SEO", "a dropdown-toggle with a url renders as", None, dt.group(0)[:160] if dt else "absent")
257
+
258
+ with sync_playwright() as pw:
259
+ b = pw.chromium.launch()
260
+
261
+ # ---------------- desktop, mouse
262
+ p = b.new_page(viewport={"width": 1280, "height": 800})
263
+ p.goto(bust(), wait_until="networkidle")
264
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
265
+ row("DESKTOP", "panels closed at rest", not info("ml-dd-menu")["shown"] and not info("ml-mega-menu")["shown"],
266
+ "dd %s, mega %s" % (info("ml-dd-menu")["shown"], info("ml-mega-menu")["shown"]))
267
+ t = info("ml-dd-toggle")
268
+ p.mouse.move(t["x"] + t["w"] / 2, t["y"] + t["h"] / 2)
269
+ t0 = time.time(); opened_at = None
270
+ while time.time() - t0 < 2:
271
+ if info("ml-dd-menu")["shown"]:
272
+ opened_at = time.time() - t0; break
273
+ p.wait_for_timeout(20)
274
+ row("DESKTOP", "hover opens the dropdown", opened_at is not None,
275
+ "visible after %s ms, aria-expanded=%s" % (int(opened_at * 1000) if opened_at else "-",
276
+ info("ml-dd-toggle")["expanded"]))
277
+ m = info("ml-dd-menu")
278
+ p.mouse.move(m["x"] + 30, m["y"] + m["h"] / 2, steps=8)
279
+ p.wait_for_timeout(500)
280
+ row("DESKTOP", "moving down into the panel keeps it open", info("ml-dd-menu")["shown"],
281
+ "still shown 500 ms after entering the panel")
282
+ p.mouse.move(700, 600)
283
+ t0 = time.time(); closed_at = None
284
+ while time.time() - t0 < 3:
285
+ if not info("ml-dd-menu")["shown"]:
286
+ closed_at = time.time() - t0; break
287
+ p.wait_for_timeout(20)
288
+ row("DESKTOP", "leaving closes it", closed_at is not None,
289
+ "hidden after %s ms" % (int(closed_at * 1000) if closed_at else "-"))
290
+ g = info("ml-mega-toggle")
291
+ p.mouse.move(g["x"] + g["w"] / 2, g["y"] + g["h"] / 2)
292
+ p.wait_for_timeout(600)
293
+ mg = info("ml-mega-menu")
294
+ row("DESKTOP", "mega panel opens on hover", mg["shown"],
295
+ "x=%d w=%d (viewport 1280)" % (mg["x"], mg["w"]))
296
+ p.mouse.move(700, 700); p.wait_for_timeout(800)
297
+
298
+ # keyboard
299
+ p.goto(bust(), wait_until="networkidle")
300
+ p.focus("#ml-dd-toggle")
301
+ p.keyboard.press("Enter")
302
+ p.wait_for_timeout(1200)
303
+ p.wait_for_load_state("domcontentloaded")
304
+ row("KEYS", "Enter on a toggle that has a url", None,
305
+ "navigated to %s" % p.url if "menu-lab" not in p.url
306
+ else "opened=%s" % info("ml-dd-menu")["shown"])
307
+ if "menu-lab" not in p.url:
308
+ p.goto(bust(), wait_until="networkidle")
309
+ p.focus("#ml-dd-toggle")
310
+ p.keyboard.press("ArrowDown"); p.wait_for_timeout(500)
311
+ row("KEYS", "ArrowDown opens it", info("ml-dd-menu")["shown"],
312
+ "shown=%s, focus on %s" % (info("ml-dd-menu")["shown"], p.evaluate(ACTIVE)))
313
+ p.keyboard.press("ArrowDown"); p.wait_for_timeout(150)
314
+ row("KEYS", "ArrowDown moves into the links", None, "focus on %s" % p.evaluate(ACTIVE))
315
+ p.keyboard.press("Escape"); p.wait_for_timeout(500)
316
+ row("KEYS", "Escape closes it and returns focus", not info("ml-dd-menu")["shown"],
317
+ "shown=%s, focus on %s" % (info("ml-dd-menu")["shown"], p.evaluate(ACTIVE)))
318
+ p.focus("#ml-mega-toggle"); p.keyboard.press("Space"); p.wait_for_timeout(500)
319
+ row("KEYS", "Space opens the mega panel (toggle without url)", info("ml-mega-menu")["shown"],
320
+ "shown=%s aria-expanded=%s" % (info("ml-mega-menu")["shown"], info("ml-mega-toggle")["expanded"]))
321
+ p.keyboard.press("Tab"); p.wait_for_timeout(150)
322
+ row("KEYS", "Tab from the open toggle goes to", None, p.evaluate(ACTIVE))
323
+ p.close()
324
+
325
+ # ---------------- touch tablet at desktop width
326
+ ctx = b.new_context(viewport={"width": 1366, "height": 1024}, has_touch=True, is_mobile=True)
327
+ p = ctx.new_page(); p.goto(bust(), wait_until="networkidle")
328
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
329
+ p.tap("#ml-dd-toggle"); p.wait_for_timeout(600)
330
+ row("TOUCH", "first tap on a linked toggle", "menu-lab" in p.url and info("ml-dd-menu")["shown"],
331
+ "url stays=%s, panel shown=%s" % ("menu-lab" in p.url, info("ml-dd-menu")["shown"] if "menu-lab" in p.url else "-"))
332
+ if "menu-lab" in p.url:
333
+ p.tap("#ml-dd-toggle"); p.wait_for_timeout(900)
334
+ row("TOUCH", "second tap on the same toggle", None,
335
+ "navigated to %s" % p.url if "menu-lab" not in p.url else "stayed; shown=%s" % info("ml-dd-menu")["shown"])
336
+ p.goto(bust(), wait_until="networkidle")
337
+ p.tap("#ml-mega-toggle"); p.wait_for_timeout(600)
338
+ row("TOUCH", "tap opens the mega panel", info("ml-mega-menu")["shown"], "")
339
+ p.tap("#ml-copy"); p.wait_for_timeout(600)
340
+ row("TOUCH", "tap outside closes it", not info("ml-mega-menu")["shown"], "")
341
+ ctx.close()
342
+
343
+ # ---------------- phone
344
+ ctx = b.new_context(viewport={"width": 390, "height": 844}, has_touch=True, is_mobile=True)
345
+ p = ctx.new_page(); p.goto(bust(), wait_until="networkidle")
346
+ info = lambda i: p.evaluate(INFO, i) # noqa: E731
347
+ row("PHONE", "desktop menu hidden, burger shown", not info("ml-desk")["shown"] and info("ml-burger")["shown"], "")
348
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
349
+ d = p.evaluate("""() => { const m = document.getElementById('ml-drawer');
350
+ return {open: m.matches(':popover-open') || m.open, role: m.getAttribute('role'),
351
+ label: m.getAttribute('aria-label'), modal: m.getAttribute('aria-modal'),
352
+ tag: m.tagName.toLowerCase(), scroll: getComputedStyle(document.documentElement).overflow
353
+ + '/' + getComputedStyle(document.body).overflow}; }""")
354
+ row("DRAWER", "burger opens the modal drawer", d["open"], str(d))
355
+ row("DRAWER", "focus moves into the drawer", p.evaluate(IN_DRAWER), "focus on %s" % p.evaluate(ACTIVE))
356
+ c = info("ml-close")
357
+ row("DRAWER", "close button inside the viewport", c["shown"] and c["y"] >= 0 and c["x"] + c["w"] <= 390,
358
+ "x=%d y=%d w=%d h=%d" % (c["x"], c["y"], c["w"], c["h"]))
359
+ row("DRAWER", "close button not covered by the z-1000 sticky header", p.evaluate(ON_TOP, "ml-close") == "self",
360
+ "element at its centre: %s" % p.evaluate(ON_TOP, "ml-close"))
361
+ seen = set()
362
+ for _ in range(8):
363
+ p.keyboard.press("Tab"); seen.add(p.evaluate(ACTIVE))
364
+ row("DRAWER", "Tab stays inside the drawer", all((s or "").startswith(("ml-d", "ml-close")) for s in seen),
365
+ "focus visited %s" % sorted(s or "-" for s in seen))
366
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
367
+ closed = not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')")
368
+ row("DRAWER", "Escape closes it", closed, "")
369
+ row("DRAWER", "focus returns to the burger", p.evaluate(ACTIVE) == "ml-burger", "focus on %s" % p.evaluate(ACTIVE))
370
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
371
+ p.tap("#ml-close"); p.wait_for_timeout(700)
372
+ row("DRAWER", "the close button closes it",
373
+ not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')"), "")
374
+ p.tap("#ml-burger"); p.wait_for_timeout(700)
375
+ p.mouse.click(20, 400); p.wait_for_timeout(700)
376
+ row("DRAWER", "a tap on the overlay closes it",
377
+ not p.evaluate("() => document.getElementById('ml-drawer').matches(':popover-open')"), "")
378
+
379
+ # navbar
380
+ p.goto(bust(), wait_until="networkidle")
381
+ nb = p.evaluate("""() => { const t = document.getElementById('ml-nb-toggle');
382
+ return {mode: document.getElementById('ml-nb').className.includes('dropdown-mode'),
383
+ tag: t.tagName.toLowerCase(), expanded: t.getAttribute('aria-expanded'),
384
+ controls: t.getAttribute('aria-controls')}; }""")
385
+ row("NAVBAR", "collapsed below _t", nb["mode"] and not info("ml-nb-nav")["shown"], str(nb))
386
+ p.tap("#ml-nb-toggle"); p.wait_for_timeout(700)
387
+ row("NAVBAR", "toggle opens the links", info("ml-nb-nav")["shown"],
388
+ "aria-expanded=%s, focus on %s" % (info("ml-nb-toggle")["expanded"], p.evaluate(ACTIVE)))
389
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
390
+ row("NAVBAR", "Escape closes it", not info("ml-nb-nav")["shown"], "shown=%s" % info("ml-nb-nav")["shown"])
391
+
392
+ # interaction panel
393
+ p.goto(bust(), wait_until="networkidle")
394
+ p.tap("#ml-oc-btn"); p.wait_for_timeout(700)
395
+ row("PANEL", "click interaction opens the panel", info("ml-oc-panel")["shown"], "")
396
+ row("PANEL", "its close control is covered by the sticky header", None,
397
+ "element at its centre: %s" % p.evaluate(ON_TOP, "ml-oc-close"))
398
+ p.keyboard.press("Escape"); p.wait_for_timeout(600)
399
+ row("PANEL", "Escape closes it", not info("ml-oc-panel")["shown"], "shown=%s" % info("ml-oc-panel")["shown"])
400
+ row("PANEL", "focus moved into it", p.evaluate("() => !!document.activeElement.closest('#ml-oc-panel')"),
401
+ "focus on %s" % p.evaluate(ACTIVE))
402
+ ctx.close()
403
+ b.close()
404
+
405
+
406
+ def main():
407
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
408
+ ap.add_argument("--config")
409
+ ap.add_argument("--post", required=True, type=int)
410
+ ap.add_argument("--slug", default="menu-lab")
411
+ ap.add_argument("--csv")
412
+ ap.add_argument("--no-build", action="store_true")
413
+ a = ap.parse_args()
414
+ cfg = mosaic_config.load(a.config)
415
+ if not a.no_build:
416
+ master = build(Client(cfg), cfg, a.post, a.slug)
417
+ print("built on master %s" % master[:8])
418
+ rows = []
419
+ drive("%s/%s/" % (cfg["base"].rstrip("/"), a.slug), rows)
420
+ if a.csv:
421
+ with open(a.csv, "w", newline="", encoding="utf-8") as fh:
422
+ w = csv.writer(fh)
423
+ w.writerow(["group", "check", "result", "evidence"])
424
+ w.writerows(rows)
425
+ fails = sum(1 for r in rows if r[2] == "FAIL")
426
+ print("\n%d checks, %d FAIL" % (len(rows), fails))
427
+
428
+
429
+ if __name__ == "__main__":
430
+ main()