aria-ease 6.12.2 → 7.0.0

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 (93) hide show
  1. package/dist/AccordionComponentStrategy-2SWMNUR6.js +1 -0
  2. package/dist/ComboboxComponentStrategy-YSYLR2U5.js +5 -0
  3. package/dist/MenuComponentStrategy-C22BZEBH.js +5 -0
  4. package/dist/RelativeTargetResolver-T4P25J2M.js +1 -0
  5. package/dist/TabsComponentStrategy-ADEEFJXM.js +1 -0
  6. package/dist/audit-APAPHXRO.js +9 -0
  7. package/dist/badgeHelper-IB5RTMAG.js +11 -0
  8. package/dist/badgeHelper-JSROP5ML.js +1 -0
  9. package/dist/buildContracts-T4XQZBDU.js +13 -0
  10. package/dist/chunk-52I3INNG.js +11 -0
  11. package/dist/chunk-APUMBDOT.js +1 -0
  12. package/dist/chunk-BHNO4ZI3.js +1 -0
  13. package/dist/chunk-CNU4N4AY.js +1 -0
  14. package/dist/chunk-SM6ZKEDR.js +1 -0
  15. package/dist/chunk-ZNQ5BXVJ.js +1 -0
  16. package/dist/cli.cjs +132 -3494
  17. package/dist/cli.js +19 -161
  18. package/dist/configLoader-ZEJVXLX7.js +1 -0
  19. package/dist/configLoader-ZXTSCIP6.js +1 -0
  20. package/dist/contractTestRunnerPlaywright-FOCQTM4L.js +46 -0
  21. package/dist/contractTestRunnerPlaywright-QPU6HZXG.js +46 -0
  22. package/dist/formatters-H3CPDLG5.js +87 -0
  23. package/dist/index.cjs +64 -4657
  24. package/dist/index.d.cts +23 -2
  25. package/dist/index.d.ts +23 -2
  26. package/dist/index.js +17 -2351
  27. package/dist/src/accordion/index.cjs +1 -183
  28. package/dist/src/accordion/index.js +1 -181
  29. package/dist/src/block/index.cjs +1 -124
  30. package/dist/src/block/index.js +1 -122
  31. package/dist/src/checkbox/index.cjs +1 -109
  32. package/dist/src/checkbox/index.js +1 -107
  33. package/dist/src/combobox/index.cjs +1 -265
  34. package/dist/src/combobox/index.js +1 -263
  35. package/dist/src/menu/index.cjs +1 -339
  36. package/dist/src/menu/index.js +1 -337
  37. package/dist/src/radio/index.cjs +1 -117
  38. package/dist/src/radio/index.js +1 -115
  39. package/dist/src/tabs/index.cjs +1 -265
  40. package/dist/src/tabs/index.js +1 -263
  41. package/dist/src/toggle/index.cjs +1 -119
  42. package/dist/src/toggle/index.js +1 -117
  43. package/dist/src/utils/test/AccordionComponentStrategy-X2GSQ5KT.js +1 -0
  44. package/dist/src/utils/test/ComboboxComponentStrategy-SICWLI27.js +5 -0
  45. package/dist/src/utils/test/MenuComponentStrategy-R4VPAHDE.js +5 -0
  46. package/dist/src/utils/test/RelativeTargetResolver-UQQMZHI6.js +1 -0
  47. package/dist/src/utils/test/TabsComponentStrategy-L2PYNEW6.js +1 -0
  48. package/dist/src/utils/test/badgeHelper-ER5ZOHWF.js +11 -0
  49. package/dist/src/utils/test/chunk-APUMBDOT.js +1 -0
  50. package/dist/src/utils/test/chunk-BHNO4ZI3.js +1 -0
  51. package/dist/src/utils/test/configLoader-NCYRL2O6.js +1 -0
  52. package/dist/src/utils/test/contractTestRunnerPlaywright-YZCMF64Q.js +46 -0
  53. package/dist/src/utils/test/dsl/index.cjs +1 -486
  54. package/dist/src/utils/test/dsl/index.d.cts +21 -0
  55. package/dist/src/utils/test/dsl/index.d.ts +21 -0
  56. package/dist/src/utils/test/dsl/index.js +1 -484
  57. package/dist/src/utils/test/index.cjs +64 -2578
  58. package/dist/src/utils/test/index.d.cts +2 -2
  59. package/dist/src/utils/test/index.d.ts +2 -2
  60. package/dist/src/utils/test/index.js +16 -340
  61. package/dist/test-VXSCSKV5.js +19 -0
  62. package/package.json +7 -9
  63. package/dist/AccordionComponentStrategy-4ZEIQ2V6.js +0 -42
  64. package/dist/ComboboxComponentStrategy-DU342VMB.js +0 -64
  65. package/dist/MenuComponentStrategy-JAMTCSNF.js +0 -81
  66. package/dist/RelativeTargetResolver-DJAITO6D.js +0 -7
  67. package/dist/TabsComponentStrategy-3SQURPMX.js +0 -29
  68. package/dist/audit-JYEPKLHR.js +0 -63
  69. package/dist/badgeHelper-JOWO6RQG.js +0 -15
  70. package/dist/badgeHelper-RDOMCC6E.js +0 -108
  71. package/dist/buildContracts-FT6KWUJN.js +0 -465
  72. package/dist/chunk-4DU5Z5BR.js +0 -340
  73. package/dist/chunk-GJGUY643.js +0 -182
  74. package/dist/chunk-GLT43UVH.js +0 -43
  75. package/dist/chunk-I2KLQ2HA.js +0 -22
  76. package/dist/chunk-JJEPLK7L.js +0 -107
  77. package/dist/chunk-PK5L2SAF.js +0 -17
  78. package/dist/configLoader-Q7N5XV4P.js +0 -183
  79. package/dist/configLoader-REHK3S3Q.js +0 -7
  80. package/dist/contractTestRunnerPlaywright-47DCBO4A.js +0 -1300
  81. package/dist/contractTestRunnerPlaywright-UJKXRXBS.js +0 -1300
  82. package/dist/formatters-32KQIIYS.js +0 -183
  83. package/dist/src/utils/test/AccordionComponentStrategy-WRHZOEN6.js +0 -38
  84. package/dist/src/utils/test/ComboboxComponentStrategy-XKQ72RFD.js +0 -60
  85. package/dist/src/utils/test/MenuComponentStrategy-VKZQYLBE.js +0 -77
  86. package/dist/src/utils/test/RelativeTargetResolver-G2XDN2VV.js +0 -1
  87. package/dist/src/utils/test/TabsComponentStrategy-BKG53SEV.js +0 -26
  88. package/dist/src/utils/test/badgeHelper-HZKGOPB4.js +0 -102
  89. package/dist/src/utils/test/chunk-4DU5Z5BR.js +0 -332
  90. package/dist/src/utils/test/chunk-GLT43UVH.js +0 -41
  91. package/dist/src/utils/test/configLoader-NA7IBCS3.js +0 -181
  92. package/dist/src/utils/test/contractTestRunnerPlaywright-AZ4QKLYT.js +0 -1278
  93. package/dist/test-6Y4CIQOM.js +0 -358
