@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.
- package/CLAUDE.md +39 -13
- package/README.md +24 -14
- package/lib/FontTracerPool.d.ts +38 -0
- package/lib/FontTracerPool.d.ts.map +1 -0
- package/lib/FontTracerPool.js +230 -217
- package/lib/FontTracerPool.js.map +1 -0
- package/lib/HeadlessBrowser.d.ts +18 -0
- package/lib/HeadlessBrowser.d.ts.map +1 -0
- package/lib/HeadlessBrowser.js +216 -210
- package/lib/HeadlessBrowser.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +15 -12
- package/lib/cli.js.map +1 -0
- package/lib/codepointMaps.d.ts +4 -0
- package/lib/codepointMaps.d.ts.map +1 -0
- package/lib/codepointMaps.js +99 -0
- package/lib/codepointMaps.js.map +1 -0
- package/lib/collectFeatureGlyphIds.d.ts +3 -0
- package/lib/collectFeatureGlyphIds.d.ts.map +1 -0
- package/lib/collectFeatureGlyphIds.js +124 -138
- package/lib/collectFeatureGlyphIds.js.map +1 -0
- package/lib/collectTextsByPage.d.ts +41 -0
- package/lib/collectTextsByPage.d.ts.map +1 -0
- package/lib/collectTextsByPage.js +726 -965
- package/lib/collectTextsByPage.js.map +1 -0
- package/lib/concurrencyLimit.d.ts +3 -0
- package/lib/concurrencyLimit.d.ts.map +1 -0
- package/lib/concurrencyLimit.js +12 -11
- package/lib/concurrencyLimit.js.map +1 -0
- package/lib/escapeJsStringLiteral.d.ts +3 -0
- package/lib/escapeJsStringLiteral.d.ts.map +1 -0
- package/lib/escapeJsStringLiteral.js +7 -6
- package/lib/escapeJsStringLiteral.js.map +1 -0
- package/lib/extractReferencedCustomPropertyNames.d.ts +3 -0
- package/lib/extractReferencedCustomPropertyNames.d.ts.map +1 -0
- package/lib/extractReferencedCustomPropertyNames.js +15 -16
- package/lib/extractReferencedCustomPropertyNames.js.map +1 -0
- package/lib/extractVisibleText.d.ts +7 -0
- package/lib/extractVisibleText.d.ts.map +1 -0
- package/lib/extractVisibleText.js +110 -119
- package/lib/extractVisibleText.js.map +1 -0
- package/lib/findCustomPropertyDefinitions.d.ts +8 -0
- package/lib/findCustomPropertyDefinitions.d.ts.map +1 -0
- package/lib/findCustomPropertyDefinitions.js +41 -48
- package/lib/findCustomPropertyDefinitions.js.map +1 -0
- package/lib/fontConverter.d.ts +2 -0
- package/lib/fontConverter.d.ts.map +1 -0
- package/lib/fontConverter.js +40 -21
- package/lib/fontConverter.js.map +1 -0
- package/lib/fontConverterWorker.d.ts +2 -0
- package/lib/fontConverterWorker.d.ts.map +1 -0
- package/lib/fontConverterWorker.js +52 -15
- package/lib/fontConverterWorker.js.map +1 -0
- package/lib/fontFaceHelpers.d.ts +64 -0
- package/lib/fontFaceHelpers.d.ts.map +1 -0
- package/lib/fontFaceHelpers.js +237 -249
- package/lib/fontFaceHelpers.js.map +1 -0
- package/lib/fontFeatureHelpers.d.ts +30 -0
- package/lib/fontFeatureHelpers.d.ts.map +1 -0
- package/lib/fontFeatureHelpers.js +277 -212
- package/lib/fontFeatureHelpers.js.map +1 -0
- package/lib/fontTracerWorker.d.ts +11 -0
- package/lib/fontTracerWorker.d.ts.map +1 -0
- package/lib/fontTracerWorker.js +94 -60
- package/lib/fontTracerWorker.js.map +1 -0
- package/lib/gatherStylesheetsWithPredicates.d.ts +26 -0
- package/lib/gatherStylesheetsWithPredicates.d.ts.map +1 -0
- package/lib/gatherStylesheetsWithPredicates.js +75 -84
- package/lib/gatherStylesheetsWithPredicates.js.map +1 -0
- package/lib/getCssRulesByProperty.d.ts +29 -0
- package/lib/getCssRulesByProperty.d.ts.map +1 -0
- package/lib/getCssRulesByProperty.js +316 -316
- package/lib/getCssRulesByProperty.js.map +1 -0
- package/lib/getFontInfo.d.ts +11 -0
- package/lib/getFontInfo.d.ts.map +1 -0
- package/lib/getFontInfo.js +31 -33
- package/lib/getFontInfo.js.map +1 -0
- package/lib/initialValueByProp.d.ts +3 -0
- package/lib/initialValueByProp.d.ts.map +1 -0
- package/lib/initialValueByProp.js +20 -17
- package/lib/initialValueByProp.js.map +1 -0
- package/lib/injectSubsetDefinitions.d.ts +3 -0
- package/lib/injectSubsetDefinitions.d.ts.map +1 -0
- package/lib/injectSubsetDefinitions.js +55 -59
- package/lib/injectSubsetDefinitions.js.map +1 -0
- package/lib/normalizeFontPropertyValue.d.ts +3 -0
- package/lib/normalizeFontPropertyValue.d.ts.map +1 -0
- package/lib/normalizeFontPropertyValue.js +59 -54
- package/lib/normalizeFontPropertyValue.js.map +1 -0
- package/lib/parseCommandLineOptions.d.ts +9 -0
- package/lib/parseCommandLineOptions.d.ts.map +1 -0
- package/lib/parseCommandLineOptions.js +145 -149
- package/lib/parseCommandLineOptions.js.map +1 -0
- package/lib/parseFontVariationSettings.d.ts +3 -0
- package/lib/parseFontVariationSettings.d.ts.map +1 -0
- package/lib/parseFontVariationSettings.js +38 -36
- package/lib/parseFontVariationSettings.js.map +1 -0
- package/lib/progress.d.ts +27 -0
- package/lib/progress.d.ts.map +1 -0
- package/lib/progress.js +51 -54
- package/lib/progress.js.map +1 -0
- package/lib/sfntCache.d.ts +4 -0
- package/lib/sfntCache.d.ts.map +1 -0
- package/lib/sfntCache.js +67 -25
- package/lib/sfntCache.js.map +1 -0
- package/lib/stripLocalTokens.d.ts +3 -0
- package/lib/stripLocalTokens.d.ts.map +1 -0
- package/lib/stripLocalTokens.js +23 -21
- package/lib/stripLocalTokens.js.map +1 -0
- package/lib/subfont.d.ts +54 -0
- package/lib/subfont.d.ts.map +1 -0
- package/lib/subfont.js +531 -629
- package/lib/subfont.js.map +1 -0
- package/lib/subsetFontWithGlyphs.d.ts +21 -0
- package/lib/subsetFontWithGlyphs.d.ts.map +1 -0
- package/lib/subsetFontWithGlyphs.js +285 -259
- package/lib/subsetFontWithGlyphs.js.map +1 -0
- package/lib/subsetFonts.d.ts +55 -0
- package/lib/subsetFonts.d.ts.map +1 -0
- package/lib/subsetFonts.js +899 -1200
- package/lib/subsetFonts.js.map +1 -0
- package/lib/subsetGeneration.d.ts +36 -0
- package/lib/subsetGeneration.d.ts.map +1 -0
- package/lib/subsetGeneration.js +328 -325
- package/lib/subsetGeneration.js.map +1 -0
- package/lib/types/shared.d.ts +11 -0
- package/lib/types/shared.d.ts.map +1 -0
- package/lib/types/shared.js +3 -0
- package/lib/types/shared.js.map +1 -0
- package/lib/unicodeRange.d.ts +3 -0
- package/lib/unicodeRange.d.ts.map +1 -0
- package/lib/unicodeRange.js +17 -30
- package/lib/unicodeRange.js.map +1 -0
- package/lib/unquote.d.ts +3 -0
- package/lib/unquote.d.ts.map +1 -0
- package/lib/unquote.js +18 -25
- package/lib/unquote.js.map +1 -0
- package/lib/variationAxes.d.ts +33 -0
- package/lib/variationAxes.d.ts.map +1 -0
- package/lib/variationAxes.js +127 -157
- package/lib/variationAxes.js.map +1 -0
- package/lib/warnAboutMissingGlyphs.d.ts +43 -0
- package/lib/warnAboutMissingGlyphs.d.ts.map +1 -0
- package/lib/warnAboutMissingGlyphs.js +139 -147
- package/lib/warnAboutMissingGlyphs.js.map +1 -0
- package/lib/wasmQueue.d.ts +3 -0
- package/lib/wasmQueue.d.ts.map +1 -0
- package/lib/wasmQueue.js +13 -10
- package/lib/wasmQueue.js.map +1 -0
- package/package.json +12 -2
|
@@ -1,344 +1,344 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
202
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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 (
|
|
213
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
237
|
-
} else if (valueNode.type !== 'space') {
|
|
238
|
-
currentItem.push(postcssValueParser.stringify(valueNode));
|
|
239
|
-
}
|
|
166
|
+
return predicates;
|
|
240
167
|
}
|
|
241
|
-
|
|
242
|
-
|
|
168
|
+
else {
|
|
169
|
+
return initialPredicates;
|
|
243
170
|
}
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
node
|
|
251
|
-
|
|
252
|
-
|
|
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 (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
331
|
-
|
|
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
|