vite 6.0.0-beta.2 → 6.0.0-beta.4

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.
@@ -0,0 +1,1099 @@
1
+ import { L as getDefaultExportFromCjs } from './dep-Cpgpmu8-.js';
2
+ import require$$0$1 from 'path';
3
+ import require$$0 from 'fs';
4
+ import { r as requireLib } from './dep-mtw2NpNs.js';
5
+
6
+ import { createRequire as __cjs_createRequire } from 'node:module';
7
+
8
+ const require = __cjs_createRequire(import.meta.url);
9
+ const __require = require;
10
+ function _mergeNamespaces(n, m) {
11
+ for (var i = 0; i < m.length; i++) {
12
+ var e = m[i];
13
+ if (typeof e !== 'string' && !Array.isArray(e)) { for (var k in e) {
14
+ if (k !== 'default' && !(k in n)) {
15
+ n[k] = e[k];
16
+ }
17
+ } }
18
+ }
19
+ return n;
20
+ }
21
+
22
+ var formatImportPrelude;
23
+ var hasRequiredFormatImportPrelude;
24
+
25
+ function requireFormatImportPrelude () {
26
+ if (hasRequiredFormatImportPrelude) return formatImportPrelude;
27
+ hasRequiredFormatImportPrelude = 1;
28
+
29
+ formatImportPrelude = function formatImportPrelude(layer, media, supports) {
30
+ const parts = [];
31
+
32
+ if (typeof layer !== "undefined") {
33
+ let layerParams = "layer";
34
+ if (layer) {
35
+ layerParams = `layer(${layer})`;
36
+ }
37
+
38
+ parts.push(layerParams);
39
+ }
40
+
41
+ if (typeof supports !== "undefined") {
42
+ parts.push(`supports(${supports})`);
43
+ }
44
+
45
+ if (typeof media !== "undefined") {
46
+ parts.push(media);
47
+ }
48
+
49
+ return parts.join(" ")
50
+ };
51
+ return formatImportPrelude;
52
+ }
53
+
54
+ var base64EncodedImport;
55
+ var hasRequiredBase64EncodedImport;
56
+
57
+ function requireBase64EncodedImport () {
58
+ if (hasRequiredBase64EncodedImport) return base64EncodedImport;
59
+ hasRequiredBase64EncodedImport = 1;
60
+
61
+ const formatImportPrelude = requireFormatImportPrelude();
62
+
63
+ // Base64 encode an import with conditions
64
+ // The order of conditions is important and is interleaved with cascade layer declarations
65
+ // Each group of conditions and cascade layers needs to be interpreted in order
66
+ // To achieve this we create a list of base64 encoded imports, where each import contains a stylesheet with another import.
67
+ // Each import can define a single group of conditions and a single cascade layer.
68
+ base64EncodedImport = function base64EncodedConditionalImport(prelude, conditions) {
69
+ conditions.reverse();
70
+ const first = conditions.pop();
71
+ let params = `${prelude} ${formatImportPrelude(
72
+ first.layer,
73
+ first.media,
74
+ first.supports,
75
+ )}`;
76
+
77
+ for (const condition of conditions) {
78
+ params = `'data:text/css;base64,${Buffer.from(`@import ${params}`).toString(
79
+ "base64",
80
+ )}' ${formatImportPrelude(
81
+ condition.layer,
82
+ condition.media,
83
+ condition.supports,
84
+ )}`;
85
+ }
86
+
87
+ return params
88
+ };
89
+ return base64EncodedImport;
90
+ }
91
+
92
+ var applyConditions;
93
+ var hasRequiredApplyConditions;
94
+
95
+ function requireApplyConditions () {
96
+ if (hasRequiredApplyConditions) return applyConditions;
97
+ hasRequiredApplyConditions = 1;
98
+
99
+ const base64EncodedConditionalImport = requireBase64EncodedImport();
100
+
101
+ applyConditions = function applyConditions(bundle, atRule) {
102
+ bundle.forEach(stmt => {
103
+ if (
104
+ stmt.type === "charset" ||
105
+ stmt.type === "warning" ||
106
+ !stmt.conditions?.length
107
+ ) {
108
+ return
109
+ }
110
+
111
+ if (stmt.type === "import") {
112
+ stmt.node.params = base64EncodedConditionalImport(
113
+ stmt.fullUri,
114
+ stmt.conditions,
115
+ );
116
+ return
117
+ }
118
+
119
+ const { nodes } = stmt;
120
+ const { parent } = nodes[0];
121
+
122
+ const atRules = [];
123
+
124
+ // Convert conditions to at-rules
125
+ for (const condition of stmt.conditions) {
126
+ if (typeof condition.media !== "undefined") {
127
+ const mediaNode = atRule({
128
+ name: "media",
129
+ params: condition.media,
130
+ source: parent.source,
131
+ });
132
+
133
+ atRules.push(mediaNode);
134
+ }
135
+
136
+ if (typeof condition.supports !== "undefined") {
137
+ const supportsNode = atRule({
138
+ name: "supports",
139
+ params: `(${condition.supports})`,
140
+ source: parent.source,
141
+ });
142
+
143
+ atRules.push(supportsNode);
144
+ }
145
+
146
+ if (typeof condition.layer !== "undefined") {
147
+ const layerNode = atRule({
148
+ name: "layer",
149
+ params: condition.layer,
150
+ source: parent.source,
151
+ });
152
+
153
+ atRules.push(layerNode);
154
+ }
155
+ }
156
+
157
+ // Add nodes to AST
158
+ const outerAtRule = atRules.shift();
159
+ const innerAtRule = atRules.reduce((previous, next) => {
160
+ previous.append(next);
161
+ return next
162
+ }, outerAtRule);
163
+
164
+ parent.insertBefore(nodes[0], outerAtRule);
165
+
166
+ // remove nodes
167
+ nodes.forEach(node => {
168
+ node.parent = undefined;
169
+ });
170
+
171
+ // better output
172
+ nodes[0].raws.before = nodes[0].raws.before || "\n";
173
+
174
+ // wrap new rules with media query and/or layer at rule
175
+ innerAtRule.append(nodes);
176
+
177
+ stmt.type = "nodes";
178
+ stmt.nodes = [outerAtRule];
179
+ delete stmt.node;
180
+ });
181
+ };
182
+ return applyConditions;
183
+ }
184
+
185
+ var applyRaws;
186
+ var hasRequiredApplyRaws;
187
+
188
+ function requireApplyRaws () {
189
+ if (hasRequiredApplyRaws) return applyRaws;
190
+ hasRequiredApplyRaws = 1;
191
+
192
+ applyRaws = function applyRaws(bundle) {
193
+ bundle.forEach((stmt, index) => {
194
+ if (index === 0) return
195
+
196
+ if (stmt.parent) {
197
+ const { before } = stmt.parent.node.raws;
198
+ if (stmt.type === "nodes") stmt.nodes[0].raws.before = before;
199
+ else stmt.node.raws.before = before;
200
+ } else if (stmt.type === "nodes") {
201
+ stmt.nodes[0].raws.before = stmt.nodes[0].raws.before || "\n";
202
+ }
203
+ });
204
+ };
205
+ return applyRaws;
206
+ }
207
+
208
+ var applyStyles;
209
+ var hasRequiredApplyStyles;
210
+
211
+ function requireApplyStyles () {
212
+ if (hasRequiredApplyStyles) return applyStyles;
213
+ hasRequiredApplyStyles = 1;
214
+
215
+ applyStyles = function applyStyles(bundle, styles) {
216
+ styles.nodes = [];
217
+
218
+ // Strip additional statements.
219
+ bundle.forEach(stmt => {
220
+ if (["charset", "import"].includes(stmt.type)) {
221
+ stmt.node.parent = undefined;
222
+ styles.append(stmt.node);
223
+ } else if (stmt.type === "nodes") {
224
+ stmt.nodes.forEach(node => {
225
+ node.parent = undefined;
226
+ styles.append(node);
227
+ });
228
+ }
229
+ });
230
+ };
231
+ return applyStyles;
232
+ }
233
+
234
+ var readCache = {exports: {}};
235
+
236
+ var pify = {exports: {}};
237
+
238
+ var hasRequiredPify;
239
+
240
+ function requirePify () {
241
+ if (hasRequiredPify) return pify.exports;
242
+ hasRequiredPify = 1;
243
+
244
+ var processFn = function (fn, P, opts) {
245
+ return function () {
246
+ var that = this;
247
+ var args = new Array(arguments.length);
248
+
249
+ for (var i = 0; i < arguments.length; i++) {
250
+ args[i] = arguments[i];
251
+ }
252
+
253
+ return new P(function (resolve, reject) {
254
+ args.push(function (err, result) {
255
+ if (err) {
256
+ reject(err);
257
+ } else if (opts.multiArgs) {
258
+ var results = new Array(arguments.length - 1);
259
+
260
+ for (var i = 1; i < arguments.length; i++) {
261
+ results[i - 1] = arguments[i];
262
+ }
263
+
264
+ resolve(results);
265
+ } else {
266
+ resolve(result);
267
+ }
268
+ });
269
+
270
+ fn.apply(that, args);
271
+ });
272
+ };
273
+ };
274
+
275
+ var pify$1 = pify.exports = function (obj, P, opts) {
276
+ if (typeof P !== 'function') {
277
+ opts = P;
278
+ P = Promise;
279
+ }
280
+
281
+ opts = opts || {};
282
+ opts.exclude = opts.exclude || [/.+Sync$/];
283
+
284
+ var filter = function (key) {
285
+ var match = function (pattern) {
286
+ return typeof pattern === 'string' ? key === pattern : pattern.test(key);
287
+ };
288
+
289
+ return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
290
+ };
291
+
292
+ var ret = typeof obj === 'function' ? function () {
293
+ if (opts.excludeMain) {
294
+ return obj.apply(this, arguments);
295
+ }
296
+
297
+ return processFn(obj, P, opts).apply(this, arguments);
298
+ } : {};
299
+
300
+ return Object.keys(obj).reduce(function (ret, key) {
301
+ var x = obj[key];
302
+
303
+ ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
304
+
305
+ return ret;
306
+ }, ret);
307
+ };
308
+
309
+ pify$1.all = pify$1;
310
+ return pify.exports;
311
+ }
312
+
313
+ var hasRequiredReadCache;
314
+
315
+ function requireReadCache () {
316
+ if (hasRequiredReadCache) return readCache.exports;
317
+ hasRequiredReadCache = 1;
318
+ var fs = require$$0;
319
+ var path = require$$0$1;
320
+ var pify = requirePify();
321
+
322
+ var stat = pify(fs.stat);
323
+ var readFile = pify(fs.readFile);
324
+ var resolve = path.resolve;
325
+
326
+ var cache = Object.create(null);
327
+
328
+ function convert(content, encoding) {
329
+ if (Buffer.isEncoding(encoding)) {
330
+ return content.toString(encoding);
331
+ }
332
+ return content;
333
+ }
334
+
335
+ readCache.exports = function (path, encoding) {
336
+ path = resolve(path);
337
+
338
+ return stat(path).then(function (stats) {
339
+ var item = cache[path];
340
+
341
+ if (item && item.mtime.getTime() === stats.mtime.getTime()) {
342
+ return convert(item.content, encoding);
343
+ }
344
+
345
+ return readFile(path).then(function (data) {
346
+ cache[path] = {
347
+ mtime: stats.mtime,
348
+ content: data
349
+ };
350
+
351
+ return convert(data, encoding);
352
+ });
353
+ }).catch(function (err) {
354
+ cache[path] = null;
355
+ return Promise.reject(err);
356
+ });
357
+ };
358
+
359
+ readCache.exports.sync = function (path, encoding) {
360
+ path = resolve(path);
361
+
362
+ try {
363
+ var stats = fs.statSync(path);
364
+ var item = cache[path];
365
+
366
+ if (item && item.mtime.getTime() === stats.mtime.getTime()) {
367
+ return convert(item.content, encoding);
368
+ }
369
+
370
+ var data = fs.readFileSync(path);
371
+
372
+ cache[path] = {
373
+ mtime: stats.mtime,
374
+ content: data
375
+ };
376
+
377
+ return convert(data, encoding);
378
+ } catch (err) {
379
+ cache[path] = null;
380
+ throw err;
381
+ }
382
+
383
+ };
384
+
385
+ readCache.exports.get = function (path, encoding) {
386
+ path = resolve(path);
387
+ if (cache[path]) {
388
+ return convert(cache[path].content, encoding);
389
+ }
390
+ return null;
391
+ };
392
+
393
+ readCache.exports.clear = function () {
394
+ cache = Object.create(null);
395
+ };
396
+ return readCache.exports;
397
+ }
398
+
399
+ var dataUrl;
400
+ var hasRequiredDataUrl;
401
+
402
+ function requireDataUrl () {
403
+ if (hasRequiredDataUrl) return dataUrl;
404
+ hasRequiredDataUrl = 1;
405
+
406
+ const anyDataURLRegexp = /^data:text\/css(?:;(base64|plain))?,/i;
407
+ const base64DataURLRegexp = /^data:text\/css;base64,/i;
408
+ const plainDataURLRegexp = /^data:text\/css;plain,/i;
409
+
410
+ function isValid(url) {
411
+ return anyDataURLRegexp.test(url)
412
+ }
413
+
414
+ function contents(url) {
415
+ if (base64DataURLRegexp.test(url)) {
416
+ // "data:text/css;base64,".length === 21
417
+ return Buffer.from(url.slice(21), "base64").toString()
418
+ }
419
+
420
+ if (plainDataURLRegexp.test(url)) {
421
+ // "data:text/css;plain,".length === 20
422
+ return decodeURIComponent(url.slice(20))
423
+ }
424
+
425
+ // "data:text/css,".length === 14
426
+ return decodeURIComponent(url.slice(14))
427
+ }
428
+
429
+ dataUrl = {
430
+ isValid,
431
+ contents,
432
+ };
433
+ return dataUrl;
434
+ }
435
+
436
+ var loadContent;
437
+ var hasRequiredLoadContent;
438
+
439
+ function requireLoadContent () {
440
+ if (hasRequiredLoadContent) return loadContent;
441
+ hasRequiredLoadContent = 1;
442
+
443
+ const readCache = requireReadCache();
444
+ const dataURL = requireDataUrl();
445
+
446
+ loadContent = function loadContent(filename) {
447
+ if (dataURL.isValid(filename)) {
448
+ return dataURL.contents(filename)
449
+ }
450
+
451
+ return readCache(filename, "utf-8")
452
+ };
453
+ return loadContent;
454
+ }
455
+
456
+ var parseStatements;
457
+ var hasRequiredParseStatements;
458
+
459
+ function requireParseStatements () {
460
+ if (hasRequiredParseStatements) return parseStatements;
461
+ hasRequiredParseStatements = 1;
462
+
463
+ // external tooling
464
+ const valueParser = requireLib();
465
+
466
+ // extended tooling
467
+ const { stringify } = valueParser;
468
+
469
+ parseStatements = function parseStatements(result, styles, conditions, from) {
470
+ const statements = [];
471
+ let nodes = [];
472
+
473
+ styles.each(node => {
474
+ let stmt;
475
+ if (node.type === "atrule") {
476
+ if (node.name === "import")
477
+ stmt = parseImport(result, node, conditions, from);
478
+ else if (node.name === "charset")
479
+ stmt = parseCharset(result, node, conditions, from);
480
+ }
481
+
482
+ if (stmt) {
483
+ if (nodes.length) {
484
+ statements.push({
485
+ type: "nodes",
486
+ nodes,
487
+ conditions: [...conditions],
488
+ from,
489
+ });
490
+ nodes = [];
491
+ }
492
+ statements.push(stmt);
493
+ } else nodes.push(node);
494
+ });
495
+
496
+ if (nodes.length) {
497
+ statements.push({
498
+ type: "nodes",
499
+ nodes,
500
+ conditions: [...conditions],
501
+ from,
502
+ });
503
+ }
504
+
505
+ return statements
506
+ };
507
+
508
+ function parseCharset(result, atRule, conditions, from) {
509
+ if (atRule.prev()) {
510
+ return result.warn("@charset must precede all other statements", {
511
+ node: atRule,
512
+ })
513
+ }
514
+ return {
515
+ type: "charset",
516
+ node: atRule,
517
+ conditions: [...conditions],
518
+ from,
519
+ }
520
+ }
521
+
522
+ function parseImport(result, atRule, conditions, from) {
523
+ let prev = atRule.prev();
524
+
525
+ // `@import` statements may follow other `@import` statements.
526
+ if (prev) {
527
+ do {
528
+ if (
529
+ prev.type === "comment" ||
530
+ (prev.type === "atrule" && prev.name === "import")
531
+ ) {
532
+ prev = prev.prev();
533
+ continue
534
+ }
535
+
536
+ break
537
+ } while (prev)
538
+ }
539
+
540
+ // All `@import` statements may be preceded by `@charset` or `@layer` statements.
541
+ // But the `@import` statements must be consecutive.
542
+ if (prev) {
543
+ do {
544
+ if (
545
+ prev.type === "comment" ||
546
+ (prev.type === "atrule" &&
547
+ (prev.name === "charset" || (prev.name === "layer" && !prev.nodes)))
548
+ ) {
549
+ prev = prev.prev();
550
+ continue
551
+ }
552
+
553
+ return result.warn(
554
+ "@import must precede all other statements (besides @charset or empty @layer)",
555
+ { node: atRule },
556
+ )
557
+ } while (prev)
558
+ }
559
+
560
+ if (atRule.nodes) {
561
+ return result.warn(
562
+ "It looks like you didn't end your @import statement correctly. " +
563
+ "Child nodes are attached to it.",
564
+ { node: atRule },
565
+ )
566
+ }
567
+
568
+ const params = valueParser(atRule.params).nodes;
569
+ const stmt = {
570
+ type: "import",
571
+ uri: "",
572
+ fullUri: "",
573
+ node: atRule,
574
+ conditions: [...conditions],
575
+ from,
576
+ };
577
+
578
+ let layer;
579
+ let media;
580
+ let supports;
581
+
582
+ for (let i = 0; i < params.length; i++) {
583
+ const node = params[i];
584
+
585
+ if (node.type === "space" || node.type === "comment") continue
586
+
587
+ if (node.type === "string") {
588
+ if (stmt.uri) {
589
+ return result.warn(`Multiple url's in '${atRule.toString()}'`, {
590
+ node: atRule,
591
+ })
592
+ }
593
+
594
+ if (!node.value) {
595
+ return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
596
+ node: atRule,
597
+ })
598
+ }
599
+
600
+ stmt.uri = node.value;
601
+ stmt.fullUri = stringify(node);
602
+ continue
603
+ }
604
+
605
+ if (node.type === "function" && /^url$/i.test(node.value)) {
606
+ if (stmt.uri) {
607
+ return result.warn(`Multiple url's in '${atRule.toString()}'`, {
608
+ node: atRule,
609
+ })
610
+ }
611
+
612
+ if (!node.nodes?.[0]?.value) {
613
+ return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
614
+ node: atRule,
615
+ })
616
+ }
617
+
618
+ stmt.uri = node.nodes[0].value;
619
+ stmt.fullUri = stringify(node);
620
+ continue
621
+ }
622
+
623
+ if (!stmt.uri) {
624
+ return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
625
+ node: atRule,
626
+ })
627
+ }
628
+
629
+ if (
630
+ (node.type === "word" || node.type === "function") &&
631
+ /^layer$/i.test(node.value)
632
+ ) {
633
+ if (typeof layer !== "undefined") {
634
+ return result.warn(`Multiple layers in '${atRule.toString()}'`, {
635
+ node: atRule,
636
+ })
637
+ }
638
+
639
+ if (typeof supports !== "undefined") {
640
+ return result.warn(
641
+ `layers must be defined before support conditions in '${atRule.toString()}'`,
642
+ {
643
+ node: atRule,
644
+ },
645
+ )
646
+ }
647
+
648
+ if (node.nodes) {
649
+ layer = stringify(node.nodes);
650
+ } else {
651
+ layer = "";
652
+ }
653
+
654
+ continue
655
+ }
656
+
657
+ if (node.type === "function" && /^supports$/i.test(node.value)) {
658
+ if (typeof supports !== "undefined") {
659
+ return result.warn(
660
+ `Multiple support conditions in '${atRule.toString()}'`,
661
+ {
662
+ node: atRule,
663
+ },
664
+ )
665
+ }
666
+
667
+ supports = stringify(node.nodes);
668
+
669
+ continue
670
+ }
671
+
672
+ media = stringify(params.slice(i));
673
+ break
674
+ }
675
+
676
+ if (!stmt.uri) {
677
+ return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
678
+ node: atRule,
679
+ })
680
+ }
681
+
682
+ if (
683
+ typeof media !== "undefined" ||
684
+ typeof layer !== "undefined" ||
685
+ typeof supports !== "undefined"
686
+ ) {
687
+ stmt.conditions.push({
688
+ layer,
689
+ media,
690
+ supports,
691
+ });
692
+ }
693
+
694
+ return stmt
695
+ }
696
+ return parseStatements;
697
+ }
698
+
699
+ var processContent;
700
+ var hasRequiredProcessContent;
701
+
702
+ function requireProcessContent () {
703
+ if (hasRequiredProcessContent) return processContent;
704
+ hasRequiredProcessContent = 1;
705
+
706
+ // builtin tooling
707
+ const path = require$$0$1;
708
+
709
+ // placeholder tooling
710
+ let sugarss;
711
+
712
+ processContent = function processContent(
713
+ result,
714
+ content,
715
+ filename,
716
+ options,
717
+ postcss,
718
+ ) {
719
+ const { plugins } = options;
720
+ const ext = path.extname(filename);
721
+
722
+ const parserList = [];
723
+
724
+ // SugarSS support:
725
+ if (ext === ".sss") {
726
+ if (!sugarss) {
727
+ /* c8 ignore next 3 */
728
+ try {
729
+ sugarss = __require('sugarss');
730
+ } catch {} // Ignore
731
+ }
732
+ if (sugarss)
733
+ return runPostcss(postcss, content, filename, plugins, [sugarss])
734
+ }
735
+
736
+ // Syntax support:
737
+ if (result.opts.syntax?.parse) {
738
+ parserList.push(result.opts.syntax.parse);
739
+ }
740
+
741
+ // Parser support:
742
+ if (result.opts.parser) parserList.push(result.opts.parser);
743
+ // Try the default as a last resort:
744
+ parserList.push(null);
745
+
746
+ return runPostcss(postcss, content, filename, plugins, parserList)
747
+ };
748
+
749
+ function runPostcss(postcss, content, filename, plugins, parsers, index) {
750
+ if (!index) index = 0;
751
+ return postcss(plugins)
752
+ .process(content, {
753
+ from: filename,
754
+ parser: parsers[index],
755
+ })
756
+ .catch(err => {
757
+ // If there's an error, try the next parser
758
+ index++;
759
+ // If there are no parsers left, throw it
760
+ if (index === parsers.length) throw err
761
+ return runPostcss(postcss, content, filename, plugins, parsers, index)
762
+ })
763
+ }
764
+ return processContent;
765
+ }
766
+
767
+ var parseStyles_1;
768
+ var hasRequiredParseStyles;
769
+
770
+ function requireParseStyles () {
771
+ if (hasRequiredParseStyles) return parseStyles_1;
772
+ hasRequiredParseStyles = 1;
773
+
774
+ const path = require$$0$1;
775
+
776
+ const dataURL = requireDataUrl();
777
+ const parseStatements = requireParseStatements();
778
+ const processContent = requireProcessContent();
779
+ const resolveId = (id) => id;
780
+ const formatImportPrelude = requireFormatImportPrelude();
781
+
782
+ async function parseStyles(
783
+ result,
784
+ styles,
785
+ options,
786
+ state,
787
+ conditions,
788
+ from,
789
+ postcss,
790
+ ) {
791
+ const statements = parseStatements(result, styles, conditions, from);
792
+
793
+ for (const stmt of statements) {
794
+ if (stmt.type !== "import" || !isProcessableURL(stmt.uri)) {
795
+ continue
796
+ }
797
+
798
+ if (options.filter && !options.filter(stmt.uri)) {
799
+ // rejected by filter
800
+ continue
801
+ }
802
+
803
+ await resolveImportId(result, stmt, options, state, postcss);
804
+ }
805
+
806
+ let charset;
807
+ const imports = [];
808
+ const bundle = [];
809
+
810
+ function handleCharset(stmt) {
811
+ if (!charset) charset = stmt;
812
+ // charsets aren't case-sensitive, so convert to lower case to compare
813
+ else if (
814
+ stmt.node.params.toLowerCase() !== charset.node.params.toLowerCase()
815
+ ) {
816
+ throw stmt.node.error(
817
+ `Incompatible @charset statements:
818
+ ${stmt.node.params} specified in ${stmt.node.source.input.file}
819
+ ${charset.node.params} specified in ${charset.node.source.input.file}`,
820
+ )
821
+ }
822
+ }
823
+
824
+ // squash statements and their children
825
+ statements.forEach(stmt => {
826
+ if (stmt.type === "charset") handleCharset(stmt);
827
+ else if (stmt.type === "import") {
828
+ if (stmt.children) {
829
+ stmt.children.forEach((child, index) => {
830
+ if (child.type === "import") imports.push(child);
831
+ else if (child.type === "charset") handleCharset(child);
832
+ else bundle.push(child);
833
+ // For better output
834
+ if (index === 0) child.parent = stmt;
835
+ });
836
+ } else imports.push(stmt);
837
+ } else if (stmt.type === "nodes") {
838
+ bundle.push(stmt);
839
+ }
840
+ });
841
+
842
+ return charset ? [charset, ...imports.concat(bundle)] : imports.concat(bundle)
843
+ }
844
+
845
+ async function resolveImportId(result, stmt, options, state, postcss) {
846
+ if (dataURL.isValid(stmt.uri)) {
847
+ // eslint-disable-next-line require-atomic-updates
848
+ stmt.children = await loadImportContent(
849
+ result,
850
+ stmt,
851
+ stmt.uri,
852
+ options,
853
+ state,
854
+ postcss,
855
+ );
856
+
857
+ return
858
+ } else if (dataURL.isValid(stmt.from.slice(-1))) {
859
+ // Data urls can't be used as a base url to resolve imports.
860
+ throw stmt.node.error(
861
+ `Unable to import '${stmt.uri}' from a stylesheet that is embedded in a data url`,
862
+ )
863
+ }
864
+
865
+ const atRule = stmt.node;
866
+ let sourceFile;
867
+ if (atRule.source?.input?.file) {
868
+ sourceFile = atRule.source.input.file;
869
+ }
870
+ const base = sourceFile
871
+ ? path.dirname(atRule.source.input.file)
872
+ : options.root;
873
+
874
+ const paths = [await options.resolve(stmt.uri, base, options, atRule)].flat();
875
+
876
+ // Ensure that each path is absolute:
877
+ const resolved = await Promise.all(
878
+ paths.map(file => {
879
+ return !path.isAbsolute(file)
880
+ ? resolveId(file)
881
+ : file
882
+ }),
883
+ );
884
+
885
+ // Add dependency messages:
886
+ resolved.forEach(file => {
887
+ result.messages.push({
888
+ type: "dependency",
889
+ plugin: "postcss-import",
890
+ file,
891
+ parent: sourceFile,
892
+ });
893
+ });
894
+
895
+ const importedContent = await Promise.all(
896
+ resolved.map(file => {
897
+ return loadImportContent(result, stmt, file, options, state, postcss)
898
+ }),
899
+ );
900
+
901
+ // Merge loaded statements
902
+ // eslint-disable-next-line require-atomic-updates
903
+ stmt.children = importedContent.flat().filter(x => !!x);
904
+ }
905
+
906
+ async function loadImportContent(
907
+ result,
908
+ stmt,
909
+ filename,
910
+ options,
911
+ state,
912
+ postcss,
913
+ ) {
914
+ const atRule = stmt.node;
915
+ const { conditions, from } = stmt;
916
+ const stmtDuplicateCheckKey = conditions
917
+ .map(condition =>
918
+ formatImportPrelude(condition.layer, condition.media, condition.supports),
919
+ )
920
+ .join(":");
921
+
922
+ if (options.skipDuplicates) {
923
+ // skip files already imported at the same scope
924
+ if (state.importedFiles[filename]?.[stmtDuplicateCheckKey]) {
925
+ return
926
+ }
927
+
928
+ // save imported files to skip them next time
929
+ if (!state.importedFiles[filename]) {
930
+ state.importedFiles[filename] = {};
931
+ }
932
+ state.importedFiles[filename][stmtDuplicateCheckKey] = true;
933
+ }
934
+
935
+ if (from.includes(filename)) {
936
+ return
937
+ }
938
+
939
+ const content = await options.load(filename, options);
940
+
941
+ if (content.trim() === "" && options.warnOnEmpty) {
942
+ result.warn(`${filename} is empty`, { node: atRule });
943
+ return
944
+ }
945
+
946
+ // skip previous imported files not containing @import rules
947
+ if (
948
+ options.skipDuplicates &&
949
+ state.hashFiles[content]?.[stmtDuplicateCheckKey]
950
+ ) {
951
+ return
952
+ }
953
+
954
+ const importedResult = await processContent(
955
+ result,
956
+ content,
957
+ filename,
958
+ options,
959
+ postcss,
960
+ );
961
+
962
+ const styles = importedResult.root;
963
+ result.messages = result.messages.concat(importedResult.messages);
964
+
965
+ if (options.skipDuplicates) {
966
+ const hasImport = styles.some(child => {
967
+ return child.type === "atrule" && child.name === "import"
968
+ });
969
+ if (!hasImport) {
970
+ // save hash files to skip them next time
971
+ if (!state.hashFiles[content]) {
972
+ state.hashFiles[content] = {};
973
+ }
974
+
975
+ state.hashFiles[content][stmtDuplicateCheckKey] = true;
976
+ }
977
+ }
978
+
979
+ // recursion: import @import from imported file
980
+ return parseStyles(
981
+ result,
982
+ styles,
983
+ options,
984
+ state,
985
+ conditions,
986
+ [...from, filename],
987
+ postcss,
988
+ )
989
+ }
990
+
991
+ function isProcessableURL(uri) {
992
+ // skip protocol base uri (protocol://url) or protocol-relative
993
+ if (/^(?:[a-z]+:)?\/\//i.test(uri)) {
994
+ return false
995
+ }
996
+
997
+ // check for fragment or query
998
+ try {
999
+ // needs a base to parse properly
1000
+ const url = new URL(uri, "https://example.com");
1001
+ if (url.search) {
1002
+ return false
1003
+ }
1004
+ } catch {} // Ignore
1005
+
1006
+ return true
1007
+ }
1008
+
1009
+ parseStyles_1 = parseStyles;
1010
+ return parseStyles_1;
1011
+ }
1012
+
1013
+ var postcssImport;
1014
+ var hasRequiredPostcssImport;
1015
+
1016
+ function requirePostcssImport () {
1017
+ if (hasRequiredPostcssImport) return postcssImport;
1018
+ hasRequiredPostcssImport = 1;
1019
+ // builtin tooling
1020
+ const path = require$$0$1;
1021
+
1022
+ // internal tooling
1023
+ const applyConditions = requireApplyConditions();
1024
+ const applyRaws = requireApplyRaws();
1025
+ const applyStyles = requireApplyStyles();
1026
+ const loadContent = requireLoadContent();
1027
+ const parseStyles = requireParseStyles();
1028
+ const resolveId = (id) => id;
1029
+
1030
+ function AtImport(options) {
1031
+ options = {
1032
+ root: process.cwd(),
1033
+ path: [],
1034
+ skipDuplicates: true,
1035
+ resolve: resolveId,
1036
+ load: loadContent,
1037
+ plugins: [],
1038
+ addModulesDirectories: [],
1039
+ warnOnEmpty: true,
1040
+ ...options,
1041
+ };
1042
+
1043
+ options.root = path.resolve(options.root);
1044
+
1045
+ // convert string to an array of a single element
1046
+ if (typeof options.path === "string") options.path = [options.path];
1047
+
1048
+ if (!Array.isArray(options.path)) options.path = [];
1049
+
1050
+ options.path = options.path.map(p => path.resolve(options.root, p));
1051
+
1052
+ return {
1053
+ postcssPlugin: "postcss-import",
1054
+ async Once(styles, { result, atRule, postcss }) {
1055
+ const state = {
1056
+ importedFiles: {},
1057
+ hashFiles: {},
1058
+ };
1059
+
1060
+ if (styles.source?.input?.file) {
1061
+ state.importedFiles[styles.source.input.file] = {};
1062
+ }
1063
+
1064
+ if (options.plugins && !Array.isArray(options.plugins)) {
1065
+ throw new Error("plugins option must be an array")
1066
+ }
1067
+
1068
+ const bundle = await parseStyles(
1069
+ result,
1070
+ styles,
1071
+ options,
1072
+ state,
1073
+ [],
1074
+ [],
1075
+ postcss,
1076
+ );
1077
+
1078
+ applyRaws(bundle);
1079
+ applyConditions(bundle, atRule);
1080
+ applyStyles(bundle, styles);
1081
+ },
1082
+ }
1083
+ }
1084
+
1085
+ AtImport.postcss = true;
1086
+
1087
+ postcssImport = AtImport;
1088
+ return postcssImport;
1089
+ }
1090
+
1091
+ var postcssImportExports = requirePostcssImport();
1092
+ var index = /*@__PURE__*/getDefaultExportFromCjs(postcssImportExports);
1093
+
1094
+ var index$1 = /*#__PURE__*/_mergeNamespaces({
1095
+ __proto__: null,
1096
+ default: index
1097
+ }, [postcssImportExports]);
1098
+
1099
+ export { index$1 as i };