@navecss/core 0.2.0 → 0.4.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/ATOMS.md +1 -1
- package/CONSUMER-ATOMS.md +41 -8
- package/LICENSE +36 -0
- package/README.md +611 -46
- package/dist/atom-names-2OreuBx9.d.ts +27 -0
- package/dist/atomic.css +3 -1
- package/dist/atoms.d.ts +10 -14
- package/dist/atoms.js +2 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +453 -0
- package/dist/check.d.ts +31 -0
- package/dist/check.js +11 -0
- package/dist/chunk-2A7IUZBH.js +31 -0
- package/dist/{chunk-BVON7XKC.js → chunk-CUL5PLPI.js} +8 -6
- package/dist/chunk-E5F6YF7A.js +2428 -0
- package/dist/chunk-GZL2VW7C.js +57 -0
- package/dist/chunk-LADFXRWQ.js +1089 -0
- package/dist/chunk-LQSGQ2OA.js +94 -0
- package/dist/chunk-NFS2REPQ.js +747 -0
- package/dist/chunk-NKUZNRF4.js +42 -0
- package/dist/chunk-SYNQJNVB.js +302 -0
- package/dist/chunk-UANF3FGO.js +115 -0
- package/dist/chunk-XQQCDUV6.js +152 -0
- package/dist/collect.d.ts +279 -0
- package/dist/collect.js +4 -0
- package/dist/cx.d.ts +23 -4
- package/dist/cx.js +19 -1
- package/dist/lightningcss.d.ts +51 -0
- package/dist/lightningcss.js +44 -0
- package/dist/no-tokens.css +7 -7
- package/dist/postcss.cjs +1 -0
- package/dist/postcss.d.cts +2 -0
- package/dist/postcss.d.ts +30 -15
- package/dist/postcss.js +237 -243
- package/dist/standalone.css +1139 -0
- package/dist/vite-options-D1-hGA9L.d.ts +86 -0
- package/dist/vite.d.ts +368 -0
- package/dist/vite.js +3318 -0
- package/package.json +55 -17
- package/skills/navecss/SKILL.md +7 -2
package/dist/postcss.js
CHANGED
|
@@ -1,314 +1,308 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveExtendSpecifier, applyExtendModule } from './chunk-NKUZNRF4.js';
|
|
2
|
+
import { snapshotExtendMap, walkExtendAtoms, foldLocated, anchorSelectorList, plan, WORKAROUND_GROUP_AT_RULE_NAMES } from './chunk-LADFXRWQ.js';
|
|
3
|
+
import { tokenize } from './chunk-NFS2REPQ.js';
|
|
4
|
+
import { formatDiagnostic } from './chunk-SYNQJNVB.js';
|
|
5
|
+
import './chunk-CUL5PLPI.js';
|
|
6
|
+
import './chunk-GZL2VW7C.js';
|
|
2
7
|
import postcss from 'postcss';
|
|
3
8
|
|
|
4
|
-
// src/
|
|
5
|
-
function
|
|
6
|
-
return
|
|
9
|
+
// src/postcss-nested-builders.ts
|
|
10
|
+
function isNestedNode(node) {
|
|
11
|
+
return node.type === "rule" || node.type === "atrule" && node.name.toLowerCase() !== "nave";
|
|
7
12
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
state.isEscaped = true;
|
|
19
|
-
return true;
|
|
13
|
+
function isFollowingNestedNode(rule, atRule) {
|
|
14
|
+
return rule.nodes.slice(0, rule.index(atRule)).some((node) => isNestedNode(node));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/postcss-node-utils.ts
|
|
18
|
+
function isInsideKeyframes(container) {
|
|
19
|
+
let node = container;
|
|
20
|
+
while (node) {
|
|
21
|
+
if (node.type === "atrule" && /keyframes$/i.test(node.name)) return true;
|
|
22
|
+
node = node.parent;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
if (text[index] === state.quote) state.quote = void 0;
|
|
23
|
-
return true;
|
|
24
|
+
return false;
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
if (char === '"' || char === "'") {
|
|
29
|
-
state.quote = char;
|
|
26
|
+
function hasWorkaroundSentence(refusedParent) {
|
|
27
|
+
if (refusedParent.type !== "atrule") return false;
|
|
28
|
+
if (!WORKAROUND_GROUP_AT_RULE_NAMES.has(refusedParent.name.toLowerCase())) {
|
|
30
29
|
return false;
|
|
31
30
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (isInsideKeyframes(refusedParent)) return false;
|
|
32
|
+
let current = refusedParent.parent;
|
|
33
|
+
while (current) {
|
|
34
|
+
if (current.type === "rule") return true;
|
|
35
|
+
current = current.parent;
|
|
35
36
|
}
|
|
36
|
-
return
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function stampSource(node, source) {
|
|
40
|
+
if (!source) return;
|
|
41
|
+
node.source = source;
|
|
42
|
+
node.walk((child) => {
|
|
43
|
+
child.source = source;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/postcss-at-rule.ts
|
|
48
|
+
function currentParams(atRule) {
|
|
49
|
+
const raw = atRule.raws.params;
|
|
50
|
+
if (raw?.value === atRule.params) return raw.raw;
|
|
51
|
+
return atRule.params;
|
|
37
52
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
|
|
53
|
+
function matchNaveAtRule(atRule) {
|
|
54
|
+
const afterName = atRule.raws.afterName ?? " ";
|
|
55
|
+
const paramsRaw = currentParams(atRule);
|
|
56
|
+
const nameBoundary = 1 + atRule.name.length;
|
|
57
|
+
const full = `@${atRule.name}${afterName}${paramsRaw}`;
|
|
58
|
+
const token = tokenize(full)[0];
|
|
59
|
+
const commonPrelude = { prelude: paramsRaw, preludeStartIndex: nameBoundary + afterName.length };
|
|
60
|
+
if (token?.type !== "at-keyword-token") return { isNave: false, ...commonPrelude };
|
|
61
|
+
const isNave = (token.structured?.value).toLowerCase() === "nave";
|
|
62
|
+
if (token.endIndex === nameBoundary) return { isNave, ...commonPrelude };
|
|
63
|
+
return { isNave, prelude: full.slice(token.endIndex), preludeStartIndex: token.endIndex };
|
|
41
64
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
branches.push(selectorList.slice(start, index));
|
|
54
|
-
start = index + 1;
|
|
65
|
+
function atRuleErrorIndex(preludeStartIndex, diagnostic) {
|
|
66
|
+
if (diagnostic.code !== "unknown-atom" && diagnostic.code !== "bad-token") return void 0;
|
|
67
|
+
return preludeStartIndex + diagnostic.offset;
|
|
68
|
+
}
|
|
69
|
+
function reportDiagnostic(diagnostic, ctx, preludeStartIndex) {
|
|
70
|
+
const refusedParent = ctx.atRule.parent;
|
|
71
|
+
const isNestedGroup = diagnostic.code === "bad-parent" && refusedParent !== void 0 && hasWorkaroundSentence(refusedParent);
|
|
72
|
+
const text = formatDiagnostic(
|
|
73
|
+
isNestedGroup ? { ...diagnostic, detail: "nested-group" } : diagnostic,
|
|
74
|
+
{
|
|
75
|
+
extend: ctx.extend
|
|
55
76
|
}
|
|
77
|
+
);
|
|
78
|
+
const index = atRuleErrorIndex(preludeStartIndex, diagnostic);
|
|
79
|
+
if (ctx.onUnknown === "warn") {
|
|
80
|
+
ctx.atRule.warn(ctx.result, text, index === void 0 ? {} : { index });
|
|
81
|
+
return;
|
|
56
82
|
}
|
|
57
|
-
|
|
83
|
+
if (ctx.onUnknown === "ignore") return;
|
|
84
|
+
ctx.fold.push({ atRule: ctx.atRule, text, index });
|
|
58
85
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
86
|
+
function declNode(atRule, decl) {
|
|
87
|
+
const node = postcss.decl({ prop: decl.prop, value: decl.value });
|
|
88
|
+
if (atRule.source) node.source = atRule.source;
|
|
89
|
+
return node;
|
|
61
90
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
91
|
+
function insertDeclarations(atRule, declarations, isWrapped) {
|
|
92
|
+
if (declarations.length === 0) return;
|
|
93
|
+
if (!isWrapped) {
|
|
94
|
+
for (const decl of declarations) atRule.before(declNode(atRule, decl));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const wrapper = postcss.rule({ selector: "&" });
|
|
98
|
+
if (atRule.source) wrapper.source = atRule.source;
|
|
99
|
+
for (const decl of declarations) wrapper.append(declNode(atRule, decl));
|
|
100
|
+
atRule.before(wrapper);
|
|
72
101
|
}
|
|
73
|
-
|
|
74
|
-
// src/postcss-nested-builders.ts
|
|
75
|
-
var DIRECTIVE = "nave";
|
|
76
|
-
function buildNestedRule(selector, decls) {
|
|
102
|
+
function buildRule(selector, declarations) {
|
|
77
103
|
const rule = postcss.rule({ selector });
|
|
78
|
-
for (const
|
|
79
|
-
rule.append(postcss.decl({ prop, value }));
|
|
80
|
-
}
|
|
104
|
+
for (const decl of declarations) rule.append(postcss.decl({ prop: decl.prop, value: decl.value }));
|
|
81
105
|
return rule;
|
|
82
106
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
);
|
|
107
|
+
function buildAppendedNode(block) {
|
|
108
|
+
if (block.kind === "pseudo") return buildRule(block.selector, block.declarations);
|
|
109
|
+
const node = postcss.atRule({ name: block.kind, params: block.condition });
|
|
110
|
+
if (block.declarations.length > 0) node.append(buildRule("&", block.declarations));
|
|
111
|
+
for (const pseudo of block.pseudos) node.append(buildRule(pseudo.selector, pseudo.declarations));
|
|
112
|
+
return node;
|
|
87
113
|
}
|
|
88
|
-
function
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
if (block.pseudos) rules.push(...buildPseudoRules(block.pseudos));
|
|
92
|
-
return rules;
|
|
114
|
+
function throwMalformedAtom(atRule, error) {
|
|
115
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
116
|
+
throw atRule.error(message);
|
|
93
117
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
function planAtRule(atRule, extend, prelude) {
|
|
119
|
+
const parent = atRule.parent;
|
|
120
|
+
const isStyleRuleParent = parent?.type === "rule";
|
|
121
|
+
const isFollowingNestedNodeHere = isStyleRuleParent ? isFollowingNestedNode(parent, atRule) : false;
|
|
122
|
+
try {
|
|
123
|
+
return {
|
|
124
|
+
isStyleRuleParent,
|
|
125
|
+
parent,
|
|
126
|
+
result: plan(
|
|
127
|
+
prelude,
|
|
128
|
+
{
|
|
129
|
+
isStyleRuleParent,
|
|
130
|
+
isInsideKeyframes: parent !== void 0 && isInsideKeyframes(parent),
|
|
131
|
+
isFollowingNestedNode: isFollowingNestedNodeHere
|
|
132
|
+
},
|
|
133
|
+
{ extend }
|
|
134
|
+
)
|
|
135
|
+
};
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return throwMalformedAtom(atRule, error);
|
|
138
|
+
}
|
|
100
139
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
140
|
+
function hasBlock(atRule) {
|
|
141
|
+
return atRule.nodes !== void 0;
|
|
142
|
+
}
|
|
143
|
+
function handleAtRule(atRule, ctx) {
|
|
144
|
+
const match = matchNaveAtRule(atRule);
|
|
145
|
+
if (!match.isNave) return;
|
|
146
|
+
const fullCtx = { ...ctx, atRule };
|
|
147
|
+
const {
|
|
148
|
+
isStyleRuleParent,
|
|
149
|
+
parent,
|
|
150
|
+
result: planResult
|
|
151
|
+
} = planAtRule(atRule, ctx.extend, match.prelude);
|
|
152
|
+
for (const diagnostic of planResult.diagnostics) {
|
|
153
|
+
reportDiagnostic(diagnostic, fullCtx, match.preludeStartIndex);
|
|
154
|
+
}
|
|
155
|
+
if (hasBlock(atRule)) {
|
|
156
|
+
reportDiagnostic(
|
|
157
|
+
{ code: "has-block", offset: 0, endOffset: atRule.toString().length },
|
|
158
|
+
fullCtx,
|
|
159
|
+
match.preludeStartIndex
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
insertDeclarations(atRule, planResult.declarations, planResult.wrapInAmpersand);
|
|
163
|
+
atRule.remove();
|
|
164
|
+
if (isStyleRuleParent && parent) {
|
|
165
|
+
for (const block of planResult.blocks) {
|
|
166
|
+
const node = buildAppendedNode(block);
|
|
167
|
+
stampSource(node, atRule.source);
|
|
168
|
+
parent.append(node);
|
|
109
169
|
}
|
|
110
170
|
}
|
|
111
|
-
return nodes;
|
|
112
171
|
}
|
|
113
|
-
|
|
114
|
-
|
|
172
|
+
|
|
173
|
+
// src/postcss-fold.ts
|
|
174
|
+
function positionOf(entry, fallbackLine) {
|
|
175
|
+
if (!entry.atRule.source) return { column: 0, line: fallbackLine };
|
|
176
|
+
return entry.atRule.positionBy(entry.index === void 0 ? {} : { index: entry.index });
|
|
115
177
|
}
|
|
116
|
-
function
|
|
117
|
-
return
|
|
178
|
+
function sortFoldBySourceOrder(entries) {
|
|
179
|
+
return entries.map((entry, originalIndex) => ({ entry, originalIndex })).toSorted((a, b) => {
|
|
180
|
+
const pa = positionOf(a.entry, a.originalIndex);
|
|
181
|
+
const pb = positionOf(b.entry, b.originalIndex);
|
|
182
|
+
return pa.line - pb.line || pa.column - pb.column;
|
|
183
|
+
}).map(({ entry }) => entry);
|
|
118
184
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
185
|
+
function foldMessage(entries) {
|
|
186
|
+
return foldLocated(
|
|
187
|
+
entries.map((entry, i) => {
|
|
188
|
+
const position = positionOf(entry, i);
|
|
189
|
+
return { text: entry.text, line: position.line, column: position.column };
|
|
190
|
+
})
|
|
191
|
+
);
|
|
128
192
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
node.source = source;
|
|
132
|
-
node.walk((child) => {
|
|
133
|
-
child.source = source;
|
|
134
|
-
});
|
|
193
|
+
function unescapeHtml(text) {
|
|
194
|
+
return text.replaceAll(/\\3c (?=\/?style\b|!--)/gi, "<");
|
|
135
195
|
}
|
|
136
|
-
function
|
|
137
|
-
return
|
|
196
|
+
function compact(text) {
|
|
197
|
+
return text.replaceAll(/\s+/g, "");
|
|
138
198
|
}
|
|
139
|
-
function
|
|
199
|
+
function declarationRefusal(prop, value) {
|
|
140
200
|
let root;
|
|
141
201
|
try {
|
|
142
202
|
root = postcss.parse(`a{${prop}:${value}}`);
|
|
143
203
|
} catch {
|
|
144
|
-
return
|
|
204
|
+
return "break-out";
|
|
145
205
|
}
|
|
146
|
-
if (root.nodes.length !== 1) return
|
|
206
|
+
if (root.nodes.length !== 1) return "break-out";
|
|
147
207
|
const rule = root.nodes[0];
|
|
148
|
-
if (rule.type !== "rule" || rule.nodes.length !== 1) return
|
|
208
|
+
if (rule.type !== "rule" || rule.nodes.length !== 1) return "break-out";
|
|
149
209
|
const decl = rule.nodes[0];
|
|
150
|
-
if (decl.type !== "decl") return
|
|
151
|
-
|
|
210
|
+
if (decl.type !== "decl" || decl.prop !== prop) return "break-out";
|
|
211
|
+
const given = `${prop}:${value}`;
|
|
212
|
+
const written = decl.toString();
|
|
213
|
+
if (written === given.trimEnd()) return void 0;
|
|
214
|
+
return compact(unescapeHtml(written)) === compact(given) ? "rewritten" : "break-out";
|
|
152
215
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
216
|
+
function propRefusal(prop) {
|
|
217
|
+
return declarationRefusal(prop, "0");
|
|
155
218
|
}
|
|
156
|
-
function
|
|
219
|
+
function selectorRefusal(key) {
|
|
157
220
|
let selector;
|
|
158
221
|
try {
|
|
159
222
|
selector = anchorSelectorList(key);
|
|
160
223
|
} catch {
|
|
161
|
-
return
|
|
224
|
+
return "break-out";
|
|
162
225
|
}
|
|
163
226
|
let root;
|
|
164
227
|
try {
|
|
165
228
|
root = postcss.parse(`${selector}{}`);
|
|
166
229
|
} catch {
|
|
167
|
-
return
|
|
230
|
+
return "break-out";
|
|
168
231
|
}
|
|
169
|
-
if (root.nodes.length !== 1) return
|
|
232
|
+
if (root.nodes.length !== 1) return "break-out";
|
|
170
233
|
const rule = root.nodes[0];
|
|
171
|
-
|
|
234
|
+
const isOneEmptyRule = rule.type === "rule" && rule.selector === selector;
|
|
235
|
+
return isOneEmptyRule && rule.nodes.length === 0 ? void 0 : "break-out";
|
|
172
236
|
}
|
|
173
|
-
function
|
|
237
|
+
function conditionRefusal(atName, condition) {
|
|
174
238
|
let root;
|
|
175
239
|
try {
|
|
176
240
|
root = postcss.parse(`@${atName} ${condition}{}`);
|
|
177
241
|
} catch {
|
|
178
|
-
return
|
|
242
|
+
return "break-out";
|
|
179
243
|
}
|
|
180
|
-
if (root.nodes.length !== 1) return
|
|
244
|
+
if (root.nodes.length !== 1) return "break-out";
|
|
181
245
|
const node = root.nodes[0];
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
function fail(describedAs, value) {
|
|
185
|
-
throw new Error(
|
|
186
|
-
`navePlugin({ extend }): ${describedAs} does not parse as a single CSS declaration, selector or condition, and would break out of the rule it is spliced into: ${JSON.stringify(value)}. extend is trusted, consumer-authored code, not sanitised input \u2014 fix the atom definition.`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
function assertDeclarationsSafe(declarations, where) {
|
|
190
|
-
if (!isPlainObject(declarations)) return;
|
|
191
|
-
for (const [prop, value] of Object.entries(declarations)) {
|
|
192
|
-
if (typeof prop === "string" && !isPropValid(prop)) {
|
|
193
|
-
fail(`${where}'s declaration property "${prop}"`, prop);
|
|
194
|
-
}
|
|
195
|
-
if (typeof value === "string" && !isDeclarationValid(prop, value)) {
|
|
196
|
-
fail(`${where}'s declaration value for "${prop}"`, value);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function assertPseudosSafe(pseudos, where) {
|
|
201
|
-
if (!isPlainObject(pseudos)) return;
|
|
202
|
-
for (const [pseudo, declarations] of Object.entries(pseudos)) {
|
|
203
|
-
if (!isSelectorValid(pseudo)) fail(`${where}'s pseudo "${pseudo}"`, pseudo);
|
|
204
|
-
assertDeclarationsSafe(declarations, `${where}'s pseudo "${pseudo}"`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function assertAtBlocksSafe(blocks, atName, where) {
|
|
208
|
-
if (!isPlainObject(blocks)) return;
|
|
209
|
-
for (const [condition, block] of Object.entries(blocks)) {
|
|
210
|
-
if (!isConditionValid(atName, condition))
|
|
211
|
-
fail(`${where}'s ${atName} condition "${condition}"`, condition);
|
|
212
|
-
if (!isPlainObject(block)) continue;
|
|
213
|
-
const blockWhere = `${where}'s ${atName} "${condition}"`;
|
|
214
|
-
assertDeclarationsSafe(block.declarations, blockWhere);
|
|
215
|
-
assertPseudosSafe(block.pseudos, blockWhere);
|
|
246
|
+
if (node.type !== "atrule" || node.name !== atName || (node.nodes?.length ?? 0) !== 0) {
|
|
247
|
+
return "break-out";
|
|
216
248
|
}
|
|
249
|
+
if (node.params === condition.trim()) return void 0;
|
|
250
|
+
return compact(node.params) === compact(condition) ? "rewritten" : "break-out";
|
|
217
251
|
}
|
|
218
252
|
function validateExtendAtoms(extend) {
|
|
219
|
-
|
|
220
|
-
if (!atom) continue;
|
|
221
|
-
const where = `atom "${name}"`;
|
|
222
|
-
assertDeclarationsSafe(atom.declarations, where);
|
|
223
|
-
assertPseudosSafe(atom.pseudos, where);
|
|
224
|
-
assertAtBlocksSafe(atom.media, "media", where);
|
|
225
|
-
assertAtBlocksSafe(atom.container, "container", where);
|
|
226
|
-
}
|
|
253
|
+
walkExtendAtoms(extend, { declarationRefusal, propRefusal, selectorRefusal, conditionRefusal });
|
|
227
254
|
}
|
|
228
255
|
|
|
229
256
|
// src/postcss.ts
|
|
230
|
-
function reportUnknown(msg, ctx) {
|
|
231
|
-
const { atRule, onUnknown, result } = ctx;
|
|
232
|
-
if (onUnknown === "warn") {
|
|
233
|
-
atRule.warn(result, msg);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (onUnknown === "ignore") return;
|
|
237
|
-
throw atRule.error(msg);
|
|
238
|
-
}
|
|
239
|
-
function checkUnknownAtoms(names, validAtomNames, ctx) {
|
|
240
|
-
if (names.length === 0) {
|
|
241
|
-
reportUnknown("@nave: directive names no atom", ctx);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
for (const name of names) {
|
|
245
|
-
if (validAtomNames.has(name)) continue;
|
|
246
|
-
reportUnknown(
|
|
247
|
-
`@nave: unknown atom "${name}". Available: ${[...validAtomNames].join(", ")}`,
|
|
248
|
-
ctx
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function insertDeclarations(atRule, declNodes, isFollowingNested) {
|
|
253
|
-
if (declNodes.length === 0) return;
|
|
254
|
-
if (!isFollowingNested) {
|
|
255
|
-
for (const decl of declNodes) atRule.before(decl);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const wrapper = postcss.rule({ selector: "&" });
|
|
259
|
-
if (atRule.source) wrapper.source = atRule.source;
|
|
260
|
-
for (const decl of declNodes) wrapper.append(decl);
|
|
261
|
-
atRule.before(wrapper);
|
|
262
|
-
}
|
|
263
257
|
var navePlugin = (options = {}) => {
|
|
264
|
-
const { onUnknown = "error", extend
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
);
|
|
258
|
+
const { onUnknown = "error", extend: extendOption } = options;
|
|
259
|
+
const extendFile = typeof extendOption === "string" ? resolveExtendSpecifier(extendOption) : void 0;
|
|
260
|
+
const staticExtend = typeof extendOption === "object" ? snapshotExtendMap(extendOption) : {};
|
|
261
|
+
validateExtendAtoms(staticExtend);
|
|
262
|
+
const loadCache = /* @__PURE__ */ new Map();
|
|
270
263
|
return {
|
|
271
264
|
postcssPlugin: "postcss-nave",
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
265
|
+
// Per-run state lives here, not in the factory closure above: PostCSS
|
|
266
|
+
// calls `prepare(result)` once per `Result`, so two stylesheets sharing
|
|
267
|
+
// one `navePlugin()` instance never share a `fold` or a resolved
|
|
268
|
+
// `extend`, however their async hooks interleave (otherwise one
|
|
269
|
+
// stylesheet's problems, or its loaded `extend`, could leak into another's).
|
|
270
|
+
prepare(result) {
|
|
271
|
+
const fold = [];
|
|
272
|
+
let extend = staticExtend;
|
|
273
|
+
return {
|
|
274
|
+
Once() {
|
|
275
|
+
fold.length = 0;
|
|
276
|
+
if (extendFile === void 0) return;
|
|
277
|
+
result.messages.push({
|
|
278
|
+
type: "dependency",
|
|
279
|
+
plugin: "postcss-nave",
|
|
280
|
+
file: extendFile,
|
|
281
|
+
parent: result.opts.from
|
|
282
|
+
});
|
|
283
|
+
return applyExtendModule(extendFile, loadCache, (value) => {
|
|
284
|
+
const snapshot = snapshotExtendMap(value);
|
|
285
|
+
validateExtendAtoms(snapshot);
|
|
286
|
+
extend = snapshot;
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
AtRule(atRule) {
|
|
290
|
+
handleAtRule(atRule, { onUnknown, result, extend, fold });
|
|
291
|
+
},
|
|
292
|
+
OnceExit() {
|
|
293
|
+
if (fold.length === 0) return;
|
|
294
|
+
const ordered = sortFoldBySourceOrder(fold);
|
|
295
|
+
const first = ordered[0];
|
|
296
|
+
throw first.atRule.error(
|
|
297
|
+
foldMessage(ordered),
|
|
298
|
+
first.index === void 0 ? {} : { index: first.index }
|
|
299
|
+
);
|
|
300
300
|
}
|
|
301
|
-
|
|
302
|
-
});
|
|
303
|
-
insertDeclarations(atRule, declNodes, isFollowingNestedNode(rule, atRule));
|
|
304
|
-
atRule.remove();
|
|
305
|
-
for (const node of nested) {
|
|
306
|
-
stampSource(node, atRule.source);
|
|
307
|
-
rule.append(node);
|
|
308
|
-
}
|
|
301
|
+
};
|
|
309
302
|
}
|
|
310
303
|
};
|
|
311
304
|
};
|
|
312
305
|
navePlugin.postcss = true;
|
|
306
|
+
var postcss_default = navePlugin;
|
|
313
307
|
|
|
314
|
-
export { navePlugin };
|
|
308
|
+
export { postcss_default as default, navePlugin };
|