content-engine-lib 1.0.4 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- import { editor_p_TYP, hydrator_p_TYP, renderer_p_TYP } from './u/types';
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;
@@ -9,6 +9,8 @@ declare const call_0: <K extends "msg">(event: K, ...args: Parameters<{
9
9
  key: string;
10
10
  value: string;
11
11
  };
12
+ $d?: any;
13
+ el?: any;
12
14
  }) => Promise<void>;
13
15
  }[K]>) => Promise<void>;
14
16
  declare const listen_1: <K extends "msg">(event: K, fn: {
@@ -21,6 +23,8 @@ declare const listen_1: <K extends "msg">(event: K, fn: {
21
23
  key: string;
22
24
  value: string;
23
25
  };
26
+ $d?: any;
27
+ el?: any;
24
28
  }) => Promise<void>;
25
29
  }[K]) => () => void;
26
30
  declare const renderer: (_p: renderer_p_TYP) => Promise<{
@@ -28,10 +32,11 @@ declare const renderer: (_p: renderer_p_TYP) => Promise<{
28
32
  data: {
29
33
  l: any[];
30
34
  } | any;
31
- }, _$cb?: {}) => Promise<{
35
+ }) => Promise<{
32
36
  r: string;
33
37
  style: string;
34
38
  head: string;
39
+ benchmark: any;
35
40
  }>;
36
41
  }>;
37
42
  declare const hydrator: (_p: hydrator_p_TYP) => Promise<{
@@ -39,21 +44,10 @@ declare const hydrator: (_p: hydrator_p_TYP) => Promise<{
39
44
  data: {
40
45
  l: any[];
41
46
  } | any;
42
- }, _$cb?: {}) => Promise<{
43
- r: string;
44
- style: string;
45
- }>;
46
- }>;
47
- declare const editor: (_p: editor_p_TYP) => Promise<{
48
- set: (_$p: {
49
- data: {
50
- l: any[];
51
- };
52
- }, _$cb?: {
53
- change: (_v: any) => any;
54
47
  }) => Promise<{
55
- r: string;
56
- style: string;
48
+ benchmark: {
49
+ time_taken_ms: string;
50
+ };
57
51
  }>;
58
52
  }>;
59
- export { renderer as ce_renderer, hydrator as ce_hydrator, editor as ce_editor, call_0 as ce_call, listen_1 as ce_listen, };
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 g = () => ({
1
+ const y = () => ({
2
2
  set: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
3
3
  const e = Math.random() * 16 | 0;
4
4
  return (t == "x" ? e : e & 3 | 8).toString(16);
5
5
  })
6
- }), h = async () => ({
6
+ }), x = async () => ({
7
7
  f: {
8
8
  name: (t) => `${t.name}${t.id}`
9
9
  }
10
- }), w = async () => ({
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 e = t.name, r = document.getElementById(t.el_id);
17
- if (!r)
16
+ const e = t.name, n = document.getElementById(t.el_id);
17
+ if (!n)
18
18
  throw new Error("[el_id] is invalid");
19
- ((a) => {
20
- const n = (o) => {
21
- ((i) => {
22
- const s = i.getAttribute("data-ce");
23
- if (!s)
19
+ ((r) => {
20
+ const a = (s) => {
21
+ ((d) => {
22
+ const i = d.getAttribute("data-ce");
23
+ if (!i)
24
24
  return;
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);
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 b of f)
34
- i.classList.remove(b);
33
+ for (const o of f)
34
+ d.classList.remove(o);
35
35
  }
36
- })(o);
36
+ })(s);
37
37
  };
38
- for (const o of a.getElementsByTagName("*"))
39
- n(o);
40
- n(a);
41
- })(r);
38
+ for (const s of r.getElementsByTagName("*"))
39
+ a(s);
40
+ a(r);
41
+ })(n);
42
42
  } catch (e) {
43
- const r = `err: [theme] ${e}`;
44
- throw console.log(r), r;
43
+ const n = `err: [theme] ${e}`;
44
+ throw console.log(n), n;
45
45
  }
46
46
  }
47
47
  });
