ezh 0.1.6 → 0.2.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.
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { $ezh, configGC, addComReader, refreshComReaders } from './elements';
2
- export { bindData, useState } from './state';
3
- export { Link, RouteLink, navigate, route, Router } from './router';
4
- //# sourceMappingURL=index.js.map
package/lib/router.js DELETED
@@ -1,111 +0,0 @@
1
- import { Path } from 'path-parser';
2
- import { $ezh } from './elements';
3
- import { useState } from './state';
4
- export { navigate, route, Router, Link, RouteLink, };
5
- let d = 0;
6
- const e = useState({ c: 0 });
7
- window.addEventListener('popstate', () => {
8
- e.c = ++d;
9
- });
10
- const navigate = (to, replace) => {
11
- const { pathname, search, hash } = window.location;
12
- const a = `${pathname}${search}${hash}`;
13
- if (to !== a) {
14
- if (!replace) {
15
- window.history.pushState(undefined, '', to);
16
- }
17
- else {
18
- window.history.replaceState(undefined, '', to);
19
- }
20
- queueMicrotask(() => {
21
- e.c = ++d;
22
- });
23
- }
24
- };
25
- const f = 'ezhEZH';
26
- class i {
27
- constructor(com, path, needAuth) {
28
- this.com = com;
29
- this.b = Path.createPath(path + f);
30
- this.needAuth = needAuth;
31
- }
32
- com;
33
- needAuth;
34
- parseParam(url) {
35
- const param = this.b.test(url);
36
- if (param) {
37
- delete param[f];
38
- return param;
39
- }
40
- }
41
- buildUrl(k) {
42
- throw new Error('WildcardRoute does not support buildUrl');
43
- }
44
- b;
45
- }
46
- class j {
47
- constructor(com, path, needAuth) {
48
- this.com = com;
49
- this.b = Path.createPath(path);
50
- this.needAuth = needAuth;
51
- }
52
- com;
53
- needAuth;
54
- parseParam(url) {
55
- return this.b.test(url);
56
- }
57
- buildUrl(param) {
58
- return this.b.build(param);
59
- }
60
- b;
61
- }
62
- const route = (com, path, needAuth = true) => {
63
- return path.endsWith('*') ? new i(com, path, needAuth) : new j(com, path, needAuth);
64
- };
65
- const Router = ({ routes, notFound, checkAuth }) => {
66
- d = e.c;
67
- const { pathname, search, hash } = window.location;
68
- const a = `${pathname}${search}${hash}`;
69
- const { $s, $k, $c } = $ezh;
70
- for (const key in routes) {
71
- const route = routes[key];
72
- const param = route.parseParam(a);
73
- if (param) {
74
- if (checkAuth && route.needAuth) {
75
- const g = checkAuth(a);
76
- if (g) {
77
- navigate(g);
78
- return;
79
- }
80
- }
81
- return $s($k(key), $c('_', route.com, param, undefined, -1));
82
- }
83
- }
84
- return notFound ? $s($k('404'), $c('_', notFound, {})) : undefined;
85
- };
86
- const h = (v, url, replace) => {
87
- v.preventDefault();
88
- const { pathname, search, hash } = window.location;
89
- const a = `${pathname}${search}${hash}`;
90
- if (url !== a) {
91
- if (!replace) {
92
- window.history.pushState(undefined, '', url);
93
- }
94
- else {
95
- window.history.replaceState(undefined, '', url);
96
- }
97
- e.c = ++d;
98
- }
99
- };
100
- const Link = (props, children) => {
101
- const { href, className, style, title, replace } = props;
102
- const onclick = href ? (v) => h(v, href, replace) : undefined;
103
- return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
104
- };
105
- const RouteLink = (props, children) => {
106
- const { route, params, className, style, title, replace } = props;
107
- const href = route.buildUrl(params);
108
- const onclick = (v) => h(v, href, replace);
109
- return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
110
- };
111
- //# sourceMappingURL=router.js.map
package/lib/state.js DELETED
@@ -1,354 +0,0 @@
1
- import { addComReader, p, 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 q = (_) => {
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 o;
75
- for (let b = begin; b < c; b++) {
76
- o = this[b];
77
- switch (typeof o) {
78
- case 'object':
79
- if (o) {
80
- while (b < c) {
81
- o = this[b];
82
- if (o && !o[f]) {
83
- this[b] = r(o);
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 D = {
102
- 'push': q(j.push),
103
- 'unshift': q(j.unshift),
104
- 'fill': q(j.fill),
105
- 'sort': q(j.sort),
106
- 'reverse': q(j.reverse),
107
- 'pop': q(j.pop),
108
- 'shift': q(j.shift),
109
- 'splice': q(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 C = D[key];
183
- if (C) {
184
- return C.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 $ = (B, a2) => {
299
- if (a2) {
300
- B.w = true;
301
- }
302
- else {
303
- B.com.watchMountChange('s', $, B);
304
- }
305
- };
306
- export const bindData = (data, key) => {
307
- return [data, key, data[key]];
308
- };
309
- export const useState = (initial, resetOnUnmount) => {
310
- const com = p;
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