@lushly-dev/fast-element 0.0.0-stage → 3.0.1-preview.1

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 (257) hide show
  1. package/CHANGELOG.md +1059 -0
  2. package/LICENSE +23 -0
  3. package/README.md +280 -2
  4. package/dist/command/command.api.json +7857 -0
  5. package/dist/context/context.api.json +1084 -0
  6. package/dist/declarative/declarative.api.json +8130 -0
  7. package/dist/definition-schema/definition-schema.api.json +2689 -0
  8. package/dist/di/di.api.json +4945 -0
  9. package/dist/dts/arrays.d.ts +2 -0
  10. package/dist/dts/binding/binding.d.ts +59 -0
  11. package/dist/dts/binding/exports.d.ts +9 -0
  12. package/dist/dts/binding/normalize.d.ts +9 -0
  13. package/dist/dts/binding/one-time.d.ts +11 -0
  14. package/dist/dts/binding/one-way.d.ts +20 -0
  15. package/dist/dts/binding/signal.d.ts +36 -0
  16. package/dist/dts/binding/two-way.d.ts +44 -0
  17. package/dist/dts/command/behavior.d.ts +94 -0
  18. package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
  19. package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
  20. package/dist/dts/command/command.d.ts +79 -0
  21. package/dist/dts/command/component-registry.d.ts +50 -0
  22. package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
  23. package/dist/dts/command/index.d.ts +21 -0
  24. package/dist/dts/command/registry.d.ts +201 -0
  25. package/dist/dts/command/schema-validation.d.ts +45 -0
  26. package/dist/dts/command/types.d.ts +332 -0
  27. package/dist/dts/command/validation.d.ts +116 -0
  28. package/dist/dts/command/weak-ref.d.ts +11 -0
  29. package/dist/dts/components/attributes.d.ts +153 -0
  30. package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
  31. package/dist/dts/components/element-controller.d.ts +349 -0
  32. package/dist/dts/components/element-hydration.d.ts +2 -0
  33. package/dist/dts/components/enable-hydration.d.ts +66 -0
  34. package/dist/dts/components/fast-definitions.d.ts +211 -0
  35. package/dist/dts/components/fast-element-registry.d.ts +23 -0
  36. package/dist/dts/components/fast-element.d.ts +91 -0
  37. package/dist/dts/components/hydration-tracker.d.ts +110 -0
  38. package/dist/dts/components/hydration.d.ts +52 -0
  39. package/dist/dts/components/schema.d.ts +205 -0
  40. package/dist/dts/context.d.ts +171 -0
  41. package/dist/dts/debug.d.ts +5 -0
  42. package/dist/dts/declarative/attribute-map.d.ts +58 -0
  43. package/dist/dts/declarative/debug.d.ts +4 -0
  44. package/dist/dts/declarative/index.d.ts +14 -0
  45. package/dist/dts/declarative/interfaces.d.ts +8 -0
  46. package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
  47. package/dist/dts/declarative/observer-map.d.ts +89 -0
  48. package/dist/dts/declarative/runtime.d.ts +5 -0
  49. package/dist/dts/declarative/syntax.d.ts +21 -0
  50. package/dist/dts/declarative/template-bridge.d.ts +33 -0
  51. package/dist/dts/declarative/template-parser.d.ts +98 -0
  52. package/dist/dts/declarative/template.d.ts +9 -0
  53. package/dist/dts/declarative/utilities.d.ts +358 -0
  54. package/dist/dts/definition-schema/api.d.ts +42 -0
  55. package/dist/dts/definition-schema/cem.d.ts +78 -0
  56. package/dist/dts/definition-schema/extension.d.ts +18 -0
  57. package/dist/dts/definition-schema/extract.d.ts +38 -0
  58. package/dist/dts/definition-schema/index.d.ts +9 -0
  59. package/dist/dts/definition-schema/storage.d.ts +35 -0
  60. package/dist/dts/definition-schema/types.d.ts +176 -0
  61. package/dist/dts/dev-mode.d.ts +13 -0
  62. package/dist/dts/di/di.d.ts +894 -0
  63. package/dist/dts/dom-policy.d.ts +101 -0
  64. package/dist/dts/dom.d.ts +88 -0
  65. package/dist/dts/hydration/diagnostics.d.ts +93 -0
  66. package/dist/dts/hydration/exports.d.ts +18 -0
  67. package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
  68. package/dist/dts/hydration/messages.d.ts +62 -0
  69. package/dist/dts/hydration/runtime.d.ts +7 -0
  70. package/dist/dts/hydration/target-builder.d.ts +107 -0
  71. package/dist/dts/index.d.ts +51 -0
  72. package/dist/dts/index.debug.d.ts +1 -0
  73. package/dist/dts/index.rollup.d.ts +1 -0
  74. package/dist/dts/index.rollup.debug.d.ts +1 -0
  75. package/dist/dts/interfaces.d.ts +106 -0
  76. package/dist/dts/metadata.d.ts +26 -0
  77. package/dist/dts/observation/arrays.d.ts +248 -0
  78. package/dist/dts/observation/notifier.d.ts +127 -0
  79. package/dist/dts/observation/observable.d.ts +276 -0
  80. package/dist/dts/observation/update-queue.d.ts +40 -0
  81. package/dist/dts/observation/volatile.d.ts +9 -0
  82. package/dist/dts/platform.d.ts +87 -0
  83. package/dist/dts/registry.d.ts +2 -0
  84. package/dist/dts/render.d.ts +7 -0
  85. package/dist/dts/schema.d.ts +1 -0
  86. package/dist/dts/scoped/detection.d.ts +55 -0
  87. package/dist/dts/scoped/index.d.ts +68 -0
  88. package/dist/dts/scoped/mixin.d.ts +118 -0
  89. package/dist/dts/scoped/registry.d.ts +76 -0
  90. package/dist/dts/scoped/types.d.ts +48 -0
  91. package/dist/dts/state/exports.d.ts +3 -0
  92. package/dist/dts/state/reactive.d.ts +8 -0
  93. package/dist/dts/state/state.d.ts +141 -0
  94. package/dist/dts/state/visitor.d.ts +6 -0
  95. package/dist/dts/state/watch.d.ts +10 -0
  96. package/dist/dts/styles/css-directive.d.ts +50 -0
  97. package/dist/dts/styles/css.d.ts +34 -0
  98. package/dist/dts/styles/element-styles.d.ts +61 -0
  99. package/dist/dts/styles/host.d.ts +65 -0
  100. package/dist/dts/styles/style-strategy.d.ts +42 -0
  101. package/dist/dts/templating/children.d.ts +62 -0
  102. package/dist/dts/templating/compiler.d.ts +54 -0
  103. package/dist/dts/templating/html-binding-directive.d.ts +155 -0
  104. package/dist/dts/templating/html-directive.d.ts +218 -0
  105. package/dist/dts/templating/html.d.ts +1 -0
  106. package/dist/dts/templating/hydration-view.d.ts +130 -0
  107. package/dist/dts/templating/markup.d.ts +48 -0
  108. package/dist/dts/templating/node-observation.d.ts +99 -0
  109. package/dist/dts/templating/ref.d.ts +23 -0
  110. package/dist/dts/templating/render.d.ts +318 -0
  111. package/dist/dts/templating/repeat.d.ts +131 -0
  112. package/dist/dts/templating/slotted.d.ts +38 -0
  113. package/dist/dts/templating/template.d.ts +221 -0
  114. package/dist/dts/templating/view.d.ts +268 -0
  115. package/dist/dts/templating/when.d.ts +12 -0
  116. package/dist/dts/testing/exports.d.ts +3 -0
  117. package/dist/dts/testing/fakes.d.ts +15 -0
  118. package/dist/dts/testing/fixture.d.ts +84 -0
  119. package/dist/dts/testing/models.d.ts +20 -0
  120. package/dist/dts/testing/timeout.d.ts +7 -0
  121. package/dist/dts/trust/index.d.ts +8 -0
  122. package/dist/dts/trust/types.d.ts +48 -0
  123. package/dist/dts/trust/utils.d.ts +26 -0
  124. package/dist/dts/tsdoc-metadata.json +11 -0
  125. package/dist/dts/utilities.d.ts +76 -0
  126. package/dist/esm/arrays.js +1 -0
  127. package/dist/esm/binding/binding.js +18 -0
  128. package/dist/esm/binding/exports.js +6 -0
  129. package/dist/esm/binding/normalize.js +17 -0
  130. package/dist/esm/binding/one-time.js +21 -0
  131. package/dist/esm/binding/one-way.js +30 -0
  132. package/dist/esm/binding/signal.js +99 -0
  133. package/dist/esm/binding/two-way.js +110 -0
  134. package/dist/esm/command/behavior.js +155 -0
  135. package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
  136. package/dist/esm/command/behaviors/undo-behavior.js +312 -0
  137. package/dist/esm/command/command.js +104 -0
  138. package/dist/esm/command/component-registry.js +107 -0
  139. package/dist/esm/command/components/confirm-dialog.js +370 -0
  140. package/dist/esm/command/index.js +22 -0
  141. package/dist/esm/command/registry.js +752 -0
  142. package/dist/esm/command/schema-validation.js +194 -0
  143. package/dist/esm/command/types.js +86 -0
  144. package/dist/esm/command/validation.js +511 -0
  145. package/dist/esm/command/weak-ref.js +5 -0
  146. package/dist/esm/components/attributes.js +219 -0
  147. package/dist/esm/components/definition-schema-transforms.js +23 -0
  148. package/dist/esm/components/element-controller.js +839 -0
  149. package/dist/esm/components/element-hydration.js +2 -0
  150. package/dist/esm/components/enable-hydration.js +123 -0
  151. package/dist/esm/components/fast-definitions.js +294 -0
  152. package/dist/esm/components/fast-element-registry.js +67 -0
  153. package/dist/esm/components/fast-element.js +82 -0
  154. package/dist/esm/components/hydration-tracker.js +210 -0
  155. package/dist/esm/components/hydration.js +187 -0
  156. package/dist/esm/components/schema.js +253 -0
  157. package/dist/esm/context.js +185 -0
  158. package/dist/esm/debug.js +71 -0
  159. package/dist/esm/declarative/attribute-map.js +121 -0
  160. package/dist/esm/declarative/debug.js +4 -0
  161. package/dist/esm/declarative/index.js +10 -0
  162. package/dist/esm/declarative/interfaces.js +9 -0
  163. package/dist/esm/declarative/observer-map-utilities.js +565 -0
  164. package/dist/esm/declarative/observer-map.js +216 -0
  165. package/dist/esm/declarative/runtime.js +14 -0
  166. package/dist/esm/declarative/syntax.js +36 -0
  167. package/dist/esm/declarative/template-bridge.js +160 -0
  168. package/dist/esm/declarative/template-parser.js +306 -0
  169. package/dist/esm/declarative/template.js +116 -0
  170. package/dist/esm/declarative/utilities.js +1069 -0
  171. package/dist/esm/definition-schema/api.js +129 -0
  172. package/dist/esm/definition-schema/cem.js +89 -0
  173. package/dist/esm/definition-schema/extension.js +53 -0
  174. package/dist/esm/definition-schema/extract.js +167 -0
  175. package/dist/esm/definition-schema/index.js +8 -0
  176. package/dist/esm/definition-schema/storage.js +58 -0
  177. package/dist/esm/definition-schema/types.js +8 -0
  178. package/dist/esm/dev-mode.js +22 -0
  179. package/dist/esm/di/di.js +1440 -0
  180. package/dist/esm/dom-policy.js +374 -0
  181. package/dist/esm/dom.js +101 -0
  182. package/dist/esm/hydration/diagnostics.js +50 -0
  183. package/dist/esm/hydration/exports.js +6 -0
  184. package/dist/esm/hydration/hydration-debugger.js +112 -0
  185. package/dist/esm/hydration/messages.js +84 -0
  186. package/dist/esm/hydration/runtime.js +33 -0
  187. package/dist/esm/hydration/target-builder.js +264 -0
  188. package/dist/esm/index.debug.js +3 -0
  189. package/dist/esm/index.js +49 -0
  190. package/dist/esm/index.rollup.debug.js +6 -0
  191. package/dist/esm/index.rollup.js +4 -0
  192. package/dist/esm/interfaces.js +55 -0
  193. package/dist/esm/metadata.js +63 -0
  194. package/dist/esm/observation/arrays.js +661 -0
  195. package/dist/esm/observation/notifier.js +164 -0
  196. package/dist/esm/observation/observable.js +324 -0
  197. package/dist/esm/observation/update-queue.js +56 -0
  198. package/dist/esm/observation/volatile.js +16 -0
  199. package/dist/esm/platform.js +98 -0
  200. package/dist/esm/registry.js +2 -0
  201. package/dist/esm/render.js +1 -0
  202. package/dist/esm/schema.js +1 -0
  203. package/dist/esm/scoped/detection.js +102 -0
  204. package/dist/esm/scoped/index.js +69 -0
  205. package/dist/esm/scoped/mixin.js +127 -0
  206. package/dist/esm/scoped/registry.js +125 -0
  207. package/dist/esm/scoped/types.js +4 -0
  208. package/dist/esm/state/exports.js +3 -0
  209. package/dist/esm/state/reactive.js +34 -0
  210. package/dist/esm/state/state.js +148 -0
  211. package/dist/esm/state/visitor.js +28 -0
  212. package/dist/esm/state/watch.js +36 -0
  213. package/dist/esm/styles/css-directive.js +36 -0
  214. package/dist/esm/styles/css.js +56 -0
  215. package/dist/esm/styles/element-styles.js +144 -0
  216. package/dist/esm/styles/host.js +1 -0
  217. package/dist/esm/styles/style-strategy.js +1 -0
  218. package/dist/esm/templating/children.js +67 -0
  219. package/dist/esm/templating/compiler.js +359 -0
  220. package/dist/esm/templating/html-binding-directive.js +288 -0
  221. package/dist/esm/templating/html-directive.js +113 -0
  222. package/dist/esm/templating/html.js +1 -0
  223. package/dist/esm/templating/hydration-view.js +228 -0
  224. package/dist/esm/templating/markup.js +83 -0
  225. package/dist/esm/templating/node-observation.js +84 -0
  226. package/dist/esm/templating/ref.js +21 -0
  227. package/dist/esm/templating/render.js +468 -0
  228. package/dist/esm/templating/repeat.js +434 -0
  229. package/dist/esm/templating/slotted.js +49 -0
  230. package/dist/esm/templating/template.js +206 -0
  231. package/dist/esm/templating/view.js +298 -0
  232. package/dist/esm/templating/when.js +22 -0
  233. package/dist/esm/testing/exports.js +3 -0
  234. package/dist/esm/testing/fakes.js +107 -0
  235. package/dist/esm/testing/fixture.js +86 -0
  236. package/dist/esm/testing/models.js +58 -0
  237. package/dist/esm/testing/timeout.js +24 -0
  238. package/dist/esm/trust/index.js +7 -0
  239. package/dist/esm/trust/types.js +6 -0
  240. package/dist/esm/trust/utils.js +126 -0
  241. package/dist/esm/utilities.js +140 -0
  242. package/dist/fast-element.api.json +26798 -0
  243. package/dist/fast-element.d.ts +3985 -0
  244. package/dist/fast-element.debug.js +7618 -0
  245. package/dist/fast-element.debug.min.js +3 -0
  246. package/dist/fast-element.js +7617 -0
  247. package/dist/fast-element.min.js +3 -0
  248. package/dist/fast-element.untrimmed.d.ts +4103 -0
  249. package/dist/observation/arrays/arrays.api.json +2621 -0
  250. package/dist/scoped/scoped.api.json +891 -0
  251. package/dist/trust/trust.api.json +629 -0
  252. package/migration/fast-html/rules/README.md +15 -0
  253. package/migration/fast-html/rules/attribute-directives.yml +38 -0
  254. package/migration/fast-html/rules/call-expression-with-event-argument.yml +41 -0
  255. package/migration/fast-html/rules/member-expression.yml +33 -0
  256. package/migration/fast-html/rules/tag-function-to-template-literal.yml +16 -0
  257. package/package.json +233 -3
