@snowui-design-system/components 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.
- package/README.md +82 -0
- package/package.json +47 -0
- package/src/App.svelte +103 -0
- package/src/components/Avatar.md +452 -0
- package/src/components/Avatar.svelte +593 -0
- package/src/components/Avatar.test.ts +231 -0
- package/src/components/AvatarGroup.md +246 -0
- package/src/components/AvatarGroup.svelte +691 -0
- package/src/components/AvatarGroup.test.ts +142 -0
- package/src/components/Badge.md +164 -0
- package/src/components/Badge.svelte +461 -0
- package/src/components/Badge.test.ts +293 -0
- package/src/components/Button.md +312 -0
- package/src/components/Button.svelte +796 -0
- package/src/components/Button.test.ts +631 -0
- package/src/components/Checkbox.md +313 -0
- package/src/components/Checkbox.svelte +466 -0
- package/src/components/Checkbox.test.ts +57 -0
- package/src/components/CodeBlock.md +240 -0
- package/src/components/CodeBlock.svelte +1287 -0
- package/src/components/CodeBlock.test.ts +192 -0
- package/src/components/Form.md +33 -0
- package/src/components/Form.test.ts +307 -0
- package/src/components/Frame.svelte +220 -0
- package/src/components/Icon.md +279 -0
- package/src/components/Icon.svelte +505 -0
- package/src/components/Icon.test.ts +82 -0
- package/src/components/Image.md +292 -0
- package/src/components/Image.svelte +634 -0
- package/src/components/Image.test.ts +42 -0
- package/src/components/ImageGroup.md +168 -0
- package/src/components/ImageGroup.svelte +151 -0
- package/src/components/ImageGroup.test.ts +46 -0
- package/src/components/InView.test.ts +55 -0
- package/src/components/Input.md +666 -0
- package/src/components/Input.svelte +2741 -0
- package/src/components/Input.test.ts +503 -0
- package/src/components/Kbd.md +100 -0
- package/src/components/Kbd.svelte +110 -0
- package/src/components/Kbd.test.ts +50 -0
- package/src/components/Listbox.md +245 -0
- package/src/components/Listbox.svelte +389 -0
- package/src/components/Listbox.test.ts +139 -0
- package/src/components/MenuItem.md +184 -0
- package/src/components/MenuItem.svelte +326 -0
- package/src/components/MenuItem.test.ts +167 -0
- package/src/components/Morph.test.ts +53 -0
- package/src/components/Popover.md +87 -0
- package/src/components/Popover.svelte +186 -0
- package/src/components/Popover.test.ts +60 -0
- package/src/components/QuickAction.md +146 -0
- package/src/components/QuickAction.svelte +161 -0
- package/src/components/QuickAction.test.ts +299 -0
- package/src/components/Radio.md +318 -0
- package/src/components/Radio.svelte +502 -0
- package/src/components/Radio.test.ts +76 -0
- package/src/components/Select.md +492 -0
- package/src/components/Select.svelte +535 -0
- package/src/components/Select.test.ts +146 -0
- package/src/components/Skeleton.md +323 -0
- package/src/components/Skeleton.svelte +791 -0
- package/src/components/Skeleton.test.ts +121 -0
- package/src/components/Spinner.md +136 -0
- package/src/components/Spinner.svelte +296 -0
- package/src/components/Spinner.test.ts +88 -0
- package/src/components/SplitText.test.ts +142 -0
- package/src/components/Stagger.test.ts +57 -0
- package/src/components/Test.md +72 -0
- package/src/components/Test.svelte +106 -0
- package/src/components/Test.test.ts +27 -0
- package/src/components/Text.md +450 -0
- package/src/components/Text.svelte +507 -0
- package/src/components/Text.test.ts +150 -0
- package/src/components/Textarea.md +240 -0
- package/src/components/Textarea.svelte +742 -0
- package/src/components/Textarea.test.ts +131 -0
- package/src/components/Toggle.md +196 -0
- package/src/components/Toggle.svelte +384 -0
- package/src/components/Toggle.test.ts +57 -0
- package/src/components/Tooltip.md +164 -0
- package/src/components/Tooltip.svelte +417 -0
- package/src/components/Tooltip.test.ts +64 -0
- package/src/context.ts +312 -0
- package/src/dev.ts +10 -0
- package/src/index.ts +29 -0
- package/src/keys.ts +26 -0
- package/src/lib/search-filter.md +82 -0
- package/src/lib/search-filter.ts +57 -0
- package/src/lib/truncate.md +25 -0
- package/src/lib/truncate.ts +234 -0
- package/src/logic/README.md +146 -0
- package/src/logic/collapse.svelte.ts +6 -0
- package/src/logic/frame-dom-runtime.md +19 -0
- package/src/logic/frame-dom-runtime.svelte.ts +286 -0
- package/src/logic/frame-field-control.md +38 -0
- package/src/logic/frame-field-control.ts +95 -0
- package/src/logic/frame-identity.md +68 -0
- package/src/logic/frame-identity.svelte.ts +25 -0
- package/src/logic/frame-layout.md +91 -0
- package/src/logic/frame-layout.svelte.ts +111 -0
- package/src/logic/frame-motion-defaults.md +180 -0
- package/src/logic/frame-motion-defaults.ts +711 -0
- package/src/logic/frame-profile.md +156 -0
- package/src/logic/frame-profile.ts +130 -0
- package/src/logic/frame-prop-filter.md +34 -0
- package/src/logic/frame-prop-filter.ts +254 -0
- package/src/logic/frame-responsive.md +91 -0
- package/src/logic/frame-responsive.svelte.ts +92 -0
- package/src/logic/frame-skeleton-runtime.md +20 -0
- package/src/logic/frame-skeleton-runtime.svelte.ts +160 -0
- package/src/logic/frame-truncation.md +127 -0
- package/src/logic/frame-truncation.svelte.ts +193 -0
- package/src/logic/frame-types.md +157 -0
- package/src/logic/frame-types.ts +434 -0
- package/src/logic/frame-utils.md +22 -0
- package/src/logic/frame-utils.ts +250 -0
- package/src/logic/geometry-cache.ts +120 -0
- package/src/logic/image-preview.md +24 -0
- package/src/logic/image-preview.ts +186 -0
- package/src/logic/layout-flip.ts +109 -0
- package/src/logic/motion-config.ts +102 -0
- package/src/logic/motion-types.md +47 -0
- package/src/logic/motion-types.ts +119 -0
- package/src/logic/observer.md +20 -0
- package/src/logic/observer.svelte.ts +53 -0
- package/src/logic/responsive.md +64 -0
- package/src/logic/responsive.svelte.ts +118 -0
- package/src/logic/text-collapse.md +22 -0
- package/src/logic/text-collapse.svelte.ts +507 -0
- package/src/logic/wc-adapter.ts +188 -0
- package/src/motion/NumberFlow.md +16 -0
- package/src/motion/README.md +87 -0
- package/src/motion/defaults/bridge.md +53 -0
- package/src/motion/defaults/bridge.ts +171 -0
- package/src/motion/defaults/content-crossfade.ts +22 -0
- package/src/motion/defaults/expand.md +66 -0
- package/src/motion/defaults/expand.ts +22 -0
- package/src/motion/defaults/fade-out.md +41 -0
- package/src/motion/defaults/fade-out.ts +14 -0
- package/src/motion/defaults/morph.md +42 -0
- package/src/motion/defaults/morph.ts +14 -0
- package/src/motion/defaults/move.md +81 -0
- package/src/motion/defaults/move.ts +31 -0
- package/src/motion/defaults/number.md +41 -0
- package/src/motion/defaults/number.ts +17 -0
- package/src/motion/defaults/replace.md +56 -0
- package/src/motion/defaults/replace.ts +22 -0
- package/src/motion/defaults/rotate.css +15 -0
- package/src/motion/defaults/rotate.md +60 -0
- package/src/motion/defaults/rotate.ts +20 -0
- package/src/motion/defaults/while-2xl.ts +9 -0
- package/src/motion/defaults/while-active.ts +12 -0
- package/src/motion/defaults/while-appear.ts +12 -0
- package/src/motion/defaults/while-click.ts +9 -0
- package/src/motion/defaults/while-collapsed.ts +12 -0
- package/src/motion/defaults/while-disabled.ts +13 -0
- package/src/motion/defaults/while-disappear.ts +12 -0
- package/src/motion/defaults/while-drag.ts +9 -0
- package/src/motion/defaults/while-editing.ts +9 -0
- package/src/motion/defaults/while-expanded.ts +12 -0
- package/src/motion/defaults/while-focus.ts +9 -0
- package/src/motion/defaults/while-hover.ts +13 -0
- package/src/motion/defaults/while-idle.ts +9 -0
- package/src/motion/defaults/while-key.ts +9 -0
- package/src/motion/defaults/while-lg.ts +9 -0
- package/src/motion/defaults/while-load.ts +11 -0
- package/src/motion/defaults/while-md.ts +9 -0
- package/src/motion/defaults/while-reload.ts +12 -0
- package/src/motion/defaults/while-scroll.ts +9 -0
- package/src/motion/defaults/while-sm.ts +9 -0
- package/src/motion/defaults/while-uploading.ts +9 -0
- package/src/motion/defaults/while-validating.ts +9 -0
- package/src/motion/defaults/while-xl.ts +9 -0
- package/src/motion/defaults/while-xs.ts +9 -0
- package/src/styles/README.md +95 -0
- package/src/styles/auto-layout.css +111 -0
- package/src/styles/index.css +7 -0
- package/src/styles/layout.css +319 -0
- package/src/styles/scale.css +106 -0
- package/src/styles/scale.md +218 -0
- package/src/styles/scrollbar.css +173 -0
- package/src/styles/tokens.css +192 -0
- package/src/vite-env.d.ts +9 -0
- package/src//344/273/243/347/240/201.txt +61 -0
|
@@ -0,0 +1,1287 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
CodeBlock 组件:代码块显示,支持行号、复制、全屏放大
|
|
3
|
+
v1.4.3
|
|
4
|
+
|
|
5
|
+
布局模型:复合管理布局(固定工具栏 + 可滚动代码区 + 全屏覆盖层)
|
|
6
|
+
|
|
7
|
+
Frame 能力接入:
|
|
8
|
+
- 根层:profile="Container",enableDefaultMotion=true
|
|
9
|
+
- 复制按钮:Frame stateContent 驱动 Copy ↔ Check 图标交叉淡化(内置 150ms crossfade)
|
|
10
|
+
- 图标切换:whileAppear={true} 触发 Frame 默认出现动效(opacity+scale,300ms easeOut)
|
|
11
|
+
- 全屏覆盖层:layoutId + Frame controller 共享元素 FLIP 布局转场
|
|
12
|
+
进入:captureLayout 记录卡片位置,全屏层挂载后 FLIP 从卡片位置放大到全屏
|
|
13
|
+
退出:playLayoutTo 将全屏层从全屏位置缩回卡片位置后卸载
|
|
14
|
+
|
|
15
|
+
外置 Icon 替换(ComponentGuidelines §2.7.1):
|
|
16
|
+
- as="trailing" / data-as="trailing" 替换默认右侧动作区
|
|
17
|
+
- data-as="copy-icon" / "copied-icon" / "expand-icon" / "collapse-icon" 保留为精确图标替换兼容入口
|
|
18
|
+
|
|
19
|
+
文档: ./CodeBlock.md
|
|
20
|
+
-->
|
|
21
|
+
|
|
22
|
+
<script module lang="ts">
|
|
23
|
+
let codeBlockInstanceSeed = 0;
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import Frame, { type FrameProps } from "./Frame.svelte";
|
|
28
|
+
import { RoundedCorner } from "@snowui-design-system/resource-svelte";
|
|
29
|
+
import { resizeManager } from "../logic/observer.svelte";
|
|
30
|
+
import { useOverlayScrollbar } from "../lib/overlay-scrollbar.svelte";
|
|
31
|
+
import { captureFlipRect, applyFlipExit } from "../logic/layout-flip";
|
|
32
|
+
import type { Snippet } from "svelte";
|
|
33
|
+
|
|
34
|
+
/* ─── SVG 路径常量(内置 Icon,来自 resource-svelte,regular weight,viewBox 0 0 32 32) ─── */
|
|
35
|
+
const ICON_COPY = `<path fill="currentColor" d="M27 4H11a1 1 0 0 0-1 1v5H5a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1v-5h5a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1m-7 22H6V12h14zm6-6h-4v-9a1 1 0 0 0-1-1h-9V6h14z"/>`;
|
|
36
|
+
const ICON_CHECK = `<path fill="currentColor" d="m28.708 9.708-16 16a1 1 0 0 1-1.415 0l-7-7a1 1 0 0 1 1.415-1.415L12 23.586 27.293 8.293a1 1 0 1 1 1.415 1.415"/>`;
|
|
37
|
+
const ICON_ARROWS_OUT = `<path fill="currentColor" d="M27 6v6a1 1 0 0 1-2 0V8.414l-6.292 6.294a1 1 0 1 1-1.415-1.415L23.586 7H20a1 1 0 1 1 0-2h6a1 1 0 0 1 1 1M13.293 17.293 7 23.586V20a1 1 0 1 0-2 0v6a1 1 0 0 0 1 1h6a1 1 0 0 0 0-2H8.414l6.294-6.292a1 1 0 1 0-1.415-1.415"/>`;
|
|
38
|
+
const ICON_ARROWS_IN = `<path fill="currentColor" d="M26.708 6.708 20.414 13H24a1 1 0 1 1 0 2h-6a1 1 0 0 1-1-1V8a1 1 0 1 1 2 0v3.586l6.293-6.293a1 1 0 1 1 1.415 1.415M14 17H8a1 1 0 1 0 0 2h3.586l-6.293 6.293a1 1 0 1 0 1.415 1.415L13 20.414V24a1 1 0 1 0 2 0v-6a1 1 0 0 0-1-1"/>`;
|
|
39
|
+
|
|
40
|
+
type CodeTokenKind =
|
|
41
|
+
| "plain"
|
|
42
|
+
| "comment"
|
|
43
|
+
| "keyword"
|
|
44
|
+
| "function"
|
|
45
|
+
| "property"
|
|
46
|
+
| "string"
|
|
47
|
+
| "variable";
|
|
48
|
+
|
|
49
|
+
interface CodeToken {
|
|
50
|
+
text: string;
|
|
51
|
+
kind: CodeTokenKind;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const KEYWORDS = new Set([
|
|
55
|
+
"as",
|
|
56
|
+
"async",
|
|
57
|
+
"await",
|
|
58
|
+
"break",
|
|
59
|
+
"case",
|
|
60
|
+
"catch",
|
|
61
|
+
"class",
|
|
62
|
+
"const",
|
|
63
|
+
"continue",
|
|
64
|
+
"default",
|
|
65
|
+
"delete",
|
|
66
|
+
"do",
|
|
67
|
+
"else",
|
|
68
|
+
"export",
|
|
69
|
+
"extends",
|
|
70
|
+
"false",
|
|
71
|
+
"finally",
|
|
72
|
+
"for",
|
|
73
|
+
"from",
|
|
74
|
+
"function",
|
|
75
|
+
"if",
|
|
76
|
+
"import",
|
|
77
|
+
"in",
|
|
78
|
+
"instanceof",
|
|
79
|
+
"let",
|
|
80
|
+
"new",
|
|
81
|
+
"null",
|
|
82
|
+
"of",
|
|
83
|
+
"return",
|
|
84
|
+
"static",
|
|
85
|
+
"switch",
|
|
86
|
+
"this",
|
|
87
|
+
"throw",
|
|
88
|
+
"true",
|
|
89
|
+
"try",
|
|
90
|
+
"typeof",
|
|
91
|
+
"undefined",
|
|
92
|
+
"var",
|
|
93
|
+
"void",
|
|
94
|
+
"while",
|
|
95
|
+
"with",
|
|
96
|
+
"yield",
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const BUILTIN_OBJECTS = new Set([
|
|
100
|
+
"Array",
|
|
101
|
+
"Boolean",
|
|
102
|
+
"Date",
|
|
103
|
+
"JSON",
|
|
104
|
+
"Map",
|
|
105
|
+
"Math",
|
|
106
|
+
"Number",
|
|
107
|
+
"Object",
|
|
108
|
+
"Promise",
|
|
109
|
+
"RegExp",
|
|
110
|
+
"Set",
|
|
111
|
+
"String",
|
|
112
|
+
"console",
|
|
113
|
+
"document",
|
|
114
|
+
"window",
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
interface Props extends Partial<FrameProps> {
|
|
118
|
+
/** 要显示的代码字符串 */
|
|
119
|
+
code?: string;
|
|
120
|
+
/** 语言标识,显示在工具栏 */
|
|
121
|
+
language?: string;
|
|
122
|
+
/** 是否显示语言标识 */
|
|
123
|
+
showLanguage?: boolean;
|
|
124
|
+
/** 是否显示行号(全屏模式下强制显示) */
|
|
125
|
+
showLineNumbers?: boolean;
|
|
126
|
+
/** 是否显示复制按钮 */
|
|
127
|
+
showCopyButton?: boolean;
|
|
128
|
+
/** 是否显示全屏放大按钮 */
|
|
129
|
+
showExpandButton?: boolean;
|
|
130
|
+
/** 默认状态最多显示几行代码,内容不足时自适应高度 */
|
|
131
|
+
visibleLines?: number;
|
|
132
|
+
/** 复制成功图标的停留时长(ms) */
|
|
133
|
+
copyTimeout?: number;
|
|
134
|
+
children?: Snippet;
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let {
|
|
139
|
+
code = "",
|
|
140
|
+
language = "",
|
|
141
|
+
showLanguage = true,
|
|
142
|
+
showLineNumbers = false,
|
|
143
|
+
showCopyButton = true,
|
|
144
|
+
showExpandButton = true,
|
|
145
|
+
visibleLines = 5,
|
|
146
|
+
copyTimeout = 2000,
|
|
147
|
+
class: className = "",
|
|
148
|
+
style: userStyle = "",
|
|
149
|
+
children,
|
|
150
|
+
enableResponsive = false,
|
|
151
|
+
enableContext = false,
|
|
152
|
+
enableScaleObserver = false,
|
|
153
|
+
...rest
|
|
154
|
+
}: Props = $props();
|
|
155
|
+
/* ─── 内部状态 ─── */
|
|
156
|
+
const fullscreenMotionId = `code-block-fullscreen-${++codeBlockInstanceSeed}`;
|
|
157
|
+
let isFullscreen = $state(false);
|
|
158
|
+
let isExitingFullscreen = $state(false);
|
|
159
|
+
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
|
160
|
+
/** 全屏层 DOM 元素,用于 FLIP 退出动效 */
|
|
161
|
+
let fullscreenElement: HTMLElement | undefined = $state(undefined);
|
|
162
|
+
let codeViewportElement: HTMLElement | undefined = $state(undefined);
|
|
163
|
+
let codeScrollbarElement: HTMLElement | undefined = $state(undefined);
|
|
164
|
+
let fullscreenViewportElement: HTMLElement | undefined = $state(undefined);
|
|
165
|
+
let fullscreenScrollbarElement: HTMLElement | undefined = $state(undefined);
|
|
166
|
+
let showTopFade = $state(false);
|
|
167
|
+
let showBottomFade = $state(false);
|
|
168
|
+
let showFullscreenTopFade = $state(false);
|
|
169
|
+
let showFullscreenBottomFade = $state(false);
|
|
170
|
+
let resizeHeight: number | undefined = $state(undefined);
|
|
171
|
+
|
|
172
|
+
/* ─── 外置 Icon 检测状态 ─── */
|
|
173
|
+
let hasCustomCopyIcon = $state(false);
|
|
174
|
+
let hasCustomCopiedIcon = $state(false);
|
|
175
|
+
let hasCustomExpandIcon = $state(false);
|
|
176
|
+
let hasCustomCollapseIcon = $state(false);
|
|
177
|
+
let hasCustomTrailing = $state(false);
|
|
178
|
+
let customCopyIconHtml = $state("");
|
|
179
|
+
let customCopiedIconHtml = $state("");
|
|
180
|
+
let customExpandIconHtml = $state("");
|
|
181
|
+
let customCollapseIconHtml = $state("");
|
|
182
|
+
let customTrailingHtml = $state("");
|
|
183
|
+
let childCode = $state("");
|
|
184
|
+
let hostElement: HTMLElement | undefined = $state(undefined);
|
|
185
|
+
|
|
186
|
+
/* ─── 计算属性 ─── */
|
|
187
|
+
const resolvedCode = $derived(code || childCode);
|
|
188
|
+
const lines = $derived(resolvedCode ? resolvedCode.split("\n") : []);
|
|
189
|
+
const resolvedShowLineNumbers = $derived(showLineNumbers || isFullscreen);
|
|
190
|
+
const resolvedVisibleLines = $derived(Math.max(1, visibleLines || 15));
|
|
191
|
+
const autoVisibleLines = $derived(
|
|
192
|
+
Math.min(Math.max(lines.length || 1, 1), resolvedVisibleLines),
|
|
193
|
+
);
|
|
194
|
+
const highlightedLines = $derived(lines.map(highlightLine));
|
|
195
|
+
const rootStyle = $derived(
|
|
196
|
+
[
|
|
197
|
+
`--snowui-code-block-visible-lines: ${autoVisibleLines};`,
|
|
198
|
+
resizeHeight !== undefined ? `height:${resizeHeight}px;` : "",
|
|
199
|
+
userStyle,
|
|
200
|
+
]
|
|
201
|
+
.filter(Boolean)
|
|
202
|
+
.join(" "),
|
|
203
|
+
);
|
|
204
|
+
const codeScrollbar = useOverlayScrollbar(
|
|
205
|
+
() => codeViewportElement,
|
|
206
|
+
() => codeScrollbarElement,
|
|
207
|
+
);
|
|
208
|
+
const fullscreenScrollbar = useOverlayScrollbar(
|
|
209
|
+
() => fullscreenViewportElement,
|
|
210
|
+
() => fullscreenScrollbarElement,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
function readIdentifier(value: string, start: number) {
|
|
214
|
+
const match = value.slice(start).match(/^[A-Za-z_$][A-Za-z0-9_$-]*/);
|
|
215
|
+
return match?.[0] ?? "";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function readNumber(value: string, start: number) {
|
|
219
|
+
const match = value.slice(start).match(/^\d+(?:\.\d+)?/);
|
|
220
|
+
return match?.[0] ?? "";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function readString(value: string, start: number) {
|
|
224
|
+
const quote = value[start];
|
|
225
|
+
let cursor = start + 1;
|
|
226
|
+
while (cursor < value.length) {
|
|
227
|
+
if (value[cursor] === "\\") {
|
|
228
|
+
cursor += 2;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (value[cursor] === quote) {
|
|
232
|
+
cursor += 1;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
cursor += 1;
|
|
236
|
+
}
|
|
237
|
+
return value.slice(start, cursor);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function nextNonSpace(value: string, start: number) {
|
|
241
|
+
let cursor = start;
|
|
242
|
+
while (cursor < value.length && /\s/.test(value[cursor])) cursor += 1;
|
|
243
|
+
return value[cursor] ?? "";
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function previousNonSpace(value: string, start: number) {
|
|
247
|
+
let cursor = start;
|
|
248
|
+
while (cursor >= 0 && /\s/.test(value[cursor])) cursor -= 1;
|
|
249
|
+
return value[cursor] ?? "";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function highlightLine(line: string): CodeToken[] {
|
|
253
|
+
const tokens: CodeToken[] = [];
|
|
254
|
+
let cursor = 0;
|
|
255
|
+
|
|
256
|
+
while (cursor < line.length) {
|
|
257
|
+
const current = line[cursor];
|
|
258
|
+
const rest = line.slice(cursor);
|
|
259
|
+
|
|
260
|
+
if (rest.startsWith("//")) {
|
|
261
|
+
tokens.push({ text: rest, kind: "comment" });
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (current === '"' || current === "'" || current === "`") {
|
|
266
|
+
const text = readString(line, cursor);
|
|
267
|
+
tokens.push({ text, kind: "string" });
|
|
268
|
+
cursor += text.length;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (/\d/.test(current)) {
|
|
273
|
+
const text = readNumber(line, cursor);
|
|
274
|
+
tokens.push({ text, kind: "keyword" });
|
|
275
|
+
cursor += text.length;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (/[A-Za-z_$]/.test(current)) {
|
|
280
|
+
const text = readIdentifier(line, cursor);
|
|
281
|
+
const before = previousNonSpace(line, cursor - 1);
|
|
282
|
+
const after = nextNonSpace(line, cursor + text.length);
|
|
283
|
+
let kind: CodeTokenKind = "variable";
|
|
284
|
+
|
|
285
|
+
if (KEYWORDS.has(text)) {
|
|
286
|
+
kind = "keyword";
|
|
287
|
+
} else if (before === ".") {
|
|
288
|
+
kind = "property";
|
|
289
|
+
} else if (after === "(" || BUILTIN_OBJECTS.has(text)) {
|
|
290
|
+
kind = "function";
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
tokens.push({ text, kind });
|
|
294
|
+
cursor += text.length;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
tokens.push({ text: current, kind: "plain" });
|
|
299
|
+
cursor += 1;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return tokens.length > 0 ? tokens : [{ text: " ", kind: "plain" }];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/* ─── 复制到剪贴板(Frame stateContent 驱动图标状态,此处只负责写剪贴板) ─── */
|
|
306
|
+
function handleCopy() {
|
|
307
|
+
const text = resolvedCode || "";
|
|
308
|
+
navigator.clipboard.writeText(text).catch(() => {});
|
|
309
|
+
clearTimeout(copyTimer);
|
|
310
|
+
/* copyTimeout 用于与 Frame whileActive duration 保持同步 */
|
|
311
|
+
copyTimer = setTimeout(() => {}, copyTimeout);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* ─── 全屏切换(FLIP 由 layout-flip.ts 工具函数驱动) ─── */
|
|
315
|
+
function enterFullscreen() {
|
|
316
|
+
/* captureFlipRect 将卡片位置写入模块级注册表;
|
|
317
|
+
全屏 Frame 挂载后其 layoutId 触发 Frame $effect 中的 beginFlipEnter,自动读取起点放大到全屏。 */
|
|
318
|
+
if (hostElement) captureFlipRect(fullscreenMotionId, hostElement);
|
|
319
|
+
isFullscreen = true;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function exitFullscreen() {
|
|
323
|
+
if (!isFullscreen || isExitingFullscreen) return;
|
|
324
|
+
if (!fullscreenElement || !hostElement) { isFullscreen = false; return; }
|
|
325
|
+
isExitingFullscreen = true;
|
|
326
|
+
const done = () => { isFullscreen = false; isExitingFullscreen = false; };
|
|
327
|
+
applyFlipExit(fullscreenElement, hostElement, { onComplete: done });
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function toggleFullscreen() {
|
|
331
|
+
if (isFullscreen) {
|
|
332
|
+
exitFullscreen();
|
|
333
|
+
} else {
|
|
334
|
+
enterFullscreen();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* ─── Esc 退出全屏 ─── */
|
|
339
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
340
|
+
if (event.key === "Escape" && isFullscreen) {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
exitFullscreen();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function refreshScrollState() {
|
|
347
|
+
codeScrollbar.refresh();
|
|
348
|
+
fullscreenScrollbar.refresh();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function updateScrollFade() {
|
|
352
|
+
if (codeViewportElement) {
|
|
353
|
+
const { scrollTop, clientHeight, scrollHeight } =
|
|
354
|
+
codeViewportElement;
|
|
355
|
+
showTopFade = scrollTop > 1;
|
|
356
|
+
showBottomFade = scrollTop + clientHeight < scrollHeight - 1;
|
|
357
|
+
}
|
|
358
|
+
if (fullscreenViewportElement) {
|
|
359
|
+
const { scrollTop, clientHeight, scrollHeight } =
|
|
360
|
+
fullscreenViewportElement;
|
|
361
|
+
showFullscreenTopFade = scrollTop > 1;
|
|
362
|
+
showFullscreenBottomFade =
|
|
363
|
+
scrollTop + clientHeight < scrollHeight - 1;
|
|
364
|
+
}
|
|
365
|
+
refreshScrollState();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function handleResizePointerDown(event: PointerEvent) {
|
|
369
|
+
event.preventDefault();
|
|
370
|
+
const iconEl = event.currentTarget as HTMLElement;
|
|
371
|
+
iconEl.setPointerCapture(event.pointerId);
|
|
372
|
+
const container = iconEl.closest(".snowui-code-block") as
|
|
373
|
+
| HTMLElement
|
|
374
|
+
| null;
|
|
375
|
+
if (!container) return;
|
|
376
|
+
const startY = event.clientY;
|
|
377
|
+
const startHeight = container.offsetHeight;
|
|
378
|
+
|
|
379
|
+
function onMove(e: PointerEvent) {
|
|
380
|
+
resizeHeight = Math.max(60, startHeight + e.clientY - startY);
|
|
381
|
+
updateScrollFade();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function onUp() {
|
|
385
|
+
iconEl.removeEventListener("pointermove", onMove);
|
|
386
|
+
iconEl.removeEventListener("pointerup", onUp);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
iconEl.addEventListener("pointermove", onMove);
|
|
390
|
+
iconEl.addEventListener("pointerup", onUp);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/* ─── 外置 Icon MutationObserver 检测(ComponentGuidelines §2.7.1) ─── */
|
|
394
|
+
$effect(() => {
|
|
395
|
+
if (!hostElement) return;
|
|
396
|
+
|
|
397
|
+
function detect() {
|
|
398
|
+
const copyIcon = hostElement!.querySelector(
|
|
399
|
+
'.snowui-code-block-accessories [data-as="copy-icon"]',
|
|
400
|
+
) as HTMLElement | null;
|
|
401
|
+
const copiedIcon = hostElement!.querySelector(
|
|
402
|
+
'.snowui-code-block-accessories [data-as="copied-icon"]',
|
|
403
|
+
) as HTMLElement | null;
|
|
404
|
+
const expandIcon = hostElement!.querySelector(
|
|
405
|
+
'.snowui-code-block-accessories [data-as="expand-icon"]',
|
|
406
|
+
) as HTMLElement | null;
|
|
407
|
+
const collapseIcon = hostElement!.querySelector(
|
|
408
|
+
'.snowui-code-block-accessories [data-as="collapse-icon"]',
|
|
409
|
+
) as HTMLElement | null;
|
|
410
|
+
const childPre = hostElement!.querySelector(
|
|
411
|
+
".snowui-code-block-accessories pre",
|
|
412
|
+
) as HTMLElement | null;
|
|
413
|
+
const trailing = hostElement!.querySelector(
|
|
414
|
+
'.snowui-code-block-accessories [data-as="trailing"], .snowui-code-block-accessories .snowui-role-trailing',
|
|
415
|
+
) as HTMLElement | null;
|
|
416
|
+
const contentSource = hostElement!.querySelector(
|
|
417
|
+
".snowui-code-block-accessories",
|
|
418
|
+
) as HTMLElement | null;
|
|
419
|
+
const contentClone = contentSource?.cloneNode(true) as
|
|
420
|
+
| HTMLElement
|
|
421
|
+
| undefined;
|
|
422
|
+
contentClone
|
|
423
|
+
?.querySelectorAll(
|
|
424
|
+
"[data-as], .snowui-role-leading, .snowui-role-trailing",
|
|
425
|
+
)
|
|
426
|
+
.forEach((node) => node.remove());
|
|
427
|
+
|
|
428
|
+
hasCustomCopyIcon = !!copyIcon;
|
|
429
|
+
hasCustomCopiedIcon = !!copiedIcon;
|
|
430
|
+
hasCustomExpandIcon = !!expandIcon;
|
|
431
|
+
hasCustomCollapseIcon = !!collapseIcon;
|
|
432
|
+
hasCustomTrailing = !!trailing;
|
|
433
|
+
customCopyIconHtml = copyIcon?.innerHTML ?? "";
|
|
434
|
+
customCopiedIconHtml = copiedIcon?.innerHTML ?? "";
|
|
435
|
+
customExpandIconHtml = expandIcon?.innerHTML ?? "";
|
|
436
|
+
customCollapseIconHtml = collapseIcon?.innerHTML ?? "";
|
|
437
|
+
customTrailingHtml = trailing?.innerHTML ?? "";
|
|
438
|
+
childCode =
|
|
439
|
+
childPre?.textContent ??
|
|
440
|
+
contentClone?.textContent?.trim() ??
|
|
441
|
+
"";
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
detect();
|
|
445
|
+
const observer = new MutationObserver(detect);
|
|
446
|
+
observer.observe(hostElement, { childList: true, subtree: true });
|
|
447
|
+
return () => observer.disconnect();
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
/* ─── 清理定时器 ─── */
|
|
451
|
+
$effect(() => {
|
|
452
|
+
return () => clearTimeout(copyTimer);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
$effect(() => {
|
|
456
|
+
highlightedLines;
|
|
457
|
+
updateScrollFade();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
$effect(() => {
|
|
461
|
+
const el = codeViewportElement;
|
|
462
|
+
if (!el) return;
|
|
463
|
+
updateScrollFade();
|
|
464
|
+
el.addEventListener("scroll", updateScrollFade);
|
|
465
|
+
const unwatch = resizeManager.watch(el, updateScrollFade);
|
|
466
|
+
return () => {
|
|
467
|
+
el.removeEventListener("scroll", updateScrollFade);
|
|
468
|
+
unwatch();
|
|
469
|
+
};
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
$effect(() => {
|
|
473
|
+
const el = fullscreenViewportElement;
|
|
474
|
+
if (!el) return;
|
|
475
|
+
updateScrollFade();
|
|
476
|
+
el.addEventListener("scroll", updateScrollFade);
|
|
477
|
+
const unwatch = resizeManager.watch(el, updateScrollFade);
|
|
478
|
+
return () => {
|
|
479
|
+
el.removeEventListener("scroll", updateScrollFade);
|
|
480
|
+
unwatch();
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
</script>
|
|
484
|
+
|
|
485
|
+
<!-- stateContent Snippet:Idle → Copy 图标 -->
|
|
486
|
+
{#snippet copyIconSnippet()}
|
|
487
|
+
{#if hasCustomCopyIcon}
|
|
488
|
+
<span class="snowui-code-block-icon-custom" data-as="copy-icon"
|
|
489
|
+
>{@html customCopyIconHtml}</span
|
|
490
|
+
>
|
|
491
|
+
{:else}
|
|
492
|
+
<svg
|
|
493
|
+
class="snowui-code-block-icon-builtin"
|
|
494
|
+
data-as="copy-icon"
|
|
495
|
+
viewBox="0 0 32 32"
|
|
496
|
+
width="16"
|
|
497
|
+
height="16"
|
|
498
|
+
aria-hidden="true">{@html ICON_COPY}</svg
|
|
499
|
+
>
|
|
500
|
+
{/if}
|
|
501
|
+
{/snippet}
|
|
502
|
+
|
|
503
|
+
<!-- stateContent Snippet:Active → Check 图标 -->
|
|
504
|
+
{#snippet copiedIconSnippet()}
|
|
505
|
+
{#if hasCustomCopiedIcon}
|
|
506
|
+
<span class="snowui-code-block-icon-custom" data-as="copied-icon"
|
|
507
|
+
>{@html customCopiedIconHtml}</span
|
|
508
|
+
>
|
|
509
|
+
{:else}
|
|
510
|
+
<svg
|
|
511
|
+
class="snowui-code-block-icon-builtin"
|
|
512
|
+
data-as="copied-icon"
|
|
513
|
+
viewBox="0 0 32 32"
|
|
514
|
+
width="16"
|
|
515
|
+
height="16"
|
|
516
|
+
aria-hidden="true">{@html ICON_CHECK}</svg
|
|
517
|
+
>
|
|
518
|
+
{/if}
|
|
519
|
+
{/snippet}
|
|
520
|
+
|
|
521
|
+
<svelte:window onkeydown={handleKeydown} />
|
|
522
|
+
|
|
523
|
+
<!-- 根容器:bind:element 用于 MutationObserver 和 FLIP captureFlipRect 起点记录 -->
|
|
524
|
+
<Frame
|
|
525
|
+
profile="Container"
|
|
526
|
+
enableResponsive={enableResponsive}
|
|
527
|
+
enableContext={enableContext}
|
|
528
|
+
enableScaleObserver={enableScaleObserver}
|
|
529
|
+
enableDefaultMotion={true}
|
|
530
|
+
bind:element={hostElement}
|
|
531
|
+
class={["snowui-code-block", className].filter(Boolean).join(" ")}
|
|
532
|
+
data-resized={resizeHeight !== undefined ? "true" : undefined}
|
|
533
|
+
style={rootStyle}
|
|
534
|
+
renderHints={{
|
|
535
|
+
variant: "rect",
|
|
536
|
+
width: "100%",
|
|
537
|
+
height: "auto",
|
|
538
|
+
radius: "var(--radius-4)",
|
|
539
|
+
}}
|
|
540
|
+
{...rest}
|
|
541
|
+
>
|
|
542
|
+
<!-- 工具栏 -->
|
|
543
|
+
<div class="snowui-code-block-toolbar">
|
|
544
|
+
{#if showLanguage && language}
|
|
545
|
+
<span class="snowui-code-block-lang">{language}</span>
|
|
546
|
+
{/if}
|
|
547
|
+
|
|
548
|
+
<div class="snowui-code-block-actions">
|
|
549
|
+
{#if hasCustomTrailing}
|
|
550
|
+
<span
|
|
551
|
+
class="snowui-code-block-trailing-custom"
|
|
552
|
+
data-as="trailing">{@html customTrailingHtml}</span
|
|
553
|
+
>
|
|
554
|
+
{:else}
|
|
555
|
+
<!-- 复制按钮:Frame stateContent 驱动 Copy ↔ Check 交叉淡化 -->
|
|
556
|
+
{#if showCopyButton}
|
|
557
|
+
<Frame
|
|
558
|
+
tag="button"
|
|
559
|
+
profile="Surface"
|
|
560
|
+
enableResponsive={false}
|
|
561
|
+
enableContext={false}
|
|
562
|
+
enableScaleObserver={false}
|
|
563
|
+
Click="Active"
|
|
564
|
+
Active={["Idle", "auto"]}
|
|
565
|
+
whileActive={{ duration: copyTimeout, opacity: [1, 1] }}
|
|
566
|
+
stateContent={{
|
|
567
|
+
Idle: copyIconSnippet,
|
|
568
|
+
Active: copiedIconSnippet,
|
|
569
|
+
}}
|
|
570
|
+
class="snowui-code-block-btn"
|
|
571
|
+
aria-label="复制代码"
|
|
572
|
+
onclick={handleCopy}
|
|
573
|
+
/>
|
|
574
|
+
{/if}
|
|
575
|
+
|
|
576
|
+
<!-- 放大/缩小按钮 -->
|
|
577
|
+
{#if showExpandButton}
|
|
578
|
+
<button
|
|
579
|
+
class="snowui-code-block-btn"
|
|
580
|
+
aria-label={isFullscreen ? "退出全屏" : "全屏查看"}
|
|
581
|
+
onclick={toggleFullscreen}
|
|
582
|
+
>
|
|
583
|
+
{#if !isFullscreen}
|
|
584
|
+
<!-- ArrowsOutSimple:Frame whileAppear 提供进场动效 -->
|
|
585
|
+
<Frame
|
|
586
|
+
whileAppear={true}
|
|
587
|
+
profile="Container"
|
|
588
|
+
enableResponsive={false}
|
|
589
|
+
enableContext={false}
|
|
590
|
+
enableScaleObserver={false}
|
|
591
|
+
class="snowui-code-block-icon-frame"
|
|
592
|
+
>
|
|
593
|
+
{#if hasCustomExpandIcon}
|
|
594
|
+
<span
|
|
595
|
+
class="snowui-code-block-icon-custom"
|
|
596
|
+
data-as="expand-icon"
|
|
597
|
+
>{@html customExpandIconHtml}</span
|
|
598
|
+
>
|
|
599
|
+
{:else}
|
|
600
|
+
<svg
|
|
601
|
+
class="snowui-code-block-icon-builtin"
|
|
602
|
+
data-as="expand-icon"
|
|
603
|
+
viewBox="0 0 32 32"
|
|
604
|
+
width="16"
|
|
605
|
+
height="16"
|
|
606
|
+
aria-hidden="true"
|
|
607
|
+
>{@html ICON_ARROWS_OUT}</svg
|
|
608
|
+
>
|
|
609
|
+
{/if}
|
|
610
|
+
</Frame>
|
|
611
|
+
{:else}
|
|
612
|
+
<!-- ArrowsInSimple:Frame whileAppear 提供进场动效 -->
|
|
613
|
+
<Frame
|
|
614
|
+
whileAppear={true}
|
|
615
|
+
profile="Container"
|
|
616
|
+
enableResponsive={false}
|
|
617
|
+
enableContext={false}
|
|
618
|
+
enableScaleObserver={false}
|
|
619
|
+
class="snowui-code-block-icon-frame"
|
|
620
|
+
>
|
|
621
|
+
{#if hasCustomCollapseIcon}
|
|
622
|
+
<span
|
|
623
|
+
class="snowui-code-block-icon-custom"
|
|
624
|
+
data-as="collapse-icon"
|
|
625
|
+
>{@html customCollapseIconHtml}</span
|
|
626
|
+
>
|
|
627
|
+
{:else}
|
|
628
|
+
<svg
|
|
629
|
+
class="snowui-code-block-icon-builtin"
|
|
630
|
+
data-as="collapse-icon"
|
|
631
|
+
viewBox="0 0 32 32"
|
|
632
|
+
width="16"
|
|
633
|
+
height="16"
|
|
634
|
+
aria-hidden="true"
|
|
635
|
+
>{@html ICON_ARROWS_IN}</svg
|
|
636
|
+
>
|
|
637
|
+
{/if}
|
|
638
|
+
</Frame>
|
|
639
|
+
{/if}
|
|
640
|
+
</button>
|
|
641
|
+
{/if}
|
|
642
|
+
{/if}
|
|
643
|
+
</div>
|
|
644
|
+
</div>
|
|
645
|
+
|
|
646
|
+
{#if showTopFade}
|
|
647
|
+
<div class="snowui-code-block-fade-top" aria-hidden="true"></div>
|
|
648
|
+
{/if}
|
|
649
|
+
<!-- 代码区 -->
|
|
650
|
+
<div class="snowui-code-block-scroll-shell">
|
|
651
|
+
<div
|
|
652
|
+
bind:this={codeViewportElement}
|
|
653
|
+
class="snowui-code-block-body snowui-overlay-scrollbar-viewport"
|
|
654
|
+
>
|
|
655
|
+
{#if resolvedShowLineNumbers && lines.length > 0}
|
|
656
|
+
<div class="snowui-code-block-gutter" aria-hidden="true">
|
|
657
|
+
{#each lines as _, i}
|
|
658
|
+
<span class="snowui-code-block-line-number"
|
|
659
|
+
>{i + 1}</span
|
|
660
|
+
>
|
|
661
|
+
{/each}
|
|
662
|
+
</div>
|
|
663
|
+
{/if}
|
|
664
|
+
<div class="snowui-code-block-pre-wrap">
|
|
665
|
+
<pre class="snowui-code-block-pre"><code
|
|
666
|
+
class="snowui-code-block-code"
|
|
667
|
+
>{#each highlightedLines as line}<span
|
|
668
|
+
class="snowui-code-block-line"
|
|
669
|
+
>{#each line as token}<span
|
|
670
|
+
class={`snowui-code-block-token snowui-code-block-token-${token.kind}`}
|
|
671
|
+
>{token.text}</span
|
|
672
|
+
>{/each}</span
|
|
673
|
+
>{/each}</code
|
|
674
|
+
></pre>
|
|
675
|
+
</div>
|
|
676
|
+
</div>
|
|
677
|
+
</div>
|
|
678
|
+
<div
|
|
679
|
+
bind:this={codeScrollbarElement}
|
|
680
|
+
class="snowui-code-block-scrollbar snowui-overlay-scrollbar"
|
|
681
|
+
data-visible={codeScrollbar.hasOverflow ? "true" : undefined}
|
|
682
|
+
aria-hidden="true"
|
|
683
|
+
>
|
|
684
|
+
<div
|
|
685
|
+
class="snowui-overlay-scrollbar-thumb"
|
|
686
|
+
style="height: {codeScrollbar.thumbHeight}px; transform: translate3d(0, {codeScrollbar.thumbY}px, 0);"
|
|
687
|
+
></div>
|
|
688
|
+
</div>
|
|
689
|
+
{#if showBottomFade}
|
|
690
|
+
<div class="snowui-code-block-fade-bottom" aria-hidden="true"></div>
|
|
691
|
+
{/if}
|
|
692
|
+
<div class="snowui-code-block-footer">
|
|
693
|
+
<span
|
|
694
|
+
class="snowui-code-block-resize-icon"
|
|
695
|
+
aria-hidden="true"
|
|
696
|
+
onpointerdown={handleResizePointerDown}
|
|
697
|
+
>
|
|
698
|
+
<RoundedCorner size={16} />
|
|
699
|
+
</span>
|
|
700
|
+
</div>
|
|
701
|
+
{#if children}
|
|
702
|
+
<div class="snowui-code-block-accessories" aria-hidden="true">
|
|
703
|
+
{@render children()}
|
|
704
|
+
</div>
|
|
705
|
+
{/if}
|
|
706
|
+
</Frame>
|
|
707
|
+
|
|
708
|
+
<!-- 全屏覆盖层:layoutId 触发 Frame 内置 FLIP 进场;bind:element 用于 applyFlipExit 退出 -->
|
|
709
|
+
{#if isFullscreen || isExitingFullscreen}
|
|
710
|
+
<Frame
|
|
711
|
+
bind:element={fullscreenElement}
|
|
712
|
+
tag="div"
|
|
713
|
+
layoutId={fullscreenMotionId}
|
|
714
|
+
role="dialog"
|
|
715
|
+
aria-modal="true"
|
|
716
|
+
aria-label="全屏代码查看"
|
|
717
|
+
profile="Container"
|
|
718
|
+
enableResponsive={false}
|
|
719
|
+
enableContext={false}
|
|
720
|
+
enableScaleObserver={false}
|
|
721
|
+
class="snowui-code-block-fullscreen"
|
|
722
|
+
tabindex={-1}
|
|
723
|
+
>
|
|
724
|
+
<!-- 全屏工具栏 -->
|
|
725
|
+
<div
|
|
726
|
+
class="snowui-code-block-toolbar snowui-code-block-toolbar-fullscreen"
|
|
727
|
+
>
|
|
728
|
+
{#if showLanguage && language}
|
|
729
|
+
<span class="snowui-code-block-lang">{language}</span>
|
|
730
|
+
{/if}
|
|
731
|
+
<div class="snowui-code-block-actions">
|
|
732
|
+
{#if hasCustomTrailing}
|
|
733
|
+
<span
|
|
734
|
+
class="snowui-code-block-trailing-custom"
|
|
735
|
+
data-as="trailing">{@html customTrailingHtml}</span
|
|
736
|
+
>
|
|
737
|
+
{:else if showCopyButton}
|
|
738
|
+
<Frame
|
|
739
|
+
tag="button"
|
|
740
|
+
profile="Surface"
|
|
741
|
+
enableResponsive={false}
|
|
742
|
+
enableContext={false}
|
|
743
|
+
enableScaleObserver={false}
|
|
744
|
+
Click="Active"
|
|
745
|
+
Active={["Idle", "auto"]}
|
|
746
|
+
whileActive={{ duration: copyTimeout, opacity: [1, 1] }}
|
|
747
|
+
stateContent={{
|
|
748
|
+
Idle: copyIconSnippet,
|
|
749
|
+
Active: copiedIconSnippet,
|
|
750
|
+
}}
|
|
751
|
+
class="snowui-code-block-btn"
|
|
752
|
+
aria-label="复制代码"
|
|
753
|
+
onclick={handleCopy}
|
|
754
|
+
/>
|
|
755
|
+
{/if}
|
|
756
|
+
{#if showExpandButton}
|
|
757
|
+
<!-- 全屏内缩小按钮(直接显示 ArrowsInSimple,不需进场动效) -->
|
|
758
|
+
<button
|
|
759
|
+
class="snowui-code-block-btn"
|
|
760
|
+
aria-label="退出全屏"
|
|
761
|
+
onclick={exitFullscreen}
|
|
762
|
+
>
|
|
763
|
+
{#if hasCustomCollapseIcon}
|
|
764
|
+
<span
|
|
765
|
+
class="snowui-code-block-icon-custom"
|
|
766
|
+
data-as="collapse-icon"
|
|
767
|
+
>{@html customCollapseIconHtml}</span
|
|
768
|
+
>
|
|
769
|
+
{:else}
|
|
770
|
+
<svg
|
|
771
|
+
class="snowui-code-block-icon-builtin"
|
|
772
|
+
viewBox="0 0 32 32"
|
|
773
|
+
width="16"
|
|
774
|
+
height="16"
|
|
775
|
+
aria-hidden="true">{@html ICON_ARROWS_IN}</svg
|
|
776
|
+
>
|
|
777
|
+
{/if}
|
|
778
|
+
</button>
|
|
779
|
+
{/if}
|
|
780
|
+
</div>
|
|
781
|
+
</div>
|
|
782
|
+
|
|
783
|
+
<!-- 全屏代码区(强制行号) -->
|
|
784
|
+
{#if showFullscreenTopFade}
|
|
785
|
+
<div class="snowui-code-block-fade-top" aria-hidden="true"></div>
|
|
786
|
+
{/if}
|
|
787
|
+
<div
|
|
788
|
+
class="snowui-code-block-scroll-shell snowui-code-block-scroll-shell-fullscreen"
|
|
789
|
+
>
|
|
790
|
+
<div
|
|
791
|
+
bind:this={fullscreenViewportElement}
|
|
792
|
+
class="snowui-code-block-body snowui-code-block-body-fullscreen snowui-overlay-scrollbar-viewport"
|
|
793
|
+
>
|
|
794
|
+
{#if lines.length > 0}
|
|
795
|
+
<div class="snowui-code-block-gutter" aria-hidden="true">
|
|
796
|
+
{#each lines as _, i}
|
|
797
|
+
<span class="snowui-code-block-line-number"
|
|
798
|
+
>{i + 1}</span
|
|
799
|
+
>
|
|
800
|
+
{/each}
|
|
801
|
+
</div>
|
|
802
|
+
{/if}
|
|
803
|
+
<div class="snowui-code-block-pre-wrap">
|
|
804
|
+
<pre class="snowui-code-block-pre"><code
|
|
805
|
+
class="snowui-code-block-code"
|
|
806
|
+
>{#each highlightedLines as line}<span
|
|
807
|
+
class="snowui-code-block-line"
|
|
808
|
+
>{#each line as token}<span
|
|
809
|
+
class={`snowui-code-block-token snowui-code-block-token-${token.kind}`}
|
|
810
|
+
>{token.text}</span
|
|
811
|
+
>{/each}</span
|
|
812
|
+
>{/each}</code
|
|
813
|
+
></pre>
|
|
814
|
+
</div>
|
|
815
|
+
</div>
|
|
816
|
+
</div>
|
|
817
|
+
<div
|
|
818
|
+
bind:this={fullscreenScrollbarElement}
|
|
819
|
+
class="snowui-code-block-scrollbar snowui-overlay-scrollbar"
|
|
820
|
+
data-visible={fullscreenScrollbar.hasOverflow ? "true" : undefined}
|
|
821
|
+
aria-hidden="true"
|
|
822
|
+
>
|
|
823
|
+
<div
|
|
824
|
+
class="snowui-overlay-scrollbar-thumb"
|
|
825
|
+
style="height: {fullscreenScrollbar.thumbHeight}px; transform: translate3d(0, {fullscreenScrollbar.thumbY}px, 0);"
|
|
826
|
+
></div>
|
|
827
|
+
</div>
|
|
828
|
+
{#if showFullscreenBottomFade}
|
|
829
|
+
<div class="snowui-code-block-fade-bottom" aria-hidden="true"></div>
|
|
830
|
+
{/if}
|
|
831
|
+
</Frame>
|
|
832
|
+
{/if}
|
|
833
|
+
|
|
834
|
+
<style>
|
|
835
|
+
/* ─── Level 2:组件基类(降权 0,0,0) ─── */
|
|
836
|
+
:global(:where(.snowui-code-block)) {
|
|
837
|
+
--snowui-code-block-bg: var(--background-2, #f9f9fa);
|
|
838
|
+
--snowui-code-block-fg: var(--black-100, #000000ff);
|
|
839
|
+
--snowui-code-block-muted-fg: var(--black-40, #00000066);
|
|
840
|
+
--snowui-code-block-gutter-fg: var(--black-20, #00000033);
|
|
841
|
+
--snowui-code-block-btn-fg: var(--black-100, #000000ff);
|
|
842
|
+
--snowui-code-block-btn-opacity: var(--snowui-state-opacity, 0.4);
|
|
843
|
+
--snowui-code-block-keyword-fg: #ff32c6;
|
|
844
|
+
--snowui-code-block-function-fg: #ffac60;
|
|
845
|
+
--snowui-code-block-property-fg: #1ac69c;
|
|
846
|
+
--snowui-code-block-string-fg: #3fa4ff;
|
|
847
|
+
--snowui-code-block-variable-fg: #c478ff;
|
|
848
|
+
--snowui-code-block-radius: var(--radius-4);
|
|
849
|
+
--snowui-code-block-padding-x: var(--padding-5);
|
|
850
|
+
--snowui-code-block-padding-y: var(--padding-5);
|
|
851
|
+
--snowui-code-block-gap: var(--gap-1);
|
|
852
|
+
--snowui-code-block-code-gap: var(--gap-3);
|
|
853
|
+
--snowui-code-block-btn-size: var(--size-6);
|
|
854
|
+
--snowui-code-block-footer-height: var(--padding-3);
|
|
855
|
+
--snowui-code-block-font-size: var(--text-12);
|
|
856
|
+
--snowui-code-block-line-height: var(--leading-12);
|
|
857
|
+
--snowui-code-block-font-family: inherit;
|
|
858
|
+
--snowui-code-block-visible-lines: 5;
|
|
859
|
+
--snowui-code-block-content-height: calc(
|
|
860
|
+
var(--snowui-code-block-visible-lines) * 1lh
|
|
861
|
+
);
|
|
862
|
+
|
|
863
|
+
display: flex;
|
|
864
|
+
flex-direction: column;
|
|
865
|
+
gap: var(--gap-2);
|
|
866
|
+
background-color: var(
|
|
867
|
+
--snowui-code-block-bg-override,
|
|
868
|
+
var(--snowui-code-block-bg)
|
|
869
|
+
);
|
|
870
|
+
color: var(
|
|
871
|
+
--snowui-code-block-fg-override,
|
|
872
|
+
var(--snowui-code-block-fg)
|
|
873
|
+
);
|
|
874
|
+
border-radius: var(
|
|
875
|
+
--snowui-code-block-radius-override,
|
|
876
|
+
var(--snowui-code-block-radius)
|
|
877
|
+
);
|
|
878
|
+
padding: var(
|
|
879
|
+
--snowui-code-block-padding-override,
|
|
880
|
+
var(
|
|
881
|
+
--snowui-code-block-padding-y-override,
|
|
882
|
+
var(--snowui-code-block-padding-y)
|
|
883
|
+
)
|
|
884
|
+
var(
|
|
885
|
+
--snowui-code-block-padding-x-override,
|
|
886
|
+
var(--snowui-code-block-padding-x)
|
|
887
|
+
)
|
|
888
|
+
);
|
|
889
|
+
font-size: var(--snowui-code-block-font-size);
|
|
890
|
+
line-height: var(--snowui-code-block-line-height);
|
|
891
|
+
font-family: var(--snowui-code-block-font-family);
|
|
892
|
+
overflow: hidden;
|
|
893
|
+
position: relative;
|
|
894
|
+
width: 100%;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
:global(:where(.snowui-code-block-fullscreen)) {
|
|
898
|
+
--snowui-code-block-bg: var(--background-2, #f9f9fa);
|
|
899
|
+
--snowui-code-block-fg: var(--black-100, #000000ff);
|
|
900
|
+
--snowui-code-block-muted-fg: var(--black-40, #00000066);
|
|
901
|
+
--snowui-code-block-gutter-fg: var(--black-20, #00000033);
|
|
902
|
+
--snowui-code-block-btn-fg: var(--black-100, #000000ff);
|
|
903
|
+
--snowui-code-block-btn-opacity: var(--snowui-state-opacity, 0.4);
|
|
904
|
+
--snowui-code-block-radius: var(--radius-4);
|
|
905
|
+
--snowui-code-block-padding-x: var(--padding-5);
|
|
906
|
+
--snowui-code-block-padding-y: var(--padding-5);
|
|
907
|
+
--snowui-code-block-gap: var(--gap-1);
|
|
908
|
+
--snowui-code-block-code-gap: var(--gap-3);
|
|
909
|
+
--snowui-code-block-btn-size: var(--size-6);
|
|
910
|
+
--snowui-code-block-footer-height: var(--padding-3);
|
|
911
|
+
--snowui-code-block-font-size: var(--text-12);
|
|
912
|
+
--snowui-code-block-line-height: var(--leading-12);
|
|
913
|
+
--snowui-code-block-font-family: inherit;
|
|
914
|
+
--snowui-code-block-content-height: 5lh;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/* ─── 工具栏 ─── */
|
|
918
|
+
:global(:where(.snowui-code-block-toolbar)) {
|
|
919
|
+
display: flex;
|
|
920
|
+
align-items: center;
|
|
921
|
+
justify-content: space-between;
|
|
922
|
+
gap: var(--gap-2);
|
|
923
|
+
position: absolute;
|
|
924
|
+
top: var(--padding-2);
|
|
925
|
+
right: var(--padding-2);
|
|
926
|
+
z-index: 3;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
:global(:where(.snowui-code-block-lang)) {
|
|
930
|
+
color: var(--snowui-code-block-muted-fg);
|
|
931
|
+
user-select: none;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
:global(:where(.snowui-code-block-actions)) {
|
|
935
|
+
display: flex;
|
|
936
|
+
align-items: center;
|
|
937
|
+
gap: var(--gap-1);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/* ─── 图标按钮(ComponentGuidelines §2.7:直接 button,不用 Button 组件) ─── */
|
|
941
|
+
:global(:where(.snowui-code-block-btn)) {
|
|
942
|
+
--snowui-field-focus-ring-width: 0;
|
|
943
|
+
display: inline-flex;
|
|
944
|
+
align-items: center;
|
|
945
|
+
justify-content: center;
|
|
946
|
+
width: var(--snowui-code-block-btn-size);
|
|
947
|
+
height: var(--snowui-code-block-btn-size);
|
|
948
|
+
padding: var(--padding-1);
|
|
949
|
+
border: none;
|
|
950
|
+
outline: none;
|
|
951
|
+
background: transparent;
|
|
952
|
+
background-image: none;
|
|
953
|
+
box-shadow: none;
|
|
954
|
+
color: var(--snowui-code-block-btn-fg);
|
|
955
|
+
opacity: var(--snowui-code-block-btn-opacity);
|
|
956
|
+
cursor: pointer;
|
|
957
|
+
border-radius: var(--radius-3);
|
|
958
|
+
transition:
|
|
959
|
+
color var(--snowui-frame-color-motion-duration, 0.15s)
|
|
960
|
+
var(--snowui-frame-color-motion-easing, ease-out),
|
|
961
|
+
opacity var(--snowui-frame-color-motion-duration, 0.15s)
|
|
962
|
+
var(--snowui-frame-color-motion-easing, ease-out);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
:global(:where(.snowui-code-block-btn:focus, .snowui-code-block-btn:focus-visible)) {
|
|
966
|
+
outline: none;
|
|
967
|
+
box-shadow: none;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
:global(:where(.snowui-code-block-btn):hover:not(:disabled)) {
|
|
971
|
+
--snowui-code-block-btn-opacity: var(--snowui-state-opacity, 1);
|
|
972
|
+
background-image: none;
|
|
973
|
+
box-shadow: none;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/* ─── 放大/缩小按钮内 Icon Frame 包裹层 ─── */
|
|
977
|
+
:global(:where(.snowui-code-block-icon-frame)) {
|
|
978
|
+
display: inline-flex;
|
|
979
|
+
align-items: center;
|
|
980
|
+
justify-content: center;
|
|
981
|
+
width: var(--size-4);
|
|
982
|
+
height: var(--size-4);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
/* ─── 代码主体区域 ─── */
|
|
986
|
+
:global(:where(.snowui-code-block-scroll-shell)) {
|
|
987
|
+
position: relative;
|
|
988
|
+
height: var(
|
|
989
|
+
--snowui-code-block-content-height-override,
|
|
990
|
+
var(--snowui-code-block-content-height)
|
|
991
|
+
);
|
|
992
|
+
min-height: 0;
|
|
993
|
+
overflow: clip;
|
|
994
|
+
background: transparent;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
:global(:where(.snowui-code-block[data-resized="true"] .snowui-code-block-scroll-shell)) {
|
|
998
|
+
flex: 1 1 0;
|
|
999
|
+
height: auto;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
:global(:where(.snowui-code-block-body)) {
|
|
1003
|
+
display: flex;
|
|
1004
|
+
align-items: flex-start;
|
|
1005
|
+
gap: var(
|
|
1006
|
+
--snowui-code-block-code-gap-override,
|
|
1007
|
+
var(--snowui-code-block-code-gap)
|
|
1008
|
+
);
|
|
1009
|
+
flex: 1 1 0;
|
|
1010
|
+
height: 100%;
|
|
1011
|
+
overflow-x: auto;
|
|
1012
|
+
min-height: 0;
|
|
1013
|
+
background: transparent;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/* ─── 行号槽 ─── */
|
|
1017
|
+
:global(:where(.snowui-code-block-gutter)) {
|
|
1018
|
+
display: block;
|
|
1019
|
+
flex-shrink: 0;
|
|
1020
|
+
width: max-content;
|
|
1021
|
+
color: var(--snowui-code-block-gutter-fg);
|
|
1022
|
+
background: transparent;
|
|
1023
|
+
text-align: right;
|
|
1024
|
+
user-select: none;
|
|
1025
|
+
font: inherit;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
:global(:where(.snowui-code-block-line-number)) {
|
|
1029
|
+
display: block;
|
|
1030
|
+
line-height: inherit;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
:global(:where(.snowui-code-block-pre-wrap)) {
|
|
1034
|
+
flex: 1 1 0;
|
|
1035
|
+
min-width: 0;
|
|
1036
|
+
overflow: visible;
|
|
1037
|
+
background: transparent;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
:global(:where(.snowui-code-block-pre)) {
|
|
1041
|
+
margin: 0;
|
|
1042
|
+
tab-size: 4;
|
|
1043
|
+
white-space: pre;
|
|
1044
|
+
overflow: visible;
|
|
1045
|
+
background: transparent;
|
|
1046
|
+
font: inherit;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
:global(:where(.snowui-code-block-code)) {
|
|
1050
|
+
display: block;
|
|
1051
|
+
color: inherit;
|
|
1052
|
+
background: transparent;
|
|
1053
|
+
border-radius: 0;
|
|
1054
|
+
font: inherit;
|
|
1055
|
+
margin: 0;
|
|
1056
|
+
padding: 0;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
:global(:where(.snowui-code-block-line)) {
|
|
1060
|
+
display: block;
|
|
1061
|
+
line-height: inherit;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
:global(:where(.snowui-code-block-token-comment)) {
|
|
1065
|
+
color: var(--black-40, #00000066);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
:global(:where(.snowui-code-block-token-keyword)) {
|
|
1069
|
+
color: #ff32c6;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
:global(:where(.snowui-code-block-token-function)) {
|
|
1073
|
+
color: #ffac60;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
:global(:where(.snowui-code-block-token-property)) {
|
|
1077
|
+
color: #1ac69c;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
:global(:where(.snowui-code-block-token-string)) {
|
|
1081
|
+
color: #3fa4ff;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
:global(:where(.snowui-code-block-token-variable)) {
|
|
1085
|
+
color: #c478ff;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/* ─── 全屏覆盖层 ─── */
|
|
1089
|
+
:global(:where(.snowui-code-block-fullscreen)) {
|
|
1090
|
+
position: fixed;
|
|
1091
|
+
inset: 0;
|
|
1092
|
+
z-index: 9999;
|
|
1093
|
+
display: flex;
|
|
1094
|
+
flex-direction: column;
|
|
1095
|
+
font-size: var(--snowui-code-block-font-size);
|
|
1096
|
+
line-height: var(--snowui-code-block-line-height);
|
|
1097
|
+
font-family: var(--snowui-code-block-font-family);
|
|
1098
|
+
background-color: var(
|
|
1099
|
+
--snowui-code-block-bg-override,
|
|
1100
|
+
var(--snowui-code-block-bg)
|
|
1101
|
+
);
|
|
1102
|
+
color: var(
|
|
1103
|
+
--snowui-code-block-fg-override,
|
|
1104
|
+
var(--snowui-code-block-fg)
|
|
1105
|
+
);
|
|
1106
|
+
border-radius: 0;
|
|
1107
|
+
padding: var(
|
|
1108
|
+
--snowui-code-block-padding-override,
|
|
1109
|
+
var(
|
|
1110
|
+
--snowui-code-block-padding-y-override,
|
|
1111
|
+
var(--snowui-code-block-padding-y)
|
|
1112
|
+
)
|
|
1113
|
+
var(
|
|
1114
|
+
--snowui-code-block-padding-x-override,
|
|
1115
|
+
var(--snowui-code-block-padding-x)
|
|
1116
|
+
)
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/* 全屏工具栏与普通态保持一致:距上/右 8px。 */
|
|
1121
|
+
:global(:where(.snowui-code-block-toolbar-fullscreen)) {
|
|
1122
|
+
padding: 0;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
:global(:where(.snowui-code-block-body-fullscreen)) {
|
|
1126
|
+
padding-bottom: max(var(--padding-0), env(safe-area-inset-bottom));
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
:global(:where(.snowui-code-block-scroll-shell-fullscreen)) {
|
|
1130
|
+
flex: 1 1 0;
|
|
1131
|
+
height: auto;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/* 组件只声明轨道定位;视觉样式由 scrollbar.css 的 .snowui-overlay-scrollbar 承接。 */
|
|
1135
|
+
/* 滚动条提升到根容器(position:relative),绕开 scroll-shell 的 overflow:clip 裁切。 */
|
|
1136
|
+
/* top/bottom 对齐 scroll-shell 上下边缘(即容器 padding-y 处),right: 4px 贴近右边缘。 */
|
|
1137
|
+
:global(:where(.snowui-code-block-scrollbar)) {
|
|
1138
|
+
top: var(
|
|
1139
|
+
--snowui-code-block-padding-y-override,
|
|
1140
|
+
var(--snowui-code-block-padding-y)
|
|
1141
|
+
);
|
|
1142
|
+
right: 4px;
|
|
1143
|
+
bottom: var(--snowui-code-block-footer-height);
|
|
1144
|
+
z-index: 2;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
:global(:where(.snowui-code-block-footer)) {
|
|
1148
|
+
position: absolute;
|
|
1149
|
+
right: var(--padding-1);
|
|
1150
|
+
bottom: var(--padding-1);
|
|
1151
|
+
display: inline-flex;
|
|
1152
|
+
align-items: center;
|
|
1153
|
+
justify-content: flex-end;
|
|
1154
|
+
pointer-events: none;
|
|
1155
|
+
z-index: 3;
|
|
1156
|
+
color: var(--black-20, #00000033);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
:global(:where(.snowui-code-block-resize-icon)) {
|
|
1160
|
+
display: inline-flex;
|
|
1161
|
+
align-items: center;
|
|
1162
|
+
justify-content: center;
|
|
1163
|
+
width: var(--size-4);
|
|
1164
|
+
height: var(--size-4);
|
|
1165
|
+
color: var(--black-100, #000000ff);
|
|
1166
|
+
opacity: var(--snowui-state-opacity, 0.1);
|
|
1167
|
+
cursor: ns-resize;
|
|
1168
|
+
pointer-events: auto;
|
|
1169
|
+
flex: 0 0 auto;
|
|
1170
|
+
transition:
|
|
1171
|
+
color var(--snowui-frame-color-motion-duration, 0.15s)
|
|
1172
|
+
var(--snowui-frame-color-motion-easing, ease-out),
|
|
1173
|
+
opacity var(--snowui-frame-color-motion-duration, 0.15s)
|
|
1174
|
+
var(--snowui-frame-color-motion-easing, ease-out);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
:global(
|
|
1178
|
+
:where(
|
|
1179
|
+
.snowui-code-block-resize-icon:hover:not(
|
|
1180
|
+
[aria-disabled="true"]
|
|
1181
|
+
):not(.snowui-disabled)
|
|
1182
|
+
)
|
|
1183
|
+
) {
|
|
1184
|
+
opacity: var(--snowui-state-opacity, 1);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
:global(:where(.snowui-code-block-resize-icon svg)) {
|
|
1188
|
+
display: block;
|
|
1189
|
+
width: 100%;
|
|
1190
|
+
height: 100%;
|
|
1191
|
+
flex: 0 0 auto;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
:global(:where(.snowui-code-block-fade-top)),
|
|
1195
|
+
:global(:where(.snowui-code-block-fade-bottom)) {
|
|
1196
|
+
position: absolute;
|
|
1197
|
+
left: 0;
|
|
1198
|
+
right: 0;
|
|
1199
|
+
height: calc(var(--snowui-code-block-padding-y) + 20px);
|
|
1200
|
+
pointer-events: none;
|
|
1201
|
+
z-index: 1;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
:global(:where(.snowui-code-block-fade-top)) {
|
|
1205
|
+
top: 0;
|
|
1206
|
+
border-radius: calc(
|
|
1207
|
+
var(
|
|
1208
|
+
--snowui-code-block-radius-override,
|
|
1209
|
+
var(--snowui-code-block-radius)
|
|
1210
|
+
)
|
|
1211
|
+
)
|
|
1212
|
+
calc(
|
|
1213
|
+
var(
|
|
1214
|
+
--snowui-code-block-radius-override,
|
|
1215
|
+
var(--snowui-code-block-radius)
|
|
1216
|
+
)
|
|
1217
|
+
)
|
|
1218
|
+
0 0;
|
|
1219
|
+
background: linear-gradient(
|
|
1220
|
+
to bottom,
|
|
1221
|
+
var(
|
|
1222
|
+
--snowui-code-block-bg-override,
|
|
1223
|
+
var(--snowui-code-block-bg)
|
|
1224
|
+
)
|
|
1225
|
+
30%,
|
|
1226
|
+
transparent 100%
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
:global(:where(.snowui-code-block-fade-bottom)) {
|
|
1231
|
+
bottom: 0;
|
|
1232
|
+
border-radius: 0 0
|
|
1233
|
+
calc(
|
|
1234
|
+
var(
|
|
1235
|
+
--snowui-code-block-radius-override,
|
|
1236
|
+
var(--snowui-code-block-radius)
|
|
1237
|
+
)
|
|
1238
|
+
)
|
|
1239
|
+
calc(
|
|
1240
|
+
var(
|
|
1241
|
+
--snowui-code-block-radius-override,
|
|
1242
|
+
var(--snowui-code-block-radius)
|
|
1243
|
+
)
|
|
1244
|
+
);
|
|
1245
|
+
background: linear-gradient(
|
|
1246
|
+
to top,
|
|
1247
|
+
var(
|
|
1248
|
+
--snowui-code-block-bg-override,
|
|
1249
|
+
var(--snowui-code-block-bg)
|
|
1250
|
+
)
|
|
1251
|
+
30%,
|
|
1252
|
+
transparent 100%
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
:global(:where(.snowui-code-block-accessories)) {
|
|
1257
|
+
position: absolute;
|
|
1258
|
+
width: 0;
|
|
1259
|
+
height: 0;
|
|
1260
|
+
overflow: hidden;
|
|
1261
|
+
pointer-events: none;
|
|
1262
|
+
opacity: 0;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/* ─── 内置 SVG 图标基础样式 ─── */
|
|
1266
|
+
:global(:where(.snowui-code-block-icon-builtin)),
|
|
1267
|
+
:global(:where(.snowui-code-block-icon-custom)) {
|
|
1268
|
+
display: block;
|
|
1269
|
+
flex-shrink: 0;
|
|
1270
|
+
color: inherit;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
:global(:where(.snowui-code-block-icon-custom > *)) {
|
|
1274
|
+
display: block;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
:global(:where(.snowui-code-block-trailing-custom)) {
|
|
1278
|
+
display: inline-flex;
|
|
1279
|
+
align-items: center;
|
|
1280
|
+
justify-content: center;
|
|
1281
|
+
color: inherit;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
:global(:where(.snowui-code-block-trailing-custom > *)) {
|
|
1285
|
+
display: inline-flex;
|
|
1286
|
+
}
|
|
1287
|
+
</style>
|