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