@splendidlabz/utils 1.8.2 → 1.9.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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/dom/events.cjs +0 -36
- package/dist/cjs/dom/index.cjs +0 -36
- package/dist/cjs/lib/functions/callback.cjs +31 -0
- package/dist/cjs/lib/index.cjs +13 -6
- package/dist/cjs/lib/strings/index.cjs +13 -6
- package/dist/cjs/lib/strings/markdown.cjs +23 -6
- package/dist/esm/dom/events.js +0 -35
- package/dist/esm/dom/index.js +0 -35
- package/dist/esm/lib/functions/callback.js +7 -0
- package/dist/esm/lib/index.js +13 -6
- package/dist/esm/lib/strings/index.js +13 -6
- package/dist/esm/lib/strings/markdown.js +13 -6
- package/dist/types/dom/events.d.cts +90 -18
- package/dist/types/dom/index.d.cts +1 -1
- package/dist/types/lib/functions/callback.d.cts +8 -0
- package/dist/types/lib/strings/markdown.d.cts +2 -2
- package/package.json +3 -1
- package/src/dom/events.js +44 -50
- package/src/lib/functions/callback.js +8 -0
- package/src/lib/strings/markdown.js +21 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @splendidlabz/utils
|
|
2
2
|
|
|
3
|
+
## 1.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Replace Markdown with Markdown-it
|
|
8
|
+
|
|
9
|
+
## 1.9.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 8f2cb34: - 48406c69 Add JSDocs for events
|
|
14
|
+
- 304b5310 Utils: Add runCallback
|
|
15
|
+
|
|
3
16
|
## 1.8.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/cjs/dom/events.cjs
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var events_exports = {};
|
|
21
21
|
__export(events_exports, {
|
|
22
22
|
addListeners: () => addListeners,
|
|
23
|
-
createListeners: () => createListeners,
|
|
24
23
|
dispatchEvent: () => dispatchEvent,
|
|
25
24
|
removeListeners: () => removeListeners,
|
|
26
25
|
updateEvent: () => updateEvent
|
|
@@ -51,44 +50,9 @@ function updateEvent(event, updates) {
|
|
|
51
50
|
...updates
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
|
-
function createListeners(listeners) {
|
|
55
|
-
listeners = listeners || [];
|
|
56
|
-
listeners.forEach((listener) => {
|
|
57
|
-
const { node, event, handler } = listener;
|
|
58
|
-
node.addEventListener(event, handler);
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
get list() {
|
|
62
|
-
return listeners;
|
|
63
|
-
},
|
|
64
|
-
add({ node, event, handler }) {
|
|
65
|
-
listeners.push({ node, event, handler });
|
|
66
|
-
node.addEventListener(event, handler);
|
|
67
|
-
},
|
|
68
|
-
remove({ node, event, handler }) {
|
|
69
|
-
const index = listeners.findIndex((listener) => {
|
|
70
|
-
if (listener.node === node && listener.event === event && listener.handler === handler) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
});
|
|
75
|
-
if (index !== -1) {
|
|
76
|
-
listeners.splice(index, 1);
|
|
77
|
-
node.removeEventListener(event, handler);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
clear() {
|
|
81
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
82
|
-
listeners = [];
|
|
83
|
-
node.removeEventListener(event, handler);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
53
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
54
|
0 && (module.exports = {
|
|
90
55
|
addListeners,
|
|
91
|
-
createListeners,
|
|
92
56
|
dispatchEvent,
|
|
93
57
|
removeListeners,
|
|
94
58
|
updateEvent
|
package/dist/cjs/dom/index.cjs
CHANGED
|
@@ -37,7 +37,6 @@ __export(dom_exports, {
|
|
|
37
37
|
checkForAccessibleName: () => checkForAccessibleName,
|
|
38
38
|
cookies: () => cookies,
|
|
39
39
|
copyRichText: () => copyRichText,
|
|
40
|
-
createListeners: () => createListeners,
|
|
41
40
|
dispatchEvent: () => dispatchEvent,
|
|
42
41
|
em: () => em,
|
|
43
42
|
findScrollContainer: () => findScrollContainer,
|
|
@@ -231,40 +230,6 @@ function updateEvent(event, updates) {
|
|
|
231
230
|
...updates
|
|
232
231
|
});
|
|
233
232
|
}
|
|
234
|
-
function createListeners(listeners) {
|
|
235
|
-
listeners = listeners || [];
|
|
236
|
-
listeners.forEach((listener) => {
|
|
237
|
-
const { node, event, handler } = listener;
|
|
238
|
-
node.addEventListener(event, handler);
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
get list() {
|
|
242
|
-
return listeners;
|
|
243
|
-
},
|
|
244
|
-
add({ node, event, handler }) {
|
|
245
|
-
listeners.push({ node, event, handler });
|
|
246
|
-
node.addEventListener(event, handler);
|
|
247
|
-
},
|
|
248
|
-
remove({ node, event, handler }) {
|
|
249
|
-
const index = listeners.findIndex((listener) => {
|
|
250
|
-
if (listener.node === node && listener.event === event && listener.handler === handler) {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
return false;
|
|
254
|
-
});
|
|
255
|
-
if (index !== -1) {
|
|
256
|
-
listeners.splice(index, 1);
|
|
257
|
-
node.removeEventListener(event, handler);
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
clear() {
|
|
261
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
262
|
-
listeners = [];
|
|
263
|
-
node.removeEventListener(event, handler);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
233
|
|
|
269
234
|
// src/dom/observers/observer.js
|
|
270
235
|
function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
|
|
@@ -1229,7 +1194,6 @@ function scrambleText(text) {
|
|
|
1229
1194
|
checkForAccessibleName,
|
|
1230
1195
|
cookies,
|
|
1231
1196
|
copyRichText,
|
|
1232
|
-
createListeners,
|
|
1233
1197
|
dispatchEvent,
|
|
1234
1198
|
em,
|
|
1235
1199
|
findScrollContainer,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/functions/callback.js
|
|
20
|
+
var callback_exports = {};
|
|
21
|
+
__export(callback_exports, {
|
|
22
|
+
runCallback: () => runCallback
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(callback_exports);
|
|
25
|
+
function runCallback(fn, ...data) {
|
|
26
|
+
if (typeof fn === "function") fn(data);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
runCallback
|
|
31
|
+
});
|
package/dist/cjs/lib/index.cjs
CHANGED
|
@@ -989,16 +989,23 @@ function parseSSE(message) {
|
|
|
989
989
|
}
|
|
990
990
|
|
|
991
991
|
// src/lib/strings/markdown.js
|
|
992
|
-
var
|
|
993
|
-
var
|
|
994
|
-
var
|
|
992
|
+
var import_markdown_it = __toESM(require("markdown-it"), 1);
|
|
993
|
+
var import_markdown_it_anchor = __toESM(require("markdown-it-anchor"), 1);
|
|
994
|
+
var md = (0, import_markdown_it.default)({
|
|
995
|
+
html: true,
|
|
996
|
+
linkify: true,
|
|
997
|
+
typographer: true
|
|
998
|
+
});
|
|
999
|
+
md.use(import_markdown_it_anchor.default, {
|
|
1000
|
+
permalink: false,
|
|
1001
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
1002
|
+
});
|
|
995
1003
|
function markdown(content, options = {}) {
|
|
996
1004
|
const defaultOptions = { inline: false };
|
|
997
1005
|
const opts = { ...defaultOptions, ...options };
|
|
998
|
-
import_marked.marked.use((0, import_marked_mangle.mangle)());
|
|
999
|
-
import_marked.marked.use((0, import_marked_gfm_heading_id.gfmHeadingId)());
|
|
1000
1006
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
1001
|
-
return
|
|
1007
|
+
if (opts.inline) return md.renderInline(treated);
|
|
1008
|
+
return md.render(treated);
|
|
1002
1009
|
}
|
|
1003
1010
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
1004
1011
|
if (!content) return { content: "", inline };
|
|
@@ -104,16 +104,23 @@ function isDigit(char) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// src/lib/strings/markdown.js
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
var
|
|
107
|
+
var import_markdown_it = __toESM(require("markdown-it"), 1);
|
|
108
|
+
var import_markdown_it_anchor = __toESM(require("markdown-it-anchor"), 1);
|
|
109
|
+
var md = (0, import_markdown_it.default)({
|
|
110
|
+
html: true,
|
|
111
|
+
linkify: true,
|
|
112
|
+
typographer: true
|
|
113
|
+
});
|
|
114
|
+
md.use(import_markdown_it_anchor.default, {
|
|
115
|
+
permalink: false,
|
|
116
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
117
|
+
});
|
|
110
118
|
function markdown(content, options = {}) {
|
|
111
119
|
const defaultOptions = { inline: false };
|
|
112
120
|
const opts = { ...defaultOptions, ...options };
|
|
113
|
-
import_marked.marked.use((0, import_marked_mangle.mangle)());
|
|
114
|
-
import_marked.marked.use((0, import_marked_gfm_heading_id.gfmHeadingId)());
|
|
115
121
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
116
|
-
return
|
|
122
|
+
if (opts.inline) return md.renderInline(treated);
|
|
123
|
+
return md.render(treated);
|
|
117
124
|
}
|
|
118
125
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
119
126
|
if (!content) return { content: "", inline };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/lib/strings/markdown.js
|
|
@@ -23,16 +33,23 @@ __export(markdown_exports, {
|
|
|
23
33
|
treatMarkdownWhitespace: () => treatMarkdownWhitespace
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(markdown_exports);
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
36
|
+
var import_markdown_it = __toESM(require("markdown-it"), 1);
|
|
37
|
+
var import_markdown_it_anchor = __toESM(require("markdown-it-anchor"), 1);
|
|
38
|
+
var md = (0, import_markdown_it.default)({
|
|
39
|
+
html: true,
|
|
40
|
+
linkify: true,
|
|
41
|
+
typographer: true
|
|
42
|
+
});
|
|
43
|
+
md.use(import_markdown_it_anchor.default, {
|
|
44
|
+
permalink: false,
|
|
45
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
46
|
+
});
|
|
29
47
|
function markdown(content, options = {}) {
|
|
30
48
|
const defaultOptions = { inline: false };
|
|
31
49
|
const opts = { ...defaultOptions, ...options };
|
|
32
|
-
import_marked.marked.use((0, import_marked_mangle.mangle)());
|
|
33
|
-
import_marked.marked.use((0, import_marked_gfm_heading_id.gfmHeadingId)());
|
|
34
50
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
35
|
-
return
|
|
51
|
+
if (opts.inline) return md.renderInline(treated);
|
|
52
|
+
return md.render(treated);
|
|
36
53
|
}
|
|
37
54
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
38
55
|
if (!content) return { content: "", inline };
|
package/dist/esm/dom/events.js
CHANGED
|
@@ -24,43 +24,8 @@ function updateEvent(event, updates) {
|
|
|
24
24
|
...updates
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
function createListeners(listeners) {
|
|
28
|
-
listeners = listeners || [];
|
|
29
|
-
listeners.forEach((listener) => {
|
|
30
|
-
const { node, event, handler } = listener;
|
|
31
|
-
node.addEventListener(event, handler);
|
|
32
|
-
});
|
|
33
|
-
return {
|
|
34
|
-
get list() {
|
|
35
|
-
return listeners;
|
|
36
|
-
},
|
|
37
|
-
add({ node, event, handler }) {
|
|
38
|
-
listeners.push({ node, event, handler });
|
|
39
|
-
node.addEventListener(event, handler);
|
|
40
|
-
},
|
|
41
|
-
remove({ node, event, handler }) {
|
|
42
|
-
const index = listeners.findIndex((listener) => {
|
|
43
|
-
if (listener.node === node && listener.event === event && listener.handler === handler) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
});
|
|
48
|
-
if (index !== -1) {
|
|
49
|
-
listeners.splice(index, 1);
|
|
50
|
-
node.removeEventListener(event, handler);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
clear() {
|
|
54
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
55
|
-
listeners = [];
|
|
56
|
-
node.removeEventListener(event, handler);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
27
|
export {
|
|
62
28
|
addListeners,
|
|
63
|
-
createListeners,
|
|
64
29
|
dispatchEvent,
|
|
65
30
|
removeListeners,
|
|
66
31
|
updateEvent
|
package/dist/esm/dom/index.js
CHANGED
|
@@ -134,40 +134,6 @@ function updateEvent(event, updates) {
|
|
|
134
134
|
...updates
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
function createListeners(listeners) {
|
|
138
|
-
listeners = listeners || [];
|
|
139
|
-
listeners.forEach((listener) => {
|
|
140
|
-
const { node, event, handler } = listener;
|
|
141
|
-
node.addEventListener(event, handler);
|
|
142
|
-
});
|
|
143
|
-
return {
|
|
144
|
-
get list() {
|
|
145
|
-
return listeners;
|
|
146
|
-
},
|
|
147
|
-
add({ node, event, handler }) {
|
|
148
|
-
listeners.push({ node, event, handler });
|
|
149
|
-
node.addEventListener(event, handler);
|
|
150
|
-
},
|
|
151
|
-
remove({ node, event, handler }) {
|
|
152
|
-
const index = listeners.findIndex((listener) => {
|
|
153
|
-
if (listener.node === node && listener.event === event && listener.handler === handler) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
return false;
|
|
157
|
-
});
|
|
158
|
-
if (index !== -1) {
|
|
159
|
-
listeners.splice(index, 1);
|
|
160
|
-
node.removeEventListener(event, handler);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
clear() {
|
|
164
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
165
|
-
listeners = [];
|
|
166
|
-
node.removeEventListener(event, handler);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
137
|
|
|
172
138
|
// src/dom/observers/observer.js
|
|
173
139
|
function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
|
|
@@ -1131,7 +1097,6 @@ export {
|
|
|
1131
1097
|
checkForAccessibleName,
|
|
1132
1098
|
cookies,
|
|
1133
1099
|
copyRichText,
|
|
1134
|
-
createListeners,
|
|
1135
1100
|
dispatchEvent,
|
|
1136
1101
|
em,
|
|
1137
1102
|
findScrollContainer,
|
package/dist/esm/lib/index.js
CHANGED
|
@@ -869,16 +869,23 @@ function parseSSE(message) {
|
|
|
869
869
|
}
|
|
870
870
|
|
|
871
871
|
// src/lib/strings/markdown.js
|
|
872
|
-
import
|
|
873
|
-
import
|
|
874
|
-
|
|
872
|
+
import markdownit from "markdown-it";
|
|
873
|
+
import anchor from "markdown-it-anchor";
|
|
874
|
+
var md = markdownit({
|
|
875
|
+
html: true,
|
|
876
|
+
linkify: true,
|
|
877
|
+
typographer: true
|
|
878
|
+
});
|
|
879
|
+
md.use(anchor, {
|
|
880
|
+
permalink: false,
|
|
881
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
882
|
+
});
|
|
875
883
|
function markdown(content, options = {}) {
|
|
876
884
|
const defaultOptions = { inline: false };
|
|
877
885
|
const opts = { ...defaultOptions, ...options };
|
|
878
|
-
marked.use(mangle());
|
|
879
|
-
marked.use(gfmHeadingId());
|
|
880
886
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
881
|
-
return
|
|
887
|
+
if (opts.inline) return md.renderInline(treated);
|
|
888
|
+
return md.render(treated);
|
|
882
889
|
}
|
|
883
890
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
884
891
|
if (!content) return { content: "", inline };
|
|
@@ -55,16 +55,23 @@ function isDigit(char) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// src/lib/strings/markdown.js
|
|
58
|
-
import
|
|
59
|
-
import
|
|
60
|
-
|
|
58
|
+
import markdownit from "markdown-it";
|
|
59
|
+
import anchor from "markdown-it-anchor";
|
|
60
|
+
var md = markdownit({
|
|
61
|
+
html: true,
|
|
62
|
+
linkify: true,
|
|
63
|
+
typographer: true
|
|
64
|
+
});
|
|
65
|
+
md.use(anchor, {
|
|
66
|
+
permalink: false,
|
|
67
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
68
|
+
});
|
|
61
69
|
function markdown(content, options = {}) {
|
|
62
70
|
const defaultOptions = { inline: false };
|
|
63
71
|
const opts = { ...defaultOptions, ...options };
|
|
64
|
-
marked.use(mangle());
|
|
65
|
-
marked.use(gfmHeadingId());
|
|
66
72
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
67
|
-
return
|
|
73
|
+
if (opts.inline) return md.renderInline(treated);
|
|
74
|
+
return md.render(treated);
|
|
68
75
|
}
|
|
69
76
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
70
77
|
if (!content) return { content: "", inline };
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
// src/lib/strings/markdown.js
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import markdownit from "markdown-it";
|
|
3
|
+
import anchor from "markdown-it-anchor";
|
|
4
|
+
var md = markdownit({
|
|
5
|
+
html: true,
|
|
6
|
+
linkify: true,
|
|
7
|
+
typographer: true
|
|
8
|
+
});
|
|
9
|
+
md.use(anchor, {
|
|
10
|
+
permalink: false,
|
|
11
|
+
slugify: (s) => s.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]/g, "")
|
|
12
|
+
});
|
|
5
13
|
function markdown(content, options = {}) {
|
|
6
14
|
const defaultOptions = { inline: false };
|
|
7
15
|
const opts = { ...defaultOptions, ...options };
|
|
8
|
-
marked.use(mangle());
|
|
9
|
-
marked.use(gfmHeadingId());
|
|
10
16
|
const { content: treated } = treatMarkdownWhitespace(content, opts);
|
|
11
|
-
return
|
|
17
|
+
if (opts.inline) return md.renderInline(treated);
|
|
18
|
+
return md.render(treated);
|
|
12
19
|
}
|
|
13
20
|
function treatMarkdownWhitespace(content, { inline } = {}) {
|
|
14
21
|
if (!content) return { content: "", inline };
|
|
@@ -1,20 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} EventListener
|
|
3
|
+
* @property {Element} node - The DOM element to attach the event listener to
|
|
4
|
+
* @property {string} event - The event type (e.g., 'click', 'keydown')
|
|
5
|
+
* @property {Function} handler - The event handler function
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} ListenerManager
|
|
9
|
+
* @property {EventListener[]} list - Array of current event listeners
|
|
10
|
+
* @property {function(EventListener): void} add - Add a new event listener
|
|
11
|
+
* @property {function(EventListener): void} remove - Remove an event listener
|
|
12
|
+
* @property {function(): void} clear - Remove all event listeners
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} CustomEventOptions
|
|
16
|
+
* @property {boolean} [bubbles=false] - Whether the event bubbles up through the DOM
|
|
17
|
+
* @property {boolean} [cancelable=false] - Whether the event can be canceled
|
|
18
|
+
* @property {boolean} [composed=false] - Whether the event will trigger listeners outside of a shadow root
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Adds multiple event listeners to their respective DOM elements
|
|
22
|
+
* @param {EventListener[]} listeners - Array of listener objects
|
|
23
|
+
*/
|
|
24
|
+
declare function addListeners(listeners: EventListener[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Removes multiple event listeners from their respective DOM elements
|
|
27
|
+
* @param {EventListener[]} listeners - Array of listener objects
|
|
28
|
+
*/
|
|
29
|
+
declare function removeListeners(listeners: EventListener[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Dispatches a custom event from a DOM node
|
|
32
|
+
* @param {Element} node - The DOM element to dispatch the event from
|
|
33
|
+
* @param {string} eventName - The name of the custom event
|
|
34
|
+
* @param {*} detail - The detail data to include with the event
|
|
35
|
+
* @param {CustomEventOptions} [options={}] - Additional event options
|
|
36
|
+
*/
|
|
37
|
+
declare function dispatchEvent(node: Element, eventName: string, detail: any, options?: CustomEventOptions): void;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new CustomEvent with updated properties from an existing event
|
|
40
|
+
* @param {Event} event - The original event object
|
|
41
|
+
* @param {Object} updates - Properties to update in the new event
|
|
42
|
+
* @return {CustomEvent} A new CustomEvent with updated properties
|
|
43
|
+
*/
|
|
44
|
+
declare function updateEvent(event: Event, updates: any): CustomEvent;
|
|
45
|
+
type EventListener = {
|
|
46
|
+
/**
|
|
47
|
+
* - The DOM element to attach the event listener to
|
|
48
|
+
*/
|
|
49
|
+
node: Element;
|
|
50
|
+
/**
|
|
51
|
+
* - The event type (e.g., 'click', 'keydown')
|
|
52
|
+
*/
|
|
53
|
+
event: string;
|
|
54
|
+
/**
|
|
55
|
+
* - The event handler function
|
|
56
|
+
*/
|
|
57
|
+
handler: Function;
|
|
58
|
+
};
|
|
59
|
+
type ListenerManager = {
|
|
60
|
+
/**
|
|
61
|
+
* - Array of current event listeners
|
|
62
|
+
*/
|
|
63
|
+
list: EventListener[];
|
|
64
|
+
/**
|
|
65
|
+
* - Add a new event listener
|
|
66
|
+
*/
|
|
67
|
+
add: (arg0: EventListener) => void;
|
|
68
|
+
/**
|
|
69
|
+
* - Remove an event listener
|
|
70
|
+
*/
|
|
71
|
+
remove: (arg0: EventListener) => void;
|
|
72
|
+
/**
|
|
73
|
+
* - Remove all event listeners
|
|
74
|
+
*/
|
|
75
|
+
clear: () => void;
|
|
76
|
+
};
|
|
77
|
+
type CustomEventOptions = {
|
|
78
|
+
/**
|
|
79
|
+
* - Whether the event bubbles up through the DOM
|
|
80
|
+
*/
|
|
81
|
+
bubbles?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* - Whether the event can be canceled
|
|
84
|
+
*/
|
|
85
|
+
cancelable?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* - Whether the event will trigger listeners outside of a shadow root
|
|
88
|
+
*/
|
|
89
|
+
composed?: boolean;
|
|
18
90
|
};
|
|
19
91
|
|
|
20
|
-
export {
|
|
92
|
+
export { type CustomEventOptions, type EventListener, type ListenerManager, addListeners, dispatchEvent, removeListeners, updateEvent };
|
|
@@ -6,7 +6,7 @@ export { boundingBox, boundingBoxRelativeToAncestor } from './bounding-box.cjs';
|
|
|
6
6
|
export { copyRichText } from './clipboard.cjs';
|
|
7
7
|
export { cookies, getCookie } from './cookie.cjs';
|
|
8
8
|
export { getCSSValue, getCSSVar, setCSSValue, setCSSVar } from './css-vars.cjs';
|
|
9
|
-
export {
|
|
9
|
+
export { CustomEventOptions, EventListener, ListenerManager, addListeners, dispatchEvent, removeListeners, updateEvent } from './events.cjs';
|
|
10
10
|
export { Focusable, Focusables, getFocusableElements } from './focusable.cjs';
|
|
11
11
|
export { em, getUnit, lh, rem, toPx } from './font-size.cjs';
|
|
12
12
|
export { getAncestorWithSiblings, getChildrenElements, getElement, getNodeType, getParentElement, getSelfIndex, getSiblingElements, isAncestor } from './get-element.cjs';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely executes a callback function if it's a function
|
|
3
|
+
* @param {Function|*} fn - The potential callback function
|
|
4
|
+
* @param {...*} data - Data arguments to pass to the callback
|
|
5
|
+
*/
|
|
6
|
+
declare function runCallback(fn: Function | any, ...data: any[]): void;
|
|
7
|
+
|
|
8
|
+
export { runCallback };
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @param {string} content - Markdown content to convert
|
|
4
4
|
* @param {Object} [options={}] - Conversion options
|
|
5
5
|
* @param {boolean} [options.inline=false] - Whether content should be treated as inline markdown
|
|
6
|
-
* @returns {string
|
|
6
|
+
* @returns {string} Converted HTML string
|
|
7
7
|
*/
|
|
8
8
|
declare function markdown(content: string, options?: {
|
|
9
9
|
inline?: boolean;
|
|
10
|
-
}): string
|
|
10
|
+
}): string;
|
|
11
11
|
/**
|
|
12
12
|
* Handles whitespace in markdown content to ensure proper rendering
|
|
13
13
|
* @param {string} content - Markdown content to process
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -54,6 +54,8 @@
|
|
|
54
54
|
"deep-eql": "^5.0.2",
|
|
55
55
|
"dompurify": "^3.2.4",
|
|
56
56
|
"glob": "^11.0.0",
|
|
57
|
+
"markdown-it": "^14.1.0",
|
|
58
|
+
"markdown-it-anchor": "^9.2.0",
|
|
57
59
|
"marked": "^15.0.7",
|
|
58
60
|
"marked-gfm-heading-id": "^4.1.1",
|
|
59
61
|
"marked-mangle": "^1.1.10",
|
package/src/dom/events.js
CHANGED
|
@@ -1,26 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} EventListener
|
|
3
|
+
* @property {Element} node - The DOM element to attach the event listener to
|
|
4
|
+
* @property {string} event - The event type (e.g., 'click', 'keydown')
|
|
5
|
+
* @property {Function} handler - The event handler function
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} ListenerManager
|
|
10
|
+
* @property {EventListener[]} list - Array of current event listeners
|
|
11
|
+
* @property {function(EventListener): void} add - Add a new event listener
|
|
12
|
+
* @property {function(EventListener): void} remove - Remove an event listener
|
|
13
|
+
* @property {function(): void} clear - Remove all event listeners
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} CustomEventOptions
|
|
18
|
+
* @property {boolean} [bubbles=false] - Whether the event bubbles up through the DOM
|
|
19
|
+
* @property {boolean} [cancelable=false] - Whether the event can be canceled
|
|
20
|
+
* @property {boolean} [composed=false] - Whether the event will trigger listeners outside of a shadow root
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds multiple event listeners to their respective DOM elements
|
|
25
|
+
* @param {EventListener[]} listeners - Array of listener objects
|
|
26
|
+
*/
|
|
1
27
|
export function addListeners(listeners) {
|
|
2
28
|
listeners.forEach(({ node, event, handler }) => {
|
|
3
29
|
node.addEventListener(event, handler)
|
|
4
30
|
})
|
|
5
31
|
}
|
|
6
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Removes multiple event listeners from their respective DOM elements
|
|
35
|
+
* @param {EventListener[]} listeners - Array of listener objects
|
|
36
|
+
*/
|
|
7
37
|
export function removeListeners(listeners) {
|
|
8
38
|
listeners.forEach(({ node, event, handler }) => {
|
|
9
39
|
node.removeEventListener(event, handler)
|
|
10
40
|
})
|
|
11
41
|
}
|
|
12
42
|
|
|
13
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Dispatches a custom event from a DOM node
|
|
45
|
+
* @param {Element} node - The DOM element to dispatch the event from
|
|
46
|
+
* @param {string} eventName - The name of the custom event
|
|
47
|
+
* @param {*} detail - The detail data to include with the event
|
|
48
|
+
* @param {CustomEventOptions} [options={}] - Additional event options
|
|
49
|
+
*/
|
|
14
50
|
export function dispatchEvent(node, eventName, detail, options = {}) {
|
|
15
51
|
node.dispatchEvent(
|
|
16
52
|
new CustomEvent(eventName, {
|
|
17
53
|
...options,
|
|
18
54
|
detail,
|
|
19
|
-
})
|
|
55
|
+
}),
|
|
20
56
|
)
|
|
21
57
|
}
|
|
22
58
|
|
|
23
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new CustomEvent with updated properties from an existing event
|
|
61
|
+
* @param {Event} event - The original event object
|
|
62
|
+
* @param {Object} updates - Properties to update in the new event
|
|
63
|
+
* @return {CustomEvent} A new CustomEvent with updated properties
|
|
64
|
+
*/
|
|
24
65
|
export function updateEvent(event, updates) {
|
|
25
66
|
const { type, ...rest } = event
|
|
26
67
|
return new CustomEvent(event.type, {
|
|
@@ -28,50 +69,3 @@ export function updateEvent(event, updates) {
|
|
|
28
69
|
...updates,
|
|
29
70
|
})
|
|
30
71
|
}
|
|
31
|
-
|
|
32
|
-
// Doesn't seem to be used anywhere now.
|
|
33
|
-
// Switch to addListeners and removeListeners instead
|
|
34
|
-
export function createListeners(listeners) {
|
|
35
|
-
listeners = listeners || []
|
|
36
|
-
|
|
37
|
-
listeners.forEach(listener => {
|
|
38
|
-
const { node, event, handler } = listener
|
|
39
|
-
node.addEventListener(event, handler)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
get list() {
|
|
44
|
-
return listeners
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
add({ node, event, handler }) {
|
|
48
|
-
listeners.push({ node, event, handler })
|
|
49
|
-
node.addEventListener(event, handler)
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
remove({ node, event, handler }) {
|
|
53
|
-
const index = listeners.findIndex(listener => {
|
|
54
|
-
if (
|
|
55
|
-
listener.node === node &&
|
|
56
|
-
listener.event === event &&
|
|
57
|
-
listener.handler === handler
|
|
58
|
-
) {
|
|
59
|
-
return true
|
|
60
|
-
}
|
|
61
|
-
return false
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
if (index !== -1) {
|
|
65
|
-
listeners.splice(index, 1)
|
|
66
|
-
node.removeEventListener(event, handler)
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
clear() {
|
|
71
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
72
|
-
listeners = []
|
|
73
|
-
node.removeEventListener(event, handler)
|
|
74
|
-
})
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely executes a callback function if it's a function
|
|
3
|
+
* @param {Function|*} fn - The potential callback function
|
|
4
|
+
* @param {...*} data - Data arguments to pass to the callback
|
|
5
|
+
*/
|
|
6
|
+
export function runCallback(fn, ...data) {
|
|
7
|
+
if (typeof fn === 'function') fn(data)
|
|
8
|
+
}
|
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import markdownit from 'markdown-it'
|
|
2
|
+
import anchor from 'markdown-it-anchor'
|
|
3
|
+
|
|
4
|
+
const md = markdownit({
|
|
5
|
+
html: true,
|
|
6
|
+
linkify: true,
|
|
7
|
+
typographer: true,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
md.use(anchor, {
|
|
11
|
+
permalink: false,
|
|
12
|
+
slugify: s =>
|
|
13
|
+
s
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.replace(/\s+/g, '-')
|
|
16
|
+
.replace(/[^\w-]/g, ''),
|
|
17
|
+
})
|
|
4
18
|
|
|
5
19
|
/**
|
|
6
20
|
* Converts markdown content to HTML with whitespace handling
|
|
7
21
|
* @param {string} content - Markdown content to convert
|
|
8
22
|
* @param {Object} [options={}] - Conversion options
|
|
9
23
|
* @param {boolean} [options.inline=false] - Whether content should be treated as inline markdown
|
|
10
|
-
* @returns {string
|
|
24
|
+
* @returns {string} Converted HTML string
|
|
11
25
|
*/
|
|
12
26
|
export function markdown(content, options = {}) {
|
|
13
27
|
const defaultOptions = { inline: false }
|
|
14
28
|
const opts = { ...defaultOptions, ...options }
|
|
15
29
|
|
|
16
|
-
// Prepare Marked
|
|
17
|
-
marked.use(mangle())
|
|
18
|
-
marked.use(gfmHeadingId())
|
|
19
|
-
|
|
20
30
|
const { content: treated } = treatMarkdownWhitespace(content, opts)
|
|
21
|
-
|
|
31
|
+
|
|
32
|
+
if (opts.inline) return md.renderInline(treated)
|
|
33
|
+
return md.render(treated)
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
/**
|