rask-ui 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.
Files changed (53) hide show
  1. package/README.md +263 -0
  2. package/dist/component.d.ts +21 -0
  3. package/dist/component.d.ts.map +1 -0
  4. package/dist/component.js +128 -0
  5. package/dist/context.d.ts +5 -0
  6. package/dist/context.d.ts.map +1 -0
  7. package/dist/context.js +29 -0
  8. package/dist/createAsync.d.ts +16 -0
  9. package/dist/createAsync.d.ts.map +1 -0
  10. package/dist/createAsync.js +24 -0
  11. package/dist/createAsyncState.d.ts +16 -0
  12. package/dist/createAsyncState.d.ts.map +1 -0
  13. package/dist/createAsyncState.js +24 -0
  14. package/dist/createContext.d.ts +5 -0
  15. package/dist/createContext.d.ts.map +1 -0
  16. package/dist/createContext.js +29 -0
  17. package/dist/createMutation.d.ts +20 -0
  18. package/dist/createMutation.d.ts.map +1 -0
  19. package/dist/createMutation.js +53 -0
  20. package/dist/createQuery.d.ts +19 -0
  21. package/dist/createQuery.d.ts.map +1 -0
  22. package/dist/createQuery.js +57 -0
  23. package/dist/createRef.d.ts +5 -0
  24. package/dist/createRef.d.ts.map +1 -0
  25. package/dist/createRef.js +7 -0
  26. package/dist/createState.d.ts +2 -0
  27. package/dist/createState.d.ts.map +1 -0
  28. package/dist/createState.js +52 -0
  29. package/dist/error.d.ts +5 -0
  30. package/dist/error.d.ts.map +1 -0
  31. package/dist/error.js +7 -0
  32. package/dist/index.d.ts +10 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +9 -0
  35. package/dist/jsx-dev-runtime.d.ts +4 -0
  36. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  37. package/dist/jsx-dev-runtime.js +5 -0
  38. package/dist/jsx-runtime.d.ts +15 -0
  39. package/dist/jsx-runtime.d.ts.map +1 -0
  40. package/dist/jsx-runtime.js +19 -0
  41. package/dist/jsx.d.ts +257 -0
  42. package/dist/jsx.d.ts.map +1 -0
  43. package/dist/jsx.js +42 -0
  44. package/dist/observation.d.ts +17 -0
  45. package/dist/observation.d.ts.map +1 -0
  46. package/dist/observation.js +50 -0
  47. package/dist/render.d.ts +7 -0
  48. package/dist/render.d.ts.map +1 -0
  49. package/dist/render.js +65 -0
  50. package/dist/suspense.d.ts +25 -0
  51. package/dist/suspense.d.ts.map +1 -0
  52. package/dist/suspense.js +97 -0
  53. package/package.json +41 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createQuery.d.ts","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,CAAC,CAAC,IACb;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG;IACrC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CA+DlE"}
@@ -0,0 +1,57 @@
1
+ import { createState } from "./createState";
2
+ export function createQuery(fetcher) {
3
+ const state = createState({
4
+ isPending: true,
5
+ data: null,
6
+ error: null,
7
+ });
8
+ const assign = (newState) => {
9
+ Object.assign(state, newState);
10
+ };
11
+ let currentAbortController;
12
+ const fetch = () => {
13
+ currentAbortController?.abort();
14
+ const abortController = (currentAbortController = new AbortController());
15
+ fetcher()
16
+ .then((data) => {
17
+ if (abortController.signal.aborted) {
18
+ return;
19
+ }
20
+ assign({
21
+ isPending: false,
22
+ data,
23
+ error: null,
24
+ });
25
+ })
26
+ .catch((error) => {
27
+ if (abortController.signal.aborted) {
28
+ return;
29
+ }
30
+ assign({
31
+ isPending: false,
32
+ data: null,
33
+ error: String(error),
34
+ });
35
+ });
36
+ };
37
+ fetch();
38
+ return {
39
+ get isPending() {
40
+ return state.isPending;
41
+ },
42
+ get data() {
43
+ return state.data;
44
+ },
45
+ get error() {
46
+ return state.error;
47
+ },
48
+ fetch(force) {
49
+ assign({
50
+ isPending: true,
51
+ data: force ? null : state.data,
52
+ error: null,
53
+ });
54
+ fetch();
55
+ },
56
+ };
57
+ }
@@ -0,0 +1,5 @@
1
+ export declare function createRef<T>(): {
2
+ (node: T | null): void;
3
+ current: T | null;
4
+ };
5
+ //# sourceMappingURL=createRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRef.d.ts","sourceRoot":"","sources":["../src/createRef.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC;WACN,CAAC,GAAG,IAAI;;EAO5B"}
@@ -0,0 +1,7 @@
1
+ export function createRef() {
2
+ function ref(node) {
3
+ ref.current = node;
4
+ }
5
+ ref.current = null;
6
+ return ref;
7
+ }
@@ -0,0 +1,2 @@
1
+ export declare function createState<T extends object>(state: T): T;
2
+ //# sourceMappingURL=createState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createState.d.ts","sourceRoot":"","sources":["../src/createState.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEzD"}
@@ -0,0 +1,52 @@
1
+ import { getCurrentObserver, Signal } from "./observation";
2
+ export function createState(state) {
3
+ return getProxy(state);
4
+ }
5
+ const proxyCache = new WeakMap();
6
+ function getProxy(value) {
7
+ if (proxyCache.has(value)) {
8
+ return proxyCache.get(value);
9
+ }
10
+ const signals = {};
11
+ const proxy = new Proxy(value, {
12
+ get(target, key) {
13
+ const value = Reflect.get(target, key);
14
+ if (typeof key === "symbol" || typeof value === "function") {
15
+ return value;
16
+ }
17
+ const observer = getCurrentObserver();
18
+ if (observer) {
19
+ const signal = (signals[key] = signals[key] || new Signal());
20
+ observer.subscribeSignal(signal);
21
+ }
22
+ if (Array.isArray(value) ||
23
+ (typeof value === "object" && value !== null)) {
24
+ return getProxy(value);
25
+ }
26
+ return value;
27
+ },
28
+ set(target, key, newValue) {
29
+ if (typeof key === "symbol") {
30
+ return Reflect.set(target, key, newValue);
31
+ }
32
+ const oldValue = Reflect.get(target, key);
33
+ // We only notify if actual change, though array length actually updates under the hood
34
+ if (newValue !== oldValue || (Array.isArray(value) && key === "length")) {
35
+ const signal = signals[key];
36
+ signal?.notify();
37
+ }
38
+ return Reflect.set(target, key, newValue);
39
+ },
40
+ deleteProperty(target, key) {
41
+ if (typeof key === "symbol") {
42
+ return Reflect.deleteProperty(target, key);
43
+ }
44
+ const signal = signals[key];
45
+ signal?.notify();
46
+ delete signals[key];
47
+ return Reflect.deleteProperty(target, key);
48
+ },
49
+ });
50
+ proxyCache.set(value, proxy);
51
+ return proxy;
52
+ }
@@ -0,0 +1,5 @@
1
+ export declare function ErrorBoundary(props: {
2
+ error: (error: unknown) => ChildNode | ChildNode[];
3
+ children: any;
4
+ }): () => any;
5
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,GAAG,SAAS,EAAE,CAAC;IACnD,QAAQ,EAAE,GAAG,CAAC;CACf,aAKA"}
package/dist/error.js ADDED
@@ -0,0 +1,7 @@
1
+ import { getCurrentComponent } from "./component";
2
+ export function ErrorBoundary(props) {
3
+ const component = getCurrentComponent();
4
+ return () => {
5
+ return component.error ? props.error(component.error) : props.children;
6
+ };
7
+ }
@@ -0,0 +1,10 @@
1
+ export { render } from "./render";
2
+ export { onMount, onCleanup } from "./component";
3
+ export { createContext } from "./createContext";
4
+ export { createState } from "./createState";
5
+ export { createAsync } from "./createAsync";
6
+ export { ErrorBoundary } from "./error";
7
+ export { createQuery } from "./createQuery";
8
+ export { createMutation } from "./createMutation";
9
+ export { createRef } from "./createRef";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { render } from "./render";
2
+ export { onMount, onCleanup } from "./component";
3
+ export { createContext } from "./createContext";
4
+ export { createState } from "./createState";
5
+ export { createAsync } from "./createAsync";
6
+ export { ErrorBoundary } from "./error";
7
+ export { createQuery } from "./createQuery";
8
+ export { createMutation } from "./createMutation";
9
+ export { createRef } from "./createRef";
@@ -0,0 +1,4 @@
1
+ export { jsx, jsxs, Fragment, FragmentSymbol } from './jsx-runtime';
2
+ export type { JSX } from './jsx-runtime';
3
+ export { jsx as jsxDEV } from './jsx-runtime';
4
+ //# sourceMappingURL=jsx-dev-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ // JSX dev runtime - adds jsxDEV for development mode
2
+ export { jsx, jsxs, Fragment, FragmentSymbol } from './jsx-runtime';
3
+ // In development mode, TypeScript uses jsxDEV instead of jsx
4
+ // We just alias it to jsx since we don't need the extra dev-mode params
5
+ export { jsx as jsxDEV } from './jsx-runtime';
@@ -0,0 +1,15 @@
1
+ import type { JSXInternal } from "./jsx";
2
+ export declare const FragmentSymbol: unique symbol;
3
+ export declare function jsx(type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>, key?: string): any;
4
+ export declare function jsx<P>(type: (props: P) => any, props: P & {
5
+ children?: any;
6
+ }, key?: string): any;
7
+ export declare function jsxs(type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>, key?: string): any;
8
+ export declare function jsxs<P>(type: (props: P) => any, props: P & {
9
+ children?: any[];
10
+ }, key?: string): any;
11
+ export declare function Fragment(props?: {
12
+ children?: any;
13
+ }): any;
14
+ export type { JSXInternal as JSX } from "./jsx";
15
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzC,eAAO,MAAM,cAAc,eAA8C,CAAC;AAE1E,wBAAgB,GAAG,CACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,cAAc,GAC/B,WAAW,CAAC,aAAa,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrB,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AACP,wBAAgB,GAAG,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,EAC7B,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AAaP,wBAAgB,IAAI,CAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,cAAc,GAC/B,WAAW,CAAC,aAAa,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrB,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AACP,wBAAgB,IAAI,CAAC,CAAC,EACpB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAA;CAAE,EAC/B,GAAG,CAAC,EAAE,MAAM,GACX,GAAG,CAAC;AAKP,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,GAAG,CAExD;AAKD,YAAY,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { jsx as internalJsx } from "./render";
2
+ export const FragmentSymbol = Symbol.for("superfine-components.Fragment");
3
+ export function jsx(type, props, key) {
4
+ const { children, ...restProps } = props;
5
+ const finalProps = key !== undefined ? { ...restProps, key } : restProps;
6
+ const finalChildren = Array.isArray(children)
7
+ ? children
8
+ : children === undefined
9
+ ? []
10
+ : [children];
11
+ return internalJsx(type, finalProps, finalChildren);
12
+ }
13
+ export function jsxs(type, props, key) {
14
+ return jsx(type, props, key);
15
+ }
16
+ export function Fragment(props) {
17
+ return props?.children;
18
+ }
19
+ Fragment.$$typeof = FragmentSymbol;
package/dist/jsx.d.ts ADDED
@@ -0,0 +1,257 @@
1
+ // JSX type definitions
2
+ // Note: This is JSXInternal, which gets renamed to JSX on export from jsx-runtime
3
+ import type { Ref } from "./state";
4
+
5
+ export namespace JSXInternal {
6
+ export type Element = any;
7
+
8
+ export interface ElementAttributesProperty {
9
+ props: {};
10
+ }
11
+
12
+ export interface ElementChildrenAttribute {
13
+ children: {};
14
+ }
15
+
16
+ export interface IntrinsicAttributes {
17
+ key?: any;
18
+ }
19
+
20
+ // CSS Properties
21
+ export type CSSProperties = {
22
+ [key: string]: string | number | undefined;
23
+ };
24
+
25
+ // Common HTML Attributes
26
+ export interface HTMLAttributes<T = HTMLElement> {
27
+ ref?: Ref<T> | ((element: T | null) => void);
28
+ id?: string;
29
+ class?: string | Record<string, boolean>;
30
+ style?: string | CSSProperties;
31
+ title?: string;
32
+ role?: string;
33
+ tabIndex?: number;
34
+
35
+ onClick?: (event: MouseEvent) => void;
36
+ onDblClick?: (event: MouseEvent) => void;
37
+ onChange?: (event: Event) => void;
38
+ onInput?: (event: Event) => void;
39
+ onSubmit?: (event: Event) => void;
40
+ onFocus?: (event: FocusEvent) => void;
41
+ onBlur?: (event: FocusEvent) => void;
42
+ onKeyDown?: (event: KeyboardEvent) => void;
43
+ onKeyUp?: (event: KeyboardEvent) => void;
44
+ onKeyPress?: (event: KeyboardEvent) => void;
45
+ onMouseDown?: (event: MouseEvent) => void;
46
+ onMouseUp?: (event: MouseEvent) => void;
47
+ onMouseEnter?: (event: MouseEvent) => void;
48
+ onMouseLeave?: (event: MouseEvent) => void;
49
+ onMouseMove?: (event: MouseEvent) => void;
50
+ onMouseOver?: (event: MouseEvent) => void;
51
+ onMouseOut?: (event: MouseEvent) => void;
52
+ onWheel?: (event: WheelEvent) => void;
53
+ onScroll?: (event: Event) => void;
54
+ onTouchStart?: (event: TouchEvent) => void;
55
+ onTouchEnd?: (event: TouchEvent) => void;
56
+ onTouchMove?: (event: TouchEvent) => void;
57
+ onTouchCancel?: (event: TouchEvent) => void;
58
+
59
+ [key: `aria-${string}`]: string | boolean | number | undefined;
60
+ [key: `data-${string}`]: string | boolean | number | undefined;
61
+
62
+ children?: any;
63
+ }
64
+
65
+ export interface AnchorHTMLAttributes<T = HTMLAnchorElement>
66
+ extends HTMLAttributes<T> {
67
+ href?: string;
68
+ target?: "_blank" | "_self" | "_parent" | "_top";
69
+ rel?: string;
70
+ download?: string;
71
+ }
72
+
73
+ export interface ButtonHTMLAttributes<T = HTMLButtonElement>
74
+ extends HTMLAttributes<T> {
75
+ type?: "button" | "submit" | "reset";
76
+ disabled?: boolean;
77
+ name?: string;
78
+ value?: string;
79
+ }
80
+
81
+ export interface FormHTMLAttributes<T = HTMLFormElement>
82
+ extends HTMLAttributes<T> {
83
+ action?: string;
84
+ method?: "get" | "post";
85
+ enctype?: string;
86
+ target?: string;
87
+ noValidate?: boolean;
88
+ }
89
+
90
+ export interface InputHTMLAttributes<T = HTMLInputElement>
91
+ extends HTMLAttributes<T> {
92
+ type?:
93
+ | "button"
94
+ | "checkbox"
95
+ | "color"
96
+ | "date"
97
+ | "datetime-local"
98
+ | "email"
99
+ | "file"
100
+ | "hidden"
101
+ | "image"
102
+ | "month"
103
+ | "number"
104
+ | "password"
105
+ | "radio"
106
+ | "range"
107
+ | "reset"
108
+ | "search"
109
+ | "submit"
110
+ | "tel"
111
+ | "text"
112
+ | "time"
113
+ | "url"
114
+ | "week";
115
+ value?: string | number;
116
+ defaultValue?: string | number;
117
+ placeholder?: string;
118
+ disabled?: boolean;
119
+ required?: boolean;
120
+ readOnly?: boolean;
121
+ name?: string;
122
+ checked?: boolean;
123
+ defaultChecked?: boolean;
124
+ min?: string | number;
125
+ max?: string | number;
126
+ step?: string | number;
127
+ pattern?: string;
128
+ accept?: string;
129
+ multiple?: boolean;
130
+ autoComplete?: string;
131
+ autoFocus?: boolean;
132
+ }
133
+
134
+ export interface LabelHTMLAttributes<T = HTMLLabelElement>
135
+ extends HTMLAttributes<T> {
136
+ htmlFor?: string;
137
+ for?: string;
138
+ }
139
+
140
+ export interface SelectHTMLAttributes<T = HTMLSelectElement>
141
+ extends HTMLAttributes<T> {
142
+ value?: string | string[];
143
+ defaultValue?: string | string[];
144
+ disabled?: boolean;
145
+ required?: boolean;
146
+ name?: string;
147
+ multiple?: boolean;
148
+ size?: number;
149
+ }
150
+
151
+ export interface OptionHTMLAttributes<T = HTMLOptionElement>
152
+ extends HTMLAttributes<T> {
153
+ value?: string | number;
154
+ selected?: boolean;
155
+ disabled?: boolean;
156
+ label?: string;
157
+ }
158
+
159
+ export interface TextareaHTMLAttributes<T = HTMLTextAreaElement>
160
+ extends HTMLAttributes<T> {
161
+ value?: string;
162
+ defaultValue?: string;
163
+ placeholder?: string;
164
+ disabled?: boolean;
165
+ required?: boolean;
166
+ readOnly?: boolean;
167
+ name?: string;
168
+ rows?: number;
169
+ cols?: number;
170
+ maxLength?: number;
171
+ wrap?: "soft" | "hard";
172
+ }
173
+
174
+ export interface FieldsetHTMLAttributes<T = HTMLFieldSetElement>
175
+ extends HTMLAttributes<T> {
176
+ disabled?: boolean;
177
+ name?: string;
178
+ }
179
+
180
+ export interface ImgHTMLAttributes<T = HTMLImageElement>
181
+ extends HTMLAttributes<T> {
182
+ src?: string;
183
+ alt?: string;
184
+ width?: number | string;
185
+ height?: number | string;
186
+ loading?: "eager" | "lazy";
187
+ crossOrigin?: "anonymous" | "use-credentials";
188
+ }
189
+
190
+ export interface SVGAttributes<T = SVGElement> extends HTMLAttributes<T> {
191
+ xmlns?: string;
192
+ viewBox?: string;
193
+ width?: number | string;
194
+ height?: number | string;
195
+ fill?: string;
196
+ stroke?: string;
197
+ strokeWidth?: number | string;
198
+ }
199
+
200
+ // Intrinsic Elements
201
+ export interface IntrinsicElements {
202
+ a: AnchorHTMLAttributes<HTMLAnchorElement>;
203
+ abbr: HTMLAttributes<HTMLElement>;
204
+ address: HTMLAttributes<HTMLElement>;
205
+ article: HTMLAttributes<HTMLElement>;
206
+ aside: HTMLAttributes<HTMLElement>;
207
+ b: HTMLAttributes<HTMLElement>;
208
+ blockquote: HTMLAttributes<HTMLQuoteElement>;
209
+ body: HTMLAttributes<HTMLBodyElement>;
210
+ br: HTMLAttributes<HTMLBRElement>;
211
+ button: ButtonHTMLAttributes<HTMLButtonElement>;
212
+ canvas: HTMLAttributes<HTMLCanvasElement>;
213
+ code: HTMLAttributes<HTMLElement>;
214
+ div: HTMLAttributes<HTMLDivElement>;
215
+ em: HTMLAttributes<HTMLElement>;
216
+ fieldset: FieldsetHTMLAttributes<HTMLFieldSetElement>;
217
+ footer: HTMLAttributes<HTMLElement>;
218
+ form: FormHTMLAttributes<HTMLFormElement>;
219
+ h1: HTMLAttributes<HTMLHeadingElement>;
220
+ h2: HTMLAttributes<HTMLHeadingElement>;
221
+ h3: HTMLAttributes<HTMLHeadingElement>;
222
+ h4: HTMLAttributes<HTMLHeadingElement>;
223
+ h5: HTMLAttributes<HTMLHeadingElement>;
224
+ h6: HTMLAttributes<HTMLHeadingElement>;
225
+ head: HTMLAttributes<HTMLHeadElement>;
226
+ header: HTMLAttributes<HTMLElement>;
227
+ hr: HTMLAttributes<HTMLHRElement>;
228
+ html: HTMLAttributes<HTMLHtmlElement>;
229
+ i: HTMLAttributes<HTMLElement>;
230
+ img: ImgHTMLAttributes<HTMLImageElement>;
231
+ input: InputHTMLAttributes<HTMLInputElement>;
232
+ label: LabelHTMLAttributes<HTMLLabelElement>;
233
+ legend: HTMLAttributes<HTMLLegendElement>;
234
+ li: HTMLAttributes<HTMLLIElement>;
235
+ main: HTMLAttributes<HTMLElement>;
236
+ nav: HTMLAttributes<HTMLElement>;
237
+ ol: HTMLAttributes<HTMLOListElement>;
238
+ option: OptionHTMLAttributes<HTMLOptionElement>;
239
+ p: HTMLAttributes<HTMLParagraphElement>;
240
+ pre: HTMLAttributes<HTMLPreElement>;
241
+ section: HTMLAttributes<HTMLElement>;
242
+ select: SelectHTMLAttributes<HTMLSelectElement>;
243
+ small: HTMLAttributes<HTMLElement>;
244
+ span: HTMLAttributes<HTMLSpanElement>;
245
+ strong: HTMLAttributes<HTMLElement>;
246
+ style: HTMLAttributes<HTMLStyleElement>;
247
+ textarea: TextareaHTMLAttributes<HTMLTextAreaElement>;
248
+ ul: HTMLAttributes<HTMLUListElement>;
249
+
250
+ // SVG
251
+ svg: SVGAttributes<SVGSVGElement>;
252
+ circle: SVGAttributes<SVGCircleElement>;
253
+ line: SVGAttributes<SVGLineElement>;
254
+ path: SVGAttributes<SVGPathElement>;
255
+ rect: SVGAttributes<SVGRectElement>;
256
+ }
257
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,wBAAgB,GAAG,CACjB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,EAAE,KAAK,EAAE,SAmDlB"}
package/dist/jsx.js ADDED
@@ -0,0 +1,42 @@
1
+ import { h } from "snabbdom";
2
+ import { createComponent } from "./component";
3
+ export function jsx(type, props, children) {
4
+ let flatChildren = children.flat();
5
+ if (typeof type === "string") {
6
+ const data = {};
7
+ for (const key in props) {
8
+ if (key === "key") {
9
+ data[key] = props[key];
10
+ continue;
11
+ }
12
+ if (key === "hook") {
13
+ data[key] = props[key];
14
+ continue;
15
+ }
16
+ if (key === "style") {
17
+ data.style = props[key];
18
+ continue;
19
+ }
20
+ if (key.startsWith("on")) {
21
+ data.on = data.on || {};
22
+ data.on[key.substring(2).toLocaleLowerCase()] = props[key];
23
+ continue;
24
+ }
25
+ if (key.startsWith("data-") || key.startsWith("aria-")) {
26
+ data.attrs = data.attrs || {};
27
+ data.attrs[key] = props[key];
28
+ continue;
29
+ }
30
+ if (type === "svg") {
31
+ data.attrs = data.attrs || {};
32
+ data.attrs[key] = props[key];
33
+ continue;
34
+ }
35
+ data.props = data.props || {};
36
+ data.props[key] = props[key];
37
+ }
38
+ return h(type, data, flatChildren);
39
+ }
40
+ const maybeSingleChild = flatChildren.length === 1 ? flatChildren[0] : flatChildren;
41
+ return createComponent(type, props, maybeSingleChild);
42
+ }
@@ -0,0 +1,17 @@
1
+ export declare function getCurrentObserver(): Observer;
2
+ export declare class Signal {
3
+ private subscribers;
4
+ subscribe(cb: () => void): () => void;
5
+ notify(): void;
6
+ }
7
+ export declare class Observer {
8
+ private signalDisposers;
9
+ private clearSignals;
10
+ private onNotify;
11
+ private isQueued;
12
+ constructor(onNotify: () => void);
13
+ subscribeSignal(signal: Signal): void;
14
+ observe(): () => void;
15
+ dispose(): void;
16
+ }
17
+ //# sourceMappingURL=observation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,aAEjC;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,WAAW,CAAyB;IAC5C,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI;IAOxB,MAAM;CAGP;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBACb,QAAQ,EAAE,MAAM,IAAI;IAchC,eAAe,CAAC,MAAM,EAAE,MAAM;IAG9B,OAAO;IAOP,OAAO;CAGR"}
@@ -0,0 +1,50 @@
1
+ const observerStack = [];
2
+ export function getCurrentObserver() {
3
+ return observerStack[0];
4
+ }
5
+ export class Signal {
6
+ subscribers = new Set();
7
+ subscribe(cb) {
8
+ this.subscribers.add(cb);
9
+ return () => {
10
+ this.subscribers.delete(cb);
11
+ };
12
+ }
13
+ notify() {
14
+ this.subscribers.forEach((cb) => cb());
15
+ }
16
+ }
17
+ export class Observer {
18
+ signalDisposers = new Set();
19
+ clearSignals() {
20
+ this.signalDisposers.forEach((dispose) => dispose());
21
+ this.signalDisposers.clear();
22
+ }
23
+ onNotify;
24
+ isQueued = false;
25
+ constructor(onNotify) {
26
+ this.onNotify = () => {
27
+ if (this.isQueued) {
28
+ return;
29
+ }
30
+ queueMicrotask(() => {
31
+ this.isQueued = false;
32
+ onNotify();
33
+ });
34
+ this.isQueued = true;
35
+ };
36
+ }
37
+ subscribeSignal(signal) {
38
+ this.signalDisposers.add(signal.subscribe(this.onNotify));
39
+ }
40
+ observe() {
41
+ this.clearSignals();
42
+ observerStack.unshift(this);
43
+ return () => {
44
+ observerStack.shift();
45
+ };
46
+ }
47
+ dispose() {
48
+ this.clearSignals();
49
+ }
50
+ }
@@ -0,0 +1,7 @@
1
+ import { type VNode } from "snabbdom";
2
+ import { type Component } from "./component";
3
+ export declare const patch: (oldVnode: VNode | Element | DocumentFragment, vnode: VNode) => VNode;
4
+ export type ChildNode = VNode | string | null | number;
5
+ export declare function render(vnode: VNode, container: HTMLElement): void;
6
+ export declare function jsx(type: string | Component<any>, props: Record<string, unknown>, children: ChildNode[]): VNode;
7
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,KAAK,EAEX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,KAAK,uEAOhB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;AAEvD,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,QAK1D;AAED,wBAAgB,GAAG,CACjB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,EAAE,SAAS,EAAE,SA6DtB"}