content-engine-lib 1.0.5 → 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/dist/index.d.ts +5 -13
- package/dist/index.es.js +199 -192
- package/dist/index.umd.js +1 -3
- package/dist/u/benchmark/index.d.ts +12 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hydrator_p_TYP, renderer_p_TYP } from './u/types';
|
|
2
2
|
declare const call_0: <K extends "msg">(event: K, ...args: Parameters<{
|
|
3
3
|
msg: (payload: {
|
|
4
4
|
type: string;
|
|
@@ -36,6 +36,7 @@ declare const renderer: (_p: renderer_p_TYP) => Promise<{
|
|
|
36
36
|
r: string;
|
|
37
37
|
style: string;
|
|
38
38
|
head: string;
|
|
39
|
+
benchmark: any;
|
|
39
40
|
}>;
|
|
40
41
|
}>;
|
|
41
42
|
declare const hydrator: (_p: hydrator_p_TYP) => Promise<{
|
|
@@ -44,18 +45,9 @@ declare const hydrator: (_p: hydrator_p_TYP) => Promise<{
|
|
|
44
45
|
l: any[];
|
|
45
46
|
} | any;
|
|
46
47
|
}) => Promise<{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}>;
|
|
50
|
-
}>;
|
|
51
|
-
declare const editor: (_p: editor_p_TYP) => Promise<{
|
|
52
|
-
set: (_$p: {
|
|
53
|
-
data: {
|
|
54
|
-
l: any[];
|
|
48
|
+
benchmark: {
|
|
49
|
+
time_taken_ms: string;
|
|
55
50
|
};
|
|
56
|
-
}) => Promise<{
|
|
57
|
-
r: string;
|
|
58
|
-
style: string;
|
|
59
51
|
}>;
|
|
60
52
|
}>;
|
|
61
|
-
export { renderer as ce_renderer, hydrator as ce_hydrator,
|
|
53
|
+
export { renderer as ce_renderer, hydrator as ce_hydrator, call_0 as ce_call, listen_1 as ce_listen, };
|
package/dist/index.es.js
CHANGED
|
@@ -1,148 +1,176 @@
|
|
|
1
|
-
const
|
|
1
|
+
const y = () => ({
|
|
2
2
|
set: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
|
|
3
|
-
const
|
|
4
|
-
return (t == "x" ?
|
|
3
|
+
const e = Math.random() * 16 | 0;
|
|
4
|
+
return (t == "x" ? e : e & 3 | 8).toString(16);
|
|
5
5
|
})
|
|
6
|
-
}),
|
|
6
|
+
}), x = async () => ({
|
|
7
7
|
f: {
|
|
8
8
|
name: (t) => `${t.name}${t.id}`
|
|
9
9
|
}
|
|
10
|
-
}),
|
|
10
|
+
}), g = async () => ({
|
|
11
11
|
set: async (t) => {
|
|
12
12
|
console.log("--theme");
|
|
13
13
|
try {
|
|
14
14
|
if (!t.el_id)
|
|
15
15
|
throw new Error("[el_id] is required");
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
16
|
+
const e = t.name, n = document.getElementById(t.el_id);
|
|
17
|
+
if (!n)
|
|
18
18
|
throw new Error("[el_id] is invalid");
|
|
19
|
-
((
|
|
20
|
-
const
|
|
21
|
-
((
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
19
|
+
((r) => {
|
|
20
|
+
const a = (s) => {
|
|
21
|
+
((d) => {
|
|
22
|
+
const i = d.getAttribute("data-ce");
|
|
23
|
+
if (!i)
|
|
24
24
|
return;
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
for (const
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
for (const
|
|
31
|
-
|
|
25
|
+
const m = JSON.parse(i).filter((l) => l?.k.startsWith("t-"));
|
|
26
|
+
if (m.length != 0)
|
|
27
|
+
for (const l of m) {
|
|
28
|
+
const u = l.k, f = l.v.split(" ");
|
|
29
|
+
if (u == `t-${e}-class`)
|
|
30
|
+
for (const o of f)
|
|
31
|
+
d.classList.add(o);
|
|
32
32
|
else
|
|
33
|
-
for (const
|
|
34
|
-
|
|
33
|
+
for (const o of f)
|
|
34
|
+
d.classList.remove(o);
|
|
35
35
|
}
|
|
36
|
-
})(
|
|
36
|
+
})(s);
|
|
37
37
|
};
|
|
38
|
-
for (const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})(
|
|
42
|
-
} catch (
|
|
43
|
-
const
|
|
44
|
-
throw console.log(
|
|
38
|
+
for (const s of r.getElementsByTagName("*"))
|
|
39
|
+
a(s);
|
|
40
|
+
a(r);
|
|
41
|
+
})(n);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
const n = `err: [theme] ${e}`;
|
|
44
|
+
throw console.log(n), n;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
function
|
|
49
|
-
let
|
|
48
|
+
function b(t, e = 1e3) {
|
|
49
|
+
let n = {
|
|
50
50
|
cnt: 0
|
|
51
51
|
};
|
|
52
|
-
return new Promise((
|
|
53
|
-
const
|
|
54
|
-
console.log(`[setInterval] is running.. [count=${
|
|
52
|
+
return new Promise((r) => {
|
|
53
|
+
const a = () => {
|
|
54
|
+
console.log(`[setInterval] is running.. [count=${n.cnt}]`);
|
|
55
55
|
try {
|
|
56
|
-
t() && (clearInterval(
|
|
56
|
+
t() && (clearInterval(s), r());
|
|
57
57
|
} catch {
|
|
58
|
-
console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${
|
|
58
|
+
console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${e}]`);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
|
|
60
|
+
n.cnt += 1;
|
|
61
|
+
}, s = setInterval(() => {
|
|
62
|
+
a();
|
|
63
|
+
}, e);
|
|
64
|
+
a();
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
let
|
|
67
|
+
let E = class {
|
|
68
68
|
listeners = {};
|
|
69
|
-
on = (
|
|
70
|
-
off = (
|
|
71
|
-
this.listeners[
|
|
69
|
+
on = (e, n) => ((this.listeners[e] ||= []).push(n), () => this.off(e, n));
|
|
70
|
+
off = (e, n) => {
|
|
71
|
+
this.listeners[e] = this.listeners[e]?.filter((r) => r !== n);
|
|
72
72
|
};
|
|
73
73
|
/** Sequential execution (await each listener) */
|
|
74
|
-
emit = async (
|
|
75
|
-
for (const
|
|
76
|
-
await
|
|
74
|
+
emit = async (e, ...n) => {
|
|
75
|
+
for (const r of this.listeners[e] ?? [])
|
|
76
|
+
await r(...n);
|
|
77
77
|
};
|
|
78
78
|
/** Parallel execution (await all listeners) */
|
|
79
|
-
emitParallel = async (
|
|
79
|
+
emitParallel = async (e, ...n) => {
|
|
80
80
|
await Promise.all(
|
|
81
|
-
(this.listeners[
|
|
81
|
+
(this.listeners[e] ?? []).map((r) => r(...n))
|
|
82
82
|
);
|
|
83
83
|
};
|
|
84
84
|
//Error-safe emit
|
|
85
|
-
emitSafe = async (
|
|
86
|
-
for (const
|
|
85
|
+
emitSafe = async (e, ...n) => {
|
|
86
|
+
for (const r of this.listeners[e] ?? [])
|
|
87
87
|
try {
|
|
88
|
-
await
|
|
89
|
-
} catch (
|
|
88
|
+
await r(...n);
|
|
89
|
+
} catch (a) {
|
|
90
90
|
this.listeners.error?.forEach(
|
|
91
|
-
(
|
|
91
|
+
(s) => s(a)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
};
|
|
96
|
-
const
|
|
96
|
+
const h = () => new E();
|
|
97
|
+
class $ {
|
|
98
|
+
startTime;
|
|
99
|
+
endTime;
|
|
100
|
+
isRunning;
|
|
101
|
+
constructor() {
|
|
102
|
+
this.startTime = 0, this.endTime = 0, this.isRunning = !1;
|
|
103
|
+
}
|
|
104
|
+
// Starts the timer
|
|
105
|
+
start() {
|
|
106
|
+
if (this.isRunning)
|
|
107
|
+
throw new Error("Benchmark has already started.");
|
|
108
|
+
this.startTime = performance.now(), this.isRunning = !0;
|
|
109
|
+
}
|
|
110
|
+
// Stops the timer and records the end time
|
|
111
|
+
stop() {
|
|
112
|
+
if (!this.isRunning)
|
|
113
|
+
throw new Error("Benchmark hasn't started.");
|
|
114
|
+
this.endTime = performance.now(), this.isRunning = !1;
|
|
115
|
+
}
|
|
116
|
+
// Get the result in milliseconds
|
|
117
|
+
result() {
|
|
118
|
+
if (this.isRunning)
|
|
119
|
+
throw new Error("Benchmark is still running.");
|
|
120
|
+
return {
|
|
121
|
+
time_taken_ms: (this.endTime - this.startTime).toFixed(4)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
97
125
|
console.log("content-engine-lib");
|
|
98
|
-
let
|
|
126
|
+
let c = {
|
|
99
127
|
lib: {
|
|
100
128
|
inbuilt_lib: [],
|
|
101
129
|
// <any>[], // [`text`,`table`,`editor`]
|
|
102
130
|
l: {},
|
|
103
131
|
set: async (t) => {
|
|
104
|
-
const
|
|
105
|
-
for (const [
|
|
106
|
-
const
|
|
107
|
-
let
|
|
108
|
-
const
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
if (/^[a-zA-Z0-9]/.test(
|
|
112
|
-
if (
|
|
113
|
-
|
|
132
|
+
const e = t?.lib || [];
|
|
133
|
+
for (const [n, r] of e.entries()) {
|
|
134
|
+
const a = r, s = `${a.name}:${t.run_from}`, d = `${t.run_from}_src`;
|
|
135
|
+
let i = a[d];
|
|
136
|
+
const _ = `${t.run_from}_src`;
|
|
137
|
+
let m = t?.lazy_lib?.[_] || null;
|
|
138
|
+
if (m && (m = m.replace("{*}", `${a.name}`)), console.log(`_lazy_src: ${m}`), console.log(`_src: ${i}`), c.lib.l.hasOwnProperty(`${s}`) == !1) {
|
|
139
|
+
if (/^[a-zA-Z0-9]/.test(i) && i.includes("/") == !1 && c.lib.inbuilt_lib.indexOf(`${a.name}`) === -1)
|
|
140
|
+
if (m)
|
|
141
|
+
i = m;
|
|
114
142
|
else
|
|
115
|
-
throw `[lib-name=${
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
143
|
+
throw `[lib-name=${a.name},lib-src=${i}] not allowed or available in in-build mode. Need to use lazy-lib config.`;
|
|
144
|
+
if (i.startsWith("./") || i.startsWith("../")) {
|
|
145
|
+
const l = await import(
|
|
118
146
|
/* @vite-ignore */
|
|
119
147
|
/* webpackIgnore: true */
|
|
120
|
-
`${
|
|
148
|
+
`${i}`
|
|
121
149
|
);
|
|
122
|
-
|
|
123
|
-
lib:
|
|
124
|
-
src:
|
|
150
|
+
c.lib.l[`${s}`] = {
|
|
151
|
+
lib: l,
|
|
152
|
+
src: i
|
|
125
153
|
};
|
|
126
154
|
}
|
|
127
|
-
if (
|
|
128
|
-
const
|
|
155
|
+
if (i.startsWith("http://") || i.startsWith("https://")) {
|
|
156
|
+
const l = await import(
|
|
129
157
|
/* @vite-ignore */
|
|
130
158
|
/* webpackIgnore: true */
|
|
131
|
-
`${
|
|
159
|
+
`${i}`
|
|
132
160
|
);
|
|
133
|
-
|
|
134
|
-
lib:
|
|
135
|
-
src:
|
|
161
|
+
c.lib.l[`${s}`] = {
|
|
162
|
+
lib: l,
|
|
163
|
+
src: i
|
|
136
164
|
};
|
|
137
165
|
}
|
|
138
166
|
}
|
|
139
167
|
}
|
|
140
|
-
console.log(await
|
|
168
|
+
console.log(await c.lib.get_all({}));
|
|
141
169
|
},
|
|
142
170
|
get: async (t) => {
|
|
143
|
-
let
|
|
144
|
-
const
|
|
145
|
-
return
|
|
171
|
+
let e = null;
|
|
172
|
+
const n = `${t.name}:${t.run_from}`;
|
|
173
|
+
return c.lib.l.hasOwnProperty(`${n}`) == !1 && await c.lib.set({
|
|
146
174
|
lib: [
|
|
147
175
|
{
|
|
148
176
|
renderer_src: t.name,
|
|
@@ -153,176 +181,155 @@ let _ = {
|
|
|
153
181
|
],
|
|
154
182
|
run_from: t.run_from,
|
|
155
183
|
lazy_lib: t.lazy_lib
|
|
156
|
-
}),
|
|
184
|
+
}), e = c.lib.l[`${n}`], e;
|
|
157
185
|
},
|
|
158
|
-
get_all: async (t) =>
|
|
186
|
+
get_all: async (t) => c.lib.l
|
|
159
187
|
},
|
|
160
188
|
path: {
|
|
161
189
|
set: (t) => {
|
|
162
|
-
let
|
|
163
|
-
const
|
|
164
|
-
if (t.src.indexOf("://localhost") !== -1 || t.src.indexOf("://127.0.0.1") !== -1 || (
|
|
165
|
-
for (const [
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
return `${
|
|
190
|
+
let e = "", n = "";
|
|
191
|
+
const r = t.src.split("/");
|
|
192
|
+
if (t.src.indexOf("://localhost") !== -1 || t.src.indexOf("://127.0.0.1") !== -1 || (n = "/dist"), r.indexOf(t.type) !== -1)
|
|
193
|
+
for (const [a, s] of r.entries()) {
|
|
194
|
+
let d = a == 0 ? "" : "/";
|
|
195
|
+
if (e += `${d}${s}`, s == t.type)
|
|
196
|
+
return `${e}${n}${t.name}`;
|
|
169
197
|
}
|
|
170
198
|
else
|
|
171
|
-
for (const [
|
|
172
|
-
let
|
|
173
|
-
if (
|
|
174
|
-
return `${
|
|
199
|
+
for (const [a, s] of r.entries()) {
|
|
200
|
+
let d = a == 0 ? "" : "/";
|
|
201
|
+
if (e += `${d}${s}`, s == "src")
|
|
202
|
+
return `${e}${n}${t.name}`;
|
|
175
203
|
}
|
|
176
|
-
return `${
|
|
204
|
+
return `${e}${n}${t.name}`;
|
|
177
205
|
}
|
|
178
206
|
}
|
|
179
207
|
};
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
return await
|
|
183
|
-
set: async (
|
|
208
|
+
const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t) => {
|
|
209
|
+
const e = await x();
|
|
210
|
+
return await c.lib.set({ lib: t.lib, run_from: "renderer", lazy_lib: t.lazy_lib }), {
|
|
211
|
+
set: async (n) => {
|
|
184
212
|
console.log("--renderer [set]");
|
|
185
|
-
|
|
213
|
+
const r = new $();
|
|
214
|
+
r.start();
|
|
215
|
+
let a = n.data?.value?.l || n.data.l, s = {
|
|
186
216
|
r: "",
|
|
187
217
|
style: "",
|
|
188
|
-
head: ""
|
|
218
|
+
head: "",
|
|
189
219
|
// `<test>head-1</test>`
|
|
220
|
+
//set..
|
|
221
|
+
//total:_l.length,
|
|
222
|
+
benchmark: null
|
|
190
223
|
};
|
|
191
224
|
return await (async () => {
|
|
192
|
-
for (const
|
|
193
|
-
const
|
|
225
|
+
for (const i of a) {
|
|
226
|
+
const _ = await await c.lib.get({ name: i.type, run_from: "renderer", lazy_lib: t.lazy_lib }), l = await (await _.lib.index({
|
|
194
227
|
f: {
|
|
195
|
-
name: (
|
|
196
|
-
get_lib: async (
|
|
197
|
-
set_theme: async (
|
|
198
|
-
path: (
|
|
228
|
+
name: (u) => e.f.name({ id: i.id, name: u }),
|
|
229
|
+
get_lib: async (u) => await await c.lib.get({ name: u.name, run_from: u.run_from, lazy_lib: t.lazy_lib }),
|
|
230
|
+
set_theme: async (u) => await (await g()).set(u),
|
|
231
|
+
path: (u) => c.path.set({ src: _.src, type: i.type, name: u }),
|
|
232
|
+
//set..
|
|
233
|
+
uuid: () => y().set(),
|
|
234
|
+
wait_until: b
|
|
199
235
|
}
|
|
200
236
|
})).set(
|
|
201
237
|
{
|
|
202
238
|
data: {
|
|
203
|
-
curr:
|
|
239
|
+
curr: i
|
|
204
240
|
}
|
|
205
241
|
}
|
|
206
242
|
/*_$cb*/
|
|
207
243
|
);
|
|
208
|
-
|
|
244
|
+
s.r += l?.r || "", s.style += l?.style || "", s.head += l?.head || "";
|
|
209
245
|
}
|
|
210
|
-
})(),
|
|
246
|
+
})(), r.stop(), s.benchmark = r.result(), s;
|
|
211
247
|
}
|
|
212
248
|
};
|
|
213
|
-
},
|
|
214
|
-
const
|
|
215
|
-
return await
|
|
216
|
-
set: async (
|
|
249
|
+
}, W = async (t) => {
|
|
250
|
+
const e = await x();
|
|
251
|
+
return await c.lib.set({ lib: t.lib, run_from: "hydrator", lazy_lib: t.lazy_lib }), {
|
|
252
|
+
set: async (n) => {
|
|
217
253
|
console.log("--hydrator [set]");
|
|
218
|
-
|
|
254
|
+
const r = new $();
|
|
255
|
+
r.start();
|
|
256
|
+
let a = {
|
|
219
257
|
r: "",
|
|
220
258
|
style: ""
|
|
221
|
-
}
|
|
259
|
+
}, s = {
|
|
260
|
+
style_id: `${y().set()}_stl`
|
|
261
|
+
}, d = n.data?.value?.l || n.data.l;
|
|
222
262
|
const i = async () => {
|
|
223
|
-
for (const
|
|
224
|
-
const
|
|
263
|
+
for (const _ of d) {
|
|
264
|
+
const m = await await c.lib.get({ name: _.type, run_from: "hydrator", lazy_lib: t.lazy_lib }), l = m.lib, u = h(), w = u.on, f = await (await l.index({
|
|
225
265
|
/**@my module can use it to set custom variables. */
|
|
226
266
|
my: {},
|
|
227
267
|
//NOTE: We cannot add or use any variable of this object, It's reserved for module.
|
|
228
268
|
f: {
|
|
229
|
-
name: (o) =>
|
|
230
|
-
get_lib: async (o) => await await
|
|
231
|
-
set_theme: async (o) => await (await
|
|
232
|
-
path: (o) =>
|
|
269
|
+
name: (o) => e.f.name({ id: _.id, name: o }),
|
|
270
|
+
get_lib: async (o) => await await c.lib.get({ name: o.name, run_from: o.run_from, lazy_lib: t.lazy_lib }),
|
|
271
|
+
set_theme: async (o) => await (await g()).set(o),
|
|
272
|
+
path: (o) => c.path.set({ src: m.src, type: _.type, name: o }),
|
|
273
|
+
//set..
|
|
274
|
+
uuid: () => y().set(),
|
|
275
|
+
wait_until: b,
|
|
233
276
|
//set..
|
|
234
|
-
call:
|
|
235
|
-
listen:
|
|
277
|
+
call: O,
|
|
278
|
+
listen: w,
|
|
236
279
|
//set..
|
|
237
|
-
new_emitter: () =>
|
|
280
|
+
new_emitter: () => h()
|
|
238
281
|
}
|
|
239
282
|
})).set(
|
|
240
283
|
{
|
|
241
284
|
data: {
|
|
242
|
-
curr:
|
|
285
|
+
curr: _
|
|
243
286
|
}
|
|
244
287
|
}
|
|
245
288
|
/*_$cb*/
|
|
246
289
|
);
|
|
247
|
-
|
|
290
|
+
T("msg", async (o) => {
|
|
248
291
|
try {
|
|
249
292
|
if (Object.keys(o.where || {}).length == 0) {
|
|
250
|
-
await
|
|
293
|
+
await u.emit("msg", o);
|
|
251
294
|
return;
|
|
252
295
|
}
|
|
253
296
|
} catch {
|
|
254
297
|
}
|
|
255
298
|
try {
|
|
256
|
-
if (
|
|
257
|
-
await
|
|
299
|
+
if (_?.[o.where?.key || ""] == o.where?.value) {
|
|
300
|
+
await u.emit("msg", o);
|
|
258
301
|
return;
|
|
259
302
|
}
|
|
260
303
|
} catch {
|
|
261
304
|
}
|
|
262
|
-
}),
|
|
305
|
+
}), a.style += f.style;
|
|
263
306
|
}
|
|
264
307
|
};
|
|
265
|
-
|
|
308
|
+
await b(
|
|
266
309
|
() => document.readyState === "complete" || typeof window < "u",
|
|
267
310
|
50
|
|
268
|
-
), await i()
|
|
311
|
+
), await i();
|
|
312
|
+
try {
|
|
313
|
+
((_) => {
|
|
314
|
+
const m = document.getElementById(`${s.style_id}`);
|
|
315
|
+
m && m.remove();
|
|
316
|
+
const l = document.createElement("style");
|
|
317
|
+
l.id = `${s.style_id}`, l.innerHTML = `${a.style}`, _.appendChild(l);
|
|
318
|
+
})(document.head);
|
|
319
|
+
} catch (_) {
|
|
320
|
+
console.log(`${_}, Failed to set style..`);
|
|
321
|
+
}
|
|
322
|
+
return r.stop(), {
|
|
323
|
+
//style_id:_ins.style_id,
|
|
324
|
+
//total:_l.length,
|
|
325
|
+
benchmark: r.result()
|
|
326
|
+
};
|
|
269
327
|
}
|
|
270
328
|
};
|
|
271
|
-
}
|
|
272
|
-
set: async (r) => {
|
|
273
|
-
console.log("--editor [set]");
|
|
274
|
-
let e = {
|
|
275
|
-
data: {
|
|
276
|
-
l: [
|
|
277
|
-
{
|
|
278
|
-
id: g().set(),
|
|
279
|
-
type: "editor",
|
|
280
|
-
data: {
|
|
281
|
-
l: []
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
}, n = {
|
|
287
|
-
r: "",
|
|
288
|
-
style: ""
|
|
289
|
-
};
|
|
290
|
-
const i = O, a = I, c = await i({
|
|
291
|
-
lib: t.lib,
|
|
292
|
-
lazy_lib: t.lazy_lib
|
|
293
|
-
}), l = await a({
|
|
294
|
-
lib: t.lib,
|
|
295
|
-
lazy_lib: t.lazy_lib
|
|
296
|
-
}), y = await c.set({
|
|
297
|
-
data: e.data
|
|
298
|
-
});
|
|
299
|
-
return (async () => {
|
|
300
|
-
const s = await l.set(
|
|
301
|
-
{
|
|
302
|
-
data: e.data
|
|
303
|
-
}
|
|
304
|
-
/*{
|
|
305
|
-
change: (_v:any) => {
|
|
306
|
-
//console.log(`--ce:editor [change]`);
|
|
307
|
-
//console.log(_v);
|
|
308
|
-
//send-cb..
|
|
309
|
-
_$cb?.change(_v);
|
|
310
|
-
}
|
|
311
|
-
}*/
|
|
312
|
-
);
|
|
313
|
-
((d) => {
|
|
314
|
-
const o = document.createElement("style");
|
|
315
|
-
o.innerHTML = `${s.style}`, d.appendChild(o);
|
|
316
|
-
})(document.head);
|
|
317
|
-
})(), n.r = y.r, n.style = `
|
|
318
|
-
${y.style}
|
|
319
|
-
`, n;
|
|
320
|
-
}
|
|
321
|
-
});
|
|
329
|
+
};
|
|
322
330
|
export {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
I as
|
|
326
|
-
|
|
327
|
-
O as ce_renderer
|
|
331
|
+
R as ce_call,
|
|
332
|
+
W as ce_hydrator,
|
|
333
|
+
I as ce_listen,
|
|
334
|
+
P as ce_renderer
|
|
328
335
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
(function(f,
|
|
2
|
-
${d.style}
|
|
3
|
-
`,r}});f.ce_call=S,f.ce_editor=W,f.ce_hydrator=p,f.ce_listen=I,f.ce_renderer=$,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(f,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(f=typeof globalThis<"u"?globalThis:f||self,y(f["content-engine-lib"]={}))})(this,(function(f){"use strict";const y=()=>({set:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}),g=async()=>({f:{name:t=>`${t.name}${t.id}`}}),x=async()=>({set:async t=>{console.log("--theme");try{if(!t.el_id)throw new Error("[el_id] is required");const e=t.name,n=document.getElementById(t.el_id);if(!n)throw new Error("[el_id] is invalid");(r=>{const a=s=>{(d=>{const i=d.getAttribute("data-ce");if(!i)return;const m=JSON.parse(i).filter(l=>l?.k.startsWith("t-"));if(m.length!=0)for(const l of m){const _=l.k,b=l.v.split(" ");if(_==`t-${e}-class`)for(const o of b)d.classList.add(o);else for(const o of b)d.classList.remove(o)}})(s)};for(const s of r.getElementsByTagName("*"))a(s);a(r)})(n)}catch(e){const n=`err: [theme] ${e}`;throw console.log(n),n}}});function w(t,e=1e3){let n={cnt:0};return new Promise(r=>{const a=()=>{console.log(`[setInterval] is running.. [count=${n.cnt}]`);try{t()&&(clearInterval(s),r())}catch{console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${e}]`)}n.cnt+=1},s=setInterval(()=>{a()},e);a()})}let T=class{listeners={};on=(e,n)=>((this.listeners[e]||=[]).push(n),()=>this.off(e,n));off=(e,n)=>{this.listeners[e]=this.listeners[e]?.filter(r=>r!==n)};emit=async(e,...n)=>{for(const r of this.listeners[e]??[])await r(...n)};emitParallel=async(e,...n)=>{await Promise.all((this.listeners[e]??[]).map(r=>r(...n)))};emitSafe=async(e,...n)=>{for(const r of this.listeners[e]??[])try{await r(...n)}catch(a){this.listeners.error?.forEach(s=>s(a))}}};const h=()=>new T;class ${startTime;endTime;isRunning;constructor(){this.startTime=0,this.endTime=0,this.isRunning=!1}start(){if(this.isRunning)throw new Error("Benchmark has already started.");this.startTime=performance.now(),this.isRunning=!0}stop(){if(!this.isRunning)throw new Error("Benchmark hasn't started.");this.endTime=performance.now(),this.isRunning=!1}result(){if(this.isRunning)throw new Error("Benchmark is still running.");return{time_taken_ms:(this.endTime-this.startTime).toFixed(4)}}}console.log("content-engine-lib");let c={lib:{inbuilt_lib:[],l:{},set:async t=>{const e=t?.lib||[];for(const[n,r]of e.entries()){const a=r,s=`${a.name}:${t.run_from}`,d=`${t.run_from}_src`;let i=a[d];const u=`${t.run_from}_src`;let m=t?.lazy_lib?.[u]||null;if(m&&(m=m.replace("{*}",`${a.name}`)),console.log(`_lazy_src: ${m}`),console.log(`_src: ${i}`),c.lib.l.hasOwnProperty(`${s}`)==!1){if(/^[a-zA-Z0-9]/.test(i)&&i.includes("/")==!1&&c.lib.inbuilt_lib.indexOf(`${a.name}`)===-1)if(m)i=m;else throw`[lib-name=${a.name},lib-src=${i}] not allowed or available in in-build mode. Need to use lazy-lib config.`;if(i.startsWith("./")||i.startsWith("../")){const l=await import(`${i}`);c.lib.l[`${s}`]={lib:l,src:i}}if(i.startsWith("http://")||i.startsWith("https://")){const l=await import(`${i}`);c.lib.l[`${s}`]={lib:l,src:i}}}}console.log(await c.lib.get_all({}))},get:async t=>{let e=null;const n=`${t.name}:${t.run_from}`;return c.lib.l.hasOwnProperty(`${n}`)==!1&&await c.lib.set({lib:[{renderer_src:t.name,hydrator_src:t.name,editor_src:t.name,name:t.name}],run_from:t.run_from,lazy_lib:t.lazy_lib}),e=c.lib.l[`${n}`],e},get_all:async t=>c.lib.l},path:{set:t=>{let e="",n="";const r=t.src.split("/");if(t.src.indexOf("://localhost")!==-1||t.src.indexOf("://127.0.0.1")!==-1||(n="/dist"),r.indexOf(t.type)!==-1)for(const[a,s]of r.entries()){let d=a==0?"":"/";if(e+=`${d}${s}`,s==t.type)return`${e}${n}${t.name}`}else for(const[a,s]of r.entries()){let d=a==0?"":"/";if(e+=`${d}${s}`,s=="src")return`${e}${n}${t.name}`}return`${e}${n}${t.name}`}}};const p=h(),k=h(),E=p.on,O=p.emit,B=k.emit,R=k.on,I=async t=>{const e=await g();return await c.lib.set({lib:t.lib,run_from:"renderer",lazy_lib:t.lazy_lib}),{set:async n=>{console.log("--renderer [set]");const r=new $;r.start();let a=n.data?.value?.l||n.data.l,s={r:"",style:"",head:"",benchmark:null};return await(async()=>{for(const i of a){const u=await await c.lib.get({name:i.type,run_from:"renderer",lazy_lib:t.lazy_lib}),l=await(await u.lib.index({f:{name:_=>e.f.name({id:i.id,name:_}),get_lib:async _=>await await c.lib.get({name:_.name,run_from:_.run_from,lazy_lib:t.lazy_lib}),set_theme:async _=>await(await x()).set(_),path:_=>c.path.set({src:u.src,type:i.type,name:_}),uuid:()=>y().set(),wait_until:w}})).set({data:{curr:i}});s.r+=l?.r||"",s.style+=l?.style||"",s.head+=l?.head||""}})(),r.stop(),s.benchmark=r.result(),s}}},P=async t=>{const e=await g();return await c.lib.set({lib:t.lib,run_from:"hydrator",lazy_lib:t.lazy_lib}),{set:async n=>{console.log("--hydrator [set]");const r=new $;r.start();let a={r:"",style:""},s={style_id:`${y().set()}_stl`},d=n.data?.value?.l||n.data.l;const i=async()=>{for(const u of d){const m=await await c.lib.get({name:u.type,run_from:"hydrator",lazy_lib:t.lazy_lib}),l=m.lib,_=h(),z=_.on,b=await(await l.index({my:{},f:{name:o=>e.f.name({id:u.id,name:o}),get_lib:async o=>await await c.lib.get({name:o.name,run_from:o.run_from,lazy_lib:t.lazy_lib}),set_theme:async o=>await(await x()).set(o),path:o=>c.path.set({src:m.src,type:u.type,name:o}),uuid:()=>y().set(),wait_until:w,call:B,listen:z,new_emitter:()=>h()}})).set({data:{curr:u}});E("msg",async o=>{try{if(Object.keys(o.where||{}).length==0){await _.emit("msg",o);return}}catch{}try{if(u?.[o.where?.key||""]==o.where?.value){await _.emit("msg",o);return}}catch{}}),a.style+=b.style}};await w(()=>document.readyState==="complete"||typeof window<"u",50),await i();try{(u=>{const m=document.getElementById(`${s.style_id}`);m&&m.remove();const l=document.createElement("style");l.id=`${s.style_id}`,l.innerHTML=`${a.style}`,u.appendChild(l)})(document.head)}catch(u){console.log(`${u}, Failed to set style..`)}return r.stop(),{benchmark:r.result()}}}};f.ce_call=O,f.ce_hydrator=P,f.ce_listen=R,f.ce_renderer=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED