dep-b202fccd.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. import { E as getDefaultExportFromCjs } from './dep-a8e37fae.js';
  2. import require$$0 from 'path';
  3. import require$$0__default from 'fs';
  4. import { l as lib } from './dep-c423598f.js';
  5. import { fileURLToPath as __cjs_fileURLToPath } from 'node:url';
  6. import { dirname as __cjs_dirname } from 'node:path';
  7. import { createRequire as __cjs_createRequire } from 'node:module';
  8. const __filename = __cjs_fileURLToPath(import.meta.url);
  9. const __dirname = __cjs_dirname(__filename);
  10. const require = __cjs_createRequire(import.meta.url);
  11. const __require = require;
  12. function _mergeNamespaces(n, m) {
  13. for (var i = 0; i < m.length; i++) {
  14. var e = m[i];
  15. if (typeof e !== 'string' && !Array.isArray(e)) { for (var k in e) {
  16. if (k !== 'default' && !(k in n)) {
  17. n[k] = e[k];
  18. }
  19. } }
  20. }
  21. return n;
  22. }
  23. const startsWithKeywordRegexp = /^(all|not|only|print|screen)/i;
  24. var joinMedia$1 = function (parentMedia, childMedia) {
  25. if (!parentMedia.length && childMedia.length) return childMedia
  26. if (parentMedia.length && !childMedia.length) return parentMedia
  27. if (!parentMedia.length && !childMedia.length) return []
  28. const media = [];
  29. parentMedia.forEach(parentItem => {
  30. const parentItemStartsWithKeyword = startsWithKeywordRegexp.test(parentItem);
  31. childMedia.forEach(childItem => {
  32. const childItemStartsWithKeyword = startsWithKeywordRegexp.test(childItem);
  33. if (parentItem !== childItem) {
  34. if (childItemStartsWithKeyword && !parentItemStartsWithKeyword) {
  35. media.push(`${childItem} and ${parentItem}`);
  36. } else {
  37. media.push(`${parentItem} and ${childItem}`);
  38. }
  39. }
  40. });
  41. });
  42. return media
  43. };
  44. var joinLayer$1 = function (parentLayer, childLayer) {
  45. if (!parentLayer.length && childLayer.length) return childLayer
  46. if (parentLayer.length && !childLayer.length) return parentLayer
  47. if (!parentLayer.length && !childLayer.length) return []
  48. return parentLayer.concat(childLayer)
  49. };
  50. var readCache$1 = {exports: {}};
  51. var pify$2 = {exports: {}};
  52. var processFn = function (fn, P, opts) {
  53. return function () {
  54. var that = this;
  55. var args = new Array(arguments.length);
  56. for (var i = 0; i < arguments.length; i++) {
  57. args[i] = arguments[i];
  58. }
  59. return new P(function (resolve, reject) {
  60. args.push(function (err, result) {
  61. if (err) {
  62. reject(err);
  63. } else if (opts.multiArgs) {
  64. var results = new Array(arguments.length - 1);
  65. for (var i = 1; i < arguments.length; i++) {
  66. results[i - 1] = arguments[i];
  67. }
  68. resolve(results);
  69. } else {
  70. resolve(result);
  71. }
  72. });
  73. fn.apply(that, args);
  74. });
  75. };
  76. };
  77. var pify$1 = pify$2.exports = function (obj, P, opts) {
  78. if (typeof P !== 'function') {
  79. opts = P;
  80. P = Promise;
  81. }
  82. opts = opts || {};
  83. opts.exclude = opts.exclude || [/.+Sync$/];
  84. var filter = function (key) {
  85. var match = function (pattern) {
  86. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  87. };
  88. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  89. };
  90. var ret = typeof obj === 'function' ? function () {
  91. if (opts.excludeMain) {
  92. return obj.apply(this, arguments);
  93. }
  94. return processFn(obj, P, opts).apply(this, arguments);
  95. } : {};
  96. return Object.keys(obj).reduce(function (ret, key) {
  97. var x = obj[key];
  98. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  99. return ret;
  100. }, ret);
  101. };
  102. pify$1.all = pify$1;
  103. var pifyExports = pify$2.exports;
  104. var fs = require$$0__default;
  105. var path$2 = require$$0;
  106. var pify = pifyExports;
  107. var stat = pify(fs.stat);
  108. var readFile = pify(fs.readFile);
  109. var resolve = path$2.resolve;
  110. var cache = Object.create(null);
  111. function convert(content, encoding) {
  112. if (Buffer.isEncoding(encoding)) {
  113. return content.toString(encoding);
  114. }
  115. return content;
  116. }
  117. readCache$1.exports = function (path, encoding) {
  118. path = resolve(path);
  119. return stat(path).then(function (stats) {
  120. var item = cache[path];
  121. if (item && item.mtime.getTime() === stats.mtime.getTime()) {
  122. return convert(item.content, encoding);
  123. }
  124. return readFile(path).then(function (data) {
  125. cache[path] = {
  126. mtime: stats.mtime,
  127. content: data
  128. };
  129. return convert(data, encoding);
  130. });
  131. }).catch(function (err) {
  132. cache[path] = null;
  133. return Promise.reject(err);
  134. });
  135. };
  136. readCache$1.exports.sync = function (path, encoding) {
  137. path = resolve(path);
  138. try {
  139. var stats = fs.statSync(path);
  140. var item = cache[path];
  141. if (item && item.mtime.getTime() === stats.mtime.getTime()) {
  142. return convert(item.content, encoding);
  143. }
  144. var data = fs.readFileSync(path);
  145. cache[path] = {
  146. mtime: stats.mtime,
  147. content: data
  148. };
  149. return convert(data, encoding);
  150. } catch (err) {
  151. cache[path] = null;
  152. throw err;
  153. }
  154. };
  155. readCache$1.exports.get = function (path, encoding) {
  156. path = resolve(path);
  157. if (cache[path]) {
  158. return convert(cache[path].content, encoding);
  159. }
  160. return null;
  161. };
  162. readCache$1.exports.clear = function () {
  163. cache = Object.create(null);
  164. };
  165. var readCacheExports = readCache$1.exports;
  166. const dataURLRegexp = /^data:text\/css;base64,/i;
  167. function isValid(url) {
  168. return dataURLRegexp.test(url)
  169. }
  170. function contents(url) {
  171. // "data:text/css;base64,".length === 21
  172. return Buffer.from(url.slice(21), "base64").toString()
  173. }
  174. var dataUrl = {
  175. isValid,
  176. contents,
  177. };
  178. const readCache = readCacheExports;
  179. const dataURL$1 = dataUrl;
  180. var loadContent$1 = filename => {
  181. if (dataURL$1.isValid(filename)) {
  182. return dataURL$1.contents(filename)
  183. }
  184. return readCache(filename, "utf-8")
  185. };
  186. // builtin tooling
  187. const path$1 = require$$0;
  188. // placeholder tooling
  189. let sugarss;
  190. var processContent$1 = function processContent(
  191. result,
  192. content,
  193. filename,
  194. options,
  195. postcss
  196. ) {
  197. const { plugins } = options;
  198. const ext = path$1.extname(filename);
  199. const parserList = [];
  200. // SugarSS support:
  201. if (ext === ".sss") {
  202. if (!sugarss) {
  203. try {
  204. sugarss = __require('sugarss');
  205. } catch {} // Ignore
  206. }
  207. if (sugarss)
  208. return runPostcss(postcss, content, filename, plugins, [sugarss])
  209. }
  210. // Syntax support:
  211. if (result.opts.syntax?.parse) {
  212. parserList.push(result.opts.syntax.parse);
  213. }
  214. // Parser support:
  215. if (result.opts.parser) parserList.push(result.opts.parser);
  216. // Try the default as a last resort:
  217. parserList.push(null);
  218. return runPostcss(postcss, content, filename, plugins, parserList)
  219. };
  220. function runPostcss(postcss, content, filename, plugins, parsers, index) {
  221. if (!index) index = 0;
  222. return postcss(plugins)
  223. .process(content, {
  224. from: filename,
  225. parser: parsers[index],
  226. })
  227. .catch(err => {
  228. // If there's an error, try the next parser
  229. index++;
  230. // If there are no parsers left, throw it
  231. if (index === parsers.length) throw err
  232. return runPostcss(postcss, content, filename, plugins, parsers, index)
  233. })
  234. }
  235. // external tooling
  236. const valueParser = lib;
  237. // extended tooling
  238. const { stringify } = valueParser;
  239. function split(params, start) {
  240. const list = [];
  241. const last = params.reduce((item, node, index) => {
  242. if (index < start) return ""
  243. if (node.type === "div" && node.value === ",") {
  244. list.push(item);
  245. return ""
  246. }
  247. return item + stringify(node)
  248. }, "");
  249. list.push(last);
  250. return list
  251. }
  252. var parseStatements$1 = function (result, styles) {
  253. const statements = [];
  254. let nodes = [];
  255. styles.each(node => {
  256. let stmt;
  257. if (node.type === "atrule") {
  258. if (node.name === "import") stmt = parseImport(result, node);
  259. else if (node.name === "media") stmt = parseMedia(result, node);
  260. else if (node.name === "charset") stmt = parseCharset(result, node);
  261. }
  262. if (stmt) {
  263. if (nodes.length) {
  264. statements.push({
  265. type: "nodes",
  266. nodes,
  267. media: [],
  268. layer: [],
  269. });
  270. nodes = [];
  271. }
  272. statements.push(stmt);
  273. } else nodes.push(node);
  274. });
  275. if (nodes.length) {
  276. statements.push({
  277. type: "nodes",
  278. nodes,
  279. media: [],
  280. layer: [],
  281. });
  282. }
  283. return statements
  284. };
  285. function parseMedia(result, atRule) {
  286. const params = valueParser(atRule.params).nodes;
  287. return {
  288. type: "media",
  289. node: atRule,
  290. media: split(params, 0),
  291. layer: [],
  292. }
  293. }
  294. function parseCharset(result, atRule) {
  295. if (atRule.prev()) {
  296. return result.warn("@charset must precede all other statements", {
  297. node: atRule,
  298. })
  299. }
  300. return {
  301. type: "charset",
  302. node: atRule,
  303. media: [],
  304. layer: [],
  305. }
  306. }
  307. function parseImport(result, atRule) {
  308. let prev = atRule.prev();
  309. if (prev) {
  310. do {
  311. if (
  312. prev.type !== "comment" &&
  313. (prev.type !== "atrule" ||
  314. (prev.name !== "import" &&
  315. prev.name !== "charset" &&
  316. !(prev.name === "layer" && !prev.nodes)))
  317. ) {
  318. return result.warn(
  319. "@import must precede all other statements (besides @charset or empty @layer)",
  320. { node: atRule }
  321. )
  322. }
  323. prev = prev.prev();
  324. } while (prev)
  325. }
  326. if (atRule.nodes) {
  327. return result.warn(
  328. "It looks like you didn't end your @import statement correctly. " +
  329. "Child nodes are attached to it.",
  330. { node: atRule }
  331. )
  332. }
  333. const params = valueParser(atRule.params).nodes;
  334. const stmt = {
  335. type: "import",
  336. node: atRule,
  337. media: [],
  338. layer: [],
  339. };
  340. // prettier-ignore
  341. if (
  342. !params.length ||
  343. (
  344. params[0].type !== "string" ||
  345. !params[0].value
  346. ) &&
  347. (
  348. params[0].type !== "function" ||
  349. params[0].value !== "url" ||
  350. !params[0].nodes.length ||
  351. !params[0].nodes[0].value
  352. )
  353. ) {
  354. return result.warn(`Unable to find uri in '${ atRule.toString() }'`, {
  355. node: atRule,
  356. })
  357. }
  358. if (params[0].type === "string") stmt.uri = params[0].value;
  359. else stmt.uri = params[0].nodes[0].value;
  360. stmt.fullUri = stringify(params[0]);
  361. let remainder = params;
  362. if (remainder.length > 2) {
  363. if (
  364. (remainder[2].type === "word" || remainder[2].type === "function") &&
  365. remainder[2].value === "layer"
  366. ) {
  367. if (remainder[1].type !== "space") {
  368. return result.warn("Invalid import layer statement", { node: atRule })
  369. }
  370. if (remainder[2].nodes) {
  371. stmt.layer = [stringify(remainder[2].nodes)];
  372. } else {
  373. stmt.layer = [""];
  374. }
  375. remainder = remainder.slice(2);
  376. }
  377. }
  378. if (remainder.length > 2) {
  379. if (remainder[1].type !== "space") {
  380. return result.warn("Invalid import media statement", { node: atRule })
  381. }
  382. stmt.media = split(remainder, 2);
  383. }
  384. return stmt
  385. }
  386. var assignLayerNames$1 = function (layer, node, state, options) {
  387. layer.forEach((layerPart, i) => {
  388. if (layerPart.trim() === "") {
  389. if (options.nameLayer) {
  390. layer[i] = options
  391. .nameLayer(state.anonymousLayerCounter++, state.rootFilename)
  392. .toString();
  393. } else {
  394. throw node.error(
  395. `When using anonymous layers in @import you must also set the "nameLayer" plugin option`
  396. )
  397. }
  398. }
  399. });
  400. };
  401. // builtin tooling
  402. const path = require$$0;
  403. // internal tooling
  404. const joinMedia = joinMedia$1;
  405. const joinLayer = joinLayer$1;
  406. const resolveId = (id) => id;
  407. const loadContent = loadContent$1;
  408. const processContent = processContent$1;
  409. const parseStatements = parseStatements$1;
  410. const assignLayerNames = assignLayerNames$1;
  411. const dataURL = dataUrl;
  412. function AtImport(options) {
  413. options = {
  414. root: process.cwd(),
  415. path: [],
  416. skipDuplicates: true,
  417. resolve: resolveId,
  418. load: loadContent,
  419. plugins: [],
  420. addModulesDirectories: [],
  421. nameLayer: null,
  422. ...options,
  423. };
  424. options.root = path.resolve(options.root);
  425. // convert string to an array of a single element
  426. if (typeof options.path === "string") options.path = [options.path];
  427. if (!Array.isArray(options.path)) options.path = [];
  428. options.path = options.path.map(p => path.resolve(options.root, p));
  429. return {
  430. postcssPlugin: "postcss-import",
  431. Once(styles, { result, atRule, postcss }) {
  432. const state = {
  433. importedFiles: {},
  434. hashFiles: {},
  435. rootFilename: null,
  436. anonymousLayerCounter: 0,
  437. };
  438. if (styles.source?.input?.file) {
  439. state.rootFilename = styles.source.input.file;
  440. state.importedFiles[styles.source.input.file] = {};
  441. }
  442. if (options.plugins && !Array.isArray(options.plugins)) {
  443. throw new Error("plugins option must be an array")
  444. }
  445. if (options.nameLayer && typeof options.nameLayer !== "function") {
  446. throw new Error("nameLayer option must be a function")
  447. }
  448. return parseStyles(result, styles, options, state, [], []).then(
  449. bundle => {
  450. applyRaws(bundle);
  451. applyMedia(bundle);
  452. applyStyles(bundle, styles);
  453. }
  454. )
  455. function applyRaws(bundle) {
  456. bundle.forEach((stmt, index) => {
  457. if (index === 0) return
  458. if (stmt.parent) {
  459. const { before } = stmt.parent.node.raws;
  460. if (stmt.type === "nodes") stmt.nodes[0].raws.before = before;
  461. else stmt.node.raws.before = before;
  462. } else if (stmt.type === "nodes") {
  463. stmt.nodes[0].raws.before = stmt.nodes[0].raws.before || "\n";
  464. }
  465. });
  466. }
  467. function applyMedia(bundle) {
  468. bundle.forEach(stmt => {
  469. if (
  470. (!stmt.media.length && !stmt.layer.length) ||
  471. stmt.type === "charset"
  472. ) {
  473. return
  474. }
  475. if (stmt.layer.length > 1) {
  476. assignLayerNames(stmt.layer, stmt.node, state, options);
  477. }
  478. if (stmt.type === "import") {
  479. const parts = [stmt.fullUri];
  480. const media = stmt.media.join(", ");
  481. if (stmt.layer.length) {
  482. const layerName = stmt.layer.join(".");
  483. let layerParams = "layer";
  484. if (layerName) {
  485. layerParams = `layer(${layerName})`;
  486. }
  487. parts.push(layerParams);
  488. }
  489. if (media) {
  490. parts.push(media);
  491. }
  492. stmt.node.params = parts.join(" ");
  493. } else if (stmt.type === "media") {
  494. if (stmt.layer.length) {
  495. const layerNode = atRule({
  496. name: "layer",
  497. params: stmt.layer.join("."),
  498. source: stmt.node.source,
  499. });
  500. if (stmt.parentMedia?.length) {
  501. const mediaNode = atRule({
  502. name: "media",
  503. params: stmt.parentMedia.join(", "),
  504. source: stmt.node.source,
  505. });
  506. mediaNode.append(layerNode);
  507. layerNode.append(stmt.node);
  508. stmt.node = mediaNode;
  509. } else {
  510. layerNode.append(stmt.node);
  511. stmt.node = layerNode;
  512. }
  513. } else {
  514. stmt.node.params = stmt.media.join(", ");
  515. }
  516. } else {
  517. const { nodes } = stmt;
  518. const { parent } = nodes[0];
  519. let outerAtRule;
  520. let innerAtRule;
  521. if (stmt.media.length && stmt.layer.length) {
  522. const mediaNode = atRule({
  523. name: "media",
  524. params: stmt.media.join(", "),
  525. source: parent.source,
  526. });
  527. const layerNode = atRule({
  528. name: "layer",
  529. params: stmt.layer.join("."),
  530. source: parent.source,
  531. });
  532. mediaNode.append(layerNode);
  533. innerAtRule = layerNode;
  534. outerAtRule = mediaNode;
  535. } else if (stmt.media.length) {
  536. const mediaNode = atRule({
  537. name: "media",
  538. params: stmt.media.join(", "),
  539. source: parent.source,
  540. });
  541. innerAtRule = mediaNode;
  542. outerAtRule = mediaNode;
  543. } else if (stmt.layer.length) {
  544. const layerNode = atRule({
  545. name: "layer",
  546. params: stmt.layer.join("."),
  547. source: parent.source,
  548. });
  549. innerAtRule = layerNode;
  550. outerAtRule = layerNode;
  551. }
  552. parent.insertBefore(nodes[0], outerAtRule);
  553. // remove nodes
  554. nodes.forEach(node => {
  555. node.parent = undefined;
  556. });
  557. // better output
  558. nodes[0].raws.before = nodes[0].raws.before || "\n";
  559. // wrap new rules with media query and/or layer at rule
  560. innerAtRule.append(nodes);
  561. stmt.type = "media";
  562. stmt.node = outerAtRule;
  563. delete stmt.nodes;
  564. }
  565. });
  566. }
  567. function applyStyles(bundle, styles) {
  568. styles.nodes = [];
  569. // Strip additional statements.
  570. bundle.forEach(stmt => {
  571. if (["charset", "import", "media"].includes(stmt.type)) {
  572. stmt.node.parent = undefined;
  573. styles.append(stmt.node);
  574. } else if (stmt.type === "nodes") {
  575. stmt.nodes.forEach(node => {
  576. node.parent = undefined;
  577. styles.append(node);
  578. });
  579. }
  580. });
  581. }
  582. function parseStyles(result, styles, options, state, media, layer) {
  583. const statements = parseStatements(result, styles);
  584. return Promise.resolve(statements)
  585. .then(stmts => {
  586. // process each statement in series
  587. return stmts.reduce((promise, stmt) => {
  588. return promise.then(() => {
  589. stmt.media = joinMedia(media, stmt.media || []);
  590. stmt.parentMedia = media;
  591. stmt.layer = joinLayer(layer, stmt.layer || []);
  592. // skip protocol base uri (protocol://url) or protocol-relative
  593. if (
  594. stmt.type !== "import" ||
  595. /^(?:[a-z]+:)?\/\//i.test(stmt.uri)
  596. ) {
  597. return
  598. }
  599. if (options.filter && !options.filter(stmt.uri)) {
  600. // rejected by filter
  601. return
  602. }
  603. return resolveImportId(result, stmt, options, state)
  604. })
  605. }, Promise.resolve())
  606. })
  607. .then(() => {
  608. let charset;
  609. const imports = [];
  610. const bundle = [];
  611. function handleCharset(stmt) {
  612. if (!charset) charset = stmt;
  613. // charsets aren't case-sensitive, so convert to lower case to compare
  614. else if (
  615. stmt.node.params.toLowerCase() !==
  616. charset.node.params.toLowerCase()
  617. ) {
  618. throw new Error(
  619. `Incompatable @charset statements:
  620. ${stmt.node.params} specified in ${stmt.node.source.input.file}
  621. ${charset.node.params} specified in ${charset.node.source.input.file}`
  622. )
  623. }
  624. }
  625. // squash statements and their children
  626. statements.forEach(stmt => {
  627. if (stmt.type === "charset") handleCharset(stmt);
  628. else if (stmt.type === "import") {
  629. if (stmt.children) {
  630. stmt.children.forEach((child, index) => {
  631. if (child.type === "import") imports.push(child);
  632. else if (child.type === "charset") handleCharset(child);
  633. else bundle.push(child);
  634. // For better output
  635. if (index === 0) child.parent = stmt;
  636. });
  637. } else imports.push(stmt);
  638. } else if (stmt.type === "media" || stmt.type === "nodes") {
  639. bundle.push(stmt);
  640. }
  641. });
  642. return charset
  643. ? [charset, ...imports.concat(bundle)]
  644. : imports.concat(bundle)
  645. })
  646. }
  647. function resolveImportId(result, stmt, options, state) {
  648. if (dataURL.isValid(stmt.uri)) {
  649. return loadImportContent(result, stmt, stmt.uri, options, state).then(
  650. result => {
  651. stmt.children = result;
  652. }
  653. )
  654. }
  655. const atRule = stmt.node;
  656. let sourceFile;
  657. if (atRule.source?.input?.file) {
  658. sourceFile = atRule.source.input.file;
  659. }
  660. const base = sourceFile
  661. ? path.dirname(atRule.source.input.file)
  662. : options.root;
  663. return Promise.resolve(options.resolve(stmt.uri, base, options))
  664. .then(paths => {
  665. if (!Array.isArray(paths)) paths = [paths];
  666. // Ensure that each path is absolute:
  667. return Promise.all(
  668. paths.map(file => {
  669. return !path.isAbsolute(file)
  670. ? resolveId(file)
  671. : file
  672. })
  673. )
  674. })
  675. .then(resolved => {
  676. // Add dependency messages:
  677. resolved.forEach(file => {
  678. result.messages.push({
  679. type: "dependency",
  680. plugin: "postcss-import",
  681. file,
  682. parent: sourceFile,
  683. });
  684. });
  685. return Promise.all(
  686. resolved.map(file => {
  687. return loadImportContent(result, stmt, file, options, state)
  688. })
  689. )
  690. })
  691. .then(result => {
  692. // Merge loaded statements
  693. stmt.children = result.reduce((result, statements) => {
  694. return statements ? result.concat(statements) : result
  695. }, []);
  696. })
  697. }
  698. function loadImportContent(result, stmt, filename, options, state) {
  699. const atRule = stmt.node;
  700. const { media, layer } = stmt;
  701. assignLayerNames(layer, atRule, state, options);
  702. if (options.skipDuplicates) {
  703. // skip files already imported at the same scope
  704. if (state.importedFiles[filename]?.[media]?.[layer]) {
  705. return
  706. }
  707. // save imported files to skip them next time
  708. if (!state.importedFiles[filename]) {
  709. state.importedFiles[filename] = {};
  710. }
  711. if (!state.importedFiles[filename][media]) {
  712. state.importedFiles[filename][media] = {};
  713. }
  714. state.importedFiles[filename][media][layer] = true;
  715. }
  716. return Promise.resolve(options.load(filename, options)).then(
  717. content => {
  718. if (content.trim() === "") {
  719. result.warn(`${filename} is empty`, { node: atRule });
  720. return
  721. }
  722. // skip previous imported files not containing @import rules
  723. if (state.hashFiles[content]?.[media]?.[layer]) {
  724. return
  725. }
  726. return processContent(
  727. result,
  728. content,
  729. filename,
  730. options,
  731. postcss
  732. ).then(importedResult => {
  733. const styles = importedResult.root;
  734. result.messages = result.messages.concat(importedResult.messages);
  735. if (options.skipDuplicates) {
  736. const hasImport = styles.some(child => {
  737. return child.type === "atrule" && child.name === "import"
  738. });
  739. if (!hasImport) {
  740. // save hash files to skip them next time
  741. if (!state.hashFiles[content]) {
  742. state.hashFiles[content] = {};
  743. }
  744. if (!state.hashFiles[content][media]) {
  745. state.hashFiles[content][media] = {};
  746. }
  747. state.hashFiles[content][media][layer] = true;
  748. }
  749. }
  750. // recursion: import @import from imported file
  751. return parseStyles(result, styles, options, state, media, layer)
  752. })
  753. }
  754. )
  755. }
  756. },
  757. }
  758. }
  759. AtImport.postcss = true;
  760. var postcssImport = AtImport;
  761. var index = /*@__PURE__*/getDefaultExportFromCjs(postcssImport);
  762. var index$1 = /*#__PURE__*/_mergeNamespaces({
  763. __proto__: null,
  764. default: index
  765. }, [postcssImport]);
  766. export { index$1 as i };