ddd-react 1.3.1 → 1.3.3

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,173 @@
1
+ const c = {
2
+ ADD: "add",
3
+ REMOVE: "remove",
4
+ MOVE: "move",
5
+ NOOP: "noop"
6
+ }, o = {
7
+ TEXT: "text",
8
+ ELEMENT: "element",
9
+ FRAGMENT: "fragment",
10
+ COMPONENT: "component",
11
+ PORTAL: "portal"
12
+ };
13
+ function u(i) {
14
+ return i.filter((t) => t != null);
15
+ }
16
+ function m(i, t) {
17
+ return {
18
+ added: t.filter((e) => !i.includes(e)),
19
+ removed: i.filter((e) => !t.includes(e))
20
+ };
21
+ }
22
+ class p {
23
+ #t = [];
24
+ #e = [];
25
+ #n;
26
+ constructor(t, e) {
27
+ this.#t = [...t], this.#e = t.map((n, s) => s), this.#n = e;
28
+ }
29
+ isAddition(t, e) {
30
+ return this.findIndexFrom(t, e) === -1;
31
+ }
32
+ isNoop(t, e) {
33
+ if (t >= this.length)
34
+ return !1;
35
+ const n = this.#t[t], s = e[t];
36
+ return this.#n(n, s);
37
+ }
38
+ isRemoval(t, e) {
39
+ if (t >= this.length)
40
+ return !1;
41
+ const n = this.#t[t];
42
+ return e.findIndex(
43
+ (r) => this.#n(n, r)
44
+ ) === -1;
45
+ }
46
+ findIndexFrom(t, e) {
47
+ for (let n = e; n < this.length; n++)
48
+ if (this.#n(t, this.#t[n]))
49
+ return n;
50
+ return -1;
51
+ }
52
+ originalIndexAt(t) {
53
+ return this.#e[t];
54
+ }
55
+ noopItem(t) {
56
+ return {
57
+ op: c.NOOP,
58
+ originalIndex: this.originalIndexAt(t),
59
+ index: t,
60
+ item: this.#t[t]
61
+ };
62
+ }
63
+ removeItemsAfter(t) {
64
+ const e = [];
65
+ for (; this.length > t; )
66
+ e.push(this.removeItem(t));
67
+ return e;
68
+ }
69
+ removeItem(t) {
70
+ const e = {
71
+ op: c.REMOVE,
72
+ index: t,
73
+ item: this.#t[t]
74
+ };
75
+ return this.#t.splice(t, 1), this.#e.splice(t, 1), e;
76
+ }
77
+ addItem(t, e) {
78
+ const n = {
79
+ op: c.ADD,
80
+ index: e,
81
+ item: t
82
+ };
83
+ return this.#t.splice(e, 0, t), this.#e.splice(e, 0, -1), n;
84
+ }
85
+ moveItem(t, e) {
86
+ const n = this.findIndexFrom(t, e), s = {
87
+ op: c.MOVE,
88
+ originalIndex: this.originalIndexAt(n),
89
+ from: n,
90
+ index: e,
91
+ item: this.#t[n]
92
+ }, [r] = this.#t.splice(n, 1);
93
+ this.#t.splice(e, 0, r);
94
+ const [h] = this.#e.splice(n, 1);
95
+ return this.#e.splice(e, 0, h), s;
96
+ }
97
+ get length() {
98
+ return this.#t.length;
99
+ }
100
+ }
101
+ function d(i, t, e = (n, s) => n === s) {
102
+ const n = [], s = new p(i, e);
103
+ for (let r = 0; r < t.length; r++) {
104
+ if (s.isRemoval(r, t)) {
105
+ n.push(s.removeItem(r)), r--;
106
+ continue;
107
+ }
108
+ if (s.isNoop(r, t)) {
109
+ n.push(s.noopItem(r));
110
+ continue;
111
+ }
112
+ const h = t[r];
113
+ if (s.isAddition(h, r)) {
114
+ n.push(s.addItem(h, r));
115
+ continue;
116
+ }
117
+ n.push(s.moveItem(h, r));
118
+ }
119
+ return n.push(...s.removeItemsAfter(t.length)), n;
120
+ }
121
+ function I(i, t = {}, e = []) {
122
+ const n = typeof i == "string" ? o.ELEMENT : o.COMPONENT;
123
+ return {
124
+ tag: i,
125
+ props: t,
126
+ type: n,
127
+ children: l(u(e))
128
+ };
129
+ }
130
+ function a(i) {
131
+ return {
132
+ type: o.TEXT,
133
+ value: i,
134
+ props: {}
135
+ };
136
+ }
137
+ function g(i) {
138
+ return {
139
+ type: o.FRAGMENT,
140
+ children: l(u(i)),
141
+ props: {}
142
+ };
143
+ }
144
+ function E(i, t) {
145
+ return {
146
+ type: o.PORTAL,
147
+ children: l(u(i)),
148
+ props: {},
149
+ container: t
150
+ };
151
+ }
152
+ function l(i) {
153
+ return i.map((t) => typeof t == "string" ? a(t) : t);
154
+ }
155
+ function f(i) {
156
+ if (!i.children)
157
+ return [];
158
+ const t = [];
159
+ for (const e of i.children)
160
+ e.type === o.FRAGMENT ? t.push(...f(e)) : t.push(e);
161
+ return t;
162
+ }
163
+ export {
164
+ c as A,
165
+ o as D,
166
+ d as a,
167
+ m as b,
168
+ E as c,
169
+ I as d,
170
+ f as e,
171
+ a as f,
172
+ g as h
173
+ };
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { D as c, e as g, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
2
+ import { d as Pt, f as mt } from "./h-BbaMkkC7.mjs";
1
3
  function v(e, t) {
2
4
  if (e === null || t === null || e === void 0 || t === void 0)
3
5
  return e === t;
@@ -37,54 +39,42 @@ function v(e, t) {
37
39
  }
38
40
  return !1;
39
41
  }
40
- function R(e, t, n, r = null) {
41
- function s(i) {
42
- const o = i;
43
- r ? t.call(r, o) : t(o);
42
+ function S(e, t, n, r = null) {
43
+ function s(o) {
44
+ const i = o;
45
+ r ? t.call(r, i) : t(i);
44
46
  }
45
47
  return n.addEventListener(e, s), s;
46
48
  }
47
- function F(e = {}, t, n = null) {
49
+ function $(e = {}, t, n = null) {
48
50
  const r = {};
49
- return Object.entries(e).forEach(([s, i]) => {
50
- r[s] = R(
51
+ return Object.entries(e).forEach(([s, o]) => {
52
+ r[s] = S(
51
53
  s,
52
- i,
54
+ o,
53
55
  t,
54
56
  n
55
57
  );
56
58
  }), r;
57
59
  }
58
- function G(e = {}, t) {
60
+ function q(e = {}, t) {
59
61
  Object.entries(e).forEach(([n, r]) => {
60
62
  t.removeEventListener(n, r);
61
63
  });
62
64
  }
63
- const h = {
64
- ADD: "add",
65
- REMOVE: "remove",
66
- MOVE: "move",
67
- NOOP: "noop"
68
- }, c = {
69
- TEXT: "text",
70
- ELEMENT: "element",
71
- FRAGMENT: "fragment",
72
- COMPONENT: "component",
73
- PORTAL: "portal"
74
- };
75
- function d(e) {
65
+ function p(e) {
76
66
  const { type: t } = e;
77
67
  switch (t) {
78
68
  case c.TEXT: {
79
- q(e);
69
+ G(e);
80
70
  break;
81
71
  }
82
72
  case c.ELEMENT: {
83
- U(e);
73
+ W(e);
84
74
  break;
85
75
  }
86
76
  case c.FRAGMENT: {
87
- $(e);
77
+ B(e);
88
78
  break;
89
79
  }
90
80
  case c.COMPONENT: {
@@ -92,7 +82,7 @@ function d(e) {
92
82
  break;
93
83
  }
94
84
  case c.PORTAL: {
95
- W(e);
85
+ X(e);
96
86
  break;
97
87
  }
98
88
  default:
@@ -100,210 +90,60 @@ function d(e) {
100
90
  }
101
91
  delete e.el;
102
92
  }
103
- function q(e) {
93
+ function G(e) {
104
94
  const { el: t } = e;
105
95
  t && t.remove();
106
96
  }
107
- function U(e) {
97
+ function W(e) {
108
98
  const { el: t, children: n, listeners: r, props: s } = e;
109
- s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), t && t.remove(), n && n.forEach(d), r && t && (G(r, t), delete e.listeners);
99
+ s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), t && t.remove(), n && n.forEach(p), r && t && (q(r, t), delete e.listeners);
110
100
  }
111
- function $(e) {
101
+ function B(e) {
112
102
  const { children: t } = e;
113
- t && t.forEach(d);
103
+ t && t.forEach(p);
114
104
  }
115
- function W(e) {
105
+ function X(e) {
116
106
  const { children: t } = e;
117
- t && t.forEach(d);
118
- }
119
- function N(e) {
120
- return e.filter((t) => t != null);
121
- }
122
- function X(e, t) {
123
- return {
124
- added: t.filter((n) => !e.includes(n)),
125
- removed: e.filter((n) => !t.includes(n))
126
- };
127
- }
128
- class _ {
129
- #t = [];
130
- #e = [];
131
- #n;
132
- constructor(t, n) {
133
- this.#t = [...t], this.#e = t.map((r, s) => s), this.#n = n;
134
- }
135
- isAddition(t, n) {
136
- return this.findIndexFrom(t, n) === -1;
137
- }
138
- isNoop(t, n) {
139
- if (t >= this.length)
140
- return !1;
141
- const r = this.#t[t], s = n[t];
142
- return this.#n(r, s);
143
- }
144
- isRemoval(t, n) {
145
- if (t >= this.length)
146
- return !1;
147
- const r = this.#t[t];
148
- return n.findIndex(
149
- (i) => this.#n(r, i)
150
- ) === -1;
151
- }
152
- findIndexFrom(t, n) {
153
- for (let r = n; r < this.length; r++)
154
- if (this.#n(t, this.#t[r]))
155
- return r;
156
- return -1;
157
- }
158
- originalIndexAt(t) {
159
- return this.#e[t];
160
- }
161
- noopItem(t) {
162
- return {
163
- op: h.NOOP,
164
- originalIndex: this.originalIndexAt(t),
165
- index: t,
166
- item: this.#t[t]
167
- };
168
- }
169
- removeItemsAfter(t) {
170
- const n = [];
171
- for (; this.length > t; )
172
- n.push(this.removeItem(t));
173
- return n;
174
- }
175
- removeItem(t) {
176
- const n = {
177
- op: h.REMOVE,
178
- index: t,
179
- item: this.#t[t]
180
- };
181
- return this.#t.splice(t, 1), this.#e.splice(t, 1), n;
182
- }
183
- addItem(t, n) {
184
- const r = {
185
- op: h.ADD,
186
- index: n,
187
- item: t
188
- };
189
- return this.#t.splice(n, 0, t), this.#e.splice(n, 0, -1), r;
190
- }
191
- moveItem(t, n) {
192
- const r = this.findIndexFrom(t, n), s = {
193
- op: h.MOVE,
194
- originalIndex: this.originalIndexAt(r),
195
- from: r,
196
- index: n,
197
- item: this.#t[r]
198
- }, [i] = this.#t.splice(r, 1);
199
- this.#t.splice(n, 0, i);
200
- const [o] = this.#e.splice(r, 1);
201
- return this.#e.splice(n, 0, o), s;
202
- }
203
- get length() {
204
- return this.#t.length;
205
- }
206
- }
207
- function B(e, t, n = (r, s) => r === s) {
208
- const r = [], s = new _(e, n);
209
- for (let i = 0; i < t.length; i++) {
210
- if (s.isRemoval(i, t)) {
211
- r.push(s.removeItem(i)), i--;
212
- continue;
213
- }
214
- if (s.isNoop(i, t)) {
215
- r.push(s.noopItem(i));
216
- continue;
217
- }
218
- const o = t[i];
219
- if (s.isAddition(o, i)) {
220
- r.push(s.addItem(o, i));
221
- continue;
222
- }
223
- r.push(s.moveItem(o, i));
224
- }
225
- return r.push(...s.removeItemsAfter(t.length)), r;
226
- }
227
- function mt(e, t = {}, n = []) {
228
- const r = typeof e == "string" ? c.ELEMENT : c.COMPONENT;
229
- return {
230
- tag: e,
231
- props: t,
232
- type: r,
233
- children: T(N(n))
234
- };
235
- }
236
- function J(e) {
237
- return {
238
- type: c.TEXT,
239
- value: e,
240
- props: {}
241
- };
242
- }
243
- function K(e) {
244
- return {
245
- type: c.FRAGMENT,
246
- children: T(N(e)),
247
- props: {}
248
- };
249
- }
250
- function Y(e, t) {
251
- return {
252
- type: c.PORTAL,
253
- children: T(N(e)),
254
- props: {},
255
- container: t
256
- };
257
- }
258
- function T(e) {
259
- return e.map((t) => typeof t == "string" ? J(t) : t);
107
+ t && t.forEach(p);
260
108
  }
261
- function g(e) {
262
- if (!e.children)
263
- return [];
264
- const t = [];
265
- for (const n of e.children)
266
- n.type === c.FRAGMENT ? t.push(...g(n)) : t.push(n);
267
- return t;
268
- }
269
- function S(e, t, n) {
109
+ function L(e, t, n) {
270
110
  e.style[t] = n.toString();
271
111
  }
272
- function H(e, t) {
112
+ function _(e, t) {
273
113
  e.style[t] = null;
274
114
  }
275
- function z(e, t) {
115
+ function J(e, t) {
276
116
  const { class: n, style: r, ...s } = t;
277
- n && Q(e, n), r && Object.entries(r).forEach(([i, o]) => {
278
- S(e, i, o);
117
+ n && K(e, n), r && Object.entries(r).forEach(([o, i]) => {
118
+ L(e, o, i);
279
119
  });
280
- for (const [i, o] of Object.entries(s))
281
- C(e, i, o);
120
+ for (const [o, i] of Object.entries(s))
121
+ w(e, o, i);
282
122
  }
283
- function Q(e, t) {
123
+ function K(e, t) {
284
124
  if (e instanceof SVGElement) {
285
125
  e.removeAttribute("class"), typeof t == "string" ? e.setAttribute("class", t) : Array.isArray(t) && e.classList.add(...t);
286
126
  return;
287
127
  }
288
128
  e.className = "", typeof t == "string" ? e.className = t : Array.isArray(t) && e.classList.add(...t);
289
129
  }
290
- function C(e, t, n) {
291
- n == null ? w(e, t) : e.setAttribute(t, String(n));
130
+ function w(e, t, n) {
131
+ n == null ? C(e, t) : e.setAttribute(t, String(n));
292
132
  }
293
- function w(e, t) {
133
+ function C(e, t) {
294
134
  e[t] = null, e.removeAttribute(t);
295
135
  }
296
- let b = !1;
297
- const O = [];
298
- function y(e) {
299
- O.push(e), Z();
136
+ let O = !1;
137
+ const P = [];
138
+ function E(e) {
139
+ P.push(e), Y();
300
140
  }
301
- function Z() {
302
- b || (b = !0, queueMicrotask(V));
141
+ function Y() {
142
+ O || (O = !0, queueMicrotask(H));
303
143
  }
304
- function V() {
305
- for (; O.length > 0; ) {
306
- const e = O.shift();
144
+ function H() {
145
+ for (; P.length > 0; ) {
146
+ const e = P.shift();
307
147
  let t;
308
148
  try {
309
149
  t = e();
@@ -319,63 +159,63 @@ function V() {
319
159
  }
320
160
  );
321
161
  }
322
- b = !1;
162
+ O = !1;
323
163
  }
324
164
  function A(e) {
325
165
  const { on: t = {}, ...n } = e.props;
326
166
  return delete n.key, { props: n, events: t };
327
167
  }
328
- function p(e, t, n = null, r = null) {
168
+ function h(e, t, n = null, r = null) {
329
169
  switch (e.type) {
330
170
  case c.TEXT: {
331
- tt(e, t, n);
171
+ z(e, t, n);
332
172
  break;
333
173
  }
334
174
  case c.ELEMENT: {
335
- nt(e, t, n, r);
175
+ Z(e, t, n, r);
336
176
  break;
337
177
  }
338
178
  case c.FRAGMENT: {
339
- et(e, t, n, r);
179
+ Q(e, t, n, r);
340
180
  break;
341
181
  }
342
182
  case c.COMPONENT: {
343
- st(e, t, n, r);
183
+ tt(e, t, n, r);
344
184
  const s = e.component;
345
- s && y(() => s.onMount());
185
+ s && E(() => s.onMount());
346
186
  break;
347
187
  }
348
188
  case c.PORTAL: {
349
- it(e, r);
189
+ et(e, r);
350
190
  break;
351
191
  }
352
192
  default:
353
193
  throw new Error(`Can't mount DOM of type: ${e.type}`);
354
194
  }
355
195
  }
356
- function tt(e, t, n) {
196
+ function z(e, t, n) {
357
197
  const { value: r } = e, s = document.createTextNode(r);
358
198
  e.el = s, j(s, t, n);
359
199
  }
360
- function et(e, t, n, r) {
200
+ function Q(e, t, n, r) {
361
201
  const { children: s } = e;
362
- e.el = t, s?.forEach((i, o) => {
363
- p(i, t, n != null ? n + o : null, r);
202
+ e.el = t, s?.forEach((o, i) => {
203
+ h(o, t, n != null ? n + i : null, r);
364
204
  });
365
205
  }
366
- function nt(e, t, n, r) {
367
- const { tag: s, children: i } = e, f = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
368
- rt(f, e, r), e.el = f, i?.forEach((l) => {
369
- p(l, f, null, r);
370
- }), j(f, t, n);
206
+ function Z(e, t, n, r) {
207
+ const { tag: s, children: o } = e, u = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
208
+ V(u, e, r), e.el = u, o?.forEach((l) => {
209
+ h(l, u, null, r);
210
+ }), j(u, t, n);
371
211
  }
372
- function rt(e, t, n) {
212
+ function V(e, t, n) {
373
213
  const { props: r, events: s } = A(t);
374
- r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = e, delete r.ref), t.listeners = F(s, e, n), z(e, r);
214
+ r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = e, delete r.ref), t.listeners = $(s, e, n), J(e, r);
375
215
  }
376
- function st(e, t, n, r) {
377
- const s = e.tag, { props: i } = A(e), o = new s(i, r);
378
- o.mount(t, n), e.component = o, e.el = o.firstElement || null;
216
+ function tt(e, t, n, r) {
217
+ const s = e.tag, { props: o } = A(e), i = new s(o, r);
218
+ i.mount(t, n), e.component = i, e.el = i.firstElement || null;
379
219
  }
380
220
  function j(e, t, n) {
381
221
  if (n == null) {
@@ -387,10 +227,10 @@ function j(e, t, n) {
387
227
  const r = t.childNodes;
388
228
  n >= r.length ? t.append(e) : t.insertBefore(e, r[n]);
389
229
  }
390
- function it(e, t) {
230
+ function et(e, t) {
391
231
  const { children: n, container: r } = e;
392
232
  n?.forEach((s) => {
393
- p(s, r, null, t);
233
+ h(s, r, null, t);
394
234
  });
395
235
  }
396
236
  function D(e, t) {
@@ -399,16 +239,16 @@ function D(e, t) {
399
239
  if (e.type === c.ELEMENT) {
400
240
  const n = e, r = t, {
401
241
  tag: s,
402
- props: { key: i }
242
+ props: { key: o }
403
243
  } = n, {
404
- tag: o,
405
- props: { key: f }
244
+ tag: i,
245
+ props: { key: u }
406
246
  } = r;
407
- return s === o && i === f;
247
+ return s === i && o === u;
408
248
  }
409
249
  if (e.type === c.COMPONENT) {
410
- const n = e, r = t, { tag: s } = n, { tag: i } = r;
411
- return s === i;
250
+ const n = e, r = t, { tag: s } = n, { tag: o } = r;
251
+ return s === o;
412
252
  }
413
253
  if (e.type === c.PORTAL) {
414
254
  const n = e, r = t;
@@ -416,158 +256,158 @@ function D(e, t) {
416
256
  }
417
257
  return !0;
418
258
  }
419
- function M(e, t) {
420
- const n = Object.keys(e), r = Object.keys(t), s = [], i = [];
421
- for (const o of r)
422
- o in e ? e[o] !== t[o] && i.push(o) : s.push(o);
259
+ function T(e, t) {
260
+ const n = Object.keys(e), r = Object.keys(t), s = [], o = [];
261
+ for (const i of r)
262
+ i in e ? e[i] !== t[i] && o.push(i) : s.push(i);
423
263
  return {
424
264
  added: s,
425
- removed: n.filter((o) => !(o in t)),
426
- updated: i
265
+ removed: n.filter((i) => !(i in t)),
266
+ updated: o
427
267
  };
428
268
  }
429
- function ot(e) {
269
+ function nt(e) {
430
270
  return e !== "";
431
271
  }
432
- function k(e) {
433
- return ot(e.trim());
272
+ function N(e) {
273
+ return nt(e.trim());
434
274
  }
435
- function P(e, t, n, r = null) {
275
+ function m(e, t, n, r = null) {
436
276
  if (!D(e, t)) {
437
- const s = ct(n, e.el);
438
- return d(e), p(t, n, s, r), t;
277
+ const s = rt(n, e.el);
278
+ return p(e), h(t, n, s, r), t;
439
279
  }
440
280
  switch (t.el = e.el, t.type) {
441
281
  case c.TEXT:
442
- return ut(e, t), t;
282
+ return st(e, t), t;
443
283
  case c.ELEMENT: {
444
- ft(e, t, r);
284
+ ot(e, t, r);
445
285
  break;
446
286
  }
447
287
  case c.COMPONENT: {
448
- dt(e, t);
288
+ lt(e, t);
449
289
  break;
450
290
  }
451
291
  case c.PORTAL: {
452
- Et(e, t, r);
292
+ at(e, t, r);
453
293
  break;
454
294
  }
455
295
  }
456
- return x(e, t, r), t;
296
+ return R(e, t, r), t;
457
297
  }
458
- function ct(e, t) {
298
+ function rt(e, t) {
459
299
  if (!t) return null;
460
300
  const n = Array.from(e.childNodes).indexOf(t);
461
301
  return n < 0 ? null : n;
462
302
  }
463
- function ut(e, t) {
303
+ function st(e, t) {
464
304
  const n = e.el, { value: r } = e, { value: s } = t;
465
305
  r !== s && n && (n.nodeValue = s);
466
306
  }
467
- function ft(e, t, n) {
307
+ function ot(e, t, n) {
468
308
  const r = e.el, {
469
309
  class: s,
470
- style: i,
471
- on: o,
472
- ...f
310
+ style: o,
311
+ on: i,
312
+ ...u
473
313
  } = e.props ?? {}, {
474
314
  class: l,
475
- style: u,
315
+ style: f,
476
316
  on: a,
477
- ...E
478
- } = t.props ?? {}, { listeners: m } = e;
479
- lt(r, f, E), at(r, s, l), ht(
317
+ ...d
318
+ } = t.props ?? {}, { listeners: b } = e;
319
+ it(r, u, d), ct(r, s, l), ft(
480
320
  r,
481
- i,
482
- u
483
- ), t.listeners = pt(
321
+ o,
322
+ f
323
+ ), t.listeners = ut(
484
324
  r,
485
- m,
486
- o ?? {},
325
+ b,
326
+ i ?? {},
487
327
  a ?? {},
488
328
  n
489
329
  );
490
330
  }
491
- function lt(e, t = {}, n = {}) {
331
+ function it(e, t = {}, n = {}) {
492
332
  const r = t.ref, s = n.ref;
493
333
  r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current = e));
494
- const i = { ...t }, o = { ...n };
495
- delete i.ref, delete o.ref;
496
- const { added: f, removed: l, updated: u } = M(i, o);
334
+ const o = { ...t }, i = { ...n };
335
+ delete o.ref, delete i.ref;
336
+ const { added: u, removed: l, updated: f } = T(o, i);
497
337
  for (const a of l)
498
- w(e, a);
499
- for (const a of f.concat(u))
500
- C(e, a, o[a]);
501
- }
502
- function at(e, t, n) {
503
- const r = I(t), s = I(n), { added: i, removed: o } = X(r, s);
504
- o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
505
- }
506
- function I(e = "") {
507
- return Array.isArray(e) ? e.filter(k) : String(e).split(/(\s+)/).filter(k);
508
- }
509
- function ht(e, t = {}, n = {}) {
510
- const { added: r, removed: s, updated: i } = M(t, n);
511
- for (const o of s)
512
- H(e, o);
513
- for (const o of r.concat(i))
514
- S(e, o, n[o]);
515
- }
516
- function pt(e, t = {}, n = {}, r = {}, s = null) {
517
- const { removed: i, added: o, updated: f } = M(n, r);
518
- for (const u of i.concat(f)) {
519
- const a = t?.[u];
520
- a && e.removeEventListener(u, a);
338
+ C(e, a);
339
+ for (const a of u.concat(f))
340
+ w(e, a, i[a]);
341
+ }
342
+ function ct(e, t, n) {
343
+ const r = M(t), s = M(n), { added: o, removed: i } = F(r, s);
344
+ i.length > 0 && e.classList.remove(...i), o.length > 0 && e.classList.add(...o);
345
+ }
346
+ function M(e = "") {
347
+ return Array.isArray(e) ? e.filter(N) : String(e).split(/(\s+)/).filter(N);
348
+ }
349
+ function ft(e, t = {}, n = {}) {
350
+ const { added: r, removed: s, updated: o } = T(t, n);
351
+ for (const i of s)
352
+ _(e, i);
353
+ for (const i of r.concat(o))
354
+ L(e, i, n[i]);
355
+ }
356
+ function ut(e, t = {}, n = {}, r = {}, s = null) {
357
+ const { removed: o, added: i, updated: u } = T(n, r);
358
+ for (const f of o.concat(u)) {
359
+ const a = t?.[f];
360
+ a && e.removeEventListener(f, a);
521
361
  }
522
362
  const l = {};
523
- for (const u of o.concat(f))
524
- l[u] = R(
525
- u,
526
- r[u],
363
+ for (const f of i.concat(u))
364
+ l[f] = S(
365
+ f,
366
+ r[f],
527
367
  e,
528
368
  s
529
369
  );
530
370
  return l;
531
371
  }
532
- function x(e, t, n) {
533
- const r = g(e), s = g(t), i = e.el, o = B(r, s, D), f = n?.offset ?? 0;
534
- for (const l of o)
535
- if (l.op === h.NOOP) {
536
- const { originalIndex: u, index: a } = l;
537
- P(r[u], s[a], i, n);
372
+ function R(e, t, n) {
373
+ const r = g(e), s = g(t), o = e.el, i = x(r, s, D), u = n?.offset ?? 0;
374
+ for (const l of i)
375
+ if (l.op === y.NOOP) {
376
+ const { originalIndex: f, index: a } = l;
377
+ m(r[f], s[a], o, n);
538
378
  }
539
- for (const l of o)
379
+ for (const l of i)
540
380
  switch (l.op) {
541
- case h.MOVE: {
542
- const { from: u, index: a } = l, E = r[u].el, m = i.childNodes[a + f];
543
- E && (i.insertBefore(E, m), P(r[u], s[a], i, n));
381
+ case y.MOVE: {
382
+ const { from: f, index: a } = l, d = r[f].el, b = o.childNodes[a + u];
383
+ d && (o.insertBefore(d, b), m(r[f], s[a], o, n));
544
384
  break;
545
385
  }
546
- case h.REMOVE: {
547
- const { item: u } = l;
548
- d(u);
386
+ case y.REMOVE: {
387
+ const { item: f } = l;
388
+ p(f);
549
389
  break;
550
390
  }
551
- case h.ADD: {
552
- const { index: u, item: a } = l;
553
- p(a, i, u + f, n);
391
+ case y.ADD: {
392
+ const { index: f, item: a } = l;
393
+ h(a, o, f + u, n);
554
394
  break;
555
395
  }
556
396
  }
557
397
  }
558
- function dt(e, t) {
398
+ function lt(e, t) {
559
399
  const { component: n } = e, { props: r } = A(t);
560
400
  n.updateProps(r), t.component = n, t.el = n.firstElement;
561
401
  }
562
- function Et(e, t, n) {
402
+ function at(e, t, n) {
563
403
  if (e.container !== t.container) {
564
- d(e), p(t, document.body, null, n);
404
+ p(e), h(t, document.body, null, n);
565
405
  return;
566
406
  }
567
- x(e, t, n);
407
+ R(e, t, n);
568
408
  }
569
- const yt = (e) => e.constructor.name.includes("Provider"), gt = (e) => e.constructor.name.includes("Consumer");
570
- class L {
409
+ const ht = (e) => e.constructor.name.includes("Provider"), pt = (e) => e.constructor.name.includes("Consumer");
410
+ class k {
571
411
  constructor(t = {}, n) {
572
412
  this.isMounted = !1, this.vdom = null, this.hostEl = null, this.parent = null, this.state = {}, this.context = null, this.dependencies = [], this.subscribedProvider = null, this.props = t, this.parent = n;
573
413
  }
@@ -608,7 +448,7 @@ class L {
608
448
  const n = { ...this.props, ...t }, r = this.props;
609
449
  this.props = n;
610
450
  let s = this.updateContext();
611
- v(r, n) && !s || (yt(this) && this.notify(), this.patch());
451
+ v(r, n) && !s || (ht(this) && this.notify(), this.patch());
612
452
  }
613
453
  setState(t) {
614
454
  typeof t == "function" ? this.state = {
@@ -619,18 +459,18 @@ class L {
619
459
  mount(t, n = null) {
620
460
  if (this.isMounted)
621
461
  throw new Error("Component is already mounted");
622
- gt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext(), this.vdom = this.render(), p(this.vdom, t, n, this), this.hostEl = t, this.isMounted = !0;
462
+ pt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext(), this.vdom = this.render(), h(this.vdom, t, n, this), this.hostEl = t, this.isMounted = !0;
623
463
  }
624
464
  unmount() {
625
- this.isMounted && (y(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
465
+ this.isMounted && (E(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
626
466
  t.subscribedProvider = null;
627
- }), this.dependencies = [], this.vdom && d(this.vdom), y(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
467
+ }), this.dependencies = [], this.vdom && p(this.vdom), E(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
628
468
  }
629
469
  patch() {
630
470
  if (!this.isMounted || !this.hostEl || !this.vdom)
631
471
  return;
632
472
  const t = this.render();
633
- this.vdom = P(this.vdom, t, this.hostEl, this), y(() => this.onUpdate());
473
+ this.vdom = m(this.vdom, t, this.hostEl, this), E(() => this.onUpdate());
634
474
  }
635
475
  updateContext() {
636
476
  const t = Object.getPrototypeOf(this).constructor.contextType;
@@ -659,26 +499,26 @@ class L {
659
499
  }
660
500
  }
661
501
  }
662
- function vt(e) {
663
- class t extends L {
502
+ function yt(e) {
503
+ class t extends k {
664
504
  render() {
665
- let i = [];
666
- return Array.isArray(this.props.children) ? i = this.props.children : this.props.children ? i = [this.props.children] : i = [], K(i);
505
+ let o = [];
506
+ return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], U(o);
667
507
  }
668
508
  }
669
- const r = class r extends L {
509
+ const r = class r extends k {
670
510
  render() {
671
- let i = this.props.children;
672
- if (Array.isArray(i))
673
- if (i.length === 1 && typeof i[0] == "function")
674
- i = i[0];
511
+ let o = this.props.children;
512
+ if (Array.isArray(o))
513
+ if (o.length === 1 && typeof o[0] == "function")
514
+ o = o[0];
675
515
  else
676
516
  throw new Error(
677
517
  "Consumer: expected single function child, got array"
678
518
  );
679
- if (typeof i != "function")
519
+ if (typeof o != "function")
680
520
  throw new Error("Consumer: children is not a function");
681
- return i(this.context);
521
+ return o(this.context);
682
522
  }
683
523
  };
684
524
  r.contextType = {
@@ -692,27 +532,27 @@ function vt(e) {
692
532
  defaultValue: e
693
533
  };
694
534
  }
695
- function bt(e, t) {
535
+ function Et(e, t) {
696
536
  if (!t)
697
537
  throw new Error("Container element is not provided for rendering.");
698
- p(e, t);
538
+ h(e, t);
699
539
  }
700
- function Ot(e = null) {
540
+ function bt(e = null) {
701
541
  return {
702
542
  current: e
703
543
  };
704
544
  }
705
- function Pt(e, t) {
545
+ function gt(e, t) {
706
546
  const n = Array.isArray(e) ? e : [e];
707
- return Y(n, t);
547
+ return I(n, t);
708
548
  }
709
549
  export {
710
- L as Component,
711
- vt as createContext,
712
- Pt as createPortal,
713
- Ot as createRef,
714
- mt as h,
715
- K as hFragment,
716
- J as hString,
717
- bt as render
550
+ k as Component,
551
+ yt as createContext,
552
+ gt as createPortal,
553
+ bt as createRef,
554
+ Pt as h,
555
+ U as hFragment,
556
+ mt as hString,
557
+ Et as render
718
558
  };
@@ -0,0 +1 @@
1
+ export { Fragment, jsxDEV } from './jsx/jsx-dev-runtime';
@@ -0,0 +1,5 @@
1
+ import { Fragment as x, jsx as a } from "./jsx-runtime.mjs";
2
+ export {
3
+ x as Fragment,
4
+ a as jsxDEV
5
+ };
@@ -1,2 +1 @@
1
- export { jsx } from './jsx/jsx-runtime';
2
- export { jsxDEV } from './jsx/jsx-dev-runtime';
1
+ export { Fragment, jsx } from './jsx/jsx-runtime';
@@ -0,0 +1,38 @@
1
+ import { h as p, d as c, f as a } from "./h-BbaMkkC7.mjs";
2
+ const b = /* @__PURE__ */ Symbol("Fragment");
3
+ function l(n) {
4
+ return n == null || n === !1 ? null : typeof n == "string" || typeof n == "number" || typeof n == "boolean" ? a(String(n)) : n;
5
+ }
6
+ function j(n, o, ...r) {
7
+ if (n === b) {
8
+ const t = r.flat().map(l).filter((e) => e != null);
9
+ return p(t);
10
+ }
11
+ let f = {}, i = {};
12
+ if (o && Object.entries(o).forEach(([t, e]) => {
13
+ if (t.startsWith("on") && typeof e == "function") {
14
+ const s = t.slice(2).toLowerCase();
15
+ f[s] = e;
16
+ } else t === "ref" ? i.ref = e : t === "className" ? i.class = e : t === "style" && typeof e == "object" ? i.style = e : t === "colorInterpolationFilters" ? i["color-interpolation-filters"] = e : t === "viewbox" ? i.viewBox = e : t !== "children" && t !== "key" && (i[t] = e);
17
+ }), typeof n == "function")
18
+ try {
19
+ return n({ ...i, on: f });
20
+ } catch {
21
+ }
22
+ if (typeof n == "function" || typeof n == "object" && n != null && "render" in n) {
23
+ const t = { ...o ?? {} };
24
+ return r.length > 0 && (t.children = r.flat().map(l).filter((e) => e != null)), c(n, t);
25
+ }
26
+ f = {}, i = {}, o && Object.entries(o).forEach(([t, e]) => {
27
+ if (t.startsWith("on") && typeof e == "function") {
28
+ const s = t.slice(2).toLowerCase();
29
+ f[s] = e;
30
+ } else t === "ref" ? i.ref = e : t === "className" ? i.class = e : t === "style" && typeof e == "object" ? i.style = e : t === "colorInterpolationFilters" ? i["color-interpolation-filters"] = e : t === "filterUnits" ? i.filterUnits = e : t === "clipPath" ? i["clip-path"] = e : t === "floodOpacity" ? i["flood-opacity"] = e : t === "stdDeviation" ? i.stdDeviation = e : t === "viewbox" ? i.viewBox = e : t !== "children" && t !== "key" && (i[t] = e);
31
+ });
32
+ const m = r.flat().map(l).filter((t) => t != null);
33
+ return c(n, { ...i, on: f }, m);
34
+ }
35
+ export {
36
+ b as Fragment,
37
+ j as jsx
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",
@@ -15,6 +15,20 @@
15
15
  "frontend",
16
16
  "typescript"
17
17
  ],
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ },
23
+ "./jsx-runtime": {
24
+ "import": "./dist/jsx-runtime.js",
25
+ "types": "./dist/jsx-runtime.d.ts"
26
+ },
27
+ "./jsx-dev-runtime": {
28
+ "import": "./dist/jsx-dev-runtime.js",
29
+ "types": "./dist/jsx-dev-runtime.d.ts"
30
+ }
31
+ },
18
32
  "author": "DDD Team",
19
33
  "main": "dist/index.mjs",
20
34
  "types": "dist/index.d.ts",