@design-edito/tools 0.1.29 → 0.1.30

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 (73) hide show
  1. package/agnostic/css/index.js +12 -11
  2. package/agnostic/errors/index.js +2 -2
  3. package/agnostic/html/hyper-json/cast/index.js +3 -3
  4. package/agnostic/html/hyper-json/index.d.ts +0 -2
  5. package/agnostic/html/hyper-json/index.js +4 -4
  6. package/agnostic/html/hyper-json/serialize/index.js +2 -2
  7. package/agnostic/html/hyper-json/transformers/append/index.js +3 -3
  8. package/agnostic/html/hyper-json/transformers/classList/index.js +3 -3
  9. package/agnostic/html/hyper-json/transformers/index.js +3 -3
  10. package/agnostic/html/hyper-json/transformers/join/index.js +3 -3
  11. package/agnostic/html/hyper-json/transformers/length/index.js +3 -3
  12. package/agnostic/html/hyper-json/transformers/print/index.js +3 -3
  13. package/agnostic/html/hyper-json/transformers/push/index.js +3 -3
  14. package/agnostic/html/hyper-json/transformers/querySelector/index.js +3 -3
  15. package/agnostic/html/hyper-json/transformers/ref/index.js +3 -3
  16. package/agnostic/html/hyper-json/transformers/replace/index.js +3 -3
  17. package/agnostic/html/hyper-json/transformers/split/index.js +3 -3
  18. package/agnostic/html/hyper-json/transformers/toArray/index.js +3 -3
  19. package/agnostic/html/hyper-json/transformers/toBoolean/index.js +3 -3
  20. package/agnostic/html/hyper-json/transformers/toElement/index.js +3 -3
  21. package/agnostic/html/hyper-json/transformers/toNodeList/index.js +3 -3
  22. package/agnostic/html/hyper-json/transformers/toNull/index.js +3 -3
  23. package/agnostic/html/hyper-json/transformers/toNumber/index.js +3 -3
  24. package/agnostic/html/hyper-json/transformers/toRecord/index.js +3 -3
  25. package/agnostic/html/hyper-json/transformers/toRef/index.js +3 -3
  26. package/agnostic/html/hyper-json/transformers/toString/index.js +3 -3
  27. package/agnostic/html/hyper-json/transformers/toText/index.js +3 -3
  28. package/agnostic/html/hyper-json/transformers/toTransformer/index.js +3 -3
  29. package/agnostic/html/hyper-json/transformers/transformSelected/index.js +3 -3
  30. package/agnostic/html/hyper-json/transformers/trim/index.js +3 -3
  31. package/agnostic/html/hyper-json/tree/index.js +3 -3
  32. package/agnostic/html/hyper-json/utils/index.js +3 -3
  33. package/agnostic/html/index.js +22 -22
  34. package/agnostic/html/sanitize/index.js +8 -7
  35. package/agnostic/html/selector-to-element/index.js +8 -7
  36. package/agnostic/html/string-to-nodes/index.js +9 -8
  37. package/agnostic/misc/crossenv/detect-runtime/index.d.ts +2 -0
  38. package/agnostic/misc/crossenv/detect-runtime/index.js +7 -0
  39. package/agnostic/misc/crossenv/index.d.ts +6 -14
  40. package/agnostic/misc/crossenv/index.js +4 -3
  41. package/agnostic/misc/crossenv/types/index.d.ts +19 -0
  42. package/agnostic/misc/crossenv/types/index.js +6 -0
  43. package/agnostic/misc/crossenv/window/index.d.ts +7 -0
  44. package/agnostic/misc/crossenv/window/index.js +6 -0
  45. package/agnostic/misc/index.js +12 -11
  46. package/agnostic/misc/logs/index.js +2 -2
  47. package/agnostic/misc/lorem-ipsum/index.js +3 -3
  48. package/agnostic/numbers/index.js +5 -5
  49. package/agnostic/objects/index.d.ts +2 -0
  50. package/agnostic/objects/index.js +8 -4
  51. package/agnostic/objects/record-format/index.d.ts +1 -1
  52. package/agnostic/objects/record-format/index.js +4 -14
  53. package/agnostic/optim/index.js +3 -3
  54. package/agnostic/strings/index.js +5 -5
  55. package/agnostic/time/index.js +3 -3
  56. package/chunks/chunk-BQV4DOSE.js +1108 -0
  57. package/chunks/chunk-CB52KVOZ.js +22 -0
  58. package/chunks/chunk-EVOTJ7SU.js +35 -0
  59. package/chunks/chunk-G2NZXHW6.js +21 -0
  60. package/chunks/chunk-HP3OH2K7.js +27 -0
  61. package/chunks/chunk-KN4RZPDY.js +211 -0
  62. package/chunks/chunk-LV2VMOWR.js +18 -0
  63. package/chunks/chunk-MUGIN5OW.js +211 -0
  64. package/chunks/chunk-NWFX6TEY.js +28 -0
  65. package/chunks/chunk-OVG5RGI3.js +29 -0
  66. package/chunks/chunk-RLJOYG64.js +33 -0
  67. package/chunks/chunk-S2NMAH7K.js +19 -0
  68. package/chunks/chunk-UFKH5WD2.js +21 -0
  69. package/chunks/chunk-WABWQCFE.js +127 -0
  70. package/chunks/chunk-YP64J65L.js +17 -0
  71. package/chunks/chunk-ZCPGE7H7.js +64 -0
  72. package/node/files/index.js +3 -3
  73. 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,17 @@
