content-engine-lib 1.0.1 → 1.0.2

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