@krate/runtime 0.4.0-rc.3 → 0.4.0-rc.5
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/class-helpers.d.ts +4 -4
- package/dist/class-helpers.js +5 -5
- package/dist/context.d.ts +18 -1
- package/dist/context.js +27 -7
- package/dist/dev-overlay.d.ts +37 -0
- package/dist/dev-overlay.js +583 -0
- package/dist/dev-overlay.test.d.ts +1 -0
- package/dist/dev-overlay.test.js +130 -0
- package/dist/dom.js +5 -5
- package/dist/error-overlay.d.ts +1 -1
- package/dist/error-overlay.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/krate-dev.js +490 -0
- package/dist/krate-hydrate.js +1 -1
- package/dist/krate-runtime.js +1 -1
- package/dist/reconcile.js +25 -21
- package/dist/reconcile.test.d.ts +1 -0
- package/dist/reconcile.test.js +47 -0
- package/dist/router.d.ts +12 -0
- package/dist/router.js +239 -54
- package/dist/server-jsx-runtime.js +1 -1
- package/dist/server-renderer.js +64 -24
- package/dist/server.js +13 -13
- package/dist/server.test.d.ts +1 -0
- package/dist/server.test.js +26 -0
- package/dist/signal.d.ts +44 -10
- package/dist/signal.js +22 -15
- package/package.json +1 -1
package/dist/class-helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ClassValue = string | number | boolean | null | undefined | ClassValue[] | Record<string, unknown>;
|
|
2
|
-
/** `clsx`
|
|
2
|
+
/** `clsx` - conditional class names from strings, arrays, and objects. */
|
|
3
3
|
export declare function clsx(...inputs: ClassValue[]): string;
|
|
4
4
|
/**
|
|
5
5
|
* Merge conflicting Tailwind utilities. This is a deliberately small subset:
|
|
@@ -8,7 +8,7 @@ export declare function clsx(...inputs: ClassValue[]): string;
|
|
|
8
8
|
* compiler folds literal calls and this covers dynamic joins.
|
|
9
9
|
*/
|
|
10
10
|
export declare function twMerge(...inputs: ClassValue[]): string;
|
|
11
|
-
/** `cn`
|
|
11
|
+
/** `cn` - `twMerge` over `clsx`, the shadcn/ui convention. */
|
|
12
12
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
13
13
|
export interface CVAConfig {
|
|
14
14
|
variants?: Record<string, Record<string, string>>;
|
|
@@ -21,7 +21,7 @@ export interface CVAConfig {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function cva(base: string, config?: CVAConfig): (props?: Record<string, unknown>) => string;
|
|
23
23
|
/**
|
|
24
|
-
* `Slot`
|
|
24
|
+
* `Slot` - renders its single child element instead of wrapping it, merging the
|
|
25
25
|
* Slot's own props onto that child. This is the `asChild` mechanic from
|
|
26
26
|
* shadcn/radix: `<Slot className="x"><a /></Slot>` returns the `<a>` with `x`
|
|
27
27
|
* merged onto it.
|
|
@@ -33,7 +33,7 @@ export declare function Slot(props: Record<string, unknown> & {
|
|
|
33
33
|
children?: unknown;
|
|
34
34
|
}): Node | null;
|
|
35
35
|
/**
|
|
36
|
-
* `cloneElement`
|
|
36
|
+
* `cloneElement` - apply extra props (and optional replacement children) to an
|
|
37
37
|
* existing node and return it. Used by `Slot`/`asChild` and by libraries that
|
|
38
38
|
* clone a single child.
|
|
39
39
|
*/
|
package/dist/class-helpers.js
CHANGED
|
@@ -23,7 +23,7 @@ function flattenClass(value, out) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
/** `clsx`
|
|
26
|
+
/** `clsx` - conditional class names from strings, arrays, and objects. */
|
|
27
27
|
export function clsx(...inputs) {
|
|
28
28
|
const out = [];
|
|
29
29
|
for (const input of inputs)
|
|
@@ -58,7 +58,7 @@ export function twMerge(...inputs) {
|
|
|
58
58
|
function tailwindPropertyKey(token) {
|
|
59
59
|
let t = token;
|
|
60
60
|
let prefix = '';
|
|
61
|
-
// Strip a variant chain (hover:, md:, focus:
|
|
61
|
+
// Strip a variant chain (hover:, md:, focus: - anything before the last `:`).
|
|
62
62
|
const colon = t.lastIndexOf(':');
|
|
63
63
|
if (colon >= 0) {
|
|
64
64
|
prefix = t.slice(0, colon + 1);
|
|
@@ -69,7 +69,7 @@ function tailwindPropertyKey(token) {
|
|
|
69
69
|
const scale = dash >= 0 ? t.slice(dash + 1, dash + 2) : '';
|
|
70
70
|
return prefix + base + (scale && /[0-9]/.test(scale) ? '-' + scale : '');
|
|
71
71
|
}
|
|
72
|
-
/** `cn`
|
|
72
|
+
/** `cn` - `twMerge` over `clsx`, the shadcn/ui convention. */
|
|
73
73
|
export function cn(...inputs) {
|
|
74
74
|
return twMerge(clsx(...inputs));
|
|
75
75
|
}
|
|
@@ -123,7 +123,7 @@ function matchesCompound(compound, selection, defaults) {
|
|
|
123
123
|
return true;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* `Slot`
|
|
126
|
+
* `Slot` - renders its single child element instead of wrapping it, merging the
|
|
127
127
|
* Slot's own props onto that child. This is the `asChild` mechanic from
|
|
128
128
|
* shadcn/radix: `<Slot className="x"><a /></Slot>` returns the `<a>` with `x`
|
|
129
129
|
* merged onto it.
|
|
@@ -189,7 +189,7 @@ function kebab(name) {
|
|
|
189
189
|
return name.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
|
-
* `cloneElement`
|
|
192
|
+
* `cloneElement` - apply extra props (and optional replacement children) to an
|
|
193
193
|
* existing node and return it. Used by `Slot`/`asChild` and by libraries that
|
|
194
194
|
* clone a single child.
|
|
195
195
|
*/
|
package/dist/context.d.ts
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
import type { CSSScope, CSSFlagsScope } from './signal.js';
|
|
1
2
|
export interface Context<T> {
|
|
2
3
|
id: number;
|
|
3
4
|
defaultValue: T;
|
|
4
5
|
Provider: (props: {
|
|
5
6
|
value: T;
|
|
6
|
-
children?:
|
|
7
|
+
children?: any;
|
|
7
8
|
}) => Node;
|
|
8
9
|
useContext: () => T;
|
|
10
|
+
/** Alias for {@link Context.useContext}. */
|
|
11
|
+
use: () => T;
|
|
9
12
|
}
|
|
10
13
|
export declare function resetContexts(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Create a context that carries a CSS scope handle (see {@link CSSScope}). The
|
|
16
|
+
* default is a harmless placeholder — a `<Provider>` value always wins — so no
|
|
17
|
+
* cast is needed:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const TabsCtx = createScope<string>();
|
|
21
|
+
* // provide: <TabsCtx.Provider value={createCSSChoice('a')}>…</Provider>
|
|
22
|
+
* // consume: const tab = TabsCtx.use();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createScope<T>(): Context<CSSScope<T>>;
|
|
26
|
+
/** Like {@link createScope} but for a `createCSSFlags` handle. */
|
|
27
|
+
export declare function createScopeFlags<K extends string>(): Context<CSSFlagsScope<K>>;
|
|
11
28
|
export declare function createContext<T>(defaultValue: T): Context<T>;
|
package/dist/context.js
CHANGED
|
@@ -10,9 +10,34 @@ export function resetContexts() {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a context that carries a CSS scope handle (see {@link CSSScope}). The
|
|
15
|
+
* default is a harmless placeholder — a `<Provider>` value always wins — so no
|
|
16
|
+
* cast is needed:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const TabsCtx = createScope<string>();
|
|
20
|
+
* // provide: <TabsCtx.Provider value={createCSSChoice('a')}>…</Provider>
|
|
21
|
+
* // consume: const tab = TabsCtx.use();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createScope() {
|
|
25
|
+
return createContext({});
|
|
26
|
+
}
|
|
27
|
+
/** Like {@link createScope} but for a `createCSSFlags` handle. */
|
|
28
|
+
export function createScopeFlags() {
|
|
29
|
+
return createContext({});
|
|
30
|
+
}
|
|
13
31
|
export function createContext(defaultValue) {
|
|
14
32
|
const id = contextId++;
|
|
15
33
|
contextStack.set(id, [defaultValue]);
|
|
34
|
+
const useContext = () => {
|
|
35
|
+
const stack = contextStack.get(id);
|
|
36
|
+
if (stack && stack.length > 0) {
|
|
37
|
+
return stack[stack.length - 1];
|
|
38
|
+
}
|
|
39
|
+
return defaultValue;
|
|
40
|
+
};
|
|
16
41
|
return {
|
|
17
42
|
id,
|
|
18
43
|
defaultValue,
|
|
@@ -45,12 +70,7 @@ export function createContext(defaultValue) {
|
|
|
45
70
|
}
|
|
46
71
|
return container;
|
|
47
72
|
},
|
|
48
|
-
useContext
|
|
49
|
-
|
|
50
|
-
if (stack && stack.length > 0) {
|
|
51
|
-
return stack[stack.length - 1];
|
|
52
|
-
}
|
|
53
|
-
return defaultValue;
|
|
54
|
-
},
|
|
73
|
+
useContext,
|
|
74
|
+
use: useContext,
|
|
55
75
|
};
|
|
56
76
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev-only error overlay + toolbar.
|
|
3
|
+
*
|
|
4
|
+
* Bundled separately as `krate-dev.js` and injected only by `krate dev`; it is
|
|
5
|
+
* never part of the production runtime. It renders structured compiler
|
|
6
|
+
* diagnostics (file:line:col + source + caret + hint) and client runtime errors,
|
|
7
|
+
* forwards runtime errors back to the dev server, and offers open-in-editor.
|
|
8
|
+
*/
|
|
9
|
+
interface MapSegment {
|
|
10
|
+
genCol: number;
|
|
11
|
+
src: number;
|
|
12
|
+
srcLine: number;
|
|
13
|
+
srcCol: number;
|
|
14
|
+
}
|
|
15
|
+
/** Decodes a Base64 VLQ mapping segment into a delta array. */
|
|
16
|
+
export declare function decodeVLQ(str: string): number[];
|
|
17
|
+
/** Decodes a v3 `mappings` string into per-generated-line segments. */
|
|
18
|
+
export declare function decodeMappings(mappings: string): MapSegment[][];
|
|
19
|
+
interface StackFrame {
|
|
20
|
+
prefix: string;
|
|
21
|
+
url: string;
|
|
22
|
+
line: number;
|
|
23
|
+
col: number;
|
|
24
|
+
suffix: string;
|
|
25
|
+
}
|
|
26
|
+
/** Parses a V8/Firefox stack line into its script location, if present. */
|
|
27
|
+
export declare function parseStackFrame(line: string): StackFrame | null;
|
|
28
|
+
/** Rewrites each mappable frame of a stack trace to its original location. */
|
|
29
|
+
export declare function symbolicateStack(stack: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Route matcher: a segment starting with `[` matches anything; `[...x]` matches
|
|
32
|
+
* the rest. Exported (pure) for testing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function routeMatches(pattern: string, pathname: string, basePath?: string): boolean;
|
|
35
|
+
/** Initialise the dev overlay. Safe to call more than once. */
|
|
36
|
+
export declare function initDevOverlay(): void;
|
|
37
|
+
export {};
|