@mgdis/core-ui-helpers 1.0.4 → 1.0.6
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 +17 -17
- package/CHANGELOG.md +13 -0
- package/dist/stencil/index.cjs +1 -1
- package/dist/stencil/index.cjs.map +1 -1
- package/dist/stencil/index.js +1 -1
- package/dist/stencil/index.js.map +1 -1
- package/dist/stencil/index.umd.js +1 -1
- package/dist/stencil/index.umd.js.map +1 -1
- package/dist/storybook/index.cjs +230 -156
- package/dist/storybook/index.cjs.map +1 -1
- package/dist/storybook/index.js +230 -156
- package/dist/storybook/index.js.map +1 -1
- package/dist/storybook/index.umd.js +230 -156
- package/dist/storybook/index.umd.js.map +1 -1
- package/package.json +12 -12
package/dist/storybook/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var BUILD = {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
/*
|
|
10
|
-
Stencil Client Platform v4.
|
|
10
|
+
Stencil Client Platform v4.38.0 | MIT Licensed | https://stenciljs.com
|
|
11
11
|
*/
|
|
12
12
|
var __defProp = Object.defineProperty;
|
|
13
13
|
var __export = (target, all) => {
|
|
@@ -815,9 +815,13 @@ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
|
|
|
815
815
|
hostTagName = hostElm.tagName;
|
|
816
816
|
if (cmpMeta.$attrsToReflect$) {
|
|
817
817
|
rootVnode.$attrs$ = rootVnode.$attrs$ || {};
|
|
818
|
-
cmpMeta.$attrsToReflect$.
|
|
819
|
-
(
|
|
820
|
-
|
|
818
|
+
cmpMeta.$attrsToReflect$.forEach(([propName, attribute]) => {
|
|
819
|
+
if (BUILD.serializer && hostRef.$serializerValues$.has(propName)) {
|
|
820
|
+
rootVnode.$attrs$[attribute] = hostRef.$serializerValues$.get(propName);
|
|
821
|
+
} else {
|
|
822
|
+
rootVnode.$attrs$[attribute] = hostElm[propName];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
821
825
|
}
|
|
822
826
|
if (isInitialLoad && rootVnode.$attrs$) {
|
|
823
827
|
for (const key of Object.keys(rootVnode.$attrs$)) {
|
|
@@ -924,37 +928,55 @@ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
|
|
|
924
928
|
const CONFIG = {
|
|
925
929
|
content_wrap: 0,
|
|
926
930
|
ignore: [],
|
|
927
|
-
ignore_with: '
|
|
931
|
+
ignore_with: '!i-£___£%_',
|
|
928
932
|
strict: false,
|
|
929
933
|
tab_size: 2,
|
|
930
934
|
tag_wrap: 0,
|
|
931
|
-
tag_wrap_width: 80,
|
|
932
935
|
trim: []
|
|
933
936
|
};
|
|
934
937
|
|
|
935
|
-
const CONTENT_IGNORE_STRING = '__!i-£___£%__';
|
|
936
|
-
const IGNORE_STRING = '!i-£___£%_';
|
|
937
|
-
|
|
938
938
|
const VOID_ELEMENTS = [
|
|
939
939
|
'area', 'base', 'br', 'col', 'embed', 'hr',
|
|
940
940
|
'img', 'input', 'link', 'meta',
|
|
941
941
|
'param', 'source', 'track', 'wbr'
|
|
942
942
|
];
|
|
943
943
|
|
|
944
|
+
/**
|
|
945
|
+
* Defined by state.js and configuration.
|
|
946
|
+
*
|
|
947
|
+
* CONTENT_IGNORE_PLACEHOLDER
|
|
948
|
+
* SELF_CLOSING_PLACEHOLDER
|
|
949
|
+
* ATTRIBUTE_IGNORE_PLACEHOLDER
|
|
950
|
+
*/
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* @typedef {object} Constants
|
|
954
|
+
* @property {string} CONTENT_IGNORE_PLACEHOLDER
|
|
955
|
+
* @property {string} SELF_CLOSING_PLACEHOLDER
|
|
956
|
+
* @property {string} ATTRIBUTE_IGNORE_PLACEHOLDER
|
|
957
|
+
*/
|
|
944
958
|
/**
|
|
945
959
|
* @typedef {object} State
|
|
946
960
|
* @property {boolean} checked_html - If passed in HTML has been checked for HTML within it.
|
|
947
961
|
* @property {import("htmlfy").Config} config - Validated configuration.
|
|
948
962
|
* @property {boolean} ignored
|
|
963
|
+
* @property {Constants} constants - Constant strings, influenced by ignore_with.
|
|
949
964
|
*/
|
|
950
965
|
|
|
951
966
|
/**
|
|
952
967
|
* @type State
|
|
968
|
+
*
|
|
969
|
+
* `constants` prefixes and suffixes must be in sync with those in utils.js
|
|
953
970
|
*/
|
|
954
971
|
const state = {
|
|
955
972
|
checked_html: false,
|
|
956
973
|
config: { ...CONFIG },
|
|
957
|
-
ignored: false
|
|
974
|
+
ignored: false,
|
|
975
|
+
constants: {
|
|
976
|
+
CONTENT_IGNORE_PLACEHOLDER: `${CONFIG.ignore_with}_`,
|
|
977
|
+
SELF_CLOSING_PLACEHOLDER: `${CONFIG.ignore_with}/_>`,
|
|
978
|
+
ATTRIBUTE_IGNORE_PLACEHOLDER: `${CONFIG.ignore_with}=_`
|
|
979
|
+
}
|
|
958
980
|
};
|
|
959
981
|
|
|
960
982
|
/**
|
|
@@ -1041,7 +1063,16 @@ const mergeObjects = (current, updates) => {
|
|
|
1041
1063
|
*/
|
|
1042
1064
|
const mergeConfig = (default_config, config) => {
|
|
1043
1065
|
const validated_config = mergeObjects(default_config, config);
|
|
1044
|
-
|
|
1066
|
+
|
|
1067
|
+
/* Below `constants` prefixes and suffixes must be in sync with those in state.js */
|
|
1068
|
+
setState({
|
|
1069
|
+
config: validated_config,
|
|
1070
|
+
constants: {
|
|
1071
|
+
CONTENT_IGNORE_PLACEHOLDER: `${validated_config.ignore_with}_`,
|
|
1072
|
+
SELF_CLOSING_PLACEHOLDER: `${validated_config.ignore_with}/_>`,
|
|
1073
|
+
ATTRIBUTE_IGNORE_PLACEHOLDER: `${validated_config.ignore_with}=_`
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1045
1076
|
return validated_config
|
|
1046
1077
|
};
|
|
1047
1078
|
|
|
@@ -1050,12 +1081,14 @@ const mergeConfig = (default_config, config) => {
|
|
|
1050
1081
|
* @param {string} html
|
|
1051
1082
|
*/
|
|
1052
1083
|
const protectAttributes = (html) => {
|
|
1084
|
+
const { constants } = getState();
|
|
1085
|
+
|
|
1053
1086
|
html = html.replace(/<[\w:\-]+([^>]*[^\/])>/g, (/** @type {string} */match, /** @type {any} */capture) => {
|
|
1054
1087
|
return match.replace(capture, (match) => {
|
|
1055
1088
|
return match
|
|
1056
|
-
.replace(/\n/g,
|
|
1057
|
-
.replace(/\r/g,
|
|
1058
|
-
.replace(/\s/g,
|
|
1089
|
+
.replace(/\n/g, constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'nl!')
|
|
1090
|
+
.replace(/\r/g, constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'cr!')
|
|
1091
|
+
.replace(/\s/g, constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'ws!')
|
|
1059
1092
|
})
|
|
1060
1093
|
});
|
|
1061
1094
|
|
|
@@ -1067,10 +1100,12 @@ const protectAttributes = (html) => {
|
|
|
1067
1100
|
* @param {string} html
|
|
1068
1101
|
*/
|
|
1069
1102
|
const protectContent = (html) => {
|
|
1103
|
+
const { constants } = getState();
|
|
1104
|
+
|
|
1070
1105
|
return html
|
|
1071
|
-
.replace(/\n/g,
|
|
1072
|
-
.replace(/\r/g,
|
|
1073
|
-
.replace(/\s/g,
|
|
1106
|
+
.replace(/\n/g, constants.CONTENT_IGNORE_PLACEHOLDER + 'nl!')
|
|
1107
|
+
.replace(/\r/g, constants.CONTENT_IGNORE_PLACEHOLDER + 'cr!')
|
|
1108
|
+
.replace(/\s/g, constants.CONTENT_IGNORE_PLACEHOLDER + 'ws!')
|
|
1074
1109
|
};
|
|
1075
1110
|
|
|
1076
1111
|
/**
|
|
@@ -1078,7 +1113,9 @@ const protectContent = (html) => {
|
|
|
1078
1113
|
* @param {string} html
|
|
1079
1114
|
*/
|
|
1080
1115
|
const finalProtectContent = (html) => {
|
|
1081
|
-
const regex = /\s*<([a-zA-Z0-9:-]+)[^>]*>\n\s*<\/\1>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n)|<([a-zA-Z0-9:-]+)[^>]*>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n\s*)<\/\3>/g;
|
|
1116
|
+
const regex = /\s*<([a-zA-Z0-9:-]+)[^>]*>\n\s*<\/\1>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n)|<([a-zA-Z0-9:-]+)[^>]*>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n\s*)<\/\3>/g;
|
|
1117
|
+
const { constants } = getState();
|
|
1118
|
+
|
|
1082
1119
|
return html
|
|
1083
1120
|
.replace(regex, (/** @type {string} */match, p1, p2, p3, p4) => {
|
|
1084
1121
|
const text_to_protect = p2 || p4;
|
|
@@ -1087,9 +1124,9 @@ const finalProtectContent = (html) => {
|
|
|
1087
1124
|
return match
|
|
1088
1125
|
|
|
1089
1126
|
const protected_text = text_to_protect
|
|
1090
|
-
.replace(/\n/g,
|
|
1091
|
-
.replace(/\r/g,
|
|
1092
|
-
.replace(/\s/g,
|
|
1127
|
+
.replace(/\n/g, constants.CONTENT_IGNORE_PLACEHOLDER + 'nl!')
|
|
1128
|
+
.replace(/\r/g, constants.CONTENT_IGNORE_PLACEHOLDER + 'cr!')
|
|
1129
|
+
.replace(/\s/g, constants.CONTENT_IGNORE_PLACEHOLDER + "ws!");
|
|
1093
1130
|
|
|
1094
1131
|
return match.replace(text_to_protect, protected_text)
|
|
1095
1132
|
})
|
|
@@ -1102,13 +1139,14 @@ const finalProtectContent = (html) => {
|
|
|
1102
1139
|
* @returns {string}
|
|
1103
1140
|
*/
|
|
1104
1141
|
const setIgnoreAttribute = (html) => {
|
|
1105
|
-
const regex = /<([A-Za-z][A-Za-z0-9]*|[a-z][a-z0-9._]*-[a-z0-9._-]+)((?:\s+[A-Za-z0-9_-]+="[^"]*"|\s*[a-z]*)*)>/g;
|
|
1142
|
+
const regex = /<([A-Za-z][A-Za-z0-9]*|[a-z][a-z0-9._]*-[a-z0-9._-]+)((?:\s+[A-Za-z0-9_-]+="[^"]*"|\s*[a-z]*)*)>/g;
|
|
1143
|
+
const { constants } = getState();
|
|
1106
1144
|
|
|
1107
1145
|
html = html.replace(regex, (/** @type {string} */match, p1, p2) => {
|
|
1108
1146
|
return match.replace(p2, (match) => {
|
|
1109
1147
|
return match
|
|
1110
|
-
.replace(/</g,
|
|
1111
|
-
.replace(/>/g,
|
|
1148
|
+
.replace(/</g, constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'lt!')
|
|
1149
|
+
.replace(/>/g, constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'gt!')
|
|
1112
1150
|
})
|
|
1113
1151
|
});
|
|
1114
1152
|
|
|
@@ -1141,12 +1179,14 @@ const trimify = (html, trim) => {
|
|
|
1141
1179
|
* @param {string} html
|
|
1142
1180
|
*/
|
|
1143
1181
|
const unprotectAttributes = (html) => {
|
|
1182
|
+
const { constants } = getState();
|
|
1183
|
+
|
|
1144
1184
|
html = html.replace(/<[\w:\-]+([^>]*[^\/])>/g, (/** @type {string} */match, /** @type {any} */capture) => {
|
|
1145
1185
|
return match.replace(capture, (match) => {
|
|
1146
1186
|
return match
|
|
1147
|
-
.replace(new RegExp(
|
|
1148
|
-
.replace(new RegExp(
|
|
1149
|
-
.replace(new RegExp(
|
|
1187
|
+
.replace(new RegExp(constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'nl!', "g"), '\n')
|
|
1188
|
+
.replace(new RegExp(constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'cr!', "g"), '\r')
|
|
1189
|
+
.replace(new RegExp(constants.ATTRIBUTE_IGNORE_PLACEHOLDER + 'ws!', "g"), ' ')
|
|
1150
1190
|
})
|
|
1151
1191
|
});
|
|
1152
1192
|
|
|
@@ -1158,25 +1198,20 @@ const unprotectAttributes = (html) => {
|
|
|
1158
1198
|
* @param {string} html
|
|
1159
1199
|
*/
|
|
1160
1200
|
const unprotectContent = (html) => {
|
|
1161
|
-
|
|
1162
|
-
|
|
1201
|
+
const { constants } = getState();
|
|
1202
|
+
|
|
1203
|
+
html = html.replace(new RegExp(`.*${constants.CONTENT_IGNORE_PLACEHOLDER}[a-z]{2}!.*`, "g"), (/** @type {string} */match) => {
|
|
1204
|
+
return match.replace(new RegExp(`${constants.CONTENT_IGNORE_PLACEHOLDER}[a-z]{2}!`, "g"), (match) => {
|
|
1163
1205
|
return match
|
|
1164
|
-
.replace(new RegExp(
|
|
1165
|
-
.replace(new RegExp(
|
|
1166
|
-
.replace(new RegExp(
|
|
1206
|
+
.replace(new RegExp(constants.CONTENT_IGNORE_PLACEHOLDER + 'nl!', "g"), '\n')
|
|
1207
|
+
.replace(new RegExp(constants.CONTENT_IGNORE_PLACEHOLDER + 'cr!', "g"), '\r')
|
|
1208
|
+
.replace(new RegExp(constants.CONTENT_IGNORE_PLACEHOLDER + 'ws!', "g"), ' ')
|
|
1167
1209
|
})
|
|
1168
1210
|
});
|
|
1169
1211
|
|
|
1170
1212
|
return html
|
|
1171
1213
|
};
|
|
1172
1214
|
|
|
1173
|
-
const escapedIgnoreString = IGNORE_STRING.replace(
|
|
1174
|
-
/[-\/\\^$*+?.()|[\]{}]/g,
|
|
1175
|
-
"\\$&"
|
|
1176
|
-
);
|
|
1177
|
-
const ltPlaceholderRegex = new RegExp(escapedIgnoreString + "lt!", "g");
|
|
1178
|
-
const gtPlaceholderRegex = new RegExp(escapedIgnoreString + "gt!", "g");
|
|
1179
|
-
|
|
1180
1215
|
/**
|
|
1181
1216
|
* Replace ignore string with html brackets.
|
|
1182
1217
|
*
|
|
@@ -1186,6 +1221,13 @@ const gtPlaceholderRegex = new RegExp(escapedIgnoreString + "gt!", "g");
|
|
|
1186
1221
|
const unsetIgnoreAttribute = (html) => {
|
|
1187
1222
|
/* Regex to find opening tags and capture their attributes. */
|
|
1188
1223
|
const tagRegex = /<([\w:\-]+)([^>]*)>/g;
|
|
1224
|
+
const { constants } = getState();
|
|
1225
|
+
const escapedIgnoreString = constants.ATTRIBUTE_IGNORE_PLACEHOLDER.replace(
|
|
1226
|
+
/[-\/\\^$*+?.()|[\]{}]/g,
|
|
1227
|
+
"\\$&"
|
|
1228
|
+
);
|
|
1229
|
+
const ltPlaceholderRegex = new RegExp(escapedIgnoreString + "lt!", "g");
|
|
1230
|
+
const gtPlaceholderRegex = new RegExp(escapedIgnoreString + "gt!", "g");
|
|
1189
1231
|
|
|
1190
1232
|
return html.replace(
|
|
1191
1233
|
tagRegex,
|
|
@@ -1222,7 +1264,6 @@ const validateConfig = (config) => {
|
|
|
1222
1264
|
Object.hasOwn(config, 'strict') ||
|
|
1223
1265
|
Object.hasOwn(config, 'tab_size') ||
|
|
1224
1266
|
Object.hasOwn(config, 'tag_wrap') ||
|
|
1225
|
-
Object.hasOwn(config, 'tag_wrap_width') ||
|
|
1226
1267
|
Object.hasOwn(config, 'trim')
|
|
1227
1268
|
);
|
|
1228
1269
|
|
|
@@ -1250,37 +1291,29 @@ const validateConfig = (config) => {
|
|
|
1250
1291
|
}
|
|
1251
1292
|
|
|
1252
1293
|
if (Object.hasOwn(config, 'content_wrap') && typeof config.content_wrap !== 'number')
|
|
1253
|
-
throw new Error(`content_wrap config must be a number, not ${typeof config.
|
|
1294
|
+
throw new Error(`content_wrap config must be a number, not ${typeof config.content_wrap}.`)
|
|
1254
1295
|
|
|
1255
1296
|
if (Object.hasOwn(config, 'ignore') && (!Array.isArray(config.ignore) || !config.ignore?.every((e) => typeof e === 'string')))
|
|
1256
1297
|
throw new Error('Ignore config must be an array of strings.')
|
|
1257
1298
|
|
|
1258
|
-
if (Object.hasOwn(config, 'ignore_with')
|
|
1259
|
-
|
|
1299
|
+
if (Object.hasOwn(config, 'ignore_with')) {
|
|
1300
|
+
if (typeof config.ignore_with !== 'string')
|
|
1301
|
+
throw new Error(`ignore_with must be a string, not ${typeof config.ignore_with}.`)
|
|
1302
|
+
else if (config.ignore_with.startsWith('_'))
|
|
1303
|
+
/**
|
|
1304
|
+
* This negatively affects processing of preserved tag attributes,
|
|
1305
|
+
* because tag names can end with an underscore, so the regex
|
|
1306
|
+
* does not capture them.
|
|
1307
|
+
*/
|
|
1308
|
+
throw new Error(`ignore_with cannot start with an underscore.`)
|
|
1309
|
+
}
|
|
1260
1310
|
|
|
1261
1311
|
if (Object.hasOwn(config, 'strict') && typeof config.strict !== 'boolean')
|
|
1262
1312
|
throw new Error(`Strict config must be a boolean, not ${typeof config.strict}.`)
|
|
1263
|
-
|
|
1264
|
-
/* TODO remove in v0.9.0 */
|
|
1265
|
-
if (Object.hasOwn(config, 'tag_wrap') && typeof config.tag_wrap === 'boolean') {
|
|
1266
|
-
console.warn('tag_wrap as a boolean is deprecated, and will not be supported in v0.9.0+. Use `tag_wrap: <number>` instead; where <number> is the max character width acceptable before wrapping attributes.');
|
|
1267
|
-
if (config.tag_wrap_width)
|
|
1268
|
-
config.tag_wrap = config.tag_wrap_width;
|
|
1269
|
-
else
|
|
1270
|
-
config.tag_wrap = default_config.tag_wrap_width;
|
|
1271
|
-
}
|
|
1272
1313
|
|
|
1273
1314
|
if (Object.hasOwn(config, 'tag_wrap') && typeof config.tag_wrap !== 'number')
|
|
1274
1315
|
throw new Error(`tag_wrap config must be a number, not ${typeof config.tag_wrap}.`)
|
|
1275
1316
|
|
|
1276
|
-
/* TODO remove in v0.9.0 */
|
|
1277
|
-
if (Object.hasOwn(config, 'tag_wrap_width'))
|
|
1278
|
-
console.warn('tag_wrap_width is deprecated, and will not be supported in v0.9.0+. Use `tag_wrap: <number>` instead; where <number> is the max character width acceptable before wrapping attributes.');
|
|
1279
|
-
|
|
1280
|
-
/* TODO remove in v0.9.0 */
|
|
1281
|
-
if (Object.hasOwn(config, 'tag_wrap_width') && typeof config.tag_wrap_width !== 'number')
|
|
1282
|
-
throw new Error(`tag_wrap_width config must be a number, not ${typeof config.tag_wrap_width}.`)
|
|
1283
|
-
|
|
1284
1317
|
if (Object.hasOwn(config, 'trim') && (!Array.isArray(config.trim) || !config.trim?.every((e) => typeof e === 'string')))
|
|
1285
1318
|
throw new Error('Trim config must be an array of strings.')
|
|
1286
1319
|
|
|
@@ -1349,11 +1382,11 @@ const wordWrap = (text, width, indent) => {
|
|
|
1349
1382
|
* for re-insertion later.
|
|
1350
1383
|
*
|
|
1351
1384
|
* @param {string} html
|
|
1352
|
-
* @
|
|
1353
|
-
* @returns {{ html_with_markers: string, extracted_map: Map<any,any> }}
|
|
1385
|
+
* @returns {{ html_with_markers: string, extracted_map: Map<any,any> }}
|
|
1354
1386
|
*/
|
|
1355
|
-
function extractIgnoredBlocks(html
|
|
1387
|
+
function extractIgnoredBlocks(html) {
|
|
1356
1388
|
setState({ ignored: true });
|
|
1389
|
+
const config = (getState()).config;
|
|
1357
1390
|
let current_html = html;
|
|
1358
1391
|
const extracted_blocks = new Map();
|
|
1359
1392
|
let marker_id = 0;
|
|
@@ -1364,19 +1397,27 @@ function extractIgnoredBlocks(html, config) {
|
|
|
1364
1397
|
const safe_tag_name = tag.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
1365
1398
|
|
|
1366
1399
|
const regex = new RegExp(
|
|
1367
|
-
|
|
1400
|
+
`(<\\s*${safe_tag_name}[^>]*>)(.*?)(<\\s*\/\\s*${safe_tag_name}\\s*>)`,
|
|
1368
1401
|
"gs" // global and dotAll
|
|
1369
1402
|
);
|
|
1370
1403
|
|
|
1404
|
+
/** @type RegExpExecArray | null */
|
|
1371
1405
|
let match;
|
|
1372
|
-
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* @type {{ start: number; end: number; marker: string }[]}
|
|
1409
|
+
*/
|
|
1410
|
+
const replacements = [];
|
|
1373
1411
|
|
|
1374
1412
|
while ((match = regex.exec(current_html)) !== null) {
|
|
1375
1413
|
const marker = `${MARKER_PREFIX}${marker_id++}___`;
|
|
1376
|
-
|
|
1414
|
+
|
|
1415
|
+
/* Only store content, and minify tags later. */
|
|
1416
|
+
extracted_blocks.set(marker, match[2]);
|
|
1417
|
+
|
|
1377
1418
|
replacements.push({
|
|
1378
|
-
start: match.index,
|
|
1379
|
-
end:
|
|
1419
|
+
start: match.index + match[1].length, // start of content
|
|
1420
|
+
end: match.index + match[1].length + match[2].length, // end of content
|
|
1380
1421
|
marker: marker,
|
|
1381
1422
|
});
|
|
1382
1423
|
}
|
|
@@ -1390,6 +1431,7 @@ function extractIgnoredBlocks(html, config) {
|
|
|
1390
1431
|
current_html.substring(rep.end);
|
|
1391
1432
|
}
|
|
1392
1433
|
}
|
|
1434
|
+
|
|
1393
1435
|
return { html_with_markers: current_html, extracted_map: extracted_blocks }
|
|
1394
1436
|
}
|
|
1395
1437
|
|
|
@@ -1410,42 +1452,55 @@ function reinsertIgnoredBlocks(html_with_markers, extracted_map) {
|
|
|
1410
1452
|
return final_html
|
|
1411
1453
|
}
|
|
1412
1454
|
|
|
1455
|
+
const void_element_regex = new RegExp(`<(${VOID_ELEMENTS.join("|")})(?:\\s(?:[^/>]|/(?!>))*)*>`, 'g');
|
|
1456
|
+
|
|
1413
1457
|
/**
|
|
1414
|
-
*
|
|
1458
|
+
* Add a placeholder for void elements that are not self-closing.
|
|
1459
|
+
* This is for internal processing only.
|
|
1415
1460
|
*
|
|
1416
|
-
* @param {string} html
|
|
1417
|
-
* @returns
|
|
1418
|
-
* @example <br> => <br />
|
|
1461
|
+
* @param {string} html
|
|
1462
|
+
* @returns
|
|
1419
1463
|
*/
|
|
1420
|
-
|
|
1421
|
-
const {
|
|
1422
|
-
|
|
1423
|
-
if (!checked_html && !isHtml(html)) return html
|
|
1424
|
-
|
|
1425
|
-
return html.replace(/<([a-zA-Z\-0-9:]+)[^>]*>/g, (match, name) => {
|
|
1426
|
-
if (VOID_ELEMENTS.indexOf(name) > -1)
|
|
1427
|
-
return (`${match.substring(0, match.length - 1)} />`).replace(/\/\s\//g, '/')
|
|
1464
|
+
function setSelfClosing(html) {
|
|
1465
|
+
const { constants } = getState();
|
|
1428
1466
|
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1467
|
+
return html.replace(
|
|
1468
|
+
// match only void elements that are not self-closing
|
|
1469
|
+
void_element_regex,
|
|
1470
|
+
match => match.replace(/>$/, constants.SELF_CLOSING_PLACEHOLDER)
|
|
1471
|
+
)
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Remove internal placeholder for non-native self-closing void elements.
|
|
1476
|
+
*
|
|
1477
|
+
* @param {string} html
|
|
1478
|
+
* @returns
|
|
1479
|
+
*/
|
|
1480
|
+
function unsetSelfClosing(html) {
|
|
1481
|
+
const { constants } = getState();
|
|
1482
|
+
|
|
1483
|
+
return html.replace(constants.SELF_CLOSING_PLACEHOLDER, ">")
|
|
1484
|
+
}
|
|
1432
1485
|
|
|
1433
1486
|
/**
|
|
1434
1487
|
* Enforce entity characters for textarea content.
|
|
1435
|
-
* To also minifiy, pass `minify` as `true`.
|
|
1488
|
+
* To also minifiy tags, pass `minify` as `true`.
|
|
1436
1489
|
*
|
|
1437
1490
|
* @param {string} html The HTML string to evaluate.
|
|
1438
|
-
* @param {boolean} [minify]
|
|
1491
|
+
* @param {boolean} [minify] Minifies the textarea tags themselves.
|
|
1439
1492
|
* Defaults to `false`. We recommend a value of `true` if you're running `entify()`
|
|
1440
1493
|
* as a standalone function.
|
|
1441
1494
|
* @returns {string}
|
|
1442
|
-
* @example <textarea>3 > 2</textarea> => <textarea>3
|
|
1495
|
+
* @example <textarea>3 > 2</textarea> => <textarea>3 > 2</textarea>
|
|
1496
|
+
* @example With minify.
|
|
1497
|
+
* <textarea >3 > 2</textarea> => <textarea>3 > 2</textarea>
|
|
1443
1498
|
*/
|
|
1444
1499
|
const entify = (html, minify = false) => {
|
|
1445
1500
|
/**
|
|
1446
1501
|
* Use entities inside textarea content.
|
|
1447
1502
|
*/
|
|
1448
|
-
html = html.replace(
|
|
1503
|
+
html = html.replace(/<\s*textarea[^>]*>((.|\n)*?)<s*\/\s*textarea\s*>/g, (match, capture) => {
|
|
1449
1504
|
return match.replace(capture, (match) => {
|
|
1450
1505
|
return match
|
|
1451
1506
|
.replace(/</g, '<')
|
|
@@ -1458,33 +1513,54 @@ const entify = (html, minify = false) => {
|
|
|
1458
1513
|
})
|
|
1459
1514
|
});
|
|
1460
1515
|
|
|
1461
|
-
/* Typical minification, but only for textareas. */
|
|
1462
1516
|
if (minify) {
|
|
1463
|
-
html = html.replace(
|
|
1464
|
-
/*
|
|
1465
|
-
|
|
1466
|
-
return match
|
|
1467
|
-
.replace(/\n|\t/g, '')
|
|
1468
|
-
.replace(/[a-z]+="\s*"/ig, '')
|
|
1469
|
-
.replace(/>\s+</g, '><')
|
|
1470
|
-
.replace(/\s+/g, ' ')
|
|
1471
|
-
});
|
|
1472
|
-
|
|
1473
|
-
/* Replace things in the entire element */
|
|
1474
|
-
match = match
|
|
1517
|
+
html = html.replace(/<\s*textarea[^>]*>(.|\n)*?<\s*\/\s*textarea\s*>/g, (match) => {
|
|
1518
|
+
/* This only affects the html tags, since everything else has been entified. */
|
|
1519
|
+
return match
|
|
1475
1520
|
.replace(/\s+/g, ' ')
|
|
1476
1521
|
.replace(/\s>/g, '>')
|
|
1477
1522
|
.replace(/>\s/g, '>')
|
|
1478
1523
|
.replace(/\s</g, '<')
|
|
1524
|
+
.replace(/<\s/g, '<')
|
|
1525
|
+
.replace(/<\/\s/g, '<\/')
|
|
1479
1526
|
.replace(/class=["']\s/g, (match) => match.replace(/\s/g, ''))
|
|
1480
|
-
.replace(/(class=.*)\s(["'])/g, '$1'+'$2')
|
|
1481
|
-
return match
|
|
1527
|
+
.replace(/(class=.*)\s(["'])/g, '$1'+'$2')
|
|
1482
1528
|
});
|
|
1483
1529
|
}
|
|
1484
1530
|
|
|
1485
1531
|
return html
|
|
1486
1532
|
};
|
|
1487
1533
|
|
|
1534
|
+
/**
|
|
1535
|
+
* Remove entity characters for textarea content.
|
|
1536
|
+
* Currently internal use only.
|
|
1537
|
+
*
|
|
1538
|
+
* @param {string} html The HTML string to evaluate.
|
|
1539
|
+
* @returns {string}
|
|
1540
|
+
* @example <textarea>3 > 2</textarea> => <textarea>3 > 2</textarea>
|
|
1541
|
+
*/
|
|
1542
|
+
const dentify = (html) => {
|
|
1543
|
+
/**
|
|
1544
|
+
* Remove entities inside textarea content.
|
|
1545
|
+
*/
|
|
1546
|
+
return html = html.replace(/<textarea[^>]*>((.|\n)*?)<\/textarea>/g, (match, capture) => {
|
|
1547
|
+
return match.replace(capture, (match) => {
|
|
1548
|
+
match = match
|
|
1549
|
+
.replace(/</g, '<')
|
|
1550
|
+
.replace(/>/g, '>')
|
|
1551
|
+
.replace(/"/g, '"')
|
|
1552
|
+
.replace(/'/g, "'")
|
|
1553
|
+
.replace(/ /g, '\n')
|
|
1554
|
+
.replace(/ /g, '\r')
|
|
1555
|
+
.replace(/ /g, ' ')
|
|
1556
|
+
// Ensure we collapse consecutive spaces, or they'll be completely removed later.
|
|
1557
|
+
.replace(/\s+/g, ' ');
|
|
1558
|
+
|
|
1559
|
+
return match
|
|
1560
|
+
})
|
|
1561
|
+
})
|
|
1562
|
+
};
|
|
1563
|
+
|
|
1488
1564
|
/**
|
|
1489
1565
|
* @type {Map<any,any>}
|
|
1490
1566
|
*/
|
|
@@ -1509,17 +1585,17 @@ const minify = (html, config) => {
|
|
|
1509
1585
|
|
|
1510
1586
|
/* Extract ignored elements. Skipped if prettify has already ignored blocks. */
|
|
1511
1587
|
if (!ignored && ignore) {
|
|
1512
|
-
const { html_with_markers, extracted_map } = extractIgnoredBlocks(html
|
|
1588
|
+
const { html_with_markers, extracted_map } = extractIgnoredBlocks(html);
|
|
1513
1589
|
html = html_with_markers;
|
|
1514
1590
|
ignore_map$1 = extracted_map;
|
|
1515
1591
|
reinsert_ignored = true;
|
|
1516
1592
|
}
|
|
1517
1593
|
|
|
1518
1594
|
/**
|
|
1519
|
-
* Ensure textarea content is
|
|
1595
|
+
* Ensure textarea content is protected
|
|
1520
1596
|
* before general minification.
|
|
1521
1597
|
*/
|
|
1522
|
-
html = entify(html);
|
|
1598
|
+
html = entify(html, true);
|
|
1523
1599
|
|
|
1524
1600
|
/* All other minification. */
|
|
1525
1601
|
// Remove ALL newlines and tabs explicitly.
|
|
@@ -1531,11 +1607,13 @@ const minify = (html, config) => {
|
|
|
1531
1607
|
// Collapse any remaining multiple spaces to single spaces.
|
|
1532
1608
|
html = html.replace(/ {2,}/g, ' ');
|
|
1533
1609
|
|
|
1534
|
-
// Remove specific single spaces
|
|
1610
|
+
// Remove specific single spaces between tags and whitespace within tags.
|
|
1535
1611
|
html = html.replace(/ >/g, ">"); // <tag > -> <tag>
|
|
1536
|
-
html = html.replace(/ </g, "<"); //
|
|
1537
|
-
html = html.replace(/> /g, ">"); //
|
|
1538
|
-
html = html.replace(
|
|
1612
|
+
html = html.replace(/ </g, "<"); // leading space before tag
|
|
1613
|
+
html = html.replace(/> /g, ">"); // trailing space after tag
|
|
1614
|
+
html = html.replace(/< /g, "<"); // < tag> -> <tag>
|
|
1615
|
+
html = html.replace(/<\s+\//g, '</'); // < /tag> -> </tag>
|
|
1616
|
+
html = html.replace(/<\/\s+/g, '</'); // </ tag> -> </tag>
|
|
1539
1617
|
|
|
1540
1618
|
// Trim spaces around equals signs in attributes (run before value trim)
|
|
1541
1619
|
// This handles `attr = "value"` -> `attr="value"`
|
|
@@ -1556,6 +1634,9 @@ const minify = (html, config) => {
|
|
|
1556
1634
|
// Final trim for the whole string
|
|
1557
1635
|
html = html.trim();
|
|
1558
1636
|
|
|
1637
|
+
/* Remove protective entities. */
|
|
1638
|
+
html = dentify(html);
|
|
1639
|
+
|
|
1559
1640
|
/* Re-insert ignored elements. Skipped unless minify did the ignore. */
|
|
1560
1641
|
if (reinsert_ignored) {
|
|
1561
1642
|
html = reinsertIgnoredBlocks(html, ignore_map$1);
|
|
@@ -1580,7 +1661,6 @@ let ignore_map;
|
|
|
1580
1661
|
* Isolate tags, content, and comments.
|
|
1581
1662
|
*
|
|
1582
1663
|
* @param {string} html The HTML string to evaluate.
|
|
1583
|
-
* @returns {string}
|
|
1584
1664
|
* @example <div>Hello World!</div> =>
|
|
1585
1665
|
* [#-# : 0 : <div> : #-#]
|
|
1586
1666
|
* Hello World!
|
|
@@ -1592,7 +1672,7 @@ const enqueue = (html) => {
|
|
|
1592
1672
|
/* Regex to find tags OR text content between tags. */
|
|
1593
1673
|
const regex = /(<[^>]+>)|([^<]+)/g;
|
|
1594
1674
|
|
|
1595
|
-
html
|
|
1675
|
+
html.replace(regex, (match, c1, c2) => {
|
|
1596
1676
|
if (c1) {
|
|
1597
1677
|
convert.line.push({ type: "tag", value: match });
|
|
1598
1678
|
} else if (c2 && c2.trim().length > 0) {
|
|
@@ -1603,40 +1683,18 @@ const enqueue = (html) => {
|
|
|
1603
1683
|
i++;
|
|
1604
1684
|
return `\n[#-# : ${i} : ${match} : #-#]\n`
|
|
1605
1685
|
});
|
|
1606
|
-
|
|
1607
|
-
return html
|
|
1608
1686
|
};
|
|
1609
1687
|
|
|
1610
1688
|
/**
|
|
1611
|
-
*
|
|
1612
|
-
*
|
|
1613
|
-
* @param {string} html The HTML string to preprocess.
|
|
1689
|
+
* Process enqueued content.
|
|
1690
|
+
*
|
|
1614
1691
|
* @returns {string}
|
|
1615
1692
|
*/
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
const { config } = getState();
|
|
1620
|
-
|
|
1621
|
-
if (config.trim.length > 0) html = trimify(html, config.trim);
|
|
1622
|
-
|
|
1623
|
-
html = minify(html);
|
|
1624
|
-
html = enqueue(html);
|
|
1625
|
-
|
|
1626
|
-
return html
|
|
1627
|
-
};
|
|
1628
|
-
|
|
1629
|
-
/**
|
|
1630
|
-
*
|
|
1631
|
-
* @param {import('htmlfy').Config} config
|
|
1632
|
-
* @returns {string}
|
|
1633
|
-
*/
|
|
1634
|
-
const process = (config) => {
|
|
1693
|
+
const process = () => {
|
|
1694
|
+
const { config, constants } = getState();
|
|
1635
1695
|
const step = " ".repeat(config.tab_size);
|
|
1636
1696
|
const tag_wrap = config.tag_wrap;
|
|
1637
1697
|
const content_wrap = config.content_wrap;
|
|
1638
|
-
const ignore_with = config.ignore_with;
|
|
1639
|
-
const placeholder_template = `-${ignore_with}`;
|
|
1640
1698
|
const strict = config.strict;
|
|
1641
1699
|
|
|
1642
1700
|
/* Track current number of indentations needed. */
|
|
@@ -1652,12 +1710,7 @@ const process = (config) => {
|
|
|
1652
1710
|
let current_line_value = source.value;
|
|
1653
1711
|
|
|
1654
1712
|
const is_ignored_content =
|
|
1655
|
-
current_line_value.startsWith(
|
|
1656
|
-
current_line_value.startsWith(placeholder_template + "gt--") ||
|
|
1657
|
-
current_line_value.startsWith(placeholder_template + "nl--") ||
|
|
1658
|
-
current_line_value.startsWith(placeholder_template + "cr--") ||
|
|
1659
|
-
current_line_value.startsWith(placeholder_template + "ws--") ||
|
|
1660
|
-
current_line_value.startsWith(placeholder_template + "tab--");
|
|
1713
|
+
current_line_value.startsWith('___HTMLFY_SPECIAL_IGNORE_MARKER_');
|
|
1661
1714
|
|
|
1662
1715
|
let subtrahend = 0;
|
|
1663
1716
|
const prev_line_data = convert.line[index - 1];
|
|
@@ -1675,8 +1728,12 @@ const process = (config) => {
|
|
|
1675
1728
|
if (prev_line_value.trim().startsWith("<!doctype")) subtrahend++;
|
|
1676
1729
|
/* prevLine is a comment. */
|
|
1677
1730
|
if (prev_line_value.trim().startsWith("<!--")) subtrahend++;
|
|
1678
|
-
/* prevLine is a
|
|
1679
|
-
if (
|
|
1731
|
+
/* prevLine is a void element. */
|
|
1732
|
+
if (
|
|
1733
|
+
prev_line_value.trim().endsWith("/>") // native self-closing
|
|
1734
|
+
||
|
|
1735
|
+
prev_line_value.trim().endsWith(constants.SELF_CLOSING_PLACEHOLDER) // synthetic self-closing
|
|
1736
|
+
) subtrahend++;
|
|
1680
1737
|
/* prevLine is a closing tag. */
|
|
1681
1738
|
if (prev_line_value.trim().startsWith("</")) subtrahend++;
|
|
1682
1739
|
/* prevLine is text. */
|
|
@@ -1692,8 +1749,6 @@ const process = (config) => {
|
|
|
1692
1749
|
/**
|
|
1693
1750
|
* Starts with a single punctuation character.
|
|
1694
1751
|
* Add punctuation to end of previous line.
|
|
1695
|
-
*
|
|
1696
|
-
* TODO - Implement inline groups instead?
|
|
1697
1752
|
*/
|
|
1698
1753
|
if (source.type === 'text' && /^[!,;\.]/.test(current_line_value)) {
|
|
1699
1754
|
if (current_line_value.length === 1) {
|
|
@@ -1719,6 +1774,9 @@ const process = (config) => {
|
|
|
1719
1774
|
|
|
1720
1775
|
let result = current_line_value;
|
|
1721
1776
|
|
|
1777
|
+
/* Remove self-closing placeholder, if needed. */
|
|
1778
|
+
result = unsetSelfClosing(result);
|
|
1779
|
+
|
|
1722
1780
|
if (
|
|
1723
1781
|
source.type === 'text' &&
|
|
1724
1782
|
content_wrap > 0 &&
|
|
@@ -1749,9 +1807,9 @@ const process = (config) => {
|
|
|
1749
1807
|
|
|
1750
1808
|
const tag_name_match = tag_parts[0].match(/<([A-Za-z_:-]+)/);
|
|
1751
1809
|
const tag_name = tag_name_match ? tag_name_match[1] : "";
|
|
1752
|
-
const
|
|
1810
|
+
const is_self_closing = tag_parts.at(-1)?.endsWith("/>") && VOID_ELEMENTS.includes(tag_name);
|
|
1753
1811
|
const closing_part = tag_parts[1].trim();
|
|
1754
|
-
const closing_padding = padding + (strict &&
|
|
1812
|
+
const closing_padding = padding + (strict && is_self_closing ? " " : "");
|
|
1755
1813
|
|
|
1756
1814
|
wrapped_tag += closing_padding + closing_part;
|
|
1757
1815
|
|
|
@@ -1776,13 +1834,20 @@ const process = (config) => {
|
|
|
1776
1834
|
if (tag_wrap > 0) final_html = protectAttributes(final_html);
|
|
1777
1835
|
|
|
1778
1836
|
/* Extra preserve wrapped content. */
|
|
1779
|
-
if (content_wrap > 0 &&
|
|
1837
|
+
if (content_wrap > 0 && new RegExp(`/\\n[ ]*[^\\n]*${constants.CONTENT_IGNORE_PLACEHOLDER}[^\\n]*\\n/`).test(final_html))
|
|
1780
1838
|
final_html = finalProtectContent(final_html);
|
|
1781
1839
|
|
|
1782
1840
|
/* Remove line returns, tabs, and consecutive spaces within html elements or their content. */
|
|
1783
1841
|
final_html = final_html.replace(
|
|
1784
|
-
/<(?<Element
|
|
1785
|
-
match =>
|
|
1842
|
+
/<(?<Element>[^>\s]+)[^>]*>[^<]*?[^><\/\s][^<]*?<\/\k<Element>>|<script[^>]*>[\s]*<\/script>|<([\w:\._-]+)([^>]*)><\/\2>|<([\w:\._-]+)([^>]*)>[\s]+<\/\4>/g,
|
|
1843
|
+
match => {
|
|
1844
|
+
// Check if this contains placeholder
|
|
1845
|
+
if (match.includes(constants.SELF_CLOSING_PLACEHOLDER) || match.includes(constants.CONTENT_IGNORE_PLACEHOLDER)) {
|
|
1846
|
+
return match // Don't modify if it contains the placeholder
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
return match.replace(/\n|\t|\s{2,}/g, '')
|
|
1850
|
+
}
|
|
1786
1851
|
);
|
|
1787
1852
|
|
|
1788
1853
|
/* Revert wrapped content. */
|
|
@@ -1815,12 +1880,17 @@ const prettify = (html, config) => {
|
|
|
1815
1880
|
/* Return content as-is if it does not contain any HTML elements. */
|
|
1816
1881
|
if (!checked_html && !isHtml(html)) return html
|
|
1817
1882
|
|
|
1818
|
-
|
|
1883
|
+
/* Runs setState for config. */
|
|
1884
|
+
const validated_config = validateConfig(config || {});
|
|
1885
|
+
|
|
1819
1886
|
const ignore = validated_config.ignore.length > 0;
|
|
1820
1887
|
|
|
1888
|
+
/* Allows you to trimify before ignoring. */
|
|
1889
|
+
if (validated_config.trim.length > 0) html = trimify(html, validated_config.trim);
|
|
1890
|
+
|
|
1821
1891
|
/* Extract ignored elements. */
|
|
1822
1892
|
if (!ignored && ignore) {
|
|
1823
|
-
const { html_with_markers, extracted_map } = extractIgnoredBlocks(html
|
|
1893
|
+
const { html_with_markers, extracted_map } = extractIgnoredBlocks(html);
|
|
1824
1894
|
html = html_with_markers;
|
|
1825
1895
|
ignore_map = extracted_map;
|
|
1826
1896
|
reinsert_ignored = true;
|
|
@@ -1829,8 +1899,12 @@ const prettify = (html, config) => {
|
|
|
1829
1899
|
/* Preserve html text within attribute values. */
|
|
1830
1900
|
html = setIgnoreAttribute(html);
|
|
1831
1901
|
|
|
1832
|
-
|
|
1833
|
-
html =
|
|
1902
|
+
/* Insert placeholder for void elements that aren't self-closing. */
|
|
1903
|
+
html = setSelfClosing(html);
|
|
1904
|
+
|
|
1905
|
+
html = minify(html);
|
|
1906
|
+
enqueue(html);
|
|
1907
|
+
html = process();
|
|
1834
1908
|
|
|
1835
1909
|
/* Revert html text within attribute values. */
|
|
1836
1910
|
html = unsetIgnoreAttribute(html);
|