content-engine-lib 1.0.6 → 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 CHANGED
@@ -32,8 +32,11 @@ 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: string;
39
+ r: any;
37
40
  style: string;
38
41
  head: string;
39
42
  benchmark: any;
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const y = () => ({
2
2
  set: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
3
- const e = Math.random() * 16 | 0;
4
- return (t == "x" ? e : e & 3 | 8).toString(16);
3
+ const r = Math.random() * 16 | 0;
4
+ return (t == "x" ? r : r & 3 | 8).toString(16);
5
5
  })
6
6
  }), x = async () => ({
7
7
  f: {
@@ -13,82 +13,82 @@ const y = () => ({
13
13
  try {
14
14
  if (!t.el_id)
15
15
  throw new Error("[el_id] is required");
16
- const e = t.name, n = document.getElementById(t.el_id);
17
- if (!n)
16
+ const r = t.name, e = document.getElementById(t.el_id);
17
+ if (!e)
18
18
  throw new Error("[el_id] is invalid");
19
- ((r) => {
20
- const a = (s) => {
21
- ((d) => {
22
- const i = d.getAttribute("data-ce");
19
+ ((s) => {
20
+ const a = (n) => {
21
+ ((f) => {
22
+ const i = f.getAttribute("data-ce");
23
23
  if (!i)
24
24
  return;
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);
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 o of f)
34
- d.classList.remove(o);
33
+ for (const o of d)
34
+ f.classList.remove(o);
35
35
  }
36
- })(s);
36
+ })(n);
37
37
  };
38
- for (const s of r.getElementsByTagName("*"))
39
- a(s);
40
- a(r);
41
- })(n);
42
- } catch (e) {
43
- const n = `err: [theme] ${e}`;
44
- throw console.log(n), n;
38
+ for (const n of s.getElementsByTagName("*"))
39
+ a(n);
40
+ a(s);
41
+ })(e);
42
+ } catch (r) {
43
+ const e = `err: [theme] ${r}`;
44
+ throw console.log(e), e;
45
45
  }
46
46
  }
47
47
  });
