ddd-react 1.3.0 → 1.3.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.js ADDED
@@ -0,0 +1,558 @@
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";
3
+ function v(e, t) {
4
+ if (e === null || t === null || e === void 0 || t === void 0)
5
+ return e === t;
6
+ if (typeof e != typeof t)
7
+ return !1;
8
+ if (Object.is(e, t))
9
+ return !0;
10
+ if (typeof e == "object") {
11
+ if (e.constructor !== t.constructor)
12
+ return !1;
13
+ if (Array.isArray(e)) {
14
+ if (e.length !== t.length)
15
+ return !1;
16
+ for (let r = 0; r < e.length; ++r)
17
+ if (!v(e[r], t[r]))
18
+ return !1;
19
+ return !0;
20
+ }
21
+ if (e.constructor === RegExp)
22
+ return e.source === t.source && e.flags === t.flags;
23
+ if (e.valueOf !== Object.prototype.valueOf)
24
+ return e.valueOf() === t.valueOf();
25
+ if (e.toString !== Object.prototype.toString)
26
+ return e.toString() === t.toString();
27
+ const n = Object.keys(e);
28
+ if (n.length !== Object.keys(t).length)
29
+ return !1;
30
+ for (let r = 0; r < n.length; ++r)
31
+ if (!Object.prototype.hasOwnProperty.call(t, n[r]))
32
+ return !1;
33
+ for (let r = 0; r < n.length; ++r) {
34
+ const s = n[r];
35
+ if (!(s === "_owner" && e.$$typeof) && !v(e[s], t[s]))
36
+ return !1;
37
+ }
38
+ return !0;
39
+ }
40
+ return !1;
41
+ }
42
+ function S(e, t, n, r = null) {
43
+ function s(o) {
44
+ const i = o;
45
+ r ? t.call(r, i) : t(i);
46
+ }
47
+ return n.addEventListener(e, s), s;
48
+ }
49
+ function $(e = {}, t, n = null) {
50
+ const r = {};
51
+ return Object.entries(e).forEach(([s, o]) => {
52
+ r[s] = S(
53
+ s,
54
+ o,
55
+ t,
56
+ n
57
+ );
58
+ }), r;
59
+ }
60
+ function q(e = {}, t) {
61
+ Object.entries(e).forEach(([n, r]) => {
62
+ t.removeEventListener(n, r);
63
+ });
64
+ }
65
+ function p(e) {
66
+ const { type: t } = e;
67
+ switch (t) {
68
+ case c.TEXT: {
69
+ G(e);
70
+ break;
71
+ }
72
+ case c.ELEMENT: {
73
+ W(e);
74
+ break;
75
+ }
76
+ case c.FRAGMENT: {
77
+ B(e);
78
+ break;
79
+ }
80
+ case c.COMPONENT: {
81
+ e.component?.unmount();
82
+ break;
83
+ }
84
+ case c.PORTAL: {
85
+ X(e);
86
+ break;
87
+ }
88
+ default:
89
+ throw new Error(`Can't destroy DOM of type: ${t}`);
90
+ }
91
+ delete e.el;
92
+ }
93
+ function G(e) {
94
+ const { el: t } = e;
95
+ t && t.remove();
96
+ }
97
+ function W(e) {
98
+ const { el: t, children: n, listeners: r, props: s } = e;
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);
100
+ }
101
+ function B(e) {
102
+ const { children: t } = e;
103
+ t && t.forEach(p);
104
+ }
105
+ function X(e) {
106
+ const { children: t } = e;
107
+ t && t.forEach(p);
108
+ }
109
+ function L(e, t, n) {
110
+ e.style[t] = n.toString();
111
+ }
112
+ function _(e, t) {
113
+ e.style[t] = null;
114
+ }
115
+ function J(e, t) {
116
+ const { class: n, style: r, ...s } = t;
117
+ n && K(e, n), r && Object.entries(r).forEach(([o, i]) => {
118
+ L(e, o, i);
119
+ });
120
+ for (const [o, i] of Object.entries(s))
121
+ w(e, o, i);
122
+ }
123
+ function K(e, t) {
124
+ if (e instanceof SVGElement) {
125
+ e.removeAttribute("class"), typeof t == "string" ? e.setAttribute("class", t) : Array.isArray(t) && e.classList.add(...t);
126
+ return;
127
+ }
128
+ e.className = "", typeof t == "string" ? e.className = t : Array.isArray(t) && e.classList.add(...t);
129
+ }
130
+ function w(e, t, n) {
131
+ n == null ? C(e, t) : e.setAttribute(t, String(n));
132
+ }
133
+ function C(e, t) {
134
+ e[t] = null, e.removeAttribute(t);
135
+ }
136
+ let O = !1;
137
+ const P = [];
138
+ function E(e) {
139
+ P.push(e), Y();
140
+ }
141
+ function Y() {
142
+ O || (O = !0, queueMicrotask(H));
143
+ }
144
+ function H() {
145
+ for (; P.length > 0; ) {
146
+ const e = P.shift();
147
+ let t;
148
+ try {
149
+ t = e();
150
+ } catch (n) {
151
+ console.error(`[scheduler]: ${n}`);
152
+ continue;
153
+ }
154
+ Promise.resolve(t).then(
155
+ () => {
156
+ },
157
+ (n) => {
158
+ console.error(`[scheduler]: ${n}`);
159
+ }
160
+ );
161
+ }
162
+ O = !1;
163
+ }
164
+ function A(e) {
165
+ const { on: t = {}, ...n } = e.props;
166
+ return delete n.key, { props: n, events: t };
167
+ }
168
+ function h(e, t, n = null, r = null) {
169
+ switch (e.type) {
170
+ case c.TEXT: {
171
+ z(e, t, n);
172
+ break;
173
+ }
174
+ case c.ELEMENT: {
175
+ Z(e, t, n, r);
176
+ break;
177
+ }
178
+ case c.FRAGMENT: {
179
+ Q(e, t, n, r);
180
+ break;
181
+ }
182
+ case c.COMPONENT: {
183
+ tt(e, t, n, r);
184
+ const s = e.component;
185
+ s && E(() => s.onMount());
186
+ break;
187
+ }
188
+ case c.PORTAL: {
189
+ et(e, r);
190
+ break;
191
+ }
192
+ default:
193
+ throw new Error(`Can't mount DOM of type: ${e.type}`);
194
+ }
195
+ }
196
+ function z(e, t, n) {
197
+ const { value: r } = e, s = document.createTextNode(r);
198
+ e.el = s, j(s, t, n);
199
+ }
200
+ function Q(e, t, n, r) {
201
+ const { children: s } = e;
202
+ e.el = t, s?.forEach((o, i) => {
203
+ h(o, t, n != null ? n + i : null, r);
204
+ });
205
+ }
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);
211
+ }
212
+ function V(e, t, n) {
213
+ const { props: r, events: s } = A(t);
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);
215
+ }
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;
219
+ }
220
+ function j(e, t, n) {
221
+ if (n == null) {
222
+ t.append(e);
223
+ return;
224
+ }
225
+ if (n < 0)
226
+ throw new Error(`Index must be a positive integer, got ${n}`);
227
+ const r = t.childNodes;
228
+ n >= r.length ? t.append(e) : t.insertBefore(e, r[n]);
229
+ }
230
+ function et(e, t) {
231
+ const { children: n, container: r } = e;
232
+ n?.forEach((s) => {
233
+ h(s, r, null, t);
234
+ });
235
+ }
236
+ function D(e, t) {
237
+ if (e.type !== t.type)
238
+ return !1;
239
+ if (e.type === c.ELEMENT) {
240
+ const n = e, r = t, {
241
+ tag: s,
242
+ props: { key: o }
243
+ } = n, {
244
+ tag: i,
245
+ props: { key: u }
246
+ } = r;
247
+ return s === i && o === u;
248
+ }
249
+ if (e.type === c.COMPONENT) {
250
+ const n = e, r = t, { tag: s } = n, { tag: o } = r;
251
+ return s === o;
252
+ }
253
+ if (e.type === c.PORTAL) {
254
+ const n = e, r = t;
255
+ return n.container === r.container;
256
+ }
257
+ return !0;
258
+ }
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);
263
+ return {
264
+ added: s,
265
+ removed: n.filter((i) => !(i in t)),
266
+ updated: o
267
+ };
268
+ }
269
+ function nt(e) {
270
+ return e !== "";
271
+ }
272
+ function N(e) {
273
+ return nt(e.trim());
274
+ }
275
+ function m(e, t, n, r = null) {
276
+ if (!D(e, t)) {
277
+ const s = rt(n, e.el);
278
+ return p(e), h(t, n, s, r), t;
279
+ }
280
+ switch (t.el = e.el, t.type) {
281
+ case c.TEXT:
282
+ return st(e, t), t;
283
+ case c.ELEMENT: {
284
+ ot(e, t, r);
285
+ break;
286
+ }
287
+ case c.COMPONENT: {
288
+ lt(e, t);
289
+ break;
290
+ }
291
+ case c.PORTAL: {
292
+ at(e, t, r);
293
+ break;
294
+ }
295
+ }
296
+ return R(e, t, r), t;
297
+ }
298
+ function rt(e, t) {
299
+ if (!t) return null;
300
+ const n = Array.from(e.childNodes).indexOf(t);
301
+ return n < 0 ? null : n;
302
+ }
303
+ function st(e, t) {
304
+ const n = e.el, { value: r } = e, { value: s } = t;
305
+ r !== s && n && (n.nodeValue = s);
306
+ }
307
+ function ot(e, t, n) {
308
+ const r = e.el, {
309
+ class: s,
310
+ style: o,
311
+ on: i,
312
+ ...u
313
+ } = e.props ?? {}, {
314
+ class: l,
315
+ style: f,
316
+ on: a,
317
+ ...d
318
+ } = t.props ?? {}, { listeners: b } = e;
319
+ it(r, u, d), ct(r, s, l), ft(
320
+ r,
321
+ o,
322
+ f
323
+ ), t.listeners = ut(
324
+ r,
325
+ b,
326
+ i ?? {},
327
+ a ?? {},
328
+ n
329
+ );
330
+ }
331
+ function it(e, t = {}, n = {}) {
332
+ const r = t.ref, s = n.ref;
333
+ r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current = e));
334
+ const o = { ...t }, i = { ...n };
335
+ delete o.ref, delete i.ref;
336
+ const { added: u, removed: l, updated: f } = T(o, i);
337
+ for (const a of l)
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);
361
+ }
362
+ const l = {};
363
+ for (const f of i.concat(u))
364
+ l[f] = S(
365
+ f,
366
+ r[f],
367
+ e,
368
+ s
369
+ );
370
+ return l;
371
+ }
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);
378
+ }
379
+ for (const l of i)
380
+ switch (l.op) {
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));
384
+ break;
385
+ }
386
+ case y.REMOVE: {
387
+ const { item: f } = l;
388
+ p(f);
389
+ break;
390
+ }
391
+ case y.ADD: {
392
+ const { index: f, item: a } = l;
393
+ h(a, o, f + u, n);
394
+ break;
395
+ }
396
+ }
397
+ }
398
+ function lt(e, t) {
399
+ const { component: n } = e, { props: r } = A(t);
400
+ n.updateProps(r), t.component = n, t.el = n.firstElement;
401
+ }
402
+ function at(e, t, n) {
403
+ if (e.container !== t.container) {
404
+ p(e), h(t, document.body, null, n);
405
+ return;
406
+ }
407
+ R(e, t, n);
408
+ }
409
+ const ht = (e) => e.constructor.name.includes("Provider"), pt = (e) => e.constructor.name.includes("Consumer");
410
+ class k {
411
+ constructor(t = {}, n) {
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;
413
+ }
414
+ addDependency({ consumer: t }) {
415
+ this.dependencies.some((n) => n.consumer === t) || (this.dependencies.push({ consumer: t }), t.subscribedProvider = this);
416
+ }
417
+ removeDependency({ consumer: t }) {
418
+ const n = this.dependencies.findIndex((r) => r.consumer === t);
419
+ n !== -1 && (this.dependencies.splice(n, 1), t.subscribedProvider = null);
420
+ }
421
+ notify() {
422
+ this.dependencies.forEach(({ consumer: t }) => {
423
+ t.isMounted && t.updateContext() && t.patch();
424
+ });
425
+ }
426
+ onMount() {
427
+ return Promise.resolve();
428
+ }
429
+ onUnmount() {
430
+ return Promise.resolve();
431
+ }
432
+ onUpdate() {
433
+ return Promise.resolve();
434
+ }
435
+ onWillUnmount() {
436
+ return Promise.resolve();
437
+ }
438
+ get elements() {
439
+ return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? g(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
440
+ }
441
+ get firstElement() {
442
+ return this.elements[0];
443
+ }
444
+ get offset() {
445
+ return this.vdom?.type === c.FRAGMENT && this.hostEl && this.firstElement ? Array.from(this.hostEl.children).indexOf(this.firstElement) : 0;
446
+ }
447
+ updateProps(t) {
448
+ const n = { ...this.props, ...t }, r = this.props;
449
+ this.props = n;
450
+ let s = this.updateContext();
451
+ v(r, n) && !s || (ht(this) && this.notify(), this.patch());
452
+ }
453
+ setState(t) {
454
+ typeof t == "function" ? this.state = {
455
+ ...this.state,
456
+ ...t(this.state, this.props)
457
+ } : this.state = { ...this.state, ...t }, this.patch();
458
+ }
459
+ mount(t, n = null) {
460
+ if (this.isMounted)
461
+ throw new Error("Component is already mounted");
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;
463
+ }
464
+ unmount() {
465
+ this.isMounted && (E(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
466
+ t.subscribedProvider = null;
467
+ }), this.dependencies = [], this.vdom && p(this.vdom), E(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
468
+ }
469
+ patch() {
470
+ if (!this.isMounted || !this.hostEl || !this.vdom)
471
+ return;
472
+ const t = this.render();
473
+ this.vdom = m(this.vdom, t, this.hostEl, this), E(() => this.onUpdate());
474
+ }
475
+ updateContext() {
476
+ const t = Object.getPrototypeOf(this).constructor.contextType;
477
+ let n = this.parent;
478
+ if (t != null) {
479
+ for (; n; ) {
480
+ if (Object.getPrototypeOf(n).constructor === t.Provider)
481
+ return this.context = n.props.value, !0;
482
+ n = n.parent;
483
+ }
484
+ n == null && (this.context = t.defaultValue);
485
+ }
486
+ return !1;
487
+ }
488
+ subscribeToProvider() {
489
+ const t = Object.getPrototypeOf(this).constructor.contextType;
490
+ if (!t)
491
+ return;
492
+ let n = this.parent;
493
+ for (; n; ) {
494
+ if (Object.getPrototypeOf(n).constructor === t.Provider) {
495
+ n.addDependency({ consumer: this });
496
+ break;
497
+ }
498
+ n = n.parent;
499
+ }
500
+ }
501
+ }
502
+ function yt(e) {
503
+ class t extends k {
504
+ render() {
505
+ let o = [];
506
+ return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], U(o);
507
+ }
508
+ }
509
+ const r = class r extends k {
510
+ render() {
511
+ let o = this.props.children;
512
+ if (Array.isArray(o))
513
+ if (o.length === 1 && typeof o[0] == "function")
514
+ o = o[0];
515
+ else
516
+ throw new Error(
517
+ "Consumer: expected single function child, got array"
518
+ );
519
+ if (typeof o != "function")
520
+ throw new Error("Consumer: children is not a function");
521
+ return o(this.context);
522
+ }
523
+ };
524
+ r.contextType = {
525
+ Provider: t,
526
+ defaultValue: e
527
+ };
528
+ let n = r;
529
+ return {
530
+ Provider: t,
531
+ Consumer: n,
532
+ defaultValue: e
533
+ };
534
+ }
535
+ function Et(e, t) {
536
+ if (!t)
537
+ throw new Error("Container element is not provided for rendering.");
538
+ h(e, t);
539
+ }
540
+ function bt(e = null) {
541
+ return {
542
+ current: e
543
+ };
544
+ }
545
+ function gt(e, t) {
546
+ const n = Array.isArray(e) ? e : [e];
547
+ return I(n, t);
548
+ }
549
+ export {
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
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.js";
2
+ export {
3
+ x as Fragment,
4
+ a as jsxDEV
5
+ };
@@ -0,0 +1 @@
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.0",
3
+ "version": "1.3.2",
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",