1
+ // src/agnostic/objects/record-format/index.ts
2
+ async function recordFormat(input, format) {
3
+ const result = {};
4
+ for (const key in format) {
5
+ const formatter = format[key];
6
+ if (typeof formatter === "function") {
7
+ result[key] = await formatter(input[key]);
8
+ } else {
9
+ result[key] = formatter;
10
+ }
11
+ }
12
+ return result;
13
+ }
14
+
15
+ export {
16
+ recordFormat
17
+ };
@@ -0,0 +1,64 @@
1
+ import {
2
+ Window
3
+ } from "./chunk-RLJOYG64.js";
4
+
5
+ // src/agnostic/html/hyper-json/serialize/index.ts
6
+ var Serialize;
7
+ ((Serialize2) => {
8
+ function serialize(value) {
9
+ const { Text, Element, NodeList } = Window.get();
10
+ if (value === null) return { type: "null", value: null };
11
+ if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") return { type: typeof value, value };
12
+ if (value instanceof Text) return { type: "text", value: value.textContent ?? "" };
13
+ if (value instanceof Element) return { type: "text", value: value.outerHTML };
14
+ if (value instanceof NodeList) return {
15
+ type: "text",
16
+ value: Array.from(value).map((e) => {
17
+ if (e instanceof Text) return e.textContent;
18
+ return e.outerHTML;
19
+ }).join("")
20
+ };
21
+ if (Array.isArray(value)) return { type: "array", value: value.map(serialize) };
22
+ if (typeof value === "function") return { type: "transformer", value };
23
+ return {
24
+ type: "record",
25
+ value: Object.entries(value).reduce((reduced, [key, val]) => ({
26
+ ...reduced,
27
+ [key]: serialize(val)
28
+ }), {})
29
+ };
30
+ }
31
+ Serialize2.serialize = serialize;
32
+ function deserialize(serialized) {
33
+ const { document } = Window.get();
34
+ if (serialized.type === "null") return null;
35
+ if (serialized.type === "boolean") return serialized.value;
36
+ if (serialized.type === "number") return serialized.value;
37
+ if (serialized.type === "string") return serialized.value;
38
+ if (serialized.type === "text") return document.createTextNode(serialized.value);
39
+ if (serialized.type === "element") {
40
+ const elt = document.createElement("div");
41
+ elt.innerHTML = serialized.value;
42
+ const firstChild = elt.firstElementChild;
43
+ return firstChild ?? document.createElement("div");
44
+ }
45
+ if (serialized.type === "nodelist") {
46
+ const elt = document.createElement("div");
47
+ elt.innerHTML = serialized.value;
48
+ return elt.childNodes;
49
+ }
50
+ if (serialized.type === "array") return serialized.value.map((val) => deserialize(val));
51
+ if (serialized.type === "transformer") return serialized.value;
52
+ return Object.entries(serialized.value).reduce((reduced, [key, serialized2]) => {
53
+ return {
54
+ ...reduced,
55
+ [key]: deserialize(serialized2)
56
+ };
57
+ }, {});
58
+ }
59
+ Serialize2.deserialize = deserialize;
60
+ })(Serialize || (Serialize = {}));
61
+
62
+ export {
63
+ Serialize
64
+ };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  readWrite
3
3
  } from "../../chunks/chunk-7DBNMU6N.js";
4
- import {
5
- Subpaths
6
- } from "../../chunks/chunk-HGCG2J77.js";
7
4
  import {
8
5
  isInDirectory
9
6
  } from "../../chunks/chunk-NRITRUZW.js";
7
+ import {
8
+ Subpaths
9
+ } from "../../chunks/chunk-HGCG2J77.js";
10
10
  import "../../chunks/chunk-LQFKUNVQ.js";
11
11
 
12
12
  // src/node/files/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",