@litfamily/litgravity 0.1.0 → 0.1.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.
Files changed (248) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +72 -17
  3. package/README_ko-KR.md +72 -17
  4. package/package.json +1 -1
  5. package/plugin/hooks/lib/lanes.mjs +65 -0
  6. package/plugin/hooks/lib/motion.mjs +34 -5
  7. package/plugin/hooks/lib/reentry.mjs +7 -0
  8. package/plugin/hooks/lib/rewind/brief.mjs +332 -0
  9. package/plugin/hooks/lib/rewind/collect.mjs +328 -0
  10. package/plugin/hooks/lib/rewind/gauge.mjs +55 -0
  11. package/plugin/hooks/lib/rewind/next-step.mjs +77 -0
  12. package/plugin/hooks/lib/rewind/redact.mjs +60 -0
  13. package/plugin/hooks/lib/rewind/transcripts.mjs +211 -0
  14. package/plugin/hooks/lib/routes.mjs +79 -5
  15. package/plugin/hooks/lib/workflow-stack.mjs +213 -0
  16. package/plugin/hooks/post-tool-use.mjs +37 -1
  17. package/plugin/hooks/pre-invocation.mjs +91 -2
  18. package/plugin/hooks/session-start.mjs +26 -3
  19. package/plugin/hooks/stop.mjs +22 -2
  20. package/plugin/hud/looks.mjs +29 -0
  21. package/plugin/hud/render.mjs +234 -12
  22. package/plugin/plugin.json +1 -1
  23. package/plugin/skills/frontend-ui-ux/SKILL.md +12 -1
  24. package/plugin/skills/frontend-ui-ux/kit/components.css +417 -0
  25. package/plugin/skills/frontend-ui-ux/kit/fonts.json +22 -0
  26. package/plugin/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  27. package/plugin/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  28. package/plugin/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  29. package/plugin/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  30. package/plugin/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  31. package/plugin/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  32. package/plugin/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  33. package/plugin/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  34. package/plugin/skills/frontend-ui-ux/kit/ui.js +226 -0
  35. package/plugin/skills/frontend-ui-ux/references/house-styles.md +234 -0
  36. package/plugin/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  37. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
  38. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +30 -9
  39. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +20 -8
  40. package/plugin/skills/frontend-ui-ux/scripts/interface-probe.mjs +42 -9
  41. package/plugin/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  42. package/plugin/skills/lit-adhd/SKILL.md +157 -0
  43. package/plugin/skills/lit-adhd/references/card-examples.md +101 -0
  44. package/plugin/skills/lit-adhd/references/status-taxonomy.md +32 -0
  45. package/plugin/skills/lit-adhd/scripts/rewind.mjs +5 -0
  46. package/plugin/skills/lit-diagram-drawer/SKILL.md +5 -3
  47. package/plugin/skills/lit-diagram-drawer/references/drawing-rules.md +1 -1
  48. package/plugin/skills/lit-diagram-drawer/references/style-guide.md +21 -12
  49. package/plugin/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  50. package/plugin/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  51. package/plugin/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  52. package/plugin/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  53. package/plugin/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
  54. package/plugin/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  55. package/plugin/skills/lit-docx/SKILL.md +3 -3
  56. package/plugin/skills/lit-handoff/SKILL.md +1 -0
  57. package/plugin/skills/lit-hijack/SKILL.md +263 -0
  58. package/plugin/skills/lit-hijack/references/capture-and-provenance.md +100 -0
  59. package/plugin/skills/lit-hijack/references/clean-room-build.md +75 -0
  60. package/plugin/skills/lit-hijack/references/distil-and-licence.md +67 -0
  61. package/plugin/skills/lit-hijack/references/gap-and-port-design.md +100 -0
  62. package/plugin/skills/lit-hijack/references/parity-and-report.md +85 -0
  63. package/plugin/skills/lit-hijack/scripts/hijack.mjs +953 -0
  64. package/plugin/skills/lit-plan/SKILL.md +1 -1
  65. package/plugin/skills/lit-pptx/SKILL.md +8 -8
  66. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  67. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  68. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  69. package/plugin/skills/lit-pptx/fonts/provenance.json +32 -1
  70. package/plugin/skills/lit-pptx/references/agents/analyst.md +34 -56
  71. package/plugin/skills/lit-pptx/references/agents/antithesis.md +49 -67
  72. package/plugin/skills/lit-pptx/references/agents/architect.md +38 -51
  73. package/plugin/skills/lit-pptx/references/agents/critic.md +25 -41
  74. package/plugin/skills/lit-pptx/references/agents/synthesizer.md +37 -46
  75. package/plugin/skills/lit-pptx/references/agents/thesis.md +29 -49
  76. package/plugin/skills/lit-pptx/references/anti-slop-checklist.md +119 -145
  77. package/plugin/skills/lit-pptx/references/authoring-guide.md +187 -278
  78. package/plugin/skills/lit-pptx/references/consensus-protocol.md +99 -97
  79. package/plugin/skills/lit-pptx/references/data-display-cookbook.md +36 -137
  80. package/plugin/skills/lit-pptx/references/density-and-fill.md +147 -216
  81. package/plugin/skills/lit-pptx/references/design-system-azure.md +56 -85
  82. package/plugin/skills/lit-pptx/references/direction-step.md +134 -176
  83. package/plugin/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +114 -115
  84. package/plugin/skills/lit-pptx/references/examples/02-pitch-studio-ko.md +66 -66
  85. package/plugin/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +63 -63
  86. package/plugin/skills/lit-pptx/references/examples/04-business-review-night-en.md +96 -96
  87. package/plugin/skills/lit-pptx/references/examples/05-research-talk-paper-en.md +81 -81
  88. package/plugin/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +103 -103
  89. package/plugin/skills/lit-pptx/references/examples/07-data-review-night-en.md +100 -98
  90. package/plugin/skills/lit-pptx/references/examples/08-image-led-atlas-ko.md +76 -76
  91. package/plugin/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +96 -96
  92. package/plugin/skills/lit-pptx/references/examples/10-status-update-ledger-ko.md +80 -80
  93. package/plugin/skills/lit-pptx/references/examples/11-portfolio-studio-en.md +72 -72
  94. package/plugin/skills/lit-pptx/references/examples/12-research-tutorial-chalk-en.md +95 -95
  95. package/plugin/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
  96. package/plugin/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
  97. package/plugin/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
  98. package/plugin/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
  99. package/plugin/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
  100. package/plugin/skills/lit-pptx/references/interview-protocol.md +83 -102
  101. package/plugin/skills/lit-pptx/references/layout-families.md +161 -265
  102. package/plugin/skills/lit-pptx/references/stages/autopilot.md +30 -70
  103. package/plugin/skills/lit-pptx/references/stages/interview.md +36 -68
  104. package/plugin/skills/lit-pptx/references/stages/plan.md +26 -67
  105. package/plugin/skills/lit-pptx/references/title-treatments.md +93 -145
  106. package/plugin/skills/lit-pptx/references/tonalities/atlas.md +95 -108
  107. package/plugin/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
  108. package/plugin/skills/lit-pptx/references/tonalities/chalk.md +107 -122
  109. package/plugin/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
  110. package/plugin/skills/lit-pptx/references/tonalities/gazette.md +87 -111
  111. package/plugin/skills/lit-pptx/references/tonalities/ledger.md +96 -125
  112. package/plugin/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
  113. package/plugin/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
  114. package/plugin/skills/lit-pptx/references/tonalities/night.md +104 -131
  115. package/plugin/skills/lit-pptx/references/tonalities/paper.md +114 -130
  116. package/plugin/skills/lit-pptx/references/tonalities/riso.md +137 -0
  117. package/plugin/skills/lit-pptx/references/tonalities/signal.md +96 -103
  118. package/plugin/skills/lit-pptx/references/tonalities/studio.md +81 -112
  119. package/plugin/skills/lit-pptx/scripts/compile-deck.js +4 -6
  120. package/plugin/skills/lit-pptx/scripts/craft_extras.py +135 -91
  121. package/plugin/skills/lit-pptx/scripts/deck_craft.py +1 -1
  122. package/plugin/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  123. package/plugin/skills/lit-pptx/scripts/layout_inventory.py +1 -1
  124. package/plugin/skills/lit-pptx/scripts/learn_template.py +1 -1
  125. package/plugin/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  126. package/plugin/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  127. package/plugin/skills/lit-pptx/scripts/lib/render-pack.js +370 -563
  128. package/plugin/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  129. package/plugin/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  130. package/plugin/skills/lit-pptx/scripts/qa_deck.py +6 -6
  131. package/plugin/skills/lit-pptx/scripts/render_pages.py +31 -0
  132. package/plugin/skills/lit-pptx/scripts/validate_pptx.py +1 -1
  133. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v1.md +167 -191
  134. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v2.md +117 -166
  135. package/plugin/skills/lit-pptx/specs/template-enrollment-contract.md +307 -330
  136. package/plugin/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  137. package/plugin/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  138. package/plugin/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  139. package/plugin/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
  140. package/plugin/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  141. package/plugin/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  142. package/plugin/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  143. package/plugin/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  144. package/plugin/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  145. package/plugin/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  146. package/plugin/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  147. package/plugin/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  148. package/plugin/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  149. package/plugin/skills/lit-schematic/SKILL.md +114 -0
  150. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  151. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  152. package/plugin/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  153. package/plugin/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  154. package/plugin/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  155. package/plugin/skills/lit-schematic/references/isometric-craft.md +101 -0
  156. package/plugin/skills/lit-schematic/references/journal-figures.md +72 -0
  157. package/plugin/skills/lit-schematic/references/kit-api.md +134 -0
  158. package/plugin/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  159. package/plugin/skills/lit-schematic/references/pid-drafting.md +103 -0
  160. package/plugin/skills/lit-schematic/references/pid-symbols.md +163 -0
  161. package/plugin/skills/lit-schematic/references/verification.md +100 -0
  162. package/plugin/skills/lit-schematic/scripts/doctor.mjs +57 -0
  163. package/plugin/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  164. package/plugin/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
  165. package/plugin/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  166. package/plugin/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  167. package/plugin/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  168. package/plugin/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  169. package/plugin/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  170. package/plugin/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  171. package/plugin/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  172. package/plugin/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  173. package/plugin/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  174. package/plugin/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  175. package/plugin/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  176. package/plugin/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  177. package/plugin/skills/lit-schematic/scripts/motion.mjs +129 -0
  178. package/plugin/skills/lit-schematic/scripts/qa.mjs +92 -0
  179. package/plugin/skills/lit-schematic/scripts/render.mjs +233 -0
  180. package/plugin/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  181. package/plugin/skills/lit-scientific-visualization/SKILL.md +17 -6
  182. package/plugin/skills/lit-typographic-motion/SKILL.md +58 -48
  183. package/plugin/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +13 -2
  184. package/plugin/skills/lit-typographic-motion/engine/blender/runner.py +218 -0
  185. package/plugin/skills/lit-typographic-motion/engine/core/presets.mjs +1 -1
  186. package/plugin/skills/lit-typographic-motion/engine/node/analysis.mjs +65 -1
  187. package/plugin/skills/lit-typographic-motion/engine/node/assets.mjs +298 -0
  188. package/plugin/skills/lit-typographic-motion/engine/node/blender.mjs +143 -0
  189. package/plugin/skills/lit-typographic-motion/engine/node/board.mjs +136 -0
  190. package/plugin/skills/lit-typographic-motion/engine/node/brief.mjs +7 -1
  191. package/plugin/skills/lit-typographic-motion/engine/node/chrome.mjs +9 -12
  192. package/plugin/skills/lit-typographic-motion/engine/node/cover-assets.mjs +5 -3
  193. package/plugin/skills/lit-typographic-motion/engine/node/cover-capture.mjs +7 -6
  194. package/plugin/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +37 -4
  195. package/plugin/skills/lit-typographic-motion/engine/node/cover.mjs +19 -8
  196. package/plugin/skills/lit-typographic-motion/engine/node/done.mjs +45 -6
  197. package/plugin/skills/lit-typographic-motion/engine/node/frame-worker.mjs +7 -5
  198. package/plugin/skills/lit-typographic-motion/engine/node/gallery.mjs +121 -0
  199. package/plugin/skills/lit-typographic-motion/engine/node/host.mjs +34 -0
  200. package/plugin/skills/lit-typographic-motion/engine/node/house.mjs +44 -0
  201. package/plugin/skills/lit-typographic-motion/engine/node/look.mjs +34 -20
  202. package/plugin/skills/lit-typographic-motion/engine/node/pipeline.mjs +19 -9
  203. package/plugin/skills/lit-typographic-motion/engine/node/scaffold.mjs +210 -0
  204. package/plugin/skills/lit-typographic-motion/engine/node/score.mjs +639 -0
  205. package/plugin/skills/lit-typographic-motion/engine/node/sound-cli.mjs +21 -4
  206. package/plugin/skills/lit-typographic-motion/engine/node/sound.mjs +127 -29
  207. package/plugin/skills/lit-typographic-motion/engine/node/stage-capture.mjs +7 -6
  208. package/plugin/skills/lit-typographic-motion/engine/node/stage-gate.mjs +59 -5
  209. package/plugin/skills/lit-typographic-motion/engine/node/stage-qa.mjs +141 -9
  210. package/plugin/skills/lit-typographic-motion/engine/node/stage-serve.mjs +28 -5
  211. package/plugin/skills/lit-typographic-motion/engine/node/stage.mjs +82 -14
  212. package/plugin/skills/lit-typographic-motion/engine/node/styles.mjs +213 -0
  213. package/plugin/skills/lit-typographic-motion/engine/node/treatment.mjs +311 -10
  214. package/plugin/skills/lit-typographic-motion/engine/stage/cover-init.js +14 -2
  215. package/plugin/skills/lit-typographic-motion/engine/stage/init.js +11 -1
  216. package/plugin/skills/lit-typographic-motion/engine/stage/qa.js +6 -1
  217. package/plugin/skills/lit-typographic-motion/engine/stage/stage-kit.js +83 -0
  218. package/plugin/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  219. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  220. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  221. package/plugin/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  222. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/expected.json +69 -0
  223. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
  224. package/plugin/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +6 -4
  225. package/plugin/skills/lit-typographic-motion/recipes/painted-light/expected.json +4 -2
  226. package/plugin/skills/lit-typographic-motion/recipes/weight-tide/expected.json +7 -5
  227. package/plugin/skills/lit-typographic-motion/references/cover.md +394 -443
  228. package/plugin/skills/lit-typographic-motion/references/craft-loop.md +57 -87
  229. package/plugin/skills/lit-typographic-motion/references/depth.md +122 -0
  230. package/plugin/skills/lit-typographic-motion/references/look.md +94 -129
  231. package/plugin/skills/lit-typographic-motion/references/runtime.md +58 -91
  232. package/plugin/skills/lit-typographic-motion/references/sound.md +130 -99
  233. package/plugin/skills/lit-typographic-motion/references/stage.md +190 -215
  234. package/plugin/skills/lit-typographic-motion/references/studio.md +245 -0
  235. package/plugin/skills/lit-typographic-motion/references/style-bibles.md +108 -97
  236. package/plugin/skills/lit-typographic-motion/references/treatment.md +191 -143
  237. package/plugin/skills/lit-typographic-motion/scripts/motion-doctor.mjs +17 -5
  238. package/plugin/skills/lit-typographic-motion/scripts/motion.mjs +47 -7
  239. package/plugin/skills/lit-typographic-motion/styles/paper.json +41 -0
  240. package/plugin/skills/lit-typographic-motion/styles/swiss-signal.json +41 -0
  241. package/plugin/skills/lit-typographic-motion/styles/terminalcore.json +42 -0
  242. package/plugin/skills/lit-typographic-motion/styles/tidal.json +41 -0
  243. package/plugin/skills/litresearch/SKILL.md +1 -0
  244. package/plugin/skills/readme-studio/SKILL.md +2 -0
  245. package/plugin/skills/readme-studio/templates/hyperframes-cover/package-lock.json +3 -3
  246. package/plugin/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  247. package/plugin/skills/review-work/SKILL.md +1 -1
  248. package/plugin/skills/start-work/SKILL.md +1 -1
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/env node
2
+ // Design lock: the one place a build picks its look. It writes the chosen house style into the
3
+ // project as design.lock.json plus ui/tokens.css, ui/components.css, ui/ui.js and the fonts, and
4
+ // the interface probe then checks the rendered page against that lock (DS-* rules).
5
+ //
6
+ // node design-lock.mjs list
7
+ // node design-lock.mjs init --family <landing|workspace|settings> --dir <project> [--style <id>]
8
+ // [--brief "<request text>"] [--density rich|calm] [--moment <kind> --moment-note "<what it is>"
9
+ // [--moment-place "<where it sits>"]] [--scaffold] [--from <style.json>] [--force]
10
+ // node design-lock.mjs moment --dir <project> --kind <kind> --note "<what it is>" [--place "<where>"]
11
+ // Without --style a style the brief names by keyword applies (styleForBrief), else the family
12
+ // default (DEFAULT_STYLE_BY_FAMILY).
13
+ // node design-lock.mjs match "<request text>"
14
+ // node design-lock.mjs show --dir <project>
15
+ //
16
+ // `--from` takes a brand's own style file in the same schema as kit/styles/*.json; its id must not
17
+ // reuse a kit style id. Nothing here fetches from the network or installs anything.
18
+ import { createHash } from "node:crypto";
19
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
20
+ import { dirname, join, resolve } from "node:path";
21
+ import process from "node:process";
22
+ import { fileURLToPath } from "node:url";
23
+
24
+ const SKILL_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
25
+ const KIT = join(SKILL_ROOT, "kit");
26
+ export const LOCK_FILE = "design.lock.json";
27
+ export const LOCK_SCHEMA = "litfamily.design-lock/v1";
28
+ export const STYLE_SCHEMA = "litfamily.frontend-style/v1";
29
+ export const FAMILIES = Object.freeze({
30
+ landing: "read-once pages: landing, product, launch, portfolio, docs home",
31
+ workspace: "screens people work in: dashboards, consoles, admin, tools, tables",
32
+ settings: "guided forms: settings, account, onboarding, checkout steps",
33
+ });
34
+ // The user-decided defaults (2026-10-25) when a brief gives no visual direction: read-once pages
35
+ // keep the authored field-notes profile; work surfaces use graphite. meadow is never a default.
36
+ export const DEFAULT_STYLE_BY_FAMILY = Object.freeze({ landing: "field-notes", workspace: "graphite", settings: "graphite" });
37
+ // Round 2 (user decision A, 2026-10-25): the lock fixes the look, and every page names the one place
38
+ // it is allowed to be bold. Read-once pages take a bold moment above the fold; work surfaces stay
39
+ // calm and take a small one. The probe checks the declared kind against [data-ui-moment] (DS-008).
40
+ export const MOMENT_SCALE_BY_FAMILY = Object.freeze({ landing: "bold", workspace: "small", settings: "small" });
41
+ export const MOMENT_KINDS = Object.freeze({
42
+ bold: Object.freeze(["hero-composition", "type-set-piece", "data-moment", "diagram", "motion-detail", "interactive-object"]),
43
+ small: Object.freeze(["chart", "empty-state", "header-detail"]),
44
+ });
45
+ export const MOMENT_SELECTOR = "[data-ui-moment]";
46
+ export const COLOR_ROLES = Object.freeze(["canvas", "surface", "sunken", "ink", "ink-2", "ink-3", "line", "line-strong", "control", "accent", "accent-hover", "on-accent", "accent-wash", "accent-ink", "accent-2", "accent-2-ink", "accent-2-wash", "on-accent-2", "support", "support-ink", "focus", "positive", "positive-wash", "warning", "warning-wash", "negative", "negative-wash", "info", "info-wash", "chart-1", "chart-2", "chart-3", "chart-4", "chart-5"]);
47
+ const SCALE_KEYS = ["xs", "sm", "md", "base", "lg", "xl", "2xl", "3xl", "4xl", "5xl"];
48
+ const RADIUS_KEYS = ["xs", "sm", "md", "lg", "pill"];
49
+ const HEX = /^#[0-9a-f]{6}$/u;
50
+ // The shape block carries what makes a register more than a palette: border weights, which role
51
+ // draws outlines, the elevation grammar the probe enforces (DS-007), how a button presses, and the
52
+ // case and family of meta text. Every value is closed so components.css can stay token-only.
53
+ export const SHAPE_CHOICES = Object.freeze({
54
+ surface_line: ["line", "line-strong", "ink"],
55
+ control_edge: ["control", "ink"],
56
+ elevation: ["soft", "offset", "flat"],
57
+ press: ["scale", "shift", "none"],
58
+ meta_font: ["text", "mono"],
59
+ meta_case: ["none", "uppercase"],
60
+ display_case: ["none", "uppercase"],
61
+ canvas_pattern: ["none", "dots", "grid", "plot"],
62
+ heading_font: ["display", "mono"],
63
+ panel_head: ["plain", "inverse", "accent"],
64
+ section_marks: ["none", "coord"],
65
+ });
66
+
67
+ export function kitStyles() {
68
+ return readdirSync(join(KIT, "styles")).filter((name) => name.endsWith(".json")).sort()
69
+ .map((name) => JSON.parse(readFileSync(join(KIT, "styles", name), "utf8")));
70
+ }
71
+
72
+ // Returns a list of problems; an empty list means the style can be locked.
73
+ export function validateStyle(style) {
74
+ const issues = [];
75
+ if (!style || typeof style !== "object") return ["style is not an object"];
76
+ if (style.schema_id !== STYLE_SCHEMA) issues.push(`schema_id must be ${STYLE_SCHEMA}`);
77
+ if (!/^[a-z][a-z0-9-]{1,31}$/u.test(style.id ?? "")) issues.push("id must be a short kebab-case name");
78
+ for (const role of ["text", "display", "mono"]) if (typeof style.fonts?.[role] !== "string" || !style.fonts[role].trim()) issues.push(`fonts.${role} is required`);
79
+ for (const key of SCALE_KEYS) if (!Number.isFinite(style.type?.scale_px?.[key])) issues.push(`type.scale_px.${key} is required`);
80
+ if (!(style.type?.display_px?.min > 0 && style.type.display_px.max >= style.type.display_px.min)) issues.push("type.display_px needs min ≤ max");
81
+ if (!(style.type?.moment_px?.max > style.type?.display_px?.max)) issues.push("type.moment_px.max must sit above type.display_px.max");
82
+ for (const key of ["text", "medium", "strong", "display"]) if (!Number.isFinite(style.type?.weights?.[key])) issues.push(`type.weights.${key} is required`);
83
+ for (const key of RADIUS_KEYS) if (!Number.isFinite(style.radius_px?.[key])) issues.push(`radius_px.${key} is required`);
84
+ if (!Array.isArray(style.space_px) || style.space_px.some((v) => !Number.isInteger(v) || v % 4 !== 0)) issues.push("space_px must be multiples of 4");
85
+ for (const theme of ["light", "dark"]) {
86
+ for (const role of COLOR_ROLES) if (!HEX.test(style.color?.[theme]?.[role] ?? "")) issues.push(`color.${theme}.${role} must be #rrggbb`);
87
+ }
88
+ const shape = style.shape;
89
+ for (const key of ["rule", "surface", "control"]) if (!(Number.isInteger(shape?.border_px?.[key]) && shape.border_px[key] >= 1 && shape.border_px[key] <= 4)) issues.push(`shape.border_px.${key} must be 1 to 4`);
90
+ for (const [key, allowed] of Object.entries(SHAPE_CHOICES)) if (!allowed.includes(shape?.[key])) issues.push(`shape.${key} must be one of ${allowed.join(", ")}`);
91
+ for (const key of ["surface", "control"]) if (!(Number.isInteger(shape?.offset_px?.[key]) && shape.offset_px[key] >= 0)) issues.push(`shape.offset_px.${key} is required`);
92
+ if (shape?.elevation === "offset" && !(shape.offset_px?.surface > 0 && shape.offset_px?.control > 0)) issues.push("an offset elevation needs offset_px above 0");
93
+ if (shape?.elevation !== "offset" && (shape?.offset_px?.surface || shape?.offset_px?.control || shape?.press === "shift")) issues.push("offset_px and press shift belong to an offset elevation");
94
+ for (const key of ["keywords", "signature", "forbid"]) if (!Array.isArray(style[key]) || !style[key].length || style[key].some((item) => typeof item !== "string" || !item.trim())) issues.push(`${key} needs at least one entry`);
95
+ return issues;
96
+ }
97
+
98
+ // The kit style a brief names, or null. A brief that names a register by one of a style's keywords
99
+ // picks it; when two styles match ("neo-brutalism" also contains "brutalism") the longer keyword
100
+ // wins. Latin keywords must start at a word boundary so "crt" does not match inside a word.
101
+ export function styleForBrief(text, styles = kitStyles()) {
102
+ const haystack = String(text ?? "").toLowerCase();
103
+ let best = null;
104
+ for (const style of styles) {
105
+ for (const keyword of style.keywords ?? []) {
106
+ const word = keyword.toLowerCase();
107
+ const escaped = word.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
108
+ const pattern = /^[a-z]/u.test(word) ? new RegExp(`(?<![a-z0-9])${escaped}`, "u") : new RegExp(escaped, "u");
109
+ if (pattern.test(haystack) && (!best || word.length > best.keyword.length)) best = { id: style.id, keyword: word };
110
+ }
111
+ }
112
+ return best;
113
+ }
114
+
115
+ // Density (user rule, 2026-10-25): rich is the default register; calm only when the request asks
116
+ // for a minimal, quiet or restrained page, or --density calm. Calm keeps the broad, flat page the
117
+ // kit shipped before; rich tightens the section rhythm and turns on texture and a glow token.
118
+ export const DENSITIES = Object.freeze(["rich", "calm"]);
119
+ const CALM_WORDS = [/(?<![a-z])minimal(?:ist|ism)?(?![a-z])/u, /(?<![a-z])(?:calm|quiet|restrained|understated|pared[- ]back|sparse)(?![a-z])/u, /미니멀/u, /차분/u, /절제/u, /담백/u, /간결/u];
120
+ export function densityForBrief(text) {
121
+ const haystack = String(text ?? "").toLowerCase();
122
+ return CALM_WORDS.some((pattern) => pattern.test(haystack)) ? "calm" : "rich";
123
+ }
124
+ const checkDensity = (density) => {
125
+ if (!DENSITIES.includes(density)) throw new Error(`--density must be rich or calm, not "${density}"`);
126
+ return density;
127
+ };
128
+
129
+ const fontStack = (family, kind) => {
130
+ const tail = kind === "mono"
131
+ ? `ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace`
132
+ : `"Pretendard Variable", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif`;
133
+ return `"${family}", ${tail}`;
134
+ };
135
+
136
+ export function tokensCss(style, fontFiles, density = "rich") {
137
+ const calm = checkDensity(density) === "calm";
138
+ const t = style.type;
139
+ const { min, max } = t.display_px;
140
+ const slope = (max - min) / (1440 - 390);
141
+ const intercept = min - slope * 390;
142
+ const colors = (theme, indent = " ") => COLOR_ROLES.map((role) => `${indent}--c-${role}: ${style.color[theme][role]};`).join("\n");
143
+ const shape = style.shape;
144
+ const control = shape.offset_px.control;
145
+ const press = { scale: "scale(0.96)", shift: `translate(${control}px, ${control}px)`, none: "none" }[shape.press];
146
+ const grid = "linear-gradient(color-mix(in srgb, var(--c-line) 70%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--c-line) 70%, transparent) 1px, transparent 1px)";
147
+ // The plot grid: minor lines lighter than the grid style, a stronger line every five cells.
148
+ // Both stay on --c-line so body text keeps its contrast over every stop (CF-204) in light and dark.
149
+ const minor = grid.replaceAll("70%", "50%");
150
+ const major = grid.replaceAll("70%", "85%");
151
+ // Notebook dots are texture, so the calm register drops them; grid and plot are a register's structure and stay.
152
+ const dots = "radial-gradient(circle, color-mix(in srgb, var(--c-line-strong) 55%, transparent) 1px, transparent 1.5px)";
153
+ const pattern = { none: ["none", "auto"], dots: calm ? ["none", "auto"] : [dots, "24px 24px"], grid: [grid, "32px 32px"], plot: [`${minor}, ${major}`, "32px 32px, 32px 32px, 160px 160px, 160px 160px"] }[shape.canvas_pattern];
154
+ // A soft accent glow for one atmosphere surface; flat and offset registers keep their own elevation grammar (DS-007).
155
+ const glow = calm || shape.elevation !== "soft" ? "none" : "0 0 48px color-mix(in srgb, var(--c-accent) 30%, transparent), 0 0 96px color-mix(in srgb, var(--c-accent-2) 18%, transparent)";
156
+ const pad = calm ? { section: [64, 96, 128], hero: [48, 64, 80] } : { section: [48, 72, 96], hero: [40, 56, 64] };
157
+ const head = { plain: ["transparent", "inherit", "initial", 0], inverse: ["var(--c-ink)", "var(--c-canvas)", "var(--c-canvas)", 1], accent: ["var(--c-accent)", "var(--c-on-accent)", "var(--c-on-accent)", 1] }[shape.panel_head];
158
+ const moment = t.moment_px.max;
159
+ const momentSlope = (moment - min) / (1440 - 390);
160
+ const faces = fontFiles.map((font) => `@font-face {\n font-family: "${font.family}";\n src: url("fonts/${font.file}") format("woff2");\n font-weight: ${font.weight};\n font-style: normal;\n font-display: swap;\n}`).join("\n");
161
+ return `/* Generated by frontend-ui-ux scripts/design-lock.mjs for the "${style.id}" style. Do not edit by hand:
162
+ re-run design-lock.mjs, or change the style file and lock again. */
163
+ ${faces}
164
+ :root {
165
+ --ui-lock: "${style.id}";
166
+ --density: "${calm ? "calm" : "rich"}";
167
+ --font-text: ${fontStack(style.fonts.text, "text")};
168
+ --font-display: ${fontStack(style.fonts.display, "text")};
169
+ --font-mono: ${fontStack(style.fonts.mono, "mono")};
170
+ --font-text-ko: ${style.fonts.text === style.fonts.mono ? fontStack(style.fonts.display, "text") : "var(--font-text)"};
171
+ ${SCALE_KEYS.map((key) => ` --fs-${key}: ${t.scale_px[key]}px;`).join("\n")}
172
+ --fs-display: clamp(${min}px, ${intercept.toFixed(2)}px + ${(slope * 100).toFixed(3)}vw, ${max}px);
173
+ --fs-moment: clamp(${min}px, ${(min - momentSlope * 390).toFixed(2)}px + ${(momentSlope * 100).toFixed(3)}vw, ${moment}px);
174
+ --fw-text: ${t.weights.text};
175
+ --fw-medium: ${t.weights.medium};
176
+ --fw-strong: ${t.weights.strong};
177
+ --fw-display: ${t.weights.display};
178
+ --track-display: ${t.tracking_em.display}em;
179
+ --track-label: ${t.tracking_em.label}em;
180
+ --lh-body: ${t.leading.body};
181
+ --lh-tight: ${t.leading.tight};
182
+ --lh-display: ${t.leading.display_latin};
183
+ --lh-display-ko: ${t.leading.display_korean};
184
+ ${style.space_px.map((value) => ` --sp-${value}: ${value}px;`).join("\n")}
185
+ ${RADIUS_KEYS.map((key) => ` --radius-${key}: ${style.radius_px[key]}px;`).join("\n")}
186
+ --shadow-raised: ${style.shadow.raised};
187
+ --shadow-overlay: ${style.shadow.overlay};
188
+ --shadow-control: ${shape.elevation === "offset" ? `${control}px ${control}px 0 0 var(--c-ink)` : "none"};
189
+ --shadow-control-pressed: ${shape.elevation === "offset" ? "0 0 0 0 var(--c-ink)" : "none"};
190
+ --press: ${press};
191
+ --bw-rule: ${shape.border_px.rule}px;
192
+ --bw-surface: ${shape.border_px.surface}px;
193
+ --bw-control: ${shape.border_px.control}px;
194
+ --c-frame: var(--c-${shape.surface_line});
195
+ --control-edge: ${shape.control_edge === "ink" ? "var(--c-ink)" : "initial"};
196
+ --font-meta: ${shape.meta_font === "mono" ? "var(--font-mono)" : "var(--font-text)"};
197
+ --font-heading: ${shape.heading_font === "mono" ? "var(--font-mono)" : "var(--font-display)"};
198
+ --font-heading-ko: ${shape.heading_font === "mono" ? "var(--font-display)" : "var(--font-heading)"};
199
+ --panel-head-bg: ${head[0]};
200
+ --panel-head-ink: ${head[1]};
201
+ --panel-head-status: ${head[2]};
202
+ --panel-head-bleed: ${head[3]};
203
+ --section-marks: ${shape.section_marks === "coord" ? "block" : "none"};
204
+ --meta-case: ${shape.meta_case};
205
+ --display-case: ${shape.display_case};
206
+ --canvas-pattern: ${pattern[0]};
207
+ --canvas-pattern-size: ${pattern[1]};
208
+ --glow: ${glow};
209
+ --dur-fast: ${style.motion.fast_ms}ms;
210
+ --dur-ui: ${style.motion.ui_ms}ms;
211
+ --dur-enter: ${style.motion.enter_ms}ms;
212
+ --dur-exit: ${style.motion.exit_ms}ms;
213
+ --ease: ${style.motion.ease};
214
+ --gutter: 16px;
215
+ --work-gutter: 16px;
216
+ --section-pad: ${pad.section[0]}px;
217
+ --hero-pad: ${pad.hero[0]}px;
218
+ ${colors("light")}
219
+ }
220
+ @media (min-width: 640px) { :root { --gutter: 24px; --work-gutter: 24px; --section-pad: ${pad.section[1]}px; --hero-pad: ${pad.hero[1]}px; } }
221
+ @media (min-width: 1024px) { :root { --gutter: 40px; --work-gutter: 32px; --section-pad: ${pad.section[2]}px; --hero-pad: ${pad.hero[2]}px; } }
222
+ @media (prefers-color-scheme: dark) {
223
+ :root:not([data-theme="light"]) {
224
+ ${colors("dark", " ")}
225
+ }
226
+ }
227
+ :root[data-theme="dark"] {
228
+ ${colors("dark")}
229
+ }
230
+ `;
231
+ }
232
+
233
+ const sha256 = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");
234
+
235
+ function kitFonts() {
236
+ const manifest = JSON.parse(readFileSync(join(KIT, "fonts.json"), "utf8"));
237
+ return manifest.fonts.map((font) => {
238
+ const source = resolve(KIT, font.source);
239
+ const licence = resolve(KIT, font.licence.source);
240
+ if (!existsSync(source) || sha256(source) !== font.sha256) throw new Error(`font ${font.file} is missing or does not match kit/fonts.json`);
241
+ if (!existsSync(licence) || sha256(licence) !== font.licence.sha256) throw new Error(`licence for ${font.family} is missing or does not match kit/fonts.json`);
242
+ return { ...font, sourcePath: source, licencePath: licence };
243
+ });
244
+ }
245
+
246
+ // What a moment is and where it sits. A lock without a kind is valid to write (the page is not
247
+ // built yet) but DS-008 fails every render until the moment is declared and present.
248
+ function momentRecord(family, { kind = null, note = null, place = null } = {}) {
249
+ const scale = MOMENT_SCALE_BY_FAMILY[family];
250
+ if (kind !== null) {
251
+ const all = [...MOMENT_KINDS.bold, ...MOMENT_KINDS.small];
252
+ if (!all.includes(kind)) throw new Error(`unknown moment "${kind}"; one of ${all.join(", ")}`);
253
+ if (!MOMENT_KINDS[scale].includes(kind)) throw new Error(`a ${scale === "small" ? "work surface takes a small" : "read-once page takes a bold"} moment: ${MOMENT_KINDS[scale].join(", ")}`);
254
+ if (!String(note ?? "").trim()) throw new Error("a moment needs --moment-note: what it shows, in a few words");
255
+ }
256
+ return { scale, kind, note: kind === null ? null : String(note).trim(), place: kind === null || !String(place ?? "").trim() ? null : String(place).trim(), selector: MOMENT_SELECTOR, above_fold: scale === "bold" };
257
+ }
258
+
259
+ export function lockRecord(style, family, moment = {}, density = "rich") {
260
+ return {
261
+ schema_id: LOCK_SCHEMA,
262
+ style: style.id,
263
+ family,
264
+ density: checkDensity(density),
265
+ fonts: [...new Set([style.fonts.text, style.fonts.display, style.fonts.mono])],
266
+ type: { scale_px: Object.values(style.type.scale_px), display_px: style.type.display_px, moment_px: style.type.moment_px },
267
+ radius_px: [...new Set([0, ...RADIUS_KEYS.map((key) => style.radius_px[key])])],
268
+ space_px: style.space_px,
269
+ colors: { light: style.color.light, dark: style.color.dark },
270
+ elevation: style.shape.elevation,
271
+ files: { tokens: "ui/tokens.css", components: "ui/components.css", script: "ui/ui.js" },
272
+ accent_art: style.accent_art ?? "none",
273
+ moment: momentRecord(family, moment),
274
+ };
275
+ }
276
+
277
+ export function setMoment({ dir, kind, note, place = null }) {
278
+ const lockPath = join(resolve(dir), LOCK_FILE);
279
+ const lock = JSON.parse(readFileSync(lockPath, "utf8"));
280
+ lock.moment = momentRecord(lock.family, { kind, note, place });
281
+ writeFileSync(lockPath, `${JSON.stringify(lock, null, 2)}\n`);
282
+ return lock.moment;
283
+ }
284
+
285
+ export function initLock({ styleId = null, family, dir, scaffold = false, from = null, force = false, brief = null, moment = null, momentNote = null, momentPlace = null, density = null }) {
286
+ if (!FAMILIES[family]) throw new Error(`--family must be one of ${Object.keys(FAMILIES).join(", ")}`);
287
+ const register = checkDensity(density ?? densityForBrief(brief));
288
+ const declared = momentRecord(family, { kind: moment, note: momentNote, place: momentPlace });
289
+ const styles = kitStyles();
290
+ let style;
291
+ if (from) {
292
+ style = JSON.parse(readFileSync(resolve(from), "utf8"));
293
+ if (styles.some((kit) => kit.id === style.id)) throw new Error(`--from style id "${style.id}" reuses a kit style id; give the brand style its own id`);
294
+ } else {
295
+ style = styles.find((kit) => kit.id === (styleId ?? styleForBrief(brief, styles)?.id ?? DEFAULT_STYLE_BY_FAMILY[family]));
296
+ if (!style) throw new Error(`unknown style "${styleId}"; run \`design-lock.mjs list\``);
297
+ }
298
+ const issues = validateStyle(style);
299
+ if (issues.length) throw new Error(`style ${style.id} cannot be locked:\n- ${issues.join("\n- ")}`);
300
+ const project = resolve(dir);
301
+ mkdirSync(join(project, "ui", "fonts"), { recursive: true });
302
+ const lockPath = join(project, LOCK_FILE);
303
+ if (existsSync(lockPath) && !force) {
304
+ const current = JSON.parse(readFileSync(lockPath, "utf8"));
305
+ if (current.style !== style.id) throw new Error(`${LOCK_FILE} already locks "${current.style}"; pass --force only if the user changed the direction`);
306
+ }
307
+ const fonts = kitFonts();
308
+ for (const font of fonts) {
309
+ copyFileSync(font.sourcePath, join(project, "ui", "fonts", font.file));
310
+ copyFileSync(font.licencePath, join(project, "ui", "fonts", font.licence.file));
311
+ }
312
+ writeFileSync(join(project, "ui", "tokens.css"), tokensCss(style, fonts, register));
313
+ copyFileSync(join(KIT, "components.css"), join(project, "ui", "components.css"));
314
+ copyFileSync(join(KIT, "ui.js"), join(project, "ui", "ui.js"));
315
+ writeFileSync(lockPath, `${JSON.stringify({ ...lockRecord(style, family, {}, register), moment: declared }, null, 2)}\n`);
316
+ let scaffolded = null;
317
+ if (scaffold) {
318
+ const page = join(project, "index.html");
319
+ if (existsSync(page) && !force) scaffolded = "kept existing index.html";
320
+ else {
321
+ copyFileSync(join(KIT, "layouts", `${family}.html`), page);
322
+ scaffolded = "index.html";
323
+ }
324
+ }
325
+ return { style, family, project, scaffolded, density: register };
326
+ }
327
+
328
+ function parse(argv) {
329
+ const [command, ...rest] = argv;
330
+ const options = { command };
331
+ for (let i = 0; i < rest.length; i += 1) {
332
+ const arg = rest[i];
333
+ if (arg === "--scaffold" || arg === "--force") options[arg.slice(2)] = true;
334
+ else if (["--style", "--family", "--dir", "--from", "--brief", "--moment", "--moment-note", "--moment-place", "--density", "--kind", "--note", "--place"].includes(arg)) options[arg.slice(2)] = rest[++i];
335
+ else if (command === "match" && options.text === undefined) options.text = arg;
336
+ else throw new Error(`unknown argument ${arg}`);
337
+ }
338
+ return options;
339
+ }
340
+
341
+ function main(argv) {
342
+ const options = parse(argv);
343
+ if (options.command === "list") {
344
+ for (const style of kitStyles()) {
345
+ console.log(`${style.id} — ${style.name}\n ${style.summary}\n use when: ${style.use_when.join("; ")}\n avoid when: ${style.avoid_when.join("; ")}\n picked by: ${style.keywords.join(", ")}\n signature: ${style.signature.join("; ")}\n never: ${style.forbid.join("; ")}\n`);
346
+ }
347
+ console.log("Families (layout starters in kit/layouts/):");
348
+ for (const [id, text] of Object.entries(FAMILIES)) console.log(` ${id} — ${text} (default style: ${DEFAULT_STYLE_BY_FAMILY[id]})\n moments (${id}): ${MOMENT_KINDS[MOMENT_SCALE_BY_FAMILY[id]].join(", ")}`);
349
+ return 0;
350
+ }
351
+ if (options.command === "init") {
352
+ if (!options.dir || !options.family) throw new Error("init needs --family and --dir (--style or --from only to override the family default)");
353
+ const result = initLock({ styleId: options.style, family: options.family, dir: options.dir, scaffold: options.scaffold, from: options.from, force: options.force, brief: options.brief, density: options.density ?? null, moment: options.moment ?? null, momentNote: options["moment-note"] ?? null, momentPlace: options["moment-place"] ?? null });
354
+ console.log(`Locked "${result.style.id}" (${result.family}, ${result.density}) in ${result.project}`);
355
+ console.log(`Wrote ${LOCK_FILE}, ui/tokens.css, ui/components.css, ui/ui.js and ui/fonts/.${result.scaffolded ? ` Scaffold: ${result.scaffolded}.` : ""}`);
356
+ console.log("Link ui/tokens.css then ui/components.css (and ui/ui.js with defer when you use charts, sortable tables or tabs).");
357
+ console.log("Build with the kit's ui-* classes and var(--c-*), var(--fs-*), var(--sp-*), var(--radius-*) only; the interface probe checks the page against this lock.");
358
+ const declared = JSON.parse(readFileSync(join(result.project, LOCK_FILE), "utf8")).moment;
359
+ console.log(declared.kind
360
+ ? `Signature moment: ${declared.kind} (${declared.note}). Mark that one element with data-ui-moment="${declared.kind}"${declared.above_fold ? " in the first screen" : ""}.`
361
+ : `No signature moment yet: decide the ${declared.scale} moment (${MOMENT_KINDS[declared.scale].join(", ")}) and record it with \`design-lock.mjs moment\`; the probe fails the page until it is declared and present (DS-008).`);
362
+ return 0;
363
+ }
364
+ if (options.command === "moment") {
365
+ if (!options.dir || !options.kind) throw new Error("moment needs --dir, --kind and --note");
366
+ const moment = setMoment({ dir: options.dir, kind: options.kind, note: options.note, place: options.place ?? null });
367
+ console.log(`Recorded ${moment.scale} moment ${moment.kind}: mark it with data-ui-moment="${moment.kind}"${moment.above_fold ? " in the first screen" : ""}.`);
368
+ return 0;
369
+ }
370
+ if (options.command === "match") {
371
+ const hit = styleForBrief(options.text);
372
+ console.log(hit ? `${hit.id} (keyword "${hit.keyword}")` : "no style named; the family default applies");
373
+ const density = densityForBrief(options.text);
374
+ console.log(`density: ${density}${density === "calm" ? " (the request asks for a calm page)" : " (the default; calm only when the request asks)"}`);
375
+ return 0;
376
+ }
377
+ if (options.command === "show") {
378
+ const lock = JSON.parse(readFileSync(join(resolve(options.dir ?? "."), LOCK_FILE), "utf8"));
379
+ console.log(JSON.stringify({ style: lock.style, family: lock.family, density: lock.density ?? null, fonts: lock.fonts, type: lock.type, radius_px: lock.radius_px, moment: lock.moment ?? null }, null, 2));
380
+ return 0;
381
+ }
382
+ throw new Error("usage: design-lock.mjs list | init [--style <id>] [--brief <text>] [--density rich|calm] --family <landing|workspace|settings> --dir <project> [--moment <kind> --moment-note <text> [--moment-place <text>]] [--scaffold] [--from <style.json>] [--force] | moment --dir <project> --kind <kind> --note <text> [--place <text>] | match <text> | show --dir <project>");
383
+ }
384
+
385
+ const startedDirectly = () => {
386
+ try {
387
+ return Boolean(process.argv[1]) && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
388
+ } catch {
389
+ return false;
390
+ }
391
+ };
392
+
393
+ if (startedDirectly()) {
394
+ try {
395
+ process.exitCode = main(process.argv.slice(2));
396
+ } catch (error) {
397
+ console.error(`design-lock: ${error.message}`);
398
+ process.exitCode = 1;
399
+ }
400
+ }
@@ -0,0 +1,196 @@
1
+ // In-page design-lock conformance (DS-001..DS-008). interface-probe.mjs serialises this function
2
+ // into the page, so it may not import anything or close over module scope; every threshold comes
3
+ // from the rule table through `options.rules`, and the lock arrives as `options.lock`.
4
+ export function measureLock(options) {
5
+ const { rules, limits, lock } = options;
6
+ const findings = [];
7
+ const notVerified = [];
8
+ const push = (rule, selector, value, threshold, severity) => {
9
+ if (findings.filter((f) => f.rule === rule).length >= limits.findingsPerRule) return;
10
+ findings.push({ rule, severity: severity ?? rules[rule].severity, tier: rules[rule].tier, selector, value, threshold });
11
+ };
12
+ const describe = (el) => {
13
+ if (el.id) return `#${el.id}`;
14
+ const cls = [...el.classList].slice(0, 2).map((c) => `.${c}`).join("");
15
+ return `${el.tagName.toLowerCase()}${cls}`;
16
+ };
17
+ const exempt = (el) => Boolean(el.closest("[data-lock-exempt], img, video, canvas, iframe, picture, object"));
18
+ const visible = (el) => {
19
+ if (typeof el.checkVisibility === "function" && !el.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true })) return false;
20
+ const box = el.getBoundingClientRect();
21
+ return box.width >= 1 && box.height >= 1;
22
+ };
23
+
24
+ // DS-001: the generated tokens.css carries the lock id on :root.
25
+ const applied = getComputedStyle(document.documentElement).getPropertyValue(rules["DS-001"].threshold.property).trim().replace(/^["']|["']$/gu, "");
26
+ if (applied !== lock.style) {
27
+ push("DS-001", ":root", applied ? `${rules["DS-001"].threshold.property}: ${applied}` : `${rules["DS-001"].threshold.property} missing`, `"${lock.style}" from design.lock.json`);
28
+ return { findings, notVerified };
29
+ }
30
+
31
+ const parse = (value) => {
32
+ let match = /^rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?\)$/u.exec(value);
33
+ if (match) return { rgb: [Number(match[1]), Number(match[2]), Number(match[3])], alpha: match[4] === undefined ? 1 : Number(match[4]) };
34
+ match = /^color\(srgb\s+([-\d.e]+)\s+([-\d.e]+)\s+([-\d.e]+)(?:\s*\/\s*([\d.]+))?\)$/u.exec(value);
35
+ if (match) return { rgb: [match[1], match[2], match[3]].map((n) => Math.round(Number(n) * 255)), alpha: match[4] === undefined ? 1 : Number(match[4]) };
36
+ return null;
37
+ };
38
+ const hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
39
+ const palette = [...Object.values(lock.colors.light), ...Object.values(lock.colors.dark)].map(hex);
40
+ const tolerance = rules["DS-003"].threshold.channelTolerance;
41
+ const onPalette = (rgb) => palette.some((p) => Math.abs(p[0] - rgb[0]) <= tolerance && Math.abs(p[1] - rgb[1]) <= tolerance && Math.abs(p[2] - rgb[2]) <= tolerance);
42
+ const toHex = (rgb) => `#${rgb.map((n) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, "0")).join("")}`;
43
+ const families = new Set(lock.fonts.map((f) => f.toLowerCase()));
44
+ const sizes = lock.type.scale_px;
45
+ const display = lock.type.display_px;
46
+ // Inside the declared signature moment type may run past the display range up to the lock's ceiling.
47
+ const momentMax = lock.type.moment_px?.max ?? display.max;
48
+ const momentAttr = rules["DS-008"].threshold.attribute;
49
+ const sizeTolerance = rules["DS-004"].threshold.tolerancePx;
50
+ const radii = lock.radius_px;
51
+ const radiusTolerance = rules["DS-005"].threshold.tolerancePx;
52
+
53
+ const offColours = new Map();
54
+ const offFamilies = new Map();
55
+ const offSizes = new Map();
56
+ const offRadii = new Map();
57
+ const offShadows = new Map();
58
+ let unparsed = 0;
59
+ // DS-007: the lock names an elevation grammar. "flat" allows only rings (no blur, no offset past a
60
+ // hairline); "offset" allows hard offsets but no blur; "soft" is left to CF-403. Insets never count.
61
+ const elevation = lock.elevation ?? "soft";
62
+ const hairline = rules["DS-007"].threshold.hairlinePx;
63
+ const shadowLengths = (value) => (value === "none" ? [] : value.split(/,(?![^()]*\))/u)).filter((part) => !/\binset\b/u.test(part))
64
+ .map((part) => part.replace(/\b(?:rgba?|color|hsla?|oklch|lab|lch)\([^)]*\)/gu, "").match(/-?[\d.]+px/gu)?.map(Number.parseFloat) ?? []);
65
+ const noteColour = (value, el, where) => {
66
+ const colour = parse(value);
67
+ if (!colour) { if (value !== "transparent" && value !== "none") unparsed += 1; return; }
68
+ if (colour.alpha < rules["DS-003"].threshold.minAlpha || onPalette(colour.rgb)) return;
69
+ const key = toHex(colour.rgb);
70
+ if (!offColours.has(key)) offColours.set(key, `${describe(el)} ${where}`);
71
+ };
72
+
73
+ const elements = [...document.body.querySelectorAll("*")].slice(0, limits.nodes);
74
+ for (const el of elements) {
75
+ if (exempt(el) || !visible(el)) continue;
76
+ const style = getComputedStyle(el);
77
+ const isSvgShape = el instanceof SVGElement && !(el instanceof SVGSVGElement);
78
+ if (isSvgShape) {
79
+ if (["rect", "path", "circle", "ellipse", "polygon", "polyline", "line"].includes(el.tagName.toLowerCase())) {
80
+ if (style.fill !== "none") noteColour(style.fill, el, "fill");
81
+ if (style.stroke !== "none") noteColour(style.stroke, el, "stroke");
82
+ }
83
+ continue;
84
+ }
85
+ const ownText = [...el.childNodes].some((node) => node.nodeType === Node.TEXT_NODE && node.textContent.trim());
86
+ if (ownText) {
87
+ noteColour(style.color, el, "text");
88
+ const family = style.fontFamily.split(",")[0].trim().replace(/^["']|["']$/gu, "").toLowerCase();
89
+ if (!families.has(family) && !offFamilies.has(family)) offFamilies.set(family, describe(el));
90
+ const px = Number.parseFloat(style.fontSize);
91
+ const ceiling = el.closest(`[${momentAttr}]`) ? momentMax : display.max;
92
+ const onScale = sizes.some((s) => Math.abs(s - px) <= sizeTolerance) || (px >= display.min - sizeTolerance && px <= ceiling + sizeTolerance);
93
+ if (!onScale && !offSizes.has(px)) offSizes.set(px, describe(el));
94
+ }
95
+ noteColour(style.backgroundColor, el, "background");
96
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
97
+ if (Number.parseFloat(style[`border${side}Width`]) > 0 && style[`border${side}Style`] !== "none") noteColour(style[`border${side}Color`], el, "border");
98
+ }
99
+ if (elevation !== "soft") {
100
+ for (const [x = 0, y = 0, blur = 0] of shadowLengths(style.boxShadow)) {
101
+ const offset = Math.abs(x) > hairline || Math.abs(y) > hairline;
102
+ if ((blur > 0 || (elevation === "flat" && offset)) && !offShadows.has(describe(el))) offShadows.set(describe(el), `${x}px ${y}px ${blur}px`);
103
+ }
104
+ }
105
+ const box = el.getBoundingClientRect();
106
+ for (const corner of ["TopLeft", "TopRight", "BottomRight", "BottomLeft"]) {
107
+ const raw = style[`border${corner}Radius`];
108
+ if (!raw || raw.includes(" ") || raw.includes("%")) continue;
109
+ const r = Number.parseFloat(raw);
110
+ if (!(r > 0)) continue;
111
+ const round = r >= Math.min(box.width, box.height) / 2 - radiusTolerance;
112
+ if (!round && !radii.some((v) => Math.abs(v - r) <= radiusTolerance) && !offRadii.has(r)) offRadii.set(r, describe(el));
113
+ }
114
+ }
115
+
116
+ for (const [family, where] of offFamilies) push("DS-002", where, `font-family "${family}"`, `one of ${lock.fonts.join(", ")}`);
117
+ if (offColours.size) {
118
+ const list = [...offColours.entries()];
119
+ const severity = list.length >= rules["DS-003"].threshold.highCount ? "HIGH" : rules["DS-003"].threshold.lowSeverity;
120
+ push("DS-003", list.slice(0, 4).map(([, where]) => where).join(" | "), `${list.length} off-palette colour(s): ${list.slice(0, 8).map(([c]) => c).join(", ")}`, `the ${lock.style} palette (light and dark roles)`, severity);
121
+ }
122
+ if (offSizes.size) push("DS-004", [...offSizes.values()].slice(0, 3).join(" | "), `${offSizes.size} size(s) off scale: ${[...offSizes.keys()].slice(0, 8).map((n) => `${n}px`).join(", ")}`, `${sizes.join("/")}px or display ${display.min}–${display.max}px`);
123
+ if (offRadii.size) push("DS-005", [...offRadii.values()].slice(0, 3).join(" | "), `${offRadii.size} radius value(s) off lock: ${[...offRadii.keys()].slice(0, 6).map((n) => `${n}px`).join(", ")}`, `${radii.join("/")}px or fully round`);
124
+ if (offShadows.size) push("DS-007", [...offShadows.keys()].slice(0, 3).join(" | "), `${offShadows.size} element(s) with ${[...offShadows.values()].slice(0, 3).join(", ")} shadows`, elevation === "flat" ? "flat lock: rings only, no blur or offset" : "offset lock: zero-blur offsets only");
125
+ if (unparsed) notVerified.push({ rule: "DS-003", reason: `${unparsed} colour value(s) in a format the probe cannot compare` });
126
+
127
+ // DS-006: a starter-layout slot such as {{Product}} left in visible text or a labelling attribute.
128
+ const slot = new RegExp(rules["DS-006"].threshold.pattern, "u");
129
+ const textHit = slot.exec(document.body.innerText.slice(0, limits.textChars * 10));
130
+ if (textHit) push("DS-006", "page text", textHit[0], "no {{slot}} from the kit layouts");
131
+ for (const el of document.querySelectorAll("[title], [aria-label], [alt], [placeholder]")) {
132
+ for (const attr of ["title", "aria-label", "alt", "placeholder"]) {
133
+ const value = el.getAttribute(attr);
134
+ const hit = value && slot.exec(value);
135
+ if (hit) push("DS-006", `${describe(el)}[${attr}]`, hit[0], "no {{slot}} from the kit layouts");
136
+ }
137
+ }
138
+ const title = slot.exec(document.title);
139
+ if (title) push("DS-006", "title", title[0], "no {{slot}} from the kit layouts");
140
+
141
+ // DS-008: the one signature moment the lock declares. It must be declared, marked, big enough to
142
+ // read, in the first screen on a read-once page, hold what its kind promises, and not be the
143
+ // generic gradient-and-centred-text hero.
144
+ const m = rules["DS-008"].threshold;
145
+ const declared = lock.moment;
146
+ if (!declared) {
147
+ push("DS-008", "design.lock.json", "the lock predates signature moments and records none", "a moment recorded with design-lock.mjs moment");
148
+ return { findings, notVerified };
149
+ }
150
+ if (!declared.kind) {
151
+ push("DS-008", "design.lock.json", "the lock declares no signature moment", `a ${declared.scale} moment recorded with design-lock.mjs moment`);
152
+ return { findings, notVerified };
153
+ }
154
+ const marked = [...document.querySelectorAll(`[${m.attribute}]`)].filter(visible);
155
+ if (!marked.length) {
156
+ push("DS-008", "page", `no [${m.attribute}] element for the declared ${declared.kind}`, `one element marked ${m.attribute}="${declared.kind}"`);
157
+ return { findings, notVerified };
158
+ }
159
+ if (marked.length > 1) push("DS-008", marked.slice(0, 3).map(describe).join(" | "), `${marked.length} elements claim the signature moment`, "one moment per page", "MEDIUM");
160
+ const el = marked.find((node) => node.getAttribute(m.attribute) === declared.kind) ?? marked[0];
161
+ const where = describe(el);
162
+ const kind = el.getAttribute(m.attribute);
163
+ if (kind !== declared.kind) push("DS-008", where, `marked "${kind}" but the lock declares "${declared.kind}"`, "the declared kind");
164
+ const box = el.getBoundingClientRect();
165
+ const area = box.width * box.height;
166
+ const minArea = declared.scale === "bold" ? m.boldMinAreaPx : m.smallMinAreaPx;
167
+ if (area < minArea) push("DS-008", where, `${Math.round(box.width)}×${Math.round(box.height)} px moment is too small to read as one`, `≥ ${minArea} px²`);
168
+ const base = options.pass === "base";
169
+ if (declared.scale === "small" && base && innerWidth >= m.foldMinViewportPx && area > m.smallMaxViewportShare * innerWidth * innerHeight) push("DS-008", where, `a work-surface moment covering ${Math.round((100 * area) / (innerWidth * innerHeight))}% of the screen`, `≤ ${m.smallMaxViewportShare * 100}%: work surfaces stay calm`, "MEDIUM");
170
+ if (declared.above_fold && base) {
171
+ const top = box.top + scrollY;
172
+ const wide = innerWidth >= m.foldMinViewportPx;
173
+ const limit = wide ? innerHeight - m.foldMinVisiblePx : innerHeight * m.phoneScreens;
174
+ if (top > limit) push("DS-008", where, `moment starts ${Math.round(top)} px down, below the fold`, wide ? `starts by ${Math.round(limit)} px (first screen)` : `starts within ${m.phoneScreens} screens (${Math.round(limit)} px)`);
175
+ }
176
+ const has = (selector) => el.matches(selector) || [...el.querySelectorAll(selector)].some(visible);
177
+ const media = has(m.media);
178
+ const inside = [el, ...el.querySelectorAll("*")].filter(visible);
179
+ const texts = inside.filter((node) => [...node.childNodes].some((child) => child.nodeType === Node.TEXT_NODE && child.textContent.trim()));
180
+ const need = m.needs[declared.kind];
181
+ const wants = {
182
+ media: ["an image, drawing, figure, frame or product view", () => media],
183
+ data: ["chart, table, figure or readout", () => has(m.data)],
184
+ control: ["control a reader can operate", () => has(m.control)],
185
+ "display-type": ["type at display size or above", () => texts.some((node) => Number.parseFloat(getComputedStyle(node).fontSize) >= display.min - sizeTolerance)],
186
+ motion: ["animation or transition", () => options.pass === "reduced-motion" || inside.some((node) => { const cs = getComputedStyle(node); return cs.animationName !== "none" || cs.transitionDuration.split(",").some((d) => Number.parseFloat(d) > 0); })],
187
+ }[need];
188
+ if (wants && !wants[1]()) push("DS-008", where, `declared ${declared.kind} but it holds no ${wants[0]}`, `a ${declared.kind} built from the page's content`);
189
+ const gradient = (node) => /gradient\(/u.test(getComputedStyle(node).backgroundImage) && !node.matches(".ui-scan, .ui-ruler");
190
+ const chain = [];
191
+ for (let node = el; node && node !== document.body && node !== document.documentElement; node = node.parentElement) chain.push(node);
192
+ const behind = chain.some(gradient) || inside.some((node) => { const b = node.getBoundingClientRect(); return gradient(node) && b.width * b.height >= m.coverShare * area; });
193
+ const biggest = texts.reduce((best, node) => (Number.parseFloat(getComputedStyle(node).fontSize) > (best ? Number.parseFloat(getComputedStyle(best).fontSize) : 0) ? node : best), null);
194
+ if (behind && !media && biggest && getComputedStyle(biggest).textAlign === "center") push("DS-008", where, "a generic gradient-and-centred-text hero", "a moment built from this page's content (composition, set piece, data, diagram, motion or object)");
195
+ return { findings, notVerified };
196
+ }