content-engine-lib 1.0.2 → 1.0.5

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