48
- function p(t, e = 1e3) {
49
- let r = {
48
+ function b(t, e = 1e3) {
49
+ let n = {
50
50
  cnt: 0
51
51
  };
52
- return new Promise((a) => {
53
- const n = () => {
54
- console.log(`[setInterval] is running.. [count=${r.cnt}]`);
52
+ return new Promise((r) => {
53
+ const a = () => {
54
+ console.log(`[setInterval] is running.. [count=${n.cnt}]`);
55
55
  try {
56
- t() && (clearInterval(o), a());
56
+ t() && (clearInterval(s), r());
57
57
  } catch {
58
58
  console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${e}]`);
59
59
  }
60
- r.cnt += 1;
61
- }, o = setInterval(() => {
62
- n();
60
+ n.cnt += 1;
61
+ }, s = setInterval(() => {
62
+ a();
63
63
  }, e);
64
- n();
64
+ a();
65
65
  });
66
66
  }
67
- let z = class {
67
+ let E = class {
68
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);
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 (e, ...r) => {
75
- for (const a of this.listeners[e] ?? [])
76
- await a(...r);
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 (e, ...r) => {
79
+ emitParallel = async (e, ...n) => {
80
80
  await Promise.all(
81
- (this.listeners[e] ?? []).map((a) => a(...r))
81
+ (this.listeners[e] ?? []).map((r) => r(...n))
82
82
  );
83
83
  };
84
84
  //Error-safe emit
85
- emitSafe = async (e, ...r) => {
86
- for (const a of this.listeners[e] ?? [])
85
+ emitSafe = async (e, ...n) => {
86
+ for (const r of this.listeners[e] ?? [])
87
87
  try {
88
- await a(...r);
89
- } catch (n) {
88
+ await r(...n);
89
+ } catch (a) {
90
90
  this.listeners.error?.forEach(
91
- (o) => o(n)
91
+ (s) => s(a)
92
92
  );
93
93
  }
94
94
  };
95
95
  };
96
- const u = () => new z();
97
- console.log("content_engine_lib");
98
- let y = {
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
+ }
125
+ console.log("content-engine-lib");
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 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];
108
- const d = `${t.run_from}_src`;
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;
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=${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("../")) {
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("../")) {
117
145
  const l = await import(
118
146
  /* @vite-ignore */
119
147
  /* webpackIgnore: true */
120
- `${s}`
148
+ `${i}`
121
149
  );
122
- y.lib.l[`${o}`] = {
150
+ c.lib.l[`${s}`] = {
123
151
  lib: l,
124
- src: s
152
+ src: i
125
153
  };
126
154
  }
127
- if (s.startsWith("http://") || s.startsWith("https://")) {
155
+ if (i.startsWith("http://") || i.startsWith("https://")) {
128
156
  const l = await import(
129
157
  /* @vite-ignore */
130
158
  /* webpackIgnore: true */
131
- `${s}`
159
+ `${i}`
132
160
  );
133
- y.lib.l[`${o}`] = {
161
+ c.lib.l[`${s}`] = {
134
162
  lib: l,
135
- src: s
163
+ src: i
136
164
  };
137
165
  }
138
166
  }
139
167
  }
140
- console.log(await y.lib.get_all({}));
168
+ console.log(await c.lib.get_all({}));
141
169
  },
142
170
  get: async (t) => {
143
171
  let e = null;
144
- const r = `${t.name}:${t.run_from}`;
145
- return y.lib.l.hasOwnProperty(`${r}`) == !1 && await y.lib.set({
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,164 +181,155 @@ let y = {
153
181
  ],
154
182
  run_from: t.run_from,
155
183
  lazy_lib: t.lazy_lib
156
- }), e = y.lib.l[`${r}`], e;
184
+ }), e = c.lib.l[`${n}`], e;
157
185
  },
158
- get_all: async (t) => y.lib.l
186
+ get_all: async (t) => c.lib.l
159
187
  },
160
188
  path: {
161
189
  set: (t) => {
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}`;
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 [n, o] of a.entries()) {
172
- let i = n == 0 ? "" : "/";
173
- if (e += `${i}${o}`, o == "src")
174
- return `${e}${r}${t.name}`;
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 `${e}${r}${t.name}`;
204
+ return `${e}${n}${t.name}`;
177
205
  }
178
206
  }
179
207
  };
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) => {
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
- let n = {
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 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({
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: (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 })
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
- })).set({
201
- data: {
202
- curr: i
236
+ })).set(
237
+ {
238
+ data: {
239
+ curr: i
240
+ }
203
241
  }
204
- }, a);
205
- n.r += c?.r || "", n.style += c?.style || "", n.head += c?.head || "";
242
+ /*_$cb*/
243
+ );
244
+ s.r += l?.r || "", s.style += l?.style || "", s.head += l?.head || "";
206
245
  }
207
- })(), n;
246
+ })(), r.stop(), s.benchmark = r.result(), s;
208
247
  }
