@visual-check/storybook 0.0.0 → 0.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD-PARTY-NOTICES.md +51 -0
  3. package/dist/angular-port/combinations.d.ts +89 -0
  4. package/dist/angular-port/combinations.d.ts.map +1 -0
  5. package/dist/angular-port/combinations.js +97 -0
  6. package/dist/angular-port/combinations.js.map +1 -0
  7. package/dist/angular.d.ts +4 -0
  8. package/dist/angular.d.ts.map +1 -0
  9. package/dist/angular.js +4 -0
  10. package/dist/angular.js.map +1 -0
  11. package/dist/dom-port/combinations.d.ts +59 -0
  12. package/dist/dom-port/combinations.d.ts.map +1 -0
  13. package/dist/dom-port/combinations.js +137 -0
  14. package/dist/dom-port/combinations.js.map +1 -0
  15. package/dist/forced-state/force-states.d.ts +68 -0
  16. package/dist/forced-state/force-states.d.ts.map +1 -0
  17. package/dist/forced-state/force-states.js +388 -0
  18. package/dist/forced-state/force-states.js.map +1 -0
  19. package/dist/forced-state/forced-states.d.ts +27 -0
  20. package/dist/forced-state/forced-states.d.ts.map +1 -0
  21. package/dist/forced-state/forced-states.js +41 -0
  22. package/dist/forced-state/forced-states.js.map +1 -0
  23. package/dist/forced-state/prototype-hooks.d.ts +28 -0
  24. package/dist/forced-state/prototype-hooks.d.ts.map +1 -0
  25. package/dist/forced-state/prototype-hooks.js +49 -0
  26. package/dist/forced-state/prototype-hooks.js.map +1 -0
  27. package/dist/forced-state/style-sheet-rewrite.d.ts +29 -0
  28. package/dist/forced-state/style-sheet-rewrite.d.ts.map +1 -0
  29. package/dist/forced-state/style-sheet-rewrite.js +148 -0
  30. package/dist/forced-state/style-sheet-rewrite.js.map +1 -0
  31. package/dist/forced-state/twin-selectors.d.ts +21 -0
  32. package/dist/forced-state/twin-selectors.d.ts.map +1 -0
  33. package/dist/forced-state/twin-selectors.js +316 -0
  34. package/dist/forced-state/twin-selectors.js.map +1 -0
  35. package/dist/grid-story/grid-layout.d.ts +156 -0
  36. package/dist/grid-story/grid-layout.d.ts.map +1 -0
  37. package/dist/grid-story/grid-layout.js +163 -0
  38. package/dist/grid-story/grid-layout.js.map +1 -0
  39. package/dist/index.d.ts +8 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +6 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/per-story-options/define-visual-check.d.ts +237 -0
  44. package/dist/per-story-options/define-visual-check.d.ts.map +1 -0
  45. package/dist/per-story-options/define-visual-check.js +60 -0
  46. package/dist/per-story-options/define-visual-check.js.map +1 -0
  47. package/dist/react-port/combinations.d.ts +27 -0
  48. package/dist/react-port/combinations.d.ts.map +1 -0
  49. package/dist/react-port/combinations.js +45 -0
  50. package/dist/react-port/combinations.js.map +1 -0
  51. package/dist/react.d.ts +4 -0
  52. package/dist/react.d.ts.map +1 -0
  53. package/dist/react.js +4 -0
  54. package/dist/react.js.map +1 -0
  55. package/dist/vue-port/combinations.d.ts +35 -0
  56. package/dist/vue-port/combinations.d.ts.map +1 -0
  57. package/dist/vue-port/combinations.js +75 -0
  58. package/dist/vue-port/combinations.js.map +1 -0
  59. package/dist/vue.d.ts +4 -0
  60. package/dist/vue.d.ts.map +1 -0
  61. package/dist/vue.js +4 -0
  62. package/dist/vue.js.map +1 -0
  63. package/package.json +78 -4
  64. package/README.md +0 -3
@@ -0,0 +1,148 @@
1
+ import { selectorListWithTwins } from './twin-selectors.js';
2
+ /**
3
+ * `CSSRule.STYLE_RULE`, written out: Node has no `CSSRule`.
4
+ */
5
+ const styleRuleType = 1;
6
+ /**
7
+ * `CSSRule.IMPORT_RULE`.
8
+ */
9
+ const importRuleType = 3;
10
+ /**
11
+ * A rewriter that reports through `warn`.
12
+ */
13
+ export function styleSheetRewriterOf(warn) {
14
+ const context = {
15
+ doneRules: new WeakMap(),
16
+ doneSheets: new WeakMap(),
17
+ sheetScopes: new WeakMap(),
18
+ warned: new Set(),
19
+ warn,
20
+ };
21
+ return {
22
+ rewriteSheet: (sheet, scope, states) => rewriteSheet(context, passOf(scope, states), sheet),
23
+ rewriteRule: (rule, scope, states) => rewriteRule(context, passOf(scope, states), rule),
24
+ forgetSheet: (sheet) => {
25
+ context.doneSheets.delete(sheet);
26
+ },
27
+ scopesOf: (sheet) => context.sheetScopes.get(sheet) ?? new Set(),
28
+ };
29
+ }
30
+ /**
31
+ * A pass over the states in a scope, with their bookkeeping tokens: `${scope}:${state}`.
32
+ */
33
+ function passOf(scope, states) {
34
+ return { scope, states, tokens: [...states].map((state) => `${scope}:${state}`) };
35
+ }
36
+ /**
37
+ * Whether the rule or sheet was done for every token.
38
+ */
39
+ function isDone(done, key, tokens) {
40
+ const doneTokens = done.get(key);
41
+ return doneTokens !== undefined && tokens.every((token) => doneTokens.has(token));
42
+ }
43
+ /**
44
+ * Records the rule or sheet as done for the tokens.
45
+ */
46
+ function markDone(done, key, tokens) {
47
+ done.set(key, new Set([...(done.get(key) ?? []), ...tokens]));
48
+ }
49
+ /**
50
+ * Walks the sheet's rules unless it was walked for this pass. A sheet whose rules can't be read is left undone, unless
51
+ * it's cross-origin, which can't change: that one is marked done but not rewritten in the scope.
52
+ */
53
+ function rewriteSheet(context, pass, sheet) {
54
+ if (isDone(context.doneSheets, sheet, pass.tokens)) {
55
+ return;
56
+ }
57
+ const rules = readableRulesOf(context, sheet);
58
+ if (rules === 'retry') {
59
+ return;
60
+ }
61
+ markDone(context.doneSheets, sheet, pass.tokens);
62
+ if (rules === 'cross-origin') {
63
+ return;
64
+ }
65
+ for (const rule of rules) {
66
+ rewriteRule(context, pass, rule);
67
+ }
68
+ context.sheetScopes.set(sheet, (context.sheetScopes.get(sheet) ?? new Set()).add(pass.scope));
69
+ }
70
+ /**
71
+ * The sheet's rules; `'cross-origin'` for a cross-origin sheet, which warns once per `href`; `'retry'` on any other
72
+ * error.
73
+ */
74
+ function readableRulesOf(context, sheet) {
75
+ try {
76
+ return Array.from(sheet.cssRules);
77
+ }
78
+ catch (error) {
79
+ if (!isSecurityError(error)) {
80
+ return 'retry';
81
+ }
82
+ warnOnce(context, `visual-check: can't force states in the stylesheet ${sheet.href}: it's cross-origin without CORS. Load it with crossorigin="anonymous" from a server that sends Access-Control-Allow-Origin.`);
83
+ return 'cross-origin';
84
+ }
85
+ }
86
+ /**
87
+ * Whether a thrown value is the `SecurityError` a cross-origin sheet's `cssRules` throws.
88
+ */
89
+ function isSecurityError(error) {
90
+ return typeof error === 'object' && error !== null && 'name' in error && error.name === 'SecurityError';
91
+ }
92
+ /**
93
+ * Rewrites a rule by its type: a style rule's selector and the rules nested in it, a grouping rule's rules, or an
94
+ * imported sheet. Anything else, `@keyframes`, `@font-face` and `@page` included, is left alone.
95
+ */
96
+ function rewriteRule(context, pass, rule) {
97
+ if (rule.type === importRuleType) {
98
+ rewriteImport(context, pass, rule);
99
+ return;
100
+ }
101
+ if (rule.type === styleRuleType) {
102
+ rewriteSelector(context, pass, rule);
103
+ }
104
+ // `@keyframes` has `cssRules` too, but its keyframes are never style rules.
105
+ if ('cssRules' in rule) {
106
+ for (const child of Array.from(rule.cssRules)) {
107
+ rewriteRule(context, pass, child);
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * Walks an `@import`ed sheet, once it's loaded.
113
+ */
114
+ function rewriteImport(context, pass, rule) {
115
+ if (rule.styleSheet !== null) {
116
+ rewriteSheet(context, pass, rule.styleSheet);
117
+ }
118
+ }
119
+ /**
120
+ * Gives a style rule's selector list its twins, in place, unless it was done for these states in this scope. A list
121
+ * the browser rejects warns once per original selector text and isn't retried.
122
+ */
123
+ function rewriteSelector(context, pass, rule) {
124
+ if (isDone(context.doneRules, rule, pass.tokens)) {
125
+ return;
126
+ }
127
+ markDone(context.doneRules, rule, pass.tokens);
128
+ const original = rule.selectorText;
129
+ const rewritten = selectorListWithTwins(original, pass.states, pass.scope);
130
+ if (rewritten === null) {
131
+ return;
132
+ }
133
+ rule.selectorText = rewritten;
134
+ if (rule.selectorText === original) {
135
+ warnOnce(context, `visual-check: couldn't force states in the rule \`${original}\`.`);
136
+ }
137
+ }
138
+ /**
139
+ * Reports a warning unless it was already given.
140
+ */
141
+ function warnOnce(context, message) {
142
+ if (context.warned.has(message)) {
143
+ return;
144
+ }
145
+ context.warned.add(message);
146
+ context.warn(message);
147
+ }
148
+ //# sourceMappingURL=style-sheet-rewrite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style-sheet-rewrite.js","sourceRoot":"","sources":["../../src/forced-state/style-sheet-rewrite.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAqE5E;;GAEG;AACH,MAAM,aAAa,GAAG,CAAC,CAAA;AAEvB;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA+B;IAClE,MAAM,OAAO,GAAmB;QAC9B,SAAS,EAAE,IAAI,OAAO,EAAE;QACxB,UAAU,EAAE,IAAI,OAAO,EAAE;QACzB,WAAW,EAAE,IAAI,OAAO,EAAE;QAC1B,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,IAAI;KACL,CAAA;IAED,OAAO;QACL,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC;QAC3F,WAAW,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;QACvF,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACrB,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAClC,CAAC;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC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AAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,QAAQ,CAAC,OAAuB,EAAE,OAAe;IACxD,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAM;IACR,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type ForcedState } from './forced-states.js';
2
+ /**
3
+ * Where a stylesheet applies: the document's own sheets, or a shadow root's (and constructed sheets not known to be the
4
+ * document's).
5
+ */
6
+ export type SheetScope = 'document' | 'shadow-root';
7
+ /**
8
+ * The selector list with the twins it lacks appended after its own selectors, in their order (for each: light twin,
9
+ * then host twin), or null when there's nothing to add. Twins of states not in `states` aren't made.
10
+ *
11
+ * A light twin replaces each state with `:is(.visual-check-<state> *)`, which matches under an ancestor with the class
12
+ * at the same specificity. A host twin, made only in a shadow-root sheet, puts the condition on the shadow host.
13
+ *
14
+ * `selectorText` is expected as the CSSOM serializes it, with pseudo-class and pseudo-element names in lowercase:
15
+ * names are matched as written, so `:HOVER` is not twinned.
16
+ *
17
+ * Adapted from Storybook's pseudo-states addon (`storybook-addon-pseudo-states`, MIT): the selector splitting from its
18
+ * `splitSelectors` and the escape handling from its `findPseudoStates`. See THIRD-PARTY-NOTICES.md at the package root.
19
+ */
20
+ export declare function selectorListWithTwins(selectorText: string, states: ReadonlySet<ForcedState>, scope: SheetScope): string | null;
21
+ //# sourceMappingURL=twin-selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twin-selectors.d.ts","sourceRoot":"","sources":["../../src/forced-state/twin-selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAoC,MAAM,oBAAoB,CAAA;AAEvF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,aAAa,CAAA;AAkJnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,EAChC,KAAK,EAAE,UAAU,GAChB,MAAM,GAAG,IAAI,CAWf"}
@@ -0,0 +1,316 @@
1
+ import { forcedStateClassOf, forcedStates } from './forced-states.js';
2
+ /**
3
+ * Matches a selector that is one of our own twins, which is never twinned again.
4
+ */
5
+ const ownTwinPattern = new RegExp(`\\.visual-check-(?:${forcedStates.join('|')})(?![\\w-])`);
6
+ /**
7
+ * Matches a character of a pseudo-class or pseudo-element name.
8
+ */
9
+ const nameCharacterPattern = /[\w-]/;
10
+ /**
11
+ * Matches a character that would make a state name part of a longer name or a function.
12
+ */
13
+ const nameContinuationPattern = /[\w(-]/;
14
+ /**
15
+ * Matches a character that ends a compound selector at the top level.
16
+ */
17
+ const compoundEndPattern = /[\s>+~),]/;
18
+ /**
19
+ * Matches the character before a compound selector: one that ends the previous compound, or `(`.
20
+ */
21
+ const compoundStartPattern = /[\s>+~(,]/;
22
+ /**
23
+ * Matches a pseudo-class or pseudo-element only a shadow-root sheet can match. Sticky: it matches at `lastIndex`.
24
+ */
25
+ const shadowOnlyPattern = /::?(?:host|host-context|slotted)(?![\w-])/y;
26
+ /**
27
+ * The closing character of each character that opens a string or an attribute selector.
28
+ */
29
+ const closerOf = { '"': '"', "'": "'", '[': ']' };
30
+ /**
31
+ * The selector list with the twins it lacks appended after its own selectors, in their order (for each: light twin,
32
+ * then host twin), or null when there's nothing to add. Twins of states not in `states` aren't made.
33
+ *
34
+ * A light twin replaces each state with `:is(.visual-check-<state> *)`, which matches under an ancestor with the class
35
+ * at the same specificity. A host twin, made only in a shadow-root sheet, puts the condition on the shadow host.
36
+ *
37
+ * `selectorText` is expected as the CSSOM serializes it, with pseudo-class and pseudo-element names in lowercase:
38
+ * names are matched as written, so `:HOVER` is not twinned.
39
+ *
40
+ * Adapted from Storybook's pseudo-states addon (`storybook-addon-pseudo-states`, MIT): the selector splitting from its
41
+ * `splitSelectors` and the escape handling from its `findPseudoStates`. See THIRD-PARTY-NOTICES.md at the package root.
42
+ */
43
+ export function selectorListWithTwins(selectorText, states, scope) {
44
+ const selectors = selectorsOf(selectorText).map((selector) => selector.trim());
45
+ const twins = [...new Set(selectors.flatMap((selector) => twinsOf(selector, states, scope)))].filter((twin) => !selectors.includes(twin));
46
+ if (twins.length === 0) {
47
+ return null;
48
+ }
49
+ return [selectorText, ...twins].join(', ');
50
+ }
51
+ /**
52
+ * One selector's twins: its light twin, then its host twin, each when it can be made.
53
+ */
54
+ function twinsOf(selector, states, scope) {
55
+ if (ownTwinPattern.test(selector)) {
56
+ return [];
57
+ }
58
+ const scanned = scan(selector, states);
59
+ if (scanned.occurrences.length === 0) {
60
+ return [];
61
+ }
62
+ const lightTwin = scanned.shadowOnly ? null : lightTwinOf(selector, scanned.occurrences);
63
+ const hostTwin = scope === 'shadow-root' ? hostTwinOf(selector, scanned) : null;
64
+ return [lightTwin, hostTwin].filter((twin) => twin !== null);
65
+ }
66
+ /**
67
+ * The selectors of a list, split at top-level commas: commas inside `()`, `[]` and strings don't split.
68
+ */
69
+ function selectorsOf(selectorText) {
70
+ const selectors = [];
71
+ let selectorStart = 0;
72
+ walk(selectorText, (index, parentheses) => {
73
+ if (selectorText[index] === ',' && parentheses.length === 0) {
74
+ selectors.push(selectorText.slice(selectorStart, index));
75
+ selectorStart = index + 1;
76
+ }
77
+ });
78
+ selectors.push(selectorText.slice(selectorStart));
79
+ return selectors;
80
+ }
81
+ /**
82
+ * Calls `visit` for each character of a selector that isn't escaped, in a string or in an attribute selector, or a
83
+ * closing parenthesis, with the parentheses open around it. Returns the index of each closing parenthesis, by the index
84
+ * of its opening one.
85
+ */
86
+ function walk(selector, visit) {
87
+ const isHidden = hiddenTextTracker();
88
+ const parentheses = [];
89
+ const closingParenthesisOf = new Map();
90
+ for (let index = 0; index < selector.length; index++) {
91
+ const character = selector[index];
92
+ if (character === '\\') {
93
+ index++;
94
+ continue;
95
+ }
96
+ if (isHidden(character)) {
97
+ continue;
98
+ }
99
+ if (character === ')') {
100
+ closeParenthesis(parentheses, index, closingParenthesisOf);
101
+ continue;
102
+ }
103
+ visit(index, parentheses);
104
+ if (character === '(') {
105
+ parentheses.push({ name: functionNameBefore(selector, index), index });
106
+ }
107
+ }
108
+ return closingParenthesisOf;
109
+ }
110
+ /**
111
+ * The functional pseudo-class or pseudo-element name, with its colons, that ends right before `index`, or empty.
112
+ */
113
+ function functionNameBefore(selector, index) {
114
+ let nameStart = index;
115
+ while (nameStart > 0 && nameCharacterPattern.test(selector[nameStart - 1])) {
116
+ nameStart--;
117
+ }
118
+ let start = nameStart;
119
+ while (start > 0 && nameStart - start < 2 && selector[start - 1] === ':') {
120
+ start--;
121
+ }
122
+ return start === nameStart ? '' : selector.slice(start, index);
123
+ }
124
+ /**
125
+ * Closes the innermost open parenthesis at `index`, recording where it closes. A stray one closes nothing.
126
+ */
127
+ function closeParenthesis(parentheses, index, closingParenthesisOf) {
128
+ const opening = parentheses.pop();
129
+ if (opening !== undefined) {
130
+ closingParenthesisOf.set(opening.index, index);
131
+ }
132
+ }
133
+ /**
134
+ * A function that takes a selector's characters in order and tells whether each is inside, or delimits, a string or an
135
+ * attribute selector.
136
+ */
137
+ function hiddenTextTracker() {
138
+ const closers = [];
139
+ return (character) => {
140
+ const open = closers.at(-1);
141
+ if (character === open) {
142
+ closers.pop();
143
+ return true;
144
+ }
145
+ const closer = closerOf[character];
146
+ if (closer !== undefined && open !== '"' && open !== "'") {
147
+ closers.push(closer);
148
+ return true;
149
+ }
150
+ return open !== undefined;
151
+ };
152
+ }
153
+ /**
154
+ * One pass over a selector: the listed states it uses outside `:not()` and where its shadow-only parts are.
155
+ */
156
+ function scan(selector, states) {
157
+ const progress = {
158
+ occurrences: [],
159
+ shadowOnly: false,
160
+ pseudoElementIndex: null,
161
+ pseudoElementSecondColonIndex: null,
162
+ };
163
+ const closingParenthesisOf = walk(selector, (index, parentheses) => {
164
+ const character = selector[index];
165
+ if (parentheses.length === 0 && compoundEndPattern.test(character)) {
166
+ progress.pseudoElementIndex = null;
167
+ }
168
+ else if (character === ':' && index !== progress.pseudoElementSecondColonIndex) {
169
+ scanColon(selector, index, parentheses, states, progress);
170
+ }
171
+ });
172
+ return { occurrences: progress.occurrences, shadowOnly: progress.shadowOnly, closingParenthesisOf };
173
+ }
174
+ /**
175
+ * Records what starts at the colon at `index`: a pseudo-element, which a later top-level state moves in front of, or
176
+ * an occurrence of a listed state.
177
+ */
178
+ function scanColon(selector, index, parentheses, states, progress) {
179
+ const topLevel = parentheses.length === 0;
180
+ shadowOnlyPattern.lastIndex = index;
181
+ progress.shadowOnly ||= shadowOnlyPattern.test(selector);
182
+ if (selector[index + 1] === ':') {
183
+ progress.pseudoElementIndex ??= topLevel ? index : null;
184
+ progress.pseudoElementSecondColonIndex = index + 1;
185
+ return;
186
+ }
187
+ const occurrence = occurrenceAt(selector, index, parentheses, states);
188
+ if (occurrence !== null) {
189
+ progress.occurrences.push({ ...occurrence, pseudoElementIndex: topLevel ? progress.pseudoElementIndex : null });
190
+ }
191
+ }
192
+ /**
193
+ * The occurrence of a listed state whose colon is at `index`, without the pseudo-element it follows, or null when the
194
+ * state isn't listed or is inside `:not()`.
195
+ */
196
+ function occurrenceAt(selector, index, parentheses, states) {
197
+ const state = stateAt(selector, index + 1, states);
198
+ const names = parentheses.map((parenthesis) => parenthesis.name);
199
+ if (state === null || names.includes(':not')) {
200
+ return null;
201
+ }
202
+ return {
203
+ state,
204
+ start: index,
205
+ end: index + 1 + state.length,
206
+ host: names.includes(':host') || names.includes(':host-context'),
207
+ topLevel: names.length === 0 || (names.length === 1 && names[0] === '::slotted'),
208
+ startsCompound: compoundStartPattern.test(selector[index - 1] ?? ' '),
209
+ };
210
+ }
211
+ /**
212
+ * The listed state whose name starts at `index` and isn't the start of a longer name, or null.
213
+ */
214
+ function stateAt(selector, index, states) {
215
+ for (const state of states) {
216
+ const following = selector[index + state.length] ?? '';
217
+ if (selector.startsWith(state, index) && !nameContinuationPattern.test(following)) {
218
+ return state;
219
+ }
220
+ }
221
+ return null;
222
+ }
223
+ /**
224
+ * The twin that matches under an ancestor with each state's class: every occurrence becomes
225
+ * `:is(.visual-check-<state> *)`, moved in front of the pseudo-element it follows.
226
+ */
227
+ function lightTwinOf(selector, occurrences) {
228
+ return withEdits(selector, occurrences.flatMap((occurrence) => replacing(occurrence, `:is(.${forcedStateClassOf(occurrence.state)} *)`)));
229
+ }
230
+ /**
231
+ * The twin that matches in a shadow tree when its host has each state's class, at the same specificity, or null when
232
+ * the selector can't keep its specificity that way.
233
+ */
234
+ function hostTwinOf(selector, scanned) {
235
+ const hostEdits = scanned.occurrences
236
+ .filter((occurrence) => occurrence.host)
237
+ .flatMap((occurrence) => replacing(occurrence, `.${forcedStateClassOf(occurrence.state)}`));
238
+ const shadowTreeOccurrences = scanned.occurrences.filter((occurrence) => !occurrence.host);
239
+ if (shadowTreeOccurrences.length === 0) {
240
+ return withEdits(selector, hostEdits);
241
+ }
242
+ if (selector.startsWith(':host-context(')) {
243
+ return null;
244
+ }
245
+ const classes = forcedStates
246
+ .filter((state) => shadowTreeOccurrences.some((occurrence) => occurrence.state === state))
247
+ .map((state) => `.${forcedStateClassOf(state)}`)
248
+ .join('');
249
+ const condition = `:where(${classes})`;
250
+ const standIns = (occurrences) => occurrences.flatMap((occurrence) => replacing(occurrence, `:is(*, .${forcedStateClassOf(occurrence.state)})`));
251
+ if (selector.startsWith(':host(')) {
252
+ const closing = scanned.closingParenthesisOf.get(':host'.length) ?? selector.length;
253
+ return withEdits(selector, [
254
+ ...hostEdits,
255
+ { index: closing, removeLength: 0, insert: condition },
256
+ ...standIns(shadowTreeOccurrences),
257
+ ]);
258
+ }
259
+ if (selector.startsWith(':host')) {
260
+ return withEdits(selector, [
261
+ { index: 0, removeLength: ':host'.length, insert: `:host(${condition})` },
262
+ ...hostEdits,
263
+ ...standIns(shadowTreeOccurrences),
264
+ ]);
265
+ }
266
+ const removed = shadowTreeOccurrences.find((occurrence) => occurrence.topLevel);
267
+ if (removed === undefined) {
268
+ return null;
269
+ }
270
+ const others = shadowTreeOccurrences.filter((occurrence) => occurrence !== removed);
271
+ const twin = withEdits(selector, [
272
+ {
273
+ index: removed.start,
274
+ removeLength: removed.end - removed.start,
275
+ insert: leavesCompoundEmpty(selector, removed) ? '*' : '',
276
+ },
277
+ ...hostEdits,
278
+ ...standIns(others),
279
+ ]);
280
+ return `:host(${condition}) ${twin}`;
281
+ }
282
+ /**
283
+ * Whether removing the occurrence leaves its compound selector with nothing in it.
284
+ */
285
+ function leavesCompoundEmpty(selector, occurrence) {
286
+ const following = selector[occurrence.end];
287
+ return (occurrence.startsCompound &&
288
+ (following === undefined || compoundEndPattern.test(following) || selector.startsWith('::', occurrence.end)));
289
+ }
290
+ /**
291
+ * The edits that replace an occurrence with `replacement`, inserted in front of the pseudo-element it follows if any.
292
+ */
293
+ function replacing(occurrence, replacement) {
294
+ const removeLength = occurrence.end - occurrence.start;
295
+ if (occurrence.pseudoElementIndex === null) {
296
+ return [{ index: occurrence.start, removeLength, insert: replacement }];
297
+ }
298
+ return [
299
+ { index: occurrence.start, removeLength, insert: '' },
300
+ { index: occurrence.pseudoElementIndex, removeLength: 0, insert: replacement },
301
+ ];
302
+ }
303
+ /**
304
+ * The selector with the edits applied. Edits at the same index keep their order.
305
+ */
306
+ function withEdits(selector, edits) {
307
+ const ordered = edits
308
+ .map((edit, order) => ({ edit, order }))
309
+ .sort((left, right) => right.edit.index - left.edit.index || right.order - left.order);
310
+ let result = selector;
311
+ for (const { edit } of ordered) {
312
+ result = result.slice(0, edit.index) + edit.insert + result.slice(edit.index + edit.removeLength);
313
+ }
314
+ return result;
315
+ }
316
+ //# sourceMappingURL=twin-selectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twin-selectors.js","sourceRoot":"","sources":["../../src/forced-state/twin-selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EA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
+ import { type ForcedState } from '../forced-state/forced-states.js';
2
+ /**
3
+ * The attribute the grid's element carries, empty, which capture finds a grid by.
4
+ *
5
+ * @public
6
+ */
7
+ export declare const gridAttribute = "data-visual-check-grid";
8
+ /**
9
+ * The values to try for each prop of a component, by prop name. Every combination of them is a row.
10
+ *
11
+ * @public
12
+ */
13
+ export type PropValues<Props> = {
14
+ readonly [Name in keyof Props]?: readonly Props[Name][];
15
+ };
16
+ /**
17
+ * What every port of the grid takes besides the component: the same in React, Vue, Angular and plain DOM.
18
+ *
19
+ * @public
20
+ */
21
+ export interface GridInput<Props> {
22
+ /**
23
+ * The values to try for each prop. Rows follow the key order (declaration order), the last prop changing fastest. A
24
+ * prop varies when it lists two or more values, even if they repeat; a prop with a single value applies to every
25
+ * row. A prop whose list is `undefined` counts as not listed. Every prop the component requires has to come from
26
+ * here or from `args`.
27
+ */
28
+ props: PropValues<Props>;
29
+ /**
30
+ * The props every row shares. A prop listed in `props` wins over the same key here. Args never appear in a caption.
31
+ * Every prop the component requires has to come from here or from `props`: a story usually passes its own args.
32
+ */
33
+ args?: Partial<Props> | undefined;
34
+ /**
35
+ * The width of every column in CSS pixels, each cell exactly that wide. Without it, a column is as wide as its widest
36
+ * cell.
37
+ */
38
+ cellWidth?: number | undefined;
39
+ /**
40
+ * The states to force, one column each after the default state's, in the order given: `hover`, `active`,
41
+ * `focus-visible`, `focus-within` and `focus`. With states, a header row names each column. Each state may appear
42
+ * once.
43
+ */
44
+ states?: readonly ForcedState[] | undefined;
45
+ /**
46
+ * Replaces a caption's default text. It gets only the row's varying props, in declaration order, and isn't called
47
+ * for a row with no varying prop.
48
+ */
49
+ caption?: ((props: Partial<Props>) => string) | undefined;
50
+ }
51
+ /**
52
+ * An element's inline styles: CSS property names as CSS writes them, to values. The order matters: `all` first.
53
+ *
54
+ * @public
55
+ */
56
+ export type GridStyle = Readonly<Record<string, string>>;
57
+ /**
58
+ * The caption above a row: a line that names the row's varying props.
59
+ *
60
+ * @public
61
+ */
62
+ export interface GridCaption {
63
+ /**
64
+ * The caption's text.
65
+ */
66
+ text: string;
67
+ /**
68
+ * The caption element's inline styles.
69
+ */
70
+ style: GridStyle;
71
+ }
72
+ /**
73
+ * The header of one column, in the header row: a line that names the column's state.
74
+ *
75
+ * @public
76
+ */
77
+ export interface GridHeader {
78
+ /**
79
+ * `default` for the first column, else `:` and the state, such as `:focus-visible`.
80
+ */
81
+ text: string;
82
+ /**
83
+ * The header element's inline styles.
84
+ */
85
+ style: GridStyle;
86
+ }
87
+ /**
88
+ * A cell of a row: the element that holds one render of the component.
89
+ *
90
+ * @public
91
+ */
92
+ export interface GridCell {
93
+ /**
94
+ * The cell element's inline styles.
95
+ */
96
+ style: GridStyle;
97
+ /**
98
+ * The class of the cell's forced state, such as `visual-check-hover`, which the cell element carries so what it holds
99
+ * shows that state; `null` for the default state's cell.
100
+ */
101
+ stateClass: string | null;
102
+ }
103
+ /**
104
+ * A row of the grid: one combination of the listed props.
105
+ *
106
+ * @public
107
+ */
108
+ export interface GridRow<Props> {
109
+ /**
110
+ * The props of the row's component: `{ ...args, ...combination }`. They are complete only when `args` and `props`
111
+ * together hold every prop the component requires.
112
+ */
113
+ props: Props;
114
+ /**
115
+ * The row's caption, or `null` for a row with no varying prop.
116
+ */
117
+ caption: GridCaption | null;
118
+ /**
119
+ * One cell per column, in column order: the default state's, then each forced state's.
120
+ */
121
+ cells: GridCell[];
122
+ }
123
+ /**
124
+ * Everything a port draws: the grid element's styles, its header row and its rows, and the states it forces.
125
+ *
126
+ * @public
127
+ */
128
+ export interface GridLayout<Props> {
129
+ /**
130
+ * The grid element's inline styles.
131
+ */
132
+ style: GridStyle;
133
+ /**
134
+ * The header row: one header per column, in column order, or none when the grid forces no state.
135
+ */
136
+ headers: GridHeader[];
137
+ /**
138
+ * The rows, in combination order.
139
+ */
140
+ rows: GridRow<Props>[];
141
+ /**
142
+ * The states the grid forces, checked, in column order after the default state's: what a port passes to
143
+ * `forceStates` while the grid is shown.
144
+ */
145
+ states: ForcedState[];
146
+ }
147
+ /**
148
+ * Works out a grid: its columns (the default state's, then one per forced state), its header row, its rows (every
149
+ * combination of the listed props), each caption's text and every element's inline styles. Each port only turns the
150
+ * layout into elements, and forces the layout's states while it's shown.
151
+ *
152
+ * @throws When a prop lists no values, or `states` lists an unknown state or one twice.
153
+ * @public
154
+ */
155
+ export declare function gridLayoutOf<Props extends object>(input: GridInput<Props>): GridLayout<Props>;
156
+ //# sourceMappingURL=grid-layout.d.ts.map