@flipova/foundation 1.13.0 → 2.0.4

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 (260) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/README.md +53 -178
  3. package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +162 -0
  4. package/components/ui/accordion/AccordionAnimatedHeight.tsx +56 -0
  5. package/components/ui/accordion/AccordionAnimatedIcon.tsx +41 -0
  6. package/components/ui/accordion/AnimatedHeight.tsx +56 -0
  7. package/components/ui/accordion/AnimatedIcon.tsx +41 -0
  8. package/components/ui/accordion/MIGRATION_SUMMARY.md +250 -0
  9. package/components/ui/accordion/USAGE_EXAMPLE.tsx +179 -0
  10. package/components/ui/accordion/animation-config.ts +32 -0
  11. package/components/ui/accordion/index.tsx +253 -0
  12. package/components/ui/actionsheet/index.tsx +511 -0
  13. package/components/ui/alert/index.tsx +158 -0
  14. package/components/ui/alert-dialog/index.tsx +254 -0
  15. package/components/ui/avatar/index.tsx +139 -0
  16. package/components/ui/badge/index.tsx +163 -0
  17. package/components/ui/bottomsheet/index.tsx +477 -0
  18. package/components/ui/box/index.tsx +19 -0
  19. package/components/ui/box/index.web.tsx +19 -0
  20. package/components/ui/box/styles.tsx +10 -0
  21. package/components/ui/button/index.tsx +264 -0
  22. package/components/ui/calendar/creator.tsx +366 -0
  23. package/components/ui/calendar/index.tsx +462 -0
  24. package/components/ui/calendar/styles.tsx +140 -0
  25. package/components/ui/card/index.tsx +23 -0
  26. package/components/ui/card/index.web.tsx +26 -0
  27. package/components/ui/card/styles.tsx +16 -0
  28. package/components/ui/center/index.tsx +22 -0
  29. package/components/ui/center/index.web.tsx +20 -0
  30. package/components/ui/center/styles.tsx +8 -0
  31. package/components/ui/checkbox/index.tsx +184 -0
  32. package/components/ui/date-time-picker/creator.tsx +109 -0
  33. package/components/ui/date-time-picker/index.tsx +585 -0
  34. package/components/ui/date-time-picker/index.web.tsx +217 -0
  35. package/components/ui/date-time-picker/styles.tsx +56 -0
  36. package/components/ui/divider/index.tsx +40 -0
  37. package/components/ui/drawer/index.tsx +362 -0
  38. package/components/ui/fab/index.tsx +215 -0
  39. package/components/ui/flat-list/index.tsx +21 -0
  40. package/components/ui/form-control/index.tsx +352 -0
  41. package/components/ui/gluestack-ui-provider/config.ts +72 -0
  42. package/components/ui/gluestack-ui-provider/index.tsx +47 -0
  43. package/components/ui/gluestack-ui-provider/index.web.tsx +96 -0
  44. package/components/ui/gluestack-ui-provider/script.ts +19 -0
  45. package/components/ui/gluestack-ui-provider/tokens.d.ts +17 -0
  46. package/components/ui/gluestack-ui-provider/tokens.js +188 -0
  47. package/components/ui/gluestack-ui-provider/useGluestackColors.ts +82 -0
  48. package/components/ui/grid/index.tsx +283 -0
  49. package/components/ui/grid/index.web.tsx +66 -0
  50. package/components/ui/grid/styles.tsx +15 -0
  51. package/components/ui/heading/index.tsx +220 -0
  52. package/components/ui/heading/index.web.tsx +202 -0
  53. package/components/ui/heading/styles.tsx +43 -0
  54. package/components/ui/hstack/index.tsx +27 -0
  55. package/components/ui/hstack/index.web.tsx +26 -0
  56. package/components/ui/hstack/styles.tsx +25 -0
  57. package/components/ui/icon/index.tsx +1588 -0
  58. package/components/ui/icon/index.web.tsx +1573 -0
  59. package/components/ui/image/index.tsx +48 -0
  60. package/components/ui/image-background/index.tsx +25 -0
  61. package/components/ui/image-viewer/index.tsx +743 -0
  62. package/components/ui/image-viewer/index.web.tsx +302 -0
  63. package/components/ui/index.ts +58 -0
  64. package/components/ui/input/index.tsx +125 -0
  65. package/components/ui/input-accessory-view/index.tsx +2 -0
  66. package/components/ui/keyboard-avoiding-view/index.tsx +2 -0
  67. package/components/ui/link/index.tsx +102 -0
  68. package/components/ui/liquid-glass/index.tsx +74 -0
  69. package/components/ui/menu/index.tsx +186 -0
  70. package/components/ui/modal/index.tsx +237 -0
  71. package/components/ui/popover/index.tsx +272 -0
  72. package/components/ui/portal/index.tsx +17 -0
  73. package/components/ui/pressable/index.tsx +39 -0
  74. package/components/ui/progress/index.tsx +83 -0
  75. package/components/ui/radio/index.tsx +217 -0
  76. package/components/ui/refresh-control/index.tsx +2 -0
  77. package/components/ui/safe-area-view/index.tsx +2 -0
  78. package/components/ui/scroll-view/index.tsx +2 -0
  79. package/components/ui/section-list/index.tsx +2 -0
  80. package/components/ui/select/index.tsx +277 -0
  81. package/components/ui/select/select-actionsheet.tsx +562 -0
  82. package/components/ui/skeleton/index.tsx +105 -0
  83. package/components/ui/skeleton/index.web.tsx +103 -0
  84. package/components/ui/skeleton/styles.tsx +35 -0
  85. package/components/ui/slider/index.tsx +181 -0
  86. package/components/ui/spinner/index.tsx +40 -0
  87. package/components/ui/status-bar/index.tsx +2 -0
  88. package/components/ui/switch/index.tsx +41 -0
  89. package/components/ui/table/index.tsx +210 -0
  90. package/components/ui/table/index.web.tsx +157 -0
  91. package/components/ui/table/styles.tsx +44 -0
  92. package/components/ui/tabs/TabsAnimatedIndicator.tsx +160 -0
  93. package/components/ui/tabs/animation-config.ts +3 -0
  94. package/components/ui/tabs/creator.tsx +206 -0
  95. package/components/ui/tabs/index.tsx +484 -0
  96. package/components/ui/text/index.tsx +48 -0
  97. package/components/ui/text/index.web.tsx +45 -0
  98. package/components/ui/text/styles.tsx +47 -0
  99. package/components/ui/textarea/index.tsx +94 -0
  100. package/components/ui/toast/index.tsx +252 -0
  101. package/components/ui/tooltip/index.tsx +131 -0
  102. package/components/ui/view/index.tsx +2 -0
  103. package/components/ui/virtualized-list/index.tsx +2 -0
  104. package/components/ui/vstack/index.tsx +28 -0
  105. package/components/ui/vstack/index.web.tsx +27 -0
  106. package/components/ui/vstack/styles.tsx +25 -0
  107. package/design/canonical.index.txt +53 -0
  108. package/design/documentation.xml +519 -0
  109. package/design/manifest.xml +90 -0
  110. package/design/schema.xsd +639 -0
  111. package/design/themes.xml +204 -0
  112. package/design/tokens.xml +510 -0
  113. package/design/tools/design.js +165 -0
  114. package/design/tools/npm.js +65 -0
  115. package/design/tools/requirements.txt +35 -0
  116. package/design/tools/sources/.checker/__init__.py +81 -0
  117. package/design/tools/sources/.checker/checks.py +198 -0
  118. package/design/tools/sources/.checker/cli.py +154 -0
  119. package/design/tools/sources/.checker/io.py +242 -0
  120. package/design/tools/sources/.checker/model.py +144 -0
  121. package/design/tools/sources/.checker/registry.py +115 -0
  122. package/design/tools/sources/.checker/report.py +21 -0
  123. package/design/tools/sources/.docgen/__init__.py +45 -0
  124. package/design/tools/sources/.docgen/cli.py +101 -0
  125. package/design/tools/sources/.docgen/model.py +147 -0
  126. package/design/tools/sources/.docgen/reference.py +97 -0
  127. package/design/tools/sources/.docgen/site.py +145 -0
  128. package/design/tools/sources/.docgen/xsddoc.py +329 -0
  129. package/design/tools/sources/.generate/__init__.py +35 -0
  130. package/design/tools/sources/.generate/cli.py +76 -0
  131. package/design/tools/sources/.generate/common.py +33 -0
  132. package/design/tools/sources/.generate/config.py +119 -0
  133. package/design/tools/sources/.generate/model.py +51 -0
  134. package/design/tools/sources/.generate/tokens.py +141 -0
  135. package/design/tools/sources/.linter/__init__.py +9 -0
  136. package/design/tools/sources/.linter/cli.py +44 -0
  137. package/design/tools/sources/.linter/discovery.py +30 -0
  138. package/design/tools/sources/.linter/errors.py +45 -0
  139. package/design/tools/sources/.linter/linter.py +68 -0
  140. package/design/tools/sources/.xmleditor/__init__.py +74 -0
  141. package/design/tools/sources/.xmleditor/blocks.py +185 -0
  142. package/design/tools/sources/.xmleditor/cli.py +141 -0
  143. package/design/tools/sources/.xmleditor/editor.py +906 -0
  144. package/design/tools/sources/.xmleditor/model.py +708 -0
  145. package/design/tools/sources/.xmleditor/widgets.py +1832 -0
  146. package/design/tools/sources/.xmleditor/xsdmodel.py +753 -0
  147. package/design/tools/sources/checker.py +55 -0
  148. package/design/tools/sources/docgen.py +66 -0
  149. package/design/tools/sources/generate.py +48 -0
  150. package/design/tools/sources/linter.py +54 -0
  151. package/design/tools/sources/ruff.toml +12 -0
  152. package/design/tools/sources/xmleditor.py +62 -0
  153. package/design/tools/unix/_venv_python.sh +16 -0
  154. package/design/tools/unix/check.sh +13 -0
  155. package/design/tools/unix/doc.sh +14 -0
  156. package/design/tools/unix/gen.sh +14 -0
  157. package/design/tools/unix/lint.sh +10 -0
  158. package/design/tools/unix/run.sh +20 -0
  159. package/design/tools/unix/verify.sh +12 -0
  160. package/design/tools/unix/xmledit.sh +12 -0
  161. package/design/tools/windows/check.cmd +12 -0
  162. package/design/tools/windows/doc.cmd +12 -0
  163. package/design/tools/windows/gen.cmd +11 -0
  164. package/design/tools/windows/lint.cmd +9 -0
  165. package/design/tools/windows/run.cmd +26 -0
  166. package/design/tools/windows/verify.cmd +10 -0
  167. package/design/tools/windows/xmledit.cmd +10 -0
  168. package/dist/chunk-LV4UIEQN.js +9730 -0
  169. package/dist/chunk-LV4UIEQN.js.map +1 -0
  170. package/dist/chunk-WNVU3BM2.mjs +9401 -0
  171. package/dist/chunk-WNVU3BM2.mjs.map +1 -0
  172. package/dist/index.d.mts +40 -9
  173. package/dist/index.d.ts +40 -9
  174. package/dist/index.js +726 -414
  175. package/dist/index.mjs +1 -5
  176. package/dist/ui/index.d.mts +6931 -3070
  177. package/dist/ui/index.d.ts +6931 -3070
  178. package/dist/ui/index.js +779 -352
  179. package/dist/ui/index.mjs +1 -2
  180. package/package.json +66 -142
  181. package/dist/chunk-2XORADW6.js +0 -24552
  182. package/dist/chunk-2XORADW6.js.map +0 -1
  183. package/dist/chunk-52BHHF5M.js +0 -46
  184. package/dist/chunk-52BHHF5M.js.map +0 -1
  185. package/dist/chunk-5647JY7Z.mjs +0 -100
  186. package/dist/chunk-5647JY7Z.mjs.map +0 -1
  187. package/dist/chunk-5N5HC4ZA.mjs +0 -3
  188. package/dist/chunk-5N5HC4ZA.mjs.map +0 -1
  189. package/dist/chunk-7QFZMGL6.js +0 -8583
  190. package/dist/chunk-7QFZMGL6.js.map +0 -1
  191. package/dist/chunk-ASZEP37D.js +0 -423
  192. package/dist/chunk-ASZEP37D.js.map +0 -1
  193. package/dist/chunk-BH5SU2JQ.mjs +0 -8282
  194. package/dist/chunk-BH5SU2JQ.mjs.map +0 -1
  195. package/dist/chunk-BO65GO53.mjs +0 -422
  196. package/dist/chunk-BO65GO53.mjs.map +0 -1
  197. package/dist/chunk-BSVXX52E.mjs +0 -413
  198. package/dist/chunk-BSVXX52E.mjs.map +0 -1
  199. package/dist/chunk-DNV5UBNF.mjs +0 -3
  200. package/dist/chunk-DNV5UBNF.mjs.map +0 -1
  201. package/dist/chunk-EDTAMUO2.js +0 -8310
  202. package/dist/chunk-EDTAMUO2.js.map +0 -1
  203. package/dist/chunk-IJTI6EX4.js +0 -4
  204. package/dist/chunk-IJTI6EX4.js.map +0 -1
  205. package/dist/chunk-M3YLASM2.js +0 -428
  206. package/dist/chunk-M3YLASM2.js.map +0 -1
  207. package/dist/chunk-OXKOGLXE.js +0 -4
  208. package/dist/chunk-OXKOGLXE.js.map +0 -1
  209. package/dist/chunk-RQXQK3ZO.mjs +0 -8486
  210. package/dist/chunk-RQXQK3ZO.mjs.map +0 -1
  211. package/dist/chunk-SR25V4EA.mjs +0 -40
  212. package/dist/chunk-SR25V4EA.mjs.map +0 -1
  213. package/dist/chunk-UB34WFEQ.js +0 -106
  214. package/dist/chunk-UB34WFEQ.js.map +0 -1
  215. package/dist/chunk-ZBRWXKDF.mjs +0 -24431
  216. package/dist/chunk-ZBRWXKDF.mjs.map +0 -1
  217. package/dist/cli/ds.d.mts +0 -1
  218. package/dist/cli/ds.d.ts +0 -1
  219. package/dist/cli/ds.js +0 -602
  220. package/dist/cli/ds.js.map +0 -1
  221. package/dist/cli/ds.mjs +0 -579
  222. package/dist/cli/ds.mjs.map +0 -1
  223. package/dist/cli/flipova.d.mts +0 -1
  224. package/dist/cli/flipova.d.ts +0 -1
  225. package/dist/cli/flipova.js +0 -161
  226. package/dist/cli/flipova.js.map +0 -1
  227. package/dist/cli/flipova.mjs +0 -154
  228. package/dist/cli/flipova.mjs.map +0 -1
  229. package/dist/config/index.d.mts +0 -123
  230. package/dist/config/index.d.ts +0 -123
  231. package/dist/config/index.js +0 -28
  232. package/dist/config/index.js.map +0 -1
  233. package/dist/config/index.mjs +0 -3
  234. package/dist/config/index.mjs.map +0 -1
  235. package/dist/index-CuaJA3gM.d.mts +0 -78
  236. package/dist/index-CuaJA3gM.d.ts +0 -78
  237. package/dist/registry/index.d.mts +0 -10160
  238. package/dist/registry/index.d.ts +0 -10160
  239. package/dist/registry/index.js +0 -392
  240. package/dist/registry/index.js.map +0 -1
  241. package/dist/registry/index.mjs +0 -3
  242. package/dist/registry/index.mjs.map +0 -1
  243. package/dist/theme/index.d.mts +0 -109
  244. package/dist/theme/index.d.ts +0 -109
  245. package/dist/theme/index.js +0 -28
  246. package/dist/theme/index.js.map +0 -1
  247. package/dist/theme/index.mjs +0 -3
  248. package/dist/theme/index.mjs.map +0 -1
  249. package/dist/tokens/index.d.mts +0 -423
  250. package/dist/tokens/index.d.ts +0 -423
  251. package/dist/tokens/index.js +0 -44
  252. package/dist/tokens/index.js.map +0 -1
  253. package/dist/tokens/index.mjs +0 -3
  254. package/dist/tokens/index.mjs.map +0 -1
  255. package/dist/types/index.d.mts +0 -202
  256. package/dist/types/index.d.ts +0 -202
  257. package/dist/types/index.js +0 -4
  258. package/dist/types/index.js.map +0 -1
  259. package/dist/types/index.mjs +0 -3
  260. package/dist/types/index.mjs.map +0 -1
