@mgdis/core-ui-helpers 1.0.0 → 1.0.1

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.
@@ -1,52 +1,52 @@
1
1
 
2
- > @mgdis/core-ui-helpers@1.0.0 build /builds/core/core-ui/core-ui/packages/helpers
2
+ > @mgdis/core-ui-helpers@1.0.1 build /builds/core/core-ui/core-ui/packages/helpers
3
3
  > rollup -c ./rollup.config.mjs
4
4
 
5
5
  
6
6
  src/angular/index.ts → dist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js...
7
- created dist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js in 5s
7
+ created dist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js in 3.6s
8
8
  
9
9
  src/angular/index.ts → dist/angular/index.d.ts...
10
- created dist/angular/index.d.ts in 2s
10
+ created dist/angular/index.d.ts in 1.2s
11
11
  
12
12
  src/locale/index.ts → dist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js...
13
- created dist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js in 2.9s
13
+ created dist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js in 2.5s
14
14
  
15
15
  src/locale/index.ts → dist/locale/index.d.ts...
16
- created dist/locale/index.d.ts in 1.1s
16
+ created dist/locale/index.d.ts in 1s
17
17
  
18
18
  src/playwright/index.ts → dist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js...
19
- created dist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js in 3.3s
19
+ created dist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js in 2.5s
20
20
  
21
21
  src/playwright/index.ts → dist/playwright/index.d.ts...
22
- created dist/playwright/index.d.ts in 1.1s
22
+ created dist/playwright/index.d.ts in 1s
23
23
  
24
24
  src/stencil/index.ts → dist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js...
25
- created dist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js in 3s
25
+ created dist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js in 2.9s
26
26
  
27
27
  src/stencil/index.ts → dist/stencil/index.d.ts...
28
28
  created dist/stencil/index.d.ts in 1s
29
29
  
30
30
  src/storybook/index.ts → dist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js...
31
- created dist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js in 2.5s
31
+ created dist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js in 2.4s
32
32
  
33
33
  src/storybook/index.ts → dist/storybook/index.d.ts...
34
- created dist/storybook/index.d.ts in 1.2s
34
+ created dist/storybook/index.d.ts in 971ms
35
35
  
36
36
  src/tests/index.ts → dist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js...
37
- created dist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js in 2.8s
37
+ created dist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js in 2.1s
38
38
  
39
39
  src/tests/index.ts → dist/tests/index.d.ts...
40
- created dist/tests/index.d.ts in 1s
40
+ created dist/tests/index.d.ts in 989ms
41
41
  
42
42
  src/utils/index.ts → dist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js...
43
- created dist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js in 2.9s
43
+ created dist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js in 2.7s
44
44
  
45
45
  src/utils/index.ts → dist/utils/index.d.ts...
46
- created dist/utils/index.d.ts in 1.3s
46
+ created dist/utils/index.d.ts in 1s
47
47
  
48
48
  src/vue/index.ts → dist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js...
49
- created dist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js in 2.7s
49
+ created dist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js in 2.4s
50
50
  
51
51
  src/vue/index.ts → dist/vue/index.d.ts...
52
- created dist/vue/index.d.ts in 1.1s
52
+ created dist/vue/index.d.ts in 899ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mgdis/core-ui-helpers
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2cda5b3: Update dependencies
8
+
3
9
  ## 1.0.0
4
10
 
5
11
  ### Major Changes
@@ -1070,73 +1070,6 @@ const setIgnoreAttribute = (html) => {
1070
1070
  return html
1071
1071
  };
1072
1072
 
