@krate/runtime 0.5.0-rc.14 → 0.5.0-rc.15

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 (61) hide show
  1. package/dist/action-context.js +5 -1
  2. package/dist/dev/api.d.ts +93 -0
  3. package/dist/dev/api.js +2 -0
  4. package/dist/dev/app.d.ts +165 -0
  5. package/dist/dev/app.js +1204 -0
  6. package/dist/dev/commands.d.ts +49 -0
  7. package/dist/dev/commands.js +114 -0
  8. package/dist/dev/highlight.d.ts +4 -0
  9. package/dist/dev/highlight.js +126 -0
  10. package/dist/dev/icons.d.ts +4 -0
  11. package/dist/dev/icons.js +57 -0
  12. package/dist/dev/inspect.d.ts +55 -0
  13. package/dist/dev/inspect.js +256 -0
  14. package/dist/dev/inspector.d.ts +39 -0
  15. package/dist/dev/inspector.js +348 -0
  16. package/dist/dev/issues.d.ts +83 -0
  17. package/dist/dev/issues.js +166 -0
  18. package/dist/dev/modal.d.ts +16 -0
  19. package/dist/dev/modal.js +836 -0
  20. package/dist/dev/native.d.ts +53 -0
  21. package/dist/dev/native.js +95 -0
  22. package/dist/dev/palette.d.ts +9 -0
  23. package/dist/dev/palette.js +250 -0
  24. package/dist/dev/panel.d.ts +31 -0
  25. package/dist/dev/panel.js +848 -0
  26. package/dist/dev/requests.d.ts +36 -0
  27. package/dist/dev/requests.js +150 -0
  28. package/dist/dev/settings.d.ts +32 -0
  29. package/dist/dev/settings.js +78 -0
  30. package/dist/dev/sourcemap.d.ts +22 -0
  31. package/dist/dev/sourcemap.js +148 -0
  32. package/dist/dev/stack.d.ts +38 -0
  33. package/dist/dev/stack.js +115 -0
  34. package/dist/dev/styles.d.ts +1 -0
  35. package/dist/dev/styles.js +424 -0
  36. package/dist/dev/util.d.ts +63 -0
  37. package/dist/dev/util.js +190 -0
  38. package/dist/dev-overlay.d.ts +9 -83
  39. package/dist/dev-overlay.js +17 -1038
  40. package/dist/island-swap.js +7 -1
  41. package/dist/krate-core.js +1 -1
  42. package/dist/krate-dev.js +441 -871
  43. package/dist/krate-f-list.js +1 -1
  44. package/dist/krate-f-navigation.js +1 -1
  45. package/dist/krate-hydrate-lite.js +5 -5
  46. package/dist/krate-hydrate.js +5 -5
  47. package/dist/krate-island-swap.js +1 -1
  48. package/dist/krate-runtime.js +5 -5
  49. package/dist/list.js +23 -1
  50. package/dist/metadata.js +23 -12
  51. package/dist/request-context.d.ts +10 -0
  52. package/dist/request-context.js +24 -0
  53. package/dist/server-handler.d.ts +2 -0
  54. package/dist/server-handler.js +1 -1
  55. package/dist/server-renderer.js +6 -2
  56. package/dist/server.js +2 -2
  57. package/dist/signal.d.ts +8 -0
  58. package/dist/signal.js +4 -0
  59. package/dist/ssr-core.d.ts +3 -0
  60. package/dist/ssr-core.js +44 -5
  61. package/package.json +1 -1
@@ -0,0 +1,190 @@
1
+ import { siteConfig } from '../site-config.js';
2
+ /** True inside a Krate Native window (`krate://app`, or `https://app.localhost` on Windows). */
3
+ export function isNativeOrigin() {
4
+ try {
5
+ return location.protocol === 'krate:' || location.origin === 'https://app.localhost';
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ }
11
+ export function devConfig() {
12
+ const raw = window.__KRATE_DEV__;
13
+ const runtime = siteConfig();
14
+ const native = isNativeOrigin();
15
+ return {
16
+ sse: raw?.sse ?? '/__krate/hotreload',
17
+ frames: raw?.frames ?? (native ? '/__krate/hmr' : ''),
18
+ events: raw?.events ?? (native ? '/__krate/dev/events' : ''),
19
+ memory: raw?.memory ?? (native ? '/__krate/dev/memory' : ''),
20
+ errors: raw?.errors ?? (native ? '/__krate/dev/client-error' : '/__krate/client-error'),
21
+ open: raw?.open ?? '/__krate/open',
22
+ api: raw?.api ?? '',
23
+ version: raw?.version ?? '',
24
+ overlay: raw?.overlay ?? true,
25
+ toolbar: raw?.toolbar ?? true,
26
+ basePath: raw?.basePath ?? runtime?.basePath ?? '',
27
+ page: raw?.page,
28
+ };
29
+ }
30
+ export function esc(s) {
31
+ return String(s)
32
+ .replace(/&/g, '&')
33
+ .replace(/</g, '&lt;')
34
+ .replace(/>/g, '&gt;')
35
+ .replace(/"/g, '&quot;')
36
+ .replace(/'/g, '&#39;');
37
+ }
38
+ /** Escapes text and renders `backtick` spans as <code>. */
39
+ export function richText(s) {
40
+ return esc(s).replace(/`([^`]+)`/g, '<code>$1</code>');
41
+ }
42
+ function norm(p) {
43
+ return p.replace(/\/+$/, '') || '/';
44
+ }
45
+ /** Strips the configured base path so match patterns (unprefixed) line up. */
46
+ export function stripBase(pathname, basePath) {
47
+ if (basePath && (pathname === basePath || pathname.startsWith(basePath + '/'))) {
48
+ const rest = pathname.slice(basePath.length);
49
+ return rest === '' ? '/' : rest;
50
+ }
51
+ return pathname;
52
+ }
53
+ /**
54
+ * Route matcher: a segment starting with `[` matches anything; `[...x]` matches
55
+ * the rest.
56
+ */
57
+ export function routeMatches(pattern, pathname, basePath = '') {
58
+ const a = norm(stripBase(pathname, basePath)).split('/');
59
+ const b = norm(pattern).split('/');
60
+ for (let i = 0; i < b.length; i++) {
61
+ const s = b[i];
62
+ if (s.charAt(0) === '[') {
63
+ if (s.indexOf('[...') === 0)
64
+ return true;
65
+ continue;
66
+ }
67
+ if (s !== a[i])
68
+ return false;
69
+ }
70
+ return a.length === b.length;
71
+ }
72
+ export function formatArg(a) {
73
+ if (a instanceof Error)
74
+ return a.message || String(a);
75
+ if (typeof a === 'string')
76
+ return a;
77
+ try {
78
+ return JSON.stringify(a) ?? String(a);
79
+ }
80
+ catch {
81
+ return String(a);
82
+ }
83
+ }
84
+ /** Kilobytes with one decimal, without the unit. */
85
+ export function kb(n) {
86
+ if (!n || n < 0)
87
+ return '0';
88
+ const v = n / 1024;
89
+ return v >= 100 ? String(Math.round(v)) : v.toFixed(1).replace(/\.0$/, '');
90
+ }
91
+ /** A duration: "184ms" below a second, "2.9s" above. */
92
+ export function fmtMs(ms) {
93
+ if (ms === undefined || !Number.isFinite(ms))
94
+ return '';
95
+ if (ms < 10)
96
+ return ms.toFixed(1) + 'ms';
97
+ if (ms < 1000)
98
+ return Math.round(ms) + 'ms';
99
+ return (ms / 1000).toFixed(ms < 10000 ? 1 : 0) + 's';
100
+ }
101
+ /** A wall clock time as HH:MM:SS. */
102
+ export function clock(t) {
103
+ const d = new Date(t);
104
+ const p = (n) => String(n).padStart(2, '0');
105
+ return p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds());
106
+ }
107
+ export function basename(p) {
108
+ const i = p.replace(/\\/g, '/').lastIndexOf('/');
109
+ return i === -1 ? p : p.slice(i + 1);
110
+ }
111
+ export function dirname(p) {
112
+ const s = p.replace(/\\/g, '/');
113
+ const i = s.lastIndexOf('/');
114
+ return i === -1 ? '' : s.slice(0, i + 1);
115
+ }
116
+ export function plural(n, one, many = one + 's') {
117
+ return n + ' ' + (n === 1 ? one : many);
118
+ }
119
+ export function isMac() {
120
+ try {
121
+ const nav = navigator;
122
+ const p = nav.userAgentData?.platform || nav.platform || nav.userAgent || '';
123
+ return /mac|iphone|ipad/i.test(p);
124
+ }
125
+ catch {
126
+ return false;
127
+ }
128
+ }
129
+ /**
130
+ * True when a key event comes from something the user types into on the page:
131
+ * an input, textarea, select or editable element. Elements inside the overlay's
132
+ * own shadow root are not counted.
133
+ */
134
+ export function isTypingTarget(e, ownHost) {
135
+ const path = typeof e.composedPath === 'function' ? e.composedPath() : [];
136
+ const t = (path[0] || e.target);
137
+ if (!t || !t.tagName)
138
+ return false;
139
+ if (ownHost && path.includes(ownHost))
140
+ return false;
141
+ const tag = t.tagName;
142
+ if (tag === 'TEXTAREA' || tag === 'SELECT')
143
+ return true;
144
+ if (tag === 'INPUT') {
145
+ const type = (t.type || 'text').toLowerCase();
146
+ return !['button', 'checkbox', 'radio', 'submit', 'reset', 'range', 'color', 'file', 'image'].includes(type);
147
+ }
148
+ return t.isContentEditable === true || t.getAttribute?.('contenteditable') === 'true';
149
+ }
150
+ /** Copies text to the clipboard; resolves false when the browser refuses. */
151
+ export async function copyText(text) {
152
+ try {
153
+ await navigator.clipboard.writeText(text);
154
+ return true;
155
+ }
156
+ catch {
157
+ try {
158
+ const ta = document.createElement('textarea');
159
+ ta.value = text;
160
+ ta.style.cssText = 'position:fixed;opacity:0;left:-9999px';
161
+ document.body.appendChild(ta);
162
+ ta.select();
163
+ const ok = document.execCommand('copy');
164
+ ta.remove();
165
+ return ok;
166
+ }
167
+ catch {
168
+ return false;
169
+ }
170
+ }
171
+ }
172
+ /** localStorage without the exceptions of private windows and blocked storage. */
173
+ export const store = {
174
+ get(key) {
175
+ try {
176
+ return localStorage.getItem(key);
177
+ }
178
+ catch {
179
+ return null;
180
+ }
181
+ },
182
+ set(key, value) {
183
+ try {
184
+ localStorage.setItem(key, value);
185
+ }
186
+ catch {
187
+ /* storage is a convenience */
188
+ }
189
+ },
190
+ };
@@ -1,88 +1,14 @@
1
1
  /**
2
- * Dev-only error overlay + toolbar.
2
+ * Dev-only overlay: the dock, its panel, the error overlay, the command menu
3
+ * and the component inspector.
3
4
  *
4
5
  * 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.
6
+ * never part of the production runtime. The modules live in ./dev/.
8
7
  */
9
- /** True inside a Krate Native window (`krate://app`, or `https://app.localhost` on Windows). */
10
- export declare function isNativeOrigin(): boolean;
11
- interface MapSegment {
12
- genCol: number;
13
- src: number;
14
- srcLine: number;
15
- srcCol: number;
16
- }
17
- /** Decodes a Base64 VLQ mapping segment into a delta array. */
18
- export declare function decodeVLQ(str: string): number[];
19
- /** Decodes a v3 `mappings` string into per-generated-line segments. */
20
- export declare function decodeMappings(mappings: string): MapSegment[][];
21
- interface StackFrame {
22
- prefix: string;
23
- url: string;
24
- line: number;
25
- col: number;
26
- suffix: string;
27
- }
28
- /** Parses a V8/Firefox stack line into its script location, if present. */
29
- export declare function parseStackFrame(line: string): StackFrame | null;
30
- /** Rewrites each mappable frame of a stack trace to its original location. */
31
- export declare function symbolicateStack(stack: string): Promise<string>;
32
- export declare function routeMatches(pattern: string, pathname: string, basePath?: string): boolean;
33
- /**
34
- * Splits a buffer of Krate frames (u32 length, JSON, u16 blob count, blobs)
35
- * into its complete JSON values. `rest` is the incomplete tail to prepend to
36
- * the next chunk. Exported (pure) for testing.
37
- */
38
- export declare function parseFrames(buf: Uint8Array): {
39
- values: unknown[];
40
- rest: Uint8Array;
41
- };
42
- /** The host-side stack a KrateError carries in dev (`data.stack`), or "". */
43
- export declare function hostStackOf(reason: unknown): string;
44
- interface HostEvent {
45
- seq: number;
46
- kind: string;
47
- fn: string;
48
- id?: number;
49
- time?: string;
50
- durNs?: number;
51
- code?: string;
52
- message?: string;
53
- }
54
- /** One line of the Host panel. Exported (pure) for testing. */
55
- export declare function hostEventLine(ev: HostEvent): string;
56
- /** The memstat report the shell serves at /__krate/dev/memory (bytes). */
57
- export interface MemoryReport {
58
- os?: string;
59
- source?: string;
60
- procs?: {
61
- pid: number;
62
- name?: string;
63
- role: string;
64
- rss?: number;
65
- pss: number;
66
- privateDirty: number;
67
- }[];
68
- total?: {
69
- pss: number;
70
- privateDirty: number;
71
- rss?: number;
72
- };
73
- notes?: string[];
74
- }
75
- /** Format a byte count for the Memory panel. Exported (pure) for testing. */
76
- export declare function formatBytes(n: number): string;
77
- /**
78
- * The JS heap of this page, or null where the engine does not expose it.
79
- * Chromium has performance.memory; WebKit (the engine of the Linux and macOS
80
- * webviews) has no heap size API, so the panel shows the web process row
81
- * (PSS and private dirty, which include the JS heap) instead.
82
- */
83
- export declare function jsHeapBytes(): number | null;
84
- /** The rows of the Memory panel as [label, value] pairs. Exported (pure) for testing. */
85
- export declare function memoryRows(rep: MemoryReport | null, domNodes: number, heap: number | null): [string, string][];
8
+ import { KrateDev } from './dev/app.js';
9
+ export { KrateDev } from './dev/app.js';
10
+ export { isNativeOrigin, routeMatches } from './dev/util.js';
11
+ export { decodeVLQ, decodeMappings, parseStackFrame, symbolicateStack } from './dev/sourcemap.js';
12
+ export { parseFrames, hostStackOf, hostEventLine, formatBytes, jsHeapBytes, memoryRows, type MemoryReport } from './dev/native.js';
86
13
  /** Initialise the dev overlay. Safe to call more than once. */
87
- export declare function initDevOverlay(): void;
88
- export {};
14
+ export declare function initDevOverlay(): KrateDev | undefined;