reigncode-app 1.3.2
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/AGENTS.md +30 -0
- package/Dockerfile +21 -0
- package/README.md +51 -0
- package/bunfig.toml +3 -0
- package/create-effect-simplification-spec.md +515 -0
- package/e2e/AGENTS.md +226 -0
- package/e2e/actions.ts +1018 -0
- package/e2e/app/home.spec.ts +24 -0
- package/e2e/app/navigation.spec.ts +10 -0
- package/e2e/app/palette.spec.ts +20 -0
- package/e2e/app/server-default.spec.ts +58 -0
- package/e2e/app/session.spec.ts +16 -0
- package/e2e/app/titlebar-history.spec.ts +120 -0
- package/e2e/commands/input-focus.spec.ts +15 -0
- package/e2e/commands/panels.spec.ts +33 -0
- package/e2e/commands/tab-close.spec.ts +32 -0
- package/e2e/files/file-open.spec.ts +31 -0
- package/e2e/files/file-tree.spec.ts +56 -0
- package/e2e/files/file-viewer.spec.ts +156 -0
- package/e2e/fixtures.ts +154 -0
- package/e2e/models/model-picker.spec.ts +48 -0
- package/e2e/models/models-visibility.spec.ts +61 -0
- package/e2e/projects/project-edit.spec.ts +43 -0
- package/e2e/projects/projects-close.spec.ts +54 -0
- package/e2e/projects/projects-switch.spec.ts +116 -0
- package/e2e/projects/workspace-new-session.spec.ts +94 -0
- package/e2e/projects/workspaces.spec.ts +375 -0
- package/e2e/prompt/context.spec.ts +95 -0
- package/e2e/prompt/prompt-async.spec.ts +76 -0
- package/e2e/prompt/prompt-drop-file-uri.spec.ts +22 -0
- package/e2e/prompt/prompt-drop-file.spec.ts +30 -0
- package/e2e/prompt/prompt-history.spec.ts +184 -0
- package/e2e/prompt/prompt-mention.spec.ts +26 -0
- package/e2e/prompt/prompt-multiline.spec.ts +24 -0
- package/e2e/prompt/prompt-shell.spec.ts +62 -0
- package/e2e/prompt/prompt-slash-open.spec.ts +22 -0
- package/e2e/prompt/prompt-slash-share.spec.ts +64 -0
- package/e2e/prompt/prompt-slash-terminal.spec.ts +18 -0
- package/e2e/prompt/prompt.spec.ts +55 -0
- package/e2e/selectors.ts +75 -0
- package/e2e/session/session-child-navigation.spec.ts +37 -0
- package/e2e/session/session-composer-dock.spec.ts +530 -0
- package/e2e/session/session-model-persistence.spec.ts +359 -0
- package/e2e/session/session-review.spec.ts +426 -0
- package/e2e/session/session-undo-redo.spec.ts +233 -0
- package/e2e/session/session.spec.ts +174 -0
- package/e2e/settings/settings-keybinds.spec.ts +389 -0
- package/e2e/settings/settings-models.spec.ts +122 -0
- package/e2e/settings/settings-providers.spec.ts +136 -0
- package/e2e/settings/settings.spec.ts +519 -0
- package/e2e/sidebar/sidebar-popover-actions.spec.ts +118 -0
- package/e2e/sidebar/sidebar-session-links.spec.ts +30 -0
- package/e2e/sidebar/sidebar.spec.ts +40 -0
- package/e2e/status/status-popover.spec.ts +94 -0
- package/e2e/terminal/terminal-init.spec.ts +28 -0
- package/e2e/terminal/terminal-reconnect.spec.ts +46 -0
- package/e2e/terminal/terminal-tabs.spec.ts +168 -0
- package/e2e/terminal/terminal.spec.ts +18 -0
- package/e2e/thinking-level.spec.ts +25 -0
- package/e2e/tsconfig.json +9 -0
- package/e2e/utils.ts +63 -0
- package/happydom.ts +75 -0
- package/index.html +23 -0
- package/package.json +77 -0
- package/playwright.config.ts +45 -0
- package/public/_headers +17 -0
- package/public/oc-theme-preload.js +35 -0
- package/script/e2e-local.ts +180 -0
- package/src/addons/serialize.test.ts +319 -0
- package/src/addons/serialize.ts +634 -0
- package/src/app.tsx +308 -0
- package/src/components/debug-bar.tsx +443 -0
- package/src/components/dialog-connect-provider.tsx +617 -0
- package/src/components/dialog-custom-provider-form.ts +158 -0
- package/src/components/dialog-custom-provider.test.ts +80 -0
- package/src/components/dialog-custom-provider.tsx +329 -0
- package/src/components/dialog-edit-project.tsx +255 -0
- package/src/components/dialog-fork.tsx +108 -0
- package/src/components/dialog-manage-models.tsx +101 -0
- package/src/components/dialog-release-notes.tsx +144 -0
- package/src/components/dialog-select-directory.tsx +392 -0
- package/src/components/dialog-select-file.tsx +466 -0
- package/src/components/dialog-select-mcp.tsx +107 -0
- package/src/components/dialog-select-model-unpaid.tsx +137 -0
- package/src/components/dialog-select-model.tsx +220 -0
- package/src/components/dialog-select-provider.tsx +86 -0
- package/src/components/dialog-select-server.tsx +649 -0
- package/src/components/dialog-settings.tsx +73 -0
- package/src/components/file-tree.test.ts +78 -0
- package/src/components/file-tree.tsx +507 -0
- package/src/components/link.tsx +26 -0
- package/src/components/model-tooltip.tsx +91 -0
- package/src/components/prompt-input/attachments.test.ts +44 -0
- package/src/components/prompt-input/attachments.ts +201 -0
- package/src/components/prompt-input/build-request-parts.test.ts +312 -0
- package/src/components/prompt-input/build-request-parts.ts +175 -0
- package/src/components/prompt-input/context-items.tsx +88 -0
- package/src/components/prompt-input/drag-overlay.tsx +25 -0
- package/src/components/prompt-input/editor-dom.test.ts +99 -0
- package/src/components/prompt-input/editor-dom.ts +148 -0
- package/src/components/prompt-input/files.ts +66 -0
- package/src/components/prompt-input/history.test.ts +153 -0
- package/src/components/prompt-input/history.ts +256 -0
- package/src/components/prompt-input/image-attachments.tsx +58 -0
- package/src/components/prompt-input/paste.ts +24 -0
- package/src/components/prompt-input/placeholder.test.ts +48 -0
- package/src/components/prompt-input/placeholder.ts +15 -0
- package/src/components/prompt-input/slash-popover.tsx +141 -0
- package/src/components/prompt-input/submit.test.ts +346 -0
- package/src/components/prompt-input/submit.ts +579 -0
- package/src/components/prompt-input.tsx +1595 -0
- package/src/components/server/server-row.tsx +130 -0
- package/src/components/session/index.ts +5 -0
- package/src/components/session/session-context-breakdown.test.ts +61 -0
- package/src/components/session/session-context-breakdown.ts +132 -0
- package/src/components/session/session-context-format.ts +20 -0
- package/src/components/session/session-context-metrics.test.ts +101 -0
- package/src/components/session/session-context-metrics.ts +82 -0
- package/src/components/session/session-context-tab.tsx +339 -0
- package/src/components/session/session-header.tsx +486 -0
- package/src/components/session/session-new-view.tsx +91 -0
- package/src/components/session/session-sortable-tab.tsx +70 -0
- package/src/components/session/session-sortable-terminal-tab.tsx +193 -0
- package/src/components/session-context-usage.tsx +122 -0
- package/src/components/settings-general.tsx +585 -0
- package/src/components/settings-keybinds.tsx +453 -0
- package/src/components/settings-list.tsx +5 -0
- package/src/components/settings-models.tsx +137 -0
- package/src/components/settings-providers.tsx +251 -0
- package/src/components/status-popover.tsx +419 -0
- package/src/components/terminal.tsx +653 -0
- package/src/components/titlebar-history.test.ts +63 -0
- package/src/components/titlebar-history.ts +57 -0
- package/src/components/titlebar.tsx +312 -0
- package/src/constants/file-picker.ts +89 -0
- package/src/context/command-keybind.test.ts +69 -0
- package/src/context/command.test.ts +25 -0
- package/src/context/command.tsx +437 -0
- package/src/context/comments.test.ts +186 -0
- package/src/context/comments.tsx +243 -0
- package/src/context/file/content-cache.ts +88 -0
- package/src/context/file/path.test.ts +360 -0
- package/src/context/file/path.ts +151 -0
- package/src/context/file/tree-store.ts +170 -0
- package/src/context/file/types.ts +41 -0
- package/src/context/file/view-cache.ts +146 -0
- package/src/context/file/watcher.test.ts +149 -0
- package/src/context/file/watcher.ts +53 -0
- package/src/context/file-content-eviction-accounting.test.ts +65 -0
- package/src/context/file.tsx +280 -0
- package/src/context/global-sdk.tsx +232 -0
- package/src/context/global-sync/bootstrap.ts +206 -0
- package/src/context/global-sync/child-store.test.ts +38 -0
- package/src/context/global-sync/child-store.ts +281 -0
- package/src/context/global-sync/event-reducer.test.ts +552 -0
- package/src/context/global-sync/event-reducer.ts +359 -0
- package/src/context/global-sync/eviction.ts +28 -0
- package/src/context/global-sync/queue.ts +83 -0
- package/src/context/global-sync/session-cache.test.ts +102 -0
- package/src/context/global-sync/session-cache.ts +62 -0
- package/src/context/global-sync/session-load.ts +25 -0
- package/src/context/global-sync/session-prefetch.test.ts +96 -0
- package/src/context/global-sync/session-prefetch.ts +100 -0
- package/src/context/global-sync/session-trim.test.ts +59 -0
- package/src/context/global-sync/session-trim.ts +56 -0
- package/src/context/global-sync/types.ts +133 -0
- package/src/context/global-sync/utils.ts +25 -0
- package/src/context/global-sync.test.ts +122 -0
- package/src/context/global-sync.tsx +408 -0
- package/src/context/highlights.tsx +233 -0
- package/src/context/language.tsx +248 -0
- package/src/context/layout-scroll.test.ts +64 -0
- package/src/context/layout-scroll.ts +126 -0
- package/src/context/layout.test.ts +69 -0
- package/src/context/layout.tsx +937 -0
- package/src/context/local.tsx +422 -0
- package/src/context/model-variant.test.ts +86 -0
- package/src/context/model-variant.ts +52 -0
- package/src/context/models.tsx +163 -0
- package/src/context/notification.tsx +373 -0
- package/src/context/permission-auto-respond.test.ts +102 -0
- package/src/context/permission-auto-respond.ts +51 -0
- package/src/context/permission.tsx +277 -0
- package/src/context/platform.tsx +99 -0
- package/src/context/prompt.tsx +297 -0
- package/src/context/sdk.tsx +49 -0
- package/src/context/server.tsx +295 -0
- package/src/context/settings.tsx +241 -0
- package/src/context/sync-optimistic.test.ts +123 -0
- package/src/context/sync.tsx +618 -0
- package/src/context/terminal-title.ts +51 -0
- package/src/context/terminal.test.ts +82 -0
- package/src/context/terminal.tsx +437 -0
- package/src/entry.tsx +144 -0
- package/src/env.d.ts +18 -0
- package/src/hooks/use-providers.ts +44 -0
- package/src/i18n/ar.ts +855 -0
- package/src/i18n/br.ts +867 -0
- package/src/i18n/bs.ts +943 -0
- package/src/i18n/da.ts +937 -0
- package/src/i18n/de.ts +879 -0
- package/src/i18n/en.ts +948 -0
- package/src/i18n/es.ts +950 -0
- package/src/i18n/fr.ts +878 -0
- package/src/i18n/ja.ts +861 -0
- package/src/i18n/ko.ts +860 -0
- package/src/i18n/no.ts +944 -0
- package/src/i18n/parity.test.ts +32 -0
- package/src/i18n/pl.ts +865 -0
- package/src/i18n/ru.ts +946 -0
- package/src/i18n/th.ts +933 -0
- package/src/i18n/tr.ts +952 -0
- package/src/i18n/zh.ts +930 -0
- package/src/i18n/zht.ts +925 -0
- package/src/index.css +29 -0
- package/src/index.ts +6 -0
- package/src/pages/directory-layout.tsx +88 -0
- package/src/pages/error.tsx +327 -0
- package/src/pages/home.tsx +131 -0
- package/src/pages/layout/deep-links.ts +50 -0
- package/src/pages/layout/helpers.test.ts +211 -0
- package/src/pages/layout/helpers.ts +98 -0
- package/src/pages/layout/inline-editor.tsx +126 -0
- package/src/pages/layout/sidebar-items.tsx +437 -0
- package/src/pages/layout/sidebar-project.tsx +384 -0
- package/src/pages/layout/sidebar-shell.tsx +125 -0
- package/src/pages/layout/sidebar-workspace.tsx +504 -0
- package/src/pages/layout.tsx +2509 -0
- package/src/pages/session/composer/index.ts +2 -0
- package/src/pages/session/composer/session-composer-region.tsx +255 -0
- package/src/pages/session/composer/session-composer-state.test.ts +128 -0
- package/src/pages/session/composer/session-composer-state.ts +249 -0
- package/src/pages/session/composer/session-followup-dock.tsx +109 -0
- package/src/pages/session/composer/session-permission-dock.tsx +74 -0
- package/src/pages/session/composer/session-question-dock.tsx +449 -0
- package/src/pages/session/composer/session-request-tree.ts +52 -0
- package/src/pages/session/composer/session-revert-dock.tsx +99 -0
- package/src/pages/session/composer/session-todo-dock.tsx +330 -0
- package/src/pages/session/file-tab-scroll.test.ts +40 -0
- package/src/pages/session/file-tab-scroll.ts +67 -0
- package/src/pages/session/file-tabs.tsx +456 -0
- package/src/pages/session/handoff.ts +36 -0
- package/src/pages/session/helpers.test.ts +181 -0
- package/src/pages/session/helpers.ts +198 -0
- package/src/pages/session/message-gesture.test.ts +62 -0
- package/src/pages/session/message-gesture.ts +21 -0
- package/src/pages/session/message-id-from-hash.ts +6 -0
- package/src/pages/session/message-timeline.tsx +1013 -0
- package/src/pages/session/review-tab.tsx +170 -0
- package/src/pages/session/session-layout.ts +20 -0
- package/src/pages/session/session-model-helpers.test.ts +51 -0
- package/src/pages/session/session-model-helpers.ts +16 -0
- package/src/pages/session/session-side-panel.tsx +453 -0
- package/src/pages/session/terminal-label.ts +16 -0
- package/src/pages/session/terminal-panel.test.ts +25 -0
- package/src/pages/session/terminal-panel.tsx +326 -0
- package/src/pages/session/use-session-commands.tsx +495 -0
- package/src/pages/session/use-session-hash-scroll.test.ts +16 -0
- package/src/pages/session/use-session-hash-scroll.ts +197 -0
- package/src/pages/session.tsx +1841 -0
- package/src/sst-env.d.ts +12 -0
- package/src/testing/model-selection.ts +80 -0
- package/src/testing/prompt.ts +56 -0
- package/src/testing/session-composer.ts +84 -0
- package/src/testing/terminal.ts +118 -0
- package/src/theme-preload.test.ts +46 -0
- package/src/utils/agent.ts +23 -0
- package/src/utils/aim.ts +138 -0
- package/src/utils/base64.ts +10 -0
- package/src/utils/comment-note.ts +88 -0
- package/src/utils/id.ts +99 -0
- package/src/utils/notification-click.test.ts +27 -0
- package/src/utils/notification-click.ts +13 -0
- package/src/utils/persist.test.ts +115 -0
- package/src/utils/persist.ts +476 -0
- package/src/utils/prompt.test.ts +44 -0
- package/src/utils/prompt.ts +203 -0
- package/src/utils/runtime-adapters.test.ts +62 -0
- package/src/utils/runtime-adapters.ts +39 -0
- package/src/utils/same.ts +6 -0
- package/src/utils/scoped-cache.test.ts +69 -0
- package/src/utils/scoped-cache.ts +104 -0
- package/src/utils/server-errors.test.ts +131 -0
- package/src/utils/server-errors.ts +80 -0
- package/src/utils/server-health.test.ts +123 -0
- package/src/utils/server-health.ts +91 -0
- package/src/utils/server.ts +22 -0
- package/src/utils/solid-dnd.tsx +49 -0
- package/src/utils/sound.ts +117 -0
- package/src/utils/terminal-writer.test.ts +64 -0
- package/src/utils/terminal-writer.ts +65 -0
- package/src/utils/time.ts +22 -0
- package/src/utils/uuid.test.ts +78 -0
- package/src/utils/uuid.ts +12 -0
- package/src/utils/worktree.test.ts +46 -0
- package/src/utils/worktree.ts +73 -0
- package/sst-env.d.ts +10 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +15 -0
- package/vite.js +26 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { useIsRouting, useLocation } from "@solidjs/router"
|
|
2
|
+
import { batch, createEffect, onCleanup, onMount } from "solid-js"
|
|
3
|
+
import { createStore } from "solid-js/store"
|
|
4
|
+
import { Tooltip } from "@reign-labs/ui/tooltip"
|
|
5
|
+
import { useLanguage } from "@/context/language"
|
|
6
|
+
|
|
7
|
+
type Mem = Performance & {
|
|
8
|
+
memory?: {
|
|
9
|
+
usedJSHeapSize: number
|
|
10
|
+
jsHeapSizeLimit: number
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Evt = PerformanceEntry & {
|
|
15
|
+
interactionId?: number
|
|
16
|
+
processingStart?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Shift = PerformanceEntry & {
|
|
20
|
+
hadRecentInput: boolean
|
|
21
|
+
value: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Obs = PerformanceObserverInit & {
|
|
25
|
+
durationThreshold?: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const span = 5000
|
|
29
|
+
|
|
30
|
+
const ms = (n?: number, d = 0) => {
|
|
31
|
+
if (n === undefined || Number.isNaN(n)) return
|
|
32
|
+
return `${n.toFixed(d)}ms`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const time = (n?: number) => {
|
|
36
|
+
if (n === undefined || Number.isNaN(n)) return
|
|
37
|
+
return `${Math.round(n)}`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const mb = (n?: number) => {
|
|
41
|
+
if (n === undefined || Number.isNaN(n)) return
|
|
42
|
+
const v = n / 1024 / 1024
|
|
43
|
+
return `${v >= 1024 ? v.toFixed(0) : v.toFixed(1)}MB`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const bad = (n: number | undefined, limit: number, low = false) => {
|
|
47
|
+
if (n === undefined || Number.isNaN(n)) return false
|
|
48
|
+
return low ? n < limit : n > limit
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const session = (path: string) => path.includes("/session")
|
|
52
|
+
|
|
53
|
+
function Cell(props: { bad?: boolean; dim?: boolean; label: string; tip: string; value: string; wide?: boolean }) {
|
|
54
|
+
return (
|
|
55
|
+
<Tooltip value={props.tip} placement="top">
|
|
56
|
+
<div
|
|
57
|
+
classList={{
|
|
58
|
+
"flex min-h-[42px] w-full min-w-0 flex-col items-center justify-center rounded-[8px] px-0.5 py-1 text-center": true,
|
|
59
|
+
"col-span-2": !!props.wide,
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<div class="text-[10px] leading-none font-black uppercase tracking-[0.04em] opacity-70">{props.label}</div>
|
|
63
|
+
<div
|
|
64
|
+
classList={{
|
|
65
|
+
"text-[13px] leading-none font-bold tabular-nums sm:text-[14px]": true,
|
|
66
|
+
"text-text-on-critical-base": !!props.bad,
|
|
67
|
+
"opacity-70": !!props.dim,
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{props.value}
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</Tooltip>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function DebugBar() {
|
|
78
|
+
const language = useLanguage()
|
|
79
|
+
const location = useLocation()
|
|
80
|
+
const routing = useIsRouting()
|
|
81
|
+
const [state, setState] = createStore({
|
|
82
|
+
cls: undefined as number | undefined,
|
|
83
|
+
delay: undefined as number | undefined,
|
|
84
|
+
fps: undefined as number | undefined,
|
|
85
|
+
gap: undefined as number | undefined,
|
|
86
|
+
heap: {
|
|
87
|
+
limit: undefined as number | undefined,
|
|
88
|
+
used: undefined as number | undefined,
|
|
89
|
+
},
|
|
90
|
+
inp: undefined as number | undefined,
|
|
91
|
+
jank: undefined as number | undefined,
|
|
92
|
+
long: {
|
|
93
|
+
block: undefined as number | undefined,
|
|
94
|
+
count: undefined as number | undefined,
|
|
95
|
+
max: undefined as number | undefined,
|
|
96
|
+
},
|
|
97
|
+
nav: {
|
|
98
|
+
dur: undefined as number | undefined,
|
|
99
|
+
pending: false,
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const na = () => language.t("debugBar.na")
|
|
104
|
+
const heap = () => (state.heap.limit ? (state.heap.used ?? 0) / state.heap.limit : undefined)
|
|
105
|
+
const heapv = () => {
|
|
106
|
+
const value = heap()
|
|
107
|
+
if (value === undefined) return na()
|
|
108
|
+
return `${Math.round(value * 100)}%`
|
|
109
|
+
}
|
|
110
|
+
const longv = () => (state.long.count === undefined ? na() : `${time(state.long.block) ?? na()}/${state.long.count}`)
|
|
111
|
+
const navv = () => (state.nav.pending ? "..." : (time(state.nav.dur) ?? na()))
|
|
112
|
+
|
|
113
|
+
let prev = ""
|
|
114
|
+
let start = 0
|
|
115
|
+
let init = false
|
|
116
|
+
let one = 0
|
|
117
|
+
let two = 0
|
|
118
|
+
|
|
119
|
+
createEffect(() => {
|
|
120
|
+
const busy = routing()
|
|
121
|
+
const next = `${location.pathname}${location.search}`
|
|
122
|
+
|
|
123
|
+
if (!init) {
|
|
124
|
+
init = true
|
|
125
|
+
prev = next
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (busy) {
|
|
130
|
+
if (one !== 0) cancelAnimationFrame(one)
|
|
131
|
+
if (two !== 0) cancelAnimationFrame(two)
|
|
132
|
+
one = 0
|
|
133
|
+
two = 0
|
|
134
|
+
if (start !== 0) return
|
|
135
|
+
start = performance.now()
|
|
136
|
+
if (session(prev)) setState("nav", { dur: undefined, pending: true })
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (start === 0) {
|
|
141
|
+
prev = next
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const at = start
|
|
146
|
+
const from = prev
|
|
147
|
+
start = 0
|
|
148
|
+
prev = next
|
|
149
|
+
|
|
150
|
+
if (!(session(from) || session(next))) return
|
|
151
|
+
|
|
152
|
+
if (one !== 0) cancelAnimationFrame(one)
|
|
153
|
+
if (two !== 0) cancelAnimationFrame(two)
|
|
154
|
+
one = requestAnimationFrame(() => {
|
|
155
|
+
one = 0
|
|
156
|
+
two = requestAnimationFrame(() => {
|
|
157
|
+
two = 0
|
|
158
|
+
setState("nav", { dur: performance.now() - at, pending: false })
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
onMount(() => {
|
|
164
|
+
const obs: PerformanceObserver[] = []
|
|
165
|
+
const fps: Array<{ at: number; dur: number }> = []
|
|
166
|
+
const long: Array<{ at: number; dur: number }> = []
|
|
167
|
+
const seen = new Map<number | string, { at: number; delay: number; dur: number }>()
|
|
168
|
+
let hasLong = false
|
|
169
|
+
let poll: number | undefined
|
|
170
|
+
let raf = 0
|
|
171
|
+
let last = 0
|
|
172
|
+
let snap = 0
|
|
173
|
+
|
|
174
|
+
const trim = (list: Array<{ at: number; dur: number }>, span: number, at: number) => {
|
|
175
|
+
while (list[0] && at - list[0].at > span) list.shift()
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const syncFrame = (at: number) => {
|
|
179
|
+
trim(fps, span, at)
|
|
180
|
+
const total = fps.reduce((sum, entry) => sum + entry.dur, 0)
|
|
181
|
+
const gap = fps.reduce((max, entry) => Math.max(max, entry.dur), 0)
|
|
182
|
+
const jank = fps.filter((entry) => entry.dur > 32).length
|
|
183
|
+
batch(() => {
|
|
184
|
+
setState("fps", total > 0 ? (fps.length * 1000) / total : undefined)
|
|
185
|
+
setState("gap", gap > 0 ? gap : undefined)
|
|
186
|
+
setState("jank", jank)
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const syncLong = (at = performance.now()) => {
|
|
191
|
+
if (!hasLong) return
|
|
192
|
+
trim(long, span, at)
|
|
193
|
+
const block = long.reduce((sum, entry) => sum + Math.max(0, entry.dur - 50), 0)
|
|
194
|
+
const max = long.reduce((hi, entry) => Math.max(hi, entry.dur), 0)
|
|
195
|
+
setState("long", { block, count: long.length, max })
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const syncInp = (at = performance.now()) => {
|
|
199
|
+
for (const [key, entry] of seen) {
|
|
200
|
+
if (at - entry.at > span) seen.delete(key)
|
|
201
|
+
}
|
|
202
|
+
let delay = 0
|
|
203
|
+
let inp = 0
|
|
204
|
+
for (const entry of seen.values()) {
|
|
205
|
+
delay = Math.max(delay, entry.delay)
|
|
206
|
+
inp = Math.max(inp, entry.dur)
|
|
207
|
+
}
|
|
208
|
+
batch(() => {
|
|
209
|
+
setState("delay", delay > 0 ? delay : undefined)
|
|
210
|
+
setState("inp", inp > 0 ? inp : undefined)
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const syncHeap = () => {
|
|
215
|
+
const mem = (performance as Mem).memory
|
|
216
|
+
if (!mem) return
|
|
217
|
+
setState("heap", { limit: mem.jsHeapSizeLimit, used: mem.usedJSHeapSize })
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const reset = () => {
|
|
221
|
+
fps.length = 0
|
|
222
|
+
long.length = 0
|
|
223
|
+
seen.clear()
|
|
224
|
+
last = 0
|
|
225
|
+
snap = 0
|
|
226
|
+
batch(() => {
|
|
227
|
+
setState("fps", undefined)
|
|
228
|
+
setState("gap", undefined)
|
|
229
|
+
setState("jank", undefined)
|
|
230
|
+
setState("delay", undefined)
|
|
231
|
+
setState("inp", undefined)
|
|
232
|
+
if (hasLong) setState("long", { block: 0, count: 0, max: 0 })
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const watch = (type: string, init: Obs, fn: (entries: PerformanceEntry[]) => void) => {
|
|
237
|
+
if (typeof PerformanceObserver === "undefined") return false
|
|
238
|
+
if (!(PerformanceObserver.supportedEntryTypes ?? []).includes(type)) return false
|
|
239
|
+
const ob = new PerformanceObserver((list) => fn(list.getEntries()))
|
|
240
|
+
try {
|
|
241
|
+
ob.observe(init)
|
|
242
|
+
obs.push(ob)
|
|
243
|
+
return true
|
|
244
|
+
} catch {
|
|
245
|
+
ob.disconnect()
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (
|
|
251
|
+
watch("layout-shift", { buffered: true, type: "layout-shift" }, (entries) => {
|
|
252
|
+
const add = entries.reduce((sum, entry) => {
|
|
253
|
+
const item = entry as Shift
|
|
254
|
+
if (item.hadRecentInput) return sum
|
|
255
|
+
return sum + item.value
|
|
256
|
+
}, 0)
|
|
257
|
+
if (add === 0) return
|
|
258
|
+
setState("cls", (value) => (value ?? 0) + add)
|
|
259
|
+
})
|
|
260
|
+
) {
|
|
261
|
+
setState("cls", 0)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (
|
|
265
|
+
watch("longtask", { buffered: true, type: "longtask" }, (entries) => {
|
|
266
|
+
const at = performance.now()
|
|
267
|
+
long.push(...entries.map((entry) => ({ at: entry.startTime, dur: entry.duration })))
|
|
268
|
+
syncLong(at)
|
|
269
|
+
})
|
|
270
|
+
) {
|
|
271
|
+
hasLong = true
|
|
272
|
+
setState("long", { block: 0, count: 0, max: 0 })
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
watch("event", { buffered: true, durationThreshold: 16, type: "event" }, (entries) => {
|
|
276
|
+
for (const raw of entries) {
|
|
277
|
+
const entry = raw as Evt
|
|
278
|
+
if (entry.duration < 16) continue
|
|
279
|
+
const key =
|
|
280
|
+
entry.interactionId && entry.interactionId > 0
|
|
281
|
+
? entry.interactionId
|
|
282
|
+
: `${entry.name}:${Math.round(entry.startTime)}`
|
|
283
|
+
const prev = seen.get(key)
|
|
284
|
+
const delay = Math.max(0, (entry.processingStart ?? entry.startTime) - entry.startTime)
|
|
285
|
+
seen.set(key, {
|
|
286
|
+
at: entry.startTime,
|
|
287
|
+
delay: Math.max(prev?.delay ?? 0, delay),
|
|
288
|
+
dur: Math.max(prev?.dur ?? 0, entry.duration),
|
|
289
|
+
})
|
|
290
|
+
if (seen.size <= 200) continue
|
|
291
|
+
const first = seen.keys().next().value
|
|
292
|
+
if (first !== undefined) seen.delete(first)
|
|
293
|
+
}
|
|
294
|
+
syncInp()
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
const loop = (at: number) => {
|
|
298
|
+
if (document.visibilityState !== "visible") {
|
|
299
|
+
raf = 0
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (last === 0) {
|
|
304
|
+
last = at
|
|
305
|
+
raf = requestAnimationFrame(loop)
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
fps.push({ at, dur: at - last })
|
|
310
|
+
last = at
|
|
311
|
+
|
|
312
|
+
if (at - snap >= 250) {
|
|
313
|
+
snap = at
|
|
314
|
+
syncFrame(at)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
raf = requestAnimationFrame(loop)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const stop = () => {
|
|
321
|
+
if (raf !== 0) cancelAnimationFrame(raf)
|
|
322
|
+
raf = 0
|
|
323
|
+
if (poll === undefined) return
|
|
324
|
+
clearInterval(poll)
|
|
325
|
+
poll = undefined
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const start = () => {
|
|
329
|
+
if (document.visibilityState !== "visible") return
|
|
330
|
+
if (poll === undefined) {
|
|
331
|
+
poll = window.setInterval(() => {
|
|
332
|
+
syncLong()
|
|
333
|
+
syncInp()
|
|
334
|
+
syncHeap()
|
|
335
|
+
}, 1000)
|
|
336
|
+
}
|
|
337
|
+
if (raf !== 0) return
|
|
338
|
+
raf = requestAnimationFrame(loop)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const vis = () => {
|
|
342
|
+
if (document.visibilityState !== "visible") {
|
|
343
|
+
stop()
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
reset()
|
|
347
|
+
start()
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
syncHeap()
|
|
351
|
+
start()
|
|
352
|
+
document.addEventListener("visibilitychange", vis)
|
|
353
|
+
|
|
354
|
+
onCleanup(() => {
|
|
355
|
+
if (one !== 0) cancelAnimationFrame(one)
|
|
356
|
+
if (two !== 0) cancelAnimationFrame(two)
|
|
357
|
+
stop()
|
|
358
|
+
document.removeEventListener("visibilitychange", vis)
|
|
359
|
+
for (const ob of obs) ob.disconnect()
|
|
360
|
+
})
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<aside
|
|
365
|
+
aria-label={language.t("debugBar.ariaLabel")}
|
|
366
|
+
class="pointer-events-auto fixed bottom-3 right-3 z-50 w-[308px] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-xl border border-border-base bg-surface-raised-stronger-non-alpha p-0.5 text-text-strong shadow-[var(--shadow-lg-border-base)] sm:bottom-4 sm:right-4 sm:w-[324px]"
|
|
367
|
+
>
|
|
368
|
+
<div class="grid grid-cols-5 gap-px font-mono">
|
|
369
|
+
<Cell
|
|
370
|
+
label={language.t("debugBar.nav.label")}
|
|
371
|
+
tip={language.t("debugBar.nav.tip")}
|
|
372
|
+
value={navv()}
|
|
373
|
+
bad={bad(state.nav.dur, 400)}
|
|
374
|
+
dim={state.nav.dur === undefined && !state.nav.pending}
|
|
375
|
+
/>
|
|
376
|
+
<Cell
|
|
377
|
+
label={language.t("debugBar.fps.label")}
|
|
378
|
+
tip={language.t("debugBar.fps.tip")}
|
|
379
|
+
value={state.fps === undefined ? na() : `${Math.round(state.fps)}`}
|
|
380
|
+
bad={bad(state.fps, 50, true)}
|
|
381
|
+
dim={state.fps === undefined}
|
|
382
|
+
/>
|
|
383
|
+
<Cell
|
|
384
|
+
label={language.t("debugBar.frame.label")}
|
|
385
|
+
tip={language.t("debugBar.frame.tip")}
|
|
386
|
+
value={time(state.gap) ?? na()}
|
|
387
|
+
bad={bad(state.gap, 50)}
|
|
388
|
+
dim={state.gap === undefined}
|
|
389
|
+
/>
|
|
390
|
+
<Cell
|
|
391
|
+
label={language.t("debugBar.jank.label")}
|
|
392
|
+
tip={language.t("debugBar.jank.tip")}
|
|
393
|
+
value={state.jank === undefined ? na() : `${state.jank}`}
|
|
394
|
+
bad={bad(state.jank, 8)}
|
|
395
|
+
dim={state.jank === undefined}
|
|
396
|
+
/>
|
|
397
|
+
<Cell
|
|
398
|
+
label={language.t("debugBar.long.label")}
|
|
399
|
+
tip={language.t("debugBar.long.tip", { max: ms(state.long.max) ?? na() })}
|
|
400
|
+
value={longv()}
|
|
401
|
+
bad={bad(state.long.block, 200)}
|
|
402
|
+
dim={state.long.count === undefined}
|
|
403
|
+
/>
|
|
404
|
+
<Cell
|
|
405
|
+
label={language.t("debugBar.delay.label")}
|
|
406
|
+
tip={language.t("debugBar.delay.tip")}
|
|
407
|
+
value={time(state.delay) ?? na()}
|
|
408
|
+
bad={bad(state.delay, 100)}
|
|
409
|
+
dim={state.delay === undefined}
|
|
410
|
+
/>
|
|
411
|
+
<Cell
|
|
412
|
+
label={language.t("debugBar.inp.label")}
|
|
413
|
+
tip={language.t("debugBar.inp.tip")}
|
|
414
|
+
value={time(state.inp) ?? na()}
|
|
415
|
+
bad={bad(state.inp, 200)}
|
|
416
|
+
dim={state.inp === undefined}
|
|
417
|
+
/>
|
|
418
|
+
<Cell
|
|
419
|
+
label={language.t("debugBar.cls.label")}
|
|
420
|
+
tip={language.t("debugBar.cls.tip")}
|
|
421
|
+
value={state.cls === undefined ? na() : state.cls.toFixed(2)}
|
|
422
|
+
bad={bad(state.cls, 0.1)}
|
|
423
|
+
dim={state.cls === undefined}
|
|
424
|
+
/>
|
|
425
|
+
<Cell
|
|
426
|
+
label={language.t("debugBar.mem.label")}
|
|
427
|
+
tip={
|
|
428
|
+
state.heap.used === undefined
|
|
429
|
+
? language.t("debugBar.mem.tipUnavailable")
|
|
430
|
+
: language.t("debugBar.mem.tip", {
|
|
431
|
+
used: mb(state.heap.used) ?? na(),
|
|
432
|
+
limit: mb(state.heap.limit) ?? na(),
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
value={heapv()}
|
|
436
|
+
bad={bad(heap(), 0.8)}
|
|
437
|
+
dim={state.heap.used === undefined}
|
|
438
|
+
wide
|
|
439
|
+
/>
|
|
440
|
+
</div>
|
|
441
|
+
</aside>
|
|
442
|
+
)
|
|
443
|
+
}
|