@@ -0,0 +1,147 @@
1
+ """docs model - declarative sources of the documentation site.
2
+
3
+ Parses `design/manifest.xml` (project metadata + determinism rules) and
4
+ `design/documentation.xml` (navigation + narrative Markdown content) into the
5
+ typed model consumed by .docgen/reference.py and .docgen/site.py.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass, field
10
+ from pathlib import Path
11
+
12
+ from lxml import etree
13
+
14
+ NS = "urn:flipova:foundation:registry"
15
+
16
+ # Map (section-id, article-id) -> dynamic key (rendered in .docgen/cli.py).
17
+ # Shared by site.py (article rendering).
18
+ DYNAMIC_ARTICLES = {
19
+ ("schema-reference", "schema"): "schema",
20
+ ("theming", "tokens"): "tokens",
21
+ ("theming", "themes"): "themes",
22
+ }
23
+
24
+
25
+ def q(tag: str) -> str:
26
+ return f"{{{NS}}}{tag}"
27
+
28
+
29
+ # Models
30
+ @dataclass
31
+ class DocArticle:
32
+ id: str
33
+ title: str
34
+ slug: str
35
+ content: str = ""
36
+
37
+
38
+ @dataclass
39
+ class DocSection:
40
+ id: str
41
+ title: str
42
+ order: int
43
+ articles: list[DocArticle] = field(default_factory=list)
44
+
45
+
46
+ # Parsers
47
+ def parse_manifest(manifest_path: Path):
48
+ """Parse the manifest.xml file (project metadata + determinism rules)."""
49
+ tree = etree.parse(str(manifest_path))
50
+ root = tree.getroot()
51
+ project = ""
52
+ version = ""
53
+ license_name = ""
54
+ language = "en"
55
+ registry_root = ""
56
+ pipeline_source = ""
57
+ outputs = {}
58
+ determinism_rules = []
59
+
60
+ meta = root.find(q("meta"))
61
+ if meta is not None:
62
+ el = meta.find(q("project"))
63
+ if el is not None:
64
+ project = (el.text or "").strip()
65
+ el = meta.find(q("license"))
66
+ if el is not None:
67
+ license_name = (el.text or "").strip()
68
+ el = meta.find(q("language"))
69
+ if el is not None:
70
+ language = (el.text or "en").strip()
71
+ el = meta.find(q("registryRoot"))
72
+ if el is not None:
73
+ registry_root = (el.text or "").strip()
74
+
75
+ pipeline = meta.find(q("pipeline"))
76
+ if pipeline is not None:
77
+ source_el = pipeline.find(q("source"))
78
+ if source_el is not None:
79
+ pipeline_source = (source_el.text or "").strip()
80
+ outputs_el = pipeline.find(q("outputs"))
81
+ if outputs_el is not None:
82
+ for output in outputs_el:
83
+ tag = etree.QName(output.tag).localname
84
+ outputs[tag] = (output.text or "").strip()
85
+
86
+ determinism = meta.find(q("determinism"))
87
+ if determinism is not None:
88
+ for rule in determinism:
89
+ if etree.QName(rule.tag).localname == "rule":
90
+ rule_def = {
91
+ "id": rule.get("id", ""),
92
+ "kind": rule.get("kind", ""),
93
+ "severity": rule.get("severity", ""),
94
+ "description": "",
95
+ "params": {},
96
+ }
97
+ desc_el = rule.find(q("description"))
98
+ if desc_el is not None:
99
+ rule_def["description"] = (desc_el.text or "").strip()
100
+ params_el = rule.find(q("params"))
101
+ if params_el is not None:
102
+ for param in params_el:
103
+ if etree.QName(param.tag).localname == "param":
104
+ rule_def["params"][param.get("name", "")] = (param.text or "").strip()
105
+ determinism_rules.append(rule_def)
106
+
107
+ return {
108
+ "project": project,
109
+ "version": version,
110
+ "license": license_name,
111
+ "language": language,
112
+ "registry_root": registry_root,
113
+ "pipeline_source": pipeline_source,
114
+ "outputs": outputs,
115
+ "determinism_rules": determinism_rules,
116
+ "doc_sections": [],
117
+ }
118
+
119
+
120
+ def parse_documentation(doc_path: Path) -> list[DocSection]:
121
+ """Parse the documentation tree (`design/documentation.xml`)."""
122
+ tree = etree.parse(str(doc_path))
123
+ root = tree.getroot()
124
+ if etree.QName(root.tag).localname != "documentation":
125
+ raise SystemExit(f"{doc_path}: expected root element <documentation>, got <{etree.QName(root.tag).localname}>")
126
+ doc_sections: list[DocSection] = []
127
+ for section in root:
128
+ if etree.QName(section.tag).localname != "section":
129
+ continue
130
+ sec_def = DocSection(
131
+ id=section.get("id", ""),
132
+ title=section.get("title", ""),
133
+ order=int(section.get("order", "0")),
134
+ )
135
+ for article in section:
136
+ if etree.QName(article.tag).localname != "article":
137
+ continue
138
+ content_el = article.find(q("content"))
139
+ content = (content_el.text or "").strip("\n") if content_el is not None else ""
140
+ sec_def.articles.append(DocArticle(
141
+ id=article.get("id", ""),
142
+ title=article.get("title", ""),
143
+ slug=article.get("slug", ""),
144
+ content=content,
145
+ ))
146
+ doc_sections.append(sec_def)
147
+ return sorted(doc_sections, key=lambda s: s.order)
@@ -0,0 +1,97 @@
1
+ """reference renderers - dynamic content of the registry/schema reference pages.
2
+
3
+ - Schema Reference: rendered from `design/schema.xsd` via .docgen/xsddoc.py
4
+ (never duplicated by hand: change the .xsd, regenerate, done).
5
+ - Tokens / Themes: rendered directly from design/tokens.xml and
6
+ design/themes.xml.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+
12
+ from lxml import etree
13
+
14
+ from .model import q
15
+ from .xsddoc import collect_types, render_markdown
16
+
17
+ # ---------------------------------------------------------------------------
18
+ # Dynamic content: Schema Reference (from schema.xsd)
19
+ # ---------------------------------------------------------------------------
20
+
21
+
22
+ def strip_leading_h1(markdown: str) -> str:
23
+ """Drop the first '# Title' line xsd2doc emits -- the page already has one."""
24
+ lines = markdown.splitlines()
25
+ while lines and not lines[0].strip():
26
+ lines.pop(0)
27
+ if lines and lines[0].startswith("# "):
28
+ lines.pop(0)
29
+ return "\n".join(lines).lstrip("\n")
30
+
31
+
32
+ def render_schema_reference(schema_path: Path) -> str:
33
+ tree = etree.parse(str(schema_path))
34
+ etree.XMLSchema(tree) # raises if the schema itself is invalid
35
+ types = collect_types(tree.getroot())
36
+ md = render_markdown(types, "Flipova Foundation Registry Schema Reference")
37
+ return strip_leading_h1(md)
38
+
39
+
40
+ # ---------------------------------------------------------------------------
41
+ # Dynamic content: registry reference (tokens.xml, themes.xml)
42
+ # ---------------------------------------------------------------------------
43
+
44
+
45
+ def render_tokens_reference(tokens_path: Path) -> str:
46
+ if not tokens_path.exists():
47
+ return "_No `tokens.xml` found._\n"
48
+ root = etree.parse(str(tokens_path)).getroot()
49
+ lines = []
50
+ for token in root.findall(q("items") + "/" + q("token")):
51
+ tid = token.get("id", "")
52
+ kind = token.get("kind", "")
53
+ lines.append(f"### {tid}")
54
+ lines.append("")
55
+ meta_bits = [f"`kind={kind}`"]
56
+ for attr in ("unit", "base", "formula", "mode"):
57
+ if token.get(attr):
58
+ meta_bits.append(f"`{attr}={token.get(attr)}`")
59
+ lines.append(" &nbsp;·&nbsp; ".join(meta_bits))
60
+ lines.append("")
61
+ values = token.find(q("values"))
62
+ ids = [v.get("id", "") for v in values.findall(q("value"))] if values is not None else []
63
+ if ids:
64
+ lines.append("Values: " + ", ".join(f"`{v}`" for v in ids))
65
+ lines.append("")
66
+ lines.append(f"Reference syntax: `$ref.tokens.{tid}.<value-id>`")
67
+ lines.append("")
68
+ return "\n".join(lines) if lines else "_No tokens declared._\n"
69
+
70
+
71
+ def render_themes_reference(themes_path: Path) -> str:
72
+ if not themes_path.exists():
73
+ return "_No `themes.xml` found._\n"
74
+ root = etree.parse(str(themes_path)).getroot()
75
+ default = root.get("default", "")
76
+ lines = [f"Default theme: `{default}`", ""]
77
+ for theme in root.findall(q("items") + "/" + q("theme")):
78
+ tid = theme.get("id", "")
79
+ mode = theme.get("mode", "")
80
+ lines.append(f"### {tid}")
81
+ lines.append("")
82
+ lines.append(f"`mode={mode}`" + (" *(default)*" if tid == default else ""))
83
+ lines.append("")
84
+ role_map = theme.find(q("roleMap"))
85
+ roles = role_map.findall(q("role")) if role_map is not None else []
86
+ if roles:
87
+ lines.append("| Role | Reference |")
88
+ lines.append("|---|---|")
89
+ for role in roles:
90
+ rname = role.get("name", role.get("id", ""))
91
+ ref_el = role.find(q("ref"))
92
+ ref_val = (ref_el.text or "").strip() if ref_el is not None else (role.text or "").strip()
93
+ lines.append(f"| `{rname}` | `{ref_val or ('$ref.tokens.color...')}` |")
94
+ lines.append("")
95
+ lines.append("Reference syntax: `$ref.themes.<role>` -> `--<role>` in the generated config")
96
+ lines.append("")
97
+ return "\n".join(lines)
@@ -0,0 +1,145 @@
1
+ """site writer — narrative articles, cross-references and static index.
2
+
3
+ - build_title_index / resolve_xrefs: rewrite prose "see **Title**" /
4
+ "following **Title**" into Markdown links pointing at the referenced
5
+ article or section.
6
+ - render_article_body: article Markdown = declared <content> + dynamic
7
+ sections (schema/API references injected by .docgen/cli.py).
8
+ - write_site: stale-output cleanup + deterministic file emission.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import re
13
+ import shutil
14
+ from pathlib import Path
15
+
16
+ from .model import DYNAMIC_ARTICLES, DocArticle, DocSection
17
+
18
+ # ---------------------------------------------------------------------------
19
+ # Cross-reference resolution: rewrites prose "see **Title**" / "following
20
+ # **Title**" into Markdown links pointing at the referenced article or section.
21
+ # ---------------------------------------------------------------------------
22
+
23
+ def build_title_index(doc_sections: list[DocSection]) -> dict[str, str]:
24
+ """Build a {title: url} lookup from article titles and section titles.
25
+
26
+ Article titles map to ``/docs/{slug}``. Section titles map to the URL of
27
+ their **first article** (Docusaurus does not generate standalone section
28
+ landing pages, so we proxy to the first child as a sensible entry point).
29
+ """
30
+ index: dict[str, str] = {}
31
+ for section in doc_sections:
32
+ section_url: str | None = None # first article's URL, if any
33
+ for article in section.articles:
34
+ if article.title and article.slug:
35
+ url = f"/docs/{article.slug}"
36
+ if section_url is None:
37
+ # First article becomes the section's proxy landing page.
38
+ section_url = url
39
+ # Article titles point at their individual page. An exact
40
+ # title match always wins over a section title match because
41
+ # articles are processed after their own section above.
42
+ index[article.title] = url
43
+ if section.title and section_url is not None:
44
+ # Section titles point at the first article in that section.
45
+ index[section.title] = section_url
46
+ return index
47
+
48
+
49
+ def resolve_xrefs(content: str, title_index: dict[str, str]) -> str:
50
+ """Convert ``see **Title**`` / ``See **Title**`` / ``following **Title**``
51
+ in *content* into ``[Title](url)`` Markdown links using *title_index*.
52
+
53
+ Only bold ``**Title**`` spans that immediately follow one of the trigger
54
+ words are rewritten, leaving standalone bold runs untouched. Unresolved
55
+ titles are left as-is so they remain visible during authoring.
56
+ """
57
+ pattern = re.compile(
58
+ r'(see|See|following)\s+\*\*([^*]+)\*\*',
59
+ re.UNICODE,
60
+ )
61
+ def _replace(m: re.Match[str]) -> str:
62
+ trigger, title = m.group(1), m.group(2)
63
+ url = title_index.get(title)
64
+ if url is None:
65
+ return m.group(0) # leave unresolved references as-is
66
+ return f"{trigger} [{title}]({url})"
67
+ return pattern.sub(_replace, content)
68
+
69
+
70
+ def render_article_body(
71
+ section: DocSection,
72
+ article: DocArticle,
73
+ dynamic: dict[str, str],
74
+ title_index: dict[str, str],
75
+ ) -> str:
76
+ parts = []
77
+ if article.content:
78
+ parts.append(article.content.strip() + "\n")
79
+ key = (section.id, article.id)
80
+ dyn_key = DYNAMIC_ARTICLES.get(key)
81
+ if dyn_key is not None:
82
+ parts.append(dynamic.get(dyn_key, ""))
83
+ body = "\n\n".join(p for p in parts if p.strip())
84
+ if not body:
85
+ body = f"# {article.title}\n\n_Content pending._\n"
86
+ # Resolve prose cross-references ("see **Title**") into links.
87
+ body = resolve_xrefs(body, title_index)
88
+ return body
89
+
90
+
91
+ def write_site(model: dict, out_dir: Path, dynamic: dict[str, str],
92
+ repo_root: Path | None = None) -> list[Path]:
93
+ out_dir = out_dir.resolve()
94
+ if repo_root is not None and out_dir == repo_root.resolve():
95
+ raise SystemExit("refusing to use the repository root itself as the docs output directory")
96
+ out_dir.mkdir(parents=True, exist_ok=True)
97
+
98
+ # Clean ONLY the artifacts this generator owns -- never wipe the whole
99
+ # output directory: it may be the Docusaurus site root containing
100
+ # hand-maintained files (package.json, src/, static/, node_modules/...).
101
+ slug_roots = {article.slug.split("/")[0]
102
+ for section in model["doc_sections"]
103
+ for article in section.articles}
104
+ slug_roots.add("api-reference") # element pages (write_element_pages)
105
+ for name in sorted(slug_roots):
106
+ stale = out_dir / name
107
+ if stale.is_dir():
108
+ shutil.rmtree(stale)
109
+ index_path = out_dir / "README.md"
110
+ if index_path.exists():
111
+ index_path.unlink()
112
+
113
+ written: list[Path] = []
114
+ version = model.get("version") or ""
115
+ nav_lines = [f"# {model['project']} -- Documentation", "",
116
+ f"**Version: {version}**" if version else "",
117
+ "",
118
+ ("> Generated by `design/tools/sources/docgen.py` from "
119
+ "`design/manifest.xml`, `design/documentation.xml` (`<documentation>`), "
120
+ "`design/schema.xsd` and the registries (`tokens.xml`, `themes.xml`). "
121
+ "Do not edit files under this directory by hand -- edit the "
122
+ "sources of truth and regenerate (`npm run design:doc`)."), ""]
123
+
124
+ # Build {title: url} lookup so prose cross-references ("see **Title**")
125
+ # can be resolved into Markdown links during article rendering.
126
+ title_index = build_title_index(model["doc_sections"])
127
+
128
+ for section in model["doc_sections"]:
129
+ nav_lines.append(f"## {section.title}")
130
+ nav_lines.append("")
131
+ for article in section.articles:
132
+ target = out_dir / f"{article.slug}.md"
133
+ target.parent.mkdir(parents=True, exist_ok=True)
134
+ body = render_article_body(section, article, dynamic, title_index)
135
+ with open(target, "w", encoding="utf-8", newline="\n") as fh:
136
+ fh.write(body.rstrip() + "\n")
137
+ written.append(target)
138
+ nav_lines.append(f"- [{article.title}]({article.slug}.md)")
139
+ nav_lines.append("")
140
+
141
+ index_path = out_dir / "README.md"
142
+ with open(index_path, "w", encoding="utf-8", newline="\n") as fh:
143
+ fh.write("\n".join(nav_lines).rstrip() + "\n")
144
+ written.append(index_path)
145
+ return written