@zyro-sec/session-ui 0.0.0-stage → 1.0.4
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 +25 -0
- package/bunfig.toml +2 -0
- package/component-tests/basic-tool.fixture.tsx +46 -0
- package/component-tests/basic-tool.spec.ts +63 -0
- package/component-tests/file-media.fixture.tsx +39 -0
- package/component-tests/file-media.spec.ts +13 -0
- package/component-tests/file-tool.spec.ts +62 -0
- package/component-tests/file-viewer.fixture.tsx +109 -0
- package/component-tests/file-viewer.spec.ts +134 -0
- package/component-tests/file.spec.ts +33 -0
- package/component-tests/line-comment-v2.spec.ts +15 -0
- package/component-tests/markdown-code-wrap.spec.ts +94 -0
- package/component-tests/markdown-readiness.spec.ts +95 -0
- package/component-tests/markdown.fixture.tsx +104 -0
- package/component-tests/markdown.spec.ts +1564 -0
- package/component-tests/mermaid-preview.spec.ts +43 -0
- package/component-tests/patch-group.spec.ts +79 -0
- package/component-tests/read-group.spec.ts +72 -0
- package/component-tests/read-image.fixture.tsx +66 -0
- package/component-tests/read-image.spec.ts +154 -0
- package/component-tests/session-compaction.spec.ts +254 -0
- package/component-tests/session-lifecycle.spec.ts +190 -0
- package/component-tests/session-message-projection.spec.ts +639 -0
- package/component-tests/session-notice-projection.spec.ts +20 -0
- package/component-tests/session-review-comments.spec.ts +179 -0
- package/component-tests/session-shell.spec.ts +93 -0
- package/component-tests/session-timeline-mobile.spec.ts +201 -0
- package/component-tests/session-timeline-notices.spec.ts +38 -0
- package/component-tests/session-timeline-reasoning.spec.ts +107 -0
- package/component-tests/session-timeline.spec.ts +157 -0
- package/component-tests/session-tool-projection.spec.ts +323 -0
- package/component-tests/text-lifecycle.fixture.tsx +26 -0
- package/component-tests/text-lifecycle.spec.ts +42 -0
- package/component-tests/timeline-subagent-rows.spec.ts +33 -0
- package/component-tests/tool-disclosure.spec.ts +48 -0
- package/component-tests/tool-group-sticky.spec.ts +37 -0
- package/component-tests/tool-group.spec.ts +290 -0
- package/component-tests/tool-status-title.fixture.tsx +22 -0
- package/component-tests/tool-status-title.spec.ts +30 -0
- package/component-tests/user-message-quotes.spec.ts +111 -0
- package/package.json +91 -4
- package/playwright.components.config.ts +4 -0
- package/playwright.local.config.ts +2 -0
- package/src/actions.ts +54 -0
- package/src/components/apply-patch-file.ts +122 -0
- package/src/components/basic-tool.css +487 -0
- package/src/components/basic-tool.tsx +258 -0
- package/src/components/copy-machine.ts +78 -0
- package/src/components/copy.ts +85 -0
- package/src/components/diagram-preview.tsx +28 -0
- package/src/components/disclosure-machine.ts +188 -0
- package/src/components/disclosure.ts +129 -0
- package/src/components/dock-prompt.stories.tsx +73 -0
- package/src/components/dock-prompt.tsx +29 -0
- package/src/components/file-comment-selection.tsx +146 -0
- package/src/components/file-media-machine.ts +165 -0
- package/src/components/file-media.stories.tsx +112 -0
- package/src/components/file-media.tsx +323 -0
- package/src/components/file-search.tsx +73 -0
- package/src/components/file.css +59 -0
- package/src/components/file.tsx +1300 -0
- package/src/components/image-preview.tsx +35 -0
- package/src/components/line-comment-annotations.tsx +580 -0
- package/src/components/line-comment-machine.ts +262 -0
- package/src/components/line-comment-styles.ts +293 -0
- package/src/components/line-comment.stories.tsx +152 -0
- package/src/components/line-comment.tsx +448 -0
- package/src/components/link-segments.ts +20 -0
- package/src/components/linked-text.tsx +21 -0
- package/src/components/markdown-cache-machine.ts +257 -0
- package/src/components/markdown-cache.tsx +556 -0
- package/src/components/markdown-clipboard.ts +101 -0
- package/src/components/markdown-code-machine.ts +200 -0
- package/src/components/markdown-code-state.ts +22 -0
- package/src/components/markdown-fragment-links.ts +74 -0
- package/src/components/markdown-github.svg +3 -0
- package/src/components/markdown-globe.svg +5 -0
- package/src/components/markdown-image-machine.ts +170 -0
- package/src/components/markdown-image.ts +156 -0
- package/src/components/markdown-inline-code-kind.ts +39 -0
- package/src/components/markdown-mermaid.ts +18 -0
- package/src/components/markdown-phase-machine.ts +102 -0
- package/src/components/markdown-projection.ts +13 -0
- package/src/components/markdown-session-links.ts +183 -0
- package/src/components/markdown-solid.test.tsx +92 -0
- package/src/components/markdown-solid.tsx +113 -0
- package/src/components/markdown-stream.ts +95 -0
- package/src/components/markdown-worker-machine.ts +516 -0
- package/src/components/markdown-worker-protocol.ts +73 -0
- package/src/components/markdown-worker.ts +250 -0
- package/src/components/markdown.css +672 -0
- package/src/components/markdown.stories.tsx +199 -0
- package/src/components/markdown.tsx +1612 -0
- package/src/components/markdown.worker.ts +188 -0
- package/src/components/message-file.ts +102 -0
- package/src/components/message-nav.css +134 -0
- package/src/components/message-nav.tsx +159 -0
- package/src/components/message-part.css +2109 -0
- package/src/components/message-part.tsx +3 -0
- package/src/components/question-prompt-experimental.css +576 -0
- package/src/components/question-prompt.css +527 -0
- package/src/components/quote-highlight.css +59 -0
- package/src/components/review-focus-driver.ts +142 -0
- package/src/components/review-focus-machine.ts +95 -0
- package/src/components/session-compaction.css +270 -0
- package/src/components/session-diff.ts +358 -0
- package/src/components/session-error.tsx +41 -0
- package/src/components/session-retry.tsx +92 -0
- package/src/components/session-review-machine.ts +241 -0
- package/src/components/session-review.css +264 -0
- package/src/components/session-review.stories.tsx +232 -0
- package/src/components/session-review.tsx +733 -0
- package/src/components/session-turn.css +282 -0
- package/src/components/shell-submessage.css +24 -0
- package/src/components/timeline-separator.tsx +69 -0
- package/src/components/tool-count-label.css +57 -0
- package/src/components/tool-count-label.tsx +76 -0
- package/src/components/tool-count-summary.css +102 -0
- package/src/components/tool-count-summary.stories.tsx +99 -0
- package/src/components/tool-count-summary.tsx +44 -0
- package/src/components/tool-error-card.css +178 -0
- package/src/components/tool-error-card.stories.tsx +113 -0
- package/src/components/tool-error-card.tsx +202 -0
- package/src/components/tool-status-title-machine.ts +128 -0
- package/src/components/tool-status-title.css +89 -0
- package/src/components/tool-status-title.tsx +163 -0
- package/src/context/data.tsx +107 -0
- package/src/context/index.ts +1 -0
- package/src/context/markdown.tsx +129 -0
- package/src/context/sources.tsx +34 -0
- package/src/document.ts +8 -0
- package/src/file-presentation.ts +34 -0
- package/src/message/action-machine.ts +72 -0
- package/src/message/agent-label.ts +3 -0
- package/src/message/attachment-card.css +119 -0
- package/src/message/attachment-card.tsx +40 -0
- package/src/message/attachment-media-machine.ts +213 -0
- package/src/message/comment-card.tsx +155 -0
- package/src/message/compaction-entrance-machine.ts +93 -0
- package/src/message/current-message.tsx +157 -0
- package/src/message/current-tool-state.ts +161 -0
- package/src/message/message-content.tsx +1391 -0
- package/src/message/paced-text-machine.ts +73 -0
- package/src/message/prompt-message.stories.tsx +149 -0
- package/src/message/relative-time.ts +45 -0
- package/src/message/user-message-quote-parts.ts +16 -0
- package/src/message/user-message-quotes.stories.tsx +797 -0
- package/src/message/user-message-quotes.tsx +135 -0
- package/src/pierre/comment-hover-machine.ts +53 -0
- package/src/pierre/comment-hover.ts +131 -0
- package/src/pierre/comment-selection-machine.ts +257 -0
- package/src/pierre/commented-lines.ts +106 -0
- package/src/pierre/diff-selection.ts +91 -0
- package/src/pierre/file-find-machine.ts +323 -0
- package/src/pierre/file-find.ts +537 -0
- package/src/pierre/file-runtime.ts +42 -0
- package/src/pierre/file-selection.ts +140 -0
- package/src/pierre/index.ts +344 -0
- package/src/pierre/media.ts +140 -0
- package/src/pierre/render-machine.ts +381 -0
- package/src/pierre/selection-bridge.ts +82 -0
- package/src/pierre/selection-machine.ts +198 -0
- package/src/pierre/virtualizer.ts +114 -0
- package/src/pierre/worker.ts +46 -0
- package/src/sources/experiment.ts +59 -0
- package/src/sources/site-icon.tsx +53 -0
- package/src/sources/sources-chip.tsx +57 -0
- package/src/sources/sources-expand-machine.ts +101 -0
- package/src/sources/sources-panel.tsx +249 -0
- package/src/sources/sources-title.tsx +21 -0
- package/src/sources/sources.css +266 -0
- package/src/sources/sources.ts +141 -0
- package/src/storybook/current-session-fixtures.ts +1492 -0
- package/src/storybook/current-session-scenarios.ts +76 -0
- package/src/storybook/current-session-story.tsx +154 -0
- package/src/storybook/index.ts +43 -0
- package/src/styles/index.css +19 -0
- package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
- package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
- package/src/timeline/code-blocks.stories.tsx +105 -0
- package/src/timeline/commentary.stories.tsx +70 -0
- package/src/timeline/commentary.ts +38 -0
- package/src/timeline/detail.ts +111 -0
- package/src/timeline/error-card.stories.tsx +134 -0
- package/src/timeline/error-spacing.stories.tsx +71 -0
- package/src/timeline/facts.ts +493 -0
- package/src/timeline/file-changes.stories.tsx +436 -0
- package/src/timeline/group-label-fixtures.ts +97 -0
- package/src/timeline/mermaid.stories.tsx +131 -0
- package/src/timeline/place.ts +280 -0
- package/src/timeline/placement-fixtures.ts +365 -0
- package/src/timeline/placement-reactivity.ts +133 -0
- package/src/timeline/projection.ts +1261 -0
- package/src/timeline/research-and-agents.stories.tsx +461 -0
- package/src/timeline/session-timeline-row.tsx +1675 -0
- package/src/timeline/session-timeline.tsx +68 -0
- package/src/timeline/steer-arrival-machine.ts +134 -0
- package/src/timeline/terminal-work.stories.tsx +464 -0
- package/src/timeline/timeline-row.stories.tsx +1069 -0
- package/src/timeline/timeline-row.ts +238 -0
- package/src/timeline/turn-phase-machine.ts +112 -0
- package/src/timeline/user-message-fold.stories.tsx +194 -0
- package/src/timeline/user-runs.ts +87 -0
- package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
- package/src/timeline-next/compaction.tsx +236 -0
- package/src/timeline-next/errors.ts +101 -0
- package/src/timeline-next/event-row.tsx +168 -0
- package/src/timeline-next/events.ts +103 -0
- package/src/timeline-next/index.ts +10 -0
- package/src/timeline-next/nested-rail.ts +125 -0
- package/src/timeline-next/projection.ts +1028 -0
- package/src/timeline-next/row.tsx +1728 -0
- package/src/timeline-next/rules.ts +89 -0
- package/src/timeline-next/separator.tsx +73 -0
- package/src/timeline-next/spacing.ts +127 -0
- package/src/timeline-next/status-line.tsx +41 -0
- package/src/timeline-next/status.ts +33 -0
- package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
- package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
- package/src/timeline-next/stories/compare.stories.tsx +486 -0
- package/src/timeline-next/stories/playground.stories.tsx +297 -0
- package/src/timeline-next/stories/session-replay.ts +1156 -0
- package/src/timeline-next/stories/session-timeline.tsx +50 -0
- package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
- package/src/timeline-next/timeline-next.css +649 -0
- package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
- package/src/timeline-next/tools/activity-label.ts +166 -0
- package/src/timeline-next/tools/assistant-content.tsx +84 -0
- package/src/timeline-next/tools/context-group.tsx +619 -0
- package/src/timeline-next/tools/error-card.tsx +147 -0
- package/src/timeline-next/tools/explore.tsx +119 -0
- package/src/timeline-next/tools/file-group.tsx +128 -0
- package/src/timeline-next/tools/patch.tsx +174 -0
- package/src/timeline-next/tools/shell.tsx +186 -0
- package/src/timeline-next/tools/thought.tsx +87 -0
- package/src/timeline-next/tools/tool-display.tsx +119 -0
- package/src/tools/ansi.ts +8 -0
- package/src/tools/context-group-label.ts +123 -0
- package/src/tools/file-runs.ts +35 -0
- package/src/tools/project-path.ts +18 -0
- package/src/tools/read-group.stories.tsx +159 -0
- package/src/tools/run-machine.ts +185 -0
- package/src/tools/shell-output-machine.ts +233 -0
- package/src/tools/shell-output.ts +91 -0
- package/src/tools/subagent-row-variants.stories.tsx +129 -0
- package/src/tools/tool-group.stories.tsx +345 -0
- package/src/tools/tool-renderer.tsx +2876 -0
- package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
- package/src/v2/components/session-file-panel-v2.tsx +149 -0
- package/src/v2/components/session-progress-indicator-v2.css +5 -0
- package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
- package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
- package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
- package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
- package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
- package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
- package/src/v2/components/session-review-v2.css +653 -0
- package/src/v2/components/session-review-v2.tsx +422 -0
- package/src/v2/components/sidebar-presence-machine.ts +69 -0
- package/tsconfig.json +20 -0
- package/README.md +0 -3
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DiffLineAnnotation,
|
|
3
|
+
FileContents,
|
|
4
|
+
FileDiffOptions,
|
|
5
|
+
registerCustomTheme,
|
|
6
|
+
type SelectedLineRange,
|
|
7
|
+
} from "@pierre/diffs"
|
|
8
|
+
import { OpenCodeTheme } from "@zyro-sec/ui/context/highlight-theme"
|
|
9
|
+
import { ComponentProps } from "solid-js"
|
|
10
|
+
import { lineCommentStyles } from "../components/line-comment-styles"
|
|
11
|
+
import quoteHighlightStyles from "../components/quote-highlight.css?inline"
|
|
12
|
+
|
|
13
|
+
// Pierre resolves themes on the main thread and hands them to its workers, so register before any viewer renders.
|
|
14
|
+
registerCustomTheme(OpenCodeTheme.name, () => Promise.resolve(OpenCodeTheme), "zed")
|
|
15
|
+
|
|
16
|
+
// Viewers and worker pools must agree: the pool's options win whenever it renders.
|
|
17
|
+
export const highlightOptions = { theme: OpenCodeTheme.name, preferredHighlighter: "highlights" } as const
|
|
18
|
+
|
|
19
|
+
export type DiffProps<T = {}> = FileDiffOptions<T, undefined> & {
|
|
20
|
+
before: FileContents
|
|
21
|
+
after: FileContents
|
|
22
|
+
annotations?: DiffLineAnnotation<T>[]
|
|
23
|
+
selectedLines?: SelectedLineRange | null
|
|
24
|
+
commentedLines?: SelectedLineRange[]
|
|
25
|
+
onLineNumberSelectionEnd?: (selection: SelectedLineRange | null) => void
|
|
26
|
+
onRendered?: () => void
|
|
27
|
+
class?: string
|
|
28
|
+
classList?: ComponentProps<"div">["classList"]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const unsafeCSS = `
|
|
32
|
+
:host {
|
|
33
|
+
--diffs-bg: var(--opencode-diffs-bg, var(--color-background-stronger));
|
|
34
|
+
--diffs-fg: var(--opencode-diffs-fg, light-dark(var(--diffs-light, #000), var(--diffs-dark, #fff)));
|
|
35
|
+
/* Pierre mixes 15% in dark mode, which makes collapsed rows read as highlighted. */
|
|
36
|
+
--diffs-bg-separator-override: light-dark(
|
|
37
|
+
color-mix(in lab, var(--diffs-bg) 98%, var(--diffs-mixer)),
|
|
38
|
+
color-mix(in lab, var(--diffs-bg) 95%, var(--diffs-mixer))
|
|
39
|
+
);
|
|
40
|
+
--diffs-bg-addition-emphasis-override: light-dark(
|
|
41
|
+
rgb(from var(--v2-green-600) r g b / 0.2),
|
|
42
|
+
rgb(from var(--v2-green-600) r g b / 0.4)
|
|
43
|
+
);
|
|
44
|
+
--diffs-bg-deletion-emphasis-override: light-dark(
|
|
45
|
+
rgb(from var(--v2-red-600) r g b / 0.2),
|
|
46
|
+
rgb(from var(--v2-red-600) r g b / 0.4)
|
|
47
|
+
);
|
|
48
|
+
--diffs-fg-number-override: var(--v2-text-text-faint);
|
|
49
|
+
/* A page can set the --opencode-diffs-addition-* variables to show additions plain, as a created file does. */
|
|
50
|
+
--diffs-fg-number-addition-override: var(
|
|
51
|
+
--opencode-diffs-addition-number-fg,
|
|
52
|
+
light-dark(var(--v2-green-900), var(--v2-green-400))
|
|
53
|
+
);
|
|
54
|
+
--diffs-fg-number-deletion-override: light-dark(var(--v2-red-800), var(--v2-red-500));
|
|
55
|
+
/* The app's code wrapping rules do not reach this shadow tree, and pretty is inherited from the page. */
|
|
56
|
+
text-wrap-style: auto;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[data-diff],
|
|
60
|
+
[data-file] {
|
|
61
|
+
--diffs-bg-deletion-override: light-dark(
|
|
62
|
+
rgb(from var(--v2-red-600) r g b / 0.05),
|
|
63
|
+
rgb(from var(--v2-red-600) r g b / 0.1)
|
|
64
|
+
);
|
|
65
|
+
--diffs-bg-deletion-number-override: var(--diffs-bg-deletion-override);
|
|
66
|
+
--diffs-bg-addition-override: var(
|
|
67
|
+
--opencode-diffs-addition-bg,
|
|
68
|
+
light-dark(rgb(from var(--v2-green-600) r g b / 0.05), rgb(from var(--v2-green-800) r g b / 0.1))
|
|
69
|
+
);
|
|
70
|
+
--diffs-bg-addition-number-override: var(--diffs-bg-addition-override);
|
|
71
|
+
--diffs-selection-base: var(--v2-background-bg-accent);
|
|
72
|
+
--diffs-selection-number-fg: var(--v2-text-text-accent);
|
|
73
|
+
--diffs-comment-bg: rgb(from var(--v2-background-bg-accent) r g b / 0.06);
|
|
74
|
+
/* Use explicit alpha instead of color-mix(..., transparent) to avoid Safari's non-premultiplied interpolation bugs. */
|
|
75
|
+
--diffs-bg-selection: var(--diffs-bg-selection-override, rgb(from var(--diffs-selection-base) r g b / 0.2));
|
|
76
|
+
--diffs-bg-selection-number: var(--diffs-bg-selection-number-override, var(--diffs-bg-selection));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Each diff token is an element, so highlight rules match one ancestor where Blink inherits them; see quote-highlight.css. */
|
|
80
|
+
@supports selector(:host-context(*)) {
|
|
81
|
+
[data-diff]::selection,
|
|
82
|
+
[data-file]::selection {
|
|
83
|
+
background-color: var(--timeline-quote-background);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
:host::highlight(opencode-find) {
|
|
87
|
+
background-color: rgb(from var(--surface-warning-base) r g b / 0.35);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
[data-diff]::highlight(timeline-quote-source),
|
|
91
|
+
[data-file]::highlight(timeline-quote-source),
|
|
92
|
+
[data-diff]::highlight(timeline-quote-source-active),
|
|
93
|
+
[data-file]::highlight(timeline-quote-source-active) {
|
|
94
|
+
background-color: var(--timeline-quote-background);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
:host::highlight(opencode-find-current) {
|
|
98
|
+
background-color: rgb(from var(--surface-warning-strong) r g b / 0.55);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@supports not selector(:host-context(*)) {
|
|
103
|
+
[data-diff] ::selection,
|
|
104
|
+
[data-file] ::selection {
|
|
105
|
+
background-color: var(--timeline-quote-background);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
::highlight(opencode-find) {
|
|
109
|
+
background-color: rgb(from var(--surface-warning-base) r g b / 0.35);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[data-diff] ::highlight(timeline-quote-source),
|
|
113
|
+
[data-file] ::highlight(timeline-quote-source),
|
|
114
|
+
[data-diff] ::highlight(timeline-quote-source-active),
|
|
115
|
+
[data-file] ::highlight(timeline-quote-source-active) {
|
|
116
|
+
background-color: var(--timeline-quote-background);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
::highlight(opencode-find-current) {
|
|
120
|
+
background-color: rgb(from var(--surface-warning-strong) r g b / 0.55);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
[data-indicators='bars'] [data-column-number][data-line-type='change-addition']::before,
|
|
125
|
+
[data-indicators='bars'] [data-column-number][data-line-type='change-deletion']::before {
|
|
126
|
+
width: 2px;
|
|
127
|
+
/* A page can quiet the change bars, as the Activity timeline does. */
|
|
128
|
+
opacity: var(--opencode-diffs-bar-opacity, 1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[data-indicators='bars'] [data-column-number][data-line-type='change-addition']::before {
|
|
132
|
+
background-color: var(--opencode-diffs-addition-color, light-dark(var(--v2-green-900), var(--v2-green-400)));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
[data-indicators='bars'] [data-column-number][data-line-type='change-deletion']::before {
|
|
136
|
+
background-image: none;
|
|
137
|
+
background-color: light-dark(var(--v2-red-800), var(--v2-red-500));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
[data-background] [data-column-number] {
|
|
141
|
+
--mix-light: 88%;
|
|
142
|
+
--mix-dark: 80%;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Changed-row overrides are final translucent fills, so Pierre must not blend them into the background again. */
|
|
146
|
+
[data-background]
|
|
147
|
+
:is([data-line], [data-no-newline], [data-column-number], [data-gutter-buffer]):is(
|
|
148
|
+
[data-line-type='change-addition'],
|
|
149
|
+
[data-line-type='change-deletion']
|
|
150
|
+
) {
|
|
151
|
+
--mix-light: 0%;
|
|
152
|
+
--mix-dark: 0%;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* A host can set --opencode-diffs-fg to tint plain text lines (such as error output) across all browsers. */
|
|
156
|
+
[data-file] [data-line] span {
|
|
157
|
+
color: var(--opencode-diffs-fg, light-dark(var(--diffs-token-light, var(--diffs-light)), var(--diffs-token-dark, var(--diffs-dark))));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Syntax colors are inline styles on token spans, so emphasized text needs !important to stay legible on its highlight. */
|
|
161
|
+
[data-line-type='change-addition'] [data-diff-span],
|
|
162
|
+
[data-line-type='change-addition'] [data-diff-span] * {
|
|
163
|
+
color: light-dark(var(--v2-green-1200), var(--v2-text-text-base)) !important;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
[data-line-type='change-deletion'] [data-diff-span],
|
|
167
|
+
[data-line-type='change-deletion'] [data-diff-span] * {
|
|
168
|
+
color: light-dark(var(--v2-red-1200), var(--v2-text-text-base)) !important;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
:is([data-separator-content], [data-expand-button]) {
|
|
172
|
+
color: var(--v2-text-text-faint);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
[data-expand-button]:hover {
|
|
176
|
+
color: var(--diffs-fg);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
[data-diff-type='split'] [data-additions],
|
|
180
|
+
[data-diff-type='split'] [data-additions] [data-gutter],
|
|
181
|
+
[data-diff-type='split'] [data-deletions],
|
|
182
|
+
[data-diff-type='split'] [data-deletions] [data-content] {
|
|
183
|
+
border-left: 0;
|
|
184
|
+
border-right: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
[data-content-buffer] {
|
|
188
|
+
background-image: none;
|
|
189
|
+
background-color: var(--diffs-bg-context-gutter);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
[data-diff] [data-line][data-comment-selected]:not([data-selected-line]) {
|
|
193
|
+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
[data-file] [data-line][data-comment-selected]:not([data-selected-line]) {
|
|
197
|
+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
[data-diff] [data-column-number][data-comment-selected]:not([data-selected-line]) {
|
|
201
|
+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection-number);
|
|
202
|
+
color: var(--diffs-selection-number-fg);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
[data-file] [data-column-number][data-comment-selected]:not([data-selected-line]) {
|
|
206
|
+
box-shadow: inset 0 0 0 9999px var(--diffs-bg-selection-number);
|
|
207
|
+
color: var(--diffs-selection-number-fg);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
[data-diff] [data-line-annotation],
|
|
211
|
+
[data-diff] [data-gutter-buffer='annotation'],
|
|
212
|
+
[data-file] [data-line-annotation],
|
|
213
|
+
[data-file] [data-gutter-buffer='annotation'] {
|
|
214
|
+
--diffs-annotation-bg: var(--diffs-comment-bg);
|
|
215
|
+
--diffs-computed-decoration-bg: var(--diffs-comment-bg);
|
|
216
|
+
--diffs-computed-diff-line-bg: var(--diffs-comment-bg);
|
|
217
|
+
--diffs-computed-selected-line-bg: var(--diffs-comment-bg);
|
|
218
|
+
--diffs-line-bg: var(--diffs-comment-bg);
|
|
219
|
+
background-color: var(--diffs-comment-bg);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
[data-diff] [data-line][data-selected-line] {
|
|
223
|
+
background-color: var(--diffs-bg-selection);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
[data-file] [data-line][data-selected-line] {
|
|
227
|
+
background-color: var(--diffs-bg-selection);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
[data-diff] [data-column-number][data-selected-line] {
|
|
231
|
+
background-color: var(--diffs-bg-selection-number);
|
|
232
|
+
color: var(--diffs-selection-number-fg);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
[data-file] [data-column-number][data-selected-line] {
|
|
236
|
+
background-color: var(--diffs-bg-selection-number);
|
|
237
|
+
color: var(--diffs-selection-number-fg);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
[data-diff] [data-column-number][data-line-type='context'][data-selected-line],
|
|
241
|
+
[data-diff] [data-column-number][data-line-type='context-expanded'][data-selected-line],
|
|
242
|
+
[data-diff] [data-column-number][data-line-type='change-addition'][data-selected-line],
|
|
243
|
+
[data-diff] [data-column-number][data-line-type='change-deletion'][data-selected-line] {
|
|
244
|
+
color: var(--diffs-selection-number-fg);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@media (max-width: 767px) {
|
|
248
|
+
/* File annotations share the code column; reclaim the number gutter. Pierre only measures column widths for
|
|
249
|
+
scrolling files with annotations, so derive the gutter from the code grid width instead. */
|
|
250
|
+
[data-file][data-overflow='wrap'] [data-code] {
|
|
251
|
+
container-type: inline-size;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
[data-file][data-overflow='wrap'] [data-line-annotation] {
|
|
255
|
+
margin-inline-start: calc(100% - 100cqi);
|
|
256
|
+
z-index: 4;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@media (pointer: fine) {
|
|
261
|
+
[data-gutter-utility-slot] {
|
|
262
|
+
opacity: 0;
|
|
263
|
+
pointer-events: none;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
[data-column-number][data-hovered] [data-gutter-utility-slot],
|
|
267
|
+
[data-gutter-utility-slot]:focus-within {
|
|
268
|
+
opacity: 1;
|
|
269
|
+
pointer-events: auto;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* The deletion word-diff emphasis is stronger than additions; soften it while selected so the selection highlight reads consistently. */
|
|
274
|
+
[data-diff] [data-line][data-line-type='change-deletion'][data-selected-line] {
|
|
275
|
+
--diffs-bg-deletion-emphasis: light-dark(
|
|
276
|
+
rgb(from var(--diffs-deletion-base) r g b / 0.07),
|
|
277
|
+
rgb(from var(--diffs-deletion-base) r g b / 0.1)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/* Pierre insets line numbers by 2ch to leave room for diff change bars; compact file viewers can tighten it. */
|
|
282
|
+
[data-file]:not([data-disable-line-numbers]) :is([data-column-number], [data-gutter-buffer]) {
|
|
283
|
+
padding-left: var(--opencode-diffs-number-inset, 2ch);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
[data-diff-header],
|
|
287
|
+
[data-diff],
|
|
288
|
+
[data-file] {
|
|
289
|
+
[data-separator] {
|
|
290
|
+
height: 24px;
|
|
291
|
+
}
|
|
292
|
+
[data-column-number] {
|
|
293
|
+
cursor: default !important;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
&[data-interactive-line-numbers] [data-column-number] {
|
|
297
|
+
cursor: default !important;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
&[data-interactive-lines] [data-line] {
|
|
301
|
+
cursor: auto !important;
|
|
302
|
+
}
|
|
303
|
+
[data-code] {
|
|
304
|
+
overflow-x: auto !important;
|
|
305
|
+
overflow-y: clip !important;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
${lineCommentStyles}
|
|
310
|
+
${quoteHighlightStyles}
|
|
311
|
+
|
|
312
|
+
`
|
|
313
|
+
|
|
314
|
+
export function createDefaultOptions<T>(style: FileDiffOptions<T, undefined>["diffStyle"]) {
|
|
315
|
+
return {
|
|
316
|
+
...highlightOptions,
|
|
317
|
+
themeType: "system",
|
|
318
|
+
disableLineNumbers: false,
|
|
319
|
+
overflow: "wrap",
|
|
320
|
+
diffStyle: style ?? "unified",
|
|
321
|
+
diffIndicators: "bars",
|
|
322
|
+
lineHoverHighlight: "both",
|
|
323
|
+
disableBackground: false,
|
|
324
|
+
expansionLineCount: 20,
|
|
325
|
+
hunkSeparators: "line-info-basic",
|
|
326
|
+
lineDiffType: "word-line",
|
|
327
|
+
maxLineDiffLength: 1000,
|
|
328
|
+
maxLineLengthForHighlighting: 1000,
|
|
329
|
+
disableFileHeader: true,
|
|
330
|
+
unsafeCSS,
|
|
331
|
+
} as const
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export const styleVariables = {
|
|
335
|
+
"--diffs-font-family": "var(--font-family-mono)",
|
|
336
|
+
"--diffs-font-size": "var(--font-size-small)",
|
|
337
|
+
"--diffs-line-height": "24px",
|
|
338
|
+
"--diffs-tab-size": 2,
|
|
339
|
+
"--diffs-font-features": "var(--font-family-mono--font-feature-settings)",
|
|
340
|
+
"--diffs-header-font-family": "var(--font-family-sans)",
|
|
341
|
+
"--diffs-gap-block": 0,
|
|
342
|
+
"--diffs-gap-style": 0,
|
|
343
|
+
"--diffs-min-number-column-width": "3ch",
|
|
344
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { PresentationFileContent } from "../file-presentation"
|
|
2
|
+
|
|
3
|
+
export type MediaKind = "image" | "audio" | "svg"
|
|
4
|
+
|
|
5
|
+
const imageExtensions = new Set(["png", "jpg", "jpeg", "gif", "webp", "avif", "bmp", "ico", "tif", "tiff", "heic"])
|
|
6
|
+
|
|
7
|
+
const audioExtensions = new Set(["mp3", "wav", "ogg", "m4a", "aac", "flac", "opus"])
|
|
8
|
+
|
|
9
|
+
type MediaValue = unknown
|
|
10
|
+
|
|
11
|
+
function mediaRecord(value: unknown) {
|
|
12
|
+
if (!value || typeof value !== "object") return
|
|
13
|
+
|
|
14
|
+
return value as Partial<PresentationFileContent> & {
|
|
15
|
+
content?: unknown
|
|
16
|
+
encoding?: unknown
|
|
17
|
+
mimeType?: unknown
|
|
18
|
+
type?: unknown
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function normalizeMimeType(type: string | undefined) {
|
|
23
|
+
if (!type) return
|
|
24
|
+
const mime = type.split(";", 1)[0]?.trim().toLowerCase()
|
|
25
|
+
|
|
26
|
+
if (!mime) return
|
|
27
|
+
|
|
28
|
+
if (mime === "audio/x-aac") return "audio/aac"
|
|
29
|
+
|
|
30
|
+
if (mime === "audio/x-m4a") return "audio/mp4"
|
|
31
|
+
|
|
32
|
+
return mime
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function fileExtension(path: string | undefined) {
|
|
36
|
+
if (!path) return ""
|
|
37
|
+
const idx = path.lastIndexOf(".")
|
|
38
|
+
|
|
39
|
+
if (idx === -1) return ""
|
|
40
|
+
|
|
41
|
+
return path.slice(idx + 1).toLowerCase()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function mediaKindFromPath(path: string | undefined): MediaKind | undefined {
|
|
45
|
+
const ext = fileExtension(path)
|
|
46
|
+
|
|
47
|
+
if (ext === "svg") return "svg"
|
|
48
|
+
|
|
49
|
+
if (imageExtensions.has(ext)) return "image"
|
|
50
|
+
|
|
51
|
+
if (audioExtensions.has(ext)) return "audio"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isBinaryContent(value: MediaValue) {
|
|
55
|
+
return mediaRecord(value)?.type === "binary"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function validDataUrl(value: string, kind: MediaKind) {
|
|
59
|
+
if (kind === "svg") return value.startsWith("data:image/svg+xml") ? value : undefined
|
|
60
|
+
|
|
61
|
+
if (kind === "image") return value.startsWith("data:image/") ? value : undefined
|
|
62
|
+
|
|
63
|
+
if (value.startsWith("data:audio/x-aac;")) return value.replace("data:audio/x-aac;", "data:audio/aac;")
|
|
64
|
+
|
|
65
|
+
if (value.startsWith("data:audio/x-m4a;")) return value.replace("data:audio/x-m4a;", "data:audio/mp4;")
|
|
66
|
+
|
|
67
|
+
if (value.startsWith("data:audio/")) return value
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function dataUrlFromMediaValue(value: MediaValue, kind: MediaKind) {
|
|
71
|
+
if (!value) return
|
|
72
|
+
|
|
73
|
+
if (typeof value === "string") {
|
|
74
|
+
return validDataUrl(value, kind)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const record = mediaRecord(value)
|
|
78
|
+
|
|
79
|
+
if (!record) return
|
|
80
|
+
|
|
81
|
+
if (typeof record.content !== "string") return
|
|
82
|
+
|
|
83
|
+
const mime = normalizeMimeType(typeof record.mimeType === "string" ? record.mimeType : undefined)
|
|
84
|
+
|
|
85
|
+
if (!mime) return
|
|
86
|
+
|
|
87
|
+
if (kind === "svg") {
|
|
88
|
+
if (mime !== "image/svg+xml") return
|
|
89
|
+
|
|
90
|
+
if (record.encoding === "base64") return `data:image/svg+xml;base64,${record.content}`
|
|
91
|
+
|
|
92
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(record.content)}`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (kind === "image" && !mime.startsWith("image/")) return
|
|
96
|
+
|
|
97
|
+
if (kind === "audio" && !mime.startsWith("audio/")) return
|
|
98
|
+
|
|
99
|
+
if (record.encoding !== "base64") return
|
|
100
|
+
|
|
101
|
+
return `data:${mime};base64,${record.content}`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function decodeBase64Utf8(value: string) {
|
|
105
|
+
if (typeof atob !== "function") return
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const raw = atob(value)
|
|
109
|
+
const bytes = Uint8Array.from(raw, (x) => x.charCodeAt(0))
|
|
110
|
+
|
|
111
|
+
if (typeof TextDecoder === "function") return new TextDecoder().decode(bytes)
|
|
112
|
+
|
|
113
|
+
return raw
|
|
114
|
+
} catch {}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function svgTextFromValue(value: MediaValue) {
|
|
118
|
+
const record = mediaRecord(value)
|
|
119
|
+
|
|
120
|
+
if (!record) return
|
|
121
|
+
|
|
122
|
+
if (typeof record.content !== "string") return
|
|
123
|
+
|
|
124
|
+
const mime = normalizeMimeType(typeof record.mimeType === "string" ? record.mimeType : undefined)
|
|
125
|
+
|
|
126
|
+
if (mime !== "image/svg+xml") return
|
|
127
|
+
|
|
128
|
+
if (record.encoding === "base64") return decodeBase64Utf8(record.content)
|
|
129
|
+
|
|
130
|
+
return record.content
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function hasMediaValue(value: MediaValue) {
|
|
134
|
+
if (typeof value === "string") return value.length > 0
|
|
135
|
+
const record = mediaRecord(value)
|
|
136
|
+
|
|
137
|
+
if (!record) return false
|
|
138
|
+
|
|
139
|
+
return typeof record.content === "string" && record.content.length > 0
|
|
140
|
+
}
|