lyco 1.3.7 → 1.3.8

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,7 @@
1
+ export declare function initWith<T>(obj: T): {
2
+ let(fn: (it: T) => void): T;
3
+ };
4
+ /**
5
+ * @alias initWith
6
+ */
7
+ export declare const iw: typeof initWith;
@@ -1,5 +1,4 @@
1
- import { TemplateResult } from 'lit';
2
- import { OnEvent, renderFnType, WithHtml } from '../core';
1
+ import { OnEvent, renderFnType, Temp, WithHtml } from '../core';
3
2
  interface FlexProps {
4
3
  direction?: "row" | "column";
5
4
  justify?: string;
@@ -8,5 +7,5 @@ interface FlexProps {
8
7
  on?: OnEvent;
9
8
  }
10
9
  export declare function Flex(props?: FlexProps): WithHtml<renderFnType>;
11
- export declare function Flex(props?: FlexProps, children?: renderFnType): TemplateResult<1>;
10
+ export declare function Flex(props?: FlexProps, children?: renderFnType): Temp;
12
11
  export {};
@@ -1,5 +1,4 @@
1
- import { TemplateResult } from 'lit';
2
- import { OnEvent, renderFnType, WithHtml } from '../core';
1
+ import { OnEvent, renderFnType, Temp, WithHtml } from '../core';
3
2
  interface FooterLayoutProps {
4
3
  columns?: number;
5
4
  gap?: string;
@@ -8,5 +7,5 @@ interface FooterLayoutProps {
8
7
  on?: OnEvent;
9
8
  }
10
9
  export declare function FooterLayout(props?: FooterLayoutProps): WithHtml<renderFnType>;
11
- export declare function FooterLayout(props?: FooterLayoutProps, children?: renderFnType): TemplateResult<1>;
10
+ export declare function FooterLayout(props?: FooterLayoutProps, children?: renderFnType): Temp;
12
11
  export {};
@@ -1,5 +1,4 @@
1
- import { TemplateResult } from 'lit';
2
- import { OnEvent, renderFnType, WithHtml } from '../core';
1
+ import { OnEvent, renderFnType, Temp, WithHtml } from '../core';
3
2
  export declare function GridCol(props?: {
4
3
  gap?: string | number;
5
4
  on?: OnEvent;
@@ -7,4 +6,4 @@ export declare function GridCol(props?: {
7
6
  export declare function GridCol(props?: {
8
7
  gap?: string | number;
9
8
  on?: OnEvent;
10
- }, children?: renderFnType): TemplateResult<1>;
9
+ }, children?: renderFnType): Temp;
@@ -1,5 +1,4 @@
1
- import { TemplateResult } from 'lit';
2
- import { OnEvent, renderFnType, WithHtml } from '../core';
1
+ import { OnEvent, renderFnType, Temp, WithHtml } from '../core';
3
2
  export declare function GridRow(props?: {
4
3
  gap?: string | number;
5
4
  on?: OnEvent;
@@ -7,4 +6,4 @@ export declare function GridRow(props?: {
7
6
  export declare function GridRow(props?: {
8
7
  gap?: string | number;
9
8
  on?: OnEvent;
10
- }, children?: renderFnType): TemplateResult<1>;
9
+ }, children?: renderFnType): Temp;
@@ -0,0 +1,8 @@
1
+ import { TemplateResult } from 'lit';
2
+ export declare function LazyForEach<T extends any[]>(items: T, render: (item: T[number], index: number) => TemplateResult, threshold?: number, animationOptions?: {
3
+ animationClass?: string;
4
+ animation?: (element: HTMLElement) => void;
5
+ cssProperties?: Record<string, string>;
6
+ duration?: number;
7
+ delay?: number;
8
+ }): TemplateResult[];
@@ -43,9 +43,10 @@ export { Sticky } from './Sticky';
43
43
  export { Table } from './Table';
44
44
  export { Wrap } from './Wrap';
45
45
  export { ZStack } from './ZStack';
46
+ export { LazyForEach } from './LazyForEach';
46
47
  export { Combobox } from './Combobox';
47
48
  export { Progress } from './Progress';
48
49
  export { Spinner } from './Spinner';
49
50
  export { WithTooltip } from './Tooltip';
50
51
  export * from './Dialog';
51
- export declare function $Html(slot: renderFnOrArrayType): import('lit').TemplateResult<1> | import('lit').TemplateResult<1>[];
52
+ export declare function $Html(slot: renderFnOrArrayType): import('../core').Temp | import('../core').Temp[];
@@ -1,15 +1,16 @@
1
1
  import { TemplateResult } from 'lit';
2
2
  declare const ___LYCO_NULL___: unique symbol;
3
- export type renderFnType = TemplateResult<1> | (() => TemplateResult<1>);
4
- export type renderFnOrArrayType = renderFnType | Array<TemplateResult<1>> | (() => TemplateResult<1>[]);
5
- export declare function renderFn(fn?: renderFnType): TemplateResult<1>;
6
- export type WithHtml<K> = ((children?: K) => TemplateResult<1>) & {
7
- html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult<1>;
3
+ export type Temp = TemplateResult<1> | TemplateResult;
4
+ export type renderFnType = Temp | (() => Temp);
5
+ export type renderFnOrArrayType = renderFnType | Array<Temp> | (() => Temp[]);
6
+ export declare function renderFn(fn?: renderFnType): Temp;
7
+ export type WithHtml<K> = ((children?: K) => Temp) & {
8
+ html: (strings: TemplateStringsArray, ...values: unknown[]) => Temp;
8
9
  };
9
- export declare function renderFnOrArray(fnOrArray?: renderFnOrArrayType, injectBox?: (box: TemplateResult<1>, idx?: number, isArray?: boolean, isFunc?: boolean) => TemplateResult<1>): TemplateResult<1> | TemplateResult<1>[];
10
+ export declare function renderFnOrArray(fnOrArray?: renderFnOrArrayType, injectBox?: (box: Temp, idx?: number, isArray?: boolean, isFunc?: boolean) => Temp): Temp | Temp[];
10
11
  export declare function randomClassName(prefix?: string): string;
11
- export declare function renderFnOrCurry(fn?: renderFnType, injectBox?: (box: TemplateResult<1>) => TemplateResult<1>): TemplateResult<1> | ((fn?: renderFnType) => TemplateResult<1>);
12
- export declare function renderFnOrArrayOrCurry(fnOrArray?: renderFnOrArrayType | string | number, injectBox?: (box: TemplateResult<1> | TemplateResult<1>[]) => TemplateResult<1> | TemplateResult<1>[], injectBox2?: (box: TemplateResult<1>, idx?: number, isArray?: boolean, isFunc?: boolean) => TemplateResult<1>): TemplateResult<1> | TemplateResult<1>[] | ((fnOrArray?: renderFnOrArrayType) => TemplateResult<1> | TemplateResult<1>[]);
12
+ export declare function renderFnOrCurry(fn?: renderFnType, injectBox?: (box: Temp) => Temp): Temp | ((fn?: renderFnType) => Temp);
13
+ export declare function renderFnOrArrayOrCurry(fnOrArray?: renderFnOrArrayType | string | number, injectBox?: (box: Temp | Temp[]) => Temp | Temp[], injectBox2?: (box: Temp, idx?: number, isArray?: boolean, isFunc?: boolean) => Temp): Temp | Temp[] | ((fnOrArray?: renderFnOrArrayType) => Temp | Temp[]);
13
14
  declare const allRandomClassName: {
14
15
  "GridBreakpoint::grid-breakpoint": {
15
16
  init: boolean;
@@ -98,7 +99,16 @@ type ComponentCount = {
98
99
  };
99
100
  export declare const componentCount: ComponentCount;
100
101
  export declare function getComponentCount(name: string): number;
101
- export declare function LycoComponent(name: string, slot: TemplateResult<1>): TemplateResult<1>;
102
+ export declare function LycoComponent(name: string, slot: Temp): TemplateResult<1>;
103
+ export declare class AnimationAPI {
104
+ static applyAnimation(element: HTMLElement, options: {
105
+ animationClass?: string;
106
+ animation?: (element: HTMLElement) => void;
107
+ cssProperties?: Record<string, string>;
108
+ duration?: number;
109
+ delay?: number;
110
+ }): void;
111
+ }
102
112
  type EventHandler<K extends keyof GlobalEventHandlersEventMap> = ((event: GlobalEventHandlersEventMap[K]) => void) | {
103
113
  handler: (event: GlobalEventHandlersEventMap[K]) => void;
104
114
  options?: boolean | AddEventListenerOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyco",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "Lit-based pure layout rendering function library , including Row/Column/Flex/Grid and other commonly used rendering functions .",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-CkkadBgp.mjs","names":["fn?: renderFnType","fnOrArray?: renderFnOrArrayType","injectBox?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>","prefix?: string","injectBox?: (box: TemplateResult<1>) => TemplateResult<1>","f?: renderFnType","fnOrArray?: renderFnOrArrayType | string | number","injectBox?: (\n\t\tbox: TemplateResult<1> | TemplateResult<1>[]\n\t) => TemplateResult<1> | TemplateResult<1>[]","injectBox2?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>","f?: any","f?: renderFnOrArrayType | string | number","prefix: string","key: keyof typeof allRandomClassName","componentCount: ComponentCount","name: string","slot: TemplateResult<1>","on: OnEvent","el: EventTarget","on: Array<[string, EventHandler<any>]>","eventListeners: Map<string, EventListener>","handler: (event: Event) => void","options: boolean | AddEventListenerOptions | undefined","event: Event","e?: Element"],"sources":["../src/core/index.ts"],"sourcesContent":["import { html, TemplateResult } from \"lit\";\n\nconst ___LYCO_NULL___ = Symbol(\"___LYCO_NULL___\");\n\nexport type renderFnType = TemplateResult<1> | (() => TemplateResult<1>);\n\nexport type renderFnOrArrayType =\n\t| renderFnType\n\t| Array<TemplateResult<1>>\n\t| (() => TemplateResult<1>[]);\n\nexport function renderFn(fn?: renderFnType): TemplateResult<1> {\n\treturn fn ? (typeof fn === \"function\" ? fn() : fn) : html``;\n}\n\nexport type WithHtml<K> = ((children?: K) => TemplateResult<1>) & {\n\thtml: (\n\t\tstrings: TemplateStringsArray,\n\t\t...values: unknown[]\n\t) => TemplateResult<1>;\n};\n\nexport function renderFnOrArray(\n\tfnOrArray?: renderFnOrArrayType,\n\tinjectBox?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>\n): TemplateResult<1> | TemplateResult<1>[] {\n\tlet _injectBox = injectBox ?? ((box) => box);\n\tif (fnOrArray === undefined) {\n\t\treturn html``;\n\t}\n\tif (Array.isArray(fnOrArray)) {\n\t\treturn fnOrArray.map((htmlTemp, idx) =>\n\t\t\t_injectBox(renderFn(htmlTemp), idx, true, false)\n\t\t);\n\t} else if (typeof fnOrArray !== \"function\") {\n\t\treturn _injectBox(renderFn(fnOrArray), undefined, false, false);\n\t}\n\n\tconst result = fnOrArray();\n\tif (Array.isArray(result)) {\n\t\treturn result.map((htmlTemp, idx) =>\n\t\t\t_injectBox(renderFn(htmlTemp), idx, true, false)\n\t\t);\n\t} else {\n\t\treturn _injectBox(renderFn(result), undefined, false, true);\n\t}\n}\n\nexport function randomClassName(prefix?: string): string {\n\tconst random = Math.random().toString(36).substring(2, 15);\n\treturn prefix ? `lyco-${prefix}-${random}` : `lyco-${random}`;\n}\n\nexport function renderFnOrCurry(\n\tfn?: renderFnType,\n\tinjectBox?: (box: TemplateResult<1>) => TemplateResult<1>\n): TemplateResult<1> | ((fn?: renderFnType) => TemplateResult<1>) {\n\tconst _injectBox = injectBox ?? ((box) => box);\n\tconst curriedFn = (f?: renderFnType) => _injectBox(renderFn(f!));\n\n\treturn fn ? curriedFn(fn) : curriedFn;\n}\n\nexport function renderFnOrArrayOrCurry(\n\tfnOrArray?: renderFnOrArrayType | string | number,\n\tinjectBox?: (\n\t\tbox: TemplateResult<1> | TemplateResult<1>[]\n\t) => TemplateResult<1> | TemplateResult<1>[],\n\tinjectBox2?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>\n):\n\t| TemplateResult<1>\n\t| TemplateResult<1>[]\n\t| ((\n\t\t\tfnOrArray?: renderFnOrArrayType\n\t ) => TemplateResult<1> | TemplateResult<1>[]) {\n\tconst typeMap = {\n\t\tstring: (f?: any) => html` ${f} `,\n\t\tnumber: (f?: any) => html` ${f} `,\n\t};\n\tconst _fnOrArray =\n\t\ttypeof fnOrArray in typeMap\n\t\t\t? typeMap[typeof fnOrArray as \"string\" | \"number\"]\n\t\t\t: fnOrArray;\n\tconst _injectBox = injectBox ?? ((box) => box);\n\tconst curriedFn = (f?: renderFnOrArrayType | string | number) =>\n\t\t_injectBox(renderFnOrArray(f as any, injectBox2)!);\n\n\treturn _fnOrArray ? curriedFn(_fnOrArray) : curriedFn;\n}\n\nconst withInit = (\n\tprefix: string\n): {\n\tinit: boolean;\n\tprefix: string;\n\tclassName: string | typeof ___LYCO_NULL___;\n} => ({\n\tinit: false,\n\tprefix,\n\tclassName: ___LYCO_NULL___,\n});\n\nconst allRandomClassName = {\n\t\"GridBreakpoint::grid-breakpoint\": withInit(\"grid-breakpoint\"),\n\t\"Hidden::hidden-container\": withInit(\"hidden-container\"),\n\t\"ListGroup::list-group\": withInit(\"list-group\"),\n\t\"ScrollBar::scrollbar-container\": withInit(\"scrollbar-container\"),\n\t\"SkeletonLoader::skeleton\": withInit(\"skeleton\"),\n\t\"Swiper::swiper\": withInit(\"swiper\"),\n\t\"Table::table\": withInit(\"table\"),\n\t\"WaterFlow::waterflow\": withInit(\"waterflow\"),\n\t\"AutoFitGrid::auto-fit-grid\": withInit(\"auto-fit-grid\"),\n\t\"GridCol::grid-col\": withInit(\"grid-col\"),\n\t\"GridRow::grid-row\": withInit(\"grid-row\"),\n\t\"List::list\": withInit(\"list\"),\n\t\"Dialog::dialog\": withInit(\"dialog\"),\n\t\"SwitchInput::switch\": withInit(\"switch\"),\n\t\"Combobox::combobox\": withInit(\"combobox\"),\n};\n\nexport function getRandomClassName(key: keyof typeof allRandomClassName) {\n\tconst r = allRandomClassName[key];\n\tif (!r.init) {\n\t\tallRandomClassName[key].init = true;\n\t\tallRandomClassName[key].className = randomClassName(r.prefix);\n\t}\n\treturn allRandomClassName[key].className === ___LYCO_NULL___\n\t\t? randomClassName(r.prefix)\n\t\t: allRandomClassName[key].className;\n}\ntype ComponentCountItem = {\n\tvalue: number;\n};\n\ntype ComponentCount = {\n\t[key: string]: ComponentCountItem;\n} & {\n\tall: ComponentCountItem; // 修改为 ComponentCountItem 类型\n};\nexport const componentCount: ComponentCount = {\n\tall: { value: 0 },\n};\n\nexport function getComponentCount(name: string) {\n\tif (!componentCount[name]?.value) {\n\t\tcomponentCount[name] = { value: 0 };\n\t}\n\treturn componentCount[name].value;\n}\n\nexport function LycoComponent(name: string, slot: TemplateResult<1>) {\n\tcomponentCount.all = {\n\t\tvalue: componentCount.all.value + 1,\n\t};\n\tcomponentCount[name] === undefined\n\t\t? (componentCount[name] = { value: 0 })\n\t\t: (componentCount[name].value = componentCount[name].value + 1);\n\t// console.debug(\n\t// \t`LycoComponent: ${name} - ${componentCount[name].value} - ${componentCount.all.value}`\n\t// );\n\treturn html`\n\t\t<!-- ${name} - ${componentCount[name].value} -->\n\t\t${slot}\n\t`;\n}\n\n// type EventType = \"click\" | \"mousedown\" | \"mouseup\" | \"mousemove\" | \"touchstart\" | \"touchend\" | \"touchmove\";\n\n// class OnEvent<T extends HTMLElement> {\n// \tel: T;\n// \tconstructor(el: T) {\n// \t\tthis.el = el;\n// \t}\n// \t// 具体事件 监听方法\n// \ton<K extends keyof GlobalEventHandlersEventMap>(\n// \t\ttype: K,\n// \t\tlistener: (this: T, ev: GlobalEventHandlersEventMap[K]) => any\n// \t): void {\n// \t\t(this.el as any)[\"on\" + type] = listener;\n// \t}\n// }\n\ntype EventHandler<K extends keyof GlobalEventHandlersEventMap> =\n\t| ((event: GlobalEventHandlersEventMap[K]) => void)\n\t| {\n\t\t\thandler: (event: GlobalEventHandlersEventMap[K]) => void;\n\t\t\toptions?: boolean | AddEventListenerOptions;\n\t };\n\nexport type OnEvent = {\n\t[K in keyof GlobalEventHandlersEventMap]?: EventHandler<K>;\n};\n\nexport function withEvents(on: OnEvent) {\n\treturn on;\n}\n\nexport function bindEvents(\n\tel: EventTarget,\n\ton: Array<[string, EventHandler<any>]>,\n\teventListeners: Map<string, EventListener>\n): void {\n\ton.forEach(([name, entry]) => {\n\t\tif (!entry) return; // 添加空值检查\n\n\t\tif (eventListeners.has(name)) {\n\t\t\tel.removeEventListener(name, eventListeners.get(name)!);\n\t\t}\n\n\t\tlet handler: (event: Event) => void;\n\t\tlet options: boolean | AddEventListenerOptions | undefined;\n\n\t\tif (typeof entry === \"function\") {\n\t\t\thandler = entry;\n\t\t\toptions = undefined;\n\t\t} else {\n\t\t\thandler = entry.handler;\n\t\t\toptions = entry.options;\n\t\t}\n\n\t\tif (!handler) return; // 确保 handler 存在\n\n\t\tconst listener = (event: Event) => handler(event);\n\t\tel.addEventListener(name, listener, options);\n\t\teventListeners.set(name, listener);\n\t});\n}\n\nexport function createEventBinder(on: OnEvent) {\n\tconst eventListeners = new Map<string, EventListener>();\n\tconst _on = Object.entries(on);\n\tconst _el = {\n\t\tvalue: null as EventTarget | null,\n\t};\n\tconst self = {\n\t\tbind(el: EventTarget) {\n\t\t\tbindEvents(el, _on, eventListeners);\n\t\t\t_el.value = el;\n\t\t},\n\t\tunbindAll() {\n\t\t\teventListeners.forEach((k, v) => {\n\t\t\t\t_el.value?.removeEventListener(v, k);\n\t\t\t});\n\t\t\teventListeners.clear();\n\t\t\t_el.value = null;\n\t\t},\n\t\tauto: (e?: Element) => {\n\t\t\tif (e) {\n\t\t\t\tself.bind(e);\n\t\t\t} else {\n\t\t\t\tself.unbindAll();\n\t\t\t}\n\t\t},\n\t};\n\treturn self;\n}\n"],"mappings":"2BAEA,MAAM,EAAkB,OAAO,kBAAkB,CASjD,SAAgB,EAASA,EAAsC,CAC9D,OAAO,SAAa,GAAO,WAAa,GAAI,CAAG,EAAM,EAAK,CAC1D,CASD,SAAgB,EACfC,EACAC,EAM0C,CAC1C,IAAI,EAAa,IAAc,AAAC,GAAQ,GACxC,GAAI,QAAA,GACH,MAAO,GAAK,EAEb,GAAI,MAAM,QAAQ,EAAU,CAC3B,MAAO,GAAU,IAAI,CAAC,EAAU,IAC/B,EAAW,EAAS,EAAS,CAAE,GAAK,GAAM,EAAM,CAChD,WACgB,GAAc,WAC/B,MAAO,GAAW,EAAS,EAAU,KAAA,IAAa,GAAO,EAAM,CAGhE,IAAM,EAAS,GAAW,CAMzB,MALG,OAAM,QAAQ,EAAO,CACjB,EAAO,IAAI,CAAC,EAAU,IAC5B,EAAW,EAAS,EAAS,CAAE,GAAK,GAAM,EAAM,CAChD,CAEM,EAAW,EAAS,EAAO,KAAA,IAAa,GAAO,EAAK,AAE5D,CAED,SAAgB,EAAgBC,EAAyB,CACxD,IAAM,EAAS,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAG,GAAG,CAC1D,OAAO,GAAU,OAAO,EAAO,GAAG,EAAO,GAAK,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AgB,CACtB,AAAI,EACH,EAAK,KAAK,EAAE,CAEZ,EAAK,WAAW,AAEjB,CACD,EACD,OAAO,CACP"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-ClQ-MQf9.js","names":["fn?: renderFnType","fnOrArray?: renderFnOrArrayType","injectBox?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>","prefix?: string","injectBox?: (box: TemplateResult<1>) => TemplateResult<1>","f?: renderFnType","fnOrArray?: renderFnOrArrayType | string | number","injectBox?: (\n\t\tbox: TemplateResult<1> | TemplateResult<1>[]\n\t) => TemplateResult<1> | TemplateResult<1>[]","injectBox2?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>","f?: any","f?: renderFnOrArrayType | string | number","prefix: string","key: keyof typeof allRandomClassName","componentCount: ComponentCount","name: string","slot: TemplateResult<1>","on: OnEvent","el: EventTarget","on: Array<[string, EventHandler<any>]>","eventListeners: Map<string, EventListener>","handler: (event: Event) => void","options: boolean | AddEventListenerOptions | undefined","event: Event","e?: Element"],"sources":["../src/core/index.ts"],"sourcesContent":["import { html, TemplateResult } from \"lit\";\n\nconst ___LYCO_NULL___ = Symbol(\"___LYCO_NULL___\");\n\nexport type renderFnType = TemplateResult<1> | (() => TemplateResult<1>);\n\nexport type renderFnOrArrayType =\n\t| renderFnType\n\t| Array<TemplateResult<1>>\n\t| (() => TemplateResult<1>[]);\n\nexport function renderFn(fn?: renderFnType): TemplateResult<1> {\n\treturn fn ? (typeof fn === \"function\" ? fn() : fn) : html``;\n}\n\nexport type WithHtml<K> = ((children?: K) => TemplateResult<1>) & {\n\thtml: (\n\t\tstrings: TemplateStringsArray,\n\t\t...values: unknown[]\n\t) => TemplateResult<1>;\n};\n\nexport function renderFnOrArray(\n\tfnOrArray?: renderFnOrArrayType,\n\tinjectBox?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>\n): TemplateResult<1> | TemplateResult<1>[] {\n\tlet _injectBox = injectBox ?? ((box) => box);\n\tif (fnOrArray === undefined) {\n\t\treturn html``;\n\t}\n\tif (Array.isArray(fnOrArray)) {\n\t\treturn fnOrArray.map((htmlTemp, idx) =>\n\t\t\t_injectBox(renderFn(htmlTemp), idx, true, false)\n\t\t);\n\t} else if (typeof fnOrArray !== \"function\") {\n\t\treturn _injectBox(renderFn(fnOrArray), undefined, false, false);\n\t}\n\n\tconst result = fnOrArray();\n\tif (Array.isArray(result)) {\n\t\treturn result.map((htmlTemp, idx) =>\n\t\t\t_injectBox(renderFn(htmlTemp), idx, true, false)\n\t\t);\n\t} else {\n\t\treturn _injectBox(renderFn(result), undefined, false, true);\n\t}\n}\n\nexport function randomClassName(prefix?: string): string {\n\tconst random = Math.random().toString(36).substring(2, 15);\n\treturn prefix ? `lyco-${prefix}-${random}` : `lyco-${random}`;\n}\n\nexport function renderFnOrCurry(\n\tfn?: renderFnType,\n\tinjectBox?: (box: TemplateResult<1>) => TemplateResult<1>\n): TemplateResult<1> | ((fn?: renderFnType) => TemplateResult<1>) {\n\tconst _injectBox = injectBox ?? ((box) => box);\n\tconst curriedFn = (f?: renderFnType) => _injectBox(renderFn(f!));\n\n\treturn fn ? curriedFn(fn) : curriedFn;\n}\n\nexport function renderFnOrArrayOrCurry(\n\tfnOrArray?: renderFnOrArrayType | string | number,\n\tinjectBox?: (\n\t\tbox: TemplateResult<1> | TemplateResult<1>[]\n\t) => TemplateResult<1> | TemplateResult<1>[],\n\tinjectBox2?: (\n\t\tbox: TemplateResult<1>,\n\t\tidx?: number,\n\t\tisArray?: boolean,\n\t\tisFunc?: boolean\n\t) => TemplateResult<1>\n):\n\t| TemplateResult<1>\n\t| TemplateResult<1>[]\n\t| ((\n\t\t\tfnOrArray?: renderFnOrArrayType\n\t ) => TemplateResult<1> | TemplateResult<1>[]) {\n\tconst typeMap = {\n\t\tstring: (f?: any) => html` ${f} `,\n\t\tnumber: (f?: any) => html` ${f} `,\n\t};\n\tconst _fnOrArray =\n\t\ttypeof fnOrArray in typeMap\n\t\t\t? typeMap[typeof fnOrArray as \"string\" | \"number\"]\n\t\t\t: fnOrArray;\n\tconst _injectBox = injectBox ?? ((box) => box);\n\tconst curriedFn = (f?: renderFnOrArrayType | string | number) =>\n\t\t_injectBox(renderFnOrArray(f as any, injectBox2)!);\n\n\treturn _fnOrArray ? curriedFn(_fnOrArray) : curriedFn;\n}\n\nconst withInit = (\n\tprefix: string\n): {\n\tinit: boolean;\n\tprefix: string;\n\tclassName: string | typeof ___LYCO_NULL___;\n} => ({\n\tinit: false,\n\tprefix,\n\tclassName: ___LYCO_NULL___,\n});\n\nconst allRandomClassName = {\n\t\"GridBreakpoint::grid-breakpoint\": withInit(\"grid-breakpoint\"),\n\t\"Hidden::hidden-container\": withInit(\"hidden-container\"),\n\t\"ListGroup::list-group\": withInit(\"list-group\"),\n\t\"ScrollBar::scrollbar-container\": withInit(\"scrollbar-container\"),\n\t\"SkeletonLoader::skeleton\": withInit(\"skeleton\"),\n\t\"Swiper::swiper\": withInit(\"swiper\"),\n\t\"Table::table\": withInit(\"table\"),\n\t\"WaterFlow::waterflow\": withInit(\"waterflow\"),\n\t\"AutoFitGrid::auto-fit-grid\": withInit(\"auto-fit-grid\"),\n\t\"GridCol::grid-col\": withInit(\"grid-col\"),\n\t\"GridRow::grid-row\": withInit(\"grid-row\"),\n\t\"List::list\": withInit(\"list\"),\n\t\"Dialog::dialog\": withInit(\"dialog\"),\n\t\"SwitchInput::switch\": withInit(\"switch\"),\n\t\"Combobox::combobox\": withInit(\"combobox\"),\n};\n\nexport function getRandomClassName(key: keyof typeof allRandomClassName) {\n\tconst r = allRandomClassName[key];\n\tif (!r.init) {\n\t\tallRandomClassName[key].init = true;\n\t\tallRandomClassName[key].className = randomClassName(r.prefix);\n\t}\n\treturn allRandomClassName[key].className === ___LYCO_NULL___\n\t\t? randomClassName(r.prefix)\n\t\t: allRandomClassName[key].className;\n}\ntype ComponentCountItem = {\n\tvalue: number;\n};\n\ntype ComponentCount = {\n\t[key: string]: ComponentCountItem;\n} & {\n\tall: ComponentCountItem; // 修改为 ComponentCountItem 类型\n};\nexport const componentCount: ComponentCount = {\n\tall: { value: 0 },\n};\n\nexport function getComponentCount(name: string) {\n\tif (!componentCount[name]?.value) {\n\t\tcomponentCount[name] = { value: 0 };\n\t}\n\treturn componentCount[name].value;\n}\n\nexport function LycoComponent(name: string, slot: TemplateResult<1>) {\n\tcomponentCount.all = {\n\t\tvalue: componentCount.all.value + 1,\n\t};\n\tcomponentCount[name] === undefined\n\t\t? (componentCount[name] = { value: 0 })\n\t\t: (componentCount[name].value = componentCount[name].value + 1);\n\t// console.debug(\n\t// \t`LycoComponent: ${name} - ${componentCount[name].value} - ${componentCount.all.value}`\n\t// );\n\treturn html`\n\t\t<!-- ${name} - ${componentCount[name].value} -->\n\t\t${slot}\n\t`;\n}\n\n// type EventType = \"click\" | \"mousedown\" | \"mouseup\" | \"mousemove\" | \"touchstart\" | \"touchend\" | \"touchmove\";\n\n// class OnEvent<T extends HTMLElement> {\n// \tel: T;\n// \tconstructor(el: T) {\n// \t\tthis.el = el;\n// \t}\n// \t// 具体事件 监听方法\n// \ton<K extends keyof GlobalEventHandlersEventMap>(\n// \t\ttype: K,\n// \t\tlistener: (this: T, ev: GlobalEventHandlersEventMap[K]) => any\n// \t): void {\n// \t\t(this.el as any)[\"on\" + type] = listener;\n// \t}\n// }\n\ntype EventHandler<K extends keyof GlobalEventHandlersEventMap> =\n\t| ((event: GlobalEventHandlersEventMap[K]) => void)\n\t| {\n\t\t\thandler: (event: GlobalEventHandlersEventMap[K]) => void;\n\t\t\toptions?: boolean | AddEventListenerOptions;\n\t };\n\nexport type OnEvent = {\n\t[K in keyof GlobalEventHandlersEventMap]?: EventHandler<K>;\n};\n\nexport function withEvents(on: OnEvent) {\n\treturn on;\n}\n\nexport function bindEvents(\n\tel: EventTarget,\n\ton: Array<[string, EventHandler<any>]>,\n\teventListeners: Map<string, EventListener>\n): void {\n\ton.forEach(([name, entry]) => {\n\t\tif (!entry) return; // 添加空值检查\n\n\t\tif (eventListeners.has(name)) {\n\t\t\tel.removeEventListener(name, eventListeners.get(name)!);\n\t\t}\n\n\t\tlet handler: (event: Event) => void;\n\t\tlet options: boolean | AddEventListenerOptions | undefined;\n\n\t\tif (typeof entry === \"function\") {\n\t\t\thandler = entry;\n\t\t\toptions = undefined;\n\t\t} else {\n\t\t\thandler = entry.handler;\n\t\t\toptions = entry.options;\n\t\t}\n\n\t\tif (!handler) return; // 确保 handler 存在\n\n\t\tconst listener = (event: Event) => handler(event);\n\t\tel.addEventListener(name, listener, options);\n\t\teventListeners.set(name, listener);\n\t});\n}\n\nexport function createEventBinder(on: OnEvent) {\n\tconst eventListeners = new Map<string, EventListener>();\n\tconst _on = Object.entries(on);\n\tconst _el = {\n\t\tvalue: null as EventTarget | null,\n\t};\n\tconst self = {\n\t\tbind(el: EventTarget) {\n\t\t\tbindEvents(el, _on, eventListeners);\n\t\t\t_el.value = el;\n\t\t},\n\t\tunbindAll() {\n\t\t\teventListeners.forEach((k, v) => {\n\t\t\t\t_el.value?.removeEventListener(v, k);\n\t\t\t});\n\t\t\teventListeners.clear();\n\t\t\t_el.value = null;\n\t\t},\n\t\tauto: (e?: Element) => {\n\t\t\tif (e) {\n\t\t\t\tself.bind(e);\n\t\t\t} else {\n\t\t\t\tself.unbindAll();\n\t\t\t}\n\t\t},\n\t};\n\treturn self;\n}\n"],"mappings":"8dAEA,0BAAM,EAAkB,OAAO,kBAAkB,CASjD,SAAgB,EAASA,EAAsC,CAC9D,OAAO,SAAa,GAAO,WAAa,GAAI,CAAG,EAAM,EAAA,KAAK,CAC1D,CASD,SAAgB,EACfC,EACAC,EAM0C,CAC1C,IAAI,EAAa,IAAc,AAAC,GAAQ,GACxC,GAAI,QAAA,GACH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