fix(docs): restore pinned color demos and color values
This commit is contained in:
@@ -1,111 +1,372 @@
|
||||
<script setup lang="ts">
|
||||
// Adapted from HeroUI ce90ea3 apps/docs/src/components/color-section.tsx.
|
||||
// Port of HeroUI ce90ea3 color-section.tsx: four original layout families.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
// Vue DOM/CSS token display; copying keeps the browser's resolved CSS color.
|
||||
import { ref } from "vue";
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
defineProps<{ name: string; tokens: string[] }>();
|
||||
import { computed, ref } from "vue";
|
||||
import { Chip } from "@heroui-vue/components";
|
||||
import { IconSettings } from "@tabler/icons-vue";
|
||||
import DocsColorSwatch from "./DocsColorSwatch.vue";
|
||||
import {
|
||||
colorSections,
|
||||
type SectionId,
|
||||
type SideSection,
|
||||
type Swatch,
|
||||
} from "./color-sections";
|
||||
const props = defineProps<{ section: SectionId }>();
|
||||
const section = computed(() => colorSections[props.section]);
|
||||
const side = computed(() =>
|
||||
section.value.kind === "ColorSectionSideBySide" ? section.value : undefined,
|
||||
);
|
||||
const stacked = computed(() =>
|
||||
section.value.kind === "ColorSectionStacked" ? section.value : undefined,
|
||||
);
|
||||
const field = computed(() =>
|
||||
section.value.kind === "ColorSectionFormField"
|
||||
? section.value.colors
|
||||
: undefined,
|
||||
);
|
||||
const primitive = computed(() =>
|
||||
section.value.kind === "ColorSectionPrimitive"
|
||||
? section.value.colors
|
||||
: undefined,
|
||||
);
|
||||
const message = ref("");
|
||||
async function copy(event: MouseEvent, token: string) {
|
||||
const value = getComputedStyle(
|
||||
event.currentTarget as HTMLElement,
|
||||
).backgroundColor;
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
message.value = `已复制 ${token}: ${value}`;
|
||||
} catch {
|
||||
message.value = `无法复制,请使用变量 ${token}`;
|
||||
}
|
||||
}
|
||||
const themes = ["light", "dark"] as const;
|
||||
const swatch = (
|
||||
label: string,
|
||||
variable: string,
|
||||
cssValue?: string,
|
||||
tooltip?: string,
|
||||
border?: boolean,
|
||||
): Swatch => ({ label, variable, cssValue, tooltip, border });
|
||||
const header = (s: SideSection) =>
|
||||
swatch(s.name, s.baseVariable, undefined, s.baseTooltip);
|
||||
</script>
|
||||
<template>
|
||||
<div class="docs-color-section not-prose">
|
||||
<div
|
||||
v-for="theme in ['light', 'dark']"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-column"
|
||||
>
|
||||
<div class="docs-color-header">
|
||||
<strong>{{ name }}</strong>
|
||||
<span>{{ theme === "light" ? "Light" : "Dark" }}</span>
|
||||
<div
|
||||
class="docs-color-section not-prose"
|
||||
:data-color-section="props.section"
|
||||
:data-color-layout="section.kind"
|
||||
>
|
||||
<div v-if="side" class="docs-color-side">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-column"
|
||||
>
|
||||
<DocsColorSwatch
|
||||
:swatch="header(side)"
|
||||
:theme="theme"
|
||||
header
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<div class="docs-color-groups">
|
||||
<div
|
||||
class="docs-color-solid"
|
||||
:style="{ backgroundColor: `var(${side.baseVariable})` }"
|
||||
>
|
||||
<span
|
||||
class="docs-color-group-title"
|
||||
:style="{ backgroundColor: `var(${side.baseVariable})` }"
|
||||
>
|
||||
{{ side.name }}
|
||||
</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
side.hoverVariable,
|
||||
side.hoverCssValue,
|
||||
side.hoverTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
side.foregroundVariable,
|
||||
undefined,
|
||||
side.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="side.soft" class="docs-color-soft">
|
||||
<div class="docs-color-soft-surface" />
|
||||
<div
|
||||
class="docs-color-soft-tint"
|
||||
:style="{
|
||||
backgroundColor:
|
||||
side.soft.baseCssValue || `var(${side.soft.baseVariable})`,
|
||||
}"
|
||||
/>
|
||||
<span class="docs-color-soft-title">{{ side.name }} Soft</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
side.soft.hoverVariable,
|
||||
side.soft.hoverCssValue,
|
||||
side.soft.hoverTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
plain-text
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
side.soft.foregroundVariable,
|
||||
side.soft.foregroundCssValue,
|
||||
side.soft.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Tooltip v-for="token in tokens" :key="token" :delay="0">
|
||||
<Button
|
||||
variant="ghost"
|
||||
class="docs-color-token"
|
||||
:style="{ backgroundColor: `var(${token})` }"
|
||||
:aria-label="`复制 ${theme} ${token}`"
|
||||
@click="copy($event, token)"
|
||||
>
|
||||
<span>{{ token }}</span>
|
||||
</Button>
|
||||
<TooltipContent>
|
||||
{{ token }} · 点击复制浏览器解析后的颜色值
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<span class="docs-color-message" role="status">{{ message }}</span>
|
||||
<template v-else-if="stacked">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-row"
|
||||
>
|
||||
<div>
|
||||
<Chip size="sm">
|
||||
<IconSettings :size="14" aria-hidden="true" />
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</Chip>
|
||||
</div>
|
||||
<div class="docs-color-swatches">
|
||||
<DocsColorSwatch
|
||||
v-for="(color, i) in theme === 'light'
|
||||
? stacked.lightColors
|
||||
: stacked.darkColors"
|
||||
:key="i"
|
||||
:swatch="color"
|
||||
:theme="theme"
|
||||
stacked
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="field">
|
||||
<div
|
||||
v-for="theme in themes"
|
||||
:key="theme"
|
||||
:data-theme="theme"
|
||||
class="docs-color-row"
|
||||
>
|
||||
<div>
|
||||
<Chip size="sm">
|
||||
<IconSettings :size="14" aria-hidden="true" />
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</Chip>
|
||||
</div>
|
||||
<div class="docs-color-field-layout">
|
||||
<div
|
||||
class="docs-color-field-bg"
|
||||
:style="{ backgroundColor: `var(${field.bg})` }"
|
||||
>
|
||||
<span
|
||||
class="docs-color-group-title"
|
||||
:style="{ backgroundColor: `var(${field.bg})` }"
|
||||
>
|
||||
Bg
|
||||
</span>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Hover',
|
||||
field.bg,
|
||||
field.bgHover,
|
||||
field.bgHoverTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch('Focus', field.bg, undefined, field.bgFocusTooltip, true)
|
||||
"
|
||||
:theme="theme"
|
||||
contrast-border
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<div class="docs-color-field-text">
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Placeholder',
|
||||
field.placeholder,
|
||||
undefined,
|
||||
field.placeholderTooltip,
|
||||
true,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
<DocsColorSwatch
|
||||
:swatch="
|
||||
swatch(
|
||||
'Foreground',
|
||||
field.foreground,
|
||||
undefined,
|
||||
field.foregroundTooltip,
|
||||
)
|
||||
"
|
||||
:theme="theme"
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else-if="primitive" class="docs-color-swatches">
|
||||
<DocsColorSwatch
|
||||
v-for="color in primitive"
|
||||
:key="color.variable"
|
||||
:swatch="color"
|
||||
stacked
|
||||
@copied="message = $event"
|
||||
/>
|
||||
</div>
|
||||
<span class="sr-only" role="status">{{ message }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.docs-color-section {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-block: 20px;
|
||||
}
|
||||
[data-theme="light"] {
|
||||
--docs-color-outline: rgb(0 0 0 / 12%);
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--docs-color-outline: rgb(255 255 255 / 12%);
|
||||
}
|
||||
.docs-color-side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
.docs-color-column {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-solid,
|
||||
.docs-color-soft,
|
||||
.docs-color-field-bg {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
color: var(--foreground);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.docs-color-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.docs-color-header span {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.docs-color-token {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
padding: 12px;
|
||||
justify-content: start;
|
||||
border-radius: 12px;
|
||||
border: 1px solid color-mix(in oklab, var(--foreground) 12%, transparent);
|
||||
}
|
||||
.docs-color-token span {
|
||||
background: inherit;
|
||||
.docs-color-group-title {
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
color: transparent;
|
||||
filter: invert(1) grayscale(1) contrast(100);
|
||||
font-size: 12px;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-color-message {
|
||||
grid-column: 1 / -1;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
.docs-color-soft {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
.docs-color-section {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
.docs-color-soft-surface,
|
||||
.docs-color-soft-tint {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
.docs-color-soft-surface {
|
||||
background: var(--surface);
|
||||
}
|
||||
.docs-color-soft-title,
|
||||
.docs-color-soft :deep(.docs-swatch) {
|
||||
position: relative;
|
||||
}
|
||||
.docs-color-soft-title {
|
||||
color: var(--foreground);
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-color-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-swatches {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-swatches :deep(.docs-swatch) {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.docs-color-field-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-field-bg {
|
||||
border: 1px solid rgb(0 0 0 / 12%);
|
||||
}
|
||||
.docs-color-field-text {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
gap: 8px;
|
||||
}
|
||||
.docs-color-field-text :deep(.docs-swatch) {
|
||||
flex: 1;
|
||||
}
|
||||
@media (min-width: 640px) {
|
||||
.docs-color-side,
|
||||
.docs-color-groups,
|
||||
.docs-color-swatches,
|
||||
.docs-color-field-layout {
|
||||
flex-direction: row;
|
||||
}
|
||||
.docs-color-field-text {
|
||||
width: 160px;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
// Vue adaptation of HeroUI ce90ea3 ColorHeader/ColorBlock/StackedSwatch.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
import type { Swatch } from "./color-sections";
|
||||
import { colorValue } from "./color-value";
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
swatch: Swatch;
|
||||
theme?: string;
|
||||
header?: boolean;
|
||||
stacked?: boolean;
|
||||
plainText?: boolean;
|
||||
contrastBorder?: boolean;
|
||||
}>(),
|
||||
{ theme: "primitive" },
|
||||
);
|
||||
const emit = defineEmits<{ copied: [message: string] }>();
|
||||
const element = ref<HTMLButtonElement>();
|
||||
const resolved = ref("");
|
||||
const expression = computed(
|
||||
() => props.swatch.cssValue ?? `var(${props.swatch.variable})`,
|
||||
);
|
||||
const token = computed(
|
||||
() => props.swatch.tooltip?.split(":")[0].trim() || props.swatch.variable,
|
||||
);
|
||||
const contrast = computed(() =>
|
||||
props.plainText
|
||||
? { color: "var(--foreground)" }
|
||||
: {
|
||||
backgroundColor: `var(${props.swatch.variable})`,
|
||||
backgroundClip: "text",
|
||||
WebkitBackgroundClip: "text",
|
||||
color: "transparent",
|
||||
filter: "invert(1) grayscale(1) contrast(100)",
|
||||
},
|
||||
);
|
||||
function read() {
|
||||
if (element.value)
|
||||
resolved.value = colorValue(
|
||||
getComputedStyle(element.value).backgroundColor,
|
||||
);
|
||||
}
|
||||
onMounted(read);
|
||||
async function copy() {
|
||||
read();
|
||||
try {
|
||||
await navigator.clipboard.writeText(resolved.value);
|
||||
emit("copied", `已复制 ${token.value}: ${resolved.value}`);
|
||||
} catch {
|
||||
emit("copied", `无法复制,请使用 ${expression.value}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Tooltip :delay="0">
|
||||
<button
|
||||
ref="element"
|
||||
type="button"
|
||||
class="docs-swatch"
|
||||
:class="{
|
||||
'docs-swatch-header': header,
|
||||
'docs-swatch-stacked': stacked,
|
||||
'docs-swatch-border': swatch.border,
|
||||
'docs-swatch-contrast-border': contrastBorder,
|
||||
}"
|
||||
:style="{ backgroundColor: expression }"
|
||||
:data-color-variable="swatch.variable"
|
||||
:data-color-label="swatch.label"
|
||||
:data-color-expression="expression"
|
||||
:aria-label="`复制 ${theme} ${swatch.label} ${token}`"
|
||||
@pointerenter="read"
|
||||
@focus="read"
|
||||
@click="copy"
|
||||
>
|
||||
<span class="docs-swatch-label" :style="contrast">
|
||||
{{ swatch.label }}
|
||||
</span>
|
||||
<span class="docs-swatch-token" :style="contrast">{{ token }}</span>
|
||||
<span v-if="header" class="docs-swatch-theme" :style="contrast">
|
||||
{{ theme === "light" ? "Light" : "Dark" }}
|
||||
</span>
|
||||
</button>
|
||||
<TooltipContent class="docs-color-tooltip">
|
||||
<pre
|
||||
>{{ token }}: {{ expression }}
|
||||
当前取值:{{ resolved }}</pre>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</template>
|
||||
<style scoped>
|
||||
.docs-swatch {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 10px 16px;
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
text-align: start;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.docs-swatch:focus-visible {
|
||||
outline: 2px solid var(--focus);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.docs-swatch-label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
line-height: 20px;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
.docs-swatch-token {
|
||||
display: none;
|
||||
font: 10px/1.1 monospace;
|
||||
opacity: 0.6;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.docs-swatch-header {
|
||||
position: relative;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.docs-swatch-header .docs-swatch-label {
|
||||
font-size: 18px;
|
||||
line-height: 28px;
|
||||
padding-inline-end: 40px;
|
||||
}
|
||||
.docs-swatch-theme {
|
||||
position: absolute;
|
||||
inset-inline-end: 16px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.docs-swatch-stacked {
|
||||
min-height: 56px;
|
||||
padding-block: 8px;
|
||||
}
|
||||
.docs-swatch-border {
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.docs-swatch-contrast-border {
|
||||
border-color: var(--docs-color-outline);
|
||||
}
|
||||
.docs-color-tooltip pre {
|
||||
margin: 0;
|
||||
font: 12px/1.6 monospace;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@media (max-width: 639px) {
|
||||
.docs-swatch-token {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,513 @@
|
||||
// Data ported verbatim from HeroUI ce90ea3 Chinese colors.mdx.
|
||||
// Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE.
|
||||
// Explicit demo formulas intentionally differ from some library-derived tokens.
|
||||
export interface Swatch {
|
||||
label: string;
|
||||
variable: string;
|
||||
cssValue?: string;
|
||||
border?: boolean;
|
||||
tooltip?: string;
|
||||
}
|
||||
interface Soft {
|
||||
baseVariable: string;
|
||||
baseCssValue?: string;
|
||||
baseTooltip?: string;
|
||||
hoverVariable: string;
|
||||
hoverCssValue?: string;
|
||||
hoverTooltip?: string;
|
||||
foregroundVariable: string;
|
||||
foregroundCssValue?: string;
|
||||
foregroundTooltip?: string;
|
||||
}
|
||||
export interface SideSection {
|
||||
kind: "ColorSectionSideBySide";
|
||||
name: string;
|
||||
baseVariable: string;
|
||||
baseTooltip?: string;
|
||||
hoverVariable: string;
|
||||
hoverCssValue?: string;
|
||||
hoverTooltip?: string;
|
||||
foregroundVariable: string;
|
||||
foregroundTooltip?: string;
|
||||
soft?: Soft;
|
||||
}
|
||||
interface StackSection {
|
||||
kind: "ColorSectionStacked";
|
||||
lightColors: Swatch[];
|
||||
darkColors: Swatch[];
|
||||
}
|
||||
interface FieldColors {
|
||||
bg: string;
|
||||
bgTooltip?: string;
|
||||
bgHover: string;
|
||||
bgHoverTooltip?: string;
|
||||
bgFocusTooltip?: string;
|
||||
placeholder: string;
|
||||
placeholderTooltip?: string;
|
||||
foreground: string;
|
||||
foregroundTooltip?: string;
|
||||
}
|
||||
interface FieldSection {
|
||||
kind: "ColorSectionFormField";
|
||||
colors: FieldColors;
|
||||
}
|
||||
interface PrimitiveSection {
|
||||
kind: "ColorSectionPrimitive";
|
||||
colors: Swatch[];
|
||||
}
|
||||
export type SectionId =
|
||||
| "accent"
|
||||
| "default"
|
||||
| "success"
|
||||
| "warning"
|
||||
| "danger"
|
||||
| "foreground"
|
||||
| "background"
|
||||
| "surface"
|
||||
| "field"
|
||||
| "separator"
|
||||
| "other"
|
||||
| "primitive";
|
||||
export const colorSections: Record<
|
||||
SectionId,
|
||||
SideSection | StackSection | FieldSection | PrimitiveSection
|
||||
> = {
|
||||
accent: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "强调色",
|
||||
baseVariable: "--accent",
|
||||
baseTooltip: "--accent: oklch(0.6204 0.195 253.83)",
|
||||
hoverVariable: "--accent",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--accent) 90%, var(--accent-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-accent-hover:\n color-mix(\n in oklab,\n var(--accent) 90%,\n var(--accent-foreground) 10%\n )",
|
||||
foregroundVariable: "--accent-foreground",
|
||||
foregroundTooltip: "--accent-foreground: var(--snow)",
|
||||
soft: {
|
||||
baseVariable: "--accent",
|
||||
baseCssValue: "color-mix(in oklab, var(--accent) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-accent-soft:\n color-mix(\n in oklab,\n var(--accent) 15%,\n transparent\n )",
|
||||
hoverVariable: "--accent",
|
||||
hoverCssValue: "color-mix(in oklab, var(--accent) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-accent-soft-hover:\n color-mix(\n in oklab,\n var(--accent) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--accent",
|
||||
foregroundCssValue: "var(--accent)",
|
||||
foregroundTooltip: "--color-accent-soft-foreground: var(--accent)",
|
||||
},
|
||||
},
|
||||
default: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "默认",
|
||||
baseVariable: "--default",
|
||||
baseTooltip: "--default: oklch(94% 0.001 286.375)",
|
||||
hoverVariable: "--default",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--default) 96%, var(--default-foreground) 4%)",
|
||||
hoverTooltip:
|
||||
"--color-default-hover:\n color-mix(\n in oklab,\n var(--default) 96%,\n var(--default-foreground) 4%\n )",
|
||||
foregroundVariable: "--default-foreground",
|
||||
foregroundTooltip: "--default-foreground: var(--eclipse)",
|
||||
},
|
||||
success: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "成功",
|
||||
baseVariable: "--success",
|
||||
baseTooltip: "--success: oklch(0.7329 0.1935 150.81)",
|
||||
hoverVariable: "--success",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--success) 90%, var(--success-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-success-hover:\n color-mix(\n in oklab,\n var(--success) 90%,\n var(--success-foreground) 10%\n )",
|
||||
foregroundVariable: "--success-foreground",
|
||||
foregroundTooltip: "--success-foreground: var(--eclipse)",
|
||||
soft: {
|
||||
baseVariable: "--success",
|
||||
baseCssValue: "color-mix(in oklab, var(--success) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-success-soft:\n color-mix(\n in oklab,\n var(--success) 15%,\n transparent\n )",
|
||||
hoverVariable: "--success",
|
||||
hoverCssValue: "color-mix(in oklab, var(--success) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-success-soft-hover:\n color-mix(\n in oklab,\n var(--success) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--success",
|
||||
foregroundCssValue: "var(--success)",
|
||||
foregroundTooltip: "--color-success-soft-foreground: var(--success)",
|
||||
},
|
||||
},
|
||||
warning: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "警告",
|
||||
baseVariable: "--warning",
|
||||
baseTooltip: "--warning: oklch(0.7819 0.1585 72.33)",
|
||||
hoverVariable: "--warning",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--warning) 90%, var(--warning-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-warning-hover:\n color-mix(\n in oklab,\n var(--warning) 90%,\n var(--warning-foreground) 10%\n )",
|
||||
foregroundVariable: "--warning-foreground",
|
||||
foregroundTooltip: "--warning-foreground: var(--eclipse)",
|
||||
soft: {
|
||||
baseVariable: "--warning",
|
||||
baseCssValue: "color-mix(in oklab, var(--warning) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-warning-soft:\n color-mix(\n in oklab,\n var(--warning) 15%,\n transparent\n )",
|
||||
hoverVariable: "--warning",
|
||||
hoverCssValue: "color-mix(in oklab, var(--warning) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-warning-soft-hover:\n color-mix(\n in oklab,\n var(--warning) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--warning",
|
||||
foregroundCssValue: "var(--warning)",
|
||||
foregroundTooltip: "--color-warning-soft-foreground: var(--warning)",
|
||||
},
|
||||
},
|
||||
danger: {
|
||||
kind: "ColorSectionSideBySide",
|
||||
name: "危险",
|
||||
baseVariable: "--danger",
|
||||
baseTooltip: "--danger: oklch(0.6532 0.2328 25.74)",
|
||||
hoverVariable: "--danger",
|
||||
hoverCssValue:
|
||||
"color-mix(in oklab, var(--danger) 90%, var(--danger-foreground) 10%)",
|
||||
hoverTooltip:
|
||||
"--color-danger-hover:\n color-mix(\n in oklab,\n var(--danger) 90%,\n var(--danger-foreground) 10%\n )",
|
||||
foregroundVariable: "--danger-foreground",
|
||||
foregroundTooltip: "--danger-foreground: var(--snow)",
|
||||
soft: {
|
||||
baseVariable: "--danger",
|
||||
baseCssValue: "color-mix(in oklab, var(--danger) 15%, transparent)",
|
||||
baseTooltip:
|
||||
"--color-danger-soft:\n color-mix(\n in oklab,\n var(--danger) 15%,\n transparent\n )",
|
||||
hoverVariable: "--danger",
|
||||
hoverCssValue: "color-mix(in oklab, var(--danger) 20%, transparent)",
|
||||
hoverTooltip:
|
||||
"--color-danger-soft-hover:\n color-mix(\n in oklab,\n var(--danger) 20%,\n transparent\n )",
|
||||
foregroundVariable: "--danger",
|
||||
foregroundCssValue: "var(--danger)",
|
||||
foregroundTooltip: "--color-danger-soft-foreground: var(--danger)",
|
||||
},
|
||||
},
|
||||
foreground: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "前景",
|
||||
variable: "--foreground",
|
||||
tooltip: "--foreground: var(--eclipse)",
|
||||
},
|
||||
{
|
||||
label: "弱化",
|
||||
variable: "--muted",
|
||||
tooltip: "--muted: oklch(0.5517 0.0138 285.94)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
tooltip: "--segment: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
tooltip: "--overlay: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "链接",
|
||||
variable: "--link",
|
||||
tooltip: "--link: var(--foreground)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "前景",
|
||||
variable: "--foreground",
|
||||
border: true,
|
||||
tooltip: "--foreground: var(--snow)",
|
||||
},
|
||||
{
|
||||
label: "弱化",
|
||||
variable: "--muted",
|
||||
border: true,
|
||||
tooltip: "--muted: oklch(70.5% 0.015 286.067)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: oklch(0.3964 0.01 285.93)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "链接",
|
||||
variable: "--link",
|
||||
border: true,
|
||||
tooltip: "--link: var(--foreground)",
|
||||
},
|
||||
],
|
||||
},
|
||||
background: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "背景",
|
||||
variable: "--background",
|
||||
border: true,
|
||||
tooltip: "--background: oklch(0.9702 0 0)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 96%, var(--foreground) 4%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-secondary:\n color-mix(\n in oklab,\n var(--background) 96%,\n var(--foreground) 4%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 92%, var(--foreground) 8%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-tertiary:\n color-mix(\n in oklab,\n var(--background) 92%,\n var(--foreground) 8%\n )",
|
||||
},
|
||||
{
|
||||
label: "反色",
|
||||
variable: "--foreground",
|
||||
tooltip: "--color-background-inverse: var(--foreground)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "背景",
|
||||
variable: "--background",
|
||||
border: true,
|
||||
tooltip: "--background: oklch(12% 0.005 285.823)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 96%, var(--foreground) 4%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-secondary:\n color-mix(\n in oklab,\n var(--background) 96%,\n var(--foreground) 4%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--background",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--background) 92%, var(--foreground) 8%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-background-tertiary:\n color-mix(\n in oklab,\n var(--background) 92%,\n var(--foreground) 8%\n )",
|
||||
},
|
||||
{
|
||||
label: "反色",
|
||||
variable: "--foreground",
|
||||
border: true,
|
||||
tooltip: "--color-background-inverse: var(--foreground)",
|
||||
},
|
||||
],
|
||||
},
|
||||
surface: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "表面",
|
||||
variable: "--surface",
|
||||
border: true,
|
||||
tooltip: "--surface: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface-secondary",
|
||||
border: true,
|
||||
tooltip: "--surface-secondary: oklch(0.9524 0.0013 286.37)",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface-tertiary",
|
||||
border: true,
|
||||
tooltip: "--surface-tertiary: oklch(0.9373 0.0013 286.37)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "表面",
|
||||
variable: "--surface",
|
||||
border: true,
|
||||
tooltip: "--surface: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface-secondary",
|
||||
border: true,
|
||||
tooltip: "--surface-secondary: oklch(0.257 0.0037 286.14)",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface-tertiary",
|
||||
border: true,
|
||||
tooltip: "--surface-tertiary: oklch(0.2721 0.0024 247.91)",
|
||||
},
|
||||
],
|
||||
},
|
||||
field: {
|
||||
kind: "ColorSectionFormField",
|
||||
colors: {
|
||||
bg: "--field-background",
|
||||
bgTooltip: "--field-background: var(--white)",
|
||||
bgHover:
|
||||
"color-mix(in oklab, var(--field-background) 90%, var(--field-foreground) 10%)",
|
||||
bgHoverTooltip:
|
||||
"--color-field-hover:\n color-mix(\n in oklab,\n var(--field-background, var(--default)) 90%,\n var(--field-foreground, var(--foreground)) 2%\n )",
|
||||
bgFocusTooltip:
|
||||
"--color-field-focus:\n var(--field-background, var(--default))",
|
||||
placeholder: "--field-placeholder",
|
||||
placeholderTooltip: "--field-placeholder: var(--muted)",
|
||||
foreground: "--field-foreground",
|
||||
foregroundTooltip: "--field-foreground: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
},
|
||||
separator: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "分隔线",
|
||||
variable: "--separator",
|
||||
border: true,
|
||||
tooltip: "--separator: oklch(92% 0.004 286.32)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 85%, var(--surface-foreground) 15%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-secondary:\n color-mix(\n in oklab,\n var(--surface) 85%,\n var(--surface-foreground) 15%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 81%, var(--surface-foreground) 19%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-tertiary:\n color-mix(\n in oklab,\n var(--surface) 81%,\n var(--surface-foreground) 19%\n )",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "分隔线",
|
||||
variable: "--separator",
|
||||
border: true,
|
||||
tooltip: "--separator: oklch(25% 0.006 286.033)",
|
||||
},
|
||||
{
|
||||
label: "次级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 85%, var(--surface-foreground) 15%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-secondary:\n color-mix(\n in oklab,\n var(--surface) 85%,\n var(--surface-foreground) 15%\n )",
|
||||
},
|
||||
{
|
||||
label: "第三级",
|
||||
variable: "--surface",
|
||||
cssValue:
|
||||
"color-mix(in oklab, var(--surface) 81%, var(--surface-foreground) 19%)",
|
||||
border: true,
|
||||
tooltip:
|
||||
"--color-separator-tertiary:\n color-mix(\n in oklab,\n var(--surface) 81%,\n var(--surface-foreground) 19%\n )",
|
||||
},
|
||||
],
|
||||
},
|
||||
other: {
|
||||
kind: "ColorSectionStacked",
|
||||
lightColors: [
|
||||
{
|
||||
label: "边框",
|
||||
variable: "--border",
|
||||
tooltip: "--border: oklch(90% 0.004 286.32)",
|
||||
},
|
||||
{
|
||||
label: "背衬",
|
||||
variable: "--backdrop",
|
||||
tooltip: "--backdrop: rgba(0, 0, 0, 0.5)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: var(--white)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: var(--white)",
|
||||
},
|
||||
],
|
||||
darkColors: [
|
||||
{
|
||||
label: "边框",
|
||||
variable: "--border",
|
||||
tooltip: "--border: oklch(28% 0.006 286.033)",
|
||||
},
|
||||
{
|
||||
label: "背衬",
|
||||
variable: "--backdrop",
|
||||
tooltip: "--backdrop: rgba(0, 0, 0, 0.6)",
|
||||
},
|
||||
{
|
||||
label: "遮罩",
|
||||
variable: "--overlay",
|
||||
border: true,
|
||||
tooltip: "--overlay: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
{
|
||||
label: "分段",
|
||||
variable: "--segment",
|
||||
border: true,
|
||||
tooltip: "--segment: oklch(0.3964 0.01 285.93)",
|
||||
},
|
||||
],
|
||||
},
|
||||
primitive: {
|
||||
kind: "ColorSectionPrimitive",
|
||||
colors: [
|
||||
{
|
||||
label: "白",
|
||||
variable: "--white",
|
||||
border: true,
|
||||
tooltip: "--white: oklch(100% 0 0)",
|
||||
},
|
||||
{
|
||||
label: "黑",
|
||||
variable: "--black",
|
||||
tooltip: "--black: oklch(0% 0 0)",
|
||||
},
|
||||
{
|
||||
label: "雪白",
|
||||
variable: "--snow",
|
||||
border: true,
|
||||
tooltip: "--snow: oklch(0.9911 0 0)",
|
||||
},
|
||||
{
|
||||
label: "月蚀",
|
||||
variable: "--eclipse",
|
||||
tooltip: "--eclipse: oklch(0.2103 0.0059 285.89)",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
// Match the fixed color-section's OKLCH clipboard format without a runtime color dependency.
|
||||
// Input is the browser's computed sRGB/OKLab/OKLCH serialization, not arbitrary CSS.
|
||||
export function colorValue(css: string) {
|
||||
const format = (n: number) => String(Number(n.toFixed(4)));
|
||||
const output = (l: number, a: number, b: number, alpha = 1) => {
|
||||
const c = Math.hypot(a, b);
|
||||
const h = c < 1e-7 ? 0 : ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360;
|
||||
return `oklch(${format(l)} ${format(c < 1e-7 ? 0 : c)} ${format(h)}${alpha < 1 ? ` / ${format(alpha)}` : ""})`;
|
||||
};
|
||||
const ok = css.match(/^ok(lab|lch)\((.+)\)$/);
|
||||
if (ok) {
|
||||
const [components, opacity] = ok[2].split("/").map((s) => s.trim());
|
||||
const values = components.split(/\s+/);
|
||||
const lightness =
|
||||
parseFloat(values[0]) / (values[0].endsWith("%") ? 100 : 1);
|
||||
const alpha =
|
||||
opacity === undefined
|
||||
? 1
|
||||
: parseFloat(opacity) / (opacity.endsWith("%") ? 100 : 1);
|
||||
if (ok[1] === "lab")
|
||||
return output(
|
||||
lightness,
|
||||
parseFloat(values[1]),
|
||||
parseFloat(values[2]),
|
||||
alpha,
|
||||
);
|
||||
return `oklch(${format(lightness)} ${format(parseFloat(values[1]))} ${format(parseFloat(values[2]) || 0)}${alpha < 1 ? ` / ${format(alpha)}` : ""})`;
|
||||
}
|
||||
const rgb = css.match(/^rgba?\((.+)\)$/);
|
||||
if (!rgb) return css;
|
||||
const parts = rgb[1].split(/[\s,/]+/).filter(Boolean);
|
||||
const [r, g, b] = parts.slice(0, 3).map((s) => {
|
||||
const v = parseFloat(s) / (s.endsWith("%") ? 100 : 255);
|
||||
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
const alpha =
|
||||
parts[3] === undefined
|
||||
? 1
|
||||
: parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
|
||||
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
||||
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
||||
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
||||
return output(
|
||||
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
||||
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
||||
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
||||
alpha,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user