agentcss 0.0.0-stage → 0.11.3

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 (274) hide show
  1. package/01-tokens/README.md +236 -0
  2. package/01-tokens/behavior/dismissable.js +132 -0
  3. package/01-tokens/behavior/emit.js +76 -0
  4. package/01-tokens/behavior/focus-return.js +81 -0
  5. package/01-tokens/behavior/roving.js +152 -0
  6. package/01-tokens/behavior/typeahead.js +124 -0
  7. package/01-tokens/focus-ring-demo.html +133 -0
  8. package/01-tokens/focus-ring.css +102 -0
  9. package/01-tokens/page.css +244 -0
  10. package/01-tokens/polyfill.js +116 -0
  11. package/01-tokens/responsive-demo.html +171 -0
  12. package/01-tokens/scrollbar-demo.html +194 -0
  13. package/01-tokens/scrollbar.css +179 -0
  14. package/01-tokens/theme-toggle.js +103 -0
  15. package/01-tokens/tokens.css +972 -0
  16. package/01-tokens/typography.css +156 -0
  17. package/02-primitives/badge/README.md +71 -0
  18. package/02-primitives/badge/badge.css +141 -0
  19. package/02-primitives/badge/demo.html +101 -0
  20. package/02-primitives/button/README.md +99 -0
  21. package/02-primitives/button/button.css +353 -0
  22. package/02-primitives/button/demo.html +200 -0
  23. package/02-primitives/card/README.md +145 -0
  24. package/02-primitives/card/card.css +246 -0
  25. package/02-primitives/card/demo.html +170 -0
  26. package/02-primitives/choice/README.md +161 -0
  27. package/02-primitives/choice/choice.css +395 -0
  28. package/02-primitives/choice/demo.html +277 -0
  29. package/02-primitives/combobox/README.md +79 -0
  30. package/02-primitives/combobox/combobox.css +223 -0
  31. package/02-primitives/combobox/combobox.js +485 -0
  32. package/02-primitives/combobox/demo.html +109 -0
  33. package/02-primitives/date-range/README.md +100 -0
  34. package/02-primitives/date-range/date-range.css +206 -0
  35. package/02-primitives/date-range/date-range.js +301 -0
  36. package/02-primitives/date-range/demo.html +104 -0
  37. package/02-primitives/input/README.md +170 -0
  38. package/02-primitives/input/demo.html +246 -0
  39. package/02-primitives/input/input.css +239 -0
  40. package/02-primitives/popover/README.md +80 -0
  41. package/02-primitives/popover/demo.html +150 -0
  42. package/02-primitives/popover/popover.css +187 -0
  43. package/02-primitives/popover/popover.js +331 -0
  44. package/02-primitives/progress/README.md +82 -0
  45. package/02-primitives/progress/demo.html +154 -0
  46. package/02-primitives/progress/progress.css +172 -0
  47. package/02-primitives/select/README.md +95 -0
  48. package/02-primitives/select/demo.html +121 -0
  49. package/02-primitives/select/select.css +151 -0
  50. package/02-primitives/select/select.js +549 -0
  51. package/02-primitives/separator/README.md +63 -0
  52. package/02-primitives/separator/demo.html +84 -0
  53. package/02-primitives/separator/separator.css +73 -0
  54. package/02-primitives/skeleton/README.md +69 -0
  55. package/02-primitives/skeleton/demo.html +110 -0
  56. package/02-primitives/skeleton/skeleton.css +96 -0
  57. package/02-primitives/switch/README.md +65 -0
  58. package/02-primitives/switch/demo.html +115 -0
  59. package/02-primitives/switch/switch.css +370 -0
  60. package/03-patterns/accordion/README.md +121 -0
  61. package/03-patterns/accordion/accordion.css +453 -0
  62. package/03-patterns/accordion/accordion.js +369 -0
  63. package/03-patterns/accordion/demo.html +223 -0
  64. package/03-patterns/content/README.md +103 -0
  65. package/03-patterns/content/content.css +286 -0
  66. package/03-patterns/content/demo.html +88 -0
  67. package/03-patterns/drawer/README.md +79 -0
  68. package/03-patterns/drawer/demo.html +101 -0
  69. package/03-patterns/drawer/drawer.css +129 -0
  70. package/03-patterns/drawer/drawer.js +258 -0
  71. package/03-patterns/dropdown/README.md +78 -0
  72. package/03-patterns/dropdown/demo.html +101 -0
  73. package/03-patterns/dropdown/dropdown.css +135 -0
  74. package/03-patterns/dropdown/dropdown.js +451 -0
  75. package/03-patterns/form-validation/README.md +147 -0
  76. package/03-patterns/form-validation/demo.html +280 -0
  77. package/03-patterns/form-validation/form-validation.css +263 -0
  78. package/03-patterns/list/README.md +150 -0
  79. package/03-patterns/list/demo.html +225 -0
  80. package/03-patterns/list/flip.js +201 -0
  81. package/03-patterns/list/list.css +162 -0
  82. package/03-patterns/nav/README.md +225 -0
  83. package/03-patterns/nav/demo.html +131 -0
  84. package/03-patterns/nav/nav.css +314 -0
  85. package/03-patterns/nav/nav.js +430 -0
  86. package/03-patterns/nav/toc.js +111 -0
  87. package/03-patterns/overlay/README.md +196 -0
  88. package/03-patterns/overlay/demo.html +241 -0
  89. package/03-patterns/overlay/overlay.css +319 -0
  90. package/03-patterns/overlay/overlay.js +563 -0
  91. package/03-patterns/pagination/README.md +114 -0
  92. package/03-patterns/pagination/demo.html +165 -0
  93. package/03-patterns/pagination/pagination.css +195 -0
  94. package/03-patterns/pagination/pagination.js +395 -0
  95. package/03-patterns/reveal/README.md +91 -0
  96. package/03-patterns/reveal/demo.html +106 -0
  97. package/03-patterns/reveal/reveal.css +93 -0
  98. package/03-patterns/reveal/reveal.js +172 -0
  99. package/03-patterns/states/README.md +141 -0
  100. package/03-patterns/states/demo.html +240 -0
  101. package/03-patterns/states/states.css +252 -0
  102. package/03-patterns/tabs/README.md +84 -0
  103. package/03-patterns/tabs/demo.html +139 -0
  104. package/03-patterns/tabs/tabs.css +172 -0
  105. package/03-patterns/tabs/tabs.js +307 -0
  106. package/03-patterns/tooltip/README.md +96 -0
  107. package/03-patterns/tooltip/demo.html +78 -0
  108. package/03-patterns/tooltip/tooltip.css +89 -0
  109. package/03-patterns/tooltip/tooltip.js +288 -0
  110. package/03-patterns/tree/README.md +94 -0
  111. package/03-patterns/tree/demo.html +138 -0
  112. package/03-patterns/tree/tree.css +113 -0
  113. package/03-patterns/tree/tree.js +456 -0
  114. package/04-recipes/analysis-report/README.md +80 -0
  115. package/04-recipes/analysis-report/analysis-report.css +187 -0
  116. package/04-recipes/analysis-report/demo.html +274 -0
  117. package/04-recipes/data-showcase/README.md +45 -0
  118. package/04-recipes/data-showcase/demo.html +247 -0
  119. package/04-recipes/detail-page/README.md +93 -0
  120. package/04-recipes/detail-page/demo.html +55 -0
  121. package/04-recipes/detail-page/detail-page.css +190 -0
  122. package/04-recipes/detail-page/full.html +60 -0
  123. package/04-recipes/detail-page/null.html +60 -0
  124. package/04-recipes/detail-page/partial.html +60 -0
  125. package/04-recipes/detail-page/verify-skeleton.py +19 -0
  126. package/04-recipes/longform/README.md +93 -0
  127. package/04-recipes/longform/agc-memory.svg +4 -0
  128. package/04-recipes/longform/content.html +610 -0
  129. package/04-recipes/longform/content.md +51 -0
  130. package/04-recipes/longform/longform.html +627 -0
  131. package/04-recipes/report/README.md +176 -0
  132. package/04-recipes/report/demo.html +355 -0
  133. package/04-recipes/report/report.css +364 -0
  134. package/04-recipes/table/README.md +103 -0
  135. package/04-recipes/table/demo.html +455 -0
  136. package/04-recipes/table/table.css +372 -0
  137. package/04-recipes/tierA-tokens.css +189 -0
  138. package/09-assets/README.md +74 -0
  139. package/09-assets/bar/README.md +94 -0
  140. package/09-assets/bar/bar.css +166 -0
  141. package/09-assets/bar/bar.js +320 -0
  142. package/09-assets/bar/demo.html +176 -0
  143. package/09-assets/echarts-adapter/demo.html +192 -0
  144. package/09-assets/echarts-adapter/echarts-adapter.js +277 -0
  145. package/09-assets/model-viewer/README.md +155 -0
  146. package/09-assets/model-viewer/demo.html +105 -0
  147. package/09-assets/model-viewer/model-viewer.css +143 -0
  148. package/09-assets/model-viewer/model-viewer.js +423 -0
  149. package/09-assets/scientific-plot/README.md +94 -0
  150. package/09-assets/scientific-plot/demo.html +252 -0
  151. package/09-assets/scientific-plot/scientific-plot.css +141 -0
  152. package/09-assets/scientific-plot/scientific-plot.js +610 -0
  153. package/09-assets/sparkline/README.md +153 -0
  154. package/09-assets/sparkline/demo.html +163 -0
  155. package/09-assets/sparkline/sparkline.css +158 -0
  156. package/09-assets/sparkline/sparkline.js +508 -0
  157. package/API.md +332 -0
  158. package/CHANGELOG.md +3138 -0
  159. package/CODE_OF_CONDUCT.md +64 -0
  160. package/CONTRIBUTING.md +89 -0
  161. package/ERRORS.md +1658 -0
  162. package/LICENSE +21 -0
  163. package/README.md +497 -2
  164. package/SECURITY.md +72 -0
  165. package/START-HERE.md +164 -0
  166. package/SUPPORT.md +109 -0
  167. package/adapters/presentation/README.md +113 -0
  168. package/adapters/presentation/check.js +101 -0
  169. package/adapters/presentation/deck.schema.json +74 -0
  170. package/adapters/presentation/to-doc.js +138 -0
  171. package/ai/START-HERE.md +104 -0
  172. package/ai/behaviors.json +380 -0
  173. package/ai/behaviors.schema.json +61 -0
  174. package/ai/capabilities.json +56 -0
  175. package/ai/cli.js +387 -0
  176. package/ai/components.json +1944 -0
  177. package/ai/components.meta.json +168 -0
  178. package/ai/components.schema.json +220 -0
  179. package/ai/contract.schema.json +147 -0
  180. package/ai/deprecations.json +55 -0
  181. package/ai/deprecations.schema.json +85 -0
  182. package/ai/motion-policy.json +22 -0
  183. package/ai/patch.js +323 -0
  184. package/ai/patch.schema.json +63 -0
  185. package/ai/profiles.json +92 -0
  186. package/ai/tokens.audience.json +55 -0
  187. package/ai/tokens.audience.schema.json +73 -0
  188. package/ai/tokens.json +762 -0
  189. package/ai/tokens.schema.json +58 -0
  190. package/ai/tokens.tree.json +752 -0
  191. package/ai/tokens.tree.schema.json +56 -0
  192. package/ai/validate.js +383 -0
  193. package/dist/01-tokens/behavior/dismissable.js +60 -0
  194. package/dist/01-tokens/behavior/emit.js +21 -0
  195. package/dist/01-tokens/behavior/focus-return.js +31 -0
  196. package/dist/01-tokens/behavior/roving.js +77 -0
  197. package/dist/01-tokens/behavior/typeahead.js +61 -0
  198. package/dist/01-tokens/focus-ring.css +1 -0
  199. package/dist/01-tokens/page.css +1 -0
  200. package/dist/01-tokens/polyfill.js +78 -0
  201. package/dist/01-tokens/scrollbar.css +1 -0
  202. package/dist/01-tokens/theme-toggle.js +61 -0
  203. package/dist/01-tokens/tokens.css +1 -0
  204. package/dist/01-tokens/typography.css +1 -0
  205. package/dist/02-primitives/badge/badge.css +1 -0
  206. package/dist/02-primitives/button/button.css +1 -0
  207. package/dist/02-primitives/card/card.css +1 -0
  208. package/dist/02-primitives/choice/choice.css +1 -0
  209. package/dist/02-primitives/combobox/combobox.css +1 -0
  210. package/dist/02-primitives/combobox/combobox.js +439 -0
  211. package/dist/02-primitives/date-range/date-range.css +1 -0
  212. package/dist/02-primitives/date-range/date-range.js +267 -0
  213. package/dist/02-primitives/input/input.css +1 -0
  214. package/dist/02-primitives/popover/popover.css +1 -0
  215. package/dist/02-primitives/popover/popover.js +257 -0
  216. package/dist/02-primitives/progress/progress.css +1 -0
  217. package/dist/02-primitives/select/select.css +1 -0
  218. package/dist/02-primitives/select/select.js +449 -0
  219. package/dist/02-primitives/separator/separator.css +1 -0
  220. package/dist/02-primitives/skeleton/skeleton.css +1 -0
  221. package/dist/02-primitives/switch/switch.css +1 -0
  222. package/dist/03-patterns/accordion/accordion.css +1 -0
  223. package/dist/03-patterns/accordion/accordion.js +219 -0
  224. package/dist/03-patterns/content/content.css +1 -0
  225. package/dist/03-patterns/drawer/drawer.css +1 -0
  226. package/dist/03-patterns/drawer/drawer.js +229 -0
  227. package/dist/03-patterns/dropdown/dropdown.css +1 -0
  228. package/dist/03-patterns/dropdown/dropdown.js +365 -0
  229. package/dist/03-patterns/form-validation/form-validation.css +1 -0
  230. package/dist/03-patterns/list/flip.js +117 -0
  231. package/dist/03-patterns/list/list.css +1 -0
  232. package/dist/03-patterns/nav/nav.css +1 -0
  233. package/dist/03-patterns/nav/nav.js +322 -0
  234. package/dist/03-patterns/nav/toc.js +76 -0
  235. package/dist/03-patterns/overlay/overlay.css +1 -0
  236. package/dist/03-patterns/overlay/overlay.js +398 -0
  237. package/dist/03-patterns/pagination/pagination.css +1 -0
  238. package/dist/03-patterns/pagination/pagination.js +273 -0
  239. package/dist/03-patterns/reveal/reveal.css +1 -0
  240. package/dist/03-patterns/reveal/reveal.js +138 -0
  241. package/dist/03-patterns/states/states.css +1 -0
  242. package/dist/03-patterns/tabs/tabs.css +1 -0
  243. package/dist/03-patterns/tabs/tabs.js +242 -0
  244. package/dist/03-patterns/tooltip/tooltip.css +1 -0
  245. package/dist/03-patterns/tooltip/tooltip.js +213 -0
  246. package/dist/03-patterns/tree/tree.css +1 -0
  247. package/dist/03-patterns/tree/tree.js +383 -0
  248. package/dist/04-recipes/analysis-report/analysis-report.css +1 -0
  249. package/dist/04-recipes/detail-page/detail-page.css +1 -0
  250. package/dist/04-recipes/report/report.css +1 -0
  251. package/dist/04-recipes/table/table.css +1 -0
  252. package/dist/04-recipes/tierA-tokens.css +1 -0
  253. package/dist/09-assets/bar/bar.css +1 -0
  254. package/dist/09-assets/bar/bar.js +222 -0
  255. package/dist/09-assets/echarts-adapter/echarts-adapter.js +185 -0
  256. package/dist/09-assets/model-viewer/model-viewer.css +1 -0
  257. package/dist/09-assets/model-viewer/model-viewer.js +320 -0
  258. package/dist/09-assets/scientific-plot/scientific-plot.css +1 -0
  259. package/dist/09-assets/scientific-plot/scientific-plot.js +568 -0
  260. package/dist/09-assets/sparkline/sparkline.css +1 -0
  261. package/dist/09-assets/sparkline/sparkline.js +265 -0
  262. package/dist/COSTS.md +56 -0
  263. package/docs/AI-CONTRACT.md +197 -0
  264. package/docs/BACKLOG.md +127 -0
  265. package/docs/BENCHMARK.md +252 -0
  266. package/docs/GUIDANCE.md +154 -0
  267. package/docs/INVARIANT.md +372 -0
  268. package/docs/LAYER-BASELINE.md +158 -0
  269. package/docs/RELEASING.md +311 -0
  270. package/docs/RFC-THEME-SCOPE.md +141 -0
  271. package/docs/ROADMAP.md +182 -0
  272. package/index.html +82 -0
  273. package/package.json +107 -4
  274. package/types/index.d.ts +310 -0
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://frontend-lib.dev/ai/tokens.tree.schema.json",
4
+ "title": "frontend-lib 第二种令牌导出(分层 · 工具链友好)",
5
+ "$comment": [
6
+ "描述 ai/tokens.tree.json 的形状:**分层、键名不带 --、字段用 value/type(不带 $)**。",
7
+ "",
8
+ "🔴 为什么要有第二种:已有的 ai/tokens.json 是 DTCG 形状(带 -- 与 $),",
9
+ " 而 Style Dictionary 与 Figma Tokens(Tokens Studio)认的是**不带 $** 的",
10
+ " value/type,并且要按类别分层。同一个文件喂不进两套工具 ⇒ 两种各出一份,",
11
+ " index 段把两种键名互相对应起来。",
12
+ "",
13
+ "⚠️ 本文件是 05-audit/gen-tokens-tree.py 的**生成物**,不要手改。",
14
+ "⚠️ 它的正确性不由本 schema 保证(形状对 ≠ 值对):值与名字由",
15
+ " token-tree-gate.py 判据 ⑤ 挂到**浏览器 CSSOM** 上复核。",
16
+ "⚠️ 本 schema 只用了 ai/validate.js 白名单里的关键字。"
17
+ ],
18
+ "type": "object",
19
+ "required": ["schemaVersion", "source", "sets", "index", "meta"],
20
+ "properties": {
21
+ "schemaVersion": { "type": "string" },
22
+ "source": { "type": "string" },
23
+ "generatedBy": { "type": "string" },
24
+ "$comment": { "type": "string" },
25
+ "sets": {
26
+ "type": "object",
27
+ "additionalProperties": {
28
+ "type": "object",
29
+ "additionalProperties": {
30
+ "type": "object",
31
+ "additionalProperties": {
32
+ "type": "object",
33
+ "required": ["value", "type"],
34
+ "properties": {
35
+ "value": { "type": "string", "minLength": 1 },
36
+ "type": { "type": "string", "minLength": 1 }
37
+ }
38
+ }
39
+ }
40
+ }
41
+ },
42
+ "index": {
43
+ "type": "object",
44
+ "additionalProperties": { "type": "string", "pattern": "^[a-z][A-Za-z0-9]*/" }
45
+ },
46
+ "meta": {
47
+ "type": "object",
48
+ "required": ["lightCount", "darkCount"],
49
+ "properties": {
50
+ "lightCount": { "type": "integer", "minimum": 0 },
51
+ "darkCount": { "type": "integer", "minimum": 0 },
52
+ "categories": { "type": "array", "items": { "type": "string" } }
53
+ }
54
+ }
55
+ }
56
+ }
package/ai/validate.js ADDED
@@ -0,0 +1,383 @@
1
+ /*
2
+ * validate.js — 契约校验器(零第三方依赖)
3
+ *
4
+ * ============================================================================
5
+ * 🔴 它是**故意不完整**的,并且这个不完整被机械地守住了
6
+ * ----------------------------------------------------------------------------
7
+ * 完整实现 JSON Schema 需要几百 KB(ajv 就是这个量级)。
8
+ * 本库的核心约束是零第三方依赖,所以这里只实现**我们自己 schema 用到的**那些关键字。
9
+ *
10
+ * ⇒ 危险在于:哪天有人在 schema 里用了我们**没实现**的关键字
11
+ * (比如 `if` / `then` / `dependentSchemas`),
12
+ * 这个校验器会**静默忽略它** ⇒ 门禁绿着,而那条约束压根没被检查。
13
+ * 这就是"假绿"最典型的一种。
14
+ *
15
+ * ⇒ 解法:`SUPPORTED_KEYWORDS` 是白名单,`assertSchemasUseOnlySupported()`
16
+ * 会在每次校验前扫一遍全部 schema,遇到白名单外的关键字**直接抛错**。
17
+ * ⇒ 工具的能力边界由机器守住,不靠人记得。
18
+ *
19
+ * ============================================================================
20
+ * 对外接口
21
+ * ----------------------------------------------------------------------------
22
+ * validate(schema, data) → { ok, errors: [{path, msg}] }
23
+ * validateDoc(doc, opt) → { ok, errors, warnings }
24
+ * assertSchemasUseOnlySupported()
25
+ * ============================================================================
26
+ */
27
+ 'use strict';
28
+
29
+ var fs = require('fs');
30
+ var path = require('path');
31
+
32
+ var AI_DIR = __dirname;
33
+
34
+ // ---------------------------------------------------------------- 能力白名单
35
+ // ⚠️ 改这个表 = 改工具的能力边界。加关键字 ⇒ 必须同时实现它,否则别加。
36
+ var SUPPORTED_KEYWORDS = [
37
+ '$schema', '$id', '$comment', '$ref', 'definitions', 'title',
38
+ 'type', 'required', 'properties', 'additionalProperties', 'patternProperties',
39
+ 'items', 'enum', 'const', 'pattern', 'minLength', 'maxLength',
40
+ 'minimum', 'maximum', 'minItems', 'maxItems', 'uniqueItems',
41
+ 'allOf', 'anyOf', 'oneOf', 'not',
42
+ // 我们自己的元信息键(不是 JSON Schema 标准,由本库读取)
43
+ 'invariants', 'opRequirements'
44
+ ];
45
+
46
+ function readJSON(rel) {
47
+ return JSON.parse(fs.readFileSync(path.join(AI_DIR, rel), 'utf8'));
48
+ }
49
+
50
+ function isPlainObject(v) {
51
+ return v !== null && typeof v === 'object' && !Array.isArray(v);
52
+ }
53
+
54
+ /**
55
+ * 扫一遍 schema 里出现的所有关键字,遇到白名单外的就抛错。
56
+ * 🔴 这是防止"校验器静默漏检"的唯一手段。
57
+ */
58
+ // 哪些键的"值"本身还是 schema
59
+ var SUBSCHEMA_KEYS = [
60
+ 'items', 'additionalProperties', 'patternProperties', 'allOf', 'anyOf',
61
+ 'oneOf', 'not', 'propertyNames', 'contains', 'if', 'then', 'else'
62
+ ];
63
+ // 哪些键是"名字 → schema"的容器(它们的**键**是字段名,不是关键字)
64
+ var CONTAINER_KEYS = ['properties', 'definitions', '$defs', 'dependentSchemas'];
65
+
66
+ function assertSchemasUseOnlySupported() {
67
+ var files = ['contract.schema.json', 'components.schema.json',
68
+ 'tokens.schema.json', 'patch.schema.json'];
69
+ var unknown = [];
70
+
71
+ function checkNode(schema, f, ptr) {
72
+ if (!isPlainObject(schema)) return;
73
+ Object.keys(schema).forEach(function (k) {
74
+ // 🔴 只检查**处于 schema 位置**的键。
75
+ // `properties` 下面的键是数据字段名(例如 DTCG 的 $value / $type),
76
+ // 把它们当关键字 ⇒ 第一版把整份 tokens.schema.json 判成了非法(实测)。
77
+ if (SUPPORTED_KEYWORDS.indexOf(k) < 0) {
78
+ unknown.push(f + ' ' + ptr + ' → ' + k);
79
+ }
80
+ });
81
+ Object.keys(schema).forEach(function (k) {
82
+ var v = schema[k];
83
+ if (CONTAINER_KEYS.indexOf(k) >= 0 && isPlainObject(v)) {
84
+ Object.keys(v).forEach(function (name) {
85
+ checkNode(v[name], f, ptr + '/' + k + '/' + name);
86
+ });
87
+ } else if (SUBSCHEMA_KEYS.indexOf(k) >= 0) {
88
+ if (Array.isArray(v)) {
89
+ v.forEach(function (s, i) { checkNode(s, f, ptr + '/' + k + '/' + i); });
90
+ } else {
91
+ checkNode(v, f, ptr + '/' + k);
92
+ }
93
+ }
94
+ });
95
+ }
96
+
97
+ files.forEach(function (f) { checkNode(readJSON(f), f, ''); });
98
+
99
+ if (unknown.length) {
100
+ throw new Error('schema 用了校验器没实现的关键字,会导致静默漏检:\n ' +
101
+ unknown.join('\n '));
102
+ }
103
+ return true;
104
+ }
105
+
106
+ // ---------------------------------------------------------------- 校验核心
107
+ function typeOk(expected, value) {
108
+ if (Array.isArray(expected)) {
109
+ return expected.some(function (e) { return typeOk(e, value); });
110
+ }
111
+ if (expected === 'object') return isPlainObject(value);
112
+ if (expected === 'array') return Array.isArray(value);
113
+ if (expected === 'string') return typeof value === 'string';
114
+ if (expected === 'number') return typeof value === 'number';
115
+ if (expected === 'boolean') return typeof value === 'boolean';
116
+ if (expected === 'null') return value === null;
117
+ if (expected === 'integer') return typeof value === 'number' && value % 1 === 0;
118
+ return true;
119
+ }
120
+
121
+ function resolveRef(root, ref) {
122
+ if (ref.charAt(0) !== '#' || ref.indexOf('#/') !== 0) {
123
+ throw new Error('只支持文档内 $ref:' + ref);
124
+ }
125
+ var parts = ref.slice(2).split('/');
126
+ var cur = root;
127
+ for (var i = 0; i < parts.length; i++) {
128
+ cur = cur[parts[i].replace(/~1/g, '/').replace(/~0/g, '~')];
129
+ if (cur === undefined) throw new Error('$ref 找不到:' + ref);
130
+ }
131
+ return cur;
132
+ }
133
+
134
+ function validate(schema, data, root, ptr, errors) {
135
+ root = root || schema;
136
+ ptr = ptr || '';
137
+ errors = errors || [];
138
+
139
+ if (schema.$ref) {
140
+ return validate(resolveRef(root, schema.$ref), data, root, ptr, errors);
141
+ }
142
+
143
+ if (schema.type !== undefined && !typeOk(schema.type, data)) {
144
+ errors.push({ path: ptr, msg: '类型应为 ' + JSON.stringify(schema.type) +
145
+ ',实际是 ' + (data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data) });
146
+ return errors;
147
+ }
148
+ if (schema.enum !== undefined && schema.enum.indexOf(data) < 0) {
149
+ errors.push({ path: ptr, msg: '取值必须是 ' + JSON.stringify(schema.enum) +
150
+ ' 之一,实际是 ' + JSON.stringify(data) });
151
+ }
152
+ if (schema.const !== undefined && data !== schema.const) {
153
+ errors.push({ path: ptr, msg: '应为 ' + JSON.stringify(schema.const) });
154
+ }
155
+ if (typeof data === 'string') {
156
+ if (schema.pattern !== undefined && !(new RegExp(schema.pattern)).test(data)) {
157
+ errors.push({ path: ptr, msg: '不符合模式 ' + schema.pattern });
158
+ }
159
+ if (schema.minLength !== undefined && data.length < schema.minLength) {
160
+ errors.push({ path: ptr, msg: '长度不足 ' + schema.minLength });
161
+ }
162
+ if (schema.maxLength !== undefined && data.length > schema.maxLength) {
163
+ errors.push({ path: ptr, msg: '长度超过 ' + schema.maxLength });
164
+ }
165
+ }
166
+ if (typeof data === 'number') {
167
+ if (schema.minimum !== undefined && data < schema.minimum) {
168
+ errors.push({ path: ptr, msg: '小于最小值 ' + schema.minimum });
169
+ }
170
+ if (schema.maximum !== undefined && data > schema.maximum) {
171
+ errors.push({ path: ptr, msg: '大于最大值 ' + schema.maximum });
172
+ }
173
+ }
174
+ if (Array.isArray(data)) {
175
+ if (schema.minItems !== undefined && data.length < schema.minItems) {
176
+ errors.push({ path: ptr, msg: '元素少于 ' + schema.minItems + ' 个' });
177
+ }
178
+ if (schema.maxItems !== undefined && data.length > schema.maxItems) {
179
+ errors.push({ path: ptr, msg: '元素多于 ' + schema.maxItems + ' 个' });
180
+ }
181
+ if (schema.items) {
182
+ data.forEach(function (v, i) {
183
+ validate(schema.items, v, root, ptr + '/' + i, errors);
184
+ });
185
+ }
186
+ }
187
+ if (isPlainObject(data)) {
188
+ (schema.required || []).forEach(function (k) {
189
+ if (!(k in data)) {
190
+ errors.push({ path: ptr, msg: '缺少必填字段 ' + k });
191
+ }
192
+ });
193
+ var props = schema.properties || {};
194
+ Object.keys(data).forEach(function (k) {
195
+ if (props[k] !== undefined) {
196
+ validate(props[k], data[k], root, ptr + '/' + k, errors);
197
+ return;
198
+ }
199
+ var matched = false;
200
+ if (schema.patternProperties) {
201
+ Object.keys(schema.patternProperties).forEach(function (p) {
202
+ if ((new RegExp(p)).test(k)) {
203
+ validate(schema.patternProperties[p], data[k], root, ptr + '/' + k, errors);
204
+ matched = true;
205
+ }
206
+ });
207
+ }
208
+ if (matched) return;
209
+ if (schema.additionalProperties === false) {
210
+ errors.push({ path: ptr + '/' + k, msg: '不允许的字段 ' + k });
211
+ } else if (isPlainObject(schema.additionalProperties)) {
212
+ validate(schema.additionalProperties, data[k], root, ptr + '/' + k, errors);
213
+ }
214
+ });
215
+ }
216
+ (schema.allOf || []).forEach(function (s) { validate(s, data, root, ptr, errors); });
217
+ if (schema.anyOf) {
218
+ var anyOk = schema.anyOf.some(function (s) {
219
+ return validate(s, data, root, ptr, []).length === 0;
220
+ });
221
+ if (!anyOk) errors.push({ path: ptr, msg: '不满足 anyOf 中任何一条' });
222
+ }
223
+ if (schema.oneOf) {
224
+ var n = schema.oneOf.filter(function (s) {
225
+ return validate(s, data, root, ptr, []).length === 0;
226
+ }).length;
227
+ if (n !== 1) {
228
+ errors.push({ path: ptr, msg: '必须恰好满足 oneOf 中的一条,实际满足 ' + n + ' 条' });
229
+ }
230
+ }
231
+ return errors;
232
+ }
233
+
234
+ // ---------------------------------------------------------------- 文档校验
235
+ /**
236
+ * 校验一份编辑文档。
237
+ * @param {object} doc 符合 contract.schema.json 的文档
238
+ * @param {object} opt { profile: 'creative'|'standard'|'strict' }
239
+ * @returns {{ok:boolean, errors:Array, warnings:Array}}
240
+ */
241
+ function validateDoc(doc, opt) {
242
+ opt = opt || {};
243
+ assertSchemasUseOnlySupported();
244
+
245
+ var contract = readJSON('contract.schema.json');
246
+ var errors = validate(contract, doc, contract, '');
247
+ var warnings = [];
248
+ // 🔴 显式覆盖必须优先于文档自己声明的档位。
249
+ // 第一版写成 `doc.profile || opt.profile` ⇒
250
+ // CLI 的 `--profile=strict` 对任何自带 profile 的文档**完全无效**(实测),
251
+ // 而退出码还是 0 ⇒ 看上去"校验通过了"。
252
+ var profileName = opt.profile || doc.profile || 'standard';
253
+ var profiles = readJSON('profiles.json').profiles;
254
+ var profile = profiles[profileName];
255
+
256
+ if (!profile) {
257
+ errors.push({ path: '/profile', msg: '未知档位 ' + profileName +
258
+ '(可用:' + Object.keys(profiles).join(' / ') + ')' });
259
+ profile = profiles.standard;
260
+ }
261
+
262
+ // ---- 结构完整性:children 引用的 id 必须存在,且不能形成环
263
+ var nodes = doc.nodes || {};
264
+ var ids = Object.keys(nodes);
265
+ ids.forEach(function (id) {
266
+ (nodes[id].children || []).forEach(function (c) {
267
+ if (!(c in nodes)) {
268
+ errors.push({ path: '/nodes/' + id + '/children',
269
+ msg: '引用了不存在的节点 id:' + c });
270
+ }
271
+ });
272
+ });
273
+ var seen = {};
274
+ function visit(id, stack) {
275
+ if (stack.indexOf(id) >= 0) {
276
+ errors.push({ path: '/nodes/' + id, msg: '节点引用成环:' + stack.concat(id).join(' → ') });
277
+ return;
278
+ }
279
+ if (seen[id]) return;
280
+ seen[id] = true;
281
+ (nodes[id].children || []).forEach(function (c) {
282
+ if (nodes[c]) visit(c, stack.concat(id));
283
+ });
284
+ }
285
+ ids.forEach(function (id) { visit(id, []); });
286
+
287
+ // ---- root 里的 id 必须存在
288
+ (doc.root || []).forEach(function (id) {
289
+ if (!(id in nodes)) {
290
+ errors.push({ path: '/root', msg: 'root 引用了不存在的节点 id:' + id });
291
+ }
292
+ });
293
+
294
+ // ---- 组件成熟度(Profile 的核心差异)
295
+ //
296
+ // ⚠️ `opt.components` 是**为了可测性**留的口子,不是给使用者的配置项。
297
+ // 没有它,"strict 档必须拒绝 beta 组件"这条规则就只能靠
298
+ // **真实组件表里恰好有 beta 组件**才验证得了。
299
+ //
300
+ // 实测踩到:状态收敛完成后 27 个组件全部升到 stable,
301
+ // 于是没有任何 beta ⇒ 这条判据**无法执行**,门禁直接报"前置条件不足"。
302
+ // ⇒ 那是"门禁因为库变好了而失去鉴别力",正是要避免的假绿。
303
+ // ⇒ 正解:用**合成夹具**证明规则本身成立,与真实组件表无关。
304
+ var src = opt.components || readJSON('components.json').components || [];
305
+ var comps = {};
306
+ src.forEach(function (c) { comps[c.id] = c; });
307
+ ids.forEach(function (id) {
308
+ var n = nodes[id];
309
+ if (n.kind === 'text' || n.kind === 'slot') return;
310
+ var c = comps[n.kind];
311
+ if (!c) {
312
+ if (profile.allowedUnknownComponent) {
313
+ warnings.push({ path: '/nodes/' + id,
314
+ msg: '组件 ' + n.kind + ' 不在契约里(本档位放行,但渲染结果无保证)' });
315
+ } else {
316
+ errors.push({ path: '/nodes/' + id,
317
+ msg: '组件 ' + n.kind + ' 不在契约里,本档位(' + profileName + ')不允许' });
318
+ }
319
+ return;
320
+ }
321
+ if (profile.allowedMaturity.indexOf(c.maturity) < 0) {
322
+ errors.push({ path: '/nodes/' + id,
323
+ msg: '组件 ' + n.kind + ' 的成熟度是 ' + c.maturity +
324
+ ',本档位(' + profileName + ')只允许 ' +
325
+ profile.allowedMaturity.join(' / ') });
326
+ }
327
+ var props = n.props || {};
328
+ // 变体
329
+ Object.keys(props).forEach(function (k) {
330
+ if (k === 'variant' && typeof props[k] === 'string') {
331
+ if (c.variants.indexOf(props[k]) < 0) {
332
+ if (profile.allowedUnknownVariant) {
333
+ warnings.push({ path: '/nodes/' + id + '/props/variant',
334
+ msg: '变体 ' + props[k] + ' 不在契约里(已知:' +
335
+ (c.variants.join(', ') || '无') + ')' });
336
+ } else {
337
+ errors.push({ path: '/nodes/' + id + '/props/variant',
338
+ msg: '变体 ' + props[k] + ' 不在契约里,本档位不允许' });
339
+ }
340
+ }
341
+ }
342
+ });
343
+ // 状态取值
344
+ Object.keys(props).forEach(function (k) {
345
+ if (k.indexOf('data-') !== 0) return;
346
+ var known = c.states && c.states.enum && c.states.enum[k];
347
+ if (known && known.indexOf(String(props[k])) < 0) {
348
+ if (profile.allowedUnknownState) {
349
+ warnings.push({ path: '/nodes/' + id + '/props/' + k,
350
+ msg: '状态取值 ' + JSON.stringify(props[k]) + ' 不在契约里(已知:' +
351
+ known.join(' / ') + ')' });
352
+ } else {
353
+ errors.push({ path: '/nodes/' + id + '/props/' + k,
354
+ msg: '状态取值 ' + JSON.stringify(props[k]) + ' 不在契约里(已知:' +
355
+ known.join(' / ') + ')—— 写错会让组件静默停在错误状态' });
356
+ }
357
+ }
358
+ });
359
+ });
360
+
361
+ // ---- 前向兼容:extensions 必须是对象,未知键不得影响判定
362
+ if (doc.extensions !== undefined && !isPlainObject(doc.extensions)) {
363
+ errors.push({ path: '/extensions', msg: 'extensions 必须是对象' });
364
+ }
365
+ if (!profile.allowedExtensions && doc.extensions &&
366
+ Object.keys(doc.extensions).length > 0) {
367
+ errors.push({ path: '/extensions', msg: '本档位(' + profileName +
368
+ ')不允许携带扩展字段' });
369
+ }
370
+
371
+ return { ok: errors.length === 0, errors: errors, warnings: warnings,
372
+ profile: profileName };
373
+ }
374
+
375
+ module.exports = {
376
+ validate: function (schema, data) {
377
+ return { ok: validate(schema, data, schema, '').length === 0,
378
+ errors: validate(schema, data, schema, '') };
379
+ },
380
+ validateDoc: validateDoc,
381
+ assertSchemasUseOnlySupported: assertSchemasUseOnlySupported,
382
+ SUPPORTED_KEYWORDS: SUPPORTED_KEYWORDS
383
+ };
@@ -0,0 +1,60 @@
1
+ var flDismissable = function (opts) {
2
+ var opt = opts || {};
3
+ var escOn = opt.escOn || [];
4
+ var inside = opt.inside || [];
5
+ var when = opt.when || function () { return true; };
6
+ var onDismiss = opt.onDismiss || function () {};
7
+
8
+ var shared = window.__flDismiss || (window.__flDismiss = { stack: [], bound: false });
9
+
10
+ function isInside(node) {
11
+ if (!node) return false;
12
+ for (var i = 0; i < inside.length; i++) {
13
+ var el = inside[i];
14
+ if (!el || !el.contains) continue;
15
+ if (el === node || el.contains(node)) return true;
16
+ }
17
+ return false;
18
+ }
19
+
20
+ function onKey(e) {
21
+ if (!when()) return;
22
+ var k = e.key;
23
+ if (k !== 'Escape' && k !== 'Esc' && e.keyCode !== 27) return;
24
+
25
+ var closed = onDismiss(e, 'esc');
26
+ if (closed === false) return;
27
+ if (e.preventDefault) e.preventDefault();
28
+ if (e.stopPropagation) e.stopPropagation();
29
+ }
30
+
31
+ function onDocClick(e) {
32
+ var top = null;
33
+ for (var i = shared.stack.length - 1; i >= 0; i--) {
34
+ if (shared.stack[i].when()) { top = shared.stack[i]; break; }
35
+ }
36
+ if (!top || top.isInside(e.target)) return;
37
+ top.onDismiss(e, 'outside');
38
+ }
39
+
40
+ var rec = { when: when, isInside: isInside, onDismiss: onDismiss };
41
+
42
+ for (var j = 0; j < escOn.length; j++) {
43
+ if (escOn[j]) escOn[j].addEventListener('keydown', onKey);
44
+ }
45
+ shared.stack.push(rec);
46
+ if (!shared.bound) {
47
+ shared.bound = true;
48
+ document.addEventListener('click', onDocClick, true);
49
+ }
50
+
51
+ return {
52
+ destroy: function () {
53
+ for (var j = 0; j < escOn.length; j++) {
54
+ if (escOn[j]) escOn[j].removeEventListener('keydown', onKey);
55
+ }
56
+ var k = shared.stack.indexOf(rec);
57
+ if (k >= 0) shared.stack.splice(k, 1);
58
+ },
59
+ };
60
+ };
@@ -0,0 +1,21 @@
1
+ var flEmit = function (el, name, detail) {
2
+ if (!el || !el.dispatchEvent) return null;
3
+ var type = name.indexOf('fl-') === 0 ? name : 'fl-' + name;
4
+ var ev = null;
5
+
6
+ if (typeof window.CustomEvent === 'function') {
7
+ try {
8
+ ev = new window.CustomEvent(type, {
9
+ detail: detail || null, bubbles: true, cancelable: false
10
+ });
11
+ } catch (e) { ev = null; }
12
+ }
13
+ if (!ev) {
14
+ try {
15
+ ev = document.createEvent('CustomEvent');
16
+ ev.initCustomEvent(type, true, false, detail || null);
17
+ } catch (e2) { return null; }
18
+ }
19
+ el.dispatchEvent(ev);
20
+ return ev;
21
+ };
@@ -0,0 +1,31 @@
1
+ var flFocusReturn = function (opts) {
2
+ var opt = opts || {};
3
+ var saved = null;
4
+
5
+ return {
6
+ save: function () {
7
+ var a = document.activeElement;
8
+ saved = (a && a !== document.body && a.focus) ? a : null;
9
+ return saved;
10
+ },
11
+
12
+ restore: function () {
13
+ var target = saved;
14
+
15
+ if (!target || !document.contains(target)) target = opt.fallback || null;
16
+ if (!target) { saved = null; return false; }
17
+ try {
18
+ target.focus();
19
+ } catch (e) {
20
+ saved = null;
21
+ return false;
22
+ }
23
+ var ok = document.activeElement === target;
24
+ saved = null;
25
+ return ok;
26
+ },
27
+
28
+ target: function () { return saved; },
29
+ clear: function () { saved = null; },
30
+ };
31
+ };
@@ -0,0 +1,77 @@
1
+ var flRoving = function (opts) {
2
+ var opt = opts || {};
3
+ var container = opt.container;
4
+ var all = opt.items || function () { return []; };
5
+ var movable = opt.movable || all;
6
+ var nodeOf = opt.nodeOf || function (x) { return x; };
7
+ var axis = opt.axis || 'x';
8
+ var loop = opt.loop !== false;
9
+ var homeEnd = opt.homeEnd !== false;
10
+
11
+ var roveTab = opt.tabindex !== false;
12
+ var onMove = opt.onMove || function () {};
13
+
14
+ function rove(target) {
15
+ if (!roveTab) return target;
16
+ var l = all() || [];
17
+ for (var i = 0; i < l.length; i++) {
18
+ var n = nodeOf(l[i]);
19
+ if (!n || !n.setAttribute) continue;
20
+ n.setAttribute('tabindex', n === target ? '0' : '-1');
21
+ }
22
+ return target;
23
+ }
24
+
25
+ function step(i, d) {
26
+ var n = (movable() || []).length;
27
+ if (!n) return -1;
28
+ if (loop) return ((i + d) % n + n) % n;
29
+ var t = i + d;
30
+ return (t < 0 || t >= n) ? -1 : t;
31
+ }
32
+
33
+ function indexOfNode(node) {
34
+ var l = movable() || [];
35
+ for (var i = 0; i < l.length; i++) {
36
+ if (nodeOf(l[i]) === node) return i;
37
+ }
38
+ return -1;
39
+ }
40
+
41
+ function onKey(e) {
42
+ var l = movable() || [];
43
+ if (!l.length) return;
44
+ var i = indexOfNode(e.target);
45
+ if (i < 0) return;
46
+ var k = e.key;
47
+ var next = -1;
48
+ var reason = 'step';
49
+
50
+ if (axis === 'y') {
51
+ if (k === 'ArrowDown') next = step(i, 1);
52
+ else if (k === 'ArrowUp') next = step(i, -1);
53
+ } else {
54
+ if (k === 'ArrowRight') next = step(i, 1);
55
+ else if (k === 'ArrowLeft') next = step(i, -1);
56
+ }
57
+ if (homeEnd && k === 'Home') { next = 0; reason = 'home'; }
58
+ else if (homeEnd && k === 'End') { next = l.length - 1; reason = 'end'; }
59
+
60
+ if (next < 0 || next >= l.length) return;
61
+
62
+ if (e.preventDefault) e.preventDefault();
63
+ if (e.stopPropagation) e.stopPropagation();
64
+ onMove(next, l[next], reason);
65
+ }
66
+
67
+ if (container) container.addEventListener('keydown', onKey);
68
+
69
+ return {
70
+ rove: rove,
71
+ step: step,
72
+ indexOf: indexOfNode,
73
+ destroy: function () {
74
+ if (container) container.removeEventListener('keydown', onKey);
75
+ },
76
+ };
77
+ };
@@ -0,0 +1,61 @@
1
+ var flTypeahead = function (opts) {
2
+ var opt = opts || {};
3
+ var items = opt.items || function () { return []; };
4
+ var textOf = opt.textOf || function (x) { return String((x && x.textContent) || ''); };
5
+ var usable = opt.usable || function () { return true; };
6
+ var timeout = opt.timeout || 500;
7
+ var onHit = opt.onHit || function () {};
8
+ var buf = '';
9
+ var timer = null;
10
+ var last = -1;
11
+
12
+ function stop() {
13
+ if (timer) { clearTimeout(timer); timer = null; }
14
+ }
15
+
16
+ function repeated(s) {
17
+ if (s.length < 2) return false;
18
+ for (var i = 1; i < s.length; i++) {
19
+ if (s.charAt(i) !== s.charAt(0)) return false;
20
+ }
21
+ return true;
22
+ }
23
+
24
+ function find(needle) {
25
+ var l = items() || [];
26
+ var n = l.length;
27
+ if (!n) return -1;
28
+ for (var k = 0; k < n; k++) {
29
+ var i = (last + 1 + k) % n;
30
+ if (!usable(l[i])) continue;
31
+ if (textOf(l[i]).toLowerCase().indexOf(needle) === 0) return i;
32
+ }
33
+ return -1;
34
+ }
35
+
36
+ function type(ch) {
37
+ if (!ch) return -1;
38
+ buf += String(ch).toLowerCase();
39
+ stop();
40
+ timer = setTimeout(clear, timeout);
41
+ var needle = repeated(buf) ? buf.charAt(0) : buf;
42
+ var i = find(needle);
43
+ if (i >= 0) {
44
+ last = i;
45
+ onHit(i, (items() || [])[i], buf);
46
+ }
47
+ return i;
48
+ }
49
+
50
+ function clear() {
51
+ buf = '';
52
+ stop();
53
+ }
54
+
55
+ return {
56
+ type: type,
57
+ clear: clear,
58
+ buffer: function () { return buf; },
59
+ destroy: function () { stop(); },
60
+ };
61
+ };