@@ -0,0 +1,129 @@
1
+ import { getClassByTag, getRegistryTagMap, getSchemaByClass } from "./storage.js";
2
+ /**
3
+ * Retrieves the schema for a custom element by its tag name.
4
+ * @param name - The custom element tag name.
5
+ * @param registry - The custom element registry (defaults to global customElements).
6
+ * @returns The component schema if found, undefined otherwise.
7
+ * @public
8
+ */
9
+ export function getSchema(name, registry = customElements) {
10
+ const cls = getClassByTag(name, registry);
11
+ if (!cls)
12
+ return undefined;
13
+ const schema = getSchemaByClass(cls);
14
+ if (!schema)
15
+ return undefined;
16
+ // Clone with actual tag name (may differ per registration)
17
+ return Object.assign(Object.assign({}, schema), { name });
18
+ }
19
+ /**
20
+ * Retrieves the schema for a custom element by its tag name, throwing if not found.
21
+ * @param name - The custom element tag name.
22
+ * @param registry - The custom element registry (defaults to global customElements).
23
+ * @returns The component schema.
24
+ * @throws TypeError if no schema is found for the element.
25
+ * @public
26
+ */
27
+ export function getSchemaOrThrow(name, registry = customElements) {
28
+ const schema = getSchema(name, registry);
29
+ if (!schema) {
30
+ throw new TypeError(`No schema found for element: ${name}`);
31
+ }
32
+ return schema;
33
+ }
34
+ /**
35
+ * Retrieves the schema for a FASTElement class directly.
36
+ * @param cls - The FASTElement class constructor.
37
+ * @returns The component schema.
38
+ * @throws TypeError if the class is not a registered FASTElement.
39
+ * @public
40
+ */
41
+ export function getComponentSchema(cls) {
42
+ const schema = getSchemaByClass(cls);
43
+ if (!schema) {
44
+ throw new TypeError(`Class is not a registered FASTElement`);
45
+ }
46
+ return schema;
47
+ }
48
+ /**
49
+ * Retrieves all registered component schemas for a given registry.
50
+ * @param registry - The custom element registry (defaults to global customElements).
51
+ * @returns A Map of tag names to component schemas.
52
+ * @public
53
+ */
54
+ export function getAllSchemas(registry = customElements) {
55
+ const result = new Map();
56
+ const tagMap = getRegistryTagMap(registry);
57
+ if (tagMap) {
58
+ for (const [name, cls] of tagMap) {
59
+ const schema = getSchemaByClass(cls);
60
+ if (schema) {
61
+ result.set(name, Object.assign(Object.assign({}, schema), { name }));
62
+ }
63
+ }
64
+ }
65
+ return result;
66
+ }
67
+ /**
68
+ * Compares two component schemas and returns the differences.
69
+ * Used to detect breaking changes between versions.
70
+ * @param a - The original schema (before).
71
+ * @param b - The new schema (after).
72
+ * @returns A SchemaDiff object describing the changes.
73
+ * @public
74
+ */
75
+ export function diffSchemas(a, b) {
76
+ const added = { properties: [], events: [], slots: [] };
77
+ const removed = { properties: [], events: [], slots: [] };
78
+ const changed = { properties: [], events: [] };
79
+ // Compare properties by name
80
+ const aProps = new Map(a.properties.map(p => [p.name, p]));
81
+ const bProps = new Map(b.properties.map(p => [p.name, p]));
82
+ for (const [name, prop] of bProps) {
83
+ if (!aProps.has(name)) {
84
+ added.properties.push(prop);
85
+ }
86
+ else if (JSON.stringify(aProps.get(name)) !== JSON.stringify(prop)) {
87
+ changed.properties.push({ before: aProps.get(name), after: prop });
88
+ }
89
+ }
90
+ for (const [name, prop] of aProps) {
91
+ if (!bProps.has(name)) {
92
+ removed.properties.push(prop);
93
+ }
94
+ }
95
+ // Compare events by name
96
+ const aEvents = new Map(a.events.map(e => [e.name, e]));
97
+ const bEvents = new Map(b.events.map(e => [e.name, e]));
98
+ for (const [name, event] of bEvents) {
99
+ if (!aEvents.has(name)) {
100
+ added.events.push(event);
101
+ }
102
+ else if (JSON.stringify(aEvents.get(name)) !== JSON.stringify(event)) {
103
+ changed.events.push({ before: aEvents.get(name), after: event });
104
+ }
105
+ }
106
+ for (const [name, event] of aEvents) {
107
+ if (!bEvents.has(name)) {
108
+ removed.events.push(event);
109
+ }
110
+ }
111
+ // Compare slots by name
112
+ const aSlots = new Map(a.slots.map(s => [s.name, s]));
113
+ const bSlots = new Map(b.slots.map(s => [s.name, s]));
114
+ for (const [name, slot] of bSlots) {
115
+ if (!aSlots.has(name)) {
116
+ added.slots.push(slot);
117
+ }
118
+ }
119
+ for (const [name, slot] of aSlots) {
120
+ if (!bSlots.has(name)) {
121
+ removed.slots.push(slot);
122
+ }
123
+ }
124
+ // Breaking changes: removed properties/events, or changed properties
125
+ const breaking = removed.properties.length > 0 ||
126
+ removed.events.length > 0 ||
127
+ changed.properties.length > 0;
128
+ return { added, removed, changed, breaking };
129
+ }
@@ -0,0 +1,89 @@
1
+ import { getRegistryTagMap, getSchemaByClass } from "./storage.js";
2
+ /**
3
+ * Converts a kebab-case string to PascalCase.
4
+ * @param str - The kebab-case string to convert.
5
+ * @returns The PascalCase version of the string.
6
+ * @example
7
+ * toPascalCase('my-button') // 'MyButton'
8
+ * toPascalCase('my-cool-element') // 'MyCoolElement'
9
+ * @public
10
+ */
11
+ export function toPascalCase(str) {
12
+ return str
13
+ .split("-")
14
+ .map(s => s.charAt(0).toUpperCase() + s.slice(1))
15
+ .join("");
16
+ }
17
+ /**
18
+ * Converts a ComponentSchema to a ManifestDeclaration.
19
+ * @param name - The tag name of the component.
20
+ * @param schema - The component schema to convert.
21
+ * @returns The manifest declaration.
22
+ */
23
+ function toManifestDeclaration(name, schema) {
24
+ const declaration = {
25
+ kind: "class",
26
+ customElement: true,
27
+ name: toPascalCase(name),
28
+ tagName: name,
29
+ members: schema.properties.map(p => ({
30
+ kind: "field",
31
+ name: p.name,
32
+ type: { text: p.type },
33
+ })),
34
+ events: schema.events.map(e => ({
35
+ name: e.name,
36
+ type: { text: "CustomEvent" },
37
+ })),
38
+ slots: schema.slots.map(s => ({
39
+ name: s.name,
40
+ description: s.description,
41
+ })),
42
+ cssProperties: schema.cssProperties.map(c => ({
43
+ name: c.name,
44
+ default: c.default,
45
+ })),
46
+ };
47
+ if (schema.description) {
48
+ declaration.description = schema.description;
49
+ }
50
+ return declaration;
51
+ }
52
+ /**
53
+ * Generates a Custom Elements Manifest (CEM 2.1.0) from registered schemas.
54
+ *
55
+ * @param registry - The custom element registry to export from (defaults to global customElements).
56
+ * @returns A Custom Elements Manifest object conforming to CEM 2.1.0 schema.
57
+ *
58
+ * @remarks
59
+ * The manifest groups each component into its own module with a synthesized path
60
+ * based on the tag name (e.g., `my-button.js`). This is suitable for documentation
61
+ * and tooling purposes but may not reflect actual file paths.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const manifest = toCustomElementsManifest();
66
+ * console.log(JSON.stringify(manifest, null, 2));
67
+ * ```
68
+ * @public
69
+ */
70
+ export function toCustomElementsManifest(registry) {
71
+ const tagMap = getRegistryTagMap(registry);
72
+ const modules = [];
73
+ if (tagMap) {
74
+ for (const [name, cls] of tagMap) {
75
+ const schema = getSchemaByClass(cls);
76
+ if (schema) {
77
+ modules.push({
78
+ kind: "javascript-module",
79
+ path: `${name}.js`,
80
+ declarations: [toManifestDeclaration(name, schema)],
81
+ });
82
+ }
83
+ }
84
+ }
85
+ return {
86
+ schemaVersion: "2.1.0",
87
+ modules,
88
+ };
89
+ }
@@ -0,0 +1,53 @@
1
+ import { registerFASTElementExtension, } from "../components/fast-definitions.js";
2
+ import { Observable } from "../observation/observable.js";
3
+ import { buildSchema } from "./extract.js";
4
+ import { registerTag, storeSchema } from "./storage.js";
5
+ const templateSubscribers = new WeakMap();
6
+ function storeDefinitionSchema(definition, registry) {
7
+ storeSchema(definition.type, buildSchema(definition, definition.type));
8
+ registerTag(definition.name, definition.type, registry);
9
+ }
10
+ /**
11
+ * Extracts and stores the Agent Definition Schema for a FAST element.
12
+ * @internal
13
+ */
14
+ export const definitionSchemaExtension = (definition, registry) => {
15
+ storeDefinitionSchema(definition, registry);
16
+ if (definition.template !== void 0 || templateSubscribers.has(definition)) {
17
+ return;
18
+ }
19
+ const notifier = Observable.getNotifier(definition);
20
+ const subscriber = {
21
+ handleChange() {
22
+ if (definition.template === void 0) {
23
+ return;
24
+ }
25
+ storeDefinitionSchema(definition, registry);
26
+ notifier.unsubscribe(subscriber, "template");
27
+ templateSubscribers.delete(definition);
28
+ },
29
+ };
30
+ templateSubscribers.set(definition, subscriber);
31
+ notifier.subscribe(subscriber, "template");
32
+ };
33
+ let disableRegisteredExtension;
34
+ /**
35
+ * Enables automatic Definition Schema extraction for subsequently defined FAST elements.
36
+ * Call this before element definitions are registered.
37
+ * @returns A callback that disables automatic extraction.
38
+ * @public
39
+ */
40
+ export function enableDefinitionSchema() {
41
+ if (disableRegisteredExtension === void 0) {
42
+ disableRegisteredExtension = registerFASTElementExtension(definitionSchemaExtension);
43
+ }
44
+ return disableDefinitionSchema;
45
+ }
46
+ /**
47
+ * Disables automatic Definition Schema extraction.
48
+ * @public
49
+ */
50
+ export function disableDefinitionSchema() {
51
+ disableRegisteredExtension === null || disableRegisteredExtension === void 0 ? void 0 : disableRegisteredExtension();
52
+ disableRegisteredExtension = void 0;
53
+ }
@@ -0,0 +1,167 @@
1
+ import { getCommandMetadata } from "../command/command.js";
2
+ /**
3
+ * Maps attribute mode to PropertyType.
4
+ * @param mode - The attribute mode ('boolean', 'reflect', 'fromView').
5
+ * @returns The corresponding PropertyType.
6
+ */
7
+ function modeToPropertyType(mode) {
8
+ switch (mode) {
9
+ case "boolean":
10
+ return "boolean";
11
+ default:
12
+ return "string";
13
+ }
14
+ }
15
+ /**
16
+ * Extracts property schemas from a FASTElementDefinition's attributes.
17
+ * @param definition - The FASTElementDefinition to extract properties from.
18
+ * @returns An array of PropertySchema objects.
19
+ */
20
+ export function extractProperties(definition) {
21
+ const properties = [];
22
+ const attributes = definition.attributes;
23
+ for (const attr of attributes) {
24
+ const property = {
25
+ name: attr.name,
26
+ type: modeToPropertyType(attr.mode),
27
+ attribute: attr.attribute,
28
+ };
29
+ properties.push(property);
30
+ }
31
+ return properties;
32
+ }
33
+ /**
34
+ * Extracts slot schemas from a template.
35
+ * Returns empty array in SSR environments where document is undefined.
36
+ * @param template - The ElementViewTemplate to extract slots from.
37
+ * @returns An array of SlotSchema objects.
38
+ */
39
+ export function extractSlots(template) {
40
+ var _a, _b;
41
+ // Guard: Return empty array in SSR environment
42
+ if (typeof document === "undefined" || !template) {
43
+ return [];
44
+ }
45
+ const slots = [];
46
+ try {
47
+ // Create a temporary host element to extract template content
48
+ const tempHost = document.createElement("div");
49
+ const view = template.create(tempHost);
50
+ view.appendTo(tempHost);
51
+ for (const slotElement of Array.from(tempHost.querySelectorAll("slot"))) {
52
+ const name = (_a = slotElement.getAttribute("name")) !== null && _a !== void 0 ? _a : "";
53
+ const description = (_b = slotElement.getAttribute("data-description")) !== null && _b !== void 0 ? _b : undefined;
54
+ slots.push({
55
+ name,
56
+ description,
57
+ });
58
+ }
59
+ view.dispose();
60
+ }
61
+ catch (_c) {
62
+ // If template extraction fails, return empty array
63
+ return [];
64
+ }
65
+ return slots;
66
+ }
67
+ /**
68
+ * Regex pattern to match CSS custom properties.
69
+ * Matches: --property-name: value;
70
+ */
71
+ const cssPropertyRegex = /(--[\w-]+):\s*([^;]+)/g;
72
+ /**
73
+ * Extracts CSS custom property schemas from styles.
74
+ * Uses naive regex extraction (v1); will upgrade to CSSTree in v2.
75
+ * @param styles - The ElementStyles to extract CSS properties from.
76
+ * @returns An array of CSSPropertySchema objects.
77
+ */
78
+ export function extractCSSProperties(styles) {
79
+ if (!styles) {
80
+ return [];
81
+ }
82
+ const cssProperties = [];
83
+ const seenProperties = new Set();
84
+ for (const style of styles.styles) {
85
+ let cssText;
86
+ if (typeof style === "string") {
87
+ cssText = style;
88
+ }
89
+ else if (typeof CSSStyleSheet !== "undefined" &&
90
+ style instanceof CSSStyleSheet) {
91
+ // Extract text from CSSStyleSheet rules
92
+ try {
93
+ const rules = style.cssRules;
94
+ const textParts = [];
95
+ for (let i = 0; i < rules.length; i++) {
96
+ textParts.push(rules[i].cssText);
97
+ }
98
+ cssText = textParts.join("\n");
99
+ }
100
+ catch (_a) {
101
+ // CSSStyleSheet may not be accessible in some environments
102
+ continue;
103
+ }
104
+ }
105
+ if (cssText) {
106
+ let match;
107
+ // Reset regex lastIndex for each new string
108
+ cssPropertyRegex.lastIndex = 0;
109
+ while ((match = cssPropertyRegex.exec(cssText)) !== null) {
110
+ const name = match[1];
111
+ const defaultValue = match[2].trim();
112
+ // Avoid duplicates
113
+ if (!seenProperties.has(name)) {
114
+ seenProperties.add(name);
115
+ cssProperties.push({
116
+ name,
117
+ default: defaultValue,
118
+ });
119
+ }
120
+ }
121
+ }
122
+ }
123
+ return cssProperties;
124
+ }
125
+ /**
126
+ * Extracts command schemas from a component class via `command` metadata.
127
+ * @param type - The class constructor to extract commands from.
128
+ * @returns An array of CommandSchema objects.
129
+ */
130
+ export function extractCommands(type) {
131
+ const metadata = getCommandMetadata(type);
132
+ return metadata.map(meta => ({
133
+ id: meta.id,
134
+ methodName: meta.methodName,
135
+ label: meta.label,
136
+ icon: meta.icon,
137
+ description: meta.description,
138
+ category: meta.category,
139
+ keybinding: meta.keybinding,
140
+ parameters: meta.parameters,
141
+ when: meta.when,
142
+ hidden: meta.hidden,
143
+ }));
144
+ }
145
+ /**
146
+ * Builds a complete ComponentSchema from a FASTElementDefinition.
147
+ * Combines property, slot, CSS property, and command extraction.
148
+ * @param definition - The FASTElementDefinition to build a schema from.
149
+ * @param type - The class constructor for the component.
150
+ * @returns A complete ComponentSchema object.
151
+ */
152
+ export function buildSchema(definition, type) {
153
+ const properties = extractProperties(definition);
154
+ const slots = extractSlots(definition.template);
155
+ const cssProperties = extractCSSProperties(definition.styles);
156
+ const commands = extractCommands(type);
157
+ return {
158
+ name: definition.name,
159
+ version: undefined, // Phase 2: Extract from decorator or package.json
160
+ description: undefined, // Phase 2: Extract from JSDoc
161
+ properties,
162
+ events: [], // Phase 2: Extract from JSDoc or decorator
163
+ slots,
164
+ cssProperties,
165
+ commands,
166
+ };
167
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public API for the Definition Schema system.
3
+ * Enables AI agents to query component capabilities via JSON introspection.
4
+ */
5
+ // Re-export all API functions
6
+ export { getSchema, getSchemaOrThrow, getComponentSchema, getAllSchemas, diffSchemas, } from "./api.js";
7
+ export { toCustomElementsManifest, toPascalCase } from "./cem.js";
8
+ export { disableDefinitionSchema, enableDefinitionSchema } from "./extension.js";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Schema storage: WeakMap keyed by class.
3
+ * Uses WeakMap to allow garbage collection when classes are no longer referenced.
4
+ */
5
+ const schemaMap = new WeakMap();
6
+ /**
7
+ * Tag-to-class mapping per registry.
8
+ * Enables lookup of component class by tag name within a specific registry.
9
+ */
10
+ const registryTagMap = new WeakMap();
11
+ /**
12
+ * Stores a component schema associated with its class constructor.
13
+ * @param cls - The class constructor for the component.
14
+ * @param schema - The component schema to store.
15
+ */
16
+ export function storeSchema(cls, schema) {
17
+ schemaMap.set(cls, schema);
18
+ }
19
+ /**
20
+ * Retrieves a component schema by its class constructor.
21
+ * @param cls - The class constructor to look up.
22
+ * @returns The component schema if found, undefined otherwise.
23
+ */
24
+ export function getSchemaByClass(cls) {
25
+ return schemaMap.get(cls);
26
+ }
27
+ /**
28
+ * Registers a tag name to class mapping within a registry.
29
+ * @param name - The custom element tag name.
30
+ * @param cls - The class constructor for the component.
31
+ * @param registry - The custom element registry (defaults to global customElements).
32
+ */
33
+ export function registerTag(name, cls, registry = customElements) {
34
+ if (!registryTagMap.has(registry)) {
35
+ registryTagMap.set(registry, new Map());
36
+ }
37
+ registryTagMap.get(registry).set(name, cls);
38
+ }
39
+ /**
40
+ * Retrieves a class constructor by its tag name within a registry.
41
+ * @param name - The custom element tag name to look up.
42
+ * @param registry - The custom element registry (defaults to global customElements).
43
+ * @returns The class constructor if found, undefined otherwise.
44
+ */
45
+ export function getClassByTag(name, registry = customElements) {
46
+ var _a;
47
+ return (_a = registryTagMap.get(registry)) === null || _a === void 0 ? void 0 : _a.get(name);
48
+ }
49
+ /**
50
+ * Gets the tag map for a specific registry.
51
+ * Used internally by getAllSchemas to iterate over registered tags.
52
+ * @param registry - The custom element registry.
53
+ * @returns The Map of tag names to classes, or undefined if no tags registered.
54
+ * @internal
55
+ */
56
+ export function getRegistryTagMap(registry = customElements) {
57
+ return registryTagMap.get(registry);
58
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Core type definitions for the Definition Schema system.
3
+ * Enables AI agents to query component capabilities via JSON introspection.
4
+ *
5
+ * @remarks
6
+ * This module contains types only - no runtime code.
7
+ */
8
+ export {};
@@ -0,0 +1,22 @@
1
+ import { getDebugMessageLookup } from "./platform.js";
2
+ /**
3
+ * Whether development-only diagnostics (warnings, `console.debug`) are enabled.
4
+ *
5
+ * @remarks
6
+ * An explicit `DEV_MODE` define always wins. Without one, diagnostics follow FAST's
7
+ * own dev/prod distinction: they are on once `enableDebug()` has loaded the debug
8
+ * messages (the debug entry point) and off in the production entry point, so they do
9
+ * not ship to production by default. It is a function because `enableDebug()` may run
10
+ * after this module is evaluated.
11
+ *
12
+ * @internal
13
+ */
14
+ export function isDevMode() {
15
+ if (typeof DEV_MODE !== "undefined") {
16
+ return DEV_MODE;
17
+ }
18
+ for (const _ in getDebugMessageLookup()) {
19
+ return true;
20
+ }
21
+ return false;
22
+ }