@design-edito/tools 0.1.35 → 0.1.37

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 (57) hide show
  1. package/agnostic/css/bem/index.js +2 -2
  2. package/agnostic/css/index.js +6 -6
  3. package/agnostic/html/hyper-json/cast/index.js +3 -2
  4. package/agnostic/html/hyper-json/index.js +4 -3
  5. package/agnostic/html/hyper-json/transformers/append/index.js +3 -2
  6. package/agnostic/html/hyper-json/transformers/classList/index.js +3 -2
  7. package/agnostic/html/hyper-json/transformers/index.js +3 -2
  8. package/agnostic/html/hyper-json/transformers/join/index.js +3 -2
  9. package/agnostic/html/hyper-json/transformers/length/index.js +3 -2
  10. package/agnostic/html/hyper-json/transformers/print/index.js +3 -2
  11. package/agnostic/html/hyper-json/transformers/push/index.js +3 -2
  12. package/agnostic/html/hyper-json/transformers/querySelector/index.js +3 -2
  13. package/agnostic/html/hyper-json/transformers/ref/index.js +3 -2
  14. package/agnostic/html/hyper-json/transformers/replace/index.js +3 -2
  15. package/agnostic/html/hyper-json/transformers/split/index.js +3 -2
  16. package/agnostic/html/hyper-json/transformers/toArray/index.js +3 -2
  17. package/agnostic/html/hyper-json/transformers/toBoolean/index.js +3 -2
  18. package/agnostic/html/hyper-json/transformers/toElement/index.js +3 -2
  19. package/agnostic/html/hyper-json/transformers/toNodeList/index.js +3 -2
  20. package/agnostic/html/hyper-json/transformers/toNull/index.js +3 -2
  21. package/agnostic/html/hyper-json/transformers/toNumber/index.js +3 -2
  22. package/agnostic/html/hyper-json/transformers/toRecord/index.js +3 -2
  23. package/agnostic/html/hyper-json/transformers/toRef/index.js +3 -2
  24. package/agnostic/html/hyper-json/transformers/toString/index.js +3 -2
  25. package/agnostic/html/hyper-json/transformers/toText/index.js +3 -2
  26. package/agnostic/html/hyper-json/transformers/toTransformer/index.js +3 -2
  27. package/agnostic/html/hyper-json/transformers/transformSelected/index.js +3 -2
  28. package/agnostic/html/hyper-json/transformers/trim/index.js +3 -2
  29. package/agnostic/html/hyper-json/tree/index.js +3 -2
  30. package/agnostic/html/hyper-json/utils/index.js +3 -2
  31. package/agnostic/html/index.js +12 -12
  32. package/agnostic/html/replace-in-element/index.d.ts +1 -1
  33. package/agnostic/html/replace-in-element/index.js +2 -1
  34. package/agnostic/misc/index.js +5 -5
  35. package/agnostic/misc/logs/index.js +2 -2
  36. package/agnostic/misc/lorem-ipsum/index.js +3 -3
  37. package/agnostic/numbers/index.js +6 -6
  38. package/agnostic/objects/index.d.ts +0 -2
  39. package/agnostic/objects/index.js +10 -14
  40. package/agnostic/strings/index.js +4 -4
  41. package/agnostic/time/index.js +3 -3
  42. package/chunks/chunk-2IV3O7FX.js +27 -0
  43. package/chunks/chunk-7YW5HL6N.js +168 -0
  44. package/chunks/chunk-BPOJYE4X.js +1108 -0
  45. package/chunks/chunk-CB52KVOZ.js +22 -0
  46. package/chunks/chunk-EVOTJ7SU.js +35 -0
  47. package/chunks/chunk-FONURDTX.js +211 -0
  48. package/chunks/chunk-HE6F5XJQ.js +20 -0
  49. package/chunks/chunk-NWFX6TEY.js +28 -0
  50. package/chunks/chunk-OVG5RGI3.js +29 -0
  51. package/chunks/chunk-R57V5HA7.js +211 -0
  52. package/chunks/chunk-TLTLM47Y.js +27 -0
  53. package/chunks/chunk-UFKH5WD2.js +21 -0
  54. package/chunks/chunk-W4OFHYWN.js +1108 -0
  55. package/chunks/chunk-WABWQCFE.js +127 -0
  56. package/chunks/chunk-XWLQR4UY.js +25 -0
  57. package/package.json +1 -1
