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