@avento-space/ts-ui 1.1.1 → 1.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/dist/chunk-42QSY3LJ.js +4855 -0
- package/dist/chunk-42QSY3LJ.js.map +1 -0
- package/dist/chunk-7GJXOXOW.js +108 -0
- package/dist/chunk-7GJXOXOW.js.map +1 -0
- package/dist/chunk-DO3PEBDS.js +79 -0
- package/dist/chunk-DO3PEBDS.js.map +1 -0
- package/dist/chunk-MFONNOJU.js +3 -0
- package/dist/chunk-MFONNOJU.js.map +1 -0
- package/dist/chunk-NJAZMTMT.js +5645 -0
- package/dist/chunk-NJAZMTMT.js.map +1 -0
- package/dist/chunk-PRZASPFU.js +1730 -0
- package/dist/chunk-PRZASPFU.js.map +1 -0
- package/dist/chunk-Q5RCPPCF.js +406 -0
- package/dist/chunk-Q5RCPPCF.js.map +1 -0
- package/dist/chunk-RAWESWNC.js +3 -0
- package/dist/chunk-RAWESWNC.js.map +1 -0
- package/dist/chunk-U4WYCYL6.js +116 -0
- package/dist/chunk-U4WYCYL6.js.map +1 -0
- package/dist/components/index.d.ts +13 -11
- package/dist/components/index.js +5 -5
- package/dist/components/index.js.map +1 -1
- package/dist/define.d.ts +2 -2
- package/dist/define.js +8 -1
- package/dist/define.js.map +1 -1
- package/dist/{core/element.d.ts → element-DHtonJNX.d.ts} +3 -2
- package/dist/form.wc-CwjVsdUu.d.ts +1518 -0
- package/dist/icons/index.d.ts +33 -5
- package/dist/icons/index.js +5 -3
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +35 -10
- package/dist/index.js +44 -9
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -2
- package/dist/jsx-dev-runtime.js +3 -1
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +644 -7
- package/dist/jsx-runtime.js +3 -120
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/plugins/index.d.ts +21 -3
- package/dist/plugins/index.js +85 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/react/index.d.ts +1260 -15
- package/dist/react/index.js +1428 -15
- package/dist/react/index.js.map +1 -1
- package/dist/{core/types.d.ts → types-DWglFa91.d.ts} +8 -7
- package/package.json +32 -8
- package/dist/components/box.wc.d.ts +0 -24
- package/dist/components/box.wc.d.ts.map +0 -1
- package/dist/components/box.wc.js +0 -52
- package/dist/components/box.wc.js.map +0 -1
- package/dist/components/button.wc.d.ts +0 -32
- package/dist/components/button.wc.d.ts.map +0 -1
- package/dist/components/button.wc.js +0 -91
- package/dist/components/button.wc.js.map +0 -1
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/input.wc.d.ts +0 -45
- package/dist/components/input.wc.d.ts.map +0 -1
- package/dist/components/input.wc.js +0 -130
- package/dist/components/input.wc.js.map +0 -1
- package/dist/components/list.wc.d.ts +0 -49
- package/dist/components/list.wc.d.ts.map +0 -1
- package/dist/components/list.wc.js +0 -120
- package/dist/components/list.wc.js.map +0 -1
- package/dist/components/portal.wc.d.ts +0 -18
- package/dist/components/portal.wc.d.ts.map +0 -1
- package/dist/components/portal.wc.js +0 -78
- package/dist/components/portal.wc.js.map +0 -1
- package/dist/components/styles.d.ts +0 -7
- package/dist/components/styles.d.ts.map +0 -1
- package/dist/components/styles.js +0 -134
- package/dist/components/styles.js.map +0 -1
- package/dist/core/define.d.ts +0 -5
- package/dist/core/define.d.ts.map +0 -1
- package/dist/core/define.js +0 -26
- package/dist/core/define.js.map +0 -1
- package/dist/core/element.d.ts.map +0 -1
- package/dist/core/element.js +0 -30
- package/dist/core/element.js.map +0 -1
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -5
- package/dist/core/index.js.map +0 -1
- package/dist/core/plugin.d.ts +0 -17
- package/dist/core/plugin.d.ts.map +0 -1
- package/dist/core/plugin.js +0 -117
- package/dist/core/plugin.js.map +0 -1
- package/dist/core/reactive-context.d.ts +0 -12
- package/dist/core/reactive-context.d.ts.map +0 -1
- package/dist/core/reactive-context.js +0 -34
- package/dist/core/reactive-context.js.map +0 -1
- package/dist/core/scheduler.d.ts +0 -13
- package/dist/core/scheduler.d.ts.map +0 -1
- package/dist/core/scheduler.js +0 -80
- package/dist/core/scheduler.js.map +0 -1
- package/dist/core/signal.d.ts +0 -14
- package/dist/core/signal.d.ts.map +0 -1
- package/dist/core/signal.js +0 -391
- package/dist/core/signal.js.map +0 -1
- package/dist/core/store.d.ts +0 -6
- package/dist/core/store.d.ts.map +0 -1
- package/dist/core/store.js +0 -35
- package/dist/core/store.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -2
- package/dist/core/types.js.map +0 -1
- package/dist/define.d.ts.map +0 -1
- package/dist/icons/icon-element.d.ts +0 -25
- package/dist/icons/icon-element.d.ts.map +0 -1
- package/dist/icons/icon-element.js +0 -63
- package/dist/icons/icon-element.js.map +0 -1
- package/dist/icons/index.d.ts.map +0 -1
- package/dist/icons/registry.d.ts +0 -6
- package/dist/icons/registry.d.ts.map +0 -1
- package/dist/icons/registry.js +0 -4775
- package/dist/icons/registry.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/jsx-dev-runtime.d.ts.map +0 -1
- package/dist/jsx-runtime.d.ts.map +0 -1
- package/dist/jsx-types.d.ts +0 -651
- package/dist/jsx-types.d.ts.map +0 -1
- package/dist/jsx-types.js +0 -3
- package/dist/jsx-types.js.map +0 -1
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/router.d.ts +0 -4
- package/dist/plugins/router.d.ts.map +0 -1
- package/dist/plugins/router.js +0 -90
- package/dist/plugins/router.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -16
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/plugins/types.js +0 -2
- package/dist/plugins/types.js.map +0 -1
- package/dist/react/icon.d.ts +0 -8
- package/dist/react/icon.d.ts.map +0 -1
- package/dist/react/icon.js +0 -7
- package/dist/react/icon.js.map +0 -1
- package/dist/react/icons.d.ts +0 -1194
- package/dist/react/icons.d.ts.map +0 -1
- package/dist/react/icons.js +0 -1196
- package/dist/react/icons.js.map +0 -1
- package/dist/react/index.d.ts.map +0 -1
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,121 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (key === 'key' || key === 'children' || key === 'ref')
|
|
5
|
-
return;
|
|
6
|
-
if (key === 'className' || key === 'class') {
|
|
7
|
-
el.setAttribute('class', String(value ?? ''));
|
|
8
|
-
}
|
|
9
|
-
else if (key === 'style' && value && typeof value === 'object') {
|
|
10
|
-
Object.assign(el.style, value);
|
|
11
|
-
}
|
|
12
|
-
else if (key === 'style' && typeof value === 'string') {
|
|
13
|
-
el.setAttribute('style', value);
|
|
14
|
-
}
|
|
15
|
-
else if (key.startsWith('on') && typeof value === 'function') {
|
|
16
|
-
const event = key.slice(2).toLowerCase();
|
|
17
|
-
el.addEventListener(event, value);
|
|
18
|
-
}
|
|
19
|
-
else if (value != null && value !== false) {
|
|
20
|
-
el.setAttribute(key, String(value));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
el.removeAttribute(key);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function applySignalProp(el, key, sig) {
|
|
27
|
-
effect(() => {
|
|
28
|
-
const val = sig.get();
|
|
29
|
-
if (key.startsWith('on') && typeof val === 'function') {
|
|
30
|
-
const event = key.slice(2).toLowerCase();
|
|
31
|
-
el.addEventListener(event, val);
|
|
32
|
-
}
|
|
33
|
-
else if (val != null && val !== false) {
|
|
34
|
-
el.setAttribute(key, String(val));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
el.removeAttribute(key);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function createTextNode(value) {
|
|
42
|
-
const text = document.createTextNode(String(value ?? ''));
|
|
43
|
-
if (isSignal(value)) {
|
|
44
|
-
effect(() => { text.textContent = String(value.get() ?? ''); });
|
|
45
|
-
}
|
|
46
|
-
return text;
|
|
47
|
-
}
|
|
48
|
-
function isSignalLike(val) {
|
|
49
|
-
return isSignal(val);
|
|
50
|
-
}
|
|
51
|
-
export function jsx(type, config, ...children) {
|
|
52
|
-
const props = config ? { ...config } : {};
|
|
53
|
-
const key = props.key;
|
|
54
|
-
delete props.key;
|
|
55
|
-
if (typeof type === 'function') {
|
|
56
|
-
const rendered = type(props, ...children);
|
|
57
|
-
return rendered instanceof Node ? rendered : document.createTextNode(String(rendered ?? ''));
|
|
58
|
-
}
|
|
59
|
-
if (type === Fragment) {
|
|
60
|
-
const frag = document.createDocumentFragment();
|
|
61
|
-
for (const child of children) {
|
|
62
|
-
const node = toNode(child);
|
|
63
|
-
if (Array.isArray(node)) {
|
|
64
|
-
for (const n of node)
|
|
65
|
-
frag.appendChild(n);
|
|
66
|
-
}
|
|
67
|
-
else if (node) {
|
|
68
|
-
frag.appendChild(node);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return frag;
|
|
72
|
-
}
|
|
73
|
-
const tag = type;
|
|
74
|
-
const el = document.createElement(tag);
|
|
75
|
-
for (const [key, value] of Object.entries(props)) {
|
|
76
|
-
if (key === 'children') {
|
|
77
|
-
const childNodes = Array.isArray(value) ? value : [value];
|
|
78
|
-
for (const child of childNodes) {
|
|
79
|
-
const node = toNode(child);
|
|
80
|
-
if (Array.isArray(node)) {
|
|
81
|
-
for (const n of node)
|
|
82
|
-
el.appendChild(n);
|
|
83
|
-
}
|
|
84
|
-
else if (node) {
|
|
85
|
-
el.appendChild(node);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (isSignalLike(value)) {
|
|
90
|
-
applySignalProp(el, key, value);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
setDOMProp(el, key, value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
for (const child of children) {
|
|
97
|
-
const node = toNode(child);
|
|
98
|
-
if (Array.isArray(node)) {
|
|
99
|
-
for (const n of node)
|
|
100
|
-
el.appendChild(n);
|
|
101
|
-
}
|
|
102
|
-
else if (node) {
|
|
103
|
-
el.appendChild(node);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return el;
|
|
107
|
-
}
|
|
108
|
-
export const jsxs = jsx;
|
|
109
|
-
export const jsxDEV = jsx;
|
|
110
|
-
function toNode(child) {
|
|
111
|
-
if (child == null || child === false || child === true)
|
|
112
|
-
return null;
|
|
113
|
-
if (child instanceof Node)
|
|
114
|
-
return child;
|
|
115
|
-
if (Array.isArray(child))
|
|
116
|
-
return child.map(c => toNode(c)).filter(Boolean);
|
|
117
|
-
if (isSignalLike(child))
|
|
118
|
-
return createTextNode(child);
|
|
119
|
-
return document.createTextNode(String(child));
|
|
120
|
-
}
|
|
1
|
+
export { Fragment, jsx, jsxDEV, jsxs } from './chunk-7GJXOXOW.js';
|
|
2
|
+
import './chunk-Q5RCPPCF.js';
|
|
3
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
121
4
|
//# sourceMappingURL=jsx-runtime.js.map
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"jsx-runtime.js"}
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { P as Plugin } from '../types-DWglFa91.js';
|
|
2
|
+
|
|
3
|
+
interface RouterPluginConfig {
|
|
4
|
+
mode?: 'history' | 'hash' | 'memory';
|
|
5
|
+
base?: string;
|
|
6
|
+
}
|
|
7
|
+
interface RouterPlugin extends Plugin {
|
|
8
|
+
navigate(path: string): void;
|
|
9
|
+
getCurrentPath(): string;
|
|
10
|
+
getQuery(): Record<string, string>;
|
|
11
|
+
subscribe(fn: (path: string) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
interface DevToolsPlugin extends Plugin {
|
|
14
|
+
sendEvent(name: string, data?: any): void;
|
|
15
|
+
logStateChange(path: string, oldVal: any, newVal: any): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare function createRouter(config?: RouterPluginConfig): RouterPlugin;
|
|
19
|
+
declare function useRouter(): RouterPlugin;
|
|
20
|
+
|
|
21
|
+
export { type DevToolsPlugin, type RouterPlugin, type RouterPluginConfig, createRouter, useRouter };
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,2 +1,86 @@
|
|
|
1
|
-
|
|
1
|
+
import { getPlugin, registerPlugin } from '../chunk-U4WYCYL6.js';
|
|
2
|
+
import { signal } from '../chunk-Q5RCPPCF.js';
|
|
3
|
+
|
|
4
|
+
// src/plugins/router.ts
|
|
5
|
+
var isBrowser = typeof window !== "undefined";
|
|
6
|
+
function getBrowserPath(base, mode) {
|
|
7
|
+
if (mode === "memory") return "/";
|
|
8
|
+
if (!isBrowser) return "/";
|
|
9
|
+
if (mode === "hash") {
|
|
10
|
+
return window.location.hash.slice(1) || "/";
|
|
11
|
+
}
|
|
12
|
+
return window.location.pathname.replace(base, "") || "/";
|
|
13
|
+
}
|
|
14
|
+
function createRouter(config = {}) {
|
|
15
|
+
const mode = config.mode ?? "history";
|
|
16
|
+
const base = config.base ?? "";
|
|
17
|
+
const currentPath = signal(getBrowserPath(base, mode));
|
|
18
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
19
|
+
function navigate(path) {
|
|
20
|
+
const fullPath = base + path;
|
|
21
|
+
if (isBrowser) {
|
|
22
|
+
if (mode === "hash") {
|
|
23
|
+
window.location.hash = path;
|
|
24
|
+
} else if (mode === "history") {
|
|
25
|
+
window.history.pushState(null, "", fullPath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
currentPath.set(path);
|
|
29
|
+
}
|
|
30
|
+
function getCurrentPath() {
|
|
31
|
+
return currentPath.get();
|
|
32
|
+
}
|
|
33
|
+
function getQuery() {
|
|
34
|
+
if (!isBrowser) return {};
|
|
35
|
+
const params = new URLSearchParams(window.location.search);
|
|
36
|
+
const result = {};
|
|
37
|
+
params.forEach((value, key) => {
|
|
38
|
+
result[key] = value;
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
function subscribe(fn) {
|
|
43
|
+
listeners.add(fn);
|
|
44
|
+
return () => listeners.delete(fn);
|
|
45
|
+
}
|
|
46
|
+
currentPath.subscribe(() => {
|
|
47
|
+
const path = currentPath.get();
|
|
48
|
+
listeners.forEach((fn) => fn(path));
|
|
49
|
+
});
|
|
50
|
+
if (isBrowser) {
|
|
51
|
+
if (mode === "history") {
|
|
52
|
+
window.addEventListener("popstate", () => {
|
|
53
|
+
currentPath.set(window.location.pathname.replace(base, "") || "/");
|
|
54
|
+
});
|
|
55
|
+
} else if (mode === "hash") {
|
|
56
|
+
window.addEventListener("hashchange", () => {
|
|
57
|
+
currentPath.set(window.location.hash.slice(1) || "/");
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const router = {
|
|
62
|
+
name: "router",
|
|
63
|
+
version: "0.2.0",
|
|
64
|
+
setup(api) {
|
|
65
|
+
api.registerHook("router:navigate", (path) => {
|
|
66
|
+
navigate(path);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
navigate,
|
|
70
|
+
getCurrentPath,
|
|
71
|
+
getQuery,
|
|
72
|
+
subscribe
|
|
73
|
+
};
|
|
74
|
+
return router;
|
|
75
|
+
}
|
|
76
|
+
function useRouter() {
|
|
77
|
+
const existing = getPlugin("router");
|
|
78
|
+
if (existing) return existing;
|
|
79
|
+
const router = createRouter();
|
|
80
|
+
registerPlugin(router);
|
|
81
|
+
return router;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { createRouter, useRouter };
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
2
86
|
//# sourceMappingURL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AAK,GAAG,CAAA;AAAA,MACtD,CAAC,CAAA;AAAA,IACH;AAAA,EACF;AAEA,EAAA,MAAM,MAAA,GAAuB;AAAA,IAC3B,IAAA,EAAM,QAAA;AAAA,IACN,OAAA,EAAS,OAAA;AAAA,IACT,MAAM,GAAA,EAAK;AACT,MAAA,GAAA,CAAI,YAAA,CAAa,iBAAA,EAAmB,CAAC,IAAA,KAAiB;AACpD,QAAA,QAAA,CAAS,IAAI,CAAA;AAAA,MACf,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,SAAA,GAA0B;AACxC,EAAA,MAAM,QAAA,GAAW,UAAU,QAAQ,CAAA;AACnC,EAAA,IAAI,UAAU,OAAO,QAAA;AAErB,EAAA,MAAM,SAAS,YAAA,EAAa;AAC5B,EAAA,cAAA,CAAe,MAAM,CAAA;AACrB,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import type { RouterPlugin, RouterPluginConfig } from './types.js';\nimport { registerPlugin, getPlugin } from '../core/plugin.js';\nimport { signal } from '../core/signal.js';\n\nconst isBrowser = typeof window !== 'undefined';\n\nfunction getBrowserPath(base: string, mode: string): string {\n if (mode === 'memory') return '/';\n if (!isBrowser) return '/';\n if (mode === 'hash') {\n return window.location.hash.slice(1) || '/';\n }\n return window.location.pathname.replace(base, '') || '/';\n}\n\nexport function createRouter(config: RouterPluginConfig = {}): RouterPlugin {\n const mode = config.mode ?? 'history';\n const base = config.base ?? '';\n const currentPath = signal(getBrowserPath(base, mode));\n const listeners = new Set<(path: string) => void>();\n\n function getInitialPath(): string {\n return getBrowserPath(base, mode);\n }\n\n function navigate(path: string): void {\n const fullPath = base + path;\n if (isBrowser) {\n if (mode === 'hash') {\n window.location.hash = path;\n } else if (mode === 'history') {\n window.history.pushState(null, '', fullPath);\n }\n }\n currentPath.set(path);\n }\n\n function getCurrentPath(): string {\n return currentPath.get();\n }\n\n function getQuery(): Record<string, string> {\n if (!isBrowser) return {};\n const params = new URLSearchParams(window.location.search);\n const result: Record<string, string> = {};\n params.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n }\n\n function subscribe(fn: (path: string) => void): () => void {\n listeners.add(fn);\n return () => listeners.delete(fn);\n }\n\n currentPath.subscribe(() => {\n const path = currentPath.get();\n listeners.forEach((fn) => fn(path));\n });\n\n if (isBrowser) {\n if (mode === 'history') {\n window.addEventListener('popstate', () => {\n currentPath.set(window.location.pathname.replace(base, '') || '/');\n });\n } else if (mode === 'hash') {\n window.addEventListener('hashchange', () => {\n currentPath.set(window.location.hash.slice(1) || '/');\n });\n }\n }\n\n const router: RouterPlugin = {\n name: 'router',\n version: '0.2.0',\n setup(api) {\n api.registerHook('router:navigate', (path: string) => {\n navigate(path);\n });\n },\n navigate,\n getCurrentPath,\n getQuery,\n subscribe,\n };\n\n return router;\n}\n\nexport function useRouter(): RouterPlugin {\n const existing = getPlugin('router');\n if (existing) return existing as RouterPlugin;\n\n const router = createRouter();\n registerPlugin(router);\n return router;\n}\n"]}
|