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/index.d.ts ADDED
@@ -0,0 +1,527 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
5
+ export type NeverUnion<T> = [
6
+ T
7
+ ] extends [
8
+ UnionToIntersection<T>
9
+ ] ? T : never;
10
+ export type ElementType<T> = T extends (infer U)[] ? U : never;
11
+ export type BasicValue = boolean | number | string | bigint;
12
+ export type EmptyValue = null | undefined;
13
+ export type BasicNullableObject = BasicObject | EmptyValue;
14
+ export type ObjectToState<T extends BasicNullableObject> = StateBase<Exclude<T, EmptyValue>> | Extract<T, EmptyValue>;
15
+ export type BasicNullableValue = BasicValue | EmptyValue;
16
+ export type ExcludeNonState<T> = T extends BasicNullableValue | symbol ? never : (any extends T ? never : T);
17
+ export type StateBasicType = BasicObject | BasicValue[] | BasicNullableObject[];
18
+ export type StateBase<T extends StateBasicType> = NeverUnion<T> extends never ? never : {
19
+ [K in keyof T]: any extends T[K] ? never : (T[K] extends BasicNullableValue | BasicNullableValue[] ? T[K] : (NeverUnion<Exclude<T[K], EmptyValue>> extends never ? never : (Exclude<T[K], EmptyValue> extends BasicObject ? ObjectToState<Extract<T[K], BasicNullableObject>> : (NeverUnion<Exclude<ElementType<Extract<T[K], BasicNullableObject[]>>, EmptyValue>> extends never ? never : (ObjectToState<ElementType<Extract<T[K], BasicNullableObject[]>>>[] | Extract<T[K], EmptyValue>)))));
20
+ };
21
+ export type Obj = Record<string, any>;
22
+ export type BasicObject = {
23
+ [K: string]: BasicValue | BasicObject | BasicNullableValue[] | BasicNullableObject[] | EmptyValue;
24
+ };
25
+ export type State<T extends StateBasicType> = StateBase<ExcludeNonState<T>>;
26
+ export type ReaderRecord = Record<string | number | symbol, Map<string, number> | undefined>;
27
+ export interface EzBaseSVGElement {
28
+ id?: string;
29
+ className?: string;
30
+ style?: CSSStyleDeclaration;
31
+ tabIndex?: number;
32
+ dataset?: DOMStringMap;
33
+ transform?: string;
34
+ visibility?: "visible" | "hidden" | "collapse";
35
+ opacity?: number;
36
+ clipPath?: string;
37
+ mask?: string;
38
+ pointerEvents?: string;
39
+ requiredExtensions?: string;
40
+ systemLanguage?: string;
41
+ }
42
+ export interface EzSVGAElement extends EzBaseSVGElement {
43
+ href?: string;
44
+ target?: string;
45
+ download?: string;
46
+ rel?: string;
47
+ referrerPolicy?: string;
48
+ }
49
+ export interface EzSVGAnimateElement extends EzBaseSVGElement {
50
+ attributeName?: string;
51
+ attributeType?: string;
52
+ from?: string;
53
+ to?: string;
54
+ dur?: string;
55
+ begin?: string;
56
+ repeatCount?: string;
57
+ fill?: string;
58
+ }
59
+ export interface EzSVGAnimateMotionElement extends EzBaseSVGElement {
60
+ path?: string;
61
+ keyPoints?: string;
62
+ rotate?: string;
63
+ }
64
+ export interface EzSVGAnimateTransformElement extends EzBaseSVGElement {
65
+ attributeName?: string;
66
+ type?: string;
67
+ from?: string;
68
+ to?: string;
69
+ dur?: string;
70
+ }
71
+ export interface EzSVGCircleElement extends EzBaseSVGElement {
72
+ cx?: string;
73
+ cy?: string;
74
+ r?: string;
75
+ }
76
+ export interface EzSVGClipPathElement extends EzBaseSVGElement {
77
+ clipPathUnits?: string;
78
+ }
79
+ export type EzSVGDefsElement = EzBaseSVGElement;
80
+ export type EzSVGDescElement = EzBaseSVGElement;
81
+ export interface EzSVGEllipseElement extends EzBaseSVGElement {
82
+ cx?: string;
83
+ cy?: string;
84
+ rx?: string;
85
+ ry?: string;
86
+ }
87
+ export interface EzSVGFEBlendElement extends EzBaseSVGElement {
88
+ mode?: string;
89
+ }
90
+ export interface EzSVGFEColorMatrixElement extends EzBaseSVGElement {
91
+ type?: string;
92
+ values?: string;
93
+ }
94
+ export type EzSVGFEComponentTransferElement = EzBaseSVGElement;
95
+ export interface EzSVGFECompositeElement extends EzBaseSVGElement {
96
+ operator?: string;
97
+ in2?: string;
98
+ }
99
+ export interface EzSVGFEConvolveMatrixElement extends EzBaseSVGElement {
100
+ order?: string;
101
+ kernelMatrix?: string;
102
+ }
103
+ export interface EzSVGFEDiffuseLightingElement extends EzBaseSVGElement {
104
+ surfaceScale?: string;
105
+ diffuseConstant?: string;
106
+ }
107
+ export interface EzSVGFEDisplacementMapElement extends EzBaseSVGElement {
108
+ scale?: string;
109
+ xChannelSelector?: string;
110
+ yChannelSelector?: string;
111
+ }
112
+ export interface EzSVGFEDistantLightElement extends EzBaseSVGElement {
113
+ azimuth?: string;
114
+ elevation?: string;
115
+ }
116
+ export type EzSVGFEFloodElement = EzBaseSVGElement;
117
+ export type EzSVGFEFuncAElement = EzBaseSVGElement;
118
+ export type EzSVGFEFuncBElement = EzBaseSVGElement;
119
+ export type EzSVGFEFuncGElement = EzBaseSVGElement;
120
+ export type EzSVGFEFuncRElement = EzBaseSVGElement;
121
+ export interface EzSVGFEGaussianBlurElement extends EzBaseSVGElement {
122
+ stdDeviation?: string;
123
+ }
124
+ export type EzSVGFEImageElement = EzBaseSVGElement;
125
+ export type EzSVGFEMergeElement = EzBaseSVGElement;
126
+ export type EzSVGFEMergeNodeElement = EzBaseSVGElement;
127
+ export interface EzSVGFEMorphologyElement extends EzBaseSVGElement {
128
+ operator?: string;
129
+ radius?: string;
130
+ }
131
+ export interface EzSVGFEOffsetElement extends EzBaseSVGElement {
132
+ dx?: string;
133
+ dy?: string;
134
+ }
135
+ export interface EzSVGFEPointLightElement extends EzBaseSVGElement {
136
+ x?: string;
137
+ y?: string;
138
+ z?: string;
139
+ }
140
+ export interface EzSVGFESpecularLightingElement extends EzBaseSVGElement {
141
+ surfaceScale?: string;
142
+ specularConstant?: string;
143
+ specularExponent?: string;
144
+ }
145
+ export interface EzSVGFESpotLightElement extends EzBaseSVGElement {
146
+ x?: string;
147
+ y?: string;
148
+ z?: string;
149
+ pointsAtX?: string;
150
+ pointsAtY?: string;
151
+ pointsAtZ?: string;
152
+ specularExponent?: string;
153
+ }
154
+ export type EzSVGFETileElement = EzBaseSVGElement;
155
+ export interface EzSVGFETurbulenceElement extends EzBaseSVGElement {
156
+ baseFrequency?: string;
157
+ numOctaves?: string;
158
+ seed?: string;
159
+ type?: string;
160
+ }
161
+ export interface EzSVGFilterElement extends EzBaseSVGElement {
162
+ filterUnits?: string;
163
+ primitiveUnits?: string;
164
+ x?: string;
165
+ y?: string;
166
+ width?: string;
167
+ height?: string;
168
+ }
169
+ export interface EzSVGForeignObjectElement extends EzBaseSVGElement {
170
+ x?: string;
171
+ y?: string;
172
+ width?: string;
173
+ height?: string;
174
+ }
175
+ export type EzSVGGElement = EzBaseSVGElement;
176
+ export interface EzSVGImageElement extends EzBaseSVGElement {
177
+ href?: string;
178
+ x?: string;
179
+ y?: string;
180
+ width?: string;
181
+ height?: string;
182
+ }
183
+ export interface EzSVGLineElement extends EzBaseSVGElement {
184
+ x1?: string;
185
+ y1?: string;
186
+ x2?: string;
187
+ y2?: string;
188
+ }
189
+ export interface EzSVGLinearGradientElement extends EzBaseSVGElement {
190
+ x1?: string;
191
+ y1?: string;
192
+ x2?: string;
193
+ y2?: string;
194
+ }
195
+ export interface EzSVGMarkerElement extends EzBaseSVGElement {
196
+ refX?: string;
197
+ refY?: string;
198
+ markerWidth?: string;
199
+ markerHeight?: string;
200
+ orient?: string;
201
+ }
202
+ export interface EzSVGMaskElement extends EzBaseSVGElement {
203
+ maskUnits?: string;
204
+ maskContentUnits?: string;
205
+ }
206
+ export type EzSVGMetadataElement = EzBaseSVGElement;
207
+ export type EzSVGMPathElement = EzBaseSVGElement;
208
+ export interface EzSVGPathElement extends EzBaseSVGElement {
209
+ d?: string;
210
+ pathLength?: string;
211
+ }
212
+ export interface EzSVGPatternElement extends EzBaseSVGElement {
213
+ patternUnits?: string;
214
+ }
215
+ export interface EzSVGPolygonElement extends EzBaseSVGElement {
216
+ points?: string;
217
+ }
218
+ export interface EzSVGPolylineElement extends EzBaseSVGElement {
219
+ points?: string;
220
+ }
221
+ export interface EzSVGRadialGradientElement extends EzBaseSVGElement {
222
+ cx?: string;
223
+ cy?: string;
224
+ r?: string;
225
+ fx?: string;
226
+ fy?: string;
227
+ }
228
+ export interface EzSVGRectElement extends EzBaseSVGElement {
229
+ x?: string;
230
+ y?: string;
231
+ width?: string;
232
+ height?: string;
233
+ rx?: string;
234
+ ry?: string;
235
+ }
236
+ export interface EzSVGScriptElement extends EzBaseSVGElement {
237
+ type?: string;
238
+ }
239
+ export type EzSVGSetElement = EzBaseSVGElement;
240
+ export interface EzSVGStopElement extends EzBaseSVGElement {
241
+ offset?: string;
242
+ stopColor?: string;
243
+ stopOpacity?: string;
244
+ }
245
+ export interface EzSVGStyleElement extends EzBaseSVGElement {
246
+ type?: string;
247
+ media?: string;
248
+ }
249
+ export interface EzSVGElement extends EzBaseSVGElement {
250
+ width?: number | string;
251
+ height?: number | string;
252
+ viewBox?: string;
253
+ preserveAspectRatio?: string;
254
+ xmlns?: string;
255
+ }
256
+ export type EzSVGSwitchElement = EzBaseSVGElement;
257
+ export type EzSVGSymbolElement = EzBaseSVGElement;
258
+ export interface EzSVGTextElement extends EzBaseSVGElement {
259
+ x?: string;
260
+ y?: string;
261
+ }
262
+ export interface EzSVGTextPathElement extends EzBaseSVGElement {
263
+ href?: string;
264
+ startOffset?: string;
265
+ }
266
+ export type EzSVGTitleElement = EzBaseSVGElement;
267
+ export interface EzSVGTSpanElement extends EzBaseSVGElement {
268
+ x?: string;
269
+ y?: string;
270
+ }
271
+ export interface EzSVGUseElement extends EzBaseSVGElement {
272
+ href?: string;
273
+ }
274
+ export interface EzSVGViewElement extends EzBaseSVGElement {
275
+ viewBox?: string;
276
+ }
277
+ export type ContainerElement = {
278
+ children?: ChildElement[] | ChildElement;
279
+ };
280
+ export interface EzSVGElementTagNameMap {
281
+ a: EzSVGAElement;
282
+ animate: EzSVGAnimateElement;
283
+ animateMotion: EzSVGAnimateMotionElement;
284
+ animateTransform: EzSVGAnimateTransformElement;
285
+ circle: EzSVGCircleElement;
286
+ clipPath: EzSVGClipPathElement & ContainerElement;
287
+ defs: EzSVGDefsElement & ContainerElement;
288
+ desc: EzSVGDescElement;
289
+ ellipse: EzSVGEllipseElement;
290
+ feBlend: EzSVGFEBlendElement;
291
+ feColorMatrix: EzSVGFEColorMatrixElement;
292
+ feComponentTransfer: EzSVGFEComponentTransferElement & ContainerElement;
293
+ feComposite: EzSVGFECompositeElement;
294
+ feConvolveMatrix: EzSVGFEConvolveMatrixElement;
295
+ feDiffuseLighting: EzSVGFEDiffuseLightingElement;
296
+ feDisplacementMap: EzSVGFEDisplacementMapElement;
297
+ feDistantLight: EzSVGFEDistantLightElement;
298
+ feDropShadow: EzSVGFilterElement;
299
+ feFlood: EzSVGFEFloodElement;
300
+ feFuncA: EzSVGFEFuncAElement;
301
+ feFuncB: EzSVGFEFuncBElement;
302
+ feFuncG: EzSVGFEFuncGElement;
303
+ feFuncR: EzSVGFEFuncRElement;
304
+ feGaussianBlur: EzSVGFEGaussianBlurElement;
305
+ feImage: EzSVGFEImageElement;
306
+ feMerge: EzSVGFEMergeElement & ContainerElement;
307
+ feMergeNode: EzSVGFEMergeNodeElement;
308
+ feMorphology: EzSVGFEMorphologyElement;
309
+ feOffset: EzSVGFEOffsetElement;
310
+ fePointLight: EzSVGFEPointLightElement;
311
+ feSpecularLighting: EzSVGFESpecularLightingElement;
312
+ feSpotLight: EzSVGFESpotLightElement;
313
+ feTile: EzSVGFETileElement;
314
+ feTurbulence: EzSVGFETurbulenceElement;
315
+ filter: EzSVGFilterElement & ContainerElement;
316
+ foreignObject: EzSVGForeignObjectElement & ContainerElement;
317
+ g: EzSVGGElement & ContainerElement;
318
+ image: EzSVGImageElement;
319
+ line: EzSVGLineElement;
320
+ linearGradient: EzSVGLinearGradientElement;
321
+ marker: EzSVGMarkerElement & ContainerElement;
322
+ mask: EzSVGMaskElement & ContainerElement;
323
+ metadata: EzSVGMetadataElement;
324
+ mpath: EzSVGMPathElement;
325
+ path: EzSVGPathElement;
326
+ pattern: EzSVGPatternElement & ContainerElement;
327
+ polygon: EzSVGPolygonElement;
328
+ polyline: EzSVGPolylineElement;
329
+ radialGradient: EzSVGRadialGradientElement;
330
+ rect: EzSVGRectElement;
331
+ script: EzSVGScriptElement;
332
+ set: EzSVGSetElement;
333
+ stop: EzSVGStopElement;
334
+ style: EzSVGStyleElement;
335
+ svg: EzSVGElement & ContainerElement;
336
+ switch: EzSVGSwitchElement & ContainerElement;
337
+ symbol: EzSVGSymbolElement & ContainerElement;
338
+ text: EzSVGTextElement & ContainerElement;
339
+ textPath: EzSVGTextPathElement;
340
+ title: EzSVGTitleElement;
341
+ tspan: EzSVGTSpanElement;
342
+ use: EzSVGUseElement;
343
+ view: EzSVGViewElement;
344
+ }
345
+ export interface EzMathMLElement extends ContainerElement {
346
+ id?: string;
347
+ className?: string;
348
+ mathvariant?: string;
349
+ displaystyle?: boolean;
350
+ scriptlevel?: number;
351
+ dir?: "ltr" | "rtl";
352
+ }
353
+ export interface EzMathMLElementTagNameMap {
354
+ annotation: EzMathMLElement;
355
+ annotationXml: EzMathMLElement;
356
+ maction: EzMathMLElement;
357
+ math: EzMathMLElement;
358
+ merror: EzMathMLElement;
359
+ mfrac: EzMathMLElement;
360
+ mi: EzMathMLElement;
361
+ mmultiscripts: EzMathMLElement;
362
+ mn: EzMathMLElement;
363
+ mo: EzMathMLElement;
364
+ mover: EzMathMLElement;
365
+ mpadded: EzMathMLElement;
366
+ mphantom: EzMathMLElement;
367
+ mprescripts: EzMathMLElement;
368
+ mroot: EzMathMLElement;
369
+ mrow: EzMathMLElement;
370
+ ms: EzMathMLElement;
371
+ mspace: EzMathMLElement;
372
+ msqrt: EzMathMLElement;
373
+ mstyle: EzMathMLElement;
374
+ msub: EzMathMLElement;
375
+ msubsup: EzMathMLElement;
376
+ msup: EzMathMLElement;
377
+ mtable: EzMathMLElement;
378
+ mtd: EzMathMLElement;
379
+ mtext: EzMathMLElement;
380
+ mtr: EzMathMLElement;
381
+ munder: EzMathMLElement;
382
+ munderover: EzMathMLElement;
383
+ semantics: EzMathMLElement;
384
+ }
385
+ export type InputControlProps = "checked" | "disabled" | "selected" | "readonly" | "multiple" | "required" | "value";
386
+ export type InputTypes = "button" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week";
387
+ export type PropsWithKey = {
388
+ key?: string | number | undefined;
389
+ };
390
+ export type OmitNonStringFields<T> = Omit<T, {
391
+ [K in keyof T]: T[K] extends string ? never : K;
392
+ }[keyof T]>;
393
+ export type ReplaceHTMLElement<T extends object> = {
394
+ [K in keyof T]: K extends "children" ? (ChildElement[] | ChildElement) : (T extends HTMLInputElement ? (K extends InputControlProps ? T[K] | [
395
+ Obj,
396
+ string,
397
+ T[K]
398
+ ] : (K extends "type" ? InputTypes : T[K])) : T extends HTMLSelectElement ? (K extends "value" ? T[K] | [
399
+ Obj,
400
+ string,
401
+ T[K]
402
+ ] : T[K]) : (K extends "style" ? Partial<OmitNonStringFields<CSSStyleDeclaration>> : T[K]));
403
+ };
404
+ export type EzHTMLElementTagNameMap = {
405
+ [K in keyof HTMLElementTagNameMap]: ReplaceHTMLElement<HTMLElementTagNameMap[K]> & PropsWithKey;
406
+ };
407
+ export type EzHTMLElementDeprecatedTagNameMap = {
408
+ [K in keyof HTMLElementDeprecatedTagNameMap]: ReplaceHTMLElement<HTMLElementDeprecatedTagNameMap[K]> & PropsWithKey;
409
+ };
410
+ export type PrefixedType<T, Prefix extends string> = {
411
+ [K in keyof T as `${Prefix}${string & K}`]: T[K];
412
+ };
413
+ export type EzTagElementNameMap = EzHTMLElementTagNameMap & EzHTMLElementDeprecatedTagNameMap & Omit<EzSVGElementTagNameMap, keyof HTMLElementTagNameMap> & PrefixedType<Pick<EzSVGElementTagNameMap, Extract<keyof EzSVGElementTagNameMap, keyof HTMLElementTagNameMap>>, "svg:"> & EzMathMLElementTagNameMap;
414
+ export type TagTypes = keyof EzTagElementNameMap;
415
+ export type TagProps<T extends TagTypes> = Partial<EzTagElementNameMap[T]>;
416
+ export type ElementProps = {
417
+ [K in TagTypes]: TagProps<K>;
418
+ };
419
+ export interface IEzElement {
420
+ readonly id: string;
421
+ readonly parent?: ITagElement;
422
+ newChildren?: IEzElement[];
423
+ index: number;
424
+ get firstElement(): Element | Text | null;
425
+ attachTo(target: ITagElement): void;
426
+ detachFrom(target: ITagElement): void;
427
+ move(): void;
428
+ update(props: unknown | null, children?: ChildElement[]): boolean;
429
+ refresh(newChildren: IEzElement[]): void;
430
+ release(target?: ITagElement): void;
431
+ }
432
+ export interface ITagElement {
433
+ readonly id: string;
434
+ readonly parent?: ITagElement;
435
+ readonly element: Element;
436
+ currentBefore?: Element | Text | null;
437
+ findNextSiblingElement(index: number): Element | Text | null;
438
+ }
439
+ export type EzElement = IEzElement | boolean | number | bigint | string | null | undefined;
440
+ export type ChildElement = EzElement | (() => EzElement | EzElement[]) | (EzElement | (() => EzElement | EzElement[]))[];
441
+ export type ComProps<P extends object> = P extends {
442
+ children?: ChildElement[];
443
+ } ? {
444
+ [K in keyof P]: K extends "children" ? ChildElement[] | ChildElement : P[K];
445
+ } : P;
446
+ export type PropsWithChildren<P extends object> = ComProps<{
447
+ children?: EzElement[];
448
+ } & P>;
449
+ export type Com<P extends object = object> = (props: ComProps<P>, children?: ChildElement[]) => EzElement;
450
+ export type Container<P extends object = object> = (props: PropsWithChildren<P>, children?: ChildElement[]) => EzElement;
451
+ export type CheckAuthFunc = (url: string) => string | undefined;
452
+ export interface IRoute<ParamT extends object> {
453
+ readonly com: Com<ParamT>;
454
+ readonly needAuth: boolean;
455
+ parseParam(url: string): ParamT | undefined;
456
+ buildUrl(param: ParamT): string;
457
+ }
458
+ export type RouteMap = {
459
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
+ [key: string]: IRoute<any extends object ? any : never>;
461
+ };
462
+ export type RouterProp = {
463
+ routes: RouteMap;
464
+ notFound?: Com;
465
+ checkAuth?: CheckAuthFunc;
466
+ };
467
+ export type LinkProp = {
468
+ href?: string;
469
+ className?: string;
470
+ style?: CSSStyleDeclaration;
471
+ title?: string;
472
+ replace?: boolean;
473
+ children?: ChildElement[] | ChildElement;
474
+ };
475
+ export type RouteLinkProp<ParamT extends object> = {
476
+ route: IRoute<ParamT>;
477
+ params: ParamT;
478
+ className?: string;
479
+ style?: CSSStyleDeclaration;
480
+ title?: string;
481
+ replace?: boolean;
482
+ children?: ChildElement[] | ChildElement;
483
+ };
484
+ export interface INameSpaceChecker {
485
+ markNameSpace(): void;
486
+ }
487
+ declare const nsCreateElMap: Record<string, (tagName: string, nsChecker: INameSpaceChecker) => Element>;
488
+ export declare const addComReader: (readerRecord: ReaderRecord, key: string | symbol | number) => void;
489
+ export declare let refreshComReaders: (readerRecord: ReaderRecord, key: string | symbol | number) => void;
490
+ export declare const configGC: (waitIntervals: number, interval?: number) => boolean;
491
+ export declare namespace $ezh {
492
+ function ezh<T extends keyof EzTagElementNameMap, P extends object>(tag: T | Com<P>, props: TagProps<T> | P | null, ...children: ChildElement[]): IEzElement;
493
+ const render: (rootElement: Element, entry: (() => EzElement) | Com) => void;
494
+ const $: <T extends keyof EzTagElementNameMap>(id: string, tag: T, props: TagProps<T> | null, children?: ChildElement[], check?: number, mutableChild?: 1) => IEzElement;
495
+ const $c: <P extends object>(id: string, entry: Com<P>, props: P | null, children?: ChildElement[], check?: number, mutableChild?: 1) => IEzElement;
496
+ const $f: (id: string, children?: ChildElement[], mutableChild?: 1) => IEzElement;
497
+ const $k: (key: string | number) => (() => void);
498
+ const $n: (ns: keyof typeof nsCreateElMap) => (() => void);
499
+ const $s: (cb: () => void, element: IEzElement) => IEzElement;
500
+ const $t: (id: string, text: string, mayChange?: 1) => IEzElement;
501
+ namespace JSX {
502
+ type Element = EzElement;
503
+ type IntrinsicElements = ElementProps;
504
+ interface ElementAttributesProperty {
505
+ props: object;
506
+ }
507
+ interface ElementChildrenAttribute {
508
+ children: object;
509
+ }
510
+ interface IntrinsicAttributes {
511
+ key?: string | number | undefined;
512
+ }
513
+ }
514
+ }
515
+ export declare const bindData: <T extends State<T>, K extends keyof T>(data: T, key: K) => [
516
+ T,
517
+ K,
518
+ T[K]
519
+ ];
520
+ export declare const useState: <T extends State<T>>(initial: T | ((current?: T) => T), resetOnUnmount?: boolean) => T;
521
+ export declare const navigate: (to: string, replace?: true) => void;
522
+ export declare const route: <ParamT extends object>(com: Com<ParamT>, path: string, needAuth?: boolean) => IRoute<ParamT>;
523
+ export declare const Router: Com<RouterProp>;
524
+ export declare const Link: (props: LinkProp, children?: ChildElement[]) => EzElement;
525
+ export declare const RouteLink: <ParamT extends object>(props: RouteLinkProp<ParamT>, children: ChildElement[]) => EzElement;
526
+
527
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
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 ADDED
@@ -0,0 +1,111 @@
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, param));
82
+ }
83
+ }
84
+ return notFound ? $s($k('404'), $c('_', notFound, {})) : undefined;
85
+ };
86
+ const h = (x, url, replace) => {
87
+ x.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 ? (x) => h(x, 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 = (x) => h(x, href, replace);
109
+ return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
110
+ };
111
+ //# sourceMappingURL=router.js.map