@mgdis/core-ui-helpers 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.turbo/turbo-build.log +16 -30
  2. package/CHANGELOG.md +14 -0
  3. package/dist/angular/index.cjs.map +1 -1
  4. package/dist/angular/index.js.map +1 -1
  5. package/dist/angular/index.umd.js.map +1 -1
  6. package/dist/locale/index.cjs.map +1 -1
  7. package/dist/locale/index.js.map +1 -1
  8. package/dist/locale/index.umd.js.map +1 -1
  9. package/dist/playwright/index.cjs.map +1 -1
  10. package/dist/playwright/index.js.map +1 -1
  11. package/dist/playwright/index.umd.js.map +1 -1
  12. package/dist/stencil/index.cjs +18 -1
  13. package/dist/stencil/index.cjs.map +1 -1
  14. package/dist/stencil/index.js +18 -1
  15. package/dist/stencil/index.js.map +1 -1
  16. package/dist/stencil/index.umd.js +18 -1
  17. package/dist/stencil/index.umd.js.map +1 -1
  18. package/dist/storybook/index.cjs +118 -46
  19. package/dist/storybook/index.cjs.map +1 -1
  20. package/dist/storybook/index.js +118 -46
  21. package/dist/storybook/index.js.map +1 -1
  22. package/dist/storybook/index.umd.js +118 -46
  23. package/dist/storybook/index.umd.js.map +1 -1
  24. package/dist/tests/index.cjs +134 -0
  25. package/dist/tests/index.cjs.map +1 -1
  26. package/dist/tests/index.d.ts +10 -1
  27. package/dist/tests/index.js +134 -1
  28. package/dist/tests/index.js.map +1 -1
  29. package/dist/tests/index.umd.js +134 -0
  30. package/dist/tests/index.umd.js.map +1 -1
  31. package/dist/utils/index.cjs +2 -2
  32. package/dist/utils/index.cjs.map +1 -1
  33. package/dist/utils/index.js +2 -2
  34. package/dist/utils/index.js.map +1 -1
  35. package/dist/utils/index.umd.js +2 -2
  36. package/dist/utils/index.umd.js.map +1 -1
  37. package/dist/vue/index.cjs.map +1 -1
  38. package/dist/vue/index.js.map +1 -1
  39. package/dist/vue/index.umd.js.map +1 -1
  40. package/package.json +12 -12
  41. package/src/tests/index.spec.ts +2 -1
  42. package/src/tests/unit/unit.spec.ts +121 -1
  43. package/src/tests/unit/unit.ts +135 -0
  44. package/src/utils/object/object.spec.ts +12 -0
  45. package/src/utils/object/object.ts +2 -2
@@ -7,7 +7,7 @@ var BUILD = {
7
7
  };
8
8
 
9
9
  /*
10
- Stencil Client Platform v4.28.2 | MIT Licensed | https://stenciljs.com
10
+ Stencil Client Platform v4.36.3 | MIT Licensed | https://stenciljs.com
11
11
  */
12
12
  var __defProp = Object.defineProperty;
13
13
  var __export = (target, all) => {
@@ -38,6 +38,11 @@ var isComplexType = (o) => {
38
38
  return o === "object" || o === "function";
39
39
  };
40
40
 
41
+ // src/utils/regular-expression.ts
42
+ var escapeRegExpSpecialCharacters = (text) => {
43
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
44
+ };
45
+
41
46
  // src/utils/result.ts
42
47
  var result_exports = {};
43
48
  __export(result_exports, {
@@ -162,7 +167,7 @@ function patchSlotNode(node) {
162
167
  const slotName = this["s-sn"];
163
168
  if (opts == null ? void 0 : opts.flatten) {
164
169
  console.error(`
165
- Flattening is not supported for Stencil non-shadow slots.
170
+ Flattening is not supported for Stencil non-shadow slots.
166
171
  You can use \`.childNodes\` to nested slot fallback content.
167
172
  If you have a particular use case, please open an issue on the Stencil repo.
168
173
  `);
@@ -252,6 +257,18 @@ var newVNode = (tag, text) => {
252
257
  };
253
258
  var Host = {};
254
259
  var isHost = (node) => node && node.$tag$ === Host;
260
+ var createSupportsRuleRe = (selector) => {
261
+ const safeSelector2 = escapeRegExpSpecialCharacters(selector);
262
+ return new RegExp(
263
+ // First capture group: match any context before the selector that's not inside @supports selector()
264
+ // Using negative lookahead to avoid matching inside @supports selector(...) condition
265
+ `(^|[^@]|@(?!supports\\s+selector\\s*\\([^{]*?${safeSelector2}))(${safeSelector2}\\b)`,
266
+ "g"
267
+ );
268
+ };
269
+ createSupportsRuleRe("::slotted");
270
+ createSupportsRuleRe(":host");
271
+ createSupportsRuleRe(":host-context");
255
272
  var setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRender) => {
256
273
  if (oldValue === newValue) {
257
274
  return;
@@ -693,7 +710,7 @@ var patch = (oldVNode, newVNode2, isInitialRender = false) => {
693
710
  !isInitialRender && BUILD.updatable && oldChildren !== null
694
711
  ) {
695
712
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
696
- }
713
+ } else ;
697
714
  if (isSvgMode && tag === "svg") {
698
715
  isSvgMode = false;
699
716
  }
@@ -793,7 +810,8 @@ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
793
810
  const hostElm = hostRef.$hostElement$;
794
811
  const cmpMeta = hostRef.$cmpMeta$;
795
812
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
796
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
813
+ const isHostElement = isHost(renderFnResults);
814
+ const rootVnode = isHostElement ? renderFnResults : h(null, null, renderFnResults);
797
815
  hostTagName = hostElm.tagName;
798
816
  if (cmpMeta.$attrsToReflect$) {
799
817
  rootVnode.$attrs$ = rootVnode.$attrs$ || {};
@@ -923,6 +941,34 @@ const VOID_ELEMENTS = [
923
941
  'param', 'source', 'track', 'wbr'
924
942
  ];
925
943
 
944
+ /**
945
+ * @typedef {object} State
946
+ * @property {boolean} checked_html - If passed in HTML has been checked for HTML within it.
947
+ * @property {import("htmlfy").Config} config - Validated configuration.
948
+ * @property {boolean} ignored
949
+ */
950
+
951
+ /**
952
+ * @type State
953
+ */
954
+ const state = {
955
+ checked_html: false,
956
+ config: { ...CONFIG },
957
+ ignored: false
958
+ };
959
+
960
+ /**
961
+ *
962
+ * @returns {State}
963
+ */
964
+ const getState = () => state;
965
+
966
+ /**
967
+ *
968
+ * @param {Partial<State>} new_state
969
+ */
970
+ const setState = (new_state) => Object.assign(state, new_state);
971
+
926
972
  /**
927
973
  * Checks if content contains at least one HTML element or custom HTML element.
928
974
  *
@@ -945,10 +991,13 @@ const VOID_ELEMENTS = [
945
991
  * @param {string} content Content to evaluate.
946
992
  * @returns {boolean} A boolean.
947
993
  */
948
- const isHtml = (content) =>
949
- /<(?:[A-Za-z]+[A-Za-z0-9]*)(?:\s+.*?)*?\/{0,1}>/.test(content) ||
994
+ const isHtml = (content) => {
995
+ setState({ checked_html: true });
996
+
997
+ return /<(?:[A-Za-z]+[A-Za-z0-9]*)(?:\s+.*?)*?\/{0,1}>/.test(content) ||
950
998
  /<(?<Element>(?:[A-Za-z]+[A-Za-z0-9]*:)?(?:[A-Za-z]+[A-Za-z0-9]*))(?:\s+.*?)*?>(?:.|\n)*?<\/{1}\k<Element>>/.test(content) ||
951
- /<(?<Element>(?:[a-z][a-z0-9._]*:)?[a-z][a-z0-9._]*-[a-z0-9._-]+)(?:\s+.*?)*?>(?:.|\n)*?<\/{1}\k<Element>>/.test(content);
999
+ /<(?<Element>(?:[a-z][a-z0-9._]*:)?[a-z][a-z0-9._]*-[a-z0-9._-]+)(?:\s+.*?)*?>(?:.|\n)*?<\/{1}\k<Element>>/.test(content)
1000
+ };
952
1001
 
953
1002
  /**
954
1003
  * Generic utility which merges two objects.
@@ -986,16 +1035,14 @@ const mergeObjects = (current, updates) => {
986
1035
  /**
987
1036
  * Merge a user config with the default config.
988
1037
  *
989
- * @param {import('htmlfy').Config} dconfig The default config.
1038
+ * @param {import('htmlfy').Config} default_config The default config.
990
1039
  * @param {import('htmlfy').UserConfig} config The user config.
991
1040
  * @returns {import('htmlfy').Config}
992
1041
  */
993
- const mergeConfig = (dconfig, config) => {
994
- /**
995
- * We need to make a deep copy of `dconfig`,
996
- * otherwise we end up altering the original `CONFIG` because `dconfig` is a reference to it.
997
- */
998
- return mergeObjects(structuredClone(dconfig), config)
1042
+ const mergeConfig = (default_config, config) => {
1043
+ const validated_config = mergeObjects(default_config, config);
1044
+ setState({ config: validated_config });
1045
+ return validated_config
999
1046
  };
1000
1047
 
1001
1048
  /**
@@ -1165,6 +1212,8 @@ const unsetIgnoreAttribute = (html) => {
1165
1212
  */
1166
1213
  const validateConfig = (config) => {
1167
1214
  if (typeof config !== 'object') throw new Error('Config must be an object.')
1215
+
1216
+ const default_config = { ...CONFIG };
1168
1217
 
1169
1218
  const config_empty = !(
1170
1219
  Object.hasOwn(config, 'content_wrap') ||
@@ -1177,7 +1226,10 @@ const validateConfig = (config) => {
1177
1226
  Object.hasOwn(config, 'trim')
1178
1227
  );
1179
1228
 
1180
- if (config_empty) return CONFIG
1229
+ if (config_empty) {
1230
+ setState({ config: default_config });
1231
+ return default_config
1232
+ }
1181
1233
 
1182
1234
  let tab_size = config.tab_size;
1183
1235
 
@@ -1215,7 +1267,7 @@ const validateConfig = (config) => {
1215
1267
  if (config.tag_wrap_width)
1216
1268
  config.tag_wrap = config.tag_wrap_width;
1217
1269
  else
1218
- config.tag_wrap = CONFIG.tag_wrap_width;
1270
+ config.tag_wrap = default_config.tag_wrap_width;
1219
1271
  }
1220
1272
 
1221
1273
  if (Object.hasOwn(config, 'tag_wrap') && typeof config.tag_wrap !== 'number')
@@ -1232,7 +1284,7 @@ const validateConfig = (config) => {
1232
1284
  if (Object.hasOwn(config, 'trim') && (!Array.isArray(config.trim) || !config.trim?.every((e) => typeof e === 'string')))
1233
1285
  throw new Error('Trim config must be an array of strings.')
1234
1286
 
1235
- return mergeConfig(CONFIG, config)
1287
+ return mergeConfig(default_config, config)
1236
1288
 
1237
1289
  };
1238
1290
 
@@ -1301,6 +1353,7 @@ const wordWrap = (text, width, indent) => {
1301
1353
  * @returns {{ html_with_markers: string, extracted_map: Map<any,any> }}
1302
1354
  */
1303
1355
  function extractIgnoredBlocks(html, config) {
1356
+ setState({ ignored: true });
1304
1357
  let current_html = html;
1305
1358
  const extracted_blocks = new Map();
1306
1359
  let marker_id = 0;
@@ -1348,6 +1401,7 @@ function extractIgnoredBlocks(html, config) {
1348
1401
  * @returns
1349
1402
  */
1350
1403
  function reinsertIgnoredBlocks(html_with_markers, extracted_map) {
1404
+ setState({ ignored: false });
1351
1405
  let final_html = html_with_markers;
1352
1406
 
1353
1407
  for (const [marker, original_block] of extracted_map) {
@@ -1360,12 +1414,13 @@ function reinsertIgnoredBlocks(html_with_markers, extracted_map) {
1360
1414
  * Ensure void elements are "self-closing".
1361
1415
  *
1362
1416
  * @param {string} html The HTML string to evaluate.
1363
- * @param {boolean} check_html Check to see if the content contains any HTML, before processing.
1364
1417
  * @returns {string}
1365
1418
  * @example <br> => <br />
1366
1419
  */
1367
- const closify = (html, check_html = true) => {
1368
- if (check_html && !isHtml(html)) return html
1420
+ const closify = (html) => {
1421
+ const { checked_html } = getState();
1422
+
1423
+ if (!checked_html && !isHtml(html)) return html
1369
1424
 
1370
1425
  return html.replace(/<([a-zA-Z\-0-9:]+)[^>]*>/g, (match, name) => {
1371
1426
  if (VOID_ELEMENTS.indexOf(name) > -1)
@@ -1430,16 +1485,35 @@ const entify = (html, minify = false) => {
1430
1485
  return html
1431
1486
  };
1432
1487
 
1488
+ /**
1489
+ * @type {Map<any,any>}
1490
+ */
1491
+ let ignore_map$1;
1492
+
1433
1493
  /**
1434
1494
  * Creates a single-line HTML string
1435
1495
  * by removing line returns, tabs, and relevant spaces.
1436
1496
  *
1437
1497
  * @param {string} html The HTML string to minify.
1438
- * @param {boolean} check_html Check to see if the content contains any HTML, before processing.
1498
+ * @param {import('htmlfy').UserConfig} [config] A user configuration object.
1439
1499
  * @returns {string} A minified HTML string.
1440
1500
  */
1441
- const minify = (html, check_html = true) => {
1442
- if (check_html && !isHtml(html)) return html
1501
+ const minify = (html, config) => {
1502
+ let reinsert_ignored = false;
1503
+ const { checked_html, ignored } = getState();
1504
+
1505
+ if (!checked_html && !isHtml(html)) return html
1506
+
1507
+ const validated_config = (getState()).config;
1508
+ const ignore = validated_config.ignore.length > 0;
1509
+
1510
+ /* Extract ignored elements. Skipped if prettify has already ignored blocks. */
1511
+ if (!ignored && ignore) {
1512
+ const { html_with_markers, extracted_map } = extractIgnoredBlocks(html, validated_config);
1513
+ html = html_with_markers;
1514
+ ignore_map$1 = extracted_map;
1515
+ reinsert_ignored = true;
1516
+ }
1443
1517
 
1444
1518
  /**
1445
1519
  * Ensure textarea content is specially minified and protected
@@ -1482,19 +1556,14 @@ const minify = (html, check_html = true) => {
1482
1556
  // Final trim for the whole string
1483
1557
  html = html.trim();
1484
1558
 
1559
+ /* Re-insert ignored elements. Skipped unless minify did the ignore. */
1560
+ if (reinsert_ignored) {
1561
+ html = reinsertIgnoredBlocks(html, ignore_map$1);
1562
+ }
1563
+
1485
1564
  return html
1486
1565
  };
1487
1566
 
1488
- /**
1489
- * @type {boolean}
1490
- */
1491
- let strict;
1492
-
1493
- /**
1494
- * @type {string[]}
1495
- */
1496
- let trim;
1497
-
1498
1567
  /**
1499
1568
  * @type {{ line: Record<string,string>[] }}
1500
1569
  */
@@ -1545,11 +1614,13 @@ const enqueue = (html) => {
1545
1614
  * @returns {string}
1546
1615
  */
1547
1616
  const preprocess = (html) => {
1548
- html = closify(html, false);
1617
+ html = closify(html);
1549
1618
 
1550
- if (trim.length > 0) html = trimify(html, trim);
1619
+ const { config } = getState();
1551
1620
 
1552
- html = minify(html, false);
1621
+ if (config.trim.length > 0) html = trimify(html, config.trim);
1622
+
1623
+ html = minify(html);
1553
1624
  html = enqueue(html);
1554
1625
 
1555
1626
  return html
@@ -1557,16 +1628,16 @@ const preprocess = (html) => {
1557
1628
 
1558
1629
  /**
1559
1630
  *
1560
- * @param {string} html The HTML string to process.
1561
1631
  * @param {import('htmlfy').Config} config
1562
1632
  * @returns {string}
1563
1633
  */
1564
- const process = (html, config) => {
1634
+ const process = (config) => {
1565
1635
  const step = " ".repeat(config.tab_size);
1566
1636
  const tag_wrap = config.tag_wrap;
1567
1637
  const content_wrap = config.content_wrap;
1568
1638
  const ignore_with = config.ignore_with;
1569
1639
  const placeholder_template = `-${ignore_with}`;
1640
+ const strict = config.strict;
1570
1641
 
1571
1642
  /* Track current number of indentations needed. */
1572
1643
  let indents = '';
@@ -1738,33 +1809,34 @@ const process = (html, config) => {
1738
1809
  * @returns {string} A well-formed HTML string.
1739
1810
  */
1740
1811
  const prettify = (html, config) => {
1741
- /* Return content as-is if it does not contain any HTML elements. */
1742
- if (!isHtml(html)) return html
1812
+ let reinsert_ignored = false;
1813
+ const { checked_html, ignored } = getState();
1743
1814
 
1744
- const validated_config = config ? validateConfig(config) : CONFIG;
1745
- strict = validated_config.strict;
1815
+ /* Return content as-is if it does not contain any HTML elements. */
1816
+ if (!checked_html && !isHtml(html)) return html
1746
1817
 
1818
+ const validated_config = config ? validateConfig(config) : { ...CONFIG };
1747
1819
  const ignore = validated_config.ignore.length > 0;
1748
- trim = validated_config.trim;
1749
1820
 
1750
1821
  /* Extract ignored elements. */
1751
- if (ignore) {
1822
+ if (!ignored && ignore) {
1752
1823
  const { html_with_markers, extracted_map } = extractIgnoredBlocks(html, validated_config);
1753
1824
  html = html_with_markers;
1754
1825
  ignore_map = extracted_map;
1826
+ reinsert_ignored = true;
1755
1827
  }
1756
1828
 
1757
1829
  /* Preserve html text within attribute values. */
1758
1830
  html = setIgnoreAttribute(html);
1759
1831
 
1760
1832
  html = preprocess(html);
1761
- html = process(html, validated_config);
1833
+ html = process(validated_config);
1762
1834
 
1763
1835
  /* Revert html text within attribute values. */
1764
1836
  html = unsetIgnoreAttribute(html);
1765
1837
 
1766
1838
  /* Re-insert ignored elements. */
1767
- if (ignore) {
1839
+ if (reinsert_ignored) {
1768
1840
  html = reinsertIgnoredBlocks(html, ignore_map);
1769
1841
  }
1770
1842