ezh 0.1.0

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/lib/state.js ADDED
@@ -0,0 +1,354 @@
1
+ import { addComReader, q, refreshComReaders } from './elements';
2
+ const f = Symbol();
3
+ const j = Array.prototype;
4
+ const x = addComReader;
5
+ let l = (readerRecord, key) => {
6
+ l = refreshComReaders;
7
+ l(readerRecord, key);
8
+ };
9
+ export let t = false;
10
+ export const y = new WeakMap();
11
+ const o = (_) => {
12
+ return function (...m) {
13
+ const i = this.length;
14
+ let begin, c, k;
15
+ switch (_) {
16
+ case j.push:
17
+ begin = i;
18
+ c = begin + m.length;
19
+ k = i;
20
+ break;
21
+ case j.unshift:
22
+ begin = 0;
23
+ c = m.length;
24
+ k = i;
25
+ break;
26
+ case j.fill:
27
+ begin = m[1];
28
+ if (begin === undefined || begin <= -i) {
29
+ begin = 0;
30
+ }
31
+ else if (begin < 0) {
32
+ begin = i + begin;
33
+ }
34
+ c = m[2];
35
+ if (c === undefined || c > i) {
36
+ c = i;
37
+ }
38
+ else if (c <= -i) {
39
+ c = 0;
40
+ }
41
+ else if (c < 0) {
42
+ c = i + c;
43
+ }
44
+ k = c;
45
+ break;
46
+ case j.sort:
47
+ case j.reverse:
48
+ begin = c = 0;
49
+ k = i;
50
+ break;
51
+ case j.pop:
52
+ begin = c = i - 1;
53
+ k = i;
54
+ break;
55
+ case j.shift:
56
+ begin = c = 0;
57
+ k = i;
58
+ break;
59
+ default:
60
+ begin = m[0];
61
+ if (begin < 0) {
62
+ begin = i + begin;
63
+ }
64
+ c = m.length > 2 ? m.length - 2 : 0;
65
+ k = m[1];
66
+ if (k === undefined) {
67
+ k = i - begin;
68
+ }
69
+ k = k > 0 ? (k !== c ? i : begin + c) : (c ? i : begin);
70
+ c += begin;
71
+ }
72
+ const h = _.bind(this)(...m);
73
+ const n = this[f];
74
+ let p;
75
+ for (let b = begin; b < c; b++) {
76
+ p = this[b];
77
+ switch (typeof p) {
78
+ case 'object':
79
+ if (p) {
80
+ while (b < c) {
81
+ p = this[b];
82
+ if (p && !p[f]) {
83
+ this[b] = r(p);
84
+ }
85
+ b++;
86
+ }
87
+ break;
88
+ }
89
+ case 'undefined':
90
+ continue;
91
+ }
92
+ break;
93
+ }
94
+ if (i !== this.length) {
95
+ l(n, 'length');
96
+ }
97
+ l(n, Symbol.iterator);
98
+ return h;
99
+ };
100
+ };
101
+ const C = {
102
+ 'push': o(j.push),
103
+ 'unshift': o(j.unshift),
104
+ 'fill': o(j.fill),
105
+ 'sort': o(j.sort),
106
+ 'reverse': o(j.reverse),
107
+ 'pop': o(j.pop),
108
+ 'shift': o(j.shift),
109
+ 'splice': o(j.splice),
110
+ };
111
+ const E = (target, d) => {
112
+ const v = d.length;
113
+ const i = target.length;
114
+ let g;
115
+ for (let b = 0; b < v; b++) {
116
+ let a = d[b];
117
+ if (a && typeof a === 'object') {
118
+ do {
119
+ a = d[b];
120
+ g = target[b];
121
+ if (a) {
122
+ if (g) {
123
+ if (g !== a) {
124
+ g[f] = a;
125
+ }
126
+ }
127
+ else {
128
+ target[b] = r(a);
129
+ }
130
+ }
131
+ else {
132
+ target[b] = a;
133
+ }
134
+ } while (++b < v);
135
+ break;
136
+ }
137
+ else if (a !== null && a !== undefined) {
138
+ do {
139
+ target[b] = d[b];
140
+ } while (++b < v);
141
+ break;
142
+ }
143
+ else {
144
+ target[b] = a;
145
+ }
146
+ }
147
+ const n = target[f];
148
+ if (i !== v) {
149
+ if (i > v) {
150
+ target.length = v;
151
+ }
152
+ l(n, 'length');
153
+ }
154
+ l(n, Symbol.iterator);
155
+ };
156
+ const F = (target, z, d) => {
157
+ const A = { ...target };
158
+ let g;
159
+ for (const u in d) {
160
+ delete A[u];
161
+ const a = d[u];
162
+ if (a && typeof a === 'object') {
163
+ g = target[u];
164
+ if (g) {
165
+ g[f] = a;
166
+ continue;
167
+ }
168
+ }
169
+ if (target[u] !== a) {
170
+ z[u] = a;
171
+ }
172
+ }
173
+ for (const u in A) {
174
+ delete z[u];
175
+ }
176
+ };
177
+ const G = {
178
+ get(target, key) {
179
+ if (key !== f) {
180
+ let h = target[key];
181
+ if (h && h === j[key]) {
182
+ const B = C[key];
183
+ if (B) {
184
+ return B.bind(target);
185
+ }
186
+ h = h.bind(target);
187
+ }
188
+ x(target[f], key !== 'length' ? Symbol.iterator : key);
189
+ return h;
190
+ }
191
+ return target;
192
+ },
193
+ set(target, key, d) {
194
+ if (key !== f) {
195
+ if (target[key] === d) {
196
+ return true;
197
+ }
198
+ const n = target[f];
199
+ if (d && typeof d === 'object') {
200
+ d = r(d);
201
+ }
202
+ target[key] = d;
203
+ if (key === 'length') {
204
+ l(n, key);
205
+ }
206
+ l(n, Symbol.iterator);
207
+ return true;
208
+ }
209
+ E(target, d);
210
+ return true;
211
+ },
212
+ has(target, key) {
213
+ x(target[f], !isNaN(parseInt(key)) ? Symbol.iterator : key);
214
+ return key in target;
215
+ },
216
+ deleteProperty(target, key) {
217
+ if (!isNaN(parseInt(key))) {
218
+ key = Symbol.iterator;
219
+ }
220
+ if (target[key] !== undefined) {
221
+ l(target[f], key);
222
+ }
223
+ return delete target[key];
224
+ },
225
+ };
226
+ const H = {
227
+ get(target, key) {
228
+ if (key !== f) {
229
+ const h = target[key];
230
+ if (key !== 'id') {
231
+ x(target[f], key);
232
+ }
233
+ return h;
234
+ }
235
+ return target;
236
+ },
237
+ set(target, key, d, z) {
238
+ if (key !== f) {
239
+ if (target[key] === d) {
240
+ return true;
241
+ }
242
+ const n = target[f];
243
+ if (d && typeof d === 'object') {
244
+ d = r(d);
245
+ }
246
+ target[key] = d;
247
+ l(n, key);
248
+ return true;
249
+ }
250
+ F(target, z, d);
251
+ return true;
252
+ },
253
+ has(target, key) {
254
+ x(target[f], key);
255
+ return key in target;
256
+ },
257
+ deleteProperty(target, key) {
258
+ if (target[key] !== undefined) {
259
+ l(target[f], key);
260
+ }
261
+ return delete target[key];
262
+ },
263
+ };
264
+ const r = (e) => {
265
+ let target;
266
+ if (!Array.isArray(e)) {
267
+ target = {};
268
+ for (const key in e) {
269
+ const a = e[key];
270
+ target[key] = a && typeof a === 'object' ? r(a) : a;
271
+ }
272
+ e = new Proxy(target, H);
273
+ }
274
+ else {
275
+ target = [];
276
+ const length = e.length;
277
+ for (let b = 0; b < length; b++) {
278
+ let a = e[b];
279
+ if (a && typeof a === 'object') {
280
+ do {
281
+ target[b] = (a = e[b]) && r(a);
282
+ } while (++b < length);
283
+ break;
284
+ }
285
+ else if (a !== null && a !== undefined) {
286
+ do {
287
+ target[b] = e[b];
288
+ } while (++b < length);
289
+ break;
290
+ }
291
+ target[b] = a;
292
+ }
293
+ e = new Proxy(target, G);
294
+ }
295
+ target[f] = {};
296
+ return e;
297
+ };
298
+ const $ = (D, a6) => {
299
+ if (a6) {
300
+ D.w = true;
301
+ }
302
+ else {
303
+ D.com.watchMountChange('s', $, D);
304
+ }
305
+ };
306
+ export const bindData = (data, key) => {
307
+ return [data, key, data[key]];
308
+ };
309
+ export const useState = (initial, resetOnUnmount) => {
310
+ const com = q;
311
+ if (com.id) {
312
+ let s = y.get(com);
313
+ if (s) {
314
+ const e = s.e;
315
+ if (!s.w) {
316
+ if (typeof initial === 'function') {
317
+ t = true;
318
+ initial = initial(e);
319
+ if (initial !== e) {
320
+ e[f] = initial;
321
+ }
322
+ t = false;
323
+ }
324
+ }
325
+ else {
326
+ t = true;
327
+ if (typeof initial === 'function') {
328
+ initial = initial();
329
+ }
330
+ e[f] = initial;
331
+ t = false;
332
+ s.w = false;
333
+ com.watchMountChange('s', $, s);
334
+ }
335
+ return e;
336
+ }
337
+ if (typeof initial === 'function') {
338
+ initial = initial();
339
+ }
340
+ const e = r(initial);
341
+ s = { com, e, w: false };
342
+ y.set(com, s);
343
+ if (resetOnUnmount) {
344
+ com.watchMountChange('s', $, s);
345
+ }
346
+ return e;
347
+ }
348
+ if (typeof initial === 'function') {
349
+ initial = initial();
350
+ }
351
+ const e = r(initial);
352
+ return e;
353
+ };
354
+ //# sourceMappingURL=state.js.map
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "ezh",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "start": "webpack serve"
6
+ },
7
+ "files": [
8
+ "./lib/*"
9
+ ],
10
+ "module": "./lib/index.js",
11
+ "typings": "./lib/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "default": "./lib/index.js",
15
+ "types": "./lib/index.d.ts"
16
+ },
17
+ "./debug": {
18
+ "default": "./lib/debugCheck.js",
19
+ "types": "./lib/debugCheck.d.ts"
20
+ }
21
+ },
22
+ "keywords": [
23
+ "ezh"
24
+ ],
25
+ "author": "Andy Deng",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@eslint/eslintrc": "^3.2.0",
29
+ "@eslint/js": "^9.19.0",
30
+ "@types/jest": "^29.5.1",
31
+ "@typescript-eslint/eslint-plugin": "^8.25.0",
32
+ "@typescript-eslint/parser": "^8.25.0",
33
+ "css-loader": "^7.1.2",
34
+ "dts-bundle-generator": "^9.5.1",
35
+ "eslint": "^9.21.0",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "ezh-trans": "^0.2.0",
38
+ "globals": "^15.14.0",
39
+ "log-class": "^1.0.1",
40
+ "minify-ts": "^1.2.3",
41
+ "sass": "^1.86.0",
42
+ "sass-loader": "^16.0.5",
43
+ "style-loader": "^4.0.0",
44
+ "ts-loader": "^9.5.2",
45
+ "typescript": "^5.1.3",
46
+ "webpack": "^5.98.0",
47
+ "webpack-cli": "^6.0.1",
48
+ "webpack-dev-server": "^5.2.0"
49
+ },
50
+ "dependencies": {
51
+ "path-parser": "^6.1.0",
52
+ "reflect-metadata": "^0.2.2"
53
+ }
54
+ }