@turntrout/subfont 1.7.0 → 1.8.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 (151) hide show
  1. package/CLAUDE.md +39 -13
  2. package/README.md +24 -14
  3. package/lib/FontTracerPool.d.ts +38 -0
  4. package/lib/FontTracerPool.d.ts.map +1 -0
  5. package/lib/FontTracerPool.js +230 -217
  6. package/lib/FontTracerPool.js.map +1 -0
  7. package/lib/HeadlessBrowser.d.ts +18 -0
  8. package/lib/HeadlessBrowser.d.ts.map +1 -0
  9. package/lib/HeadlessBrowser.js +216 -210
  10. package/lib/HeadlessBrowser.js.map +1 -0
  11. package/lib/cli.d.ts +3 -0
  12. package/lib/cli.d.ts.map +1 -0
  13. package/lib/cli.js +15 -12
  14. package/lib/cli.js.map +1 -0
  15. package/lib/codepointMaps.d.ts +4 -0
  16. package/lib/codepointMaps.d.ts.map +1 -0
  17. package/lib/codepointMaps.js +99 -0
  18. package/lib/codepointMaps.js.map +1 -0
  19. package/lib/collectFeatureGlyphIds.d.ts +3 -0
  20. package/lib/collectFeatureGlyphIds.d.ts.map +1 -0
  21. package/lib/collectFeatureGlyphIds.js +124 -138
  22. package/lib/collectFeatureGlyphIds.js.map +1 -0
  23. package/lib/collectTextsByPage.d.ts +41 -0
  24. package/lib/collectTextsByPage.d.ts.map +1 -0
  25. package/lib/collectTextsByPage.js +726 -965
  26. package/lib/collectTextsByPage.js.map +1 -0
  27. package/lib/concurrencyLimit.d.ts +3 -0
  28. package/lib/concurrencyLimit.d.ts.map +1 -0
  29. package/lib/concurrencyLimit.js +12 -11
  30. package/lib/concurrencyLimit.js.map +1 -0
  31. package/lib/escapeJsStringLiteral.d.ts +3 -0
  32. package/lib/escapeJsStringLiteral.d.ts.map +1 -0
  33. package/lib/escapeJsStringLiteral.js +7 -6
  34. package/lib/escapeJsStringLiteral.js.map +1 -0
  35. package/lib/extractReferencedCustomPropertyNames.d.ts +3 -0
  36. package/lib/extractReferencedCustomPropertyNames.d.ts.map +1 -0
  37. package/lib/extractReferencedCustomPropertyNames.js +15 -16
  38. package/lib/extractReferencedCustomPropertyNames.js.map +1 -0
  39. package/lib/extractVisibleText.d.ts +7 -0
  40. package/lib/extractVisibleText.d.ts.map +1 -0
  41. package/lib/extractVisibleText.js +110 -119
  42. package/lib/extractVisibleText.js.map +1 -0
  43. package/lib/findCustomPropertyDefinitions.d.ts +8 -0
  44. package/lib/findCustomPropertyDefinitions.d.ts.map +1 -0
  45. package/lib/findCustomPropertyDefinitions.js +41 -48
  46. package/lib/findCustomPropertyDefinitions.js.map +1 -0
  47. package/lib/fontConverter.d.ts +2 -0
  48. package/lib/fontConverter.d.ts.map +1 -0
  49. package/lib/fontConverter.js +40 -21
  50. package/lib/fontConverter.js.map +1 -0
  51. package/lib/fontConverterWorker.d.ts +2 -0
  52. package/lib/fontConverterWorker.d.ts.map +1 -0
  53. package/lib/fontConverterWorker.js +52 -15
  54. package/lib/fontConverterWorker.js.map +1 -0
  55. package/lib/fontFaceHelpers.d.ts +64 -0
  56. package/lib/fontFaceHelpers.d.ts.map +1 -0
  57. package/lib/fontFaceHelpers.js +237 -249
  58. package/lib/fontFaceHelpers.js.map +1 -0
  59. package/lib/fontFeatureHelpers.d.ts +30 -0
  60. package/lib/fontFeatureHelpers.d.ts.map +1 -0
  61. package/lib/fontFeatureHelpers.js +277 -212
  62. package/lib/fontFeatureHelpers.js.map +1 -0
  63. package/lib/fontTracerWorker.d.ts +11 -0
  64. package/lib/fontTracerWorker.d.ts.map +1 -0
  65. package/lib/fontTracerWorker.js +94 -60
  66. package/lib/fontTracerWorker.js.map +1 -0
  67. package/lib/gatherStylesheetsWithPredicates.d.ts +26 -0
  68. package/lib/gatherStylesheetsWithPredicates.d.ts.map +1 -0
  69. package/lib/gatherStylesheetsWithPredicates.js +75 -84
  70. package/lib/gatherStylesheetsWithPredicates.js.map +1 -0
  71. package/lib/getCssRulesByProperty.d.ts +29 -0
  72. package/lib/getCssRulesByProperty.d.ts.map +1 -0
  73. package/lib/getCssRulesByProperty.js +316 -316
  74. package/lib/getCssRulesByProperty.js.map +1 -0
  75. package/lib/getFontInfo.d.ts +11 -0
  76. package/lib/getFontInfo.d.ts.map +1 -0
  77. package/lib/getFontInfo.js +31 -33
  78. package/lib/getFontInfo.js.map +1 -0
  79. package/lib/initialValueByProp.d.ts +3 -0
  80. package/lib/initialValueByProp.d.ts.map +1 -0
  81. package/lib/initialValueByProp.js +20 -17
  82. package/lib/initialValueByProp.js.map +1 -0
  83. package/lib/injectSubsetDefinitions.d.ts +3 -0
  84. package/lib/injectSubsetDefinitions.d.ts.map +1 -0
  85. package/lib/injectSubsetDefinitions.js +55 -59
  86. package/lib/injectSubsetDefinitions.js.map +1 -0
  87. package/lib/normalizeFontPropertyValue.d.ts +3 -0
  88. package/lib/normalizeFontPropertyValue.d.ts.map +1 -0
  89. package/lib/normalizeFontPropertyValue.js +59 -54
  90. package/lib/normalizeFontPropertyValue.js.map +1 -0
  91. package/lib/parseCommandLineOptions.d.ts +9 -0
  92. package/lib/parseCommandLineOptions.d.ts.map +1 -0
  93. package/lib/parseCommandLineOptions.js +145 -149
  94. package/lib/parseCommandLineOptions.js.map +1 -0
  95. package/lib/parseFontVariationSettings.d.ts +3 -0
  96. package/lib/parseFontVariationSettings.d.ts.map +1 -0
  97. package/lib/parseFontVariationSettings.js +38 -36
  98. package/lib/parseFontVariationSettings.js.map +1 -0
  99. package/lib/progress.d.ts +27 -0
  100. package/lib/progress.d.ts.map +1 -0
  101. package/lib/progress.js +51 -54
  102. package/lib/progress.js.map +1 -0
  103. package/lib/sfntCache.d.ts +4 -0
  104. package/lib/sfntCache.d.ts.map +1 -0
  105. package/lib/sfntCache.js +67 -25
  106. package/lib/sfntCache.js.map +1 -0
  107. package/lib/stripLocalTokens.d.ts +3 -0
  108. package/lib/stripLocalTokens.d.ts.map +1 -0
  109. package/lib/stripLocalTokens.js +23 -21
  110. package/lib/stripLocalTokens.js.map +1 -0
  111. package/lib/subfont.d.ts +54 -0
  112. package/lib/subfont.d.ts.map +1 -0
  113. package/lib/subfont.js +531 -629
  114. package/lib/subfont.js.map +1 -0
  115. package/lib/subsetFontWithGlyphs.d.ts +21 -0
  116. package/lib/subsetFontWithGlyphs.d.ts.map +1 -0
  117. package/lib/subsetFontWithGlyphs.js +285 -259
  118. package/lib/subsetFontWithGlyphs.js.map +1 -0
  119. package/lib/subsetFonts.d.ts +55 -0
  120. package/lib/subsetFonts.d.ts.map +1 -0
  121. package/lib/subsetFonts.js +899 -1200
  122. package/lib/subsetFonts.js.map +1 -0
  123. package/lib/subsetGeneration.d.ts +36 -0
  124. package/lib/subsetGeneration.d.ts.map +1 -0
  125. package/lib/subsetGeneration.js +328 -325
  126. package/lib/subsetGeneration.js.map +1 -0
  127. package/lib/types/shared.d.ts +11 -0
  128. package/lib/types/shared.d.ts.map +1 -0
  129. package/lib/types/shared.js +3 -0
  130. package/lib/types/shared.js.map +1 -0
  131. package/lib/unicodeRange.d.ts +3 -0
  132. package/lib/unicodeRange.d.ts.map +1 -0
  133. package/lib/unicodeRange.js +17 -30
  134. package/lib/unicodeRange.js.map +1 -0
  135. package/lib/unquote.d.ts +3 -0
  136. package/lib/unquote.d.ts.map +1 -0
  137. package/lib/unquote.js +18 -25
  138. package/lib/unquote.js.map +1 -0
  139. package/lib/variationAxes.d.ts +33 -0
  140. package/lib/variationAxes.d.ts.map +1 -0
  141. package/lib/variationAxes.js +127 -157
  142. package/lib/variationAxes.js.map +1 -0
  143. package/lib/warnAboutMissingGlyphs.d.ts +43 -0
  144. package/lib/warnAboutMissingGlyphs.d.ts.map +1 -0
  145. package/lib/warnAboutMissingGlyphs.js +139 -147
  146. package/lib/warnAboutMissingGlyphs.js.map +1 -0
  147. package/lib/wasmQueue.d.ts +3 -0
  148. package/lib/wasmQueue.d.ts.map +1 -0
  149. package/lib/wasmQueue.js +13 -10
  150. package/lib/wasmQueue.js.map +1 -0
  151. package/package.json +12 -2
