aria-ease 7.0.0 → 7.1.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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/RelativeTargetResolver-PDJM3ZJI.js +1 -0
  3. package/dist/TabsComponentStrategy-LKV6D2B7.js +1 -0
  4. package/dist/{audit-APAPHXRO.js → audit-WBKVW7H6.js} +2 -2
  5. package/dist/chunk-WIWSYIGK.js +1 -0
  6. package/dist/cli.cjs +60 -60
  7. package/dist/cli.js +3 -3
  8. package/dist/contractTestRunnerPlaywright-44QPA5JG.js +46 -0
  9. package/dist/contractTestRunnerPlaywright-IUUAGMXP.js +46 -0
  10. package/dist/index.cjs +40 -40
  11. package/dist/index.d.cts +35 -11
  12. package/dist/index.d.ts +35 -11
  13. package/dist/index.js +14 -14
  14. package/dist/src/accordion/index.cjs +1 -1
  15. package/dist/src/accordion/index.js +1 -1
  16. package/dist/src/block/index.cjs +1 -1
  17. package/dist/src/block/index.js +1 -1
  18. package/dist/src/checkbox/index.cjs +1 -1
  19. package/dist/src/checkbox/index.js +1 -1
  20. package/dist/src/combobox/index.cjs +1 -1
  21. package/dist/src/combobox/index.js +1 -1
  22. package/dist/src/menu/index.cjs +1 -1
  23. package/dist/src/menu/index.js +1 -1
  24. package/dist/src/radio/index.cjs +1 -1
  25. package/dist/src/radio/index.js +1 -1
  26. package/dist/src/tabs/index.cjs +1 -1
  27. package/dist/src/tabs/index.js +1 -1
  28. package/dist/src/toggle/index.cjs +1 -1
  29. package/dist/src/toggle/index.js +1 -1
  30. package/dist/src/utils/test/RelativeTargetResolver-5SIQLWPN.js +1 -0
  31. package/dist/src/utils/test/TabsComponentStrategy-DTQQUCK2.js +1 -0
  32. package/dist/src/utils/test/chunk-WIWSYIGK.js +1 -0
  33. package/dist/src/utils/test/contractTestRunnerPlaywright-VALOFEZZ.js +46 -0
  34. package/dist/src/utils/test/dsl/index.cjs +1 -1
  35. package/dist/src/utils/test/dsl/index.d.cts +35 -11
  36. package/dist/src/utils/test/dsl/index.d.ts +35 -11
  37. package/dist/src/utils/test/dsl/index.js +1 -1
  38. package/dist/src/utils/test/index.cjs +36 -36
  39. package/dist/src/utils/test/index.js +1 -1
  40. package/dist/{test-VXSCSKV5.js → test-MWX7KH44.js} +1 -1
  41. package/package.json +2 -2
  42. package/dist/RelativeTargetResolver-T4P25J2M.js +0 -1
  43. package/dist/TabsComponentStrategy-ADEEFJXM.js +0 -1
  44. package/dist/chunk-BHNO4ZI3.js +0 -1
  45. package/dist/contractTestRunnerPlaywright-FOCQTM4L.js +0 -46
  46. package/dist/contractTestRunnerPlaywright-QPU6HZXG.js +0 -46
  47. package/dist/src/utils/test/RelativeTargetResolver-UQQMZHI6.js +0 -1
  48. package/dist/src/utils/test/TabsComponentStrategy-L2PYNEW6.js +0 -1
  49. package/dist/src/utils/test/chunk-BHNO4ZI3.js +0 -1
  50. package/dist/src/utils/test/contractTestRunnerPlaywright-YZCMF64Q.js +0 -46
@@ -1,8 +1,19 @@
1
1
  type StatePack = Record<string, {
2
- setup?: DynamicAction[];
3
- assertion?: DynamicAssertion[] | DynamicAssertion;
2
+ setup?: Array<{
3
+ when: string[];
4
+ steps: ((arg?: {
5
+ relativeTarget?: string | number;
6
+ }) => DynamicAction[]) | DynamicAction[];
7
+ }>;
8
+ assertion?: ((arg?: {
9
+ relativeTarget?: string | number;
10
+ }) => DynamicAssertion[] | DynamicAssertion) | DynamicAssertion[] | DynamicAssertion;
4
11
  requires?: string[];
5
12
  }>;
13
+ type RelativeState = {
14
+ type: string;
15
+ ref: string | number;
16
+ };
6
17
  type Level = "required" | "recommended" | "optional";