@@ -0,0 +1,127 @@
1
+ import {
2
+ register
3
+ } from "./chunk-CB52KVOZ.js";
4
+
5
+ // src/agnostic/html/sanitize/index.ts
6
+ var Sanitize;
7
+ ((Sanitize2) => {
8
+ Sanitize2.defaultOptions = { depth: 20 };
9
+ function sanitize(inputStr, options = Sanitize2.defaultOptions) {
10
+ const actualDocument = options.documentObj ?? window.document;
11
+ if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
12
+ const wrapperDiv = actualDocument.createElement("div");
13
+ const { inputFreeTransform } = options;
14
+ wrapperDiv.innerHTML = inputFreeTransform !== void 0 ? inputFreeTransform(inputStr) : inputStr;
15
+ const sanitizedWrapper = sanitizeElement(wrapperDiv, options);
16
+ const returned = sanitizedWrapper?.innerHTML;
17
+ return returned ?? "";
18
+ }
19
+ Sanitize2.sanitize = sanitize;
20
+ function sanitizeElement(element, options = Sanitize2.defaultOptions) {
21
+ const actualDocument = options.documentObj ?? window.document;
22
+ if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
23
+ const { tagName, attributes, childNodes } = element;
24
+ const {
25
+ allowedTags = [],
26
+ allowedAttributes = {},
27
+ forbiddenTags = [],
28
+ forbiddenAttributes = {},
29
+ depth = 20,
30
+ verbose = false
31
+ } = options;
32
+ if (depth <= 0) {
33
+ console.warn("Max depth reached");
34
+ return null;
35
+ }
36
+ const normalizedTagName = tagName.toLowerCase().trim();
37
+ const tagIsInForbidden = forbiddenTags.includes("*") || forbiddenTags.includes(normalizedTagName);
38
+ if (tagIsInForbidden) {
39
+ if (verbose === true) console.warn(tagName, "tag is forbidden");
40
+ return null;
41
+ }
42
+ const tagIsInAllowed = allowedTags.includes("*") || allowedTags.includes(normalizedTagName);
43
+ if (!tagIsInAllowed) {
44
+ if (verbose === true) console.warn(tagName, "tag is not allowed");
45
+ return null;
46
+ }
47
+ const returnedElement = actualDocument.createElement(tagName);
48
+ const returnedAttributes = Array.from(attributes).filter(({ name: attributeName, value: attributeValue }) => {
49
+ const allTagsForbiddenAttributes = forbiddenAttributes["*"] ?? [];
50
+ const thisTagForbiddenAttributes = forbiddenAttributes[normalizedTagName] ?? [];
51
+ const mergedForbiddenAttributes = [...allTagsForbiddenAttributes, ...thisTagForbiddenAttributes];
52
+ const isInForbidden = mergedForbiddenAttributes.some(({
53
+ attributeName: nameTester,
54
+ attributeValues: valTesters
55
+ }) => {
56
+ if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) return false;
57
+ if (typeof nameTester !== "string" && !nameTester.test(attributeName)) return false;
58
+ if (valTesters === void 0) {
59
+ if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
60
+ return true;
61
+ }
62
+ if (valTesters.includes("*")) {
63
+ if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
64
+ return true;
65
+ }
66
+ return valTesters.some((valTester) => {
67
+ if (typeof valTester === "string" && attributeValue === valTester) {
68
+ if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
69
+ return true;
70
+ }
71
+ if (typeof valTester !== "string" && valTester.test(attributeValue)) {
72
+ if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
73
+ return true;
74
+ }
75
+ return false;
76
+ });
77
+ });
78
+ if (isInForbidden) return false;
79
+ const allTagsAllowedAttributes = allowedAttributes["*"] ?? [];
80
+ const thisTagAllowedAttributes = allowedAttributes[normalizedTagName] ?? [];
81
+ const mergedAllowedAttributes = [...allTagsAllowedAttributes, ...thisTagAllowedAttributes];
82
+ let latestNotAllowedReason = [tagName, "has no allowed attributes"];
83
+ const isInAllowed = mergedAllowedAttributes.some(({
84
+ attributeName: nameTester,
85
+ attributeValues: valTesters
86
+ }) => {
87
+ if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) {
88
+ latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
89
+ return false;
90
+ }
91
+ if (typeof nameTester !== "string" && !nameTester.test(attributeName)) {
92
+ latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
93
+ return false;
94
+ }
95
+ if (valTesters === void 0) return true;
96
+ if (valTesters.includes("*")) return true;
97
+ return valTesters.some((valTester) => {
98
+ if (typeof valTester === "string" && attributeValue === valTester) return true;
99
+ if (typeof valTester !== "string" && valTester.test(attributeValue)) return true;
100
+ latestNotAllowedReason = [attributeValue, "value for", attributeName, "attribute on", tagName, "tag is not allowed"];
101
+ return false;
102
+ });
103
+ });
104
+ if (!isInAllowed) {
105
+ if (verbose === true) console.warn(...latestNotAllowedReason);
106
+ return false;
107
+ }
108
+ return true;
109
+ });
110
+ returnedAttributes.forEach(({ name, value }) => {
111
+ returnedElement.setAttribute(name, value);
112
+ });
113
+ const sanitizedChildNodes = Array.from(childNodes).map((node) => {
114
+ if (node.nodeType === Node.ELEMENT_NODE) return sanitizeElement(node, { ...options, depth: depth - 1 });
115
+ else if (node.nodeType === Node.TEXT_NODE) return node;
116
+ else if (options.keepComments === true && node.nodeType === Node.COMMENT_NODE) return node;
117
+ return null;
118
+ }).filter((elt) => elt !== null);
119
+ returnedElement.replaceChildren(...sanitizedChildNodes);
120
+ return returnedElement;
121
+ }
122
+ Sanitize2.sanitizeElement = sanitizeElement;
123
+ })(Sanitize || (Sanitize = {}));
124
+
125
+ export {
126
+ Sanitize
127
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ getNodeAncestors
3
+ } from "./chunk-LUPVHC73.js";
4
+
5
+ // src/agnostic/html/replace-in-element/index.ts
6
+ function replaceInElement(inputElement, replaceMap) {
7
+ const actualReplaceMap = new Map(Array.from(replaceMap).filter(([toReplace]) => {
8
+ const toReplaceAncestors = getNodeAncestors(toReplace);
9
+ return toReplaceAncestors.includes(inputElement);
10
+ }));
11
+ actualReplaceMap.forEach((replacer, toReplace) => {
12
+ if ("nodeType" in replacer) {
13
+ toReplace.parentNode?.insertBefore(replacer, toReplace);
14
+ } else {
15
+ const replacerNodes = Array.from(replacer);
16
+ replacerNodes.forEach((rpl) => toReplace.parentNode?.insertBefore(rpl, toReplace));
17
+ }
18
+ toReplace.parentNode?.removeChild(toReplace);
19
+ });
20
+ return inputElement;
21
+ }
22
+
23
+ export {
24
+ replaceInElement
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",