@chamn/render 0.9.3 → 0.10.1

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.
@@ -0,0 +1,1785 @@
1
+ var Se = Object.defineProperty;
2
+ var ye = (n, e, t) => e in n ? Se(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var p = (n, e, t) => ye(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { capitalize as Ce, isArray as te, isPlainObject as k, isEqual as Ee, merge as Ne } from "lodash-es";
5
+ import N, { Component as be, createElement as ve, useEffect as ne, useRef as re, useMemo as se } from "react";
6
+ import { createStore as xe } from "zustand/vanilla";
7
+ import { isPropModel as U, isExpression as w, isFunction as oe, isSlotModel as Re, isAction as Me, isNodeModel as Oe, getRandomStr as W, InnerComponentNameEnum as j, ENGEnvEnum as De, CPage as Y, checkPage as we } from "@chamn/model";
8
+ import { htmlTagNames as Ae } from "html-tag-names";
9
+ import { findCurrentHostFiber as Ie } from "react-reconciler/reflection";
10
+ import J from "loadjs";
11
+ const Le = (n) => () => {
12
+ console.warn(`${n} need to be implement getComponent`);
13
+ }, Te = ["customPageRootRender"], K = [
14
+ // 页面渲染
15
+ "pageRender",
16
+ // 渲染一个组件
17
+ "render",
18
+ // 将一个 组件 model 节点 转换为一个可被运行的渲染函数
19
+ "convertModelToComponent",
20
+ "getComponent",
21
+ "getContext",
22
+ "getUtils",
23
+ "transformProps",
24
+ "errorCatch",
25
+ "requestAPI",
26
+ "clear"
27
+ ], Pe = (n) => [...K, ...Te].reduce((t, r) => {
28
+ var s;
29
+ return n != null && n[r] ? t[r] = (s = n[r]) == null ? void 0 : s.bind(n) : K.includes(r) && (t[r] = Le), t;
30
+ }, {}), X = (n, e = {
31
+ keyListVar: "ALL_NODE_IDS",
32
+ getReadValCode: ""
33
+ }) => {
34
+ let t = n;
35
+ return t[0] === String(Number(t[0])) && (t = `_${t}`), `
36
+ var ${n} = {};
37
+
38
+ ${e.keyListVar}.forEach(function (key) {
39
+ var tempK = /^\\d/.test(key) ? ('_' + key) : key;
40
+ Object.defineProperty(${n}, tempK, {
41
+ get: function () {
42
+ ${e.getReadValCode}
43
+ },
44
+ set: function (value) {},
45
+ enumerable: true
46
+ });
47
+ });
48
+ `;
49
+ }, vt = function(n) {
50
+ return !(!n || typeof n != "function" || !n.prototype);
51
+ };
52
+ function je(n) {
53
+ const e = n == null ? void 0 : n.prototype;
54
+ return !!(e && e.isReactComponent);
55
+ }
56
+ function Ve(n) {
57
+ var r, s;
58
+ const t = typeof Symbol == "function" && Symbol.for ? Symbol.for("react.forward_ref") : 60112;
59
+ return (n == null ? void 0 : n.$$typeof) === t || ((r = n == null ? void 0 : n.prototype) == null ? void 0 : r.isReactComponent) || ((s = n == null ? void 0 : n.prototype) == null ? void 0 : s.setState) || n._forwardRef;
60
+ }
61
+ function ke(n) {
62
+ class e extends be {
63
+ render() {
64
+ return ve(n, this.props);
65
+ }
66
+ }
67
+ return e.displayName = n.displayName, e;
68
+ }
69
+ const I = (n, e) => {
70
+ const t = (r) => {
71
+ let s = `function run () { return ${r}; }`;
72
+ return String(r).includes("return ") && (s = `function runExp () { ${r} }`), B({
73
+ funcBody: s,
74
+ funcName: "run",
75
+ nodeContext: e.nodeContext,
76
+ storeManager: e.storeManager,
77
+ nodeModel: e.nodeModel
78
+ })();
79
+ };
80
+ try {
81
+ return t(n);
82
+ } catch (r) {
83
+ console.warn(r);
84
+ const s = `[${n}] expression run failed`;
85
+ return console.warn(s), null;
86
+ }
87
+ }, B = (n) => {
88
+ const {
89
+ funcBody: e,
90
+ funcName: t,
91
+ nodeContext: r,
92
+ storeManager: s,
93
+ $$response: o,
94
+ nodeModel: c,
95
+ actionVariableSpace: l
96
+ } = n, i = t || "anonymous";
97
+ return {
98
+ [i]: function(...y) {
99
+ let h;
100
+ const $ = Object.keys(l || {}).map((C) => `var ${C} = $ACTION_VAR_SPACE[${JSON.stringify(C)}];`);
101
+ try {
102
+ return h = `
103
+ var $$$__args__$$$ = Array.from(arguments);
104
+ function $$_run_$$() {
105
+ var __extraParams = $$$__args__$$$.pop();
106
+ var __$$storeManager__ = __extraParams.storeManager;
107
+ var $ALL_NODE_IDS = Array.from(__$$storeManager__.storeMap.keys().filter(Boolean));;
108
+ var $RESPONSE = __extraParams.$$response;;
109
+ var $CTX = __extraParams.$$context;
110
+ var $$context = $CTX;
111
+ var $PARAMS = $$context.params || {};
112
+ var $EVENT_PARAMS = $$$__args__$$$[0];
113
+ var $Event = $$$__args__$$$[0];
114
+ var $EVENT = $$$__args__$$$[0];
115
+ var $ARGS = $$$__args__$$$;
116
+
117
+ var $ACTION_VAR_SPACE = __extraParams.actionVariableSpace;
118
+ // 新增的变量
119
+ var $N_ID = ${JSON.stringify(c.id)};
120
+ var $NODE_MODAL = __extraParams.nodeModel;
121
+ var $IDS = $ALL_NODE_IDS.reduce(function (res, id) {
122
+ res[id] = id;
123
+ return res;
124
+ }, {});
125
+ var $M = {};
126
+ var $G_STATE = __$$storeManager__.getState('globalState');
127
+ var $STATE = __$$storeManager__.getState($N_ID);
128
+ var $LOOP_DATA = $CTX.loopData;
129
+
130
+
131
+ ${X("$ALL_STATE", {
132
+ keyListVar: "$ALL_NODE_IDS ",
133
+ getReadValCode: "return __$$storeManager__.getState(key);"
134
+ })}
135
+
136
+ ${X("$U_STATE", {
137
+ keyListVar: "$ALL_NODE_IDS ",
138
+ getReadValCode: "return function (newVal) { __$$storeManager__.setState(key, newVal); }"
139
+ })}
140
+
141
+ $$context.stateManager = __$$storeManager__.getStateSnapshot();
142
+ // action flowACTION_VAR_SPACE 中定义的变量
143
+ ${$.join(`;
144
+ `)}
145
+
146
+ var $$_f_$$ = ${e.trim() || "function () {}"};
147
+
148
+ return $$_f_$$.apply($$_f_$$, $$$__args__$$$);
149
+ }
150
+ return $$_run_$$();
151
+ `, new Function(h)(...y, { $$context: r, storeManager: s, $$response: o, actionVariableSpace: l, nodeModel: c });
152
+ } catch (C) {
153
+ console.warn(C);
154
+ }
155
+ }
156
+ }[i];
157
+ }, ae = (n, e) => {
158
+ const t = {};
159
+ return e.forEach((r, s) => {
160
+ t[r] = n[s];
161
+ }), t;
162
+ }, Be = (n = []) => {
163
+ const e = {};
164
+ return n.forEach(({ property: t, value: r }) => {
165
+ let s = t.replace("-webkit", "Webkit");
166
+ s = s.replace("-ms", "ms"), s = s.replace("-moz", "Moz"), s = s.replace("-o", "O");
167
+ let o = s.split("-");
168
+ o.length >= 2 && (o = o.map((c, l) => l !== 0 ? Ce(c) : c)), e[o.join("")] = r;
169
+ }), e;
170
+ }, xt = (n) => {
171
+ let e = "";
172
+ return Object.keys(n || {}).forEach((t) => {
173
+ e += `${t}:${n[t]};`;
174
+ }), e;
175
+ }, Rt = (n, e) => {
176
+ const t = {};
177
+ return n.forEach((r) => {
178
+ if (r.globalName) {
179
+ const s = e[r.globalName];
180
+ s && (t[r.globalName] = s, s.__esModule && s.default && (t[r.globalName] = s.default));
181
+ }
182
+ }), t;
183
+ }, Mt = (n, e = 1) => {
184
+ let t = 0, r = n, s = {}, o = {};
185
+ for (; t < e; )
186
+ Object.keys(r).forEach((c) => {
187
+ s = {
188
+ ...s,
189
+ ...r[c]
190
+ };
191
+ }), o = s, r = s, s = {}, t += 1;
192
+ return o;
193
+ }, Ge = (n, e) => {
194
+ const t = [];
195
+ return e.forEach((r) => {
196
+ const o = r.exec(n);
197
+ o != null && o.length && t.push(o[1]);
198
+ }), t;
199
+ }, ce = (n, e) => {
200
+ const t = {};
201
+ return e.forEach((r) => {
202
+ n[r.name] && (t[r.name] = n[r.name]);
203
+ }), t;
204
+ }, Ot = (n, e) => ce(n, e), Dt = (n, e) => ce(n, e), Q = (n) => {
205
+ var t;
206
+ return ((t = n.value.css) == null ? void 0 : t.class) || `c_${n.id}`;
207
+ }, Fe = (n, e) => {
208
+ const t = n.split(".");
209
+ let r, s = e;
210
+ return t.forEach((o) => {
211
+ r = s == null ? void 0 : s[o], s = r;
212
+ }), r || (() => `Component [${n}] not found`);
213
+ }, Z = (n, e) => {
214
+ const t = {
215
+ ...n
216
+ };
217
+ return t.__proto__ = e, t;
218
+ };
219
+ class Ue {
220
+ constructor() {
221
+ p(this, "storeMap", /* @__PURE__ */ new Map());
222
+ }
223
+ addStore(e, t) {
224
+ const r = xe(t);
225
+ return this.storeMap.set(e, r), r.name = e, r;
226
+ }
227
+ setStore(e, t) {
228
+ this.storeMap.set(e, t);
229
+ }
230
+ removeStore(e) {
231
+ this.storeMap.delete(e);
232
+ }
233
+ getStore(e) {
234
+ return this.storeMap.get(e);
235
+ }
236
+ getState(e) {
237
+ var t;
238
+ return (t = this.storeMap.get(e)) == null ? void 0 : t.getState();
239
+ }
240
+ getStateObj(e) {
241
+ return {
242
+ state: this.getState(e),
243
+ updateState: (t) => {
244
+ this.setState(e, t);
245
+ }
246
+ };
247
+ }
248
+ setState(e, t) {
249
+ var r;
250
+ return (r = this.storeMap.get(e)) == null ? void 0 : r.setState(t);
251
+ }
252
+ connect(e, t) {
253
+ const r = this.storeMap.get(e);
254
+ return r ? r.subscribe(t) : (console.warn("store not exits"), () => {
255
+ });
256
+ }
257
+ /**
258
+ * storeManger 赋值以及 获取需要做转换
259
+ */
260
+ getStateSnapshot() {
261
+ const e = {};
262
+ return this.storeMap.forEach((t, r) => {
263
+ e[r] = this.getStateObj(r);
264
+ }), e;
265
+ }
266
+ destroy() {
267
+ this.storeMap = /* @__PURE__ */ new Map();
268
+ }
269
+ }
270
+ class He {
271
+ constructor() {
272
+ p(this, "varSpace", /* @__PURE__ */ new Map());
273
+ }
274
+ get(e) {
275
+ return this.varSpace.get(e);
276
+ }
277
+ add(e, t) {
278
+ this.varSpace.set(e, t);
279
+ }
280
+ remove(e) {
281
+ this.varSpace.delete(e);
282
+ }
283
+ destroy() {
284
+ this.varSpace.clear();
285
+ }
286
+ getStateSnapshot() {
287
+ const e = {};
288
+ return this.varSpace.forEach((t, r) => {
289
+ e[r] = t;
290
+ }), e;
291
+ }
292
+ }
293
+ class ie {
294
+ constructor() {
295
+ p(this, "refMap", /* @__PURE__ */ new Map());
296
+ }
297
+ get(e) {
298
+ return this.refMap.get(e);
299
+ }
300
+ add(e, t) {
301
+ this.refMap.set(e, t);
302
+ }
303
+ remove(e) {
304
+ this.refMap.delete(e);
305
+ }
306
+ destroy() {
307
+ this.refMap.clear();
308
+ }
309
+ }
310
+ const F = "DYNAMIC", We = ["$$context", "$$nodeModel"], le = "ON_DID_RENDER", ue = "ON_WILL_DESTROY", qe = [le, ue], H = (n, e) => {
311
+ let t = n;
312
+ return e && (t = {
313
+ ...n
314
+ }, t.__proto__ = e || null), t;
315
+ }, V = (n, e = {}, ...t) => typeof n == "string" || typeof n == "number" ? String(n) : (We.forEach((s) => {
316
+ s in e && n.__CP_TYPE__ !== F && delete e[s];
317
+ }), N.createElement(n, e, ...t)), ee = (n = {}, e) => {
318
+ const t = [], r = (s, o) => {
319
+ let c = o;
320
+ U(o) && (c = o.value), e(c) ? t.push({
321
+ keyPath: s,
322
+ val: c
323
+ }) : te(c) ? c.forEach((l, i) => {
324
+ r([...s, String(i)], l);
325
+ }) : k(c) && Object.keys(c).forEach((l) => {
326
+ r([...s, l], c[l]);
327
+ });
328
+ };
329
+ return r(["$root"], n), t;
330
+ }, L = (n, e) => {
331
+ const t = n.handler, { context: r, storeManager: s } = e;
332
+ return e.actionVariableSpace || (e.actionVariableSpace = {}), async function(...o) {
333
+ const c = {}, l = async (y) => {
334
+ const h = y;
335
+ if (h.type === "RUN_CODE") {
336
+ const _ = B({
337
+ funcName: "",
338
+ funcBody: `function() {
339
+ ${h.value}
340
+ }`,
341
+ nodeContext: r,
342
+ storeManager: s,
343
+ $$response: e.$$response,
344
+ actionVariableSpace: e.actionVariableSpace,
345
+ nodeModel: e.nodeModel
346
+ });
347
+ let $;
348
+ e.$$response !== void 0 ? $ = _(e.$$response, ...o) : $ = _(...o), $ != null && $.then ? c[h.id] = await $ : c[h.id] = $;
349
+ }
350
+ if (h.type === "JUMP_LINK") {
351
+ const $ = ze(h, e)(...o);
352
+ $ != null && $.then ? c[h.id] = await $ : c[h.id] = $;
353
+ }
354
+ if (h.type === "REQUEST_API") {
355
+ const { run: _, afterFailedResponse: $, afterSuccessResponse: C } = Ye(h, e);
356
+ try {
357
+ const v = _(...o);
358
+ v != null && v.then ? c[h.id] = await v : c[h.id] = v, h.responseVarName && (e.actionVariableSpace[h.responseVarName] = c[h.id]);
359
+ const a = C(c[h.id], ...o);
360
+ return a != null && a.then ? await a : a;
361
+ } catch (v) {
362
+ const a = await $(v);
363
+ return a != null && a.then ? await a : a;
364
+ }
365
+ }
366
+ if (h.type === "CALL_NODE_METHOD") {
367
+ const $ = Je(h, e)(...o);
368
+ $ != null && $.then ? c[h.id] = await $ : c[h.id] = $, h.returnVarName && (e.actionVariableSpace[h.returnVarName] = c[h.id]);
369
+ }
370
+ if (h.type === "ASSIGN_VALUE") {
371
+ const _ = Ke(h, e);
372
+ let $ = [...o];
373
+ e.$$response !== void 0 && ($ = [e.$$response, $]);
374
+ const C = _(...$);
375
+ c[h.id] = await C;
376
+ }
377
+ };
378
+ let i = t[0];
379
+ const S = /* @__PURE__ */ new Set();
380
+ for (; i; ) {
381
+ if (S.has(i.id))
382
+ return;
383
+ await l(i), S.add(i.id), i = t.find((h) => (i == null ? void 0 : i.next) && h.id === (i == null ? void 0 : i.next));
384
+ }
385
+ };
386
+ };
387
+ function ze(n, e) {
388
+ return A(n.link, e);
389
+ }
390
+ const A = (n, e) => function(...t) {
391
+ return w(n) ? I(n.value, {
392
+ ...e.context,
393
+ nodeContext: e.context,
394
+ storeManager: e.storeManager,
395
+ $$response: e.$$response,
396
+ actionVariableSpace: e.actionVariableSpace,
397
+ nodeModel: e.nodeModel
398
+ }) : oe(n) ? B({
399
+ funcName: n.name || "",
400
+ funcBody: n.value,
401
+ nodeContext: e.context,
402
+ storeManager: e.storeManager,
403
+ $$response: e.$$response,
404
+ actionVariableSpace: e.actionVariableSpace,
405
+ nodeModel: e.nodeModel
406
+ })(...t) : n;
407
+ }, Ye = (n, e) => ({
408
+ run: function(...o) {
409
+ var _, $;
410
+ let c = "";
411
+ n.apiPath && (c = A(n.apiPath, e)(...o));
412
+ const l = n.body || {};
413
+ Object.keys(l).forEach((C) => {
414
+ l[C] = A(l[C], e)(...o);
415
+ });
416
+ const i = n.query || {};
417
+ Object.keys(i).forEach((C) => {
418
+ i[C] = A(i[C], e)(...o);
419
+ });
420
+ const S = n.header || {};
421
+ Object.keys(S).forEach((C) => {
422
+ S[C] = A(S[C], e)(...o);
423
+ });
424
+ const y = n.method || "GET";
425
+ return ($ = (_ = e.context).requestAPI) == null ? void 0 : $.call(_, {
426
+ url: c,
427
+ method: y,
428
+ header: S,
429
+ body: l,
430
+ query: i
431
+ });
432
+ },
433
+ afterSuccessResponse: async (o, ...c) => {
434
+ if (!n.afterSuccessResponse)
435
+ return o;
436
+ const l = [...n.afterSuccessResponse || [], ...n.afterFailedResponse || []];
437
+ return L(
438
+ {
439
+ handler: l
440
+ },
441
+ {
442
+ ...e,
443
+ $$response: o
444
+ }
445
+ )(...c);
446
+ },
447
+ afterFailedResponse: async (o, ...c) => {
448
+ if (!n.afterFailedResponse)
449
+ return o;
450
+ const l = [...n.afterFailedResponse || [], ...n.afterSuccessResponse || []];
451
+ return L(
452
+ {
453
+ handler: l
454
+ },
455
+ {
456
+ ...e,
457
+ $$response: o
458
+ }
459
+ )(...c);
460
+ }
461
+ }), Je = (n, e) => (...t) => {
462
+ const r = B({
463
+ funcName: "",
464
+ funcBody: `
465
+ function () {
466
+ var args = arguments;
467
+ var nodeRef = $$context.nodeRefs.get(${JSON.stringify(n.nodeId)});
468
+ if(nodeRef && nodeRef.current) {
469
+ var func = nodeRef.current[${JSON.stringify(n.methodName)}]?.bind(nodeRef.current);
470
+ var isDev = Boolean(nodeRef.current?.getTargetComponentRef);
471
+ if (isDev) {
472
+ const ins = nodeRef.current.getTargetComponentRef()?.current;
473
+ func = ins?.[${JSON.stringify(n.methodName)}]?.bind(ins);
474
+ }
475
+ if (func) {
476
+ func.apply(null, args);
477
+ }
478
+ }
479
+ }`,
480
+ nodeContext: e.context,
481
+ storeManager: e.storeManager,
482
+ $$response: e.$$response,
483
+ nodeModel: e.nodeModel
484
+ });
485
+ let s = t;
486
+ return Array.isArray(n.args) && (s = n.args.map((o) => {
487
+ const c = [e.$$response, ...t].filter(Boolean);
488
+ return A(o, e)(...c);
489
+ })), r(...s);
490
+ }, Ke = (n, e) => async (...t) => {
491
+ const s = A(n.currentValue, e)(...t);
492
+ let o;
493
+ if (s != null && s.then ? o = await s : o = s, n.valueType === "STATE") {
494
+ const c = n.targetValueName, l = e.storeManager.getStore(c.nodeId);
495
+ l && l.setState({
496
+ [c.keyPath]: o
497
+ });
498
+ } else n.valueType === "MEMORY" && (e.actionVariableSpace[n.targetValueName] = o);
499
+ return o;
500
+ }, G = (n = {}, e) => {
501
+ const { $$context: t, getComponent: r, storeManager: s } = e, o = n, c = (i) => {
502
+ if (Array.isArray(i))
503
+ return i.map((S) => c(S));
504
+ if (U(i))
505
+ return c(i.value);
506
+ if (Re(i)) {
507
+ const S = i.value, y = S.value;
508
+ if (!y)
509
+ return console.warn("slot value is null, this maybe cause some error, pls check it", n), () => {
510
+ };
511
+ const h = (_) => {
512
+ const $ = `${_.id}-${F}`, C = r(_), v = q(C, _, {
513
+ ...e
514
+ }), a = S.params || [];
515
+ return {
516
+ component: (...d) => {
517
+ const m = ae(d, a), g = H(
518
+ {
519
+ params: m,
520
+ nodeRefs: t.nodeRefs,
521
+ // 使用空函数,避免获取到父节点的方法或者函数
522
+ getProps: function() {
523
+ },
524
+ callEventMethod: function() {
525
+ }
526
+ },
527
+ t
528
+ );
529
+ return V(v, {
530
+ $$context: g,
531
+ key: $
532
+ });
533
+ },
534
+ key: $
535
+ };
536
+ };
537
+ if (Array.isArray(y)) {
538
+ const _ = y == null ? void 0 : y.map(($) => h($));
539
+ return (...$) => _.map((C) => {
540
+ if (je(C.component)) {
541
+ const a = C.component;
542
+ return N.createElement(a, {
543
+ $$context: t,
544
+ key: C.key
545
+ });
546
+ } else {
547
+ const a = C.component;
548
+ return a == null ? void 0 : a(...$);
549
+ }
550
+ });
551
+ } else
552
+ return h(y).component;
553
+ } else {
554
+ if (w(i))
555
+ return I(i.value, {
556
+ nodeContext: t,
557
+ storeManager: e.storeManager,
558
+ nodeModel: e.nodeModel
559
+ });
560
+ if (oe(i)) {
561
+ const S = i;
562
+ return B({
563
+ funcBody: S.value,
564
+ funcName: S.name || "",
565
+ nodeContext: t,
566
+ storeManager: s,
567
+ nodeModel: e.nodeModel
568
+ });
569
+ } else {
570
+ if (Me(i))
571
+ return L(i, {
572
+ context: t,
573
+ storeManager: s,
574
+ actionVariableSpace: {},
575
+ nodeModel: e.nodeModel
576
+ });
577
+ if (k(i)) {
578
+ let S = i;
579
+ U(i) && (S = i.value);
580
+ const y = S, h = {};
581
+ return Object.keys(S).forEach((_) => {
582
+ h[_] = c(y[_]);
583
+ }), h;
584
+ } else
585
+ return i;
586
+ }
587
+ }
588
+ }, l = {};
589
+ return Object.keys(o).forEach((i) => {
590
+ const S = o[i];
591
+ l[i] = c(S);
592
+ }), l;
593
+ }, Xe = (n, e) => {
594
+ const { runtimeComponentCache: t, $$context: r = {}, getComponent: s, renderMode: o } = e, { $$context: c, idx: l, ...i } = e;
595
+ return typeof n == "string" ? V(n) : Oe(n) ? (({ currentNode: y }) => {
596
+ const h = y.value.id;
597
+ let _ = null;
598
+ if (t.get(h)) {
599
+ const v = t.get(h);
600
+ _ = v == null ? void 0 : v.component;
601
+ } else {
602
+ const v = s(y);
603
+ _ = q(v, y, {
604
+ ...i
605
+ }), !t.get(h) && o !== "design" && t.set(h, {
606
+ component: _
607
+ });
608
+ }
609
+ const $ = `${h}-${F}`;
610
+ return V(_, {
611
+ $$context: r,
612
+ $$nodeModel: n,
613
+ key: $
614
+ });
615
+ })({
616
+ currentNode: n
617
+ }) : void 0;
618
+ }, q = (n, e, t) => {
619
+ const {
620
+ storeManager: r,
621
+ variableManager: s,
622
+ onGetRef: o,
623
+ onComponentMount: c,
624
+ onComponentDestroy: l,
625
+ refManager: i,
626
+ processNodeConfigHook: S,
627
+ requestAPI: y,
628
+ doc: h
629
+ } = t, { ..._ } = t;
630
+ class $ extends N.Component {
631
+ constructor(a) {
632
+ super(a);
633
+ p(this, "_CONDITION", !0);
634
+ p(this, "_DESIGN_BOX", !1);
635
+ p(this, "_NODE_MODEL", e);
636
+ p(this, "_NODE_ID", e.id);
637
+ p(this, "UNIQUE_ID", `${e.id}_${W()}`);
638
+ p(this, "targetComponentRef");
639
+ p(this, "listenerHandler", []);
640
+ p(this, "storeState");
641
+ /** 存储清理 store 的监听函数 */
642
+ p(this, "storeListenDisposeList", []);
643
+ /** save dom and media css */
644
+ p(this, "domHeader");
645
+ p(this, "mediaStyleDomMap", {});
646
+ /** 存储当前节点的一些变量和方法,不具有响应性 */
647
+ p(this, "variableSpace");
648
+ p(this, "nodeName");
649
+ // 是否已挂载
650
+ p(this, "isMounted", !1);
651
+ p(this, "updateState", (a) => {
652
+ this.isMounted && (e.value.componentName === j.ROOT_CONTAINER ? this.setState(a) : this.storeState.setState(a));
653
+ });
654
+ p(this, "getStyleDomById", (a) => {
655
+ const u = this.mediaStyleDomMap;
656
+ let f = u[a];
657
+ return f || (f = h.createElement("style"), u[a] = f), f.id = a, f;
658
+ });
659
+ p(this, "addMediaCSS", () => {
660
+ var f;
661
+ let a = this.domHeader;
662
+ if (a || (a = (f = h.getElementsByTagName("head")) == null ? void 0 : f[0], this.domHeader = a), !this.domHeader) {
663
+ console.warn("not found header dom");
664
+ return;
665
+ }
666
+ const u = this._NODE_MODEL.value.css;
667
+ u && u.value.forEach((d) => {
668
+ var b;
669
+ const m = `${this.UNIQUE_ID}_${d.state}`;
670
+ let g = Q(this._NODE_MODEL);
671
+ if (d.state !== "normal" && (g = `${g}:${d.state}`), d.text) {
672
+ const E = this.getStyleDomById(m);
673
+ E.innerText = `.${g} { ${d.text} }`, a == null || a.appendChild(E);
674
+ }
675
+ (b = d.media) != null && b.length && d.media.forEach((E) => {
676
+ const x = `${m}_${E.type}_${E.value}`, M = this.getStyleDomById(x);
677
+ M.media = `screen and (${E.type}:${E.value}px)`, M.innerHTML = `.${g} { ${E.text} }`, a == null || a.appendChild(M);
678
+ });
679
+ });
680
+ });
681
+ p(this, "removeMediaCSS", () => {
682
+ const a = this.mediaStyleDomMap;
683
+ Object.keys(a).forEach((u) => {
684
+ var f;
685
+ (f = this.domHeader) == null || f.removeChild(a[u]);
686
+ }), this.mediaStyleDomMap = {};
687
+ });
688
+ p(this, "rebuildNode", () => {
689
+ this.storeListenDisposeList.forEach((a) => a()), this.removeMediaCSS(), this.connectStore(), this.addMediaCSS(), this.forceUpdate();
690
+ });
691
+ this.targetComponentRef = N.createRef(), this.listenerHandler = [], this.state = e.value.state || {};
692
+ let u = e.value.nodeName || e.id;
693
+ e.value.componentName === j.ROOT_CONTAINER && (u = "globalState"), this.nodeName = u;
694
+ const f = r.getStore(u);
695
+ f ? (this.storeState = f, f.setState({
696
+ ...e.value.state || {}
697
+ })) : this.storeState = r.addStore(u, () => ({
698
+ ...e.value.state || {}
699
+ }));
700
+ const d = this.storeState.subscribe((g) => {
701
+ this.setStateIfChanged(g);
702
+ });
703
+ this.storeListenDisposeList.push(d), this.connectStore();
704
+ const m = s.get(u);
705
+ m ? this.variableSpace = m : (this.variableSpace = {
706
+ staticVar: {},
707
+ methods: {}
708
+ }, s.add(u, this.variableSpace));
709
+ }
710
+ /** 如果值和当前 state 一样了就不触发更新 */
711
+ setStateIfChanged(a) {
712
+ this.isMounted && e.value.componentName !== j.ROOT_CONTAINER && this.setState((u) => {
713
+ const f = typeof a == "function" ? a(u) : a;
714
+ return Ee(u, { ...u, ...f }) ? null : f;
715
+ });
716
+ }
717
+ connectStore() {
718
+ const a = ee(e.props, (g) => !!w(g)), u = ee(
719
+ {
720
+ css: e.value.css,
721
+ class: e.value.classNames
722
+ },
723
+ (g) => !!w(g)
724
+ );
725
+ let f = [];
726
+ [...a, ...u].map((g) => {
727
+ const b = g.val, E = [
728
+ // 匹配 $$context.stateManger.xxx.state
729
+ new RegExp(`(?<=context\\.stateManager(?:\\.|\\[["'])?)\\w+(?=(?:["']?\\])?(?:\\.|\\[)?["']?state)`, "gim"),
730
+ // 匹配 $ALL_STATE.xxx;
731
+ /\$ALL_STATE(?:\.|(?:\[\s*["']))(\w+)(?=(?:["']\s*\])?)/gim,
732
+ // 匹配 getStateObj("xxx")
733
+ /getStateObj\(["']([^"']+)["']\)/gim
734
+ ], x = Ge(b.value, E);
735
+ f = [...f, ...x], /\$CTX\.globalState|\$G_STATE/.test(b.value) && f.push("globalState");
736
+ }).filter(Boolean);
737
+ const d = Array.from(new Set(f)), m = [];
738
+ d.length && d.forEach((g) => {
739
+ if (!g)
740
+ return;
741
+ r.getStore(g) || (r.addStore(g, () => ({})), console.warn(r, g, "not exits, auto create"));
742
+ const E = r.connect(g, (x) => {
743
+ this.setStateIfChanged(x);
744
+ });
745
+ m.push(E);
746
+ }), this.storeListenDisposeList = m;
747
+ }
748
+ componentDidMount() {
749
+ var f;
750
+ this.isMounted = !0, this.addMediaCSS(), o == null || o(this.targetComponentRef, e, this), c == null || c(this, e);
751
+ const a = (f = e.value.eventListener) == null ? void 0 : f.find((d) => d.name === le);
752
+ a && L(a.func, {
753
+ context: this.createCurrentNodeCtx(),
754
+ storeManager: r,
755
+ actionVariableSpace: {},
756
+ nodeModel: e
757
+ })();
758
+ const u = () => {
759
+ this.isMounted && (r.setStore(e.value.nodeName || e.id, this.storeState), this.storeState.setState({
760
+ ...this.state,
761
+ ...e.value.state || {}
762
+ }), this.rebuildNode());
763
+ };
764
+ e.onChange(u);
765
+ }
766
+ componentWillUnmount() {
767
+ var f;
768
+ this.storeListenDisposeList.forEach((d) => d()), this.removeMediaCSS(), l == null || l(this, e);
769
+ const a = ue, u = (f = e.value.eventListener) == null ? void 0 : f.find((d) => d.name === a);
770
+ u && L(u.func, {
771
+ context: this.createCurrentNodeCtx(),
772
+ storeManager: r,
773
+ actionVariableSpace: {},
774
+ nodeModel: e
775
+ })();
776
+ }
777
+ /** 转换节点的 methods */
778
+ transformMethods(a) {
779
+ const { context: u } = a, f = G(
780
+ {
781
+ methods: e.value.methods
782
+ },
783
+ {
784
+ $$context: u,
785
+ ..._,
786
+ nodeModel: e
787
+ }
788
+ ), d = e.value.methods || [], m = f.methods, g = d.reduce((b, E, x) => (b[E.name] = m[x], b), {});
789
+ u.methods = g, this.variableSpace.methods = Object.assign(this.variableSpace.methods, g);
790
+ }
791
+ /** 处理根节点的 context */
792
+ processRootContext(a) {
793
+ e.value.componentName === j.ROOT_CONTAINER && (a.globalState = this.state, a.updateGlobalState = this.updateState, a.requestAPI = y, a.getGlobalState = () => this.state);
794
+ }
795
+ processNodeClassName(a, u) {
796
+ var m;
797
+ const f = ((m = e.value.classNames) == null ? void 0 : m.map((g) => {
798
+ var x;
799
+ const b = g.name;
800
+ return (w(g.status) ? I(((x = g.status) == null ? void 0 : x.value) || "", {
801
+ nodeContext: u,
802
+ nodeModel: e,
803
+ storeManager: r
804
+ }) : !1) ? b : "";
805
+ })) || [];
806
+ let d = `${a ?? ""} ${f.join(" ")}`.trim();
807
+ return e.value.css && (d = `${Q(e)} ${d}`.trim()), d;
808
+ }
809
+ processNodeStyle(a) {
810
+ if (!e.value.style)
811
+ return {};
812
+ const u = G(
813
+ { style: e.value.style },
814
+ {
815
+ $$context: a,
816
+ ..._,
817
+ nodeModel: e
818
+ }
819
+ );
820
+ return Be(u.style || []);
821
+ }
822
+ processNodeChild(a, u) {
823
+ let f = [];
824
+ if (a !== void 0)
825
+ f = Array.isArray(a) ? a : [a];
826
+ else {
827
+ const d = [];
828
+ e.value.children.forEach((g, b) => {
829
+ const E = Xe(g, {
830
+ $$context: u,
831
+ idx: b,
832
+ ..._
833
+ });
834
+ d.push(E);
835
+ }), f = d;
836
+ }
837
+ return f;
838
+ }
839
+ processNodeConditionAndConfigHook(a, u, f) {
840
+ let d = e.value.condition ?? !0;
841
+ typeof d != "boolean" && (d = I(d.value, {
842
+ nodeContext: f || {},
843
+ nodeModel: e,
844
+ storeManager: r
845
+ }));
846
+ let m = {
847
+ condition: d,
848
+ props: a
849
+ };
850
+ S && (m = S(m, e));
851
+ const g = V(n, m.props, ...u);
852
+ return this._CONDITION = m.condition, m.condition ? g : N.createElement(
853
+ "div",
854
+ {
855
+ key: a.key,
856
+ style: {
857
+ display: "none"
858
+ }
859
+ },
860
+ g
861
+ );
862
+ }
863
+ processNodeEventListener(a) {
864
+ const u = e.value.eventListener, f = {};
865
+ return u == null || u.forEach((d) => {
866
+ if (qe.includes(d.name))
867
+ return;
868
+ const m = L(d.func, {
869
+ context: a,
870
+ storeManager: r,
871
+ actionVariableSpace: {},
872
+ nodeModel: e
873
+ });
874
+ f[d.name] = m;
875
+ }), f;
876
+ }
877
+ createCurrentNodeCtx() {
878
+ const { $$context: a } = this.props, u = e.value.nodeName || e.id, f = e.id, d = {
879
+ state: this.state || {},
880
+ staticVar: this.variableSpace.staticVar,
881
+ updateState: this.updateState,
882
+ storeManager: r,
883
+ getState: () => r.getStateObj(u),
884
+ getStateObj: () => r.getStateObj(u),
885
+ getStateObjById: (g) => r.getStateObj(g),
886
+ stateManager: r.getStateSnapshot(),
887
+ getMethods: () => {
888
+ const g = s.get(f).methods, b = i.get(f).current;
889
+ return Z(g, b);
890
+ },
891
+ getMethodsById: (g) => {
892
+ const b = s.get(g).methods, E = i.get(g).current;
893
+ return Z(b, E);
894
+ },
895
+ getStaticVar: () => s.get(u).staticVar,
896
+ getStaticVarById: (g) => s.get(g).staticVar,
897
+ /** 获取当前节点的事件函数 */
898
+ callEventMethod: (g, b) => {
899
+ var x, M;
900
+ const E = i.get(f).current;
901
+ (M = E == null ? void 0 : (x = E.props)[g]) == null || M.call(x, b);
902
+ },
903
+ /** 获取当前 node 的 props */
904
+ getProps: () => {
905
+ const g = i.get(f).current;
906
+ return g == null ? void 0 : g.props;
907
+ },
908
+ nodeRefs: a.nodeRefs
909
+ };
910
+ return this.processRootContext(d), H(d, a);
911
+ }
912
+ injectEngEnv() {
913
+ const a = {}, u = e.value.injectEnvList || [];
914
+ if (Array.isArray(e.value.injectEnvList)) {
915
+ const f = {
916
+ [De.COMPONENTS]: t.components
917
+ };
918
+ u.reduce((d, m) => (d[m] = f[m], d), a);
919
+ }
920
+ return a;
921
+ }
922
+ renderCore() {
923
+ const { $$context: a, ...u } = this.props, f = {
924
+ key: e.id,
925
+ ...e.props,
926
+ ...u
927
+ }, d = this.createCurrentNodeCtx();
928
+ this.transformMethods({ context: d });
929
+ let m = G(f, {
930
+ $$context: d,
931
+ ..._,
932
+ nodeModel: e
933
+ });
934
+ const g = this.injectEngEnv();
935
+ Object.assign(m, g);
936
+ const b = this.processNodeClassName(m.className, d);
937
+ m.className = b;
938
+ const E = this.processNodeStyle(d);
939
+ m.style = {
940
+ ...(m == null ? void 0 : m.style) || {},
941
+ ...E || {}
942
+ };
943
+ const { children: x } = m;
944
+ delete m.children;
945
+ const M = this.processNodeChild(x, d);
946
+ if (m.ref = this.targetComponentRef, e.value.eventListener) {
947
+ const T = this.processNodeEventListener(d);
948
+ m = {
949
+ ...m,
950
+ ...T
951
+ };
952
+ }
953
+ return this.processNodeConditionAndConfigHook(m, M, d);
954
+ }
955
+ renderLoop() {
956
+ const { $$context: a, ...u } = this.props, f = {
957
+ key: e.id,
958
+ ...e.props,
959
+ ...u
960
+ }, d = this.createCurrentNodeCtx();
961
+ this.transformMethods({ context: d });
962
+ const m = e.value.loop;
963
+ let g = [];
964
+ if (m && m.open) {
965
+ this.targetComponentRef.current = [];
966
+ let b = m.data || [];
967
+ if (w(m.data)) {
968
+ const E = m.data;
969
+ b = I(E.value, {
970
+ nodeContext: d || {},
971
+ storeManager: r,
972
+ nodeModel: e
973
+ }) || [];
974
+ }
975
+ return g = b.map((...E) => {
976
+ const x = E[1], M = [m.forName || "item", m.forIndex || "index"], z = ae(E, M);
977
+ let T = "loopData";
978
+ m.name && (T = `${T}${m.name}`);
979
+ const D = H(
980
+ {
981
+ [T]: z,
982
+ nodeRefs: d.nodeRefs,
983
+ // 使用空函数,避免获取到父节点的方法或者函数
984
+ getProps: function() {
985
+ },
986
+ callEventMethod: function() {
987
+ }
988
+ },
989
+ d
990
+ );
991
+ let R = G(f, {
992
+ $$context: D,
993
+ ..._,
994
+ nodeModel: e
995
+ });
996
+ const pe = this.injectEngEnv();
997
+ Object.assign(R, pe);
998
+ const he = this.processNodeClassName(R.className, D);
999
+ R.className = he;
1000
+ const me = this.processNodeStyle(D);
1001
+ R.style = {
1002
+ ...(R == null ? void 0 : R.style) || {},
1003
+ ...me || {}
1004
+ };
1005
+ const { children: ge } = R;
1006
+ delete R.children;
1007
+ const $e = this.processNodeChild(ge, D);
1008
+ if (R.key = `${R.key}-${x}`, w(m.key)) {
1009
+ const P = m.key, _e = I(P.value, {
1010
+ nodeContext: D || {},
1011
+ storeManager: r,
1012
+ nodeModel: e
1013
+ });
1014
+ R.key += `-${_e}`;
1015
+ }
1016
+ if (R.ref = (P) => {
1017
+ this.targetComponentRef.current = this.targetComponentRef.current || [], this.targetComponentRef.current[x] = P;
1018
+ }, e.value.eventListener) {
1019
+ const P = this.processNodeEventListener(D);
1020
+ R = {
1021
+ ...R,
1022
+ ...P
1023
+ };
1024
+ }
1025
+ return this.processNodeConditionAndConfigHook(R, $e, D);
1026
+ }), g;
1027
+ }
1028
+ }
1029
+ render() {
1030
+ const a = e.value.loop;
1031
+ return a && a.open ? this.renderLoop() : this.renderCore();
1032
+ }
1033
+ }
1034
+ return p($, "__CP_TYPE__", F), $.displayName = `${e.value.componentName}Dynamic`, $;
1035
+ };
1036
+ class Qe {
1037
+ constructor() {
1038
+ p(this, "renderMode", "normal");
1039
+ p(this, "components", {});
1040
+ p(this, "storeManager", new Ue());
1041
+ // 存储节点的变量或者方法
1042
+ p(this, "variableManager", new He());
1043
+ p(this, "runtimeComponentCache", /* @__PURE__ */ new Map());
1044
+ p(this, "onGetRef");
1045
+ p(this, "onGetComponent");
1046
+ p(this, "onComponentMount");
1047
+ p(this, "refManager", new ie());
1048
+ p(this, "onComponentDestroy");
1049
+ /**
1050
+ * 处理 props 钩子, 可以统一拦截 node 的处理,并修改其值
1051
+ */
1052
+ p(this, "processNodeConfigHook");
1053
+ /** 请求 API */
1054
+ p(this, "requestAPI", async (e) => {
1055
+ throw console.log(e), new Error("Need to implement requestAPI for Render");
1056
+ });
1057
+ }
1058
+ /**
1059
+ * 根据 node 获取对应渲染的组件
1060
+ * @param currentNode
1061
+ * @returns
1062
+ */
1063
+ getComponent(e) {
1064
+ var s;
1065
+ const t = e.value.componentName;
1066
+ let r = Fe(t, this.components);
1067
+ return Ve(r) || (r = ke(r), this.components[t] = r), this.onGetComponent && (r = (s = this.onGetComponent) == null ? void 0 : s.call(this, r, e)), r;
1068
+ }
1069
+ pageRender(e, {
1070
+ components: t,
1071
+ onGetRef: r,
1072
+ refManager: s,
1073
+ $$context: o = {
1074
+ nodeRefs: s,
1075
+ // 使用空函数,避免获取到父节点的方法或者函数
1076
+ getProps: function() {
1077
+ },
1078
+ callEventMethod: function() {
1079
+ }
1080
+ },
1081
+ onGetComponent: c,
1082
+ onComponentMount: l,
1083
+ onComponentDestroy: i,
1084
+ renderMode: S,
1085
+ processNodeConfigHook: y,
1086
+ requestAPI: h,
1087
+ doc: _
1088
+ }) {
1089
+ this.renderMode = S, this.components = t, this.onGetRef = r, this.onGetComponent = c, this.onComponentMount = l, this.onComponentDestroy = i, this.processNodeConfigHook = y, this.refManager = s, this.requestAPI = h;
1090
+ const $ = e.value.componentsTree, C = this.getComponent($), v = q(C, e.value.componentsTree, {
1091
+ storeManager: this.storeManager,
1092
+ variableManager: this.variableManager,
1093
+ runtimeComponentCache: this.runtimeComponentCache,
1094
+ getComponent: this.getComponent.bind(this),
1095
+ refManager: this.refManager,
1096
+ onGetRef: this.onGetRef,
1097
+ processNodeConfigHook: y,
1098
+ onComponentMount: l,
1099
+ onComponentDestroy: i,
1100
+ renderMode: S,
1101
+ requestAPI: h,
1102
+ components: this.components,
1103
+ doc: _
1104
+ }), a = {}, u = $.props;
1105
+ return Object.keys(u).forEach((f) => {
1106
+ a[f] = u[f].value;
1107
+ }), a.$$context = o, V(v, a);
1108
+ }
1109
+ clear() {
1110
+ this.runtimeComponentCache.clear(), this.storeManager.destroy();
1111
+ }
1112
+ }
1113
+ const wt = Pe(new Qe()), O = (n) => {
1114
+ const e = {};
1115
+ return n.forEach((t) => {
1116
+ e[t.key] = t.value;
1117
+ }), e;
1118
+ }, Ze = Ae.reduce((n, e) => (n[e] = ({ children: t, $$attributes: r = [], ...s }) => {
1119
+ let o = t;
1120
+ Array.isArray(t) || (o = [t]);
1121
+ const c = {
1122
+ boxSizing: "border-box",
1123
+ ...s.style || {}
1124
+ };
1125
+ return N.createElement(
1126
+ e,
1127
+ {
1128
+ ...s,
1129
+ ...O(r),
1130
+ style: c
1131
+ },
1132
+ ...o
1133
+ );
1134
+ }, n), {}), et = ({ children: n, width: e, height: t, $$attributes: r = [], ...s }) => {
1135
+ let o = n;
1136
+ Array.isArray(n) || (o = [n]), o = o.filter((S) => S !== void 0);
1137
+ const { style: c = {}, ...l } = O(r), i = {
1138
+ height: t,
1139
+ width: e,
1140
+ boxSizing: "border-box",
1141
+ ...c,
1142
+ ...s.style || {}
1143
+ };
1144
+ return N.createElement(
1145
+ "div",
1146
+ {
1147
+ ...s,
1148
+ ...l,
1149
+ style: i
1150
+ },
1151
+ ...o
1152
+ );
1153
+ }, tt = ({ afterMount: n, beforeDestroy: e, $$attributes: t = [], ...r }) => {
1154
+ ne(() => (n == null || n(r), () => {
1155
+ e == null || e(r);
1156
+ }), []);
1157
+ const s = {
1158
+ boxSizing: "border-box",
1159
+ ...r.style || {}
1160
+ };
1161
+ return N.createElement("canvas", {
1162
+ ...r,
1163
+ ...O(t),
1164
+ style: s
1165
+ });
1166
+ }, nt = ({ children: n, $$attributes: e = [], ...t }) => {
1167
+ let r = n;
1168
+ Array.isArray(n) || (r = [n]);
1169
+ const s = {
1170
+ boxSizing: "border-box",
1171
+ ...t.style || {}
1172
+ };
1173
+ return N.createElement(
1174
+ "img",
1175
+ {
1176
+ ...t,
1177
+ ...O(e),
1178
+ style: s
1179
+ },
1180
+ ...r
1181
+ );
1182
+ }, rt = ({ children: n, $$attributes: e = [], ...t }) => {
1183
+ let r = n;
1184
+ Array.isArray(n) || (r = [n]);
1185
+ const s = {
1186
+ boxSizing: "border-box",
1187
+ ...t.style || {}
1188
+ };
1189
+ return N.createElement(
1190
+ "video",
1191
+ {
1192
+ ...t,
1193
+ ...O(e),
1194
+ style: s
1195
+ },
1196
+ ...r
1197
+ );
1198
+ }, st = ({ children: n, $$attributes: e = [], ...t }) => {
1199
+ let r = n;
1200
+ Array.isArray(n) || (r = [n]);
1201
+ const s = {
1202
+ boxSizing: "border-box",
1203
+ ...t.style || {}
1204
+ };
1205
+ return N.createElement(
1206
+ "audio",
1207
+ {
1208
+ ...t,
1209
+ ...O(e),
1210
+ style: s
1211
+ },
1212
+ ...r
1213
+ );
1214
+ }, ot = ({ $$attributes: n = [], content: e, ...t }) => {
1215
+ const r = {
1216
+ boxSizing: "border-box",
1217
+ ...t.style || {}
1218
+ };
1219
+ return N.createElement(
1220
+ "span",
1221
+ {
1222
+ ...t,
1223
+ ...O(n),
1224
+ style: r
1225
+ },
1226
+ e
1227
+ );
1228
+ }, at = ({ children: n, $$attributes: e = [], afterMount: t, beforeDestroy: r, style: s, ...o }) => {
1229
+ let c = n;
1230
+ Array.isArray(n) || (c = [n]), ne(() => (t == null || t(o), () => {
1231
+ r == null || r(o);
1232
+ }), []);
1233
+ const l = {
1234
+ boxSizing: "border-box",
1235
+ ...s || {}
1236
+ };
1237
+ return N.createElement(
1238
+ "div",
1239
+ {
1240
+ ...o,
1241
+ ...O(e),
1242
+ style: l
1243
+ },
1244
+ ...c
1245
+ );
1246
+ }, ct = ({ children: n, $$attributes: e = [], htmlTag: t = "div", ...r }) => {
1247
+ let s = n;
1248
+ Array.isArray(n) || (s = [n]);
1249
+ const { style: o = {}, ...c } = O(e), l = {
1250
+ boxSizing: "border-box",
1251
+ ...o,
1252
+ ...r.style || {}
1253
+ };
1254
+ return N.createElement(
1255
+ t,
1256
+ {
1257
+ ...r,
1258
+ ...c,
1259
+ style: l
1260
+ },
1261
+ ...s
1262
+ );
1263
+ }, it = {
1264
+ RootContainer: ({ children: n }) => n,
1265
+ ...Ze,
1266
+ CContainer: at,
1267
+ CVideo: rt,
1268
+ CAudio: st,
1269
+ CBlock: et,
1270
+ CImage: nt,
1271
+ CText: ot,
1272
+ CCanvas: tt,
1273
+ CNativeTag: ct
1274
+ };
1275
+ class lt extends N.Component {
1276
+ constructor(t) {
1277
+ super(t);
1278
+ p(this, "refManager");
1279
+ // save component instance
1280
+ p(this, "dynamicComponentInstanceMap", /* @__PURE__ */ new Map());
1281
+ p(this, "onGetRef", (t, r, s) => {
1282
+ var o, c;
1283
+ (c = (o = this.props).onGetRef) == null || c.call(o, t, r, s), this.dynamicComponentInstanceMap.set(r.id, s), this.refManager.add(r.value.refId || r.id, t);
1284
+ });
1285
+ p(this, "rerender", (t) => {
1286
+ if (this.props.adapter.clear(), (t == null ? void 0 : t.nodeType) === "PAGE" && t)
1287
+ this.setState({
1288
+ pageModel: t
1289
+ });
1290
+ else if (k(t) && we(t)) {
1291
+ const r = t;
1292
+ this.setState({
1293
+ pageModel: new Y(r, {
1294
+ materials: this.state.pageModel.materialsModel.rawValue
1295
+ })
1296
+ });
1297
+ }
1298
+ });
1299
+ this.state = {
1300
+ pageModel: t.pageModel || new Y(t.page)
1301
+ }, this.refManager = new ie();
1302
+ }
1303
+ getPageModel() {
1304
+ return this.state.pageModel;
1305
+ }
1306
+ componentDidMount() {
1307
+ const { render: t } = this.props;
1308
+ t && (t.ref.current = this), window.parent && (window.parent.__CB_RENDER_WIN__ = window);
1309
+ }
1310
+ componentWillUnmount() {
1311
+ this.refManager.destroy();
1312
+ }
1313
+ render() {
1314
+ const { props: t } = this, { adapter: r, onGetComponent: s, onComponentDestroy: o, onComponentMount: c } = t, { pageModel: l } = this.state;
1315
+ if (!l)
1316
+ return console.warn("pageModel is null"), null;
1317
+ const i = {
1318
+ ...it,
1319
+ ...t.components
1320
+ }, S = this.props.$$context || {};
1321
+ let y = this.props.doc;
1322
+ return typeof window < "u" && (y = this.props.doc || window.document), r.pageRender(l, {
1323
+ libs: {},
1324
+ components: i,
1325
+ refManager: this.refManager,
1326
+ onGetRef: this.onGetRef,
1327
+ onGetComponent: s,
1328
+ onComponentMount: c,
1329
+ onComponentDestroy: o,
1330
+ $$context: {
1331
+ ...S,
1332
+ nodeRefs: this.refManager
1333
+ },
1334
+ renderMode: t.renderMode || "normal",
1335
+ requestAPI: t.requestAPI ?? r.requestAPI,
1336
+ processNodeConfigHook: t.processNodeConfigHook,
1337
+ doc: y
1338
+ });
1339
+ }
1340
+ }
1341
+ const At = () => {
1342
+ const n = re(null);
1343
+ return se(() => ({
1344
+ ref: n,
1345
+ rerender: function(...t) {
1346
+ n.current && n.current.rerender(...t);
1347
+ }
1348
+ }), []);
1349
+ };
1350
+ class ut extends N.Component {
1351
+ constructor(t) {
1352
+ super(t);
1353
+ p(this, "onDoubleClick", () => {
1354
+ this.setState({
1355
+ hasError: !1,
1356
+ error: null
1357
+ });
1358
+ });
1359
+ this.state = { hasError: !1, error: "" };
1360
+ }
1361
+ static getDerivedStateFromError(t) {
1362
+ return { hasError: !0, error: t };
1363
+ }
1364
+ componentDidCatch(t, r) {
1365
+ var s, o;
1366
+ (o = (s = this.props).onError) == null || o.call(s, r);
1367
+ }
1368
+ render() {
1369
+ if (this.state.hasError) {
1370
+ const { onDoubleClick: t } = this, r = this.props.node.value;
1371
+ console.error(this.props.node, this.props.children);
1372
+ const s = N.createElement(
1373
+ "div",
1374
+ {
1375
+ style: {
1376
+ backgroundColor: "rgb(255 206 215 / 13%)",
1377
+ padding: "5px",
1378
+ color: "#ff0000b0",
1379
+ textAlign: "center",
1380
+ fontSize: "12px"
1381
+ }
1382
+ },
1383
+ "Render error, node id: ",
1384
+ r.id,
1385
+ ", node name:",
1386
+ r.title,
1387
+ " component name:",
1388
+ r.title || r.componentName,
1389
+ N.createElement("p", null, "msg: ", String(this.state.error)),
1390
+ N.createElement(
1391
+ "button",
1392
+ {
1393
+ onDoubleClick: t,
1394
+ style: {
1395
+ border: "1px solid rgba(100,100,100,0.1)",
1396
+ backgroundColor: "#fff",
1397
+ padding: "5px 10px",
1398
+ borderRadius: "2px",
1399
+ color: "gray",
1400
+ cursor: "pointer",
1401
+ marginTop: "5px"
1402
+ }
1403
+ },
1404
+ "double click to refresh"
1405
+ ),
1406
+ N.createElement("div", {
1407
+ style: {
1408
+ display: "none"
1409
+ }
1410
+ })
1411
+ );
1412
+ return N.createElement(this.props.targetComponent, { onlyRenderChild: !0 }, s);
1413
+ }
1414
+ return this.props.children;
1415
+ }
1416
+ }
1417
+ function dt(n) {
1418
+ return n._reactInternals;
1419
+ }
1420
+ function ft(n) {
1421
+ const e = dt(n);
1422
+ if (e === void 0) {
1423
+ if (typeof n.render == "function")
1424
+ throw new Error("Unable to find node on an unmounted component.");
1425
+ {
1426
+ const r = Object.keys(n).join(",");
1427
+ throw new Error(`Argument appears to not be a ReactComponent. Keys: ${r}`);
1428
+ }
1429
+ }
1430
+ const t = Ie(e);
1431
+ return t === null ? null : t.stateNode;
1432
+ }
1433
+ function pt(n) {
1434
+ return ft(n);
1435
+ }
1436
+ class ht {
1437
+ constructor() {
1438
+ p(this, "instanceMap", /* @__PURE__ */ new Map());
1439
+ }
1440
+ get(e) {
1441
+ return this.instanceMap.get(e);
1442
+ }
1443
+ add(e, t) {
1444
+ const r = this.instanceMap.get(e);
1445
+ r ? r.push(t) : this.instanceMap.set(e, [t]);
1446
+ }
1447
+ remove(e, t) {
1448
+ const r = this.instanceMap.get(e);
1449
+ if (t !== void 0 && Array.isArray(r)) {
1450
+ const s = r.filter((o) => o !== t);
1451
+ this.instanceMap.set(e, s);
1452
+ } else
1453
+ this.instanceMap.delete(e);
1454
+ }
1455
+ destroy() {
1456
+ this.instanceMap.clear();
1457
+ }
1458
+ }
1459
+ const mt = (n) => {
1460
+ const { node: e } = n, t = se(() => {
1461
+ const l = e.isContainer();
1462
+ return k(l) ? l : {
1463
+ placeholder: "Drag the component to place it",
1464
+ width: "100%",
1465
+ height: "100%",
1466
+ style: {}
1467
+ };
1468
+ }, [e]), { placeholder: r, height: s, width: o, style: c } = t;
1469
+ return N.createElement(
1470
+ "div",
1471
+ {
1472
+ style: {
1473
+ margin: 0,
1474
+ padding: 0,
1475
+ display: "flex",
1476
+ alignItems: "center",
1477
+ justifyContent: "center",
1478
+ backgroundColor: "rgba(200,200,200,0.1)",
1479
+ border: "1px solid rgba(0,0,0,0.1)",
1480
+ borderRadius: "2px",
1481
+ fontSize: "14px",
1482
+ color: "gray",
1483
+ cursor: "default",
1484
+ minHeight: "50px",
1485
+ width: o,
1486
+ height: s,
1487
+ boxSizing: "border-box",
1488
+ ...c
1489
+ }
1490
+ },
1491
+ r
1492
+ );
1493
+ };
1494
+ class It extends N.Component {
1495
+ constructor(t) {
1496
+ super(t);
1497
+ p(this, "instanceManager", new ht());
1498
+ p(this, "renderRef");
1499
+ p(this, "dropPlaceholder", mt);
1500
+ p(this, "_components", {});
1501
+ p(this, "onGetComponent", (t, r) => {
1502
+ var i, S;
1503
+ const s = this;
1504
+ let o = t;
1505
+ const c = (S = (i = r.material) == null ? void 0 : i.value.advanceCustom) == null ? void 0 : S.wrapComponent;
1506
+ c && (o = c(t, {
1507
+ node: r,
1508
+ ctx: window.__C_ENGINE_DESIGNER_PLUGIN_CTX__
1509
+ }));
1510
+ class l extends N.Component {
1511
+ constructor() {
1512
+ super(...arguments);
1513
+ p(this, "_DESIGN_BOX", !0);
1514
+ p(this, "_NODE_MODEL", r);
1515
+ p(this, "_NODE_ID", r.id);
1516
+ p(this, "_UNIQUE_ID", `${r.id}_${W()}`);
1517
+ p(this, "_STATUS");
1518
+ p(this, "_design_target_component", N.createRef());
1519
+ p(this, "_dom");
1520
+ }
1521
+ componentDidMount() {
1522
+ s.instanceManager.add(r.id, this);
1523
+ }
1524
+ getTargetComponentRef() {
1525
+ return this._design_target_component;
1526
+ }
1527
+ componentWillUnmount() {
1528
+ this._STATUS = "DESTROY", s.instanceManager.remove(r.id, this);
1529
+ }
1530
+ getDom() {
1531
+ var $, C, v, a;
1532
+ if (((C = ($ = r.material) == null ? void 0 : $.value.advanceCustom) == null ? void 0 : C.autoGetDom) ?? !0) {
1533
+ const u = pt(this), f = (v = r.material) == null ? void 0 : v.value.rootSelector;
1534
+ return f && ((a = u == null ? void 0 : u.querySelector) == null ? void 0 : a.call(u, f)) || u;
1535
+ } else
1536
+ return this._dom;
1537
+ }
1538
+ render() {
1539
+ var d, m, g, b;
1540
+ const { children: _ = [], onlyRenderChild: $, ...C } = this.props, v = {
1541
+ ...C,
1542
+ ref: (E) => {
1543
+ this._design_target_component.current = E;
1544
+ }
1545
+ };
1546
+ let a = _;
1547
+ if (te(_) || (a = [_]), !!!a.filter(Boolean).length && (r.isContainer() || r.value.componentName === j.ROOT_CONTAINER)) {
1548
+ const E = (m = (d = r.material) == null ? void 0 : d.value.advanceCustom) == null ? void 0 : m.dropPlaceholder;
1549
+ a.push(
1550
+ N.createElement(E || s.dropPlaceholder, {
1551
+ node: r
1552
+ })
1553
+ );
1554
+ }
1555
+ return $ ? a : ((b = (g = r.material) == null ? void 0 : g.value.advanceCustom) == null ? void 0 : b.autoGetDom) ?? !0 ? N.createElement(o, v, ...a) : N.createElement(
1556
+ o,
1557
+ {
1558
+ ...v,
1559
+ // 注入到组件中, 配合设计器使用
1560
+ $SET_DOM: (x) => {
1561
+ this._dom = x;
1562
+ }
1563
+ },
1564
+ ...a
1565
+ );
1566
+ }
1567
+ }
1568
+ return N.forwardRef(function(h, _) {
1569
+ return N.createElement(
1570
+ ut,
1571
+ {
1572
+ node: r,
1573
+ targetComponent: l
1574
+ },
1575
+ N.createElement(l, {
1576
+ ref: _,
1577
+ ...h
1578
+ })
1579
+ );
1580
+ });
1581
+ });
1582
+ this._components = Object.assign(this._components, this.props.components), this.renderRef = N.createRef(), t.dropPlaceholder && (this.dropPlaceholder = t.dropPlaceholder);
1583
+ }
1584
+ updateComponents(t = {}) {
1585
+ this._components = Object.assign(this._components, t), this.forceUpdate();
1586
+ }
1587
+ componentDidMount() {
1588
+ var t, r;
1589
+ window.__CHAMN_RENDER_MODE = "DESIGN", this.updateComponents(this.props.components), (r = (t = this.props).onMount) == null || r.call(t, this);
1590
+ }
1591
+ getPageModel() {
1592
+ var t;
1593
+ return (t = this.renderRef.current) == null ? void 0 : t.state.pageModel;
1594
+ }
1595
+ rerender(t) {
1596
+ var r;
1597
+ return (r = this.renderRef.current) == null ? void 0 : r.rerender(t);
1598
+ }
1599
+ getInstancesById(t, r) {
1600
+ let s = [...this.instanceManager.get(t) || []];
1601
+ return r !== void 0 && (s = s.filter((o) => r === (o == null ? void 0 : o._UNIQUE_ID))), s;
1602
+ }
1603
+ getInstanceByDom(t) {
1604
+ const r = de(t);
1605
+ if (!r)
1606
+ return null;
1607
+ const s = fe(r);
1608
+ return (s == null ? void 0 : s.stateNode) || null;
1609
+ }
1610
+ getDomsById(t, r) {
1611
+ const s = this.getInstancesById(t), o = [];
1612
+ return s == null || s.forEach((c) => {
1613
+ var i;
1614
+ if ((c == null ? void 0 : c._STATUS) === "DESTROY")
1615
+ return;
1616
+ const l = c.getDom();
1617
+ if (l && !(l instanceof Text))
1618
+ if (r) {
1619
+ const S = Array.from(((i = l.querySelectorAll) == null ? void 0 : i.call(l, r)) || []);
1620
+ o.push(...S);
1621
+ } else
1622
+ o.push(l);
1623
+ }), o;
1624
+ }
1625
+ getDomRectById(t, r) {
1626
+ return this.getDomsById(t, r).map((c) => c == null ? void 0 : c.getBoundingClientRect()).filter(Boolean);
1627
+ }
1628
+ render() {
1629
+ const { props: t, onGetComponent: r } = this, { render: s, ...o } = t;
1630
+ return s && (s.ref.current = this), N.createElement(lt, {
1631
+ onGetComponent: r,
1632
+ ...o,
1633
+ components: this._components,
1634
+ // 拦截特殊属性配置, 配合设计模式使用
1635
+ /**
1636
+ * 可以对节点的一些配置数据做统一处理
1637
+ * 比如: fixedProps 强制将 fixedProps 内的值覆盖 node 本省的配置
1638
+ * 比如: 统一处理节点的 Condition 属性,控制节点是否显示
1639
+ * @param config
1640
+ * @param node
1641
+ * @returns
1642
+ */
1643
+ processNodeConfigHook: (c, l) => {
1644
+ var C, v;
1645
+ if (l.nodeType !== "NODE")
1646
+ return c;
1647
+ const { props: i, condition: S } = c;
1648
+ let y = { ...i };
1649
+ const h = ((C = l.value.configure) == null ? void 0 : C.devState) || {}, _ = (v = l.material) == null ? void 0 : v.value.fixedProps;
1650
+ if (_ !== void 0) {
1651
+ if (k(_))
1652
+ y = {
1653
+ ...y,
1654
+ ..._
1655
+ };
1656
+ else if (typeof _ == "function") {
1657
+ const a = _(y);
1658
+ y = {
1659
+ ...y,
1660
+ ...a
1661
+ };
1662
+ }
1663
+ }
1664
+ let $ = S;
1665
+ return h.condition === !1 && ($ = h.condition), {
1666
+ props: Ne(y, h.props || {}),
1667
+ condition: $
1668
+ };
1669
+ },
1670
+ renderMode: "design",
1671
+ ref: this.renderRef
1672
+ });
1673
+ }
1674
+ }
1675
+ const de = (n) => {
1676
+ if (!n)
1677
+ return null;
1678
+ const e = Object.keys(n).find((t) => t.startsWith("__reactInternalInstance$") || t.startsWith("__reactFiber$")) || "";
1679
+ return e ? n[e] : de(n.parentElement);
1680
+ }, fe = (n) => {
1681
+ var e;
1682
+ return n ? (e = n == null ? void 0 : n.stateNode) != null && e._DESIGN_BOX ? n : fe(n.return) : null;
1683
+ }, Lt = () => {
1684
+ const n = re(null);
1685
+ return {
1686
+ ref: n,
1687
+ rerender: function(...e) {
1688
+ n.current && n.current.rerender(...e);
1689
+ },
1690
+ getInstancesById(e, t) {
1691
+ var r;
1692
+ return ((r = n.current) == null ? void 0 : r.getInstancesById(e, t)) || [];
1693
+ },
1694
+ getInstanceByDom(e) {
1695
+ var t;
1696
+ return ((t = n.current) == null ? void 0 : t.getInstanceByDom(e)) || null;
1697
+ },
1698
+ getDomsById(e, t) {
1699
+ var r;
1700
+ return ((r = n.current) == null ? void 0 : r.getDomsById(e, t)) || [];
1701
+ },
1702
+ getDomRectById(e, t) {
1703
+ var r;
1704
+ return ((r = n.current) == null ? void 0 : r.getDomRectById(e, t)) || [];
1705
+ }
1706
+ };
1707
+ };
1708
+ class Tt {
1709
+ constructor(e, t) {
1710
+ p(this, "assets");
1711
+ p(this, "loadStatus");
1712
+ p(this, "win", window);
1713
+ p(this, "_onSuccessList", []);
1714
+ p(this, "_onErrorList", []);
1715
+ this.assets = JSON.parse(JSON.stringify(e || [])), this.loadStatus = "INIT", t != null && t.window && (this.win = t.window);
1716
+ }
1717
+ load(e) {
1718
+ const t = this.assets || [], r = [];
1719
+ for (let s = 0; s < t.length; s++) {
1720
+ const o = t[s];
1721
+ o.id || (o.id = W()), r.push(o.id);
1722
+ const c = o.resources.map((l) => l.src);
1723
+ c.length && J(c, o.id, {
1724
+ async: (e == null ? void 0 : e.async) ?? !1,
1725
+ before: (l, i) => (this.win.document.body.appendChild(i), !1)
1726
+ });
1727
+ }
1728
+ return new Promise((s, o) => {
1729
+ if (t.length === 0) {
1730
+ this._onSuccessList.forEach((c) => c()), s("");
1731
+ return;
1732
+ }
1733
+ J.ready(r, {
1734
+ success: () => {
1735
+ this._onSuccessList.forEach((c) => c()), s("");
1736
+ },
1737
+ error: (c) => {
1738
+ this._onErrorList.forEach((l) => l(c)), o(c);
1739
+ }
1740
+ });
1741
+ });
1742
+ }
1743
+ onSuccess(e) {
1744
+ return this._onSuccessList.push(e), this;
1745
+ }
1746
+ onError(e) {
1747
+ return this._onErrorList.push(e), this;
1748
+ }
1749
+ }
1750
+ export {
1751
+ Tt as AssetLoader,
1752
+ ht as ComponentInstanceManager,
1753
+ F as DYNAMIC_COMPONENT_TYPE,
1754
+ mt as DefaultDropPlaceholder,
1755
+ Qe as DefineReactAdapter,
1756
+ It as DesignRender,
1757
+ qe as INNER_EVENT_LIST,
1758
+ We as InnerPropList,
1759
+ le as ON_DID_RENDER,
1760
+ ue as ON_WILL_DESTROY,
1761
+ wt as ReactAdapter,
1762
+ ie as RefManager,
1763
+ lt as Render,
1764
+ Ve as canAcceptsRef,
1765
+ Rt as collectVariable,
1766
+ ke as compWrapper,
1767
+ B as convertCodeStringToFunction,
1768
+ Fe as findComponentByChainRefer,
1769
+ Mt as flatObject,
1770
+ Be as formatSourceStylePropertyName,
1771
+ Pe as getAdapter,
1772
+ xt as getCSSTextValue,
1773
+ Ot as getComponentsLibs,
1774
+ Z as getInheritObj,
1775
+ Ge as getMatchVal,
1776
+ Q as getNodeCssClassName,
1777
+ ae as getObjFromArrayMap,
1778
+ Dt as getThirdLibs,
1779
+ vt as isClass,
1780
+ I as runExpression,
1781
+ je as shouldConstruct,
1782
+ Lt as useDesignRender,
1783
+ At as useRender
1784
+ };
1785
+ //# sourceMappingURL=index.es.js.map