7
18
  type ContractMeta = {
8
19
  id?: string;
@@ -33,9 +44,10 @@ type RelationshipInvariant = {
33
44
  };
34
45
  type StaticAssertion = {
35
46
  target: string;
47
+ assertion: "toBeVisible" | "notToBeVisible" | "toHaveAttribute" | "toHaveValue" | "toHaveFocus" | "notToHaveFocus" | "toHaveRole";
36
48
  attribute: string;
37
49
  expectedValue?: string;
38
- failureMessage: string;
50
+ failureMessage?: string;
39
51
  level: Level;
40
52
  requires?: string;
41
53
  setup?: DynamicAction[];
@@ -46,7 +58,7 @@ type DynamicAssertion = {
46
58
  attribute?: string;
47
59
  expectedValue?: string;
48
60
  failureMessage?: string;
49
- relativeTarget?: string;
61
+ relativeTarget?: string | number;
50
62
  virtualId?: string;
51
63
  selectorKey?: string;
52
64
  level?: Level;
@@ -54,17 +66,18 @@ type DynamicAssertion = {
54
66
  type DynamicAction = {
55
67
  type: "focus";
56
68
  target: string;
57
- relativeTarget?: "first" | "last" | "next" | "previous";
69
+ relativeTarget?: "first" | "last" | "next" | "previous" | number;
58
70
  virtualId?: string;
59
71
  } | {
60
- type: "click" | "keypress" | "type" | "hover";
72
+ type: "click" | "keypress" | "type" | "hover" | "focus";
61
73
  target: string;
62
74
  key?: string;
63
75
  value?: string;
64
- relativeTarget?: string;
76
+ relativeTarget?: string | number;
65
77
  };
66
78
  type DynamicTest = {
67
79
  description: string;
80
+ orientation?: "vertical" | "horizontal";
68
81
  level?: Level;
69
82
  action: DynamicAction[];
70
83
  assertions: DynamicAssertion[];
@@ -139,16 +152,27 @@ declare class DynamicTestBuilder {
139
152
  private statePack;
140
153
  private event;
141
154
  private _as;
142
- private _on;
155
+ private _onTarget;
156
+ private _onRelativeTarget;
143
157
  private _given;
144
158
  private _then;
145
159
  private _desc;
146
160
  private _level;
161
+ private _orientation;
147
162
  constructor(parent: ContractBuilder, statePack: StatePack, event: string);
148
163
  as(actionType: string): this;
149
- on(target: string): this;
150
- given(states: string | string[]): this;
151
- then(states: string | string[]): this;
164
+ on(target: string, relativeTarget?: string | number): this;
165
+ given(states: string | string[] | RelativeState | RelativeState[]): this;
166
+ then(states: string | string[] | RelativeState | RelativeState[]): this;
167
+ orientation(orientation: "vertical" | "horizontal"): this;
168
+ /**
169
+ * Normalize states to an array of string or resolved state keys from relative state objects.
170
+ */
171
+ private _normalizeStates;
172
+ /**
173
+ * Find a generic state key in the state pack by type.
174
+ */
175
+ private _findStateKeyByTypeAndRef;
152
176
  describe(desc: string): this;
153
177
  required(): ContractBuilder;
154
178
  optional(): ContractBuilder;
@@ -1,8 +1,19 @@
1
1
  type StatePack = Record<string, {
2
- setup?: DynamicAction[];
3
- assertion?: DynamicAssertion[] | DynamicAssertion;
2
+ setup?: Array<{
3
+ when: string[];
4
+ steps: ((arg?: {
5
+ relativeTarget?: string | number;
6
+ }) => DynamicAction[]) | DynamicAction[];
7
+ }>;
8
+ assertion?: ((arg?: {
9
+ relativeTarget?: string | number;
10
+ }) => DynamicAssertion[] | DynamicAssertion) | DynamicAssertion[] | DynamicAssertion;
4
11
  requires?: string[];
5
12
  }>;
13
+ type RelativeState = {
14
+ type: string;
15
+ ref: string | number;
16
+ };
6
17
  type Level = "required" | "recommended" | "optional";
7
18
  type ContractMeta = {
8
19
  id?: string;
@@ -33,9 +44,10 @@ type RelationshipInvariant = {
33
44
  };
34
45
  type StaticAssertion = {
35
46
  target: string;
47
+ assertion: "toBeVisible" | "notToBeVisible" | "toHaveAttribute" | "toHaveValue" | "toHaveFocus" | "notToHaveFocus" | "toHaveRole";
36
48
  attribute: string;
37
49
  expectedValue?: string;
38
- failureMessage: string;
50
+ failureMessage?: string;
39
51
  level: Level;
40
52
  requires?: string;
41
53
  setup?: DynamicAction[];
@@ -46,7 +58,7 @@ type DynamicAssertion = {
46
58
  attribute?: string;
47
59
  expectedValue?: string;
48
60
  failureMessage?: string;
49
- relativeTarget?: string;
61
+ relativeTarget?: string | number;
50
62
  virtualId?: string;
51
63
  selectorKey?: string;
52
64
  level?: Level;
@@ -54,17 +66,18 @@ type DynamicAssertion = {
54
66
  type DynamicAction = {
55
67
  type: "focus";
56
68
  target: string;
57
- relativeTarget?: "first" | "last" | "next" | "previous";
69
+ relativeTarget?: "first" | "last" | "next" | "previous" | number;
58
70
  virtualId?: string;
59
71
  } | {
60
- type: "click" | "keypress" | "type" | "hover";
72
+ type: "click" | "keypress" | "type" | "hover" | "focus";
61
73
  target: string;
62
74
  key?: string;
63
75
  value?: string;
64
- relativeTarget?: string;
76
+ relativeTarget?: string | number;
65
77
  };
66
78
  type DynamicTest = {
67
79
  description: string;
80
+ orientation?: "vertical" | "horizontal";
68
81
  level?: Level;
69
82
  action: DynamicAction[];
70
83
  assertions: DynamicAssertion[];
@@ -139,16 +152,27 @@ declare class DynamicTestBuilder {
139
152
  private statePack;
140
153
  private event;
141
154
  private _as;
142
- private _on;
155
+ private _onTarget;
156
+ private _onRelativeTarget;
143
157
  private _given;
144
158
  private _then;
145
159
  private _desc;
146
160
  private _level;
161
+ private _orientation;
147
162
  constructor(parent: ContractBuilder, statePack: StatePack, event: string);
148
163
  as(actionType: string): this;
149
- on(target: string): this;
150
- given(states: string | string[]): this;
151
- then(states: string | string[]): this;
164
+ on(target: string, relativeTarget?: string | number): this;
165
+ given(states: string | string[] | RelativeState | RelativeState[]): this;
166
+ then(states: string | string[] | RelativeState | RelativeState[]): this;
167
+ orientation(orientation: "vertical" | "horizontal"): this;
168
+ /**
169
+ * Normalize states to an array of string or resolved state keys from relative state objects.
170
+ */
171
+ private _normalizeStates;
172
+ /**
173
+ * Find a generic state key in the state pack by type.
174
+ */
175
+ private _findStateKeyByTypeAndRef;
152
176
  describe(desc: string): this;
153
177
  required(): ContractBuilder;
154
178
  optional(): ContractBuilder;
@@ -1 +1 @@
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};
1
+ var T={"popup.open":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:S},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:[...w(),...b()]},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:_},"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:V},activeOption:{requires:["popup.open"],setup:[{when:["keyboard","pointer"],steps:(e={})=>typeof e.relativeTarget=="number"?Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"input",key:"ArrowDown"})):e.relativeTarget==="first"?[]:e.relativeTarget==="last"?[{type:"keypress",target:"input",key:"ArrowUp"}]:[]}],assertion:(e={})=>M(e.relativeTarget)},"activeDescendant.notEmpty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:E},"activeDescendant.Empty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:b},selectedOption:{requires:["popup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",key:"Enter",relativeTargeta:e.relativeTarget}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTargeta:e.relativeTarget}]}],assertion:(e={})=>q(e.relativeTarget)}};function S(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected combobox main to have aria-expanded='true'."}]}function w(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected combobox main to have aria-expanded='false'."}]}function M(e){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:e,property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first option."}]}function E(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function b(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function q(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${e} option to have aria-selected='true'.`}]}function _(){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 V(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var A={"popup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:H},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:I},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:R},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:F},activeItem:{requires:["popup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>B(e.relativeTarget)},"submenu.open":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:P},"submenu.closed":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowLeft"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:O},"submenuTrigger.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:z},"submenuTrigger.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:$},activeSubmenuItem:{requires:["submenu.open"],setup:[{when:["keyboard"],steps:(e={})=>{let t=[{type:"focus",target:"submenuTrigger"},{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}];return typeof e.relativeTarget=="number"&&(t=t.concat(Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"submenuItems",key:"ArrowDown"})))),t}},{when:["pointer"],steps:(e={})=>[{type:"click",target:"submenuTrigger"},{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>L(e.relativeTarget)}};function H(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected menu main to have aria-expanded='true'."}]}function I(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected menu main to have aria-expanded='false'."}]}function R(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function F(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function B(e){return [{target:"relative",assertion:"toHaveFocus",expectedValue:e,failureMessage:`${e} menu item should have focus.`}]}function P(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected submenu trigger to have aria-expanded='true'."}]}function O(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected submenu trigger to have aria-expanded='false'."}]}function z(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function $(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function L(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveFocus",failureMessage:`Expected submenu item ${e} to have focus.`}]}var k={activeTab:{setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",relativeTarget:e.relativeTarget,key:"ArrowLeft"}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>K(e.relativeTarget)},focusedTab:{setup:[{when:["keyboard"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]},{when:["pointer"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>j(e.relativeTarget)}};function j(e){return [{target:"relative",assertion:"toHaveFocus",relativeTarget:e,failureMessage:"Expected first tab to have focus."}]}function J(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have tabindex='0'.`}]}function K(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have aria-selected='true'.`},{target:"panel",assertion:"toBeVisible",controlledBy:{target:"relative",relativeTarget:e},failureMessage:`Expected panel controlled by the ${e} tab to be visible.`},J(e)]}function N(e,t){return t.some(c=>e.capabilities.includes(c))}function y(e,t){Array.isArray(e)&&e.length&&!e[0].when&&(e=[{when:["keyboard"],steps:()=>e}]);for(let c of e)if(N(t,c.when))return c.steps(t);throw new Error(`No setup strategy matches capabilities: ${t.capabilities.join(", ")}`)}var U={combobox:T,menu:A,tabs:k},m=class{constructor(t){this.jsonContract=t;}toJSON(){return this.jsonContract}},f=class{constructor(t){this.componentName=t;this.statePack=U[t]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(t){return this.metaValue=t,this}selectors(t){return this.selectorsValue=t,this}relationships(t){let c=this.statePack,p={capabilities:["keyboard"]},g=(o,i=new Set)=>{if(i.has(o))return [];i.add(o);let a=c[o];if(!a)return [];let r=[];if(Array.isArray(a.requires))for(let s of a.requires)r=r.concat(g(s,i));return a.setup&&(r=r.concat(y(a.setup,p))),r};return t({ariaReference:(o,i,a)=>({requires:r=>{let s=g(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required",setup:s}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional",setup:s}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended",setup:s})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended"})}),contains:(o,i)=>({requires:a=>{let r=g(a,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended"})})}),this}static(t){return t({target:p=>{let g=i=>{let a=this.statePack,r={capabilities:["keyboard"]},s=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=a[n];if(!d)return [];let v=[];if(Array.isArray(d.requires))for(let x of d.requires)v=v.concat(s(x,u));return d.setup&&(v=v.concat(y(d.setup,r))),v};return s(i,new Set)},l=i=>i==="role"?"toHaveRole":"toHaveAttribute",o=(i,a,r)=>{let s=l(i);return {required:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"required",setup:r}),optional:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"optional",setup:r}),recommended:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"recommended",setup:r})}};return {has:(i,a)=>({...o(i,a),requires:s=>{let n=g(s);return o(i,a,n)}})}}}),this}when(t){return new h(this,this.statePack,t)}addDynamicTest(t){this.dynamicTests.push(t);}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}}},h=class{constructor(t,c,p){this.parent=t;this.statePack=c;this.event=p;}_as;_onTarget;_onRelativeTarget;_given=[];_then=[];_desc="";_level="required";_orientation;as(t){return this._as=t,this}on(t,c){return this._onTarget=t,this._onRelativeTarget=c,this}given(t){return this._given=this._normalizeStates(t),this}then(t){return this._then=this._normalizeStates(t),this}orientation(t){return this._orientation=t,this}_normalizeStates(t){return (Array.isArray(t)?t:[t]).flatMap(p=>typeof p=="string"?[p]:typeof p=="object"&&p!==null&&"type"in p&&"ref"in p?this._findStateKeyByTypeAndRef(p.type)?[{type:p.type,ref:p.ref}]:[]:[p])}_findStateKeyByTypeAndRef(t){if(Object.keys(this.statePack).includes(t))return t}describe(t){return this._desc=t,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"]},g=(r,s=new Set)=>{if(s.has(r))return [];s.add(r);let n=this.statePack[r];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(g(d,s));return n.setup&&(u=u.concat(y(n.setup,p))),u},l=[];for(let r of this._given)if(typeof r=="string")l.push(...g(r));else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.setup)for(let u of n.setup)typeof u.steps=="function"?l.push(...u.steps({relativeTarget:r.ref})):Array.isArray(u.steps)&&l.push(...u.steps);}}let o=new Set;l=l.filter(r=>{let s=JSON.stringify(r);return o.has(s)?false:(o.add(s),true)});let i=[];for(let r of this._then)if(typeof r=="string"){let s=this.statePack[r];if(s&&s.assertion!==void 0){let n=s.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${r}': ${u.message}`)}Array.isArray(n)?i.push(...n):i.push(n);}}else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.assertion!==void 0){let u=n.assertion;if(typeof u=="function")try{u=u({relativeTarget:r.ref});}catch(d){throw new Error(`Error calling assertion function for state '${s}': ${d.message}`)}Array.isArray(u)?i.push(...u):i.push(u);}}}let a=[{type:this._as,target:this._onTarget,key:this._as==="keypress"?this.event:void 0,relativeTarget:this._onRelativeTarget}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,orientation:this._orientation||"horizontal",action:a,assertions:i,...l.length?{setup:l}:{}});}};function ie(e,t){let c=new f(e);return t(c),new m(c.build())}export{ie as createContract};