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