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

1794 строки
76 KiB

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