@@ -1,484 +1 @@
1
- // src/utils/test/dsl/src/state-packs/comboboxStatePack.ts
2
- function hasCapabilities(ctx, requiredCaps) {
3
- return requiredCaps.some((cap) => ctx.capabilities.includes(cap));
4
- }
5
- function resolveSetup(setup, ctx) {
6
- if (Array.isArray(setup) && setup.length && !setup[0].when) {
7
- setup = [{ when: ["keyboard"], steps: () => setup }];
8
- }
9
- for (const strat of setup) {
10
- if (hasCapabilities(ctx, strat.when)) {
11
- return strat.steps(ctx);
12
- }
13
- }
14
- throw new Error(
15
- `No setup strategy matches capabilities: ${ctx.capabilities.join(", ")}`
16
- );
17
- }
18
- var COMBOBOX_STATES = {
19
- "popup.open": {
20
- setup: [
21
- {
22
- when: ["keyboard", "textInput"],
23
- steps: () => [
24
- { type: "keypress", target: "input", key: "ArrowDown" }
25
- ]
26
- },
27
- {
28
- when: ["pointer"],
29
- steps: () => [
30
- { type: "click", target: "button" }
31
- ]
32
- }
33
- ],
34
- assertion: isComboboxOpen
35
- },
36
- "popup.closed": {
37
- setup: [
38
- {
39
- when: ["keyboard"],
40
- steps: () => [
41
- /* { type: "keypress", target: "input", key: "Escape" } */
42
- ]
43
- },
44
- {
45
- when: ["pointer"],
46
- steps: () => [
47
- /* { type: "click", target: "button" } */
48
- ]
49
- }
50
- ],
51
- assertion: [...isComboboxClosed(), ...isActiveDescendantEmpty()]
52
- },
53
- "main.focused": {
54
- setup: [
55
- {
56
- when: ["keyboard"],
57
- steps: () => [
58
- { type: "focus", target: "main" }
59
- ]
60
- }
61
- ],
62
- assertion: isMainFocused
63
- },
64
- "main.notFocused": {
65
- setup: [
66
- {
67
- when: ["keyboard"],
68
- steps: () => [
69
- //what to do here?
70
- ]
71
- }
72
- ],
73
- assertion: isMainNotFocused
74
- },
75
- "input.filled": {
76
- setup: [
77
- {
78
- when: ["keyboard", "textInput"],
79
- steps: () => [
80
- { type: "type", target: "input", value: "test" }
81
- ]
82
- }
83
- ],
84
- assertion: isInputFilled
85
- },
86
- "input.notFilled": {
87
- setup: [
88
- {
89
- when: ["keyboard", "textInput"],
90
- steps: () => [
91
- { type: "type", target: "input", value: "" }
92
- ]
93
- }
94
- ],
95
- assertion: isInputNotFilled
96
- },
97
- "activeOption.first": {
98
- requires: ["popup.open"],
99
- setup: [
100
- {
101
- when: ["keyboard"],
102
- steps: () => [
103
- { type: "keypress", target: "input", key: "ArrowDown" }
104
- ]
105
- }
106
- ],
107
- assertion: isActiveDescendantFirst
108
- },
109
- "activeOption.last": {
110
- requires: ["activeOption.first"],
111
- setup: [
112
- {
113
- when: ["keyboard"],
114
- steps: () => [
115
- { type: "keypress", target: "input", key: "ArrowUp" }
116
- ]
117
- }
118
- ],
119
- assertion: isActiveDescendantLast
120
- },
121
- "activeDescendant.notEmpty": {
122
- requires: [],
123
- setup: [
124
- {
125
- when: ["keyboard"],
126
- steps: () => []
127
- }
128
- ],
129
- assertion: isActiveDescendantNotEmpty
130
- },
131
- "activeDescendant.Empty": {
132
- requires: [],
133
- setup: [
134
- {
135
- when: ["keyboard"],
136
- steps: () => []
137
- }
138
- ],
139
- assertion: isActiveDescendantEmpty
140
- },
141
- "selectedOption.first": {
142
- requires: ["popup.open"],
143
- setup: [
144
- {
145
- when: ["pointer"],
146
- steps: () => [
147
- { type: "click", target: "relative", relativeTarget: "first" }
148
- ]
149
- }
150
- ],
151
- assertion: () => isAriaSelected("first")
152
- },
153
- "selectedOption.last": {
154
- requires: ["popup.open"],
155
- setup: [
156
- {
157
- when: ["pointer"],
158
- steps: () => [
159
- { type: "click", target: "relative", relativeTarget: "last" }
160
- ]
161
- }
162
- ],
163
- assertion: () => isAriaSelected("last")
164
- }
165
- };
166
- function isComboboxOpen() {
167
- return [
168
- {
169
- target: "popup",
170
- assertion: "toBeVisible",
171
- failureMessage: "Expected popup to be visible"
172
- },
173
- {
174
- target: "main",
175
- assertion: "toHaveAttribute",
176
- attribute: "aria-expanded",
177
- expectedValue: "true",
178
- failureMessage: "Expect combobox main to have aria-expanded='true'."
179
- }
180
- ];
181
- }
182
- function isComboboxClosed() {
183
- return [
184
- {
185
- target: "popup",
186
- assertion: "notToBeVisible",
187
- failureMessage: "Expected popup to be closed"
188
- },
189
- {
190
- target: "main",
191
- assertion: "toHaveAttribute",
192
- attribute: "aria-expanded",
193
- expectedValue: "false",
194
- failureMessage: "Expect combobox main to have aria-expanded='false'."
195
- }
196
- ];
197
- }
198
- function isActiveDescendantFirst() {
199
- return [
200
- {
201
- target: "main",
202
- assertion: "toHaveAttribute",
203
- attribute: "aria-activedescendant",
204
- expectedValue: { ref: "relative", relativeTarget: "first", property: "id" },
205
- failureMessage: "Expected aria-activedescendant on main to match the id of the first option."
206
- }
207
- ];
208
- }
209
- function isActiveDescendantLast() {
210
- return [
211
- {
212
- target: "main",
213
- assertion: "toHaveAttribute",
214
- attribute: "aria-activedescendant",
215
- expectedValue: { ref: "relative", relativeTarget: "last", property: "id" },
216
- failureMessage: "Expected aria-activedescendant on main to match the id of the last option."
217
- }
218
- ];
219
- }
220
- function isActiveDescendantNotEmpty() {
221
- return [
222
- {
223
- target: "main",
224
- assertion: "toHaveAttribute",
225
- attribute: "aria-activedescendant",
226
- expectedValue: "!empty",
227
- failureMessage: "Expected aria-activedescendant on main to not be empty."
228
- }
229
- ];
230
- }
231
- function isActiveDescendantEmpty() {
232
- return [
233
- {
234
- target: "main",
235
- assertion: "toHaveAttribute",
236
- attribute: "aria-activedescendant",
237
- expectedValue: "",
238
- failureMessage: "Expected aria-activedescendant on main to be empty."
239
- }
240
- ];
241
- }
242
- function isAriaSelected(index) {
243
- return [
244
- {
245
- target: "relative",
246
- relativeTarget: index,
247
- assertion: "toHaveAttribute",
248
- attribute: "aria-selected",
249
- expectedValue: "true",
250
- failureMessage: `Expected ${index} option to have aria-selected='true'.`
251
- }
252
- ];
253
- }
254
- function isMainFocused() {
255
- return [
256
- {
257
- target: "main",
258
- assertion: "toHaveFocus",
259
- failureMessage: "Expected main to be focused."
260
- }
261
- ];
262
- }
263
- function isMainNotFocused() {
264
- return [
265
- {
266
- target: "main",
267
- assertion: "notToHaveFocus",
268
- failureMessage: "Expected main to not have focused."
269
- }
270
- ];
271
- }
272
- function isInputFilled() {
273
- return [
274
- {
275
- target: "input",
276
- assertion: "toHaveValue",
277
- expectedValue: "test",
278
- failureMessage: "Expected input to have the value 'test'."
279
- }
280
- ];
281
- }
282
- function isInputNotFilled() {
283
- return [
284
- {
285
- target: "input",
286
- assertion: "toHaveValue",
287
- expectedValue: "",
288
- failureMessage: "Expected input to have the value ''."
289
- }
290
- ];
291
- }
292
-
293
- // src/utils/test/dsl/src/contractBuilder.ts
294
- var STATE_PACKS = {
295
- "combobox": COMBOBOX_STATES
296
- // Add more mappings as needed
297
- };
298
- var FluentContract = class {
299
- constructor(jsonContract) {
300
- this.jsonContract = jsonContract;
301
- }
302
- toJSON() {
303
- return this.jsonContract;
304
- }
305
- };
306
- var ContractBuilder = class {
307
- constructor(componentName) {
308
- this.componentName = componentName;
309
- this.statePack = STATE_PACKS[componentName] || {};
310
- }
311
- metaValue = {};
312
- selectorsValue = {};
313
- relationshipInvariants = [];
314
- staticAssertions = [];
315
- dynamicTests = [];
316
- statePack;
317
- meta(meta) {
318
- this.metaValue = meta;
319
- return this;
320
- }
321
- selectors(selectors) {
322
- this.selectorsValue = selectors;
323
- return this;
324
- }
325
- relationships(fn) {
326
- const api = {
327
- ariaReference: (from, attribute, to) => ({
328
- required: () => this.relationshipInvariants.push({ type: "aria-reference", from, attribute, to, level: "required" }),
329
- optional: () => this.relationshipInvariants.push({ type: "aria-reference", from, attribute, to, level: "optional" }),
330
- recommended: () => this.relationshipInvariants.push({ type: "aria-reference", from, attribute, to, level: "recommended" })
331
- }),
332
- contains: (parent, child) => ({
333
- required: () => this.relationshipInvariants.push({ type: "contains", parent, child, level: "required" }),
334
- optional: () => this.relationshipInvariants.push({ type: "contains", parent, child, level: "optional" }),
335
- recommended: () => this.relationshipInvariants.push({ type: "contains", parent, child, level: "recommended" })
336
- })
337
- };
338
- fn(api);
339
- return this;
340
- }
341
- static(fn) {
342
- const api = {
343
- target: (target) => ({
344
- has: (attribute, expectedValue) => ({
345
- required: () => this.staticAssertions.push({ target, attribute, expectedValue, failureMessage: "", level: "required" }),
346
- optional: () => this.staticAssertions.push({ target, attribute, expectedValue, failureMessage: "", level: "optional" }),
347
- recommended: () => this.staticAssertions.push({ target, attribute, expectedValue, failureMessage: "", level: "recommended" })
348
- })
349
- })
350
- };
351
- fn(api);
352
- return this;
353
- }
354
- when(event) {
355
- return new DynamicTestBuilder(this, this.statePack, event);
356
- }
357
- addDynamicTest(test) {
358
- this.dynamicTests.push(test);
359
- }
360
- build() {
361
- return {
362
- meta: this.metaValue,
363
- selectors: this.selectorsValue,
364
- relationships: this.relationshipInvariants.length ? this.relationshipInvariants : void 0,
365
- static: this.staticAssertions.length ? [{ assertions: this.staticAssertions }] : [],
366
- dynamic: this.dynamicTests
367
- };
368
- }
369
- };
370
- var DynamicTestBuilder = class {
371
- constructor(parent, statePack, event) {
372
- this.parent = parent;
373
- this.statePack = statePack;
374
- this.event = event;
375
- }
376
- _as;
377
- _on;
378
- _given = [];
379
- _then = [];
380
- _desc = "";
381
- _level = "required";
382
- as(actionType) {
383
- this._as = actionType;
384
- return this;
385
- }
386
- on(target) {
387
- this._on = target;
388
- return this;
389
- }
390
- given(states) {
391
- this._given = Array.isArray(states) ? states : [states];
392
- return this;
393
- }
394
- then(states) {
395
- this._then = Array.isArray(states) ? states : [states];
396
- return this;
397
- }
398
- describe(desc) {
399
- this._desc = desc;
400
- return this;
401
- }
402
- required() {
403
- this._level = "required";
404
- this._finalize();
405
- return this.parent;
406
- }
407
- optional() {
408
- this._level = "optional";
409
- this._finalize();
410
- return this.parent;
411
- }
412
- recommended() {
413
- this._level = "recommended";
414
- this._finalize();
415
- return this.parent;
416
- }
417
- _finalize() {
418
- const capabilityMap = {
419
- keypress: "keyboard",
420
- click: "pointer",
421
- type: "textInput",
422
- focus: "keyboard",
423
- hover: "pointer"
424
- // add more mappings as needed
425
- };
426
- const capability = capabilityMap[this._as || "keyboard"] || (this._as || "keyboard");
427
- const ctx = { capabilities: [capability] };
428
- const resolveAllSetups = (stateName, visited = /* @__PURE__ */ new Set()) => {
429
- if (visited.has(stateName)) return [];
430
- visited.add(stateName);
431
- const s = this.statePack[stateName];
432
- if (!s) return [];
433
- let actions = [];
434
- if (Array.isArray(s.requires)) {
435
- for (const req of s.requires) {
436
- actions = actions.concat(resolveAllSetups(req, visited));
437
- }
438
- }
439
- if (s.setup) actions = actions.concat(resolveSetup(s.setup, ctx));
440
- return actions;
441
- };
442
- const setup = [];
443
- for (const state of this._given) {
444
- setup.push(...resolveAllSetups(state));
445
- }
446
- const assertions = [];
447
- for (const state of this._then) {
448
- const s = this.statePack[state];
449
- if (s && s.assertion !== void 0) {
450
- let value = s.assertion;
451
- if (typeof value === "function") {
452
- try {
453
- value = value();
454
- } catch (e) {
455
- throw new Error(`Error calling assertion function for state '${state}': ${e.message}`);
456
- }
457
- }
458
- if (Array.isArray(value)) assertions.push(...value);
459
- else assertions.push(value);
460
- }
461
- }
462
- const action = [
463
- {
464
- type: this._as,
465
- target: this._on,
466
- key: this._as === "keypress" ? this.event : void 0
467
- }
468
- ];
469
- this.parent.addDynamicTest({
470
- description: this._desc || "",
471
- level: this._level,
472
- action,
473
- assertions,
474
- ...setup.length ? { setup } : {}
475
- });
476
- }
477
- };
478
- function createContract(componentName, define) {
479
- const builder = new ContractBuilder(componentName);
480
- define(builder);
481
- return new FluentContract(builder.build());
482
- }
483
-
484
- export { createContract };
1
+ var A={"popup.open":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:w},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:[...M(),...f()]},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:E},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:D},"input.filled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:"test"}]}],assertion:C},"input.notFilled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:""}]}],assertion:I},"activeOption.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]}],assertion:q},"activeOption.last":{requires:["activeOption.first"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowUp"}]}],assertion:S},"activeDescendant.notEmpty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:T},"activeDescendant.Empty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:f},"selectedOption.first":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"first"}]}],assertion:()=>b("first")},"selectedOption.last":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"last"}]}],assertion:()=>b("last")}};function w(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect combobox main to have aria-expanded='true'."}]}function M(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect combobox main to have aria-expanded='false'."}]}function q(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"first",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first option."}]}function S(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"last",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the last option."}]}function T(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function f(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function b(a){return [{target:"relative",relativeTarget:a,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${a} option to have aria-selected='true'.`}]}function E(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected main to be focused."}]}function D(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected main to not have focused."}]}function C(){return [{target:"input",assertion:"toHaveValue",expectedValue:"test",failureMessage:"Expected input to have the value 'test'."}]}function I(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var x={"popup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:V},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:_},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:F},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:H},"activeItem.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[]}],assertion:P},"activeItem.last":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"ArrowUp"}]}],assertion:O},"submenu.open":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:B},"submenu.closed":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowLeft"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:R},"submenuTrigger.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:L},"submenuTrigger.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:z},"submenuActiveItem.first":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:J}};function V(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect menu main to have aria-expanded='true'."}]}function _(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect menu main to have aria-expanded='false'."}]}function F(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function H(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function P(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"first",failureMessage:"First menu item should have focus."}]}function O(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"last",failureMessage:"Last menu item should have focus."}]}function B(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect submenu trigger to have aria-expanded='true'."}]}function R(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect submenu trigger to have aria-expanded='false'."}]}function L(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function z(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function J(){return [{target:"submenuItems",assertion:"toHaveFocus",failureMessage:"First interactive item in the submenu should have focus after Right Arrow open the submenu."}]}function N(a,e){return e.some(o=>a.capabilities.includes(o))}function v(a,e){Array.isArray(a)&&a.length&&!a[0].when&&(a=[{when:["keyboard"],steps:()=>a}]);for(let o of a)if(N(e,o.when))return o.steps(e);throw new Error(`No setup strategy matches capabilities: ${e.capabilities.join(", ")}`)}var U={combobox:A,menu:x},h=class{constructor(e){this.jsonContract=e;}toJSON(){return this.jsonContract}},y=class{constructor(e){this.componentName=e;this.statePack=U[e]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(e){return this.metaValue=e,this}selectors(e){return this.selectorsValue=e,this}relationships(e){let o=this.statePack,p={capabilities:["keyboard"]},c=(t,i=new Set)=>{if(i.has(t))return [];i.add(t);let s=o[t];if(!s)return [];let r=[];if(Array.isArray(s.requires))for(let n of s.requires)r=r.concat(c(n,i));return s.setup&&(r=r.concat(v(s.setup,p))),r};return e({ariaReference:(t,i,s)=>({requires:r=>{let n=c(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required",setup:n}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional",setup:n}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended",setup:n})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended"})}),contains:(t,i)=>({requires:s=>{let r=c(s,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended"})})}),this}static(e){return e({target:p=>{let c=t=>{let i=this.statePack,s={capabilities:["keyboard"]},r=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=i[n];if(!d)return [];let g=[];if(Array.isArray(d.requires))for(let k of d.requires)g=g.concat(r(k,u));return d.setup&&(g=g.concat(v(d.setup,s))),g};return r(t,new Set)},l=(t,i,s)=>({required:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"required",setup:s}),optional:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"optional",setup:s}),recommended:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"recommended",setup:s})});return {has:(t,i)=>({...l(t,i),requires:r=>{let n=c(r);return l(t,i,n)}})}}}),this}when(e){return new m(this,this.statePack,e)}addDynamicTest(e){this.dynamicTests.push(e);}build(){return {meta:this.metaValue,selectors:this.selectorsValue,relationships:this.relationshipInvariants.length?this.relationshipInvariants:void 0,static:this.staticAssertions.length?[{assertions:this.staticAssertions}]:[],dynamic:this.dynamicTests}}},m=class{constructor(e,o,p){this.parent=e;this.statePack=o;this.event=p;}_as;_on;_given=[];_then=[];_desc="";_level="required";as(e){return this._as=e,this}on(e){return this._on=e,this}given(e){return this._given=Array.isArray(e)?e:[e],this}then(e){return this._then=Array.isArray(e)?e:[e],this}describe(e){return this._desc=e,this}required(){return this._level="required",this._finalize(),this.parent}optional(){return this._level="optional",this._finalize(),this.parent}recommended(){return this._level="recommended",this._finalize(),this.parent}_finalize(){let p={capabilities:[{keypress:"keyboard",click:"pointer",type:"textInput",focus:"keyboard",hover:"pointer"}[this._as||"keyboard"]||this._as||"keyboard"]},c=(s,r=new Set)=>{if(r.has(s))return [];r.add(s);let n=this.statePack[s];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(c(d,r));return n.setup&&(u=u.concat(v(n.setup,p))),u},l=[];for(let s of this._given)l.push(...c(s));let t=[];for(let s of this._then){let r=this.statePack[s];if(r&&r.assertion!==void 0){let n=r.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${s}': ${u.message}`)}Array.isArray(n)?t.push(...n):t.push(n);}}let i=[{type:this._as,target:this._on,key:this._as==="keypress"?this.event:void 0}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,action:i,assertions:t,...l.length?{setup:l}:{}});}};function Y(a,e){let o=new y(a);return e(o),new h(o.build())}export{Y as createContract};