209
248
  };
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) => {
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) => {
214
253
  console.log("--hydrator [set]");
215
- let n = {
254
+ const r = new $();
255
+ r.start();
256
+ let a = {
216
257
  r: "",
217
258
  style: ""
218
- };
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({
259
+ }, s = {
260
+ style_id: `${y().set()}_stl`
261
+ }, d = n.data?.value?.l || n.data.l;
262
+ const i = async () => {
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({
222
265
  /**@my module can use it to set custom variables. */
223
266
  my: {},
224
267
  //NOTE: We cannot add or use any variable of this object, It's reserved for module.
225
268
  f: {
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: _ }),
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 }),
230
273
  //set..
231
- call: E,
232
- listen: l,
274
+ uuid: () => y().set(),
275
+ wait_until: b,
233
276
  //set..
234
- new_emitter: () => u()
277
+ call: O,
278
+ listen: w,
279
+ //set..
280
+ new_emitter: () => h()
235
281
  }
236
- })).set({
237
- data: {
238
- curr: i
282
+ })).set(
283
+ {
284
+ data: {
285
+ curr: _
286
+ }
239
287
  }
240
- }, a);
241
- k("msg", async (_) => {
288
+ /*_$cb*/
289
+ );
290
+ T("msg", async (o) => {
242
291
  try {
243
- if (Object.keys(_.where || {}).length == 0) {
244
- await c.emit("msg", _);
292
+ if (Object.keys(o.where || {}).length == 0) {
293
+ await u.emit("msg", o);
245
294
  return;
246
295
  }
247
296
  } catch {
248
297
  }
249
298
  try {
250
- if (i?.[_.where?.key || ""] == _.where?.value) {
251
- await c.emit("msg", _);
299
+ if (_?.[o.where?.key || ""] == o.where?.value) {
300
+ await u.emit("msg", o);
252
301
  return;
253
302
  }
254
303
  } catch {
255
304
  }
256
- }), n.style += m.style;
305
+ }), a.style += f.style;
257
306
  }
258
307
  };
259
- return await p(
308
+ await b(
260
309
  () => document.readyState === "complete" || typeof window < "u",
261
310
  50
262
- ), await o(), n;
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
+ };
263
327
  }
264
328
  };
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) => {
267
- console.log("--editor [set]");
268
- let a = {
269
- data: {
270
- l: [
271
- {
272
- id: g().set(),
273
- type: "editor",
274
- data: {
275
- l: []
276
- }
277
- }
278
- ]
279
- }
280
- }, n = {
281
- r: "",
282
- style: ""
283
- };
284
- const o = O, i = I, s = await o({
285
- lib: t.lib,
286
- lazy_lib: t.lazy_lib
287
- }), d = await i({
288
- lib: t.lib,
289
- lazy_lib: t.lazy_lib
290
- }), c = await s.set({
291
- data: a.data
292
- });
293
- return (async () => {
294
- const l = await d.set({
295
- data: a.data
296
- }, {
297
- change: (m) => {
298
- r?.change(m);
299
- }
300
- });
301
- ((m) => {
302
- const _ = document.createElement("style");
303
- _.innerHTML = `${l.style}`, m.appendChild(_);
304
- })(document.head);
305
- })(), n.r = c.r, n.style = `
306
- ${c.style}
307
- `, n;
308
- }
309
- });
329
+ };
310
330
  export {
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
331
+ R as ce_call,
332
+ W as ce_hydrator,
333
+ I as ce_listen,
334
+ P as ce_renderer
316
335
  };
package/dist/index.umd.js CHANGED
@@ -1,3 +1 @@
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
- ${c.style}
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"})}));
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"})}));
@@ -0,0 +1,12 @@
1
+ declare class Benchmark {
2
+ private startTime;
3
+ private endTime;
4
+ private isRunning;
5
+ constructor();
6
+ start(): void;
7
+ stop(): void;
8
+ result(): {
9
+ time_taken_ms: string;
10
+ };
11
+ }
12
+ export { Benchmark };
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from '../emitter';
2
2
  declare const index: () => Emitter<{
3
3
  msg: (payload: {
4
- /**eg=> `on:change`, `on:add` etc. */
4
+ /**eg=> `change`, `add` etc. */
5
5
  type: string;
6
6
  /**can pass existing `_p` variable. */
7
7
  _p?: any;
@@ -16,6 +16,10 @@ declare const index: () => Emitter<{
16
16
  /**eg=> xx776-6564-6547 (Module-Id), text (Module-Type) */
17
17
  value: string;
18
18
  };
19
+ /**can be used to pass eg=> `_$p[`data`].curr[`data`],`, `_$p[`data`].curr` */
20
+ $d?: any;
21
+ /**can be used to pass eg=> `HTMLElement` */
22
+ el?: any;
19
23
  }) => Promise<void>;
20
24
  }>;
21
25
  export { index as new_emitter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "content-engine-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A lightweight library for content engine functionality",
5
5
  "keywords": ["content", "engine", "library", "content-engine"],
6
6
  "author": "Coreutility",
@@ -1,8 +0,0 @@
1
- import { _$cb_TYP, _$p_TYP, _p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb: _$cb_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- }>;
7
- }>;
8
- export { index };
@@ -1,19 +0,0 @@
1
- declare const index: (_p: {
2
- f: {
3
- name: (v: string) => string;
4
- };
5
- }) => Promise<{
6
- set: (_$p: {
7
- data: {
8
- curr: {
9
- "id": "";
10
- "type": "editor";
11
- "data": string;
12
- };
13
- };
14
- }) => Promise<{
15
- r: string;
16
- style: string;
17
- }>;
18
- }>;
19
- export { index };
@@ -1,8 +0,0 @@
1
- import { _$cb_TYP, _$p_TYP, _p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb: _$cb_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- }>;
7
- }>;
8
- export { index };
@@ -1,19 +0,0 @@
1
- declare const index: (_p: {
2
- f: {
3
- name: (v: string) => string;
4
- };
5
- }) => Promise<{
6
- set: (_$p: {
7
- data: {
8
- curr: {
9
- "id": "";
10
- "type": "editor";
11
- "data": string;
12
- };
13
- };
14
- }) => Promise<{
15
- r: string;
16
- style: string;
17
- }>;
18
- }>;
19
- export { index };
@@ -1,13 +0,0 @@
1
- declare const index: () => Promise<{
2
- set: (_$p: {}) => Promise<{
3
- data: {
4
- l: {
5
- type: string;
6
- title: string;
7
- desc: string;
8
- icon: string;
9
- }[];
10
- };
11
- }>;
12
- }>;
13
- export { index as component_index };
@@ -1,35 +0,0 @@
1
- type _p_TYP = {
2
- f: {
3
- name: (v: string) => string;
4
- get_lib: (v: {
5
- name: string;
6
- run_from: any;
7
- }) => any;
8
- set_theme: (v: {
9
- name: string;
10
- el_id: string;
11
- }) => any;
12
- path: (v: string) => string;
13
- };
14
- };
15
- type _$p_TYP = {
16
- data: {
17
- curr: {
18
- "id": "";
19
- "type": "editor";
20
- "data": {
21
- "l": any[];
22
- };
23
- };
24
- };
25
- };
26
- type _$cb_TYP = {
27
- change: (_v: {
28
- _$p: _$p_TYP;
29
- }) => any;
30
- add: (_v: {
31
- $d: _$p_TYP[`data`][`curr`][`data`];
32
- el: HTMLElement;
33
- }) => any;
34
- };
35
- export type { _p_TYP, _$p_TYP, _$cb_TYP };
@@ -1,7 +0,0 @@
1
- import { _p_TYP, _$cb_TYP, _$p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb?: _$cb_TYP) => Promise<{
4
- r: string;
5
- }>;
6
- }>;
7
- export { index as editor };
@@ -1,11 +0,0 @@
1
- import { _$cb_TYP, _$p_TYP, _p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb: _$cb_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- evt: {
7
- change: () => void;
8
- };
9
- }>;
10
- }>;
11
- export { index, index as hydrator };
@@ -1,8 +0,0 @@
1
- import { _$p_TYP, _p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- }>;
7
- }>;
8
- export { index, index as renderer };
@@ -1,45 +0,0 @@
1
- type _p_TYP = {
2
- f: {
3
- name: (v: string) => string;
4
- get_lib: (v: {
5
- name: string;
6
- run_from: any;
7
- }) => any;
8
- set_theme: (v: {
9
- name: string;
10
- el_id: string;
11
- }) => any;
12
- path: (v: string) => string;
13
- };
14
- };
15
- type _$p_TYP = {
16
- data: {
17
- curr: {
18
- "id": "";
19
- "type": "table";
20
- "data": {
21
- sortBy: string;
22
- sortDirection: string;
23
- columns: {
24
- key: string;
25
- title: string;
26
- type: 'number' | 'string';
27
- sortable: boolean;
28
- }[];
29
- rows: {
30
- id: string;
31
- }[];
32
- };
33
- };
34
- };
35
- };
36
- type _$cb_TYP = {
37
- change: (_v: {
38
- _$p: _$p_TYP;
39
- }) => any;
40
- add: (_v: {
41
- $d: _$p_TYP[`data`][`curr`][`data`][`columns`][`0`] | _$p_TYP[`data`][`curr`][`data`][`rows`][`0`] | any;
42
- el: HTMLElement;
43
- }) => any;
44
- };
45
- export type { _p_TYP, _$p_TYP, _$cb_TYP };
@@ -1,7 +0,0 @@
1
- import { _p_TYP, _$cb_TYP, _$p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb?: _$cb_TYP) => Promise<{
4
- r: string;
5
- }>;
6
- }>;
7
- export { index as editor };
@@ -1,11 +0,0 @@
1
- import { _p_TYP, _$cb_TYP, _$p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb?: _$cb_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- evt: {
7
- change: () => void;
8
- };
9
- }>;
10
- }>;
11
- export { index, index as hydrator };
@@ -1,8 +0,0 @@
1
- import { _p_TYP, _$cb_TYP, _$p_TYP } from '../shared/types';
2
- declare const index: (_p: _p_TYP) => Promise<{
3
- set: (_$p: _$p_TYP, _$cb?: _$cb_TYP) => Promise<{
4
- r: string;
5
- style: string;
6
- }>;
7
- }>;
8
- export { index, index as renderer };
@@ -1,35 +0,0 @@
1
- type _p_TYP = {
2
- f: {
3
- name: (v: string) => string;
4
- get_lib: (v: {
5
- name: string;
6
- run_from: any;
7
- }) => any;
8
- set_theme: (v: {
9
- name: string;
10
- el_id: string;
11
- }) => any;
12
- path: (v: string) => string;
13
- };
14
- };
15
- type _$p_TYP = {
16
- data: {
17
- curr: {
18
- "id": "";
19
- "type": "text";
20
- "data": {
21
- "data": string;
22
- };
23
- };
24
- };
25
- };
26
- type _$cb_TYP = {
27
- change: (_v: {
28
- _$p: _$p_TYP;
29
- }) => any;
30
- add: (_v: {
31
- $d: _$p_TYP[`data`][`curr`][`data`];
32
- el: HTMLElement;
33
- }) => any;
34
- };
35
- export type { _p_TYP, _$p_TYP, _$cb_TYP };