版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1788 строки
76 KiB

  1. var HTMLParser = /** @class */ (function () {
  2. function HTMLParser(html) {
  3. this.html = html;
  4. }
  5. HTMLParser.prototype.parseAttrs = function () {
  6. if (!this.html)
  7. return [];
  8. var output = [];
  9. var regex = /\S+\s*=\s*"[^"]+"|\S+\s*=\s*'[^']+'|\S+\s*=\s*[^>\s]+/igm;
  10. var match;
  11. while ((match = regex.exec(this.html))) {
  12. if (match) {
  13. var raw = match[0];
  14. var sep = raw.indexOf('=');
  15. var key = raw.slice(0, sep).trim();
  16. var value = raw.slice(sep + 1).trim();
  17. if (['"', '\''].includes(value.charAt(0)))
  18. value = value.slice(1, -1);
  19. value = value.split(/\s/).filter(function (i) { return i; });
  20. value = value[0] === undefined ? '' : value[1] === undefined ? value[0] : value;
  21. output.push({
  22. raw: raw,
  23. key: key,
  24. value: value,
  25. start: match.index,
  26. end: regex.lastIndex,
  27. });
  28. }
  29. }
  30. return output;
  31. };
  32. HTMLParser.prototype.parseClasses = function () {
  33. var _a, _b;
  34. // Match all class properties
  35. if (!this.html)
  36. return [];
  37. var output = [];
  38. var regex = /class(Name)?\s*=\s*{`[^`]+`}|class(Name)?\s*=\s*"[^"]+"|class(Name)?\s*=\s*'[^']+'|class(Name)?\s*=\s*[^>\s]+/igm;
  39. var match;
  40. while ((match = regex.exec(this.html))) {
  41. if (match) {
  42. var raw = match[0];
  43. var sep = raw.indexOf('=');
  44. var value = raw.slice(sep + 1).trim();
  45. var start = match.index + sep + 1 + ((_b = (_a = this.html.slice(sep + 1).match(/[^'"]/)) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : 0);
  46. var end = regex.lastIndex;
  47. var first = value.charAt(0);
  48. while (['"', '\'', '`', '{'].includes(first)) {
  49. value = value.slice(1, -1);
  50. first = value.charAt(0);
  51. end--;
  52. start++;
  53. }
  54. output.push({
  55. result: value,
  56. start: start,
  57. end: end,
  58. });
  59. }
  60. }
  61. return output;
  62. };
  63. HTMLParser.prototype.parseTags = function () {
  64. // Match all html tags
  65. if (!this.html)
  66. return [];
  67. return Array.from(new Set(this.html.match(/<\w+/g))).map(function (i) {
  68. return i.substring(1);
  69. });
  70. };
  71. return HTMLParser;
  72. }());
  73. /*! *****************************************************************************
  74. Copyright (c) Microsoft Corporation.
  75. Permission to use, copy, modify, and/or distribute this software for any
  76. purpose with or without fee is hereby granted.
  77. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  78. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  79. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  80. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  81. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  82. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  83. PERFORMANCE OF THIS SOFTWARE.
  84. ***************************************************************************** */
  85. /* global Reflect, Promise */
  86. var extendStatics = function(d, b) {
  87. extendStatics = Object.setPrototypeOf ||
  88. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  89. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  90. return extendStatics(d, b);
  91. };
  92. function __extends(d, b) {
  93. if (typeof b !== "function" && b !== null)
  94. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  95. extendStatics(d, b);
  96. function __() { this.constructor = d; }
  97. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  98. }
  99. function __spreadArray(to, from, pack) {
  100. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  101. if (ar || !(i in from)) {
  102. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  103. ar[i] = from[i];
  104. }
  105. }
  106. return to.concat(ar || Array.prototype.slice.call(from));
  107. }
  108. function toArray(v) {
  109. if (Array.isArray(v))
  110. return v;
  111. return [v];
  112. }
  113. function hash(str) {
  114. str = str.replace(/\r/g, '');
  115. var hash = 5381;
  116. var i = str.length;
  117. while (i--)
  118. hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
  119. return (hash >>> 0).toString(36);
  120. }
  121. function indent(code, tab) {
  122. if (tab === void 0) { tab = 2; }
  123. var spaces = Array(tab).fill(' ').join('');
  124. return code
  125. .split('\n')
  126. .map(function (line) { return spaces + line; })
  127. .join('\n');
  128. }
  129. function wrapit(code, start, end, tab, minify) {
  130. if (start === void 0) { start = '{'; }
  131. if (end === void 0) { end = '}'; }
  132. if (tab === void 0) { tab = 2; }
  133. if (minify === void 0) { minify = false; }
  134. if (minify)
  135. return "".concat(start).concat(code).concat(end);
  136. return "".concat(start, "\n").concat(indent(code, tab), "\n").concat(end);
  137. }
  138. function isSpace(str) {
  139. return /^\s*$/.test(str);
  140. }
  141. function camelToDash(str) {
  142. // Use exact the same regex as Post CSS
  143. return str.replace(/([A-Z])/g, '-$1').replace(/^ms-/, '-ms-').toLowerCase();
  144. }
  145. function searchFrom(text, target, startIndex, endIndex) {
  146. if (startIndex === void 0) { startIndex = 0; }
  147. // search from partial of string
  148. var subText = text.substring(startIndex, endIndex);
  149. var relativeIndex = subText.search(target);
  150. return relativeIndex === -1 ? -1 : startIndex + relativeIndex;
  151. }
  152. function connectList(a, b, append) {
  153. if (append === void 0) { append = true; }
  154. return append ? __spreadArray(__spreadArray([], (a !== null && a !== void 0 ? a : []), true), (b !== null && b !== void 0 ? b : []), true) : __spreadArray(__spreadArray([], (b !== null && b !== void 0 ? b : []), true), (a !== null && a !== void 0 ? a : []), true);
  155. }
  156. function deepCopy(source) {
  157. return Array.isArray(source)
  158. ? source.map(function (item) { return deepCopy(item); })
  159. : source instanceof Date
  160. ? new Date(source.getTime())
  161. : source && typeof source === 'object'
  162. ? Object.getOwnPropertyNames(source).reduce(function (o, prop) {
  163. var descriptor = Object.getOwnPropertyDescriptor(source, prop);
  164. if (descriptor) {
  165. Object.defineProperty(o, prop, descriptor);
  166. if (source && typeof source === 'object') {
  167. o[prop] = deepCopy(source[prop]);
  168. }
  169. }
  170. return o;
  171. }, Object.create(Object.getPrototypeOf(source)))
  172. : source;
  173. }
  174. function isTagName(name) {
  175. return ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embd', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'].includes(name);
  176. }
  177. function searchPropEnd(text, startIndex) {
  178. if (startIndex === void 0) { startIndex = 0; }
  179. var index = startIndex;
  180. var output = -1;
  181. var openSingleQuote = false;
  182. var openDoubleQuote = false;
  183. var openBracket = false;
  184. var isEscaped = false;
  185. while (index < text.length) {
  186. switch (text.charAt(index)) {
  187. case '\\':
  188. isEscaped = !isEscaped;
  189. break;
  190. case '\'':
  191. if (!openDoubleQuote && !openBracket && !isEscaped)
  192. openSingleQuote = !openSingleQuote;
  193. isEscaped = false;
  194. break;
  195. case '"':
  196. if (!openSingleQuote && !openBracket && !isEscaped)
  197. openDoubleQuote = !openDoubleQuote;
  198. isEscaped = false;
  199. break;
  200. case '(':
  201. if (!openBracket && !openSingleQuote && !openDoubleQuote && !isEscaped)
  202. openBracket = true;
  203. isEscaped = false;
  204. break;
  205. case ')':
  206. if (openBracket && !isEscaped)
  207. openBracket = false;
  208. isEscaped = false;
  209. break;
  210. case ';':
  211. if (!isEscaped && !openSingleQuote && !openDoubleQuote && !openBracket)
  212. output = index;
  213. isEscaped = false;
  214. break;
  215. default:
  216. isEscaped = false;
  217. break;
  218. }
  219. if (output !== -1)
  220. break;
  221. index++;
  222. }
  223. return output;
  224. }
  225. var Property = /** @class */ (function () {
  226. function Property(name, value, comment, important) {
  227. if (important === void 0) { important = false; }
  228. this.meta = { type: 'utilities', group: 'plugin', order: 0, offset: 0, corePlugin: false };
  229. this.name = name;
  230. this.value = value;
  231. this.comment = comment;
  232. this.important = important;
  233. }
  234. Property._singleParse = function (css) {
  235. css = css.trim();
  236. if (!css)
  237. return;
  238. if (css.charAt(0) === '@')
  239. return InlineAtRule.parse(css);
  240. var split = css.search(':');
  241. var end = searchPropEnd(css);
  242. if (split === -1)
  243. return;
  244. var important = false;
  245. var prop = css.substring(split + 1, end === -1 ? undefined : end).trim();
  246. if (/!important;?$/.test(prop)) {
  247. important = true;
  248. prop = prop.replace(/!important/, '').trimRight();
  249. }
  250. return new Property(css.substring(0, split).trim(), prop, undefined, important);
  251. };
  252. Property.parse = function (css) {
  253. if (!/;\s*$/.test(css))
  254. css += ';'; // Fix for the situation where the last semicolon is omitted
  255. var properties = [];
  256. var index = 0;
  257. var end = searchPropEnd(css, index);
  258. while (end !== -1) {
  259. var parsed = this._singleParse(css.substring(searchFrom(css, /\S/, index), end + 1));
  260. if (parsed)
  261. properties.push(parsed);
  262. index = end + 1;
  263. end = searchPropEnd(css, index);
  264. }
  265. var count = properties.length;
  266. if (count > 1)
  267. return properties;
  268. if (count === 1)
  269. return properties[0];
  270. };
  271. Property.prototype.clone = function () {
  272. return deepCopy(this);
  273. };
  274. Property.prototype.toStyle = function (selector) {
  275. var style = new Style(selector, this, this.important);
  276. style.meta = this.meta;
  277. return style;
  278. };
  279. Property.prototype.build = function (minify) {
  280. var _this = this;
  281. if (minify === void 0) { minify = false; }
  282. var createProperty = function (name, value) {
  283. if (minify) {
  284. return "".concat(name, ":").concat(value).concat(_this.important ? '!important' : '', ";");
  285. }
  286. else {
  287. var p = "".concat(name, ": ").concat(value).concat(_this.important ? ' !important' : '', ";");
  288. return _this.comment ? p + " /* ".concat(_this.comment, " */") : p;
  289. }
  290. };
  291. if (!this.value)
  292. return '';
  293. return typeof this.name === 'string'
  294. ? createProperty(this.name, this.value)
  295. : this.name
  296. .map(function (i) { return createProperty(i, _this.value); })
  297. .join(minify ? '' : '\n');
  298. };
  299. Property.prototype.updateMeta = function (type, group, order, offset, corePlugin) {
  300. if (offset === void 0) { offset = 0; }
  301. if (corePlugin === void 0) { corePlugin = false; }
  302. this.meta = {
  303. type: type,
  304. group: group,
  305. order: order,
  306. offset: offset,
  307. corePlugin: corePlugin,
  308. };
  309. return this;
  310. };
  311. return Property;
  312. }());
  313. var InlineAtRule = /** @class */ (function (_super) {
  314. __extends(InlineAtRule, _super);
  315. function InlineAtRule(name, value, important) {
  316. if (important === void 0) { important = false; }
  317. var _this = _super.call(this, name, value, undefined, important) || this;
  318. _this.name = name;
  319. return _this;
  320. }
  321. InlineAtRule.parse = function (css) {
  322. var _a;
  323. var matchName = css.match(/@[^\s;{}]+/);
  324. if (matchName) {
  325. var name_1 = matchName[0].substring(1);
  326. var important = false;
  327. var expression = matchName.index !== undefined
  328. ? (_a = css
  329. .substring(matchName.index + name_1.length + 1)
  330. .match(/(?:(['"]).*?\1|[^;])*/)) === null || _a === void 0 ? void 0 : _a[0].trim()
  331. : undefined;
  332. if (expression && /!important;?$/.test(expression)) {
  333. important = true;
  334. expression = expression.replace(/!important/, '').trimRight();
  335. }
  336. return new InlineAtRule(name_1, expression === '' ? undefined : expression, important);
  337. }
  338. };
  339. InlineAtRule.prototype.build = function () {
  340. return this.value
  341. ? "@".concat(this.name, " ").concat(this.value).concat(this.important ? ' !important' : '', ";")
  342. : "@".concat(this.name).concat(this.important ? ' !important' : '', ";");
  343. };
  344. return InlineAtRule;
  345. }(Property));
  346. var Style = /** @class */ (function () {
  347. function Style(selector, property, important) {
  348. if (important === void 0) { important = false; }
  349. this.meta = { type: 'components', group: 'plugin', order: 0, offset: 0, corePlugin: false };
  350. this.selector = selector;
  351. this.important = important;
  352. this.property = toArray(property || []);
  353. }
  354. Object.defineProperty(Style.prototype, "rule", {
  355. get: function () {
  356. var _this = this;
  357. var _a, _b, _c;
  358. var selectors = ((_a = this.selector) !== null && _a !== void 0 ? _a : '').trim().split(/\s*,\s*/g);
  359. this._parentSelectors && (selectors = selectors.map(function (i) { var _a; return "".concat((_a = _this._parentSelectors) === null || _a === void 0 ? void 0 : _a.join(' '), " ").concat(i); }));
  360. ((_b = this._wrapSelectors) !== null && _b !== void 0 ? _b : []).forEach(function (func) { return (selectors = selectors.map(function (i) { return func(i); })); });
  361. this._pseudoClasses && (selectors = selectors.map(function (i) { var _a; return i + ":".concat((_a = _this._pseudoClasses) === null || _a === void 0 ? void 0 : _a.join(':')); }));
  362. this._pseudoElements && (selectors = selectors.map(function (i) { var _a; return i + "::".concat((_a = _this._pseudoElements) === null || _a === void 0 ? void 0 : _a.join('::')); }));
  363. this._brotherSelectors && (selectors = selectors.map(function (i) { var _a; return i + ".".concat((_a = _this._brotherSelectors) === null || _a === void 0 ? void 0 : _a.join('.')); }));
  364. this._childSelectors && (selectors = selectors.map(function (i) { var _a; return i + " ".concat((_a = _this._childSelectors) === null || _a === void 0 ? void 0 : _a.join(' ')); }));
  365. ((_c = this._wrapRules) !== null && _c !== void 0 ? _c : []).forEach(function (func) { return (selectors = selectors.map(function (i) { return func(i); })); });
  366. return selectors.join(', ');
  367. },
  368. enumerable: false,
  369. configurable: true
  370. });
  371. Object.defineProperty(Style.prototype, "pseudoClasses", {
  372. get: function () {
  373. return this._pseudoClasses;
  374. },
  375. enumerable: false,
  376. configurable: true
  377. });
  378. Object.defineProperty(Style.prototype, "pseudoElements", {
  379. get: function () {
  380. return this._pseudoElements;
  381. },
  382. enumerable: false,
  383. configurable: true
  384. });
  385. Object.defineProperty(Style.prototype, "parentSelectors", {
  386. get: function () {
  387. return this._parentSelectors;
  388. },
  389. enumerable: false,
  390. configurable: true
  391. });
  392. Object.defineProperty(Style.prototype, "childSelectors", {
  393. get: function () {
  394. return this._childSelectors;
  395. },
  396. enumerable: false,
  397. configurable: true
  398. });
  399. Object.defineProperty(Style.prototype, "brotherSelectors", {
  400. get: function () {
  401. return this._brotherSelectors;
  402. },
  403. enumerable: false,
  404. configurable: true
  405. });
  406. Object.defineProperty(Style.prototype, "wrapProperties", {
  407. get: function () {
  408. return this._wrapProperties;
  409. },
  410. enumerable: false,
  411. configurable: true
  412. });
  413. Object.defineProperty(Style.prototype, "wrapSelectors", {
  414. get: function () {
  415. return this._wrapSelectors;
  416. },
  417. enumerable: false,
  418. configurable: true
  419. });
  420. Object.defineProperty(Style.prototype, "wrapRules", {
  421. get: function () {
  422. return this._wrapRules;
  423. },
  424. enumerable: false,
  425. configurable: true
  426. });
  427. Object.defineProperty(Style.prototype, "simple", {
  428. get: function () {
  429. // is this style only has property and no wrap?
  430. return !(this.atRules || this._pseudoClasses || this._pseudoElements || this._parentSelectors || this._childSelectors || this._brotherSelectors || this._wrapProperties || this._wrapSelectors || this._wrapRules);
  431. },
  432. enumerable: false,
  433. configurable: true
  434. });
  435. Object.defineProperty(Style.prototype, "isAtrule", {
  436. get: function () {
  437. return !(this.atRules === undefined || this.atRules.length === 0);
  438. },
  439. enumerable: false,
  440. configurable: true
  441. });
  442. Style.generate = function (parent, property, root) {
  443. if (!root)
  444. root = (parent === null || parent === void 0 ? void 0 : parent.startsWith('@'))
  445. ? new Style().atRule(parent)
  446. : new Style(parent);
  447. var output = [];
  448. var _loop_1 = function (key, value) {
  449. var propertyValue = value;
  450. if (Array.isArray(propertyValue) && propertyValue.every(function (e) { return typeof e === 'object'; })) {
  451. propertyValue = Object.assign.apply(Object, __spreadArray([{}], propertyValue, false));
  452. }
  453. if (typeof propertyValue === 'string') {
  454. root.add(new Property(camelToDash(key), propertyValue));
  455. }
  456. else if (Array.isArray(propertyValue)) {
  457. propertyValue.map(function (i) { return root === null || root === void 0 ? void 0 : root.add(new Property(camelToDash(key), i)); });
  458. }
  459. else {
  460. var wrap = deepCopy(root);
  461. wrap.property = [];
  462. var child = void 0;
  463. if (key.startsWith('@')) {
  464. child = wrap.atRule(key, false);
  465. }
  466. else {
  467. if (wrap.selector === undefined) {
  468. wrap.selector = key;
  469. child = wrap;
  470. }
  471. else {
  472. if (/^[a-z]+$/.test(key) && !isTagName(key)) {
  473. wrap.wrapProperty(function (property) { return "".concat(key, "-").concat(property); });
  474. child = wrap;
  475. }
  476. else {
  477. var _hKey_1 = function (selector, key) { return (/&/.test(key) ? key : "& ".concat(key)).replace('&', selector); };
  478. wrap.wrapSelector(function (selector) {
  479. return selector
  480. .trim()
  481. .split(/\s*,\s*/g)
  482. .map(function (s) {
  483. return key
  484. .split(/\s*,\s*/g)
  485. .map(function (i) { return _hKey_1(s, i); })
  486. .join(', ');
  487. })
  488. .join(', ');
  489. });
  490. child = wrap;
  491. }
  492. }
  493. }
  494. output = output.concat(Style.generate(key.startsWith('@') ? undefined : key, propertyValue, child));
  495. }
  496. };
  497. for (var _i = 0, _a = Object.entries(property !== null && property !== void 0 ? property : {}); _i < _a.length; _i++) {
  498. var _b = _a[_i], key = _b[0], value = _b[1];
  499. _loop_1(key, value);
  500. }
  501. if (root.property.length > 0)
  502. output.unshift(root);
  503. return output;
  504. };
  505. Style.prototype.atRule = function (atrule, append) {
  506. if (append === void 0) { append = true; }
  507. if (!atrule)
  508. return this;
  509. if (this.atRules) {
  510. append ? this.atRules.push(atrule) : this.atRules.unshift(atrule);
  511. }
  512. else {
  513. this.atRules = [atrule];
  514. }
  515. return this;
  516. };
  517. Style.prototype.pseudoClass = function (string) {
  518. if (this._pseudoClasses) {
  519. this._pseudoClasses.push(string);
  520. }
  521. else {
  522. this._pseudoClasses = [string];
  523. }
  524. return this;
  525. };
  526. Style.prototype.pseudoElement = function (string) {
  527. if (this._pseudoElements) {
  528. this._pseudoElements.push(string);
  529. }
  530. else {
  531. this._pseudoElements = [string];
  532. }
  533. return this;
  534. };
  535. Style.prototype.brother = function (string) {
  536. if (this._brotherSelectors) {
  537. this._brotherSelectors.push(string);
  538. }
  539. else {
  540. this._brotherSelectors = [string];
  541. }
  542. return this;
  543. };
  544. Style.prototype.parent = function (string) {
  545. if (this._parentSelectors) {
  546. this._parentSelectors.push(string);
  547. }
  548. else {
  549. this._parentSelectors = [string];
  550. }
  551. return this;
  552. };
  553. Style.prototype.child = function (string) {
  554. if (this._childSelectors) {
  555. this._childSelectors.push(string);
  556. }
  557. else {
  558. this._childSelectors = [string];
  559. }
  560. return this;
  561. };
  562. Style.prototype.wrapProperty = function (func) {
  563. if (this._wrapProperties) {
  564. this._wrapProperties.push(func);
  565. }
  566. else {
  567. this._wrapProperties = [func];
  568. }
  569. return this;
  570. };
  571. Style.prototype.wrapSelector = function (func) {
  572. if (this._wrapSelectors) {
  573. this._wrapSelectors.push(func);
  574. }
  575. else {
  576. this._wrapSelectors = [func];
  577. }
  578. return this;
  579. };
  580. Style.prototype.wrapRule = function (func) {
  581. if (this._wrapRules) {
  582. this._wrapRules.push(func);
  583. }
  584. else {
  585. this._wrapRules = [func];
  586. }
  587. return this;
  588. };
  589. Style.prototype.add = function (item) {
  590. item = toArray(item);
  591. if (this.important)
  592. item.forEach(function (i) { return (i.important = true); });
  593. this.property = __spreadArray(__spreadArray([], this.property, true), item, true);
  594. return this;
  595. };
  596. Style.prototype.extend = function (item, onlyProperty, append) {
  597. if (onlyProperty === void 0) { onlyProperty = false; }
  598. if (append === void 0) { append = true; }
  599. if (!item)
  600. return this;
  601. if (item.wrapProperties) {
  602. var props_1 = [];
  603. item.property.forEach(function (p) {
  604. var _a;
  605. var pc = new Property(p.name, p.value, p.comment);
  606. (_a = item.wrapProperties) === null || _a === void 0 ? void 0 : _a.forEach(function (wrap) {
  607. pc.name = Array.isArray(pc.name)
  608. ? pc.name.map(function (i) { return wrap(i); })
  609. : wrap(pc.name);
  610. });
  611. if (item.important)
  612. pc.important = true;
  613. props_1.push(pc);
  614. });
  615. this.property = connectList(this.property, props_1, append);
  616. }
  617. else {
  618. if (item.important)
  619. item.property.forEach(function (i) { return (i.important = true); });
  620. this.property = connectList(this.property, item.property, append);
  621. }
  622. if (onlyProperty)
  623. return this;
  624. item.selector && (this.selector = item.selector);
  625. this.meta = item.meta;
  626. item.atRules &&
  627. (this.atRules = connectList(item.atRules, this.atRules, append)); // atrule is build in reverse
  628. item._brotherSelectors &&
  629. (this._brotherSelectors = connectList(this._brotherSelectors, item._brotherSelectors, append));
  630. item._childSelectors &&
  631. (this._childSelectors = connectList(this._childSelectors, item._childSelectors, append));
  632. item._parentSelectors &&
  633. (this._parentSelectors = connectList(this._parentSelectors, item._parentSelectors, append));
  634. item._pseudoClasses &&
  635. (this._pseudoClasses = connectList(this._pseudoClasses, item._pseudoClasses, append));
  636. item._pseudoElements &&
  637. (this._pseudoElements = connectList(this._pseudoElements, item._pseudoElements, append));
  638. item._wrapRules &&
  639. (this._wrapRules = connectList(this._wrapRules, item._wrapRules, append));
  640. item._wrapSelectors &&
  641. (this._wrapSelectors = connectList(this._wrapSelectors, item._wrapSelectors, append));
  642. return this;
  643. };
  644. Style.prototype.clean = function () {
  645. // remove duplicated property
  646. var property = [];
  647. var cache = [];
  648. this.property.forEach(function (i) {
  649. var inline = i.build();
  650. if (!cache.includes(inline)) {
  651. cache.push(inline);
  652. property.push(i);
  653. }
  654. });
  655. this.property = property;
  656. return this;
  657. };
  658. Style.prototype.flat = function () {
  659. var properties = [];
  660. this.property.forEach(function (p) {
  661. if (Array.isArray(p.name)) {
  662. p.name.forEach(function (i) {
  663. properties.push(new Property(i, p.value, p.comment));
  664. });
  665. }
  666. else {
  667. properties.push(p);
  668. }
  669. });
  670. this.property = properties;
  671. return this;
  672. };
  673. Style.prototype.clone = function (selector, property) {
  674. var newStyle = deepCopy(this);
  675. if (selector)
  676. newStyle.selector = selector;
  677. if (property)
  678. newStyle.property = Array.isArray(property) ? property : [property];
  679. return newStyle;
  680. };
  681. Style.prototype.sort = function () {
  682. // sort property
  683. this.property = this.property.sort(function (a, b) {
  684. return "".concat(a.name).substring(0, 2) > "".concat(b.name).substring(0, 2) ? 1 : -1;
  685. });
  686. return this;
  687. };
  688. Style.prototype.build = function (minify, prefixer) {
  689. var _this = this;
  690. if (minify === void 0) { minify = false; }
  691. if (prefixer === void 0) { prefixer = true; }
  692. var properties = this.property;
  693. if (!prefixer)
  694. properties = properties.filter(function (p) {
  695. if (p.value && /-(webkit|ms|moz|o)-/.test(p.value))
  696. return false;
  697. if (Array.isArray(p.name)) {
  698. p.name = p.name.filter(function (i) { return !/^-(webkit|ms|moz|o)-/.test(i); });
  699. return true;
  700. }
  701. return !/^-(webkit|ms|moz|o)-/.test(p.name);
  702. });
  703. var result = properties.map(function (p) {
  704. if (_this._wrapProperties) {
  705. var name_2 = p.name;
  706. _this._wrapProperties.forEach(function (w) { return (name_2 = Array.isArray(name_2) ? name_2.map(function (n) { return w(n); }) : w(name_2)); });
  707. return new Property(name_2, p.value, p.comment, _this.important ? true : p.important).build(minify);
  708. }
  709. return _this.important ? new Property(p.name, p.value, p.comment, true).build(minify) : p.build(minify);
  710. }).join(minify ? '' : '\n');
  711. if (!this.selector && !this.atRules)
  712. return result.replace(/;}/g, '}');
  713. if (this.selector)
  714. result = (minify ? this.rule.replace(/,\s/g, ',') : this.rule + ' ') + wrapit(result, undefined, undefined, undefined, result !== '' ? minify : true);
  715. if (this.atRules) {
  716. for (var _i = 0, _a = this.atRules; _i < _a.length; _i++) {
  717. var rule = _a[_i];
  718. result = minify ? "".concat(rule.replace(/\s/g, '')).concat(wrapit(result, undefined, undefined, undefined, minify)) : "".concat(rule, " ").concat(wrapit(result, undefined, undefined, undefined, result !== '' ? minify : true));
  719. }
  720. }
  721. return minify ? result.replace(/;}/g, '}') : result;
  722. };
  723. Style.prototype.updateMeta = function (type, group, order, offset, corePlugin, respectSelector) {
  724. if (offset === void 0) { offset = 0; }
  725. if (corePlugin === void 0) { corePlugin = false; }
  726. if (respectSelector === void 0) { respectSelector = false; }
  727. this.meta = {
  728. type: type,
  729. group: group,
  730. order: order,
  731. offset: offset,
  732. corePlugin: corePlugin,
  733. respectSelector: respectSelector,
  734. };
  735. return this;
  736. };
  737. return Style;
  738. }());
  739. /** @class */ ((function (_super) {
  740. __extends(GlobalStyle, _super);
  741. function GlobalStyle(selector, property, important) {
  742. return _super.call(this, selector, property, important) || this;
  743. }
  744. return GlobalStyle;
  745. })(Style));
  746. var Keyframes = /** @class */ (function (_super) {
  747. __extends(Keyframes, _super);
  748. function Keyframes(selector, property, important) {
  749. return _super.call(this, selector, property, important) || this;
  750. }
  751. // root param only for consist with style
  752. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  753. Keyframes.generate = function (name, children, root, prefixer) {
  754. if (prefixer === void 0) { prefixer = true; }
  755. var styles = [];
  756. var webkitStyles = [];
  757. for (var _i = 0, _a = Object.entries(children); _i < _a.length; _i++) {
  758. var _b = _a[_i], key = _b[0], value = _b[1];
  759. var style = new Keyframes(key).atRule("@keyframes ".concat(name));
  760. var webkitStyle = new Keyframes(key).atRule("@-webkit-keyframes ".concat(name));
  761. for (var _c = 0, _d = Object.entries(value); _c < _d.length; _c++) {
  762. var _e = _d[_c], pkey = _e[0], pvalue = _e[1];
  763. var prop = pkey;
  764. if (pkey === 'transform') {
  765. prop = prefixer ? ['-webkit-transform', 'transform'] : 'transform';
  766. }
  767. else if (['animationTimingFunction', 'animation-timing-function'].includes(pkey)) {
  768. prop = prefixer ? [
  769. '-webkit-animation-timing-function',
  770. 'animation-timing-function',
  771. ] : 'animation-timing-function';
  772. }
  773. style.add(new Property(prop, pvalue));
  774. webkitStyle.add(new Property(prop, pvalue));
  775. }
  776. styles.push(style);
  777. if (prefixer)
  778. webkitStyles.push(webkitStyle);
  779. }
  780. return __spreadArray(__spreadArray([], styles, true), webkitStyles, true);
  781. };
  782. return Keyframes;
  783. }(Style));
  784. /** @class */ ((function (_super) {
  785. __extends(Container, _super);
  786. function Container(selector, property, important) {
  787. return _super.call(this, selector, property, important) || this;
  788. }
  789. return Container;
  790. })(Style));
  791. var minMaxWidth = /(!?\(\s*min(-device-)?-width).+\(\s*max(-device)?-width/i;
  792. var minWidth = /\(\s*min(-device)?-width/i;
  793. var maxMinWidth = /(!?\(\s*max(-device)?-width).+\(\s*min(-device)?-width/i;
  794. var maxWidth = /\(\s*max(-device)?-width/i;
  795. var isMinWidth = _testQuery(minMaxWidth, maxMinWidth, minWidth);
  796. var isMaxWidth = _testQuery(maxMinWidth, minMaxWidth, maxWidth);
  797. var minMaxHeight = /(!?\(\s*min(-device)?-height).+\(\s*max(-device)?-height/i;
  798. var minHeight = /\(\s*min(-device)?-height/i;
  799. var maxMinHeight = /(!?\(\s*max(-device)?-height).+\(\s*min(-device)?-height/i;
  800. var maxHeight = /\(\s*max(-device)?-height/i;
  801. var isMinHeight = _testQuery(minMaxHeight, maxMinHeight, minHeight);
  802. var isMaxHeight = _testQuery(maxMinHeight, minMaxHeight, maxHeight);
  803. var isPrint = /print/i;
  804. var isPrintOnly = /^print\$/i;
  805. var isAtRule = /^\s*@/i;
  806. var isMedia = /^\s*@media/i;
  807. var maxValue = Number.MAX_VALUE;
  808. function _getQueryLength(length) {
  809. var result = /(-?\d*\.?\d+)(ch|em|ex|px|rpx|rem)/.exec(length);
  810. if (result === null) {
  811. return maxValue;
  812. }
  813. var number = result[1];
  814. var unit = result[2];
  815. switch (unit) {
  816. case 'ch':
  817. return parseFloat(number) * 8.8984375;
  818. case 'em':
  819. case 'rem':
  820. return parseFloat(number) * 16;
  821. case 'ex':
  822. return parseFloat(number) * 8.296875;
  823. case 'px':
  824. case 'rpx':
  825. return parseFloat(number);
  826. }
  827. return +number;
  828. }
  829. function _testQuery(doubleTestTrue, doubleTestFalse, singleTest) {
  830. return function (query) {
  831. if (doubleTestTrue.test(query)) {
  832. return true;
  833. }
  834. else if (doubleTestFalse.test(query)) {
  835. return false;
  836. }
  837. return singleTest.test(query);
  838. };
  839. }
  840. function _testAtRule(a, b) {
  841. var isMediaA = isMedia.test(a);
  842. var isMediaB = isMedia.test(b);
  843. if (isMediaA && isMediaB)
  844. return null;
  845. var isAtRuleA = isAtRule.test(a);
  846. var isAtRuleB = isAtRule.test(b);
  847. if (isAtRuleA)
  848. return 1;
  849. if (isAtRuleB)
  850. return -1;
  851. return 0; // don't sort selector name, may cause overwrite bug.
  852. }
  853. function _testIsPrint(a, b) {
  854. var isPrintA = isPrint.test(a);
  855. var isPrintOnlyA = isPrintOnly.test(a);
  856. var isPrintB = isPrint.test(b);
  857. var isPrintOnlyB = isPrintOnly.test(b);
  858. if (isPrintA && isPrintB) {
  859. if (!isPrintOnlyA && isPrintOnlyB) {
  860. return 1;
  861. }
  862. if (isPrintOnlyA && !isPrintOnlyB) {
  863. return -1;
  864. }
  865. return a.localeCompare(b);
  866. }
  867. if (isPrintA) {
  868. return 1;
  869. }
  870. if (isPrintB) {
  871. return -1;
  872. }
  873. return null;
  874. }
  875. function sortMediaQuery(a, b) {
  876. var testAtRule = _testAtRule(a, b);
  877. if (testAtRule !== null)
  878. return testAtRule;
  879. var testIsPrint = _testIsPrint(a, b);
  880. if (testIsPrint !== null)
  881. return testIsPrint;
  882. var minA = isMinWidth(a) || isMinHeight(a);
  883. var maxA = isMaxWidth(a) || isMaxHeight(a);
  884. var minB = isMinWidth(b) || isMinHeight(b);
  885. var maxB = isMaxWidth(b) || isMaxHeight(b);
  886. if (minA && maxB) {
  887. return -1;
  888. }
  889. if (maxA && minB) {
  890. return 1;
  891. }
  892. var lengthA = _getQueryLength(a);
  893. var lengthB = _getQueryLength(b);
  894. if (lengthA === maxValue && lengthB === maxValue) {
  895. return a.localeCompare(b);
  896. }
  897. else if (lengthA === maxValue) {
  898. return 1;
  899. }
  900. else if (lengthB === maxValue) {
  901. return -1;
  902. }
  903. if (lengthA > lengthB) {
  904. if (maxA) {
  905. return -1;
  906. }
  907. return 1;
  908. }
  909. if (lengthA < lengthB) {
  910. if (maxA) {
  911. return 1;
  912. }
  913. return -1;
  914. }
  915. return a.localeCompare(b);
  916. }
  917. function getWeights(a) {
  918. var first = a.charAt(0);
  919. var second = a.charAt(1);
  920. if (first === ':' && second === ':')
  921. return 59; // ::moz ...
  922. if (first === '#')
  923. return 500; // #id ...
  924. if (first !== '.')
  925. return first.charCodeAt(0); // html, body ...
  926. return 499;
  927. }
  928. function sortMeta(a, b) {
  929. var _a, _b, _c, _d;
  930. if (a.meta.type === 'base' && b.meta.type === 'base')
  931. return getWeights((_a = a.selector) !== null && _a !== void 0 ? _a : '') - getWeights((_b = b.selector) !== null && _b !== void 0 ? _b : '');
  932. return sortMediaQuery(((_c = a.meta.variants) === null || _c === void 0 ? void 0 : _c[0]) || '', ((_d = b.meta.variants) === null || _d === void 0 ? void 0 : _d[0]) || '') || (a.meta.order - b.meta.order) || (a.meta.offset - b.meta.offset) || +b.meta.corePlugin - +a.meta.corePlugin;
  933. }
  934. function _buildAtrule(atrule, children, minify, prefixer) {
  935. if (minify === void 0) { minify = false; }
  936. if (prefixer === void 0) { prefixer = true; }
  937. return "".concat(atrule).concat(minify ? '' : ' ').concat(wrapit(_buildStyleList(children, minify, prefixer), undefined, undefined, undefined, minify));
  938. }
  939. function _buildStyleList(styleList, minify, prefixer) {
  940. if (minify === void 0) { minify = false; }
  941. if (prefixer === void 0) { prefixer = true; }
  942. var currentAtrule;
  943. var currentStyle;
  944. var styleStack = [];
  945. var output = [];
  946. var _loop_1 = function (style) {
  947. if (style.isAtrule) {
  948. if (currentStyle) {
  949. output.push(currentStyle.clean().build(minify, prefixer));
  950. currentStyle = undefined;
  951. }
  952. var newAtrule = style.atRules.pop();
  953. if (currentAtrule) {
  954. if (currentAtrule === newAtrule && newAtrule !== '@font-face') { // @font-face shouldn't been combined
  955. styleStack.push(style);
  956. }
  957. else {
  958. output.push(_buildAtrule(currentAtrule, styleStack, minify, prefixer));
  959. currentAtrule = newAtrule;
  960. styleStack = [style];
  961. }
  962. }
  963. else {
  964. currentAtrule = newAtrule;
  965. styleStack = [style];
  966. }
  967. }
  968. else {
  969. if (currentAtrule) {
  970. output.push(_buildAtrule(currentAtrule, styleStack, minify, prefixer));
  971. currentAtrule = undefined;
  972. styleStack = [];
  973. }
  974. if (currentStyle) {
  975. if (style.rule === currentStyle.rule) {
  976. if (style.important)
  977. style.property.forEach(function (p) { return p.important = true; });
  978. if (style.wrapProperties)
  979. style.property.forEach(function (p) { var _a; return (_a = style.wrapProperties) === null || _a === void 0 ? void 0 : _a.forEach(function (wrap) { return p.name = Array.isArray(p.name) ? p.name.map(function (i) { return wrap(i); }) : wrap(p.name); }); });
  980. currentStyle.add(style.property);
  981. }
  982. else {
  983. output.push(currentStyle.clean().build(minify, prefixer));
  984. currentStyle = style;
  985. }
  986. }
  987. else {
  988. currentStyle = style;
  989. }
  990. }
  991. };
  992. for (var _i = 0, styleList_1 = styleList; _i < styleList_1.length; _i++) {
  993. var style = styleList_1[_i];
  994. _loop_1(style);
  995. }
  996. if (currentAtrule)
  997. output.push(_buildAtrule(currentAtrule, styleStack, minify, prefixer));
  998. if (currentStyle)
  999. output.push(currentStyle.clean().build(minify, prefixer));
  1000. return output.join(minify ? '' : '\n');
  1001. }
  1002. function compileStyleSheet (styleList, minify, prefixer) {
  1003. if (minify === void 0) { minify = false; }
  1004. if (prefixer === void 0) { prefixer = true; }
  1005. return _buildStyleList(deepCopy(styleList), minify, prefixer);
  1006. }
  1007. var StyleSheet = /** @class */ (function () {
  1008. function StyleSheet(children) {
  1009. this.prefixer = true;
  1010. this.children = children || [];
  1011. }
  1012. StyleSheet.prototype.add = function (item) {
  1013. if (!item)
  1014. return this;
  1015. if (Array.isArray(item)) {
  1016. this.children = __spreadArray(__spreadArray([], this.children, true), item, true);
  1017. }
  1018. else {
  1019. this.children.push(item);
  1020. }
  1021. return this;
  1022. };
  1023. StyleSheet.prototype.extend = function (styleSheet, append, dedup) {
  1024. if (append === void 0) { append = true; }
  1025. if (dedup === void 0) { dedup = false; }
  1026. if (styleSheet) {
  1027. var extended = styleSheet.children;
  1028. if (dedup) {
  1029. var hashes_1 = extended.map(function (i) { return hash(i.build()); });
  1030. extended = extended.filter(function (i) { return !hashes_1.includes(hash(i.build())); });
  1031. }
  1032. this.prefixer = styleSheet.prefixer;
  1033. this.children = append ? __spreadArray(__spreadArray([], this.children, true), extended, true) : __spreadArray(__spreadArray([], extended, true), this.children, true);
  1034. }
  1035. return this;
  1036. };
  1037. StyleSheet.prototype.combine = function () {
  1038. var styleMap = {};
  1039. this.children.forEach(function (style, index) {
  1040. var _a;
  1041. var hashValue = hash(style.atRules + style.meta.type + style.rule);
  1042. if (hashValue in styleMap) {
  1043. if ((_a = style.atRules) === null || _a === void 0 ? void 0 : _a.includes('@font-face')) {
  1044. // keeps multiple @font-face
  1045. styleMap[hashValue + index] = style;
  1046. }
  1047. else {
  1048. styleMap[hashValue] = styleMap[hashValue].extend(style, true);
  1049. }
  1050. }
  1051. else {
  1052. styleMap[hashValue] = style;
  1053. }
  1054. });
  1055. this.children = Object.values(styleMap).map(function (i) { return i.clean(); });
  1056. return this;
  1057. };
  1058. StyleSheet.prototype.layer = function (type) {
  1059. var styleSheet = new StyleSheet(this.children.filter(function (i) { return i.meta.type === type; }));
  1060. styleSheet.prefixer = this.prefixer;
  1061. return styleSheet;
  1062. };
  1063. StyleSheet.prototype.split = function () {
  1064. return {
  1065. base: this.layer('base'),
  1066. components: this.layer('components'),
  1067. utilities: this.layer('utilities'),
  1068. };
  1069. };
  1070. StyleSheet.prototype.clone = function () {
  1071. return deepCopy(this);
  1072. };
  1073. StyleSheet.prototype.sort = function () {
  1074. this.children = this.children.sort(sortMeta);
  1075. return this;
  1076. };
  1077. StyleSheet.prototype.sortby = function (compareFn) {
  1078. this.children = this.children.sort(compareFn);
  1079. return this;
  1080. };
  1081. StyleSheet.prototype.build = function (minify) {
  1082. if (minify === void 0) { minify = false; }
  1083. return compileStyleSheet(this.children, minify, this.prefixer);
  1084. };
  1085. return StyleSheet;
  1086. }());
  1087. var pseudoClassNames = [
  1088. 'hover',
  1089. 'focus',
  1090. 'active',
  1091. 'visited',
  1092. 'link',
  1093. 'target',
  1094. 'focus-visible',
  1095. 'focus-within',
  1096. 'checked',
  1097. 'default',
  1098. 'disabled',
  1099. 'enabled',
  1100. 'indeterminate',
  1101. 'invalid',
  1102. 'valid',
  1103. 'optional',
  1104. 'required',
  1105. 'placeholder-shown',
  1106. 'read-only',
  1107. 'read-write',
  1108. 'first-of-type',
  1109. 'last-of-type',
  1110. 'only-child',
  1111. 'only-of-type',
  1112. 'root',
  1113. 'empty',
  1114. ];
  1115. __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], pseudoClassNames, true), [
  1116. 'not-checked',
  1117. 'not-disabled',
  1118. 'not-first-of-type',
  1119. 'not-last-of-type',
  1120. 'first',
  1121. 'not-first',
  1122. 'last',
  1123. 'not-last',
  1124. 'not-only-child',
  1125. 'not-only-of-type',
  1126. 'even',
  1127. 'odd',
  1128. 'even-of-type',
  1129. 'odd-of-type',
  1130. 'before',
  1131. 'after',
  1132. 'first-letter',
  1133. 'first-line',
  1134. 'file-selector-button',
  1135. 'file',
  1136. 'selection',
  1137. 'marker',
  1138. 'svg',
  1139. 'all',
  1140. 'children',
  1141. 'siblings',
  1142. 'sibling',
  1143. 'ltr',
  1144. 'rtl'
  1145. ], false), pseudoClassNames.map(function (pseudoClassName) { return "group-".concat(pseudoClassName); }), true), [
  1146. 'motion-safe',
  1147. 'motion-reduce'
  1148. ], false), pseudoClassNames.map(function (pseudoClassName) { return "peer-".concat(pseudoClassName); }), true), pseudoClassNames.map(function (pseudoClassName) { return "peer-not-".concat(pseudoClassName); }), true);
  1149. var layerOrder;
  1150. (function (layerOrder) {
  1151. layerOrder[layerOrder["base"] = 10] = "base";
  1152. layerOrder[layerOrder["components"] = 150] = "components";
  1153. layerOrder[layerOrder["shortcuts"] = 160] = "shortcuts";
  1154. layerOrder[layerOrder["utilities"] = 20000] = "utilities";
  1155. })(layerOrder || (layerOrder = {}));
  1156. var pluginOrder;
  1157. (function (pluginOrder) {
  1158. pluginOrder[pluginOrder["columns"] = 80] = "columns";
  1159. pluginOrder[pluginOrder["container"] = 100] = "container";
  1160. pluginOrder[pluginOrder["space"] = 200] = "space";
  1161. pluginOrder[pluginOrder["divideWidth"] = 300] = "divideWidth";
  1162. pluginOrder[pluginOrder["divideColor"] = 400] = "divideColor";
  1163. pluginOrder[pluginOrder["divideStyle"] = 500] = "divideStyle";
  1164. pluginOrder[pluginOrder["divideOpacity"] = 600] = "divideOpacity";
  1165. pluginOrder[pluginOrder["accessibility"] = 700] = "accessibility";
  1166. pluginOrder[pluginOrder["appearance"] = 800] = "appearance";
  1167. pluginOrder[pluginOrder["backgroundAttachment"] = 900] = "backgroundAttachment";
  1168. pluginOrder[pluginOrder["backgroundClip"] = 1000] = "backgroundClip";
  1169. pluginOrder[pluginOrder["backgroundColor"] = 1100] = "backgroundColor";
  1170. pluginOrder[pluginOrder["backgroundImage"] = 1200] = "backgroundImage";
  1171. pluginOrder[pluginOrder["gradientColorStops"] = 1300] = "gradientColorStops";
  1172. pluginOrder[pluginOrder["backgroundOpacity"] = 1400] = "backgroundOpacity";
  1173. pluginOrder[pluginOrder["backgroundPosition"] = 1500] = "backgroundPosition";
  1174. pluginOrder[pluginOrder["backgroundRepeat"] = 1600] = "backgroundRepeat";
  1175. pluginOrder[pluginOrder["backgroundSize"] = 1700] = "backgroundSize";
  1176. pluginOrder[pluginOrder["backgroundOrigin"] = 1750] = "backgroundOrigin";
  1177. pluginOrder[pluginOrder["borderCollapse"] = 1800] = "borderCollapse";
  1178. pluginOrder[pluginOrder["borderColor"] = 1900] = "borderColor";
  1179. pluginOrder[pluginOrder["borderOpacity"] = 2000] = "borderOpacity";
  1180. pluginOrder[pluginOrder["borderRadius"] = 2100] = "borderRadius";
  1181. pluginOrder[pluginOrder["borderStyle"] = 2200] = "borderStyle";
  1182. pluginOrder[pluginOrder["borderWidth"] = 2300] = "borderWidth";
  1183. pluginOrder[pluginOrder["boxDecorationBreak"] = 2350] = "boxDecorationBreak";
  1184. pluginOrder[pluginOrder["boxSizing"] = 2400] = "boxSizing";
  1185. pluginOrder[pluginOrder["cursor"] = 2500] = "cursor";
  1186. pluginOrder[pluginOrder["captionSide"] = 2550] = "captionSide";
  1187. pluginOrder[pluginOrder["emptyCells"] = 2560] = "emptyCells";
  1188. pluginOrder[pluginOrder["display"] = 2600] = "display";
  1189. pluginOrder[pluginOrder["flexBasis"] = 2699] = "flexBasis";
  1190. pluginOrder[pluginOrder["flexDirection"] = 2700] = "flexDirection";
  1191. pluginOrder[pluginOrder["flexWrap"] = 2800] = "flexWrap";
  1192. pluginOrder[pluginOrder["placeItems"] = 2900] = "placeItems";
  1193. pluginOrder[pluginOrder["placeContent"] = 3000] = "placeContent";
  1194. pluginOrder[pluginOrder["placeSelf"] = 3100] = "placeSelf";
  1195. pluginOrder[pluginOrder["alignItems"] = 3200] = "alignItems";
  1196. pluginOrder[pluginOrder["alignContent"] = 3300] = "alignContent";
  1197. pluginOrder[pluginOrder["alignSelf"] = 3400] = "alignSelf";
  1198. pluginOrder[pluginOrder["justifyItems"] = 3500] = "justifyItems";
  1199. pluginOrder[pluginOrder["justifyContent"] = 3600] = "justifyContent";
  1200. pluginOrder[pluginOrder["justifySelf"] = 3700] = "justifySelf";
  1201. pluginOrder[pluginOrder["flex"] = 3800] = "flex";
  1202. pluginOrder[pluginOrder["flexGrow"] = 3900] = "flexGrow";
  1203. pluginOrder[pluginOrder["flexShrink"] = 4000] = "flexShrink";
  1204. pluginOrder[pluginOrder["order"] = 4100] = "order";
  1205. pluginOrder[pluginOrder["float"] = 4200] = "float";
  1206. pluginOrder[pluginOrder["clear"] = 4300] = "clear";
  1207. pluginOrder[pluginOrder["fontFamily"] = 4400] = "fontFamily";
  1208. pluginOrder[pluginOrder["fontWeight"] = 4500] = "fontWeight";
  1209. pluginOrder[pluginOrder["height"] = 4600] = "height";
  1210. pluginOrder[pluginOrder["fontSize"] = 4700] = "fontSize";
  1211. pluginOrder[pluginOrder["lineHeight"] = 4800] = "lineHeight";
  1212. pluginOrder[pluginOrder["listStylePosition"] = 4900] = "listStylePosition";
  1213. pluginOrder[pluginOrder["listStyleType"] = 5000] = "listStyleType";
  1214. pluginOrder[pluginOrder["margin"] = 5100] = "margin";
  1215. pluginOrder[pluginOrder["maxHeight"] = 5200] = "maxHeight";
  1216. pluginOrder[pluginOrder["maxWidth"] = 5300] = "maxWidth";
  1217. pluginOrder[pluginOrder["minHeight"] = 5400] = "minHeight";
  1218. pluginOrder[pluginOrder["minWidth"] = 5500] = "minWidth";
  1219. pluginOrder[pluginOrder["objectFit"] = 5600] = "objectFit";
  1220. pluginOrder[pluginOrder["objectPosition"] = 5700] = "objectPosition";
  1221. pluginOrder[pluginOrder["opacity"] = 5800] = "opacity";
  1222. pluginOrder[pluginOrder["outline"] = 5900] = "outline";
  1223. pluginOrder[pluginOrder["overflow"] = 6000] = "overflow";
  1224. pluginOrder[pluginOrder["overscrollBehavior"] = 6100] = "overscrollBehavior";
  1225. pluginOrder[pluginOrder["padding"] = 6200] = "padding";
  1226. pluginOrder[pluginOrder["placeholderColor"] = 6300] = "placeholderColor";
  1227. pluginOrder[pluginOrder["placeholderOpacity"] = 6400] = "placeholderOpacity";
  1228. pluginOrder[pluginOrder["caretColor"] = 6450] = "caretColor";
  1229. pluginOrder[pluginOrder["caretOpacity"] = 6460] = "caretOpacity";
  1230. pluginOrder[pluginOrder["tabSize"] = 6470] = "tabSize";
  1231. pluginOrder[pluginOrder["pointerEvents"] = 6500] = "pointerEvents";
  1232. pluginOrder[pluginOrder["position"] = 6600] = "position";
  1233. pluginOrder[pluginOrder["inset"] = 6700] = "inset";
  1234. pluginOrder[pluginOrder["resize"] = 6800] = "resize";
  1235. pluginOrder[pluginOrder["boxShadow"] = 6900] = "boxShadow";
  1236. pluginOrder[pluginOrder["boxShadowColor"] = 6950] = "boxShadowColor";
  1237. pluginOrder[pluginOrder["ringWidth"] = 7000] = "ringWidth";
  1238. pluginOrder[pluginOrder["ringOffsetColor"] = 7100] = "ringOffsetColor";
  1239. pluginOrder[pluginOrder["ringOffsetWidth"] = 7200] = "ringOffsetWidth";
  1240. pluginOrder[pluginOrder["ringColor"] = 7300] = "ringColor";
  1241. pluginOrder[pluginOrder["ringOpacity"] = 7400] = "ringOpacity";
  1242. pluginOrder[pluginOrder["fill"] = 7500] = "fill";
  1243. pluginOrder[pluginOrder["stroke"] = 7600] = "stroke";
  1244. pluginOrder[pluginOrder["strokeWidth"] = 7700] = "strokeWidth";
  1245. pluginOrder[pluginOrder["strokeDashArray"] = 7750] = "strokeDashArray";
  1246. pluginOrder[pluginOrder["strokeDashOffset"] = 7760] = "strokeDashOffset";
  1247. pluginOrder[pluginOrder["tableLayout"] = 7800] = "tableLayout";
  1248. pluginOrder[pluginOrder["textAlign"] = 7900] = "textAlign";
  1249. pluginOrder[pluginOrder["textColor"] = 8000] = "textColor";
  1250. pluginOrder[pluginOrder["textOpacity"] = 8100] = "textOpacity";
  1251. pluginOrder[pluginOrder["textOverflow"] = 8200] = "textOverflow";
  1252. pluginOrder[pluginOrder["textShadow"] = 8250] = "textShadow";
  1253. pluginOrder[pluginOrder["fontStyle"] = 8300] = "fontStyle";
  1254. pluginOrder[pluginOrder["textTransform"] = 8400] = "textTransform";
  1255. pluginOrder[pluginOrder["textDecorationStyle"] = 8450] = "textDecorationStyle";
  1256. pluginOrder[pluginOrder["textDecorationLength"] = 8455] = "textDecorationLength";
  1257. pluginOrder[pluginOrder["textDecorationColor"] = 8460] = "textDecorationColor";
  1258. pluginOrder[pluginOrder["textDecorationOpacity"] = 8470] = "textDecorationOpacity";
  1259. pluginOrder[pluginOrder["textDecorationOffset"] = 8480] = "textDecorationOffset";
  1260. pluginOrder[pluginOrder["textDecorationThickness"] = 8490] = "textDecorationThickness";
  1261. pluginOrder[pluginOrder["textDecoration"] = 8500] = "textDecoration";
  1262. pluginOrder[pluginOrder["textIndent"] = 8550] = "textIndent";
  1263. pluginOrder[pluginOrder["textStrokeColor"] = 8560] = "textStrokeColor";
  1264. pluginOrder[pluginOrder["textStrokeWidth"] = 8570] = "textStrokeWidth";
  1265. pluginOrder[pluginOrder["content"] = 8580] = "content";
  1266. pluginOrder[pluginOrder["fontSmoothing"] = 8600] = "fontSmoothing";
  1267. pluginOrder[pluginOrder["fontVariantNumeric"] = 8700] = "fontVariantNumeric";
  1268. pluginOrder[pluginOrder["letterSpacing"] = 8800] = "letterSpacing";
  1269. pluginOrder[pluginOrder["userSelect"] = 8900] = "userSelect";
  1270. pluginOrder[pluginOrder["verticalAlign"] = 9000] = "verticalAlign";
  1271. pluginOrder[pluginOrder["visibility"] = 9100] = "visibility";
  1272. pluginOrder[pluginOrder["backfaceVisibility"] = 9150] = "backfaceVisibility";
  1273. pluginOrder[pluginOrder["whitespace"] = 9200] = "whitespace";
  1274. pluginOrder[pluginOrder["wordBreak"] = 9300] = "wordBreak";
  1275. pluginOrder[pluginOrder["writingMode"] = 9340] = "writingMode";
  1276. pluginOrder[pluginOrder["hyphens"] = 9350] = "hyphens";
  1277. pluginOrder[pluginOrder["width"] = 9400] = "width";
  1278. pluginOrder[pluginOrder["zIndex"] = 9500] = "zIndex";
  1279. pluginOrder[pluginOrder["isolation"] = 9550] = "isolation";
  1280. pluginOrder[pluginOrder["gap"] = 9600] = "gap";
  1281. pluginOrder[pluginOrder["gridAutoFlow"] = 9700] = "gridAutoFlow";
  1282. pluginOrder[pluginOrder["gridTemplateColumns"] = 9800] = "gridTemplateColumns";
  1283. pluginOrder[pluginOrder["gridAutoColumns"] = 9900] = "gridAutoColumns";
  1284. pluginOrder[pluginOrder["gridColumn"] = 10000] = "gridColumn";
  1285. pluginOrder[pluginOrder["gridColumnStart"] = 10100] = "gridColumnStart";
  1286. pluginOrder[pluginOrder["gridColumnEnd"] = 10200] = "gridColumnEnd";
  1287. pluginOrder[pluginOrder["gridTemplateRows"] = 10300] = "gridTemplateRows";
  1288. pluginOrder[pluginOrder["gridAutoRows"] = 10400] = "gridAutoRows";
  1289. pluginOrder[pluginOrder["gridRow"] = 10500] = "gridRow";
  1290. pluginOrder[pluginOrder["gridRowStart"] = 10600] = "gridRowStart";
  1291. pluginOrder[pluginOrder["gridRowEnd"] = 10700] = "gridRowEnd";
  1292. pluginOrder[pluginOrder["transform"] = 10800] = "transform";
  1293. pluginOrder[pluginOrder["transformOrigin"] = 10900] = "transformOrigin";
  1294. pluginOrder[pluginOrder["scale"] = 11000] = "scale";
  1295. pluginOrder[pluginOrder["rotate"] = 11100] = "rotate";
  1296. pluginOrder[pluginOrder["translate"] = 11200] = "translate";
  1297. pluginOrder[pluginOrder["skew"] = 11300] = "skew";
  1298. pluginOrder[pluginOrder["perspective"] = 11350] = "perspective";
  1299. pluginOrder[pluginOrder["perspectiveOrigin"] = 11360] = "perspectiveOrigin";
  1300. pluginOrder[pluginOrder["transitionProperty"] = 11400] = "transitionProperty";
  1301. pluginOrder[pluginOrder["transitionTimingFunction"] = 11500] = "transitionTimingFunction";
  1302. pluginOrder[pluginOrder["transitionDuration"] = 11600] = "transitionDuration";
  1303. pluginOrder[pluginOrder["transitionDelay"] = 11700] = "transitionDelay";
  1304. pluginOrder[pluginOrder["keyframes"] = 11800] = "keyframes";
  1305. pluginOrder[pluginOrder["animation"] = 11900] = "animation";
  1306. pluginOrder[pluginOrder["imageRendering"] = 11950] = "imageRendering";
  1307. pluginOrder[pluginOrder["mixBlendMode"] = 12000] = "mixBlendMode";
  1308. pluginOrder[pluginOrder["backgroundBlendMode"] = 12100] = "backgroundBlendMode";
  1309. pluginOrder[pluginOrder["filter"] = 12200] = "filter";
  1310. pluginOrder[pluginOrder["blur"] = 12300] = "blur";
  1311. pluginOrder[pluginOrder["brightness"] = 12400] = "brightness";
  1312. pluginOrder[pluginOrder["contrast"] = 12500] = "contrast";
  1313. pluginOrder[pluginOrder["dropShadow"] = 12600] = "dropShadow";
  1314. pluginOrder[pluginOrder["grayscale"] = 12700] = "grayscale";
  1315. pluginOrder[pluginOrder["hueRotate"] = 12800] = "hueRotate";
  1316. pluginOrder[pluginOrder["invert"] = 12900] = "invert";
  1317. pluginOrder[pluginOrder["saturate"] = 13000] = "saturate";
  1318. pluginOrder[pluginOrder["sepia"] = 13100] = "sepia";
  1319. pluginOrder[pluginOrder["backdropFilter"] = 13200] = "backdropFilter";
  1320. pluginOrder[pluginOrder["backdropBlur"] = 13300] = "backdropBlur";
  1321. pluginOrder[pluginOrder["backdropBrightness"] = 13400] = "backdropBrightness";
  1322. pluginOrder[pluginOrder["backdropContrast"] = 13500] = "backdropContrast";
  1323. pluginOrder[pluginOrder["backdropGrayscale"] = 13600] = "backdropGrayscale";
  1324. pluginOrder[pluginOrder["backdropHueRotate"] = 13700] = "backdropHueRotate";
  1325. pluginOrder[pluginOrder["backdropInvert"] = 13800] = "backdropInvert";
  1326. pluginOrder[pluginOrder["backdropOpacity"] = 13900] = "backdropOpacity";
  1327. pluginOrder[pluginOrder["backdropSaturate"] = 14000] = "backdropSaturate";
  1328. pluginOrder[pluginOrder["backdropSepia"] = 14100] = "backdropSepia";
  1329. pluginOrder[pluginOrder["willChange"] = 14200] = "willChange";
  1330. pluginOrder[pluginOrder["touchAction"] = 14300] = "touchAction";
  1331. pluginOrder[pluginOrder["scrollBehavior"] = 14400] = "scrollBehavior";
  1332. pluginOrder[pluginOrder["accentColor"] = 14500] = "accentColor";
  1333. })(pluginOrder || (pluginOrder = {}));
  1334. var CSSParser = /** @class */ (function () {
  1335. function CSSParser(css, processor) {
  1336. this.variables = {};
  1337. this._cache = {};
  1338. this.css = css;
  1339. this.processor = processor;
  1340. }
  1341. CSSParser.prototype._addCache = function (style) {
  1342. var rule = style.rule;
  1343. if (['.', '#'].includes(rule.charAt(0)))
  1344. this._cache[rule] = (rule in this._cache) ? __spreadArray(__spreadArray([], this._cache[rule], true), [deepCopy(style)], false) : [deepCopy(style)];
  1345. };
  1346. CSSParser.prototype._searchGroup = function (text, startIndex) {
  1347. if (startIndex === void 0) { startIndex = 0; }
  1348. var level = 1;
  1349. var endBracket = searchFrom(text, '}', startIndex);
  1350. while (endBracket !== -1) {
  1351. var nextBracket = searchFrom(text, '{', startIndex);
  1352. if (endBracket < nextBracket || nextBracket === -1) {
  1353. level--;
  1354. startIndex = endBracket + 1;
  1355. if (level === 0)
  1356. return endBracket;
  1357. }
  1358. else {
  1359. level++;
  1360. startIndex = nextBracket + 1;
  1361. }
  1362. endBracket = searchFrom(text, '}', startIndex);
  1363. }
  1364. return -1;
  1365. };
  1366. CSSParser.prototype._loadTheme = function (prop) {
  1367. if (!prop)
  1368. return;
  1369. if (!this.processor)
  1370. return prop;
  1371. var index = 0;
  1372. var output = [];
  1373. while (index < prop.length) {
  1374. var matched = prop.slice(index).match(/theme\([^)]*?\)/);
  1375. if (!matched || matched.index === undefined)
  1376. break;
  1377. output.push(prop.slice(index, index + matched.index));
  1378. var args = matched[0].slice(6, -1).split(/\s*,\s*/).map(function (i) { return i.trim().replace(/^['"]+|['"]+$/g, ''); });
  1379. output.push(this.processor.theme(args[0], args[1]));
  1380. index += matched.index + matched[0].length;
  1381. }
  1382. output.push(prop.slice(index));
  1383. return output.join('');
  1384. };
  1385. CSSParser.prototype._handleDirectives = function (atrule) {
  1386. var _a, _b, _c;
  1387. if (!this.processor)
  1388. return { atrule: atrule };
  1389. var iatrule = InlineAtRule.parse(atrule);
  1390. if (!iatrule)
  1391. return;
  1392. if (iatrule.name === 'apply')
  1393. return { apply: iatrule.value, important: iatrule.important };
  1394. if (iatrule.name === 'layer')
  1395. return { layer: ((_a = iatrule.value) !== null && _a !== void 0 ? _a : 'components') };
  1396. if (iatrule.name === 'variants' && iatrule.value)
  1397. return { variants: iatrule.value.split(',').map(function (i) { return i.trim().split(':'); }) };
  1398. if (iatrule.name === 'screen' && iatrule.value) {
  1399. var screens = this.processor.resolveVariants('screen');
  1400. if (iatrule.value in screens)
  1401. return { atrule: (_c = (_b = screens[iatrule.value]().atRules) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : atrule };
  1402. if (['dark', 'light'].includes(iatrule.value))
  1403. return { atrule: "@media (prefers-color-scheme: ".concat(iatrule.value, ")") };
  1404. }
  1405. return { atrule: atrule };
  1406. };
  1407. CSSParser.prototype._generateNestProperty = function (props, parent, parentType) {
  1408. var style = new Style(undefined, props);
  1409. if (!parent || !parentType)
  1410. return style;
  1411. if (parentType === 'selector') {
  1412. style.selector = parent;
  1413. return style;
  1414. }
  1415. return style.atRule(parent);
  1416. };
  1417. CSSParser.prototype._generateNestStyle = function (styles, parent, parentType) {
  1418. var _this = this;
  1419. var layer = 'utilities';
  1420. var order = layerOrder['utilities'] + 1;
  1421. var group = 'block';
  1422. if (!parent)
  1423. return styles;
  1424. if (parentType === 'selector') {
  1425. styles.forEach(function (i) {
  1426. if (i instanceof Keyframes)
  1427. return;
  1428. if (!i.selector) {
  1429. i.selector = parent;
  1430. }
  1431. else {
  1432. var selector_1 = i.selector;
  1433. selector_1 = selector_1.trim().split(/\s*,\s*/g).map(function (i) { return /&/.test(i) ? i : "& ".concat(i); }).join(', ');
  1434. i.selector = /\s*,\s*/.test(parent) ? parent.trim().split(/\s*,\s*/g).map(function (i) { return selector_1.replace(/&/g, i); }).join(', ') : selector_1.replace(/&/g, parent);
  1435. }
  1436. i.updateMeta(layer, group, order);
  1437. _this._addCache(i);
  1438. });
  1439. }
  1440. else if (parentType === 'atRule') {
  1441. var atrule_1 = parent;
  1442. if (this.processor) {
  1443. // handle directives
  1444. var directives = this._handleDirectives(parent);
  1445. if (directives) {
  1446. if ('atrule' in directives) {
  1447. // @screen
  1448. atrule_1 = directives.atrule;
  1449. }
  1450. else if ('layer' in directives) {
  1451. // @layer
  1452. atrule_1 = undefined;
  1453. layer = directives.layer;
  1454. order = layerOrder[layer];
  1455. group = 'layer-block';
  1456. }
  1457. else if ('variants' in directives) {
  1458. // @variants
  1459. var output = [];
  1460. for (var _i = 0, _a = directives.variants; _i < _a.length; _i++) {
  1461. var variant = _a[_i];
  1462. var wrapper = this.processor.wrapWithVariants(variant, styles);
  1463. if (wrapper)
  1464. output = output.concat(wrapper);
  1465. }
  1466. output.map(function (i) {
  1467. i.updateMeta(layer, group, order);
  1468. _this._addCache(i);
  1469. });
  1470. return output;
  1471. }
  1472. }
  1473. }
  1474. styles.filter(function (i) { return !(i instanceof Keyframes); }).forEach(function (i) {
  1475. i.atRule(atrule_1);
  1476. i.updateMeta(layer, group, order);
  1477. _this._addCache(i);
  1478. });
  1479. }
  1480. return styles;
  1481. };
  1482. CSSParser.prototype.parse = function (css, parent, parentType) {
  1483. var _this = this;
  1484. var _a;
  1485. if (css === void 0) { css = this.css; }
  1486. var styleSheet = new StyleSheet();
  1487. if (!css || isSpace(css))
  1488. return styleSheet;
  1489. var index = 0;
  1490. var firstLetter = searchFrom(css, /\S/, index);
  1491. var len = css.length;
  1492. var _loop_1 = function () {
  1493. var propEnd = searchPropEnd(css, index);
  1494. var nestStart = searchFrom(css, '{', firstLetter);
  1495. var firstChar = css.charAt(firstLetter);
  1496. if (firstChar === '/') {
  1497. // remove comment
  1498. switch (css.charAt(firstLetter + 1)) {
  1499. case '/':
  1500. index = firstLetter + 2;
  1501. while (index < len) {
  1502. if (css.charAt(index) === '\n')
  1503. break;
  1504. index++;
  1505. }
  1506. index += 1;
  1507. break;
  1508. case '*':
  1509. index = firstLetter + 2;
  1510. while (index < len) {
  1511. if (css.charAt(index) === '*' && css.charAt(index + 1) === '/')
  1512. break;
  1513. index++;
  1514. }
  1515. index += 2;
  1516. break;
  1517. }
  1518. }
  1519. else if (propEnd === -1 || (nestStart !== -1 && propEnd > nestStart)) {
  1520. // nested AtRule or Selector
  1521. var selector = css.substring(firstLetter, nestStart).trim();
  1522. index = nestStart + 1;
  1523. var nestEnd = this_1._searchGroup(css, index);
  1524. if (nestEnd === -1)
  1525. return "break"; // doesn't close block
  1526. // allow last rule without semicolon
  1527. var rule = css.slice(index, nestEnd);
  1528. if (!/[};]\s*$/.test(rule))
  1529. rule = rule + ';';
  1530. var content = this_1.parse(rule, selector);
  1531. index = nestEnd + 1;
  1532. styleSheet.add(this_1._generateNestStyle(content.children, selector, firstChar === '@' ? 'atRule' : 'selector'));
  1533. }
  1534. else if (firstChar === '$') {
  1535. // define variable
  1536. var prop = Property.parse(css.slice(firstLetter, propEnd));
  1537. if (prop && !Array.isArray(prop) && !Array.isArray(prop.name) && prop.value) {
  1538. this_1.variables[prop.name.slice(1)] = prop.value;
  1539. }
  1540. index = propEnd + 1;
  1541. }
  1542. else if (firstChar === '@') {
  1543. // inline AtRule
  1544. var data = css.slice(firstLetter, propEnd);
  1545. if (this_1.processor) {
  1546. // handle directives
  1547. var directives_1 = this_1._handleDirectives(data.trim());
  1548. if (directives_1) {
  1549. if ('atrule' in directives_1) {
  1550. var atRule = InlineAtRule.parse(directives_1.atrule);
  1551. if (atRule)
  1552. styleSheet.add(this_1._generateNestProperty(atRule, parent, parentType));
  1553. }
  1554. else if ('apply' in directives_1 && directives_1.apply) {
  1555. var result = this_1.processor.compile(directives_1.apply, undefined, false, false, function (ignored) {
  1556. if (('.' + ignored) in _this._cache)
  1557. return _this._cache['.' + ignored];
  1558. });
  1559. styleSheet.add(result.styleSheet.clone().children.map(function (i) {
  1560. if (!(i instanceof Keyframes)) {
  1561. i.selector = undefined;
  1562. if (directives_1.important) {
  1563. i.property.map(function (i) { return i.important = true; });
  1564. }
  1565. }
  1566. return i;
  1567. }));
  1568. }
  1569. }
  1570. }
  1571. else {
  1572. // normal atrule
  1573. var atRule = InlineAtRule.parse(data);
  1574. if (atRule)
  1575. styleSheet.add(this_1._generateNestProperty(atRule, parent, parentType));
  1576. }
  1577. index = propEnd + 1;
  1578. }
  1579. else {
  1580. // inline Property
  1581. var prop = Property.parse(css.slice(firstLetter, propEnd));
  1582. index = propEnd + 1;
  1583. if (prop) {
  1584. // handle theme function
  1585. if (Array.isArray(prop)) {
  1586. prop.filter(function (p) { var _a; return (_a = p.value) === null || _a === void 0 ? void 0 : _a.match(/theme\([^)]*\)/); }).forEach(function (p) { return p.value = _this._loadTheme(p.value); });
  1587. }
  1588. else if ((_a = prop.value) === null || _a === void 0 ? void 0 : _a.match(/theme\([^)]*\)/)) {
  1589. prop.value = this_1._loadTheme(prop.value);
  1590. }
  1591. styleSheet.add(this_1._generateNestProperty(prop, parent, parentType));
  1592. }
  1593. }
  1594. firstLetter = searchFrom(css, /\S/, index);
  1595. };
  1596. var this_1 = this;
  1597. while (firstLetter !== -1) {
  1598. var state_1 = _loop_1();
  1599. if (state_1 === "break")
  1600. break;
  1601. }
  1602. if (!parent)
  1603. this._cache = {};
  1604. return styleSheet.combine();
  1605. };
  1606. return CSSParser;
  1607. }());
  1608. var ClassParser = /** @class */ (function () {
  1609. function ClassParser(classNames, separator, variants) {
  1610. if (separator === void 0) { separator = ':'; }
  1611. this.classNames = classNames;
  1612. this.separator = separator;
  1613. this.variants = variants || [];
  1614. this.index = 0;
  1615. }
  1616. ClassParser.prototype._handle_group = function (removeDuplicated) {
  1617. if (removeDuplicated === void 0) { removeDuplicated = true; }
  1618. if (!this.classNames)
  1619. return [];
  1620. var preChar;
  1621. var char;
  1622. var group;
  1623. var func;
  1624. var variant;
  1625. var variants = [];
  1626. var variantStart = this.index + 1;
  1627. var classStart = this.index + 1;
  1628. var groupStart = this.index + 1;
  1629. var important = false;
  1630. var ignoreSpace = false;
  1631. var ignoreBracket = false;
  1632. var insideSquareBracket = false;
  1633. var brackets = 0;
  1634. var sepLength = this.separator.length;
  1635. var parts = [];
  1636. var length = this.classNames.length;
  1637. while (this.index < length) {
  1638. this.index++;
  1639. char = this.classNames.charAt(this.index);
  1640. // ignore parsing and leave content inside square brackets as-is
  1641. if (insideSquareBracket) {
  1642. if (' \n\t\r'.includes(char)) {
  1643. insideSquareBracket = false;
  1644. }
  1645. else {
  1646. if (char === ']')
  1647. insideSquareBracket = false;
  1648. continue;
  1649. }
  1650. }
  1651. // handle chars
  1652. switch (char) {
  1653. case '!':
  1654. important = true;
  1655. break;
  1656. case this.separator[0]:
  1657. if (this.classNames.slice(this.index, this.index + sepLength) === this.separator) {
  1658. variant = this.classNames.slice(variantStart, this.index);
  1659. if (variant.charAt(0) === '!')
  1660. variant = variant.slice(1);
  1661. if (this.variants.includes(variant)) {
  1662. variants.push(variant);
  1663. this.index += sepLength - 1;
  1664. variantStart = this.index + 1;
  1665. ignoreSpace = true;
  1666. }
  1667. }
  1668. break;
  1669. case '[':
  1670. insideSquareBracket = true;
  1671. break;
  1672. case '(':
  1673. preChar = this.classNames.charAt(this.index - 1);
  1674. if (preChar === '-' || (!ignoreSpace && preChar === ' ')) {
  1675. ignoreBracket = true;
  1676. }
  1677. else if (ignoreSpace) {
  1678. group = this._handle_group();
  1679. }
  1680. else {
  1681. brackets += 1;
  1682. func = this.classNames.slice(groupStart, this.index);
  1683. while (!isSpace(this.classNames.charAt(this.index))) {
  1684. this.index++;
  1685. }
  1686. this.index--;
  1687. }
  1688. ignoreSpace = false;
  1689. break;
  1690. case '"':
  1691. case '`':
  1692. case '\'':
  1693. case ')':
  1694. case ' ':
  1695. case '\n':
  1696. case '\t':
  1697. case '\r':
  1698. if (!ignoreSpace) {
  1699. if (groupStart !== this.index) {
  1700. var raw = this.classNames.slice(classStart, this.index);
  1701. var start = classStart - 1;
  1702. var end = this.index - 1;
  1703. if (Array.isArray(group)) {
  1704. parts.push({ raw: raw, start: start, end: end, variants: variants, content: group, type: 'group', important: important });
  1705. group = undefined;
  1706. }
  1707. else if (func) {
  1708. var utility = this.classNames.slice(variantStart, this.index);
  1709. parts.push({ raw: raw, start: start, end: end, variants: variants, content: utility, type: 'utility', important: important });
  1710. func = undefined;
  1711. }
  1712. else if (ignoreBracket && char === ')') {
  1713. // utility with bracket
  1714. var utility = this.classNames.slice(variantStart, this.index + 1);
  1715. parts.push({ raw: raw + ')', start: start, end: this.index, variants: variants, content: important ? utility.slice(1) : utility, type: 'utility', important: important });
  1716. }
  1717. else {
  1718. var utility = this.classNames.slice(variantStart, this.index);
  1719. if (utility.charAt(0) === '*') {
  1720. parts.push({ raw: raw, start: start, end: end, variants: variants, content: utility.slice(1), type: 'alias', important: important });
  1721. }
  1722. else {
  1723. parts.push({ raw: raw, start: start, end: end, variants: variants, content: utility.charAt(0) === '!' ? utility.slice(1) : utility, type: 'utility', important: important });
  1724. }
  1725. }
  1726. variants = [];
  1727. important = false;
  1728. }
  1729. groupStart = this.index + 1;
  1730. classStart = this.index + 1;
  1731. }
  1732. variantStart = this.index + 1;
  1733. break;
  1734. default:
  1735. ignoreSpace = false;
  1736. }
  1737. if (char === ')') {
  1738. brackets -= 1;
  1739. if (!ignoreBracket && brackets < 0)
  1740. break; // end group
  1741. ignoreBracket = false;
  1742. }
  1743. }
  1744. if (removeDuplicated) {
  1745. var newParts_1 = [];
  1746. var cache_1 = [];
  1747. parts.forEach(function (item) {
  1748. if (!cache_1.includes(item.raw)) {
  1749. cache_1.push(item.raw);
  1750. newParts_1.push(item);
  1751. }
  1752. });
  1753. return newParts_1;
  1754. }
  1755. return parts;
  1756. };
  1757. ClassParser.prototype.parse = function (removeDuplicated) {
  1758. if (removeDuplicated === void 0) { removeDuplicated = true; }
  1759. if (!this.classNames)
  1760. return [];
  1761. // Turn classes into group;
  1762. this.classNames = '(' + this.classNames + ')';
  1763. var elements = this._handle_group(removeDuplicated);
  1764. // Initialization, convenient for next call
  1765. this.index = 0;
  1766. this.classNames = this.classNames.slice(1, -1);
  1767. return elements;
  1768. };
  1769. return ClassParser;
  1770. }());
  1771. export { CSSParser, ClassParser, HTMLParser };