@mgdis/core-ui-helpers 1.0.0 → 1.0.2
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.
- package/.turbo/turbo-build.log +31 -17
- package/CHANGELOG.md +13 -0
- package/dist/locale/index.cjs +1 -1
- package/dist/locale/index.cjs.map +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/locale/index.js.map +1 -1
- package/dist/locale/index.umd.js +1 -1
- package/dist/locale/index.umd.js.map +1 -1
- package/dist/playwright/index.cjs.map +1 -1
- package/dist/playwright/index.js.map +1 -1
- package/dist/playwright/index.umd.js.map +1 -1
- package/dist/stencil/index.cjs.map +1 -1
- package/dist/stencil/index.js.map +1 -1
- package/dist/stencil/index.umd.js.map +1 -1
- package/dist/storybook/index.cjs +99 -99
- package/dist/storybook/index.cjs.map +1 -1
- package/dist/storybook/index.js +99 -99
- package/dist/storybook/index.js.map +1 -1
- package/dist/storybook/index.umd.js +99 -99
- package/dist/storybook/index.umd.js.map +1 -1
- package/dist/tests/index.cjs.map +1 -1
- package/dist/tests/index.js.map +1 -1
- package/dist/tests/index.umd.js.map +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.umd.js.map +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.umd.js.map +1 -1
- package/package.json +15 -15
- package/src/locale/locale.ts +1 -1
package/dist/storybook/index.cjs
CHANGED
|
@@ -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
|
-
/*
|
|
1759
|
-
if (ignore)
|
|
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
|
-
/*
|
|
1771
|
-
if (ignore)
|
|
1768
|
+
/* Re-insert ignored elements. */
|
|
1769
|
+
if (ignore) {
|
|
1770
|
+
html = reinsertIgnoredBlocks(html, ignore_map);
|
|
1771
|
+
}
|
|
1772
1772
|
|
|
1773
1773
|
return html
|
|
1774
1774
|
};
|