content-engine-lib 1.0.0 → 1.0.2
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 +181 -129
- package/dist/index.umd.js +2 -2
- package/dist/u/emitter/index.d.ts +12 -0
- package/dist/u/get_emitter/index.d.ts +21 -0
- package/dist/u/types/index.d.ts +1 -1
- package/package.json +3 -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 u of
|
|
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, y = l.v.split(" ");
|
|
29
|
+
if (m == `t-${e}-class`)
|
|
30
|
+
for (const u of y)
|
|
31
31
|
i.classList.add(u);
|
|
32
32
|
else
|
|
33
|
-
for (const u of
|
|
33
|
+
for (const u of y)
|
|
34
34
|
i.classList.remove(u);
|
|
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 b = () => new z();
|
|
67
97
|
console.log("content_engine_lib");
|
|
68
|
-
let
|
|
98
|
+
let _ = {
|
|
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}`), _.lib.l.hasOwnProperty(`${o}`) == !1) {
|
|
111
|
+
if (/^[a-zA-Z0-9]/.test(s) && s.includes("/") == !1 && _.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
|
+
_.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
|
+
_.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 _.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 _.lib.l.hasOwnProperty(`${r}`) == !1 && await _.lib.set({
|
|
116
146
|
lib: [
|
|
117
147
|
{
|
|
118
148
|
renderer_src: t.name,
|
|
@@ -123,100 +153,120 @@ let c = {
|
|
|
123
153
|
],
|
|
124
154
|
run_from: t.run_from,
|
|
125
155
|
lazy_lib: t.lazy_lib
|
|
126
|
-
}),
|
|
156
|
+
}), e = _.lib.l[`${r}`], e;
|
|
127
157
|
},
|
|
128
|
-
get_all: async (t) =>
|
|
158
|
+
get_all: async (t) => _.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 = b(), $ = b(), k = x.on, W = x.emit, E = $.emit, C = $.on, O = async (t) => {
|
|
181
|
+
const e = await h();
|
|
182
|
+
return await _.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 _.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 _.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) => _.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 _.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 _.lib.get({ name: i.type, run_from: "hydrator", lazy_lib: t.lazy_lib }), d = s.lib, c = b(), l = c.on, m = b(), f = await (await d.index({
|
|
192
222
|
f: {
|
|
193
|
-
name: (
|
|
194
|
-
get_lib: async (
|
|
195
|
-
set_theme: async (
|
|
196
|
-
path: (
|
|
223
|
+
name: (y) => e.f.name({ id: i.id, name: y }),
|
|
224
|
+
get_lib: async (y) => await await _.lib.get({ name: y.name, run_from: y.run_from, lazy_lib: t.lazy_lib }),
|
|
225
|
+
set_theme: async (y) => await (await w()).set(y),
|
|
226
|
+
path: (y) => _.path.set({ src: s.src, type: i.type, name: y }),
|
|
227
|
+
//set..
|
|
228
|
+
call: E,
|
|
229
|
+
listen: l,
|
|
230
|
+
//set..
|
|
231
|
+
emitter: m
|
|
197
232
|
}
|
|
198
233
|
})).set({
|
|
199
234
|
data: {
|
|
200
235
|
curr: i
|
|
201
236
|
}
|
|
202
|
-
},
|
|
203
|
-
|
|
237
|
+
}, a);
|
|
238
|
+
k("msg", async (y) => {
|
|
239
|
+
try {
|
|
240
|
+
if (Object.keys(y.where || {}).length == 0) {
|
|
241
|
+
await c.emit("msg", y);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
if (i?.[y.where?.key || ""] == y.where?.value) {
|
|
248
|
+
await c.emit("msg", y);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}), n.style += f.style;
|
|
204
254
|
}
|
|
205
255
|
};
|
|
206
|
-
return await
|
|
256
|
+
return await p(
|
|
207
257
|
() => document.readyState === "complete" || typeof window < "u",
|
|
208
258
|
50
|
|
209
|
-
), await
|
|
259
|
+
), await o(), n;
|
|
210
260
|
}
|
|
211
261
|
};
|
|
212
|
-
},
|
|
213
|
-
set: async (
|
|
262
|
+
}, S = async (t) => (await h(), await _.lib.set({ lib: t.lib, run_from: "editor", lazy_lib: t.lazy_lib }), {
|
|
263
|
+
set: async (e, r) => {
|
|
214
264
|
console.log("--editor [set]");
|
|
215
|
-
let
|
|
265
|
+
let a = {
|
|
216
266
|
data: {
|
|
217
267
|
l: [
|
|
218
268
|
{
|
|
219
|
-
id:
|
|
269
|
+
id: g().set(),
|
|
220
270
|
type: "editor",
|
|
221
271
|
data: {
|
|
222
272
|
l: []
|
|
@@ -224,38 +274,40 @@ const $ = async (t) => {
|
|
|
224
274
|
}
|
|
225
275
|
]
|
|
226
276
|
}
|
|
227
|
-
},
|
|
277
|
+
}, n = {
|
|
228
278
|
r: "",
|
|
229
279
|
style: ""
|
|
230
280
|
};
|
|
231
|
-
const
|
|
281
|
+
const o = O, i = I, s = await o({
|
|
232
282
|
lib: t.lib,
|
|
233
283
|
lazy_lib: t.lazy_lib
|
|
234
284
|
}), d = await i({
|
|
235
285
|
lib: t.lib,
|
|
236
286
|
lazy_lib: t.lazy_lib
|
|
237
|
-
}),
|
|
238
|
-
data:
|
|
287
|
+
}), c = await s.set({
|
|
288
|
+
data: a.data
|
|
239
289
|
});
|
|
240
290
|
return (async () => {
|
|
241
|
-
const
|
|
242
|
-
data:
|
|
291
|
+
const l = await d.set({
|
|
292
|
+
data: a.data
|
|
243
293
|
}, {
|
|
244
|
-
change: (
|
|
245
|
-
|
|
294
|
+
change: (m) => {
|
|
295
|
+
r?.change(m);
|
|
246
296
|
}
|
|
247
297
|
});
|
|
248
|
-
((
|
|
249
|
-
const
|
|
250
|
-
|
|
298
|
+
((m) => {
|
|
299
|
+
const f = document.createElement("style");
|
|
300
|
+
f.innerHTML = `${l.style}`, m.appendChild(f);
|
|
251
301
|
})(document.head);
|
|
252
|
-
})(),
|
|
253
|
-
${
|
|
254
|
-
`,
|
|
302
|
+
})(), n.r = c.r, n.style = `
|
|
303
|
+
${c.style}
|
|
304
|
+
`, n;
|
|
255
305
|
}
|
|
256
306
|
});
|
|
257
307
|
export {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
308
|
+
W as ce_call,
|
|
309
|
+
S as ce_editor,
|
|
310
|
+
I as ce_hydrator,
|
|
311
|
+
C as ce_listen,
|
|
312
|
+
O as ce_renderer
|
|
261
313
|
};
|
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)})}),x=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,d=l.v.split(" ");if(u==`t-${t}-class`)for(const h of d)s.classList.add(h);else for(const h of d)s.classList.remove(h)}})(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 w=()=>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 $=w(),p=w(),P=$.on,S=$.emit,T=p.emit,I=p.on,z=async e=>{const t=await x();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 x();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=w(),l=c.on,u=w(),b=await(await f.index({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,emitter:u}})).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+=b.style}};return await O(()=>document.readyState==="complete"||typeof window<"u",50),await o(),r}}},W=async e=>(await x(),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 b=document.createElement("style");b.innerHTML=`${l.style}`,u.appendChild(b)})(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 get_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.2",
|
|
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",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
27
28
|
"import": "./dist/index.es.js",
|
|
28
29
|
"require": "./dist/index.umd.js"
|
|
29
30
|
}
|