index.mjs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. function $parcel$defineInteropFlag(a) {
  2. Object.defineProperty(a, '__esModule', {value: true, configurable: true});
  3. }
  4. function $parcel$export(e, n, v, s) {
  5. Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
  6. }
  7. var $009ddb00d3ec72b8$exports = {};
  8. $parcel$defineInteropFlag($009ddb00d3ec72b8$exports);
  9. $parcel$export($009ddb00d3ec72b8$exports, "default", () => $009ddb00d3ec72b8$export$2e2bcd8739ae039);
  10. class $009ddb00d3ec72b8$export$2e2bcd8739ae039 extends Error {
  11. constructor(filename, msg, lineno, column, css){
  12. super(filename + ':' + lineno + ':' + column + ': ' + msg);
  13. this.reason = msg;
  14. this.filename = filename;
  15. this.line = lineno;
  16. this.column = column;
  17. this.source = css;
  18. }
  19. }
  20. var $0865a9fb4cc365fe$exports = {};
  21. $parcel$defineInteropFlag($0865a9fb4cc365fe$exports);
  22. $parcel$export($0865a9fb4cc365fe$exports, "default", () => $0865a9fb4cc365fe$export$2e2bcd8739ae039);
  23. /**
  24. * Store position information for a node
  25. */ class $0865a9fb4cc365fe$export$2e2bcd8739ae039 {
  26. constructor(start, end, source){
  27. this.start = start;
  28. this.end = end;
  29. this.source = source;
  30. }
  31. }
  32. var $b2e137848b48cf4f$exports = {};
  33. $parcel$export($b2e137848b48cf4f$exports, "CssTypes", () => $b2e137848b48cf4f$export$9be5dd6e61d5d73a);
  34. var $b2e137848b48cf4f$export$9be5dd6e61d5d73a = /*#__PURE__*/ function(CssTypes) {
  35. CssTypes["stylesheet"] = "stylesheet";
  36. CssTypes["rule"] = "rule";
  37. CssTypes["declaration"] = "declaration";
  38. CssTypes["comment"] = "comment";
  39. CssTypes["container"] = "container";
  40. CssTypes["charset"] = "charset";
  41. CssTypes["document"] = "document";
  42. CssTypes["customMedia"] = "custom-media";
  43. CssTypes["fontFace"] = "font-face";
  44. CssTypes["host"] = "host";
  45. CssTypes["import"] = "import";
  46. CssTypes["keyframes"] = "keyframes";
  47. CssTypes["keyframe"] = "keyframe";
  48. CssTypes["layer"] = "layer";
  49. CssTypes["media"] = "media";
  50. CssTypes["namespace"] = "namespace";
  51. CssTypes["page"] = "page";
  52. CssTypes["startingStyle"] = "starting-style";
  53. CssTypes["supports"] = "supports";
  54. return CssTypes;
  55. }({});
  56. // http://www.w3.org/TR/CSS21/grammar.html
  57. // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
  58. // New rule => https://www.w3.org/TR/CSS22/syndata.html#comments
  59. // [^] is equivalent to [.\n\r]
  60. const $d708735ed1303b43$var$commentre = /\/\*[^]*?(?:\*\/|$)/g;
  61. const $d708735ed1303b43$export$98e6a39c04603d36 = (css, options)=>{
  62. options = options || {};
  63. /**
  64. * Positional.
  65. */ let lineno = 1;
  66. let column = 1;
  67. /**
  68. * Update lineno and column based on `str`.
  69. */ function updatePosition(str) {
  70. const lines = str.match(/\n/g);
  71. if (lines) lineno += lines.length;
  72. const i = str.lastIndexOf('\n');
  73. column = ~i ? str.length - i : column + str.length;
  74. }
  75. /**
  76. * Mark position and patch `node.position`.
  77. */ function position() {
  78. const start = {
  79. line: lineno,
  80. column: column
  81. };
  82. return function(node) {
  83. node.position = new (0, $0865a9fb4cc365fe$export$2e2bcd8739ae039)(start, {
  84. line: lineno,
  85. column: column
  86. }, options?.source || '');
  87. whitespace();
  88. return node;
  89. };
  90. }
  91. /**
  92. * Error `msg`.
  93. */ const errorsList = [];
  94. function error(msg) {
  95. const err = new (0, $009ddb00d3ec72b8$export$2e2bcd8739ae039)(options?.source || '', msg, lineno, column, css);
  96. if (options?.silent) errorsList.push(err);
  97. else throw err;
  98. }
  99. /**
  100. * Parse stylesheet.
  101. */ function stylesheet() {
  102. const rulesList = rules();
  103. const result = {
  104. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).stylesheet,
  105. stylesheet: {
  106. source: options?.source,
  107. rules: rulesList,
  108. parsingErrors: errorsList
  109. }
  110. };
  111. return result;
  112. }
  113. /**
  114. * Opening brace.
  115. */ function open() {
  116. return match(/^{\s*/);
  117. }
  118. /**
  119. * Closing brace.
  120. */ function close() {
  121. return match(/^}/);
  122. }
  123. /**
  124. * Parse ruleset.
  125. */ function rules() {
  126. let node;
  127. const rules = [];
  128. whitespace();
  129. comments(rules);
  130. while(css.length && css.charAt(0) !== '}' && (node = atrule() || rule()))if (node) {
  131. rules.push(node);
  132. comments(rules);
  133. }
  134. return rules;
  135. }
  136. /**
  137. * Match `re` and return captures.
  138. */ function match(re) {
  139. const m = re.exec(css);
  140. if (!m) return;
  141. const str = m[0];
  142. updatePosition(str);
  143. css = css.slice(str.length);
  144. return m;
  145. }
  146. /**
  147. * Parse whitespace.
  148. */ function whitespace() {
  149. match(/^\s*/);
  150. }
  151. /**
  152. * Parse comments;
  153. */ function comments(rules) {
  154. let c;
  155. rules = rules || [];
  156. while(c = comment())if (c) rules.push(c);
  157. return rules;
  158. }
  159. /**
  160. * Parse comment.
  161. */ function comment() {
  162. const pos = position();
  163. if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) return;
  164. const m = match(/^\/\*[^]*?\*\//);
  165. if (!m) return error('End of comment missing');
  166. return pos({
  167. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).comment,
  168. comment: m[0].slice(2, -2)
  169. });
  170. }
  171. function findClosingParenthese(str, start, depth) {
  172. let ptr = start + 1;
  173. let found = false;
  174. let closeParentheses = str.indexOf(')', ptr);
  175. while(!found && closeParentheses !== -1){
  176. const nextParentheses = str.indexOf('(', ptr);
  177. if (nextParentheses !== -1 && nextParentheses < closeParentheses) {
  178. const nextSearch = findClosingParenthese(str, nextParentheses + 1, depth + 1);
  179. ptr = nextSearch + 1;
  180. closeParentheses = str.indexOf(')', ptr);
  181. } else found = true;
  182. }
  183. if (found && closeParentheses !== -1) return closeParentheses;
  184. else return -1;
  185. }
  186. /**
  187. * Parse selector.
  188. */ function selector() {
  189. const m = match(/^([^{]+)/);
  190. if (!m) return;
  191. // remove comment in selector;
  192. let res = $d708735ed1303b43$var$trim(m[0]).replace($d708735ed1303b43$var$commentre, '');
  193. // Optimisation: If there is no ',' no need to split or post-process (this is less costly)
  194. if (res.indexOf(',') === -1) return [
  195. res
  196. ];
  197. // Replace all the , in the parentheses by \u200C
  198. let ptr = 0;
  199. let startParentheses = res.indexOf('(', ptr);
  200. while(startParentheses !== -1){
  201. const closeParentheses = findClosingParenthese(res, startParentheses, 0);
  202. if (closeParentheses === -1) break;
  203. ptr = closeParentheses + 1;
  204. res = res.substring(0, startParentheses) + res.substring(startParentheses, closeParentheses).replace(/,/g, '\u200C') + res.substring(closeParentheses);
  205. startParentheses = res.indexOf('(', ptr);
  206. }
  207. // Replace all the , in ' and " by \u200C
  208. res = res/**
  209. * replace ',' by \u200C for data selector (div[data-lang="fr,de,us"])
  210. *
  211. * Examples:
  212. * div[data-lang="fr,\"de,us"]
  213. * div[data-lang='fr,\'de,us']
  214. *
  215. * Regex logic:
  216. * ("|')(?:\\\1|.)*?\1 => Handle the " and '
  217. *
  218. * Optimization 1:
  219. * No greedy capture (see docs about the difference between .* and .*?)
  220. *
  221. * Optimization 2:
  222. * ("|')(?:\\\1|.)*?\1 this use reference to capture group, it work faster.
  223. */ .replace(/("|')(?:\\\1|.)*?\1/g, (m)=>m.replace(/,/g, '\u200C'));
  224. // Split all the left , and replace all the \u200C by ,
  225. return res// Split the selector by ','
  226. .split(',')// Replace back \u200C by ','
  227. .map((s)=>{
  228. return $d708735ed1303b43$var$trim(s.replace(/\u200C/g, ','));
  229. });
  230. }
  231. /**
  232. * Parse declaration.
  233. */ function declaration() {
  234. const pos = position();
  235. // prop
  236. const propMatch = match(/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
  237. if (!propMatch) return;
  238. const propValue = $d708735ed1303b43$var$trim(propMatch[0]);
  239. // :
  240. if (!match(/^:\s*/)) return error("property missing ':'");
  241. // val
  242. const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^)])*?\)|[^};])+)/);
  243. const ret = pos({
  244. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).declaration,
  245. property: propValue.replace($d708735ed1303b43$var$commentre, ''),
  246. value: val ? $d708735ed1303b43$var$trim(val[0]).replace($d708735ed1303b43$var$commentre, '') : ''
  247. });
  248. // ;
  249. match(/^[;\s]*/);
  250. return ret;
  251. }
  252. /**
  253. * Parse declarations.
  254. */ function declarations() {
  255. const decls = [];
  256. if (!open()) return error("missing '{'");
  257. comments(decls);
  258. // declarations
  259. let decl;
  260. while(decl = declaration())if (decl) {
  261. decls.push(decl);
  262. comments(decls);
  263. }
  264. if (!close()) return error("missing '}'");
  265. return decls;
  266. }
  267. /**
  268. * Parse keyframe.
  269. */ function keyframe() {
  270. let m;
  271. const vals = [];
  272. const pos = position();
  273. while(m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)){
  274. vals.push(m[1]);
  275. match(/^,\s*/);
  276. }
  277. if (!vals.length) return;
  278. return pos({
  279. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).keyframe,
  280. values: vals,
  281. declarations: declarations() || []
  282. });
  283. }
  284. /**
  285. * Parse keyframes.
  286. */ function atkeyframes() {
  287. const pos = position();
  288. const m1 = match(/^@([-\w]+)?keyframes\s*/);
  289. if (!m1) return;
  290. const vendor = m1[1];
  291. // identifier
  292. const m2 = match(/^([-\w]+)\s*/);
  293. if (!m2) return error('@keyframes missing name');
  294. const name = m2[1];
  295. if (!open()) return error("@keyframes missing '{'");
  296. let frame;
  297. let frames = comments();
  298. while(frame = keyframe()){
  299. frames.push(frame);
  300. frames = frames.concat(comments());
  301. }
  302. if (!close()) return error("@keyframes missing '}'");
  303. return pos({
  304. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).keyframes,
  305. name: name,
  306. vendor: vendor,
  307. keyframes: frames
  308. });
  309. }
  310. /**
  311. * Parse supports.
  312. */ function atsupports() {
  313. const pos = position();
  314. const m = match(/^@supports *([^{]+)/);
  315. if (!m) return;
  316. const supports = $d708735ed1303b43$var$trim(m[1]);
  317. if (!open()) return error("@supports missing '{'");
  318. const style = comments().concat(rules());
  319. if (!close()) return error("@supports missing '}'");
  320. return pos({
  321. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).supports,
  322. supports: supports,
  323. rules: style
  324. });
  325. }
  326. /**
  327. * Parse host.
  328. */ function athost() {
  329. const pos = position();
  330. const m = match(/^@host\s*/);
  331. if (!m) return;
  332. if (!open()) return error("@host missing '{'");
  333. const style = comments().concat(rules());
  334. if (!close()) return error("@host missing '}'");
  335. return pos({
  336. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).host,
  337. rules: style
  338. });
  339. }
  340. /**
  341. * Parse container.
  342. */ function atcontainer() {
  343. const pos = position();
  344. const m = match(/^@container *([^{]+)/);
  345. if (!m) return;
  346. const container = $d708735ed1303b43$var$trim(m[1]);
  347. if (!open()) return error("@container missing '{'");
  348. const style = comments().concat(rules());
  349. if (!close()) return error("@container missing '}'");
  350. return pos({
  351. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).container,
  352. container: container,
  353. rules: style
  354. });
  355. }
  356. /**
  357. * Parse container.
  358. */ function atlayer() {
  359. const pos = position();
  360. const m = match(/^@layer *([^{;@]+)/);
  361. if (!m) return;
  362. const layer = $d708735ed1303b43$var$trim(m[1]);
  363. if (!open()) {
  364. match(/^[;\s]*/);
  365. return pos({
  366. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).layer,
  367. layer: layer
  368. });
  369. }
  370. const style = comments().concat(rules());
  371. if (!close()) return error("@layer missing '}'");
  372. return pos({
  373. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).layer,
  374. layer: layer,
  375. rules: style
  376. });
  377. }
  378. /**
  379. * Parse media.
  380. */ function atmedia() {
  381. const pos = position();
  382. const m = match(/^@media *([^{]+)/);
  383. if (!m) return;
  384. const media = $d708735ed1303b43$var$trim(m[1]);
  385. if (!open()) return error("@media missing '{'");
  386. const style = comments().concat(rules());
  387. if (!close()) return error("@media missing '}'");
  388. return pos({
  389. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).media,
  390. media: media,
  391. rules: style
  392. });
  393. }
  394. /**
  395. * Parse custom-media.
  396. */ function atcustommedia() {
  397. const pos = position();
  398. const m = match(/^@custom-media\s+(--\S+)\s*([^{;\s][^{;]*);/);
  399. if (!m) return;
  400. return pos({
  401. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).customMedia,
  402. name: $d708735ed1303b43$var$trim(m[1]),
  403. media: $d708735ed1303b43$var$trim(m[2])
  404. });
  405. }
  406. /**
  407. * Parse paged media.
  408. */ function atpage() {
  409. const pos = position();
  410. const m = match(/^@page */);
  411. if (!m) return;
  412. const sel = selector() || [];
  413. if (!open()) return error("@page missing '{'");
  414. let decls = comments();
  415. // declarations
  416. let decl;
  417. while(decl = declaration()){
  418. decls.push(decl);
  419. decls = decls.concat(comments());
  420. }
  421. if (!close()) return error("@page missing '}'");
  422. return pos({
  423. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).page,
  424. selectors: sel,
  425. declarations: decls
  426. });
  427. }
  428. /**
  429. * Parse document.
  430. */ function atdocument() {
  431. const pos = position();
  432. const m = match(/^@([-\w]+)?document *([^{]+)/);
  433. if (!m) return;
  434. const vendor = $d708735ed1303b43$var$trim(m[1]);
  435. const doc = $d708735ed1303b43$var$trim(m[2]);
  436. if (!open()) return error("@document missing '{'");
  437. const style = comments().concat(rules());
  438. if (!close()) return error("@document missing '}'");
  439. return pos({
  440. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).document,
  441. document: doc,
  442. vendor: vendor,
  443. rules: style
  444. });
  445. }
  446. /**
  447. * Parse font-face.
  448. */ function atfontface() {
  449. const pos = position();
  450. const m = match(/^@font-face\s*/);
  451. if (!m) return;
  452. if (!open()) return error("@font-face missing '{'");
  453. let decls = comments();
  454. // declarations
  455. let decl;
  456. while(decl = declaration()){
  457. decls.push(decl);
  458. decls = decls.concat(comments());
  459. }
  460. if (!close()) return error("@font-face missing '}'");
  461. return pos({
  462. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).fontFace,
  463. declarations: decls
  464. });
  465. }
  466. /**
  467. * Parse starting style.
  468. */ function atstartingstyle() {
  469. const pos = position();
  470. const m = match(/^@starting-style\s*/);
  471. if (!m) return;
  472. if (!open()) return error("@starting-style missing '{'");
  473. const style = comments().concat(rules());
  474. if (!close()) return error("@starting-style missing '}'");
  475. return pos({
  476. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).startingStyle,
  477. rules: style
  478. });
  479. }
  480. /**
  481. * Parse import
  482. */ const atimport = _compileAtrule('import');
  483. /**
  484. * Parse charset
  485. */ const atcharset = _compileAtrule('charset');
  486. /**
  487. * Parse namespace
  488. */ const atnamespace = _compileAtrule('namespace');
  489. /**
  490. * Parse non-block at-rules
  491. */ function _compileAtrule(name) {
  492. const re = new RegExp('^@' + name + '\\s*((?::?[^;\'"]|"(?:\\\\"|[^"])*?"|\'(?:\\\\\'|[^\'])*?\')+)(?:;|$)');
  493. // ^@import\s*([^;"']|("|')(?:\\\2|.)*?\2)+(;|$)
  494. return function() {
  495. const pos = position();
  496. const m = match(re);
  497. if (!m) return;
  498. const ret = {
  499. type: name
  500. };
  501. ret[name] = m[1].trim();
  502. return pos(ret);
  503. };
  504. }
  505. /**
  506. * Parse at rule.
  507. */ function atrule() {
  508. if (css[0] !== '@') return;
  509. return atkeyframes() || atmedia() || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface() || atcontainer() || atstartingstyle() || atlayer();
  510. }
  511. /**
  512. * Parse rule.
  513. */ function rule() {
  514. const pos = position();
  515. const sel = selector();
  516. if (!sel) return error('selector missing');
  517. comments();
  518. return pos({
  519. type: (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).rule,
  520. selectors: sel,
  521. declarations: declarations() || []
  522. });
  523. }
  524. return $d708735ed1303b43$var$addParent(stylesheet());
  525. };
  526. /**
  527. * Trim `str`.
  528. */ function $d708735ed1303b43$var$trim(str) {
  529. return str ? str.trim() : '';
  530. }
  531. /**
  532. * Adds non-enumerable parent node reference to each node.
  533. */ function $d708735ed1303b43$var$addParent(obj, parent) {
  534. const isNode = obj && typeof obj.type === 'string';
  535. const childParent = isNode ? obj : parent;
  536. for(const k in obj){
  537. const value = obj[k];
  538. if (Array.isArray(value)) value.forEach((v)=>{
  539. $d708735ed1303b43$var$addParent(v, childParent);
  540. });
  541. else if (value && typeof value === 'object') $d708735ed1303b43$var$addParent(value, childParent);
  542. }
  543. if (isNode) Object.defineProperty(obj, 'parent', {
  544. configurable: true,
  545. writable: true,
  546. enumerable: false,
  547. value: parent || null
  548. });
  549. return obj;
  550. }
  551. var $d708735ed1303b43$export$2e2bcd8739ae039 = $d708735ed1303b43$export$98e6a39c04603d36;
  552. class $de9540138ed1fd01$var$Compiler {
  553. constructor(options){
  554. this.level = 0;
  555. this.indentation = ' ';
  556. this.compress = false;
  557. if (typeof options?.indent === 'string') this.indentation = options?.indent;
  558. if (options?.compress) this.compress = true;
  559. }
  560. // We disable no-unused-vars for _position. We keep position for potential reintroduction of source-map
  561. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  562. emit(str, _position) {
  563. return str;
  564. }
  565. /**
  566. * Increase, decrease or return current indentation.
  567. */ indent(level) {
  568. this.level = this.level || 1;
  569. if (level) {
  570. this.level += level;
  571. return '';
  572. }
  573. return Array(this.level).join(this.indentation);
  574. }
  575. visit(node) {
  576. switch(node.type){
  577. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).stylesheet:
  578. return this.stylesheet(node);
  579. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).rule:
  580. return this.rule(node);
  581. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).declaration:
  582. return this.declaration(node);
  583. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).comment:
  584. return this.comment(node);
  585. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).container:
  586. return this.container(node);
  587. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).charset:
  588. return this.charset(node);
  589. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).document:
  590. return this.document(node);
  591. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).customMedia:
  592. return this.customMedia(node);
  593. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).fontFace:
  594. return this.fontFace(node);
  595. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).host:
  596. return this.host(node);
  597. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).import:
  598. return this.import(node);
  599. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).keyframes:
  600. return this.keyframes(node);
  601. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).keyframe:
  602. return this.keyframe(node);
  603. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).layer:
  604. return this.layer(node);
  605. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).media:
  606. return this.media(node);
  607. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).namespace:
  608. return this.namespace(node);
  609. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).page:
  610. return this.page(node);
  611. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).startingStyle:
  612. return this.startingStyle(node);
  613. case (0, $b2e137848b48cf4f$export$9be5dd6e61d5d73a).supports:
  614. return this.supports(node);
  615. }
  616. }
  617. mapVisit(nodes, delim) {
  618. let buf = '';
  619. delim = delim || '';
  620. for(let i = 0, length = nodes.length; i < length; i++){
  621. buf += this.visit(nodes[i]);
  622. if (delim && i < length - 1) buf += this.emit(delim);
  623. }
  624. return buf;
  625. }
  626. compile(node) {
  627. if (this.compress) return node.stylesheet.rules.map(this.visit, this).join('');
  628. return this.stylesheet(node);
  629. }
  630. /**
  631. * Visit stylesheet node.
  632. */ stylesheet(node) {
  633. return this.mapVisit(node.stylesheet.rules, '\n\n');
  634. }
  635. /**
  636. * Visit comment node.
  637. */ comment(node) {
  638. if (this.compress) return this.emit('', node.position);
  639. return this.emit(this.indent() + '/*' + node.comment + '*/', node.position);
  640. }
  641. /**
  642. * Visit container node.
  643. */ container(node) {
  644. if (this.compress) return this.emit('@container ' + node.container, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  645. return this.emit(this.indent() + '@container ' + node.container, node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit('\n' + this.indent(-1) + this.indent() + '}');
  646. }
  647. /**
  648. * Visit container node.
  649. */ layer(node) {
  650. if (this.compress) return this.emit('@layer ' + node.layer, node.position) + (node.rules ? this.emit('{') + this.mapVisit(node.rules) + this.emit('}') : ';');
  651. return this.emit(this.indent() + '@layer ' + node.layer, node.position) + (node.rules ? this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit('\n' + this.indent(-1) + this.indent() + '}') : ';');
  652. }
  653. /**
  654. * Visit import node.
  655. */ import(node) {
  656. return this.emit('@import ' + node.import + ';', node.position);
  657. }
  658. /**
  659. * Visit media node.
  660. */ media(node) {
  661. if (this.compress) return this.emit('@media ' + node.media, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  662. return this.emit(this.indent() + '@media ' + node.media, node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit('\n' + this.indent(-1) + this.indent() + '}');
  663. }
  664. /**
  665. * Visit document node.
  666. */ document(node) {
  667. const doc = '@' + (node.vendor || '') + 'document ' + node.document;
  668. if (this.compress) return this.emit(doc, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  669. return this.emit(doc, node.position) + this.emit(" {\n" + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit(this.indent(-1) + '\n}');
  670. }
  671. /**
  672. * Visit charset node.
  673. */ charset(node) {
  674. return this.emit('@charset ' + node.charset + ';', node.position);
  675. }
  676. /**
  677. * Visit namespace node.
  678. */ namespace(node) {
  679. return this.emit('@namespace ' + node.namespace + ';', node.position);
  680. }
  681. /**
  682. * Visit container node.
  683. */ startingStyle(node) {
  684. if (this.compress) return this.emit('@starting-style', node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  685. return this.emit(this.indent() + '@starting-style', node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit('\n' + this.indent(-1) + this.indent() + '}');
  686. }
  687. /**
  688. * Visit supports node.
  689. */ supports(node) {
  690. if (this.compress) return this.emit('@supports ' + node.supports, node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  691. return this.emit(this.indent() + '@supports ' + node.supports, node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit('\n' + this.indent(-1) + this.indent() + '}');
  692. }
  693. /**
  694. * Visit keyframes node.
  695. */ keyframes(node) {
  696. if (this.compress) return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position) + this.emit('{') + this.mapVisit(node.keyframes) + this.emit('}');
  697. return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.keyframes, '\n') + this.emit(this.indent(-1) + '}');
  698. }
  699. /**
  700. * Visit keyframe node.
  701. */ keyframe(node) {
  702. const decls = node.declarations;
  703. if (this.compress) return this.emit(node.values.join(','), node.position) + this.emit('{') + this.mapVisit(decls) + this.emit('}');
  704. return this.emit(this.indent()) + this.emit(node.values.join(', '), node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(decls, '\n') + this.emit(this.indent(-1) + '\n' + this.indent() + '}\n');
  705. }
  706. /**
  707. * Visit page node.
  708. */ page(node) {
  709. if (this.compress) {
  710. const sel = node.selectors.length ? node.selectors.join(', ') : '';
  711. return this.emit('@page ' + sel, node.position) + this.emit('{') + this.mapVisit(node.declarations) + this.emit('}');
  712. }
  713. const sel = node.selectors.length ? node.selectors.join(', ') + ' ' : '';
  714. return this.emit('@page ' + sel, node.position) + this.emit('{\n') + this.emit(this.indent(1)) + this.mapVisit(node.declarations, '\n') + this.emit(this.indent(-1)) + this.emit('\n}');
  715. }
  716. /**
  717. * Visit font-face node.
  718. */ fontFace(node) {
  719. if (this.compress) return this.emit('@font-face', node.position) + this.emit('{') + this.mapVisit(node.declarations) + this.emit('}');
  720. return this.emit('@font-face ', node.position) + this.emit('{\n') + this.emit(this.indent(1)) + this.mapVisit(node.declarations, '\n') + this.emit(this.indent(-1)) + this.emit('\n}');
  721. }
  722. /**
  723. * Visit host node.
  724. */ host(node) {
  725. if (this.compress) return this.emit('@host', node.position) + this.emit('{') + this.mapVisit(node.rules) + this.emit('}');
  726. return this.emit('@host', node.position) + this.emit(' {\n' + this.indent(1)) + this.mapVisit(node.rules, '\n\n') + this.emit(this.indent(-1) + '\n}');
  727. }
  728. /**
  729. * Visit custom-media node.
  730. */ customMedia(node) {
  731. return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
  732. }
  733. /**
  734. * Visit rule node.
  735. */ rule(node) {
  736. const decls = node.declarations;
  737. if (!decls.length) return '';
  738. if (this.compress) return this.emit(node.selectors.join(','), node.position) + this.emit('{') + this.mapVisit(decls) + this.emit('}');
  739. const indent = this.indent();
  740. return this.emit(node.selectors.map((s)=>{
  741. return indent + s;
  742. }).join(',\n'), node.position) + this.emit(' {\n') + this.emit(this.indent(1)) + this.mapVisit(decls, '\n') + this.emit(this.indent(-1)) + this.emit('\n' + this.indent() + '}');
  743. }
  744. /**
  745. * Visit declaration node.
  746. */ declaration(node) {
  747. if (this.compress) return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
  748. return this.emit(this.indent()) + this.emit(node.property + ': ' + node.value, node.position) + this.emit(';');
  749. }
  750. }
  751. var $de9540138ed1fd01$export$2e2bcd8739ae039 = $de9540138ed1fd01$var$Compiler;
  752. var $fdf773ab87e20450$export$2e2bcd8739ae039 = (node, options)=>{
  753. const compiler = new (0, $de9540138ed1fd01$export$2e2bcd8739ae039)(options || {});
  754. return compiler.compile(node);
  755. };
  756. const $149c1bd638913645$export$98e6a39c04603d36 = (0, $d708735ed1303b43$export$2e2bcd8739ae039);
  757. const $149c1bd638913645$export$fac44ee5b035f737 = (0, $fdf773ab87e20450$export$2e2bcd8739ae039);
  758. var $149c1bd638913645$export$2e2bcd8739ae039 = {
  759. parse: $149c1bd638913645$export$98e6a39c04603d36,
  760. stringify: $149c1bd638913645$export$fac44ee5b035f737
  761. };
  762. export {$149c1bd638913645$export$98e6a39c04603d36 as parse, $149c1bd638913645$export$fac44ee5b035f737 as stringify, $149c1bd638913645$export$2e2bcd8739ae039 as default, $b2e137848b48cf4f$export$9be5dd6e61d5d73a as CssTypes};
  763. //# sourceMappingURL=index.mjs.map