48
- function b(t, e = 1e3) {
49
- let n = {
48
+ function b(t, r = 1e3) {
49
+ let e = {
50
50
  cnt: 0
51
51
  };
52
- return new Promise((r) => {
52
+ return new Promise((s) => {
53
53
  const a = () => {
54
- console.log(`[setInterval] is running.. [count=${n.cnt}]`);
54
+ console.log(`[setInterval] is running.. [count=${e.cnt}]`);
55
55
  try {
56
- t() && (clearInterval(s), r());
56
+ t() && (clearInterval(n), s());
57
57
  } catch {
58
- console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${e}]`);
58
+ console.log(`warn: [wait_until] ignoring the exception in setInterval and will check again after [interval=${r}]`);
59
59
  }
60
- n.cnt += 1;
61
- }, s = setInterval(() => {
60
+ e.cnt += 1;
61
+ }, n = setInterval(() => {
62
62
  a();
63
- }, e);
63
+ }, r);
64
64
  a();
65
65
  });
66
66
  }
67
67
  let E = class {
68
68
  listeners = {};
69
- on = (e, n) => ((this.listeners[e] ||= []).push(n), () => this.off(e, n));
70
- off = (e, n) => {
71
- this.listeners[e] = this.listeners[e]?.filter((r) => r !== n);
69
+ on = (r, e) => ((this.listeners[r] ||= []).push(e), () => this.off(r, e));
70
+ off = (r, e) => {
71
+ this.listeners[r] = this.listeners[r]?.filter((s) => s !== e);
72
72
  };
73
73
  /** Sequential execution (await each listener) */
74
- emit = async (e, ...n) => {
75
- for (const r of this.listeners[e] ?? [])
76
- await r(...n);
74
+ emit = async (r, ...e) => {
75
+ for (const s of this.listeners[r] ?? [])
76
+ await s(...e);
77
77
  };
78
78
  /** Parallel execution (await all listeners) */
79
- emitParallel = async (e, ...n) => {
79
+ emitParallel = async (r, ...e) => {
80
80
  await Promise.all(
81
- (this.listeners[e] ?? []).map((r) => r(...n))
81
+ (this.listeners[r] ?? []).map((s) => s(...e))
82
82
  );
83
83
  };
84
84
  //Error-safe emit
85
- emitSafe = async (e, ...n) => {
86
- for (const r of this.listeners[e] ?? [])
85
+ emitSafe = async (r, ...e) => {
86
+ for (const s of this.listeners[r] ?? [])
87
87
  try {
88
- await r(...n);
88
+ await s(...e);
89
89
  } catch (a) {
90
90
  this.listeners.error?.forEach(
91
- (s) => s(a)
91
+ (n) => n(a)
92
92
  );
93
93
  }
94
94
  };
@@ -129,16 +129,16 @@ let c = {
129
129
  // <any>[], // [`text`,`table`,`editor`]
130
130
  l: {},
131
131
  set: async (t) => {
132
- const e = t?.lib || [];
133
- for (const [n, r] of e.entries()) {
134
- const a = r, s = `${a.name}:${t.run_from}`, d = `${t.run_from}_src`;
135
- let i = a[d];
136
- const _ = `${t.run_from}_src`;
137
- let m = t?.lazy_lib?.[_] || null;
138
- if (m && (m = m.replace("{*}", `${a.name}`)), console.log(`_lazy_src: ${m}`), console.log(`_src: ${i}`), c.lib.l.hasOwnProperty(`${s}`) == !1) {
132
+ const r = t?.lib || [];
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
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;
140
+ if (u)
141
+ i = u;
142
142
  else
143
143
  throw `[lib-name=${a.name},lib-src=${i}] not allowed or available in in-build mode. Need to use lazy-lib config.`;
144
144
  if (i.startsWith("./") || i.startsWith("../")) {
@@ -147,7 +147,7 @@ let c = {
147
147
  /* webpackIgnore: true */
148
148
  `${i}`
149
149
  );
150
- c.lib.l[`${s}`] = {
150
+ c.lib.l[`${n}`] = {
151
151
  lib: l,
152
152
  src: i
153
153
  };
@@ -158,7 +158,7 @@ let c = {
158
158
  /* webpackIgnore: true */
159
159
  `${i}`
160
160
  );
161
- c.lib.l[`${s}`] = {
161
+ c.lib.l[`${n}`] = {
162
162
  lib: l,
163
163
  src: i
164
164
  };
@@ -168,9 +168,9 @@ let c = {
168
168
  console.log(await c.lib.get_all({}));
169
169
  },
170
170
  get: async (t) => {
171
- let e = null;
172
- const n = `${t.name}:${t.run_from}`;
173
- return c.lib.l.hasOwnProperty(`${n}`) == !1 && await c.lib.set({
171
+ let r = null;
172
+ const e = `${t.name}:${t.run_from}`;
173
+ return c.lib.l.hasOwnProperty(`${e}`) == !1 && await c.lib.set({
174
174
  lib: [
175
175
  {
176
176
  renderer_src: t.name,
@@ -181,39 +181,40 @@ let c = {
181
181
  ],
182
182
  run_from: t.run_from,
183
183
  lazy_lib: t.lazy_lib
184
- }), e = c.lib.l[`${n}`], e;
184
+ }), r = c.lib.l[`${e}`], r;
185
185
  },
186
186
  get_all: async (t) => c.lib.l
187
187
  },
188
188
  path: {
189
189
  set: (t) => {
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}`;
190
+ let r = "", e = "";
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)
196
+ return `${r}${e}${t.name}`;
197
197
  }
198
198
  else
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}`;
199
+ for (const [a, n] of s.entries()) {
200
+ let f = a == 0 ? "" : "/";
201
+ if (r += `${f}${n}`, n == "src")
202
+ return `${r}${e}${t.name}`;
203
203
  }
204
- return `${e}${n}${t.name}`;
204
+ return `${r}${e}${t.name}`;
205
205
  }
206
206
  }
207
207
  };
208
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();
209
+ const r = await x();
210
210
  return await c.lib.set({ lib: t.lib, run_from: "renderer", lazy_lib: t.lazy_lib }), {
211
- set: async (n) => {
212
- console.log("--renderer [set]");
213
- const r = new $();
214
- r.start();
215
- let a = n.data?.value?.l || n.data.l, s = {
216
- r: "",
211
+ set: async (e) => {
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
+ //``
217
218
  style: "",
218
219
  head: "",
219
220
  // `<test>head-1</test>`
@@ -221,14 +222,14 @@ const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t
221
222
  //total:_l.length,
222
223
  benchmark: null
223
224
  };
224
- return await (async () => {
225
+ return e.return.r == "full" ? n.r = "" : n.r = [], await (async () => {
225
226
  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({
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({
227
228
  f: {
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 }),
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: _ }),
232
233
  //set..
233
234
  uuid: () => y().set(),
234
235
  wait_until: b
@@ -241,35 +242,35 @@ const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t
241
242
  }
242
243
  /*_$cb*/
243
244
  );
244
- s.r += l?.r || "", s.style += l?.style || "", s.head += l?.head || "";
245
+ e?.return?.r == "full" ? n.r += l?.r || "" : n.r.push(l?.r || ""), n.style += l?.style || "", n.head += l?.head || "";
245
246
  }
246
- })(), r.stop(), s.benchmark = r.result(), s;
247
+ })(), s.stop(), n.benchmark = s.result(), n;
247
248
  }
248
249
  };
249
250
  }, W = async (t) => {
250
- const e = await x();
251
+ const r = await x();
251
252
  return await c.lib.set({ lib: t.lib, run_from: "hydrator", lazy_lib: t.lazy_lib }), {
252
- set: async (n) => {
253
+ set: async (e) => {
253
254
  console.log("--hydrator [set]");
254
- const r = new $();
255
- r.start();
255
+ const s = new $();
256
+ s.start();
256
257
  let a = {
257
258
  r: "",
258
259
  style: ""
259
- }, s = {
260
+ }, n = {
260
261
  style_id: `${y().set()}_stl`
261
- }, d = n.data?.value?.l || n.data.l;
262
+ }, f = e.data?.value?.l || e.data.l;
262
263
  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({
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({
265
266
  /**@my module can use it to set custom variables. */
266
267
  my: {},
267
268
  //NOTE: We cannot add or use any variable of this object, It's reserved for module.
268
269
  f: {
269
- name: (o) => e.f.name({ id: _.id, name: o }),
270
+ name: (o) => r.f.name({ id: m.id, name: o }),
270
271
  get_lib: async (o) => await await c.lib.get({ name: o.name, run_from: o.run_from, lazy_lib: t.lazy_lib }),
271
272
  set_theme: async (o) => await (await g()).set(o),
272
- path: (o) => c.path.set({ src: m.src, type: _.type, name: o }),
273
+ path: (o) => c.path.set({ src: u.src, type: m.type, name: o }),
273
274
  //set..
274
275
  uuid: () => y().set(),
275
276
  wait_until: b,
@@ -282,7 +283,7 @@ const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t
282
283
  })).set(
283
284
  {
284
285
  data: {
285
- curr: _
286
+ curr: m
286
287
  }
287
288
  }
288
289
  /*_$cb*/
@@ -290,19 +291,19 @@ const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t
290
291
  T("msg", async (o) => {
291
292
  try {
292
293
  if (Object.keys(o.where || {}).length == 0) {
293
- await u.emit("msg", o);
294
+ await _.emit("msg", o);
294
295
  return;
295
296
  }
296
297
  } catch {
297
298
  }
298
299
  try {
299
- if (_?.[o.where?.key || ""] == o.where?.value) {
300
- await u.emit("msg", o);
300
+ if (m?.[o.where?.key || ""] == o.where?.value) {
301
+ await _.emit("msg", o);
301
302
  return;
302
303
  }
303
304
  } catch {
304
305
  }
305
- }), a.style += f.style;
306
+ }), a.style += d.style;
306
307
  }
307
308
  };
308
309
  await b(
@@ -310,19 +311,19 @@ const p = h(), k = h(), T = p.on, R = p.emit, O = k.emit, I = k.on, P = async (t
310
311
  50
311
312
  ), await i();
312
313
  try {
313
- ((_) => {
314
- const m = document.getElementById(`${s.style_id}`);
315
- m && m.remove();
314
+ ((m) => {
315
+ const u = document.getElementById(`${n.style_id}`);
316
+ u && u.remove();
316
317
  const l = document.createElement("style");
317
- l.id = `${s.style_id}`, l.innerHTML = `${a.style}`, _.appendChild(l);
318
+ l.id = `${n.style_id}`, l.innerHTML = `${a.style}`, m.appendChild(l);
318
319
  })(document.head);
319
- } catch (_) {
320
- console.log(`${_}, Failed to set style..`);
320
+ } catch (m) {
321
+ console.log(`${m}, Failed to set style..`);
321
322
  }
322
- return r.stop(), {
323
+ return s.stop(), {
323
324
  //style_id:_ins.style_id,
324
325
  //total:_l.length,
325
- benchmark: r.result()
326
+ benchmark: s.result()
326
327
  };
327
328
  }
328
329
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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"})}));
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"})}));
@@ -19,5 +19,4 @@ type renderer_p_TYP = {
19
19
  };
20
20
  };
21
21
  type hydrator_p_TYP = renderer_p_TYP;
22
- type editor_p_TYP = renderer_p_TYP;
23
- export type { renderer_p_TYP, hydrator_p_TYP, editor_p_TYP, };
22
+ export type { renderer_p_TYP, hydrator_p_TYP, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "content-engine-lib",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "A lightweight library for content engine functionality",
5
5
  "keywords": ["content", "engine", "library", "content-engine"],
6
6
  "author": "Coreutility",