@siteimprove/alfa-dom 0.89.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +291 -0
  2. package/dist/h.d.ts +37 -0
  3. package/dist/h.js +214 -0
  4. package/dist/index.d.ts +32 -0
  5. package/dist/index.js +32 -0
  6. package/dist/jsx-runtime.d.ts +26 -0
  7. package/dist/jsx-runtime.js +41 -0
  8. package/dist/jsx.d.ts +44 -0
  9. package/dist/jsx.js +45 -0
  10. package/dist/namespace.d.ts +43 -0
  11. package/dist/namespace.js +57 -0
  12. package/dist/native.d.ts +18 -0
  13. package/dist/native.js +449 -0
  14. package/dist/node/attribute/predicate/has-name.d.ts +11 -0
  15. package/dist/node/attribute/predicate/has-name.js +13 -0
  16. package/dist/node/attribute/predicate.d.ts +2 -0
  17. package/dist/node/attribute/predicate.js +2 -0
  18. package/dist/node/attribute.d.ts +90 -0
  19. package/dist/node/attribute.js +164 -0
  20. package/dist/node/comment.d.ts +42 -0
  21. package/dist/node/comment.js +74 -0
  22. package/dist/node/document.d.ts +59 -0
  23. package/dist/node/document.js +113 -0
  24. package/dist/node/element/input-type.d.ts +12 -0
  25. package/dist/node/element/input-type.js +10 -0
  26. package/dist/node/element/predicate/has-attribute.d.ts +12 -0
  27. package/dist/node/element/predicate/has-attribute.js +11 -0
  28. package/dist/node/element/predicate/has-box.d.ts +9 -0
  29. package/dist/node/element/predicate/has-box.js +7 -0
  30. package/dist/node/element/predicate/has-display-size.d.ts +7 -0
  31. package/dist/node/element/predicate/has-display-size.js +28 -0
  32. package/dist/node/element/predicate/has-id.d.ts +16 -0
  33. package/dist/node/element/predicate/has-id.js +17 -0
  34. package/dist/node/element/predicate/has-input-type.d.ts +12 -0
  35. package/dist/node/element/predicate/has-input-type.js +17 -0
  36. package/dist/node/element/predicate/has-name.d.ts +11 -0
  37. package/dist/node/element/predicate/has-name.js +13 -0
  38. package/dist/node/element/predicate/has-namespace.d.ts +12 -0
  39. package/dist/node/element/predicate/has-namespace.js +13 -0
  40. package/dist/node/element/predicate/has-tab-index.d.ts +12 -0
  41. package/dist/node/element/predicate/has-tab-index.js +11 -0
  42. package/dist/node/element/predicate/has-unique-id.d.ts +7 -0
  43. package/dist/node/element/predicate/has-unique-id.js +31 -0
  44. package/dist/node/element/predicate/is-actually-disabled.d.ts +8 -0
  45. package/dist/node/element/predicate/is-actually-disabled.js +47 -0
  46. package/dist/node/element/predicate/is-browsing-context-container.d.ts +8 -0
  47. package/dist/node/element/predicate/is-browsing-context-container.js +20 -0
  48. package/dist/node/element/predicate/is-content.d.ts +10 -0
  49. package/dist/node/element/predicate/is-content.js +17 -0
  50. package/dist/node/element/predicate/is-document-element.d.ts +6 -0
  51. package/dist/node/element/predicate/is-document-element.js +13 -0
  52. package/dist/node/element/predicate/is-draggable.d.ts +8 -0
  53. package/dist/node/element/predicate/is-draggable.js +28 -0
  54. package/dist/node/element/predicate/is-editing-host.d.ts +8 -0
  55. package/dist/node/element/predicate/is-editing-host.js +20 -0
  56. package/dist/node/element/predicate/is-fallback.d.ts +15 -0
  57. package/dist/node/element/predicate/is-fallback.js +28 -0
  58. package/dist/node/element/predicate/is-replaced.d.ts +8 -0
  59. package/dist/node/element/predicate/is-replaced.js +17 -0
  60. package/dist/node/element/predicate/is-scoped-to.d.ts +7 -0
  61. package/dist/node/element/predicate/is-scoped-to.js +11 -0
  62. package/dist/node/element/predicate/is-suggested-focusable.d.ts +14 -0
  63. package/dist/node/element/predicate/is-suggested-focusable.js +47 -0
  64. package/dist/node/element/predicate.d.ts +20 -0
  65. package/dist/node/element/predicate.js +20 -0
  66. package/dist/node/element.d.ts +122 -0
  67. package/dist/node/element.js +330 -0
  68. package/dist/node/fragment.d.ts +38 -0
  69. package/dist/node/fragment.js +68 -0
  70. package/dist/node/predicate/has-child.d.ts +7 -0
  71. package/dist/node/predicate/has-child.js +8 -0
  72. package/dist/node/predicate/has-descendant.d.ts +7 -0
  73. package/dist/node/predicate/has-descendant.js +8 -0
  74. package/dist/node/predicate/has-inclusive-descendant.d.ts +7 -0
  75. package/dist/node/predicate/has-inclusive-descendant.js +8 -0
  76. package/dist/node/predicate/has-text-content.d.ts +7 -0
  77. package/dist/node/predicate/has-text-content.js +12 -0
  78. package/dist/node/predicate/is-root.d.ts +7 -0
  79. package/dist/node/predicate/is-root.js +7 -0
  80. package/dist/node/predicate.d.ts +6 -0
  81. package/dist/node/predicate.js +6 -0
  82. package/dist/node/query/element-descendants.d.ts +8 -0
  83. package/dist/node/query/element-descendants.js +17 -0
  84. package/dist/node/query/element-id-map.d.ts +14 -0
  85. package/dist/node/query/element-id-map.js +30 -0
  86. package/dist/node/query/inclusive-element-descendants.d.ts +8 -0
  87. package/dist/node/query/inclusive-element-descendants.js +10 -0
  88. package/dist/node/query/index.d.ts +12 -0
  89. package/dist/node/query/index.js +13 -0
  90. package/dist/node/shadow.d.ts +66 -0
  91. package/dist/node/shadow.js +128 -0
  92. package/dist/node/slot.d.ts +29 -0
  93. package/dist/node/slot.js +41 -0
  94. package/dist/node/slotable.d.ts +29 -0
  95. package/dist/node/slotable.js +40 -0
  96. package/dist/node/text.d.ts +46 -0
  97. package/dist/node/text.js +83 -0
  98. package/dist/node/traversal/get-nodes-between.d.ts +24 -0
  99. package/dist/node/traversal/get-nodes-between.js +62 -0
  100. package/dist/node/traversal/lowest-common-ancestor.d.ts +13 -0
  101. package/dist/node/traversal/lowest-common-ancestor.js +19 -0
  102. package/dist/node/traversal.d.ts +2 -0
  103. package/dist/node/traversal.js +2 -0
  104. package/dist/node/type.d.ts +45 -0
  105. package/dist/node/type.js +74 -0
  106. package/dist/node.d.ts +263 -0
  107. package/dist/node.js +325 -0
  108. package/dist/style/block.d.ts +30 -0
  109. package/dist/style/block.js +63 -0
  110. package/dist/style/declaration.d.ts +65 -0
  111. package/dist/style/declaration.js +103 -0
  112. package/dist/style/rule/condition.d.ts +21 -0
  113. package/dist/style/rule/condition.js +30 -0
  114. package/dist/style/rule/font-face.d.ts +29 -0
  115. package/dist/style/rule/font-face.js +47 -0
  116. package/dist/style/rule/grouping.d.ts +22 -0
  117. package/dist/style/rule/grouping.js +34 -0
  118. package/dist/style/rule/import.d.ts +47 -0
  119. package/dist/style/rule/import.js +114 -0
  120. package/dist/style/rule/keyframe.d.ts +32 -0
  121. package/dist/style/rule/keyframe.js +53 -0
  122. package/dist/style/rule/keyframes.d.ts +28 -0
  123. package/dist/style/rule/keyframes.js +49 -0
  124. package/dist/style/rule/layer.d.ts +61 -0
  125. package/dist/style/rule/layer.js +106 -0
  126. package/dist/style/rule/media.d.ts +32 -0
  127. package/dist/style/rule/media.js +54 -0
  128. package/dist/style/rule/namespace.d.ts +31 -0
  129. package/dist/style/rule/namespace.js +52 -0
  130. package/dist/style/rule/page.d.ts +32 -0
  131. package/dist/style/rule/page.js +53 -0
  132. package/dist/style/rule/style.d.ts +35 -0
  133. package/dist/style/rule/style.js +62 -0
  134. package/dist/style/rule/supports.d.ts +32 -0
  135. package/dist/style/rule/supports.js +56 -0
  136. package/dist/style/rule.d.ts +60 -0
  137. package/dist/style/rule.js +109 -0
  138. package/dist/style/sheet.d.ts +37 -0
  139. package/dist/style/sheet.js +66 -0
  140. package/package.json +69 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,291 @@
1
+ # @siteimprove/alfa-dom
2
+
3
+ ## 0.89.2
4
+
5
+ ### Patch Changes
6
+
7
+ - **Changed:** Trying to fix a problem in generating provenance statements ([#1674](https://github.com/Siteimprove/alfa/pull/1674))
8
+
9
+ ## 0.89.1
10
+
11
+ ### Patch Changes
12
+
13
+ - **Added:** Trying to publish Alfa packages on the npm registry ([#1673](https://github.com/Siteimprove/alfa/pull/1673))
14
+
15
+ ## 0.89.0
16
+
17
+ ## 0.88.0
18
+
19
+ ### Minor Changes
20
+
21
+ - **Fixed:** The publish flow was updated to a new version. ([`a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2`](https://github.com/Siteimprove/alfa/commit/a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2))
22
+
23
+ Some 0.87.\* versions were generating uninstallable package. This should be fixed now.
24
+
25
+ ## 0.87.12
26
+
27
+ ## 0.87.11
28
+
29
+ ## 0.87.10
30
+
31
+ ## 0.87.7
32
+
33
+ ## 0.87.6
34
+
35
+ ## 0.87.5
36
+
37
+ ## 0.87.4
38
+
39
+ ## 0.87.3
40
+
41
+ ### Patch Changes
42
+
43
+ - **Fixed:** Workaround for when adopted style sheets are missing has been added. ([#1656](https://github.com/Siteimprove/alfa/pull/1656))
44
+
45
+ ## 0.87.2
46
+
47
+ ## 0.87.1
48
+
49
+ ## 0.87.0
50
+
51
+ ### Minor Changes
52
+
53
+ - **Added:** A new function `getInclusiveElementDescendants` was added to the `Query` namespace. ([#1651](https://github.com/Siteimprove/alfa/pull/1651))
54
+
55
+ - **Breaking:** Optional serialization type parameters have been removed. ([#1651](https://github.com/Siteimprove/alfa/pull/1651))
56
+
57
+ - **Added:** `Element` serialised with high verbosity now include the serialisation ID of their assigned slot, if any. ([#1651](https://github.com/Siteimprove/alfa/pull/1651))
58
+
59
+ This help de-serialise the shadow trees for tools that do not want to re-compute slot assignement.
60
+
61
+ ## 0.86.2
62
+
63
+ ## 0.86.1
64
+
65
+ ## 0.86.0
66
+
67
+ ### Minor Changes
68
+
69
+ - **Breaking:** TS resolution has been changed to `Node16`, target to `es2022`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
70
+
71
+ - **Breaking:** Alfa is now distributed as ESM rather than CJS modules; projects using it must be ESM or use dynamic `import()`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
72
+
73
+ ⚠️ This is the last of a series of changes on the internal structure and build process of distributed packages that was started with v0.85.0.
74
+
75
+ ## 0.85.1
76
+
77
+ ## 0.85.0
78
+
79
+ ### Minor Changes
80
+
81
+ - **Breaking:** The .js files are now built in the `dist` folder rather than in `src`. ([#1628](https://github.com/Siteimprove/alfa/pull/1628))
82
+
83
+ ⚠️ This is the first of a series of changes on the internal structure and build process of distributed packages. It is probably better to not use this version and wait until more of these internal changes have been done to jump directly to the final result. We are internally releasing these changes for validation purpose only.
84
+
85
+ This should not impact consumers, the `package.json` files should be set correctly to consume these files.
86
+
87
+ ## 0.84.0
88
+
89
+ ## 0.83.1
90
+
91
+ ## 0.83.0
92
+
93
+ ## 0.82.0
94
+
95
+ ### Minor Changes
96
+
97
+ - **Added:** DOM node builders like `Element.of` etc. now optionally accept `serializationId` which will be used when serializing depending on the verbosity chosen. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
98
+
99
+ If one is not supplied it will be randomly generated as an UUID.
100
+
101
+ - **Added:** Verbosity option has been added to JSON serialization of alfa-tree `Node` and to `Outcome` and `Group`. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
102
+
103
+ - **Breaking:** Node 18 is no longer supported. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
104
+
105
+ ## 0.81.0
106
+
107
+ ### Patch Changes
108
+
109
+ - **Added:** Each package now contains its internal dependency graph in its `docs` directory. ([#1610](https://github.com/Siteimprove/alfa/pull/1610))
110
+
111
+ - **Fixed:** `Native.fromWindow` now behaves better in case when injected in content scripts. ([#1619](https://github.com/Siteimprove/alfa/pull/1619))
112
+
113
+ Some browsers make content scripts live in different worlds than the actual page. This causes `.constructor.name` to fail when run from the content script on object created in the page (typically, all DOM objects), in turn crashing the CSS rule type detection.
114
+
115
+ This introduces a heuristic to catch this case and fall back on other solutions.
116
+
117
+ ## 0.80.0
118
+
119
+ ### Patch Changes
120
+
121
+ - **Fixed:** `Native.fromNode` now correctly handles sheets without conditions. ([#1608](https://github.com/Siteimprove/alfa/pull/1608))
122
+
123
+ ## 0.79.1
124
+
125
+ ### Patch Changes
126
+
127
+ - **Fixed:** Correctly encapsulated sub-functions of `Native.fromNode`. ([#1606](https://github.com/Siteimprove/alfa/pull/1606))
128
+
129
+ ## 0.79.0
130
+
131
+ ### Minor Changes
132
+
133
+ - **Breaking:** `ImportRule.queries` has been renamed `ImportRule.mediaQueries`. ([#1603](https://github.com/Siteimprove/alfa/pull/1603))
134
+
135
+ This allows support queries in import rules in a unified naming scheme.
136
+
137
+ - **Breaking:** `Native.fromNode()` is now asynchronous. ([#1600](https://github.com/Siteimprove/alfa/pull/1600))
138
+
139
+ This allows to perform asynchronous operations on the page being scraped.
140
+
141
+ - **Added:** CSS `import` rules now support `layer`, and `supports` condition. ([#1603](https://github.com/Siteimprove/alfa/pull/1603))
142
+
143
+ ### Patch Changes
144
+
145
+ - **Added:** `Native.fromNode()` now includes an option to enforce `crossorigin: anonymous` on `<link>` elements missing a CORS. ([#1600](https://github.com/Siteimprove/alfa/pull/1600))
146
+
147
+ This can help solve some problems encountered during scraping, when they are tied to missing CORS policy.
148
+
149
+ - **Fixed:** `Native.fromNode()` now correctly handles CSS shorthands whose value is a `var(…)`. ([#1600](https://github.com/Siteimprove/alfa/pull/1600))
150
+
151
+ - **Fixed:** Bug where boxes where not being serialized due to device not being passed down when recursing has been fixed. ([#1605](https://github.com/Siteimprove/alfa/pull/1605))
152
+
153
+ - **Fixed:** `Node.tabOrder()` now correctly inserts shadow tree content in its place, instead of at the start. ([#1599](https://github.com/Siteimprove/alfa/pull/1599))
154
+
155
+ - **Added:** `Native.fromNode` now parses `@layer` rules. ([#1600](https://github.com/Siteimprove/alfa/pull/1600))
156
+
157
+ ## 0.78.2
158
+
159
+ ## 0.78.1
160
+
161
+ ## 0.78.0
162
+
163
+ ## 0.77.0
164
+
165
+ ## 0.76.0
166
+
167
+ ## 0.75.2
168
+
169
+ ## 0.75.1
170
+
171
+ ## 0.75.0
172
+
173
+ ### Minor Changes
174
+
175
+ - **Added:** Most CSS conditional rules now have a `.matches(device)` helper, checking against the parsed queries. ([#1581](https://github.com/Siteimprove/alfa/pull/1581))
176
+
177
+ - **Added:** CSS `@layer` rules are now handled when building cascades. ([#1574](https://github.com/Siteimprove/alfa/pull/1574))
178
+
179
+ ## 0.74.0
180
+
181
+ ## 0.73.0
182
+
183
+ ### Patch Changes
184
+
185
+ - **Fixed:** Parents of `Comment` inside a shadow tree now correctly skip over the shadow root when traversing the flat tree. ([#1547](https://github.com/Siteimprove/alfa/pull/1547))
186
+
187
+ - **Fixed:** Nested style rules now correctly get their sheet as owner. ([#1560](https://github.com/Siteimprove/alfa/pull/1560))
188
+
189
+ - **Fixed:** `Node.toString()` now stops dropping text nodes with only spaces. ([#1566](https://github.com/Siteimprove/alfa/pull/1566))
190
+
191
+ ## 0.72.0
192
+
193
+ ## 0.71.1
194
+
195
+ ## 0.71.0
196
+
197
+ ## 0.70.0
198
+
199
+ ### Minor Changes
200
+
201
+ - **Added:** New functions `Node.clone` for cloning nodes and optionally replacing child elements based on a predicate. ([#1523](https://github.com/Siteimprove/alfa/pull/1523))
202
+
203
+ ## 0.69.0
204
+
205
+ ### Minor Changes
206
+
207
+ - **Added:** Tree `Node`, and DOM `Node` can now have an `externalId` (`string`) and some `extraData` (`any`). ([#1498](https://github.com/Siteimprove/alfa/pull/1498))
208
+
209
+ These are intended for callers that need to record some extra data during audits and retrieve it afterward. Especially, the `externalId` is intended for callers who already have an identifier for nodes and do not want to lose it during audits, nor maintain a map between these identifiers and Alfa nodes.
210
+
211
+ Alfa is guaranteed to never interact with the `extraData` in any way; except that it will be typed as `any`, so any type guard or assertions must be re-applied afterward.
212
+
213
+ Alfa may, in the future, decide that `Node` with the same `externalId` can be identified in some way, e.g., because they represent two versions of the same object that were turned into two different Alfa object. This can for example happen when two copies of the same page in different states (e.g., different tab opened) are audited; this creates two Alfa `Document`, but the external caller may have the extra knowledge that some of the nodes should be identified.
214
+
215
+ It is up to the callers to ensure that the `externalId` are unique, since they are meant to carry knowledge that Alfa cannot infer.
216
+
217
+ The `externalId`, if any, is included in the serialisation of nodes. The `extraData` is never included because Alfa does not ensure it is serializable (it may contain circular references, …)
218
+
219
+ `extraData` can only be provided when building DOM nodes with the `#of` methods, or the `h.*` functions. `externalId` for `Element` can also be provided by a key with the same name in the JSX syntax.
220
+
221
+ ## 0.68.0
222
+
223
+ ### Minor Changes
224
+
225
+ - **Breaking:** `Element#of` now requires the device used when scraping a page in order to store a box. ([#1474](https://github.com/Siteimprove/alfa/pull/1474))
226
+
227
+ This ensures that the boxes of the elements will be stored with and only be accessible for the same device instance. If no device is provided, no box is stored with the element.
228
+
229
+ - **Added:** `Document#toJSON` now optionally accepts serialization options containing device. ([#1474](https://github.com/Siteimprove/alfa/pull/1474))
230
+
231
+ The options will be passed down to all children of the document and used by `Element` to serialize the box corresponding to the device.
232
+
233
+ ## 0.67.0
234
+
235
+ ## 0.66.0
236
+
237
+ ## 0.65.1
238
+
239
+ ## 0.65.0
240
+
241
+ ### Minor Changes
242
+
243
+ - **Added:** Support for optional `box` everywhere when constructing an `Element`. ([#1440](https://github.com/Siteimprove/alfa/pull/1440))
244
+
245
+ Boxes are expected to be the result of `getBoundingClientRect`, i.e. contain adding and border.
246
+
247
+ It is up to the caller to ensure that the boxes were generated on the same `Device` that is used for audits. Alfa does not (and cannot) verify this.
248
+
249
+ Alfa assumes that the boxes where generated with an empty `Context`. It is up to the caller to ensure that this is the case.
250
+
251
+ - **Removed:** Many pieces of code are no longer exported. These were mostly internal exports that are no longer used in other files and should not impact intended usage of the packages. ([#1437](https://github.com/Siteimprove/alfa/pull/1437))
252
+
253
+ - **Breaking:** Renamed public property `rectangle` to `box` which was overlooked in the last version ([#1440](https://github.com/Siteimprove/alfa/pull/1440))
254
+
255
+ - **Added:** A `Element.hasBox` predicate builder is now available. ([#1450](https://github.com/Siteimprove/alfa/pull/1450))
256
+
257
+ ## 0.64.0
258
+
259
+ ### Minor Changes
260
+
261
+ - **Added:** Optional `Rectangle` property on `Element`. ([#1427](https://github.com/Siteimprove/alfa/pull/1427))
262
+
263
+ The new property can optionally be set when constructing an element, but it doesn't do anything yet.
264
+
265
+ - **Breaking:** The method `.elementDescendants()` on the classes `Document` and `Node` has been removed. In stead the function `Query.getElementDescendants()` should be used. ([#1425](https://github.com/Siteimprove/alfa/pull/1425))
266
+
267
+ - **Added:** `Query` namespace with functions for querying element descendants and elements by id. ([#1413](https://github.com/Siteimprove/alfa/pull/1413))
268
+
269
+ The result of the queries are cached.
270
+
271
+ ## 0.63.3
272
+
273
+ ## 0.63.2
274
+
275
+ ## 0.63.1
276
+
277
+ ## 0.63.0
278
+
279
+ ### Minor Changes
280
+
281
+ - **Breaking:** `hasUniqueId` is now directly a `Predicate` ([#1408](https://github.com/Siteimprove/alfa/pull/1408))
282
+
283
+ It used to a be `() => Predicate`, the useless void parameter has now been removed. To migrate, simply replace any call to `hasUniqueId()` by `hasUniqueId` (remove the useless empty parameter).
284
+
285
+ - **Added:** `hasTabIndex` now also accepts number values ([#1409](https://github.com/Siteimprove/alfa/pull/1409))
286
+
287
+ `hasTabIndex` accepts numbers and will be satisfied if the tabindex is any of these numbers. It still alternatively accepts a `Predicate<number>`.
288
+
289
+ ## 0.62.2
290
+
291
+ ## 0.62.1
package/dist/h.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { Device } from "@siteimprove/alfa-device";
2
+ import type { Rectangle } from "@siteimprove/alfa-rectangle";
3
+ import type { Node, Rule } from "./index.js";
4
+ import { Attribute, Block, Declaration, Document, Element, FontFaceRule, Fragment, ImportRule, Layer, KeyframeRule, KeyframesRule, MediaRule, Namespace, NamespaceRule, PageRule, Shadow, Sheet, StyleRule, SupportsRule, Text, Type } from "./index.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export declare function h<N extends string = string>(name: N, attributes?: Array<Attribute> | Record<string, string | boolean>, children?: Array<Node | string>, style?: Array<Declaration> | Record<string, string>, box?: Rectangle, device?: Device, externalId?: string, serializationId?: string, extraData?: any): Element<N>;
9
+ /**
10
+ * @public
11
+ */
12
+ export declare namespace h {
13
+ function element<N extends string = string>(name: N, attributes?: Array<Attribute> | Record<string, string | boolean>, children?: Array<Node | string>, style?: Array<Declaration> | Record<string, string>, namespace?: Namespace, box?: Rectangle, device?: Device, externalId?: string, serializationId?: string, extraData?: any): Element<N>;
14
+ function attribute<N extends string = string>(name: N, value: string, externalId?: string, serializationId?: string, extraData?: any): Attribute<N>;
15
+ function text(data: string, externalId?: string, serializationId?: string, extraData?: any): Text;
16
+ function document(children: Array<Node | string>, style?: Array<Sheet>, externalId?: string, serializationId?: string, extraData?: any): Document;
17
+ function shadow(children: Array<Node | string>, style?: Array<Sheet>, mode?: Shadow.Mode, externalId?: string, serializationId?: string, extraData?: any): Shadow;
18
+ function type<N extends string = string>(name: N, publicId?: string, systemId?: string, externalId?: string, serializationId?: string, extraData?: any): Type<N>;
19
+ function fragment(children: Array<Node | string>, externalId?: string, extraData?: any): Fragment;
20
+ function sheet(rules: Array<Rule>, disabled?: boolean, condition?: string): Sheet;
21
+ function block(declarations: Array<Declaration> | Record<string, string>): Block;
22
+ function declaration(name: string, value: string, important?: boolean): Declaration;
23
+ namespace rule {
24
+ function fontFace(declarations: Array<Declaration> | Record<string, string>): FontFaceRule;
25
+ function importRule(url: string, sheet: Sheet, mediaCondition?: string, supportCondition?: string, layer?: string): ImportRule;
26
+ function keyframe(key: string, declarations: Array<Declaration> | Record<string, string>): KeyframeRule;
27
+ function keyframes(name: string, rules: Array<Rule>): KeyframesRule;
28
+ function layerBlock(rules: Array<Rule>, layer?: string): Layer.BlockRule;
29
+ function layerStatement(layers: Array<string>): Layer.StatementRule;
30
+ function media(condition: string, rules: Array<Rule>): MediaRule;
31
+ function namespace(namespace: string, prefix?: string): NamespaceRule;
32
+ function page(selector: string, declarations: Array<Declaration> | Record<string, string>): PageRule;
33
+ function style(selector: string, declarations: Array<Declaration> | Record<string, string>, hint?: boolean): StyleRule;
34
+ function supports(condition: string, rules: Array<Rule>): SupportsRule;
35
+ }
36
+ }
37
+ //# sourceMappingURL=h.d.ts.map
package/dist/h.js ADDED
@@ -0,0 +1,214 @@
1
+ import { None, Option } from "@siteimprove/alfa-option";
2
+ import { Predicate } from "@siteimprove/alfa-predicate";
3
+ import { Device } from "@siteimprove/alfa-device";
4
+ import { Attribute, Block, Declaration, Document, Element, FontFaceRule, Fragment, ImportRule, Layer, KeyframeRule, KeyframesRule, MediaRule, Namespace, NamespaceRule, PageRule, Shadow, Sheet, StyleRule, SupportsRule, Text, Type, } from "./index.js";
5
+ const { entries } = Object;
6
+ const { nor } = Predicate;
7
+ /**
8
+ * @public
9
+ */
10
+ export function h(name, attributes, children, style, box, device = Device.standard(), externalId, serializationId, extraData) {
11
+ return h.element(name, attributes, children, style, undefined, box, device, externalId, serializationId, extraData);
12
+ }
13
+ /**
14
+ * @public
15
+ */
16
+ (function (h) {
17
+ function element(name, attributes = [], children = [], style = [], namespace, box, device, externalId, serializationId, extraData) {
18
+ attributes = Array.isArray(attributes)
19
+ ? attributes
20
+ : entries(attributes).reduce((attributes, [name, value]) => {
21
+ if (value === false) {
22
+ return attributes;
23
+ }
24
+ return [
25
+ ...attributes,
26
+ h.attribute(hyphenate(name), value === true ? "" : value),
27
+ ];
28
+ }, []);
29
+ const block = h.block(style);
30
+ if (block.size > 0) {
31
+ attributes = [...attributes, h.attribute("style", block.toString())];
32
+ }
33
+ namespace =
34
+ namespace ??
35
+ Option.from(attributes.find((attribute) => attribute.name === "xmlns"))
36
+ .map((attribute) => attribute.value)
37
+ .filter(Namespace.isNamespace)
38
+ .getOr(defaultNamespace(name));
39
+ const content = children.find(Document.isDocument);
40
+ const shadow = children.find(Shadow.isShadow);
41
+ const element = Element.of(Option.of(namespace), None, name, attributes, children
42
+ .filter(nor(Document.isDocument, Shadow.isShadow))
43
+ .map((child) => (typeof child === "string" ? h.text(child) : child)), (Array.isArray(style) && style.length === 0) ||
44
+ Object.keys(style).length === 0
45
+ ? None
46
+ : Option.of(block), Option.from(box), Option.from(device), externalId, serializationId, extraData);
47
+ if (content !== undefined) {
48
+ element._attachContent(content);
49
+ }
50
+ if (shadow !== undefined) {
51
+ element._attachShadow(shadow);
52
+ }
53
+ return element;
54
+ }
55
+ h.element = element;
56
+ function attribute(name, value, externalId, serializationId, extraData) {
57
+ return Attribute.of(None, None, name, value, externalId, serializationId, extraData);
58
+ }
59
+ h.attribute = attribute;
60
+ function text(data, externalId, serializationId, extraData) {
61
+ return Text.of(data, externalId, serializationId, extraData);
62
+ }
63
+ h.text = text;
64
+ function document(children, style, externalId, serializationId, extraData) {
65
+ return Document.of(children.map((child) => typeof child === "string" ? text(child) : child), style, externalId, serializationId, extraData);
66
+ }
67
+ h.document = document;
68
+ function shadow(children, style, mode, externalId, serializationId, extraData) {
69
+ return Shadow.of(children.map((child) => typeof child === "string" ? text(child) : child), style, mode, externalId, serializationId, extraData);
70
+ }
71
+ h.shadow = shadow;
72
+ function type(name, publicId, systemId, externalId, serializationId, extraData) {
73
+ return Type.of(name, Option.from(publicId), Option.from(systemId), externalId, serializationId, extraData);
74
+ }
75
+ h.type = type;
76
+ function fragment(children, externalId, extraData) {
77
+ return Fragment.of(children.map((child) => typeof child === "string" ? text(child) : child), externalId, extraData);
78
+ }
79
+ h.fragment = fragment;
80
+ function sheet(rules, disabled, condition) {
81
+ return Sheet.of(rules, disabled, Option.from(condition));
82
+ }
83
+ h.sheet = sheet;
84
+ function block(declarations) {
85
+ return Block.of(Array.isArray(declarations)
86
+ ? declarations
87
+ : entries(declarations).map(([name, value]) => {
88
+ const important = value.endsWith("!important");
89
+ value = value.replace(/!important$/, "").trim();
90
+ // Hyphenate the declaration name unless it's the name of a custom
91
+ // property; these we keep as-is.
92
+ if (!name.startsWith("--")) {
93
+ name = hyphenate(name);
94
+ }
95
+ return Declaration.of(name, value, important);
96
+ }));
97
+ }
98
+ h.block = block;
99
+ function declaration(name, value, important) {
100
+ return Declaration.of(name, value, important);
101
+ }
102
+ h.declaration = declaration;
103
+ let rule;
104
+ (function (rule) {
105
+ function fontFace(declarations) {
106
+ return FontFaceRule.of(block(declarations));
107
+ }
108
+ rule.fontFace = fontFace;
109
+ function importRule(url, sheet, mediaCondition, supportCondition,
110
+ // Use "" for anonymous layer.
111
+ layer) {
112
+ return ImportRule.of(url, sheet, Option.from(mediaCondition), Option.from(supportCondition), Option.from(layer));
113
+ }
114
+ rule.importRule = importRule;
115
+ function keyframe(key, declarations) {
116
+ return KeyframeRule.of(key, block(declarations));
117
+ }
118
+ rule.keyframe = keyframe;
119
+ function keyframes(name, rules) {
120
+ return KeyframesRule.of(name, rules);
121
+ }
122
+ rule.keyframes = keyframes;
123
+ function layerBlock(rules, layer) {
124
+ return Layer.BlockRule.of(rules, layer);
125
+ }
126
+ rule.layerBlock = layerBlock;
127
+ function layerStatement(layers) {
128
+ return Layer.StatementRule.of(layers);
129
+ }
130
+ rule.layerStatement = layerStatement;
131
+ function media(condition, rules) {
132
+ return MediaRule.of(condition, rules);
133
+ }
134
+ rule.media = media;
135
+ function namespace(namespace, prefix) {
136
+ return NamespaceRule.of(namespace, Option.from(prefix));
137
+ }
138
+ rule.namespace = namespace;
139
+ function page(selector, declarations) {
140
+ return PageRule.of(selector, block(declarations));
141
+ }
142
+ rule.page = page;
143
+ function style(selector, declarations, hint) {
144
+ return StyleRule.of(selector, block(declarations), hint);
145
+ }
146
+ rule.style = style;
147
+ function supports(condition, rules) {
148
+ return SupportsRule.of(condition, rules);
149
+ }
150
+ rule.supports = supports;
151
+ })(rule = h.rule || (h.rule = {}));
152
+ })(h || (h = {}));
153
+ function hyphenate(value) {
154
+ return value.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
155
+ }
156
+ function defaultNamespace(name) {
157
+ switch (name) {
158
+ // The <a> element exists both in SVG and HTML namespaces.
159
+ // It is defaulted in the HTML namespace and must be explicitly built in
160
+ // the SVG one if needed.
161
+ case "circle":
162
+ case "ellipse":
163
+ case "foreignObject":
164
+ case "g":
165
+ case "image":
166
+ case "line":
167
+ case "mesh":
168
+ case "path":
169
+ case "polygon":
170
+ case "polyline":
171
+ case "rect":
172
+ case "svg":
173
+ case "symbol":
174
+ case "text":
175
+ case "textPath":
176
+ case "use":
177
+ return Namespace.SVG;
178
+ case "annotation":
179
+ case "annotation-xml":
180
+ case "maction":
181
+ case "math":
182
+ case "merror":
183
+ case "mfrac":
184
+ case "mi":
185
+ case "mmultiscripts":
186
+ case "mn":
187
+ case "mo":
188
+ case "mover":
189
+ case "mpadded":
190
+ case "mphantom":
191
+ case "mprescripts":
192
+ case "mroot":
193
+ case "mrow":
194
+ case "ms":
195
+ case "mspace":
196
+ case "msqrt":
197
+ case "mstyle":
198
+ case "msub":
199
+ case "msubsup":
200
+ case "msup":
201
+ case "mtable":
202
+ case "mtd":
203
+ case "mtext":
204
+ case "mtr":
205
+ case "munder":
206
+ case "munderover":
207
+ case "none":
208
+ case "semantics":
209
+ return Namespace.MathML;
210
+ default:
211
+ return Namespace.HTML;
212
+ }
213
+ }
214
+ //# sourceMappingURL=h.js.map
@@ -0,0 +1,32 @@
1
+ export * from "./namespace.js";
2
+ export * from "./style/block.js";
3
+ export * from "./style/declaration.js";
4
+ export * from "./style/rule.js";
5
+ export * from "./style/rule/grouping.js";
6
+ export * from "./style/rule/condition.js";
7
+ export * from "./style/rule/font-face.js";
8
+ export * from "./style/rule/import.js";
9
+ export * from "./style/rule/keyframe.js";
10
+ export * from "./style/rule/keyframes.js";
11
+ export * from "./style/rule/layer.js";
12
+ export * from "./style/rule/media.js";
13
+ export * from "./style/rule/namespace.js";
14
+ export * from "./style/rule/page.js";
15
+ export * from "./style/rule/style.js";
16
+ export * from "./style/rule/supports.js";
17
+ export * from "./style/sheet.js";
18
+ export * from "./node.js";
19
+ export * from "./node/slot.js";
20
+ export * from "./node/slotable.js";
21
+ export * from "./node/attribute.js";
22
+ export * from "./node/comment.js";
23
+ export * from "./node/document.js";
24
+ export * from "./node/element.js";
25
+ export * from "./node/fragment.js";
26
+ export * from "./node/shadow.js";
27
+ export * from "./node/text.js";
28
+ export * from "./node/type.js";
29
+ export * from "./node/query/index.js";
30
+ export * from "./h.js";
31
+ export * from "./jsx.js";
32
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ export * from "./namespace.js";
2
+ export * from "./style/block.js";
3
+ export * from "./style/declaration.js";
4
+ export * from "./style/rule.js";
5
+ export * from "./style/rule/grouping.js";
6
+ export * from "./style/rule/condition.js";
7
+ export * from "./style/rule/font-face.js";
8
+ export * from "./style/rule/import.js";
9
+ export * from "./style/rule/keyframe.js";
10
+ export * from "./style/rule/keyframes.js";
11
+ export * from "./style/rule/layer.js";
12
+ export * from "./style/rule/media.js";
13
+ export * from "./style/rule/namespace.js";
14
+ export * from "./style/rule/page.js";
15
+ export * from "./style/rule/style.js";
16
+ export * from "./style/rule/supports.js";
17
+ export * from "./style/sheet.js";
18
+ export * from "./node.js";
19
+ export * from "./node/slot.js";
20
+ export * from "./node/slotable.js";
21
+ export * from "./node/attribute.js";
22
+ export * from "./node/comment.js";
23
+ export * from "./node/document.js";
24
+ export * from "./node/element.js";
25
+ export * from "./node/fragment.js";
26
+ export * from "./node/shadow.js";
27
+ export * from "./node/text.js";
28
+ export * from "./node/type.js";
29
+ export * from "./node/query/index.js";
30
+ export * from "./h.js";
31
+ export * from "./jsx.js";
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "./jsx.js";
2
+ import type { Element } from "./index.js";
3
+ export declare namespace JSX {
4
+ type Element = _jsx.JSX.Element;
5
+ interface IntrinsicElements extends _jsx.JSX.IntrinsicElements {
6
+ }
7
+ }
8
+ /**
9
+ * @public
10
+ */
11
+ export declare function jsx<N extends string = string>(name: N, properties: _jsx.Properties & {
12
+ children?: _jsx.Child;
13
+ }): Element<N>;
14
+ /**
15
+ * @public
16
+ */
17
+ export declare function jsxs<N extends string = string>(name: N, properties: _jsx.Properties & {
18
+ children?: _jsx.Children;
19
+ }): Element<N>;
20
+ /**
21
+ * @public
22
+ */
23
+ export declare function jsxDEV<N extends string = string>(name: N, properties: _jsx.Properties & {
24
+ children?: _jsx.Child | _jsx.Children;
25
+ }): Element<N>;
26
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "./jsx.js";
2
+ /**
3
+ * @public
4
+ */
5
+ export function jsx(name, properties) {
6
+ const { children, ...rest } = properties;
7
+ if (children === undefined) {
8
+ return _jsx(name, rest);
9
+ }
10
+ else {
11
+ return _jsx(name, rest, children);
12
+ }
13
+ }
14
+ /**
15
+ * @public
16
+ */
17
+ export function jsxs(name, properties) {
18
+ const { children, ...rest } = properties;
19
+ if (children === undefined) {
20
+ return _jsx(name, rest);
21
+ }
22
+ else {
23
+ return _jsx(name, rest, ...children);
24
+ }
25
+ }
26
+ /**
27
+ * @public
28
+ */
29
+ export function jsxDEV(name, properties) {
30
+ const { children, ...rest } = properties;
31
+ if (children === undefined) {
32
+ return _jsx(name, rest);
33
+ }
34
+ else if (Array.isArray(children)) {
35
+ return _jsx(name, rest, ...children);
36
+ }
37
+ else {
38
+ return _jsx(name, rest, children);
39
+ }
40
+ }
41
+ //# sourceMappingURL=jsx-runtime.js.map