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

1 год назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. 'use strict';
  2. /*! *****************************************************************************
  3. Copyright (c) Microsoft Corporation.
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  7. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  8. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  9. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  10. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  12. PERFORMANCE OF THIS SOFTWARE.
  13. ***************************************************************************** */
  14. /* global Reflect, Promise */
  15. var extendStatics = function(d, b) {
  16. extendStatics = Object.setPrototypeOf ||
  17. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  18. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  19. return extendStatics(d, b);
  20. };
  21. function __extends(d, b) {
  22. if (typeof b !== "function" && b !== null)
  23. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  24. extendStatics(d, b);
  25. function __() { this.constructor = d; }
  26. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  27. }
  28. var __assign = function() {
  29. __assign = Object.assign || function __assign(t) {
  30. for (var s, i = 1, n = arguments.length; i < n; i++) {
  31. s = arguments[i];
  32. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  33. }
  34. return t;
  35. };
  36. return __assign.apply(this, arguments);
  37. };
  38. function __spreadArray(to, from, pack) {
  39. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  40. if (ar || !(i in from)) {
  41. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  42. ar[i] = from[i];
  43. }
  44. }
  45. return to.concat(ar || Array.prototype.slice.call(from));
  46. }
  47. var createPlugin = function (plugin, config) {
  48. return {
  49. handler: plugin,
  50. config: config,
  51. };
  52. };
  53. createPlugin.withOptions = function (pluginFunction, configFunction) {
  54. if (configFunction === void 0) { configFunction = function () { return ({}); }; }
  55. var optionsFunction = function (options) {
  56. if (options === void 0) { options = {}; }
  57. return {
  58. __options: options,
  59. handler: pluginFunction(options),
  60. config: configFunction(options),
  61. };
  62. };
  63. optionsFunction.__isOptionsFunction = true;
  64. // Expose plugin dependencies so that `object-hash` returns a different
  65. // value if anything here changes, to ensure a rebuild is triggered.
  66. optionsFunction.__pluginFunction = pluginFunction;
  67. optionsFunction.__configFunction = configFunction;
  68. return optionsFunction;
  69. };
  70. function toArray(v) {
  71. if (Array.isArray(v))
  72. return v;
  73. return [v];
  74. }
  75. function indent(code, tab) {
  76. if (tab === void 0) { tab = 2; }
  77. var spaces = Array(tab).fill(' ').join('');
  78. return code
  79. .split('\n')
  80. .map(function (line) { return spaces + line; })
  81. .join('\n');
  82. }
  83. function wrapit(code, start, end, tab, minify) {
  84. if (start === void 0) { start = '{'; }
  85. if (end === void 0) { end = '}'; }
  86. if (tab === void 0) { tab = 2; }
  87. if (minify === void 0) { minify = false; }
  88. if (minify)
  89. return "".concat(start).concat(code).concat(end);
  90. return "".concat(start, "\n").concat(indent(code, tab), "\n").concat(end);
  91. }
  92. function camelToDash(str) {
  93. // Use exact the same regex as Post CSS
  94. return str.replace(/([A-Z])/g, '-$1').replace(/^ms-/, '-ms-').toLowerCase();
  95. }
  96. function dashToCamel(str) {
  97. if (!/-/.test(str))
  98. return str;
  99. return str.toLowerCase().replace(/-(.)/g, function (_, group) { return group.toUpperCase(); });
  100. }
  101. function searchFrom(text, target, startIndex, endIndex) {
  102. if (startIndex === void 0) { startIndex = 0; }
  103. // search from partial of string
  104. var subText = text.substring(startIndex, endIndex);
  105. var relativeIndex = subText.search(target);
  106. return relativeIndex === -1 ? -1 : startIndex + relativeIndex;
  107. }
  108. function connectList(a, b, append) {
  109. if (append === void 0) { append = true; }
  110. 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);
  111. }
  112. function deepCopy(source) {
  113. return Array.isArray(source)
  114. ? source.map(function (item) { return deepCopy(item); })
  115. : source instanceof Date
  116. ? new Date(source.getTime())
  117. : source && typeof source === 'object'
  118. ? Object.getOwnPropertyNames(source).reduce(function (o, prop) {
  119. var descriptor = Object.getOwnPropertyDescriptor(source, prop);
  120. if (descriptor) {
  121. Object.defineProperty(o, prop, descriptor);
  122. if (source && typeof source === 'object') {
  123. o[prop] = deepCopy(source[prop]);
  124. }
  125. }
  126. return o;
  127. }, Object.create(Object.getPrototypeOf(source)))
  128. : source;
  129. }
  130. function isTagName(name) {
  131. 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);
  132. }
  133. function searchPropEnd(text, startIndex) {
  134. if (startIndex === void 0) { startIndex = 0; }
  135. var index = startIndex;
  136. var output = -1;
  137. var openSingleQuote = false;
  138. var openDoubleQuote = false;
  139. var openBracket = false;
  140. var isEscaped = false;
  141. while (index < text.length) {
  142. switch (text.charAt(index)) {
  143. case '\\':
  144. isEscaped = !isEscaped;
  145. break;
  146. case '\'':
  147. if (!openDoubleQuote && !openBracket && !isEscaped)
  148. openSingleQuote = !openSingleQuote;
  149. isEscaped = false;
  150. break;
  151. case '"':
  152. if (!openSingleQuote && !openBracket && !isEscaped)
  153. openDoubleQuote = !openDoubleQuote;
  154. isEscaped = false;
  155. break;
  156. case '(':
  157. if (!openBracket && !openSingleQuote && !openDoubleQuote && !isEscaped)
  158. openBracket = true;
  159. isEscaped = false;
  160. break;
  161. case ')':
  162. if (openBracket && !isEscaped)
  163. openBracket = false;
  164. isEscaped = false;
  165. break;
  166. case ';':
  167. if (!isEscaped && !openSingleQuote && !openDoubleQuote && !openBracket)
  168. output = index;
  169. isEscaped = false;
  170. break;
  171. default:
  172. isEscaped = false;
  173. break;
  174. }
  175. if (output !== -1)
  176. break;
  177. index++;
  178. }
  179. return output;
  180. }
  181. var Property = /** @class */ (function () {
  182. function Property(name, value, comment, important) {
  183. if (important === void 0) { important = false; }
  184. this.meta = { type: 'utilities', group: 'plugin', order: 0, offset: 0, corePlugin: false };
  185. this.name = name;
  186. this.value = value;
  187. this.comment = comment;
  188. this.important = important;
  189. }
  190. Property._singleParse = function (css) {
  191. css = css.trim();
  192. if (!css)
  193. return;
  194. if (css.charAt(0) === '@')
  195. return InlineAtRule.parse(css);
  196. var split = css.search(':');
  197. var end = searchPropEnd(css);
  198. if (split === -1)
  199. return;
  200. var important = false;
  201. var prop = css.substring(split + 1, end === -1 ? undefined : end).trim();
  202. if (/!important;?$/.test(prop)) {
  203. important = true;
  204. prop = prop.replace(/!important/, '').trimRight();
  205. }
  206. return new Property(css.substring(0, split).trim(), prop, undefined, important);
  207. };
  208. Property.parse = function (css) {
  209. if (!/;\s*$/.test(css))
  210. css += ';'; // Fix for the situation where the last semicolon is omitted
  211. var properties = [];
  212. var index = 0;
  213. var end = searchPropEnd(css, index);
  214. while (end !== -1) {
  215. var parsed = this._singleParse(css.substring(searchFrom(css, /\S/, index), end + 1));
  216. if (parsed)
  217. properties.push(parsed);
  218. index = end + 1;
  219. end = searchPropEnd(css, index);
  220. }
  221. var count = properties.length;
  222. if (count > 1)
  223. return properties;
  224. if (count === 1)
  225. return properties[0];
  226. };
  227. Property.prototype.clone = function () {
  228. return deepCopy(this);
  229. };
  230. Property.prototype.toStyle = function (selector) {
  231. var style = new Style(selector, this, this.important);
  232. style.meta = this.meta;
  233. return style;
  234. };
  235. Property.prototype.build = function (minify) {
  236. var _this = this;
  237. if (minify === void 0) { minify = false; }
  238. var createProperty = function (name, value) {
  239. if (minify) {
  240. return "".concat(name, ":").concat(value).concat(_this.important ? '!important' : '', ";");
  241. }
  242. else {
  243. var p = "".concat(name, ": ").concat(value).concat(_this.important ? ' !important' : '', ";");
  244. return _this.comment ? p + " /* ".concat(_this.comment, " */") : p;
  245. }
  246. };
  247. if (!this.value)
  248. return '';
  249. return typeof this.name === 'string'
  250. ? createProperty(this.name, this.value)
  251. : this.name
  252. .map(function (i) { return createProperty(i, _this.value); })
  253. .join(minify ? '' : '\n');
  254. };
  255. Property.prototype.updateMeta = function (type, group, order, offset, corePlugin) {
  256. if (offset === void 0) { offset = 0; }
  257. if (corePlugin === void 0) { corePlugin = false; }
  258. this.meta = {
  259. type: type,
  260. group: group,
  261. order: order,
  262. offset: offset,
  263. corePlugin: corePlugin,
  264. };
  265. return this;
  266. };
  267. return Property;
  268. }());
  269. var InlineAtRule = /** @class */ (function (_super) {
  270. __extends(InlineAtRule, _super);
  271. function InlineAtRule(name, value, important) {
  272. if (important === void 0) { important = false; }
  273. var _this = _super.call(this, name, value, undefined, important) || this;
  274. _this.name = name;
  275. return _this;
  276. }
  277. InlineAtRule.parse = function (css) {
  278. var _a;
  279. var matchName = css.match(/@[^\s;{}]+/);
  280. if (matchName) {
  281. var name_1 = matchName[0].substring(1);
  282. var important = false;
  283. var expression = matchName.index !== undefined
  284. ? (_a = css
  285. .substring(matchName.index + name_1.length + 1)
  286. .match(/(?:(['"]).*?\1|[^;])*/)) === null || _a === void 0 ? void 0 : _a[0].trim()
  287. : undefined;
  288. if (expression && /!important;?$/.test(expression)) {
  289. important = true;
  290. expression = expression.replace(/!important/, '').trimRight();
  291. }
  292. return new InlineAtRule(name_1, expression === '' ? undefined : expression, important);
  293. }
  294. };
  295. InlineAtRule.prototype.build = function () {
  296. return this.value
  297. ? "@".concat(this.name, " ").concat(this.value).concat(this.important ? ' !important' : '', ";")
  298. : "@".concat(this.name).concat(this.important ? ' !important' : '', ";");
  299. };
  300. return InlineAtRule;
  301. }(Property));
  302. var Style = /** @class */ (function () {
  303. function Style(selector, property, important) {
  304. if (important === void 0) { important = false; }
  305. this.meta = { type: 'components', group: 'plugin', order: 0, offset: 0, corePlugin: false };
  306. this.selector = selector;
  307. this.important = important;
  308. this.property = toArray(property || []);
  309. }
  310. Object.defineProperty(Style.prototype, "rule", {
  311. get: function () {
  312. var _this = this;
  313. var _a, _b, _c;
  314. var selectors = ((_a = this.selector) !== null && _a !== void 0 ? _a : '').trim().split(/\s*,\s*/g);
  315. this._parentSelectors && (selectors = selectors.map(function (i) { var _a; return "".concat((_a = _this._parentSelectors) === null || _a === void 0 ? void 0 : _a.join(' '), " ").concat(i); }));
  316. ((_b = this._wrapSelectors) !== null && _b !== void 0 ? _b : []).forEach(function (func) { return (selectors = selectors.map(function (i) { return func(i); })); });
  317. this._pseudoClasses && (selectors = selectors.map(function (i) { var _a; return i + ":".concat((_a = _this._pseudoClasses) === null || _a === void 0 ? void 0 : _a.join(':')); }));
  318. this._pseudoElements && (selectors = selectors.map(function (i) { var _a; return i + "::".concat((_a = _this._pseudoElements) === null || _a === void 0 ? void 0 : _a.join('::')); }));
  319. this._brotherSelectors && (selectors = selectors.map(function (i) { var _a; return i + ".".concat((_a = _this._brotherSelectors) === null || _a === void 0 ? void 0 : _a.join('.')); }));
  320. this._childSelectors && (selectors = selectors.map(function (i) { var _a; return i + " ".concat((_a = _this._childSelectors) === null || _a === void 0 ? void 0 : _a.join(' ')); }));
  321. ((_c = this._wrapRules) !== null && _c !== void 0 ? _c : []).forEach(function (func) { return (selectors = selectors.map(function (i) { return func(i); })); });
  322. return selectors.join(', ');
  323. },
  324. enumerable: false,
  325. configurable: true
  326. });
  327. Object.defineProperty(Style.prototype, "pseudoClasses", {
  328. get: function () {
  329. return this._pseudoClasses;
  330. },
  331. enumerable: false,
  332. configurable: true
  333. });
  334. Object.defineProperty(Style.prototype, "pseudoElements", {
  335. get: function () {
  336. return this._pseudoElements;
  337. },
  338. enumerable: false,
  339. configurable: true
  340. });
  341. Object.defineProperty(Style.prototype, "parentSelectors", {
  342. get: function () {
  343. return this._parentSelectors;
  344. },
  345. enumerable: false,
  346. configurable: true
  347. });
  348. Object.defineProperty(Style.prototype, "childSelectors", {
  349. get: function () {
  350. return this._childSelectors;
  351. },
  352. enumerable: false,
  353. configurable: true
  354. });
  355. Object.defineProperty(Style.prototype, "brotherSelectors", {
  356. get: function () {
  357. return this._brotherSelectors;
  358. },
  359. enumerable: false,
  360. configurable: true
  361. });
  362. Object.defineProperty(Style.prototype, "wrapProperties", {
  363. get: function () {
  364. return this._wrapProperties;
  365. },
  366. enumerable: false,
  367. configurable: true
  368. });
  369. Object.defineProperty(Style.prototype, "wrapSelectors", {
  370. get: function () {
  371. return this._wrapSelectors;
  372. },
  373. enumerable: false,
  374. configurable: true
  375. });
  376. Object.defineProperty(Style.prototype, "wrapRules", {
  377. get: function () {
  378. return this._wrapRules;
  379. },
  380. enumerable: false,
  381. configurable: true
  382. });
  383. Object.defineProperty(Style.prototype, "simple", {
  384. get: function () {
  385. // is this style only has property and no wrap?
  386. return !(this.atRules || this._pseudoClasses || this._pseudoElements || this._parentSelectors || this._childSelectors || this._brotherSelectors || this._wrapProperties || this._wrapSelectors || this._wrapRules);
  387. },
  388. enumerable: false,
  389. configurable: true
  390. });
  391. Object.defineProperty(Style.prototype, "isAtrule", {
  392. get: function () {
  393. return !(this.atRules === undefined || this.atRules.length === 0);
  394. },
  395. enumerable: false,
  396. configurable: true
  397. });
  398. Style.generate = function (parent, property, root) {
  399. if (!root)
  400. root = (parent === null || parent === void 0 ? void 0 : parent.startsWith('@'))
  401. ? new Style().atRule(parent)
  402. : new Style(parent);
  403. var output = [];
  404. var _loop_1 = function (key, value) {
  405. var propertyValue = value;
  406. if (Array.isArray(propertyValue) && propertyValue.every(function (e) { return typeof e === 'object'; })) {
  407. propertyValue = Object.assign.apply(Object, __spreadArray([{}], propertyValue, false));
  408. }
  409. if (typeof propertyValue === 'string') {
  410. root.add(new Property(camelToDash(key), propertyValue));
  411. }
  412. else if (Array.isArray(propertyValue)) {
  413. propertyValue.map(function (i) { return root === null || root === void 0 ? void 0 : root.add(new Property(camelToDash(key), i)); });
  414. }
  415. else {
  416. var wrap = deepCopy(root);
  417. wrap.property = [];
  418. var child = void 0;
  419. if (key.startsWith('@')) {
  420. child = wrap.atRule(key, false);
  421. }
  422. else {
  423. if (wrap.selector === undefined) {
  424. wrap.selector = key;
  425. child = wrap;
  426. }
  427. else {
  428. if (/^[a-z]+$/.test(key) && !isTagName(key)) {
  429. wrap.wrapProperty(function (property) { return "".concat(key, "-").concat(property); });
  430. child = wrap;
  431. }
  432. else {
  433. var _hKey_1 = function (selector, key) { return (/&/.test(key) ? key : "& ".concat(key)).replace('&', selector); };
  434. wrap.wrapSelector(function (selector) {
  435. return selector
  436. .trim()
  437. .split(/\s*,\s*/g)
  438. .map(function (s) {
  439. return key
  440. .split(/\s*,\s*/g)
  441. .map(function (i) { return _hKey_1(s, i); })
  442. .join(', ');
  443. })
  444. .join(', ');
  445. });
  446. child = wrap;
  447. }
  448. }
  449. }
  450. output = output.concat(Style.generate(key.startsWith('@') ? undefined : key, propertyValue, child));
  451. }
  452. };
  453. for (var _i = 0, _a = Object.entries(property !== null && property !== void 0 ? property : {}); _i < _a.length; _i++) {
  454. var _b = _a[_i], key = _b[0], value = _b[1];
  455. _loop_1(key, value);
  456. }
  457. if (root.property.length > 0)
  458. output.unshift(root);
  459. return output;
  460. };
  461. Style.prototype.atRule = function (atrule, append) {
  462. if (append === void 0) { append = true; }
  463. if (!atrule)
  464. return this;
  465. if (this.atRules) {
  466. append ? this.atRules.push(atrule) : this.atRules.unshift(atrule);
  467. }
  468. else {
  469. this.atRules = [atrule];
  470. }
  471. return this;
  472. };
  473. Style.prototype.pseudoClass = function (string) {
  474. if (this._pseudoClasses) {
  475. this._pseudoClasses.push(string);
  476. }
  477. else {
  478. this._pseudoClasses = [string];
  479. }
  480. return this;
  481. };
  482. Style.prototype.pseudoElement = function (string) {
  483. if (this._pseudoElements) {
  484. this._pseudoElements.push(string);
  485. }
  486. else {
  487. this._pseudoElements = [string];
  488. }
  489. return this;
  490. };
  491. Style.prototype.brother = function (string) {
  492. if (this._brotherSelectors) {
  493. this._brotherSelectors.push(string);
  494. }
  495. else {
  496. this._brotherSelectors = [string];
  497. }
  498. return this;
  499. };
  500. Style.prototype.parent = function (string) {
  501. if (this._parentSelectors) {
  502. this._parentSelectors.push(string);
  503. }
  504. else {
  505. this._parentSelectors = [string];
  506. }
  507. return this;
  508. };
  509. Style.prototype.child = function (string) {
  510. if (this._childSelectors) {
  511. this._childSelectors.push(string);
  512. }
  513. else {
  514. this._childSelectors = [string];
  515. }
  516. return this;
  517. };
  518. Style.prototype.wrapProperty = function (func) {
  519. if (this._wrapProperties) {
  520. this._wrapProperties.push(func);
  521. }
  522. else {
  523. this._wrapProperties = [func];
  524. }
  525. return this;
  526. };
  527. Style.prototype.wrapSelector = function (func) {
  528. if (this._wrapSelectors) {
  529. this._wrapSelectors.push(func);
  530. }
  531. else {
  532. this._wrapSelectors = [func];
  533. }
  534. return this;
  535. };
  536. Style.prototype.wrapRule = function (func) {
  537. if (this._wrapRules) {
  538. this._wrapRules.push(func);
  539. }
  540. else {
  541. this._wrapRules = [func];
  542. }
  543. return this;
  544. };
  545. Style.prototype.add = function (item) {
  546. item = toArray(item);
  547. if (this.important)
  548. item.forEach(function (i) { return (i.important = true); });
  549. this.property = __spreadArray(__spreadArray([], this.property, true), item, true);
  550. return this;
  551. };
  552. Style.prototype.extend = function (item, onlyProperty, append) {
  553. if (onlyProperty === void 0) { onlyProperty = false; }
  554. if (append === void 0) { append = true; }
  555. if (!item)
  556. return this;
  557. if (item.wrapProperties) {
  558. var props_1 = [];
  559. item.property.forEach(function (p) {
  560. var _a;
  561. var pc = new Property(p.name, p.value, p.comment);
  562. (_a = item.wrapProperties) === null || _a === void 0 ? void 0 : _a.forEach(function (wrap) {
  563. pc.name = Array.isArray(pc.name)
  564. ? pc.name.map(function (i) { return wrap(i); })
  565. : wrap(pc.name);
  566. });
  567. if (item.important)
  568. pc.important = true;
  569. props_1.push(pc);
  570. });
  571. this.property = connectList(this.property, props_1, append);
  572. }
  573. else {
  574. if (item.important)
  575. item.property.forEach(function (i) { return (i.important = true); });
  576. this.property = connectList(this.property, item.property, append);
  577. }
  578. if (onlyProperty)
  579. return this;
  580. item.selector && (this.selector = item.selector);
  581. this.meta = item.meta;
  582. item.atRules &&
  583. (this.atRules = connectList(item.atRules, this.atRules, append)); // atrule is build in reverse
  584. item._brotherSelectors &&
  585. (this._brotherSelectors = connectList(this._brotherSelectors, item._brotherSelectors, append));
  586. item._childSelectors &&
  587. (this._childSelectors = connectList(this._childSelectors, item._childSelectors, append));
  588. item._parentSelectors &&
  589. (this._parentSelectors = connectList(this._parentSelectors, item._parentSelectors, append));
  590. item._pseudoClasses &&
  591. (this._pseudoClasses = connectList(this._pseudoClasses, item._pseudoClasses, append));
  592. item._pseudoElements &&
  593. (this._pseudoElements = connectList(this._pseudoElements, item._pseudoElements, append));
  594. item._wrapRules &&
  595. (this._wrapRules = connectList(this._wrapRules, item._wrapRules, append));
  596. item._wrapSelectors &&
  597. (this._wrapSelectors = connectList(this._wrapSelectors, item._wrapSelectors, append));
  598. return this;
  599. };
  600. Style.prototype.clean = function () {
  601. // remove duplicated property
  602. var property = [];
  603. var cache = [];
  604. this.property.forEach(function (i) {
  605. var inline = i.build();
  606. if (!cache.includes(inline)) {
  607. cache.push(inline);
  608. property.push(i);
  609. }
  610. });
  611. this.property = property;
  612. return this;
  613. };
  614. Style.prototype.flat = function () {
  615. var properties = [];
  616. this.property.forEach(function (p) {
  617. if (Array.isArray(p.name)) {
  618. p.name.forEach(function (i) {
  619. properties.push(new Property(i, p.value, p.comment));
  620. });
  621. }
  622. else {
  623. properties.push(p);
  624. }
  625. });
  626. this.property = properties;
  627. return this;
  628. };
  629. Style.prototype.clone = function (selector, property) {
  630. var newStyle = deepCopy(this);
  631. if (selector)
  632. newStyle.selector = selector;
  633. if (property)
  634. newStyle.property = Array.isArray(property) ? property : [property];
  635. return newStyle;
  636. };
  637. Style.prototype.sort = function () {
  638. // sort property
  639. this.property = this.property.sort(function (a, b) {
  640. return "".concat(a.name).substring(0, 2) > "".concat(b.name).substring(0, 2) ? 1 : -1;
  641. });
  642. return this;
  643. };
  644. Style.prototype.build = function (minify, prefixer) {
  645. var _this = this;
  646. if (minify === void 0) { minify = false; }
  647. if (prefixer === void 0) { prefixer = true; }
  648. var properties = this.property;
  649. if (!prefixer)
  650. properties = properties.filter(function (p) {
  651. if (p.value && /-(webkit|ms|moz|o)-/.test(p.value))
  652. return false;
  653. if (Array.isArray(p.name)) {
  654. p.name = p.name.filter(function (i) { return !/^-(webkit|ms|moz|o)-/.test(i); });
  655. return true;
  656. }
  657. return !/^-(webkit|ms|moz|o)-/.test(p.name);
  658. });
  659. var result = properties.map(function (p) {
  660. if (_this._wrapProperties) {
  661. var name_2 = p.name;
  662. _this._wrapProperties.forEach(function (w) { return (name_2 = Array.isArray(name_2) ? name_2.map(function (n) { return w(n); }) : w(name_2)); });
  663. return new Property(name_2, p.value, p.comment, _this.important ? true : p.important).build(minify);
  664. }
  665. return _this.important ? new Property(p.name, p.value, p.comment, true).build(minify) : p.build(minify);
  666. }).join(minify ? '' : '\n');
  667. if (!this.selector && !this.atRules)
  668. return result.replace(/;}/g, '}');
  669. if (this.selector)
  670. result = (minify ? this.rule.replace(/,\s/g, ',') : this.rule + ' ') + wrapit(result, undefined, undefined, undefined, result !== '' ? minify : true);
  671. if (this.atRules) {
  672. for (var _i = 0, _a = this.atRules; _i < _a.length; _i++) {
  673. var rule = _a[_i];
  674. 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));
  675. }
  676. }
  677. return minify ? result.replace(/;}/g, '}') : result;
  678. };
  679. Style.prototype.updateMeta = function (type, group, order, offset, corePlugin, respectSelector) {
  680. if (offset === void 0) { offset = 0; }
  681. if (corePlugin === void 0) { corePlugin = false; }
  682. if (respectSelector === void 0) { respectSelector = false; }
  683. this.meta = {
  684. type: type,
  685. group: group,
  686. order: order,
  687. offset: offset,
  688. corePlugin: corePlugin,
  689. respectSelector: respectSelector,
  690. };
  691. return this;
  692. };
  693. return Style;
  694. }());
  695. /** @class */ ((function (_super) {
  696. __extends(GlobalStyle, _super);
  697. function GlobalStyle(selector, property, important) {
  698. return _super.call(this, selector, property, important) || this;
  699. }
  700. return GlobalStyle;
  701. })(Style));
  702. /** @class */ ((function (_super) {
  703. __extends(Keyframes, _super);
  704. function Keyframes(selector, property, important) {
  705. return _super.call(this, selector, property, important) || this;
  706. }
  707. // root param only for consist with style
  708. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  709. Keyframes.generate = function (name, children, root, prefixer) {
  710. if (prefixer === void 0) { prefixer = true; }
  711. var styles = [];
  712. var webkitStyles = [];
  713. for (var _i = 0, _a = Object.entries(children); _i < _a.length; _i++) {
  714. var _b = _a[_i], key = _b[0], value = _b[1];
  715. var style = new Keyframes(key).atRule("@keyframes ".concat(name));
  716. var webkitStyle = new Keyframes(key).atRule("@-webkit-keyframes ".concat(name));
  717. for (var _c = 0, _d = Object.entries(value); _c < _d.length; _c++) {
  718. var _e = _d[_c], pkey = _e[0], pvalue = _e[1];
  719. var prop = pkey;
  720. if (pkey === 'transform') {
  721. prop = prefixer ? ['-webkit-transform', 'transform'] : 'transform';
  722. }
  723. else if (['animationTimingFunction', 'animation-timing-function'].includes(pkey)) {
  724. prop = prefixer ? [
  725. '-webkit-animation-timing-function',
  726. 'animation-timing-function',
  727. ] : 'animation-timing-function';
  728. }
  729. style.add(new Property(prop, pvalue));
  730. webkitStyle.add(new Property(prop, pvalue));
  731. }
  732. styles.push(style);
  733. if (prefixer)
  734. webkitStyles.push(webkitStyle);
  735. }
  736. return __spreadArray(__spreadArray([], styles, true), webkitStyles, true);
  737. };
  738. return Keyframes;
  739. })(Style));
  740. /** @class */ ((function (_super) {
  741. __extends(Container, _super);
  742. function Container(selector, property, important) {
  743. return _super.call(this, selector, property, important) || this;
  744. }
  745. return Container;
  746. })(Style));
  747. function expandDirection(value, divide) {
  748. if (divide === void 0) { divide = false; }
  749. var map = {
  750. '': ['*'],
  751. y: ['top', 'bottom'],
  752. x: ['left', 'right'],
  753. t: divide ? ['top-left', 'top-right'] : ['top'],
  754. r: divide ? ['top-right', 'bottom-right'] : ['right'],
  755. b: divide ? ['bottom-right', 'bottom-left'] : ['bottom'],
  756. l: divide ? ['top-left', 'bottom-left'] : ['left'],
  757. tl: ['top-left'],
  758. tr: ['top-right'],
  759. br: ['bottom-right'],
  760. bl: ['bottom-left'],
  761. };
  762. if (value in map)
  763. return map[value];
  764. }
  765. var colorName = {
  766. "aliceblue": [240, 248, 255],
  767. "antiquewhite": [250, 235, 215],
  768. "aqua": [0, 255, 255],
  769. "aquamarine": [127, 255, 212],
  770. "azure": [240, 255, 255],
  771. "beige": [245, 245, 220],
  772. "bisque": [255, 228, 196],
  773. "black": [0, 0, 0],
  774. "blanchedalmond": [255, 235, 205],
  775. "blue": [0, 0, 255],
  776. "blueviolet": [138, 43, 226],
  777. "brown": [165, 42, 42],
  778. "burlywood": [222, 184, 135],
  779. "cadetblue": [95, 158, 160],
  780. "chartreuse": [127, 255, 0],
  781. "chocolate": [210, 105, 30],
  782. "coral": [255, 127, 80],
  783. "cornflowerblue": [100, 149, 237],
  784. "cornsilk": [255, 248, 220],
  785. "crimson": [220, 20, 60],
  786. "cyan": [0, 255, 255],
  787. "darkblue": [0, 0, 139],
  788. "darkcyan": [0, 139, 139],
  789. "darkgoldenrod": [184, 134, 11],
  790. "darkgray": [169, 169, 169],
  791. "darkgreen": [0, 100, 0],
  792. "darkgrey": [169, 169, 169],
  793. "darkkhaki": [189, 183, 107],
  794. "darkmagenta": [139, 0, 139],
  795. "darkolivegreen": [85, 107, 47],
  796. "darkorange": [255, 140, 0],
  797. "darkorchid": [153, 50, 204],
  798. "darkred": [139, 0, 0],
  799. "darksalmon": [233, 150, 122],
  800. "darkseagreen": [143, 188, 143],
  801. "darkslateblue": [72, 61, 139],
  802. "darkslategray": [47, 79, 79],
  803. "darkslategrey": [47, 79, 79],
  804. "darkturquoise": [0, 206, 209],
  805. "darkviolet": [148, 0, 211],
  806. "deeppink": [255, 20, 147],
  807. "deepskyblue": [0, 191, 255],
  808. "dimgray": [105, 105, 105],
  809. "dimgrey": [105, 105, 105],
  810. "dodgerblue": [30, 144, 255],
  811. "firebrick": [178, 34, 34],
  812. "floralwhite": [255, 250, 240],
  813. "forestgreen": [34, 139, 34],
  814. "fuchsia": [255, 0, 255],
  815. "gainsboro": [220, 220, 220],
  816. "ghostwhite": [248, 248, 255],
  817. "gold": [255, 215, 0],
  818. "goldenrod": [218, 165, 32],
  819. "gray": [128, 128, 128],
  820. "green": [0, 128, 0],
  821. "greenyellow": [173, 255, 47],
  822. "grey": [128, 128, 128],
  823. "honeydew": [240, 255, 240],
  824. "hotpink": [255, 105, 180],
  825. "indianred": [205, 92, 92],
  826. "indigo": [75, 0, 130],
  827. "ivory": [255, 255, 240],
  828. "khaki": [240, 230, 140],
  829. "lavender": [230, 230, 250],
  830. "lavenderblush": [255, 240, 245],
  831. "lawngreen": [124, 252, 0],
  832. "lemonchiffon": [255, 250, 205],
  833. "lightblue": [173, 216, 230],
  834. "lightcoral": [240, 128, 128],
  835. "lightcyan": [224, 255, 255],
  836. "lightgoldenrodyellow": [250, 250, 210],
  837. "lightgray": [211, 211, 211],
  838. "lightgreen": [144, 238, 144],
  839. "lightgrey": [211, 211, 211],
  840. "lightpink": [255, 182, 193],
  841. "lightsalmon": [255, 160, 122],
  842. "lightseagreen": [32, 178, 170],
  843. "lightskyblue": [135, 206, 250],
  844. "lightslategray": [119, 136, 153],
  845. "lightslategrey": [119, 136, 153],
  846. "lightsteelblue": [176, 196, 222],
  847. "lightyellow": [255, 255, 224],
  848. "lime": [0, 255, 0],
  849. "limegreen": [50, 205, 50],
  850. "linen": [250, 240, 230],
  851. "magenta": [255, 0, 255],
  852. "maroon": [128, 0, 0],
  853. "mediumaquamarine": [102, 205, 170],
  854. "mediumblue": [0, 0, 205],
  855. "mediumorchid": [186, 85, 211],
  856. "mediumpurple": [147, 112, 219],
  857. "mediumseagreen": [60, 179, 113],
  858. "mediumslateblue": [123, 104, 238],
  859. "mediumspringgreen": [0, 250, 154],
  860. "mediumturquoise": [72, 209, 204],
  861. "mediumvioletred": [199, 21, 133],
  862. "midnightblue": [25, 25, 112],
  863. "mintcream": [245, 255, 250],
  864. "mistyrose": [255, 228, 225],
  865. "moccasin": [255, 228, 181],
  866. "navajowhite": [255, 222, 173],
  867. "navy": [0, 0, 128],
  868. "oldlace": [253, 245, 230],
  869. "olive": [128, 128, 0],
  870. "olivedrab": [107, 142, 35],
  871. "orange": [255, 165, 0],
  872. "orangered": [255, 69, 0],
  873. "orchid": [218, 112, 214],
  874. "palegoldenrod": [238, 232, 170],
  875. "palegreen": [152, 251, 152],
  876. "paleturquoise": [175, 238, 238],
  877. "palevioletred": [219, 112, 147],
  878. "papayawhip": [255, 239, 213],
  879. "peachpuff": [255, 218, 185],
  880. "peru": [205, 133, 63],
  881. "pink": [255, 192, 203],
  882. "plum": [221, 160, 221],
  883. "powderblue": [176, 224, 230],
  884. "purple": [128, 0, 128],
  885. "rebeccapurple": [102, 51, 153],
  886. "red": [255, 0, 0],
  887. "rosybrown": [188, 143, 143],
  888. "royalblue": [65, 105, 225],
  889. "saddlebrown": [139, 69, 19],
  890. "salmon": [250, 128, 114],
  891. "sandybrown": [244, 164, 96],
  892. "seagreen": [46, 139, 87],
  893. "seashell": [255, 245, 238],
  894. "sienna": [160, 82, 45],
  895. "silver": [192, 192, 192],
  896. "skyblue": [135, 206, 235],
  897. "slateblue": [106, 90, 205],
  898. "slategray": [112, 128, 144],
  899. "slategrey": [112, 128, 144],
  900. "snow": [255, 250, 250],
  901. "springgreen": [0, 255, 127],
  902. "steelblue": [70, 130, 180],
  903. "tan": [210, 180, 140],
  904. "teal": [0, 128, 128],
  905. "thistle": [216, 191, 216],
  906. "tomato": [255, 99, 71],
  907. "turquoise": [64, 224, 208],
  908. "violet": [238, 130, 238],
  909. "wheat": [245, 222, 179],
  910. "white": [255, 255, 255],
  911. "whitesmoke": [245, 245, 245],
  912. "yellow": [255, 255, 0],
  913. "yellowgreen": [154, 205, 50]
  914. };
  915. var simpleSwizzle = {exports: {}};
  916. var isArrayish$1 = function isArrayish(obj) {
  917. if (!obj || typeof obj === 'string') {
  918. return false;
  919. }
  920. return obj instanceof Array || Array.isArray(obj) ||
  921. (obj.length >= 0 && (obj.splice instanceof Function ||
  922. (Object.getOwnPropertyDescriptor(obj, (obj.length - 1)) && obj.constructor.name !== 'String')));
  923. };
  924. var isArrayish = isArrayish$1;
  925. var concat = Array.prototype.concat;
  926. var slice = Array.prototype.slice;
  927. var swizzle$1 = simpleSwizzle.exports = function swizzle(args) {
  928. var results = [];
  929. for (var i = 0, len = args.length; i < len; i++) {
  930. var arg = args[i];
  931. if (isArrayish(arg)) {
  932. // http://jsperf.com/javascript-array-concat-vs-push/98
  933. results = concat.call(results, slice.call(arg));
  934. } else {
  935. results.push(arg);
  936. }
  937. }
  938. return results;
  939. };
  940. swizzle$1.wrap = function (fn) {
  941. return function () {
  942. return fn(swizzle$1(arguments));
  943. };
  944. };
  945. /* MIT license */
  946. var colorNames = colorName;
  947. var swizzle = simpleSwizzle.exports;
  948. var hasOwnProperty = Object.hasOwnProperty;
  949. var reverseNames = {};
  950. // create a list of reverse color names
  951. for (var name in colorNames) {
  952. if (hasOwnProperty.call(colorNames, name)) {
  953. reverseNames[colorNames[name]] = name;
  954. }
  955. }
  956. var cs = {
  957. to: {},
  958. get: {}
  959. };
  960. cs.get = function (string) {
  961. var prefix = string.substring(0, 3).toLowerCase();
  962. var val;
  963. var model;
  964. switch (prefix) {
  965. case 'hsl':
  966. val = cs.get.hsl(string);
  967. model = 'hsl';
  968. break;
  969. case 'hwb':
  970. val = cs.get.hwb(string);
  971. model = 'hwb';
  972. break;
  973. default:
  974. val = cs.get.rgb(string);
  975. model = 'rgb';
  976. break;
  977. }
  978. if (!val) {
  979. return null;
  980. }
  981. return {model: model, value: val};
  982. };
  983. cs.get.rgb = function (string) {
  984. if (!string) {
  985. return null;
  986. }
  987. var abbr = /^#([a-f0-9]{3,4})$/i;
  988. var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
  989. var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
  990. var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
  991. var keyword = /^(\w+)$/;
  992. var rgb = [0, 0, 0, 1];
  993. var match;
  994. var i;
  995. var hexAlpha;
  996. if (match = string.match(hex)) {
  997. hexAlpha = match[2];
  998. match = match[1];
  999. for (i = 0; i < 3; i++) {
  1000. // https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
  1001. var i2 = i * 2;
  1002. rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
  1003. }
  1004. if (hexAlpha) {
  1005. rgb[3] = parseInt(hexAlpha, 16) / 255;
  1006. }
  1007. } else if (match = string.match(abbr)) {
  1008. match = match[1];
  1009. hexAlpha = match[3];
  1010. for (i = 0; i < 3; i++) {
  1011. rgb[i] = parseInt(match[i] + match[i], 16);
  1012. }
  1013. if (hexAlpha) {
  1014. rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
  1015. }
  1016. } else if (match = string.match(rgba)) {
  1017. for (i = 0; i < 3; i++) {
  1018. rgb[i] = parseInt(match[i + 1], 0);
  1019. }
  1020. if (match[4]) {
  1021. if (match[5]) {
  1022. rgb[3] = parseFloat(match[4]) * 0.01;
  1023. } else {
  1024. rgb[3] = parseFloat(match[4]);
  1025. }
  1026. }
  1027. } else if (match = string.match(per)) {
  1028. for (i = 0; i < 3; i++) {
  1029. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  1030. }
  1031. if (match[4]) {
  1032. if (match[5]) {
  1033. rgb[3] = parseFloat(match[4]) * 0.01;
  1034. } else {
  1035. rgb[3] = parseFloat(match[4]);
  1036. }
  1037. }
  1038. } else if (match = string.match(keyword)) {
  1039. if (match[1] === 'transparent') {
  1040. return [0, 0, 0, 0];
  1041. }
  1042. if (!hasOwnProperty.call(colorNames, match[1])) {
  1043. return null;
  1044. }
  1045. rgb = colorNames[match[1]];
  1046. rgb[3] = 1;
  1047. return rgb;
  1048. } else {
  1049. return null;
  1050. }
  1051. for (i = 0; i < 3; i++) {
  1052. rgb[i] = clamp(rgb[i], 0, 255);
  1053. }
  1054. rgb[3] = clamp(rgb[3], 0, 1);
  1055. return rgb;
  1056. };
  1057. cs.get.hsl = function (string) {
  1058. if (!string) {
  1059. return null;
  1060. }
  1061. var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
  1062. var match = string.match(hsl);
  1063. if (match) {
  1064. var alpha = parseFloat(match[4]);
  1065. var h = ((parseFloat(match[1]) % 360) + 360) % 360;
  1066. var s = clamp(parseFloat(match[2]), 0, 100);
  1067. var l = clamp(parseFloat(match[3]), 0, 100);
  1068. var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
  1069. return [h, s, l, a];
  1070. }
  1071. return null;
  1072. };
  1073. cs.get.hwb = function (string) {
  1074. if (!string) {
  1075. return null;
  1076. }
  1077. var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
  1078. var match = string.match(hwb);
  1079. if (match) {
  1080. var alpha = parseFloat(match[4]);
  1081. var h = ((parseFloat(match[1]) % 360) + 360) % 360;
  1082. var w = clamp(parseFloat(match[2]), 0, 100);
  1083. var b = clamp(parseFloat(match[3]), 0, 100);
  1084. var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
  1085. return [h, w, b, a];
  1086. }
  1087. return null;
  1088. };
  1089. cs.to.hex = function () {
  1090. var rgba = swizzle(arguments);
  1091. return (
  1092. '#' +
  1093. hexDouble(rgba[0]) +
  1094. hexDouble(rgba[1]) +
  1095. hexDouble(rgba[2]) +
  1096. (rgba[3] < 1
  1097. ? (hexDouble(Math.round(rgba[3] * 255)))
  1098. : '')
  1099. );
  1100. };
  1101. cs.to.rgb = function () {
  1102. var rgba = swizzle(arguments);
  1103. return rgba.length < 4 || rgba[3] === 1
  1104. ? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
  1105. : 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
  1106. };
  1107. cs.to.rgb.percent = function () {
  1108. var rgba = swizzle(arguments);
  1109. var r = Math.round(rgba[0] / 255 * 100);
  1110. var g = Math.round(rgba[1] / 255 * 100);
  1111. var b = Math.round(rgba[2] / 255 * 100);
  1112. return rgba.length < 4 || rgba[3] === 1
  1113. ? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
  1114. : 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
  1115. };
  1116. cs.to.hsl = function () {
  1117. var hsla = swizzle(arguments);
  1118. return hsla.length < 4 || hsla[3] === 1
  1119. ? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
  1120. : 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
  1121. };
  1122. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  1123. // (hwb have alpha optional & 1 is default value)
  1124. cs.to.hwb = function () {
  1125. var hwba = swizzle(arguments);
  1126. var a = '';
  1127. if (hwba.length >= 4 && hwba[3] !== 1) {
  1128. a = ', ' + hwba[3];
  1129. }
  1130. return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
  1131. };
  1132. cs.to.keyword = function (rgb) {
  1133. return reverseNames[rgb.slice(0, 3)];
  1134. };
  1135. // helpers
  1136. function clamp(num, min, max) {
  1137. return Math.min(Math.max(min, num), max);
  1138. }
  1139. function hexDouble(num) {
  1140. var str = Math.round(num).toString(16).toUpperCase();
  1141. return (str.length < 2) ? '0' + str : str;
  1142. }
  1143. // TODO: tsconfig -> ES2019 (node 12+)
  1144. // https://node.green/#ES2019-features--Object-fromEntries
  1145. // https://github.com/microsoft/TypeScript/issues/30933#issuecomment-591682635
  1146. function fromEntries(entries) {
  1147. return entries.reduce(function (acc, _a) {
  1148. var _b;
  1149. var key = _a[0], value = _a[1];
  1150. return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
  1151. }, {});
  1152. }
  1153. // docs
  1154. // https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-position
  1155. var index = createPlugin(function (_a) {
  1156. var addUtilities = _a.addUtilities, addDynamic = _a.addDynamic, theme = _a.theme, variants = _a.variants;
  1157. addUtilities(__assign(__assign(__assign(__assign(__assign({
  1158. // visual hide scrollbar
  1159. '.scrollbar-hide': {
  1160. /* Firefox */
  1161. 'scrollbar-width': 'none',
  1162. /* Safari and Chrome */
  1163. '&::-webkit-scrollbar': {
  1164. display: 'none',
  1165. },
  1166. } }, fromEntries(['start', 'end', 'center'].map(function (align) { return [
  1167. ".snap-".concat(align),
  1168. { 'scroll-snap-align': align },
  1169. ]; }))), { '.snap-align-none': {
  1170. 'scroll-snap-align': 'none',
  1171. },
  1172. // scroll-snap-type
  1173. '.snap': {
  1174. 'scroll-snap-type': 'var(--scroll-snap-axis, both) var(--scroll-snap-strictness, mandatory)',
  1175. } }), fromEntries(['none', 'mandatory', 'proximity'].map(function (strictness) { return [
  1176. ".snap-".concat(strictness),
  1177. { '--scroll-snap-strictness': strictness },
  1178. ]; }))), fromEntries(['x', 'y', 'block', 'inline', 'both'].map(function (axis) { return [
  1179. ".snap-".concat(axis),
  1180. { '--scroll-snap-axis': axis },
  1181. ]; }))), fromEntries(['normal', 'always'].map(function (limit) { return [
  1182. ".snap-".concat(limit),
  1183. { 'scroll-snap-stop': limit },
  1184. ]; }))));
  1185. ['margin', 'padding'].forEach(function (name) {
  1186. var n = name.charAt(0);
  1187. var tn = dashToCamel("snap-".concat(name));
  1188. addDynamic("snap-".concat(n), function (_a) {
  1189. var Utility = _a.Utility, Property = _a.Property;
  1190. var value = Utility.handler
  1191. .handleStatic(theme(tn))
  1192. .handleSquareBrackets()
  1193. .handleSpacing()
  1194. .handleSize()
  1195. .handleNegative()
  1196. .handleVariable().value;
  1197. if (!value)
  1198. return;
  1199. var suf = Utility.raw.split('-');
  1200. var directions = expandDirection(suf.length ? suf[1].substring(1) : '', false);
  1201. if (directions) {
  1202. if (directions[0] === '*')
  1203. return Property("scroll-".concat(name), value);
  1204. return Property(directions.map(function (i) { return "scroll-".concat(name, "-").concat(i); }), value);
  1205. }
  1206. }, {
  1207. variants: variants(tn),
  1208. group: tn,
  1209. completions: __spreadArray([], ['{static}', '{float}', '{size}', '${var}', '[7px]']
  1210. .map(function (type) { return ['', 'y', 'x', 't', 'l', 'b', 'r']
  1211. .map(function (i) { return "snap-".concat(n).concat(i, "-").concat(type); }); })
  1212. .reduce(function (a, b) { return a.concat(b); }, []), true),
  1213. });
  1214. });
  1215. }, {
  1216. theme: {
  1217. snapMargin: function (theme) {
  1218. var _a;
  1219. return (__assign({ auto: 'auto' }, ((_a = theme('spacing')) !== null && _a !== void 0 ? _a : {})));
  1220. },
  1221. snapPadding: function (theme) { return theme('spacing'); },
  1222. },
  1223. variants: {
  1224. snapMargin: ['responsive'],
  1225. snapPadding: ['responsive'],
  1226. },
  1227. });
  1228. module.exports = index;