1073
- /**
1074
- * @typedef {"<" | ">" | "\n" | "\r" | " " | "\t"} ReplacementKey
1075
- * Defines the possible keys for the replacements object.
1076
- */
1077
-
1078
- /**
1079
- * Replace entities with ignore string.
1080
- *
1081
- * @param {string} html
1082
- * @param {import('htmlfy').Config} config
1083
- * @returns {string}
1084
- */
1085
- const setIgnoreElement = (html, config) => {
1086
- const ignore = config.ignore;
1087
- const ignore_string = config.ignore_with;
1088
-
1089
- /* Pre-create replacement map for faster lookup. */
1090
- const replacements = {
1091
- "<": "-" + ignore_string + "lt-",
1092
- ">": "-" + ignore_string + "gt-",
1093
- "\n": "-" + ignore_string + "nl-",
1094
- "\r": "-" + ignore_string + "cr-",
1095
- " ": "-" + ignore_string + "ws-", // Use space ' ' as key
1096
- "\t": "-" + ignore_string + "tab-", // Use tab '\t' as key (add placeholder if needed)
1097
- // Add other specific whitespace chars like \v, \f if necessary
1098
- };
1099
- /* Regex to match any character we need to replace inside the ignored content. */
1100
- const charReplaceRegex = /[<>\n\r \t]/g;
1101
-
1102
- for (let e = 0; e < ignore.length; e++) {
1103
- const tagName = ignore[e].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
1104
- const regex = new RegExp(
1105
- `<${tagName}[^>]*>(.*?)<\/${tagName}>`,
1106
- "gs" // Use 'g' (global) and 's' (dotAll) flags
1107
- );
1108
-
1109
- html = html.replace(
1110
- regex,
1111
- (/** @type {string} */ fullMatch, /** @type {string} */ capture) => {
1112
- const processedCapture = capture.replace(
1113
- charReplaceRegex,
1114
- (/** @type {string} */ char) => {
1115
- return replacements[/** @type {ReplacementKey} */ (char)] // Return the placeholder
1116
- // Or safer if map might be incomplete: return replacements[char] || char
1117
- }
1118
- );
1119
-
1120
- /* Reconstruct the string using original tags and processed content. */
1121
- const openingTagEnd = fullMatch.indexOf(">") + 1;
1122
- const closingTagStart = fullMatch.lastIndexOf(`</${tagName}>`);
1123
-
1124
- /* Check if tags were found (basic sanity check). */
1125
- if (openingTagEnd > 0 && closingTagStart > 0) {
1126
- const openingTag = fullMatch.substring(0, openingTagEnd);
1127
- const closingTag = fullMatch.substring(closingTagStart);
1128
- return openingTag + processedCapture + closingTag
1129
- } else {
1130
- // Should not happen with valid HTML and correct regex
1131
- // Return original match to avoid breaking things further
1132
- return fullMatch
1133
- }
1134
- }
1135
- );
1136
- }
1137
- return html
1138
- };
1139
-
1140
1073
  /**
1141
1074
  * Trim leading and trailing whitespace characters.
1142
1075
  *
@@ -1226,34 +1159,6 @@ const unsetIgnoreAttribute = (html) => {
1226
1159
  )
1227
1160
  };
1228
1161
 
1229
- /**
1230
- * Replace ignore string with entities.
1231
- *
1232
- * @param {string} html
1233
- * @param {import('htmlfy').Config} config
1234
- * @returns {string}
1235
- */
1236
- const unsetIgnoreElement = (html, config) => {
1237
- const ignore = config.ignore;
1238
- const ignore_string = config.ignore_with;
1239
-
1240
- for (let e = 0; e < ignore.length; e++) {
1241
- const regex = new RegExp(`<${ignore[e]}[^>]*>((.|\n)*?)<\/${ignore[e]}>`, "g");
1242
-
1243
- html = html.replace(regex, (/** @type {string} */match, /** @type {any} */capture) => {
1244
- return match.replace(capture, (match) => {
1245
- return match
1246
- .replace(new RegExp('-' + ignore_string + 'lt-', "g"), '<')
1247
- .replace(new RegExp('-' + ignore_string + 'gt-', "g"), '>')
1248
- .replace(new RegExp('-' + ignore_string + 'nl-', "g"), '\n')
1249
- .replace(new RegExp('-' + ignore_string + 'cr-', "g"), '\r')
1250
- .replace(new RegExp('-' + ignore_string + 'ws-', "g"), ' ')
1251
- })
1252
- });
1253
- }
1254
- return html
1255
- };
1256
-
1257
1162
  /**
1258
1163
  * Validate any passed-in config options and merge with CONFIG.
1259
1164
  *
@@ -1388,6 +1293,71 @@ const wordWrap = (text, width, indent) => {
1388
1293
  return protectContent(result)
1389
1294
  };
1390
1295
 
1296
+ /**
1297
+ * Extract any HTML blocks to be ignored,
1298
+ * and replace them with a placeholder
1299
+ * for re-insertion later.
1300
+ *
1301
+ * @param {string} html
1302
+ * @param {import('htmlfy').Config} config
1303
+ * @returns {{ html_with_markers: string, extracted_map: Map<any,any> }}
1304
+ */
1305
+ function extractIgnoredBlocks(html, config) {
1306
+ let current_html = html;
1307
+ const extracted_blocks = new Map();
1308
+ let marker_id = 0;
1309
+ const MARKER_PREFIX = "___HTMLFY_SPECIAL_IGNORE_MARKER_";
1310
+
1311
+ for (const tag of config.ignore) {
1312
+ /* Ensure tag is escaped if it can contain regex special chars. */
1313
+ const safe_tag_name = tag.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
1314
+
1315
+ const regex = new RegExp(
1316
+ `<${safe_tag_name}[^>]*>.*?<\/${safe_tag_name}>`,
1317
+ "gs" // global and dotAll
1318
+ );
1319
+
1320
+ let match;
1321
+ const replacements = []; // Store [startIndex, endIndex, marker]
1322
+
1323
+ while ((match = regex.exec(current_html)) !== null) {
1324
+ const marker = `${MARKER_PREFIX}${marker_id++}___`;
1325
+ extracted_blocks.set(marker, match[0]); // Store the full original match
1326
+ replacements.push({
1327
+ start: match.index,
1328
+ end: regex.lastIndex,
1329
+ marker: marker,
1330
+ });
1331
+ }
1332
+
1333
+ /* Apply replacements from the end to the beginning to keep indices valid. */
1334
+ for (let i = replacements.length - 1; i >= 0; i--) {
1335
+ const rep = replacements[i];
1336
+ current_html =
1337
+ current_html.substring(0, rep.start) +
1338
+ rep.marker +
1339
+ current_html.substring(rep.end);
1340
+ }
1341
+ }
1342
+ return { html_with_markers: current_html, extracted_map: extracted_blocks }
1343
+ }
1344
+
1345
+ /**
1346
+ * Re-insert ignored HTML blocks.
1347
+ *
1348
+ * @param {string} html_with_markers
1349
+ * @param {Map<any,any>} extracted_map
1350
+ * @returns
1351
+ */
1352
+ function reinsertIgnoredBlocks(html_with_markers, extracted_map) {
1353
+ let final_html = html_with_markers;
1354
+
1355
+ for (const [marker, original_block] of extracted_map) {
1356
+ final_html = final_html.split(marker).join(original_block);
1357
+ }
1358
+ return final_html
1359
+ }
1360
+
1391
1361
  /**
1392
1362
  * Ensure void elements are "self-closing".
1393
1363
  *
@@ -1534,6 +1504,11 @@ const convert = {
1534
1504
  line: []
1535
1505
  };
1536
1506
 
1507
+ /**
1508
+ * @type {Map<any,any>}
1509
+ */
1510
+ let ignore_map;
1511
+
1537
1512
  /**
1538
1513
  * Isolate tags, content, and comments.
1539
1514
  *
@@ -1644,6 +1619,25 @@ const process = (html, config) => {
1644
1619
  const current_indent_level = offset; // Store the level for this line
1645
1620
 
1646
1621
  indents = indents.substring(0, current_indent_level); // Adjust for *next* round
1622
+
1623
+ /**
1624
+ * Starts with a single punctuation character.
1625
+ * Add punctuation to end of previous line.
1626
+ *
1627
+ * TODO - Implement inline groups instead?
1628
+ */
1629
+ if (source.type === 'text' && /^[!,;\.]/.test(current_line_value)) {
1630
+ if (current_line_value.length === 1) {
1631
+ output_lines[output_lines.length - 1] =
1632
+ output_lines.at(-1) + current_line_value;
1633
+ return
1634
+ } else {
1635
+ output_lines[output_lines.length - 1] =
1636
+ output_lines.at(-1) + current_line_value.charAt(0);
1637
+ current_line_value = current_line_value.slice(1).trim();
1638
+ }
1639
+ }
1640
+
1647
1641
  const padding = step.repeat(current_indent_level);