@@ -1,344 +1,344 @@
1
- const specificity = require('specificity');
2
- const postcss = require('postcss');
3
- const postcssValueParser = require('postcss-value-parser');
4
- const unquote = require('./unquote');
5
- const parseAnimationShorthand = require('@hookun/parse-animation-shorthand');
6
-
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const specificity = __importStar(require("specificity"));
36
+ const postcss = __importStar(require("postcss"));
37
+ const postcssValueParser = require("postcss-value-parser");
38
+ const unquote = require("./unquote");
39
+ const parseAnimationShorthand = __importStar(require("@hookun/parse-animation-shorthand"));
7
40
  const counterRendererNames = new Set([
8
- 'none',
9
- 'disc',
10
- 'circle',
11
- 'square',
12
- 'decimal',
13
- 'decimal-leading-zero',
14
- 'lower-roman',
15
- 'upper-roman',
16
- 'lower-greek',
17
- 'lower-latin',
18
- 'lower-alpha',
19
- 'upper-latin',
20
- 'upper-alpha',
21
- 'armenian',
22
- 'georgian',
23
- 'hebrew',
41
+ 'none',
42
+ 'disc',
43
+ 'circle',
44
+ 'square',
45
+ 'decimal',
46
+ 'decimal-leading-zero',
47
+ 'lower-roman',
48
+ 'upper-roman',
49
+ 'lower-greek',
50
+ 'lower-latin',
51
+ 'lower-alpha',
52
+ 'upper-latin',
53
+ 'upper-alpha',
54
+ 'armenian',
55
+ 'georgian',
56
+ 'hebrew',
24
57
  ]);
25
-
26
58
  function unwrapNamespace(str) {
27
- if (/^["']/.test(str)) {
28
- return unquote(str);
29
- } else if (/^url\(.*\)$/i.test(str)) {
30
- return unquote(str.replace(/^url\((.*)\)$/i, '$1'));
31
- } else {
32
- throw new Error(`Cannot parse CSS namespace: ${str}`);
33
- }
59
+ if (/^["']/.test(str)) {
60
+ return unquote(str);
61
+ }
62
+ else if (/^url\(.*\)$/i.test(str)) {
63
+ return unquote(str.replace(/^url\((.*)\)$/i, '$1'));
64
+ }
65
+ else {
66
+ throw new Error(`Cannot parse CSS namespace: ${str}`);
67
+ }
34
68
  }
35
-
36
69
  // Build a collision-free fingerprint for a CSS rule entry. Null bytes (\0)
37
70
  // delimit fields because they cannot appear in CSS property values.
38
71
  function ruleFingerprint(rule) {
39
- const predicateEntries = Object.keys(rule.predicates)
40
- .sort()
41
- .map((k) => `${k}=${rule.predicates[k]}`);
42
- return [
43
- rule.selector,
44
- rule.value,
45
- rule.prop,
46
- rule.important,
47
- (rule.specificityArray || []).join(','),
48
- rule.namespaceURI,
49
- predicateEntries.join('&'),
50
- ].join('\0');
72
+ const predicateEntries = Object.keys(rule.predicates)
73
+ .sort()
74
+ .map((k) => `${k}=${rule.predicates[k]}`);
75
+ return [
76
+ rule.selector,
77
+ rule.value,
78
+ rule.prop,
79
+ rule.important,
80
+ (rule.specificityArray || []).join(','),
81
+ rule.namespaceURI,
82
+ predicateEntries.join('&'),
83
+ ].join('\0');
51
84
  }
52
-
53
85
  // Remove fully-duplicate rule entries (same selector, value, specificity,
54
86
  // predicates, namespace, and importance) within each property.
55
87
  function deduplicateRules(rulesByProperty) {
56
- for (const key of Object.keys(rulesByProperty)) {
57
- if (key === 'counterStyles' || key === 'keyframes') continue;
58
- const rules = rulesByProperty[key];
59
- if (rules.length <= 1) continue;
60
- const seen = new Set();
61
- rulesByProperty[key] = rules.filter((rule) => {
62
- const fp = ruleFingerprint(rule);
63
- if (seen.has(fp)) return false;
64
- seen.add(fp);
65
- return true;
66
- });
67
- }
88
+ for (const key of Object.keys(rulesByProperty)) {
89
+ if (key === 'counterStyles' || key === 'keyframes')
90
+ continue;
91
+ const rules = rulesByProperty[key];
92
+ if (rules.length <= 1)
93
+ continue;
94
+ const seen = new Set();
95
+ rulesByProperty[key] = rules.filter((rule) => {
96
+ const fp = ruleFingerprint(rule);
97
+ if (seen.has(fp))
98
+ return false;
99
+ seen.add(fp);
100
+ return true;
101
+ });
102
+ }
68
103
  }
69
-
70
104
  function getCssRulesByProperty(properties, cssSource, existingPredicates) {
71
- if (!Array.isArray(properties)) {
72
- throw new Error('properties argument must be an array');
73
- }
74
- if (typeof cssSource !== 'string') {
75
- throw new Error('cssSource argument must be a string containing valid CSS');
76
- }
77
- existingPredicates = existingPredicates || {};
78
-
79
- const parseTree = postcss.parse(cssSource);
80
- let defaultNamespaceURI;
81
- const namespacePrefixes = new Map();
82
- // Parse @namespace rules: either a default namespace or a prefixed one.
83
- // Spec: https://developer.mozilla.org/en-US/docs/Web/CSS/@namespace
84
- // Grammar: @namespace <prefix>? [<string> | url(<uri>)]
85
- parseTree.walkAtRules('namespace', (rule) => {
86
- const match = rule.params.match(
87
- /^(?<prefix>\w+)\s+(?<uri>.+)$|^(?<defaultUri>.+)$/
88
- );
89
- if (!match) return;
90
- const { prefix, uri, defaultUri } = match.groups;
91
- if (prefix) {
92
- namespacePrefixes.set(prefix, unwrapNamespace(uri));
93
- } else {
94
- defaultNamespaceURI = unwrapNamespace(defaultUri);
95
- }
96
- });
97
- const rulesByProperty = {
98
- counterStyles: [],
99
- keyframes: [],
100
- };
101
-
102
- for (const property of properties) {
103
- rulesByProperty[property] = [];
104
- }
105
-
106
- // Resolve the namespace URI for a selector by examining its subject
107
- // (the rightmost compound selector) for a namespace prefix like svg|text.
108
- function resolveNamespaceURI(selector) {
109
- if (namespacePrefixes.size === 0) {
110
- return defaultNamespaceURI;
111
- }
112
- // Find the subject (rightmost simple selector before pseudo-elements).
113
- // Split on combinators: whitespace, >, +, ~
114
- const compoundSelectors = selector.split(/\s*[>+~]\s*|\s+/);
115
- const subject = compoundSelectors[compoundSelectors.length - 1];
116
- // Check for namespace prefix: prefix|element, *|element, or |element
117
- const nsMatch = subject.match(/^(?<nsPrefix>\*|\w*)\|/);
118
- if (!nsMatch) {
119
- return defaultNamespaceURI;
120
- }
121
- const prefix = nsMatch.groups.nsPrefix;
122
- if (prefix === '*') {
123
- // *|element matches any namespace — no namespace filter
124
- return undefined;
125
- }
126
- if (prefix === '') {
127
- // |element means no namespace (elements not in any namespace)
128
- return '';
129
- }
130
- return namespacePrefixes.get(prefix) || defaultNamespaceURI;
131
- }
132
-
133
- const specificityCache = new Map();
134
- function getSpecificity(selector) {
135
- let cached = specificityCache.get(selector);
136
- if (!cached) {
137
- cached = specificity.calculate(selector);
138
- specificityCache.set(selector, cached);
139
- }
140
- return cached;
141
- }
142
-
143
- const activeCssQueryPredicates = [];
144
- function getCurrentPredicates() {
145
- if (activeCssQueryPredicates.length > 0) {
146
- const predicates = { ...existingPredicates };
147
- for (const predicate of activeCssQueryPredicates) {
148
- predicates[predicate] = true;
149
- }
150
- return predicates;
151
- } else {
152
- return existingPredicates;
153
- }
154
- }
155
-
156
- function pushRulePerSelector(node, prop, value) {
157
- getSpecificity(node.parent.selector).forEach((specificityObject) => {
158
- const isStyleAttribute = specificityObject.selector === 'bogusselector';
159
- const selectorStr = isStyleAttribute
160
- ? undefined
161
- : specificityObject.selector.trim();
162
- (rulesByProperty[prop] = rulesByProperty[prop] || []).push({
163
- predicates: getCurrentPredicates(),
164
- namespaceURI: isStyleAttribute
165
- ? defaultNamespaceURI
166
- : resolveNamespaceURI(selectorStr),
167
- selector: selectorStr,
168
- specificityArray: isStyleAttribute
169
- ? [1, 0, 0, 0]
170
- : specificityObject.specificityArray,
171
- prop,
172
- value,
173
- important: !!node.important,
174
- });
105
+ const initialPredicates = existingPredicates || {};
106
+ const parseTree = postcss.parse(cssSource);
107
+ let defaultNamespaceURI;
108
+ const namespacePrefixes = new Map();
109
+ // Parse @namespace rules: either a default namespace or a prefixed one.
110
+ parseTree.walkAtRules('namespace', (rule) => {
111
+ const match = rule.params.match(/^(?<prefix>\w+)\s+(?<uri>.+)$|^(?<defaultUri>.+)$/);
112
+ if (!match || !match.groups)
113
+ return;
114
+ const { prefix, uri, defaultUri } = match.groups;
115
+ if (prefix) {
116
+ namespacePrefixes.set(prefix, unwrapNamespace(uri));
117
+ }
118
+ else {
119
+ defaultNamespaceURI = unwrapNamespace(defaultUri);
120
+ }
175
121
  });
176
- }
177
-
178
- (function visit(node) {
179
- // Check for selector. We might be in an at-rule like @font-face
180
- if (node.type === 'decl' && node.parent.selector) {
181
- const isCustomProperty = /^--/.test(node.prop);
182
- const propName = isCustomProperty ? node.prop : node.prop.toLowerCase(); // Custom properties ARE case sensitive
183
- if (isCustomProperty || properties.includes(propName)) {
184
- pushRulePerSelector(node, propName, node.value);
185
- } else if (
186
- propName === 'list-style' &&
187
- properties.includes('list-style-type')
188
- ) {
189
- let listStyleType;
190
- for (const valueNode of postcssValueParser(node.value).nodes) {
191
- if (valueNode.type === 'string') {
192
- listStyleType = valueNode.value;
193
- } else if (
194
- valueNode.type === 'word' &&
195
- counterRendererNames.has(valueNode.value)
196
- ) {
197
- listStyleType = valueNode.value;
198
- }
122
+ const rulesByProperty = {
123
+ counterStyles: [],
124
+ keyframes: [],
125
+ };
126
+ for (const property of properties) {
127
+ rulesByProperty[property] = [];
128
+ }
129
+ // Resolve the namespace URI for a selector by examining its subject
130
+ // (the rightmost compound selector) for a namespace prefix like svg|text.
131
+ function resolveNamespaceURI(selector) {
132
+ if (namespacePrefixes.size === 0) {
133
+ return defaultNamespaceURI;
199
134
  }
200
-
201
- if (typeof listStyleType !== 'undefined') {
202
- pushRulePerSelector(node, 'list-style-type', listStyleType);
135
+ const compoundSelectors = selector.split(/\s*[>+~]\s*|\s+/);
136
+ const subject = compoundSelectors[compoundSelectors.length - 1];
137
+ const nsMatch = subject.match(/^(?<nsPrefix>\*|\w*)\|/);
138
+ if (!nsMatch || !nsMatch.groups) {
139
+ return defaultNamespaceURI;
203
140
  }
204
- } else if (propName === 'animation') {
205
- const parsedAnimation = parseAnimationShorthand.parseSingle(
206
- node.value
207
- ).value;
208
-
209
- if (properties.includes('animation-name')) {
210
- pushRulePerSelector(node, 'animation-name', parsedAnimation.name);
141
+ const prefix = nsMatch.groups.nsPrefix;
142
+ if (prefix === '*') {
143
+ return undefined;
211
144
  }
212
- if (properties.includes('animation-timing-function')) {
213
- pushRulePerSelector(
214
- node,
215
- 'animation-timing-function',
216
- parseAnimationShorthand.serialize({
217
- name: '',
218
- timingFunction: parsedAnimation.timingFunction,
219
- })
220
- );
145
+ if (prefix === '') {
146
+ return '';
221
147
  }
222
- } else if (propName === 'transition') {
223
- // Use postcss-value-parser — regex split breaks on commas inside cubic-bezier() etc.
224
- const transitionProperties = [];
225
- const transitionDurations = [];
226
- const parsed = postcssValueParser(node.value);
227
- let currentItem = [];
228
- for (const valueNode of parsed.nodes) {
229
- if (valueNode.type === 'div' && valueNode.value === ',') {
230
- if (currentItem.length > 0) {
231
- transitionProperties.push(currentItem[0]);
232
- }
233
- if (currentItem.length > 1) {
234
- transitionDurations.push(currentItem[1]);
148
+ return namespacePrefixes.get(prefix) || defaultNamespaceURI;
149
+ }
150
+ const specificityCache = new Map();
151
+ function getSpecificity(selector) {
152
+ let cached = specificityCache.get(selector);
153
+ if (!cached) {
154
+ cached = specificity.calculate(selector);
155
+ specificityCache.set(selector, cached);
156
+ }
157
+ return cached;
158
+ }
159
+ const activeCssQueryPredicates = [];
160
+ function getCurrentPredicates() {
161
+ if (activeCssQueryPredicates.length > 0) {
162
+ const predicates = { ...initialPredicates };
163
+ for (const predicate of activeCssQueryPredicates) {
164
+ predicates[predicate] = true;
235
165
  }
236
- currentItem = [];
237
- } else if (valueNode.type !== 'space') {
238
- currentItem.push(postcssValueParser.stringify(valueNode));
239
- }
166
+ return predicates;
240
167
  }
241
- if (currentItem.length > 0) {
242
- transitionProperties.push(currentItem[0]);
168
+ else {
169
+ return initialPredicates;
243
170
  }
244
- if (currentItem.length > 1) {
245
- transitionDurations.push(currentItem[1]);
171
+ }
172
+ function pushRulePerSelector(node, prop, value) {
173
+ const parent = node.parent;
174
+ getSpecificity(parent.selector).forEach((specificityObject) => {
175
+ const isStyleAttribute = specificityObject.selector === 'bogusselector';
176
+ const selectorStr = isStyleAttribute
177
+ ? undefined
178
+ : specificityObject.selector.trim();
179
+ const list = (rulesByProperty[prop] = (rulesByProperty[prop] ||
180
+ []));
181
+ list.push({
182
+ predicates: getCurrentPredicates(),
183
+ namespaceURI: isStyleAttribute
184
+ ? defaultNamespaceURI
185
+ : resolveNamespaceURI(selectorStr),
186
+ selector: selectorStr,
187
+ specificityArray: isStyleAttribute
188
+ ? [1, 0, 0, 0]
189
+ : specificityObject.specificityArray,
190
+ prop,
191
+ value,
192
+ important: !!node.important,
193
+ });
194
+ });
195
+ }
196
+ (function visit(node) {
197
+ // Check for selector. We might be in an at-rule like @font-face
198
+ if (node.type === 'decl' && node.parent && node.parent.type === 'rule') {
199
+ const isCustomProperty = /^--/.test(node.prop);
200
+ const propName = isCustomProperty ? node.prop : node.prop.toLowerCase(); // Custom properties ARE case sensitive
201
+ if (isCustomProperty || properties.includes(propName)) {
202
+ pushRulePerSelector(node, propName, node.value);
203
+ }
204
+ else if (propName === 'list-style' &&
205
+ properties.includes('list-style-type')) {
206
+ let listStyleType;
207
+ for (const valueNode of postcssValueParser(node.value).nodes) {
208
+ if (valueNode.type === 'string') {
209
+ listStyleType = valueNode.value;
210
+ }
211
+ else if (valueNode.type === 'word' &&
212
+ counterRendererNames.has(valueNode.value)) {
213
+ listStyleType = valueNode.value;
214
+ }
215
+ }
216
+ if (typeof listStyleType !== 'undefined') {
217
+ pushRulePerSelector(node, 'list-style-type', listStyleType);
218
+ }
219
+ }
220
+ else if (propName === 'animation') {
221
+ const parsedAnimation = parseAnimationShorthand.parseSingle(node.value).value;
222
+ if (properties.includes('animation-name')) {
223
+ pushRulePerSelector(node, 'animation-name', parsedAnimation.name);
224
+ }
225
+ if (properties.includes('animation-timing-function')) {
226
+ pushRulePerSelector(node, 'animation-timing-function', parseAnimationShorthand.serialize({
227
+ name: '',
228
+ timingFunction: parsedAnimation.timingFunction,
229
+ }));
230
+ }
231
+ }
232
+ else if (propName === 'transition') {
233
+ const transitionProperties = [];
234
+ const transitionDurations = [];
235
+ const parsed = postcssValueParser(node.value);
236
+ let currentItem = [];
237
+ for (const valueNode of parsed.nodes) {
238
+ if (valueNode.type === 'div' && valueNode.value === ',') {
239
+ if (currentItem.length > 0) {
240
+ transitionProperties.push(currentItem[0]);
241
+ }
242
+ if (currentItem.length > 1) {
243
+ transitionDurations.push(currentItem[1]);
244
+ }
245
+ currentItem = [];
246
+ }
247
+ else if (valueNode.type !== 'space') {
248
+ currentItem.push(postcssValueParser.stringify(valueNode));
249
+ }
250
+ }
251
+ if (currentItem.length > 0) {
252
+ transitionProperties.push(currentItem[0]);
253
+ }
254
+ if (currentItem.length > 1) {
255
+ transitionDurations.push(currentItem[1]);
256
+ }
257
+ if (properties.includes('transition-property')) {
258
+ pushRulePerSelector(node, 'transition-property', transitionProperties.join(', '));
259
+ }
260
+ if (properties.includes('transition-duration')) {
261
+ pushRulePerSelector(node, 'transition-duration', transitionDurations.join(', '));
262
+ }
263
+ }
264
+ else if (propName === 'font') {
265
+ const fontLonghands = [
266
+ 'font-family',
267
+ 'font-weight',
268
+ 'font-size',
269
+ 'font-style',
270
+ ].filter((prop) => properties.includes(prop));
271
+ if (fontLonghands.length > 0) {
272
+ const fontParent = node.parent;
273
+ getSpecificity(fontParent.selector).forEach((specificityObject) => {
274
+ const isStyleAttribute = specificityObject.selector === 'bogusselector';
275
+ const fontSelector = isStyleAttribute
276
+ ? undefined
277
+ : specificityObject.selector.trim();
278
+ const entry = {
279
+ predicates: getCurrentPredicates(),
280
+ namespaceURI: isStyleAttribute
281
+ ? defaultNamespaceURI
282
+ : resolveNamespaceURI(fontSelector),
283
+ selector: fontSelector,
284
+ specificityArray: isStyleAttribute
285
+ ? [1, 0, 0, 0]
286
+ : specificityObject.specificityArray,
287
+ prop: 'font',
288
+ value: node.value,
289
+ important: !!node.important,
290
+ };
291
+ for (const prop of fontLonghands) {
292
+ rulesByProperty[prop].push(entry);
293
+ }
294
+ });
295
+ }
296
+ }
246
297
  }
247
-
248
- if (properties.includes('transition-property')) {
249
- pushRulePerSelector(
250
- node,
251
- 'transition-property',
252
- transitionProperties.join(', ')
253
- );
298
+ else if (node.type === 'atrule' &&
299
+ node.name.toLowerCase() === 'counter-style') {
300
+ const props = {};
301
+ for (const childNode of node.nodes ?? []) {
302
+ if (childNode.type === 'decl') {
303
+ props[childNode.prop] = childNode.value;
304
+ }
305
+ }
306
+ rulesByProperty.counterStyles.push({
307
+ name: node.params,
308
+ predicates: getCurrentPredicates(),
309
+ props,
310
+ });
254
311
  }
255
- if (properties.includes('transition-duration')) {
256
- pushRulePerSelector(
257
- node,
258
- 'transition-duration',
259
- transitionDurations.join(', ')
260
- );
312
+ else if (node.type === 'atrule' &&
313
+ node.name.toLowerCase() === 'keyframes') {
314
+ rulesByProperty.keyframes.push({
315
+ name: node.params,
316
+ namespaceURI: defaultNamespaceURI,
317
+ predicates: getCurrentPredicates(),
318
+ node,
319
+ });
320
+ return;
261
321
  }
262
- } else if (propName === 'font') {
263
- const fontLonghands = [
264
- 'font-family',
265
- 'font-weight',
266
- 'font-size',
267
- 'font-style',
268
- ].filter((prop) => properties.includes(prop));
269
- if (fontLonghands.length > 0) {
270
- getSpecificity(node.parent.selector).forEach((specificityObject) => {
271
- const isStyleAttribute =
272
- specificityObject.selector === 'bogusselector';
273
- const fontSelector = isStyleAttribute
274
- ? undefined
275
- : specificityObject.selector.trim();
276
- const entry = {
277
- predicates: getCurrentPredicates(),
278
- namespaceURI: isStyleAttribute
279
- ? defaultNamespaceURI
280
- : resolveNamespaceURI(fontSelector),
281
- selector: fontSelector,
282
- specificityArray: isStyleAttribute
283
- ? [1, 0, 0, 0]
284
- : specificityObject.specificityArray,
285
- prop: 'font',
286
- value: node.value,
287
- important: !!node.important,
288
- };
289
- for (const prop of fontLonghands) {
290
- rulesByProperty[prop].push(entry);
322
+ const containerNodes = node.nodes;
323
+ if (containerNodes) {
324
+ let popAfter = false;
325
+ if (node.type === 'atrule') {
326
+ const name = node.name.toLowerCase();
327
+ if (name === 'media' || name === 'supports') {
328
+ activeCssQueryPredicates.push(`${name}Query:${node.params}`);
329
+ popAfter = true;
330
+ }
331
+ }
332
+ for (const childNode of containerNodes) {
333
+ visit(childNode);
334
+ }
335
+ if (popAfter) {
336
+ activeCssQueryPredicates.pop();
291
337
  }
292
- });
293
- }
294
- }
295
- } else if (
296
- node.type === 'atrule' &&
297
- node.name.toLowerCase() === 'counter-style'
298
- ) {
299
- const props = {};
300
- for (const childNode of node.nodes) {
301
- props[childNode.prop] = childNode.value;
302
- }
303
- rulesByProperty.counterStyles.push({
304
- name: node.params,
305
- predicates: getCurrentPredicates(),
306
- props,
307
- });
308
- } else if (
309
- node.type === 'atrule' &&
310
- node.name.toLowerCase() === 'keyframes'
311
- ) {
312
- rulesByProperty.keyframes.push({
313
- name: node.params,
314
- namespaceURI: defaultNamespaceURI,
315
- predicates: getCurrentPredicates(),
316
- node,
317
- });
318
- return;
319
- }
320
-
321
- if (node.nodes) {
322
- let popAfter = false;
323
- if (node.type === 'atrule') {
324
- const name = node.name.toLowerCase();
325
- if (name === 'media' || name === 'supports') {
326
- activeCssQueryPredicates.push(`${name}Query:${node.params}`);
327
- popAfter = true;
328
338
  }
329
- }
330
- for (const childNode of node.nodes) {
331
- visit(childNode);
332
- }
333
- if (popAfter) {
334
- activeCssQueryPredicates.pop();
335
- }
336
- }
337
- })(parseTree);
338
-
339
- deduplicateRules(rulesByProperty);
340
-
341
- return rulesByProperty;
339
+ })(parseTree);
340
+ deduplicateRules(rulesByProperty);
341
+ return rulesByProperty;
342
342
  }
343
-
344
343
  module.exports = getCssRulesByProperty;
344
+ //# sourceMappingURL=getCssRulesByProperty.js.map