1648
1642
 
1649
1643
  if (is_ignored_content) {
@@ -1755,8 +1749,12 @@ const prettify = (html, config) => {
1755
1749
  const ignore = validated_config.ignore.length > 0;
1756
1750
  trim = validated_config.trim;
1757
1751
 
1758
- /* Preserve ignored elements. */
1759
- if (ignore) html = setIgnoreElement(html, validated_config);
1752
+ /* Extract ignored elements. */
1753
+ if (ignore) {
1754
+ const { html_with_markers, extracted_map } = extractIgnoredBlocks(html, validated_config);
1755
+ html = html_with_markers;
1756
+ ignore_map = extracted_map;
1757
+ }
1760
1758
 
1761
1759
  /* Preserve html text within attribute values. */
1762
1760
  html = setIgnoreAttribute(html);
@@ -1767,8 +1765,10 @@ const prettify = (html, config) => {
1767
1765
  /* Revert html text within attribute values. */
1768
1766
  html = unsetIgnoreAttribute(html);
1769
1767
 
1770
- /* Revert ignored elements. */
1771
- if (ignore) html = unsetIgnoreElement(html, validated_config);
1768
+ /* Re-insert ignored elements. */
1769
+ if (ignore) {
1770
+ html = reinsertIgnoredBlocks(html, ignore_map);
1771
+ }
1772
1772
 
1773
1773
  return html
1774
1774
  };