merge: integrate color foundation and migration handoff

This commit is contained in:
maoyingjie
2026-10-25 11:10:47 +08:00
26 changed files with 2429 additions and 88 deletions
+10
View File
@@ -492,3 +492,13 @@ DateField/DateInputGroup 已公开,先读[DATE-02 报告](docs/migrations/DATE
浏览器可以在原生监听器之间执行微任务,document capture 后不能用 queueMicrotask 清掉尚未执行的目标处理器;改用整次派发后且可取消的任务。disabled/outside-month 原生按钮仍可能收到 pointerenter,桥接必须检查真实 Cell 状态;不要只按日期边界判断。样式适配原生按钮拉伸,不能被 playground 的全局 header/font 规则覆盖。
下一轮其他 AI 按 [DATE-05 提示词](docs/migrations/DATE-05-range-calendar-prompt.md) 同步 main 后新开分支,只消费内核完成公开十部件/六个年份别名、类型、20 例与文档。真实缺口交失败用例给集成人。触屏长按、范围字段/Picker/Time 桥接与颜色共享状态仍由集成人处理,不能从私有夹具或 Calendar 验收推断已完成。
## COLOR-01 颜色共享状态约束(2026-10-25)
先读 [颜色基建决策](docs/decisions/color-foundation.md) / [COLOR-01](docs/migrations/COLOR-01-foundation.md)。本轮只有私有 Color、接受值 owner、事务、Area 控制器/梯度与集成夹具;不得当作公共颜色组件已经迁移。
颜色模型不经 hex 往返;同空间通道和 HSL/HSB 灰色 hue/alpha 要保留。父拒绝后坐标/原生数值/兄弟控件都从接受值派生,同提案下一次可重试。继承归属动态切换须清理原 owner token,禁用子项不能取消兄弟手势。默认值捕获、modelValue 优先与原生 reset 复用 choice,不建另一套 Form/颜色队列。
Area 覆盖所有有序轴和 RTL;稳定 Root 捕获指针,内容区/边框/分别缩放与抓取偏移一起验。左右 X、上下 Y、Home/End X 页步长、PageUp/Down Y 页步长,依据通道元数据移动对应原生焦点;两个真实 range 保持单一 Tab 入口,step=any 不应破坏键盘步长。xName/yName/form 和受控 reset 后真实 input.value 不遗漏。
后续可按 [COLOR-02](docs/migrations/COLOR-02-area-swatch-prompt.md) 交接公开 Area/Swatch 与 14 例,只消费共享内核;真实缺口交失败用例给集成人。Color 辅助 API 不冒充 RAC 全接口,全 locale/感知色名、物理触屏、读屏、Nuxt 等验收边界保留说明。
+6 -1
View File
@@ -1,5 +1,9 @@
<script setup lang="ts">
import { ref } from "vue";
import ColorFoundationLab from "./ColorFoundationLab.vue";
const colorFoundation =
typeof window !== "undefined" &&
new URLSearchParams(window.location.search).has("color-foundation");
import RangeCalendarFoundationLab from "./RangeCalendarFoundationLab.vue";
const rangeFoundation =
typeof window !== "undefined" &&
@@ -35,7 +39,8 @@ function save() {
}
</script>
<template>
<RangeCalendarFoundationLab v-if="rangeFoundation" />
<ColorFoundationLab v-if="colorFoundation" />
<RangeCalendarFoundationLab v-else-if="rangeFoundation" />
<SelectLifecycle v-else-if="selectLifecycle" />
<ScrollTabsLab v-else-if="scrollTabsLab" />
<OverlayAnimationLab v-else-if="animationLab" />
+147
View File
@@ -0,0 +1,147 @@
<script setup lang="ts">
import { shallowRef } from "vue";
import Area from "../../../packages/vue/tests/fixtures/ColorAreaFoundation.vue";
import Picker from "../../../packages/vue/tests/fixtures/ColorPickerFoundation.vue";
import { parseColor } from "../../../packages/vue/src/components/color/value";
import {
Button,
Popover,
PopoverContent,
PopoverDialog,
} from "@heroui-vue/components";
const count = shallowRef(0),
end = shallowRef(0),
rejected = shallowRef(0),
rejectEnd = shallowRef(0);
const rejectedValue = parseColor("hsb(240,50%,50%)");
</script>
<template>
<main class="color-foundation-lab">
<h1>颜色共享状态 · 私有基建验收</h1>
<p>颜色、通道与透明度共用一个接受值;公开组件和正式文档尚未迁移。</p>
<div class="color-foundation-grid">
<section id="color-shared">
<h2>Area / Hue / 文本 / Swatch 同步</h2>
<form>
<Picker
name="color"
default-value="hsb(240,50%,50%)"
@change="count++"
@change-end="end++"
/>
<output>change {{ count }} / changeEnd {{ end }}</output>
<Button type="reset" variant="secondary" size="sm">原生重置</Button>
</form>
</section>
<section id="color-rejected">
<h2>受控拒绝:指针和提交保持父值</h2>
<Picker
:model-value="rejectedValue"
@change="rejected++"
@change-end="rejectEnd++"
/>
<output>拒绝 {{ rejected }} / 完成 {{ rejectEnd }}</output>
</section>
<section id="color-gray">
<h2>灰色保留色相和 alpha</h2>
<Picker default-value="hsb(270,0%,50%,.5)" />
</section>
<section id="color-rgb">
<h2>RGB 交换轴 / RTL</h2>
<Area
default-value="rgb(80,120,160)"
color-space="rgb"
x-channel="blue"
y-channel="red"
dir="rtl"
aria-label="RGB blue/red"
/>
</section>
<section id="color-hue-y">
<h2>Hue 在 Y 轴</h2>
<Area
default-value="hsb(240,70%,70%)"
color-space="hsb"
x-channel="brightness"
y-channel="hue"
aria-label="Brightness/hue"
/>
</section>
<section id="color-popover">
<h2>跨 Popover 保持共享 owner</h2>
<Picker default-value="hsb(120,50%,70%)" v-slot="{ value }">
<Popover>
<Button variant="secondary">打开颜色区域</Button>
<PopoverContent class="w-64">
<PopoverDialog>
<Area
color-space="hsb"
x-channel="saturation"
y-channel="brightness"
aria-label="Popover color area"
/>
</PopoverDialog>
</PopoverContent>
</Popover>
<output>{{ value?.toString("hsb") }}</output>
</Picker>
</section>
</div>
</main>
</template>
<style>
.color-foundation-lab {
padding: 32px;
min-height: 100vh;
background: var(--background);
color: var(--foreground);
font-family: Inter, sans-serif;
}
.color-foundation-lab h1 {
font-size: 24px;
margin-bottom: 8px;
}
.color-foundation-lab p {
color: var(--muted);
margin-bottom: 24px;
}
.color-foundation-grid {
display: flex;
flex-wrap: wrap;
gap: 24px;
align-items: flex-start;
}
.color-foundation-grid section {
padding: 20px;
border: 1px solid var(--border);
border-radius: 16px;
min-width: 300px;
}
.color-foundation-grid h2 {
font-size: 14px;
margin-bottom: 20px;
}
.color-foundation-grid output {
display: block;
font-size: 12px;
margin: 12px 0;
}
.color-foundation-grid
[data-color-picker-foundation]
> input:not([type="hidden"]) {
display: block;
margin-top: 16px;
max-width: 224px;
}
.color-foundation-grid [data-color-text] {
border: 1px solid var(--border);
border-radius: 8px;
padding: 6px;
font-size: 13px;
}
.color-foundation-grid [data-color-swatch] {
margin-top: 8px;
border: 1px solid var(--border);
border-radius: 8px;
}
</style>
+89 -85
View File
@@ -2,91 +2,91 @@
基于固定上游提交的公共组件导出清单。验证中不等于完整兼容;目前没有组件完成视觉、浏览器与完整行为验收。
| 组件 | 状态 | 当前能力 / 差异 |
| -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
| range-calendar | 私有基建已验证(DATE-04) | 接受值/草稿、障碍、共享视图与鼠标拖动已验证;尚未公开部件或 20 个正式预览,见 DATE-04 |
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
| 组件 | 状态 | 当前能力 / 差异 |
| -------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
| color-area | 私有基建已验证(COLOR-01) | 接受值、二维键盘、18 轴组合、指针捕获与两个原生轴/reset 已验证;未公开部件或 7 个正式预览 |
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-picker | 共享状态已验证(COLOR-01) | 私有 owner 联动 Area/Hue/文本/预览/Popover;未公开 Picker,滑条/字段完整协议仍待接续 |
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
| range-calendar | 私有基建已验证(DATE-04) | 接受值/草稿、障碍、共享视图与鼠标拖动已验证;尚未公开部件或 20 个正式预览,见 DATE-04 |
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
## 公共导出差异
@@ -218,3 +218,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
## DATE-04 范围选择基建
共享日历视图已提取,私有范围选择与手势经过集成、SSR、水合和重点浏览器验证;这不代表 RangeCalendar 公共迁移完成。当前范围、触屏长按拖选与字段组合的待办见 [DATE-04](migrations/DATE-04-range-foundation.md),公开收尾交接见 [DATE-05 提示词](migrations/DATE-05-range-calendar-prompt.md)。
## COLOR-01 颜色基建
颜色值、接受值/继承 owner、二维交互与梯度已由私有夹具验证;不表示公开组件或 React Stately Color 全 API 完成。范围和限制见 [COLOR-01](migrations/COLOR-01-foundation.md),可交接的 Area/Swatch 公共迁移见 [COLOR-02](migrations/COLOR-02-area-swatch-prompt.md)。
+54
View File
@@ -0,0 +1,54 @@
# COLOR-01:颜色状态与二维输入基建
2026-10-25,从 main `58ca16e` 同步后新建 `feat/color-foundation`,独立目录 heroui-vue-core。目标是先消除共享颜色、通道、受控拒绝与拖动的架构风险,公开壳层/完整预览交接,而不是一次包办整个颜色系列。
## 基线与实际底座
固定 HeroUI 3.2.6 / ce90ea3:color-area、color-picker、color-field/input-group、color-slider、color-swatch/picker 组件及对应 CSS/tv;中文 ColorArea 和 ColorSwatch 各 7 个正式预览。版本和来源不能从官网最新设计推断。
实际使用 Reka **2.11.0** 的公开颜色解析/转换导出,不导入内部源码、不修改 node_modules、不添加其他 UI 底座或 React 运行时。安装版实测用例为 tests/color-foundation-probes.test.ts,从组件包 fixture 解析依赖,避免给根测试偷偷绑 pnpm 私有目录。
| 实际探针 | 结果 | 方案 |
| ------------------------- | ----------------------------------- | ------------------------------------------------------- |
| 受控 Area 拒绝 ArrowRight | x 指针仍从 50 到 51,事件为 hex | 接受值与坐标统一派生;不让底座的乐观 ref 成为第二状态源 |
| 键盘 ArrowRight 后 keyup | 没有 changeEnd | 私有事务明确 begin/request/end/cancel |
| alpha | 模型 fraction,但底座通道范围 0–100 | 本库颜色模型、通道范围统一 0–1,显示百分比单独格式化 |
| HSB 灰色的通用 hue getter | 得到 0 而非原色相 | 同空间直接取通道;HSL/HSB 直接转换保留 hue |
| 函数尾部垃圾 / 超界数值 | 解析接受 | 边界完整匹配、有限数校验、明确夹限 |
| #RGBA | 安装版不接受 | 薄适配扩展为 #RRGGBBAA |
| hue 在 Y 轴 | 不生成对应的完整 hue 图层 | 梯度按全部有序轴组合生成,与指针使用同一通道定义 |
同时核对 Adobe 官方 [ColorArea 语义与原生轴](https://github.com/adobe/react-spectrum/blob/main/packages/react-aria/src/color/useColorArea.ts) 和 [Color 通道元数据](https://github.com/adobe/react-spectrum/blob/main/packages/react-stately/src/color/Color.ts):二维按键与焦点、页步长、两个原生轴及 xName/yName/form 作为辅助审计。它们是当日参考,不替代固定 HeroUI 基线;未移植 React hooks。
## 模型边界
`components/color/value.ts` 提供私有不可变 Color 和解析边界:RGB/HSL/HSB、alpha 0–1;字符串输入,Color 对象输出;clone、getColorSpace/getColorChannels/getChannels、getChannelRange/getChannelValue、withChannelValue/withAlpha、toFormat(三种空间)、toString、数值本地化。Raw Reka Color 只通过私有 static 转换桥使用,不能作为公共实例类型暴露。
accepted state 不经 hex 序列化往返。toString 是展示/序列化边界,显式 rgb/hsl/hsb 不输出 alpha,rgba/hsla/hsba 和 hexa 保留相应透明度。格式化不会改写完整模型精度;toFormat 的数学转换不强制做八位通道量化。
- Hue/RGB/百分比的 pageSize 分别为 15/17/10,alpha 为 0.1;键盘单步与原生 range 的 step=any 分开,后者防止浏览器把浮点接受值擅自对齐成整数。
- 自身 HSB/HSL 保存的灰色 hue 会保留;外部替换为没有色相信息的灰色 hex 不猜测先前 hue。跨空间在数学奇点可能丢失无定义的饱和度,不承诺任意格式转换后恢复潜在通道。
- hex3/4/6/8,数值 RGB/HSL/HSB/HSV 逗号或空格/slash 形式已覆盖。CSS 命名色、var()、Lab/OKLCH、颜色配置文件及所有 CSS Color 4 语法不在本轮范围。
- 这是本库适配类型,不继承整个 React Stately Color 接口;感知色名/全量读屏文案等方法未实现。公共 API 后续须只声明实际支持的集合。
## 唯一状态与事务
`model.ts` 复用 useChoiceValue 保存接受值/捕获初值;modelValue(含显式 null)优先于 value;defaultValue 捕获一次。子控件在省略全部自身值属性时注入最近 owner,动态添加/移除自身属性可以切换归属。父拒绝后坐标、文本、预览、原生值保持接受值,下一次相同手势仍可重试。
begin/request/end/cancel 以 Symbol 识别手势来源。changeEnd 传最后提案,不能把未接受提案当成接受值;取消、卸载、失去捕获、禁用/只读、外部替换与模式切换不伪造完成事件。继承链记录每个 token 的原 owner,切换 owner 时清理旧事务;禁用某个子项不能取消兄弟项的拖动。组件之间不新增全局颜色队列。
## 二维控制器与梯度
`area.ts` 只从接受值派生坐标;稳定 Root 持有 pointer capture。使用内容区几何并考虑边框、祖先分别缩放 X/Y;抓住 thumb 时保留抓取偏移。忽略其他 pointer、非主指针和非左键;处理取消、lostcapture、window blur、节点变化、上下文变化和卸载。
左右键操作 X,上下键操作 Y,Shift 使用各通道 pageSize;PageUp/Down 操作 Y,Home/End 按 X 页步长移动并遵循 RTL。移动时聚焦对应原生轴;两个 range 提供真实数值/单位和一个 Tab 入口,不用一个虚构的二维 aria-valuenow 代替全部语义。外部原生取消先于默认控制器。
`gradient.ts` 覆盖三种空间的 **18 个有序轴组合**,含交换轴和 RTL;RGB 使用 screen 图层,极坐标空间按 hue/饱和度/亮度层组合。不使用只覆盖默认轴的 fallback,不因像素相近就改变真实模型。
Area 的 xName/yName/form 使用两个真实 range 提交,消费既有 useChoiceForm 恢复 reset 后的接受值和真实 input.value,覆盖父值未变化时 Vue 不重写 DOM 的情况。继承子项的 reset 不另改 owner 值,owner 表单重置由组合层负责;不能为每个子项又注册一套 Form 协议。
## 夹具与未完成项
ColorAreaFoundation / ColorPickerFoundation 是 tests/fixtures 下的私有集成证明。后者用同一 owner 联动 Area、色相、文本、预览、Popover 和一个可选隐藏提交值;隐藏值显式采用 hexa,属于八位序列化,不能声称它保留任意浮点 alpha,也不是公开 ColorField/Picker 的最终序列化契约。未来字段仍核对基线并复用本库 field/Form。
ColorArea CSS 已从基线准备,hv- 命名空间及 Apache 声明保留;未公开 ColorArea/ColorPicker/parseColor。完整 props/slots、variants、locale 文案、色名、文档/预览和产物契约在公开迁移时单独验收。真实浏览器只验桌面关键操作;没有完成物理触屏、全读屏、全浏览器、Nuxt 或自动像素对比。
+8
View File
@@ -326,3 +326,11 @@ DateField 七部件与 DateInputGroup 六部件、17 例已落地,范围和差
实际浏览器发现的重点:原生事件监听器间的微任务会提前清理手势;disabled 月外日期仍会收到 pointerenter;RAC 块容器与原生 button 的拉伸不同;验收页的全局 header/font 会污染真实组件。后续在实际事件/Cell 状态/几何上回归,不能仅凭 jsdom 绿色或源 CSS 数值判断。
本轮只交 RangeCalendar 公共壳层、20 例、文档/产物契约;不让其他 AI 顺带重建 Picker/Time 的提交/reset 桥接或触屏长按手势。日期字段适配及 ColorArea/ColorPicker 的共享状态仍由集成人负责,先补探针后决定可派发范围。
## COLOR-01:共享颜色与二维输入(2026-10-25)
集成人完成私有颜色模型/owner/事务、Area 指针与键盘、18 个有序轴梯度及表单/reset 探针;未公开颜色组件。先读 [颜色决策](decisions/color-foundation.md) 和 [验收](migrations/COLOR-01-foundation.md)。现可按 [COLOR-02](migrations/COLOR-02-area-swatch-prompt.md) 交出 ColorArea + ColorSwatch 的公共壳层和 14 例;当前 RangeCalendar 任务先完成也可以,不把未提交源码带入另一批次。
不能让子控件各持 hex 副本;灰色 hue、alpha、父拒绝后的坐标/原生值、原 owner token 和兄弟禁用隔离要一起验。不要照搬 Reka 默认键盘、alpha 单位或渐变 fallback;也不要从文档表格漏掉 xName/yName/form。原生 range 不能将模型浮点值擅自对齐成整数,单步/pageSize 与显示格式分别管理。
公共任务只声明已实现的 Color 方法/格式;感知自动色名/全 locale 字典有明确差异。ColorSlider/Field/InputGroup/Picker/SwatchPicker 继续按输入协议与依赖关系接续,私有组合夹具不能作为公共完成证明。
+36
View File
@@ -0,0 +1,36 @@
# COLOR-01 共享颜色与 ColorArea 基建验收
2026-10-25,heroui-vue-core / feat/color-foundation,起点 main `58ca16e`。用户要求集成人继续重要基建;当前只有私有能力和集成夹具,**不是公开颜色组件迁移完成**。
设计、底座证据和差异见 [颜色基建决策](../decisions/color-foundation.md)。固定 ce90ea3;未增加依赖或改写 node_modules。ColorArea CSS 保留上游许可证,默认主题/数值沿用源样式。
## 本轮交付
| 范围 | 实现 | 验证 |
| ---------- | ----------------------------------------------------- | ----------------------------------------------------------------------- |
| 颜色值 | 不可变 Color、解析/转换/alpha、通道元数据和数值格式化 | 解析拒绝、拷贝、灰色 hue、RGB/HSL/HSB 精度、显式格式与私有类型反例 |
| 共享 owner | 接受值/捕获默认值、继承/独立模式、token 事务 | 拒绝重试、原 owner 清理、兄弟禁用隔离、外部替换、reset/取消 reset |
| ColorArea | Root 捕获、内容几何、grab offset、二维键盘和原生轴 | 指针 ID、取消/失捕获/window blur/卸载、缩放/边框、双轴提交、单 Tab 入口 |
| 梯度 | 18 个有序轴组合、交换轴、RTL、RGB screen | CSS 构建、各轴组合断言与真实浏览器计算样式/显示 |
| 组合 | Area / Hue / 文本 / Swatch / Popover 私有夹具 | 同一接受值、原生表单、真实 Teleport 共享、Esc/焦点恢复 |
## 实际结果
新增 **32** 项本库行为/集成/实际 jsdom 水合,**7** 项安装版探针,**2** 项真正 node SSR;完整回归 **78 文件 / 962 项通过**。vue-tsc(含颜色正反类型)、库/样式、文档 SSR 和 playground 构建通过;已有文档大 chunk 提示保留。新增测试已接入 test:unit/test:ssr。
5176 `?color-foundation` 真实浏览器重点:
- 224×224 区域,抓取偏移拖动得到 HSB(240,75%,75%);change 可多次、changeEnd 仅一次。
- 受控拒绝时 Area 保持 50%/50%,提案和完成分别发生,文本/预览保持父值。
- 键盘 ArrowUp 将焦点移至 Y,Home 按 X 页步长移动并聚焦 X;单一 Tab 入口后跳到色相。
- Popover 中 Area 更新到 HSB(120,75%,95%),外部 owner 同步;Escape 关闭并恢复触发按钮焦点。
- 原生 reset 将 Area/色相/文本/预览恢复初值,不增加 change/changeEnd。
- 交换 RGB 轴/RTL、Hue 在 Y 的梯度和两轴真实数值检查。截图:临时 `/private/tmp/heroui-color-foundation-review.png`,不是构建依赖。
独立 tarball 在工作区外检查新 CSS 存在且没有提前暴露 ColorArea/ColorPicker/parseColor,占位导出不得误标公开迁移完成;保留 Calendar/DateField/Select 的 ESM/SSR/CSS 和两种模块解析类型回归。最终结果也写入 verification.md。
## 可交出的下一轮
[COLOR-02 提示词](COLOR-02-area-swatch-prompt.md):ColorArea 公共两部件、ColorSwatch、共享颜色公共辅助类型,14 个完整基线预览与文档/产物验收。复用本轮内核,不复制颜色转换或交互状态。ColorSwatch 的自动色名/locale 与 RAC 若不同必须列差异,不宣称继承整个 RAC Color。
ColorPicker 公共组合、ColorSlider/Field/InputGroup/SwatchPicker 仍未完成。滑条/文本的完整输入协议、校验与第三方表单、跨控件取消/提交边界继续由集成人先验证;私有夹具不是这些公共组件的替代品。物理触屏、完整读屏与全 locale、跨浏览器/Nuxt、逐像素均未完成。
@@ -0,0 +1,31 @@
# 待派发:ColorArea + ColorSwatch 公共迁移
供用户在合适时交给其他 AI;当前 RangeCalendar 公开迁移任务可以先完成,不要把未完成分支的修改带入本批次。以下不代表组件已经实现。
```text
请在自己的 heroui-vue checkout 完成 ColorArea + ColorSwatch 公共迁移。先读 AGENTS.md、migration-handoff、COLOR-01 报告、颜色基建决策和近几轮迁移经验。不要修改 heroui-vue-core 或其他任务的服务。
先检查 status,保留未提交源码/旧截图;fetch origin,切 main,pull --ff-only,再新建 feat/color-02-area-swatch。确认 main 含 COLOR-01 内核,不能从旧分支继续开发。
固定 HeroUI 3.2.6 / ce90ea3。核对 ../heroui 的 color-area/color-swatch 实现、index、CSS/tv、中文正文和全部演示。视觉、布局、文案、变体、参数及状态保持高度一致,框架差异明确记录。
必须消费 packages/vue/src/components/color 的 Color/parseColor、useColorState、useColorArea、colorAreaBackground。ColorAreaFoundation.vue/ColorPickerFoundation.vue 仅为集成参考,不从 tests 导入发布运行时。禁止复制第二份解析/通道转换/灰色 hue/接受值/事务/指针模型。底座真实缺口交最小失败用例给集成人,不自行重写 choice/field/Form/overlay/color 内核。
实现 ColorArea/ColorAreaRoot/ColorAreaThumb、ColorSwatch/ColorSwatchRoot,全部 Props/slots/variants/类型和 parseColor 从包根导出。Color 类型来自同一实例类型,不暴露 Reka 原始可变对象或内部 static 桥。仅声明实际支持的方法和格式,不套 React Stately 的完整接口。ColorArea / Swatch 的 value/color 入参按源组件分别核对;共享模型的 null 不等于所有公共组件都必须接受 null。
Area 的两个原生 range 需放在 Thumb 内提供正确名称、数值/单位、ARIA/class/style/事件归属;一个 Tab 入口,二维键盘、原生取消、指针抓取偏移和取消复用控制器。xName/yName/form 真实提交,不退化成只支持隐藏 hex 值。reset 消费现有协议且恢复真实 range.value,父拒绝后不能保留浏览器改过的原生值。showDots/禁用/焦点/拖动和 reduced-motion 对齐源 CSS,不为文档写组件补丁。
ColorSwatch 可用 useColorStateContext 只读消费最近 owner,显式 color 属性优先,不创建无用的可编辑状态。ColorSwatch 沿用源尺寸/形状/棋盘透明背景、空值与 colorName、aria-label 优先级;正确角色与默认可访问名称必须有意义。当前 Color 没有 RAC 的感知色名/全 locale 词典;可采用本地化 RGB/alpha 数值描述作为明确替代,不能静默伪造完全一致的自动色名。自定义 colorName/ARIA 文案按基线展示并测试。
ColorArea 7 例依正文次序:basic、with-dots、space-and-channels、disabled、controlled、render-function、custom-styles。ColorSwatch 7 例:basic、sizes、shapes、transparency、render-function、accessibility、custom-styles。核对实际内容,空间/轴选择使用本库 Select/ListBox,图标使用 Tabler,预览/复制/高亮同一 SFC。
文档补完整中文正文、API、作用域和样式表,所有表格满宽换行,无横向拖动或短表收缩;类型管道转义。导航只改唯一清单,按上游顺序归类。不提前添加未完成 Picker/Slider/Field 的假链接。
验证值优先级/初值捕获/拒绝重试、灰色 hue、alpha、交换轴/RTL、原生两个轴提交/reset/取消、原生事件取消、动态 attrs/禁用/locale/owner 归属和卸载清理。14 个预览同页检查重复 ID/控制台告警,真正 Node SSR 和实际水合要断言真实节点。
运行适用/全量测试、typecheck、build:docs、格式;独立 tarball 消费的 ESM/SSR/CSS + strict NodeNext/bundler 正反类型(模型、空间/通道、变体、Props、事件、scoped slots),保留原 Calendar/DateField/Select 回归。不能靠源码 alias 或 unused expect-error 过关。
浏览器重点检查区域梯度/指针、受控拒绝、空间/轴切换、Swatch 透明度/尺寸、键盘焦点和文档表格,不必逐例盲点。触屏/读屏/逐像素/Nuxt 没执行就明确写。不要把私有 prototype 的 field/slider 当公共 ColorField/ColorSlider 完成。
更新 compatibility/upstream/verification,提交 COLOR-02 报告,逐项原契约→实现→验证→差异。完成后停在任务分支交回复核,不自行合并/推送 main。ColorPicker/Slider/Field/InputGroup/SwatchPicker 不在本轮范围,共享内核仍由集成人维护。
```
+4
View File
@@ -206,3 +206,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
## DATE-04 RangeCalendar 私有基建(2026-10-25)
核对 ce90ea3 的 range-calendar 组件、CSS/tv、中文正文和 20 个预览;本轮仅范围状态/交互及共享日历适配。range-calendar.css 加 hv- 前缀,原生 button 增加 w-full 等价块拉伸,Apache 声明沿用 third-party/HEROUI-LICENSE。Adobe 官方当日源文件仅作语义辅助审计,没有移植 React hook;与固定基线和待补能力分开记录,见 [DATE-04](migrations/DATE-04-range-foundation.md)。
## COLOR-01 颜色基建(2026-10-25)
固定 ce90ea3 的 color-area/picker、颜色系列组件/API、同名 CSS/tv、中文 Area/Swatch 各 7 例。ColorArea CSS 加 hv- 前缀,保留 Apache-2.0 声明。Reka 2.11 公开纯颜色转换用于私有适配,未复制其源码或修改安装包;Adobe 官方 ColorArea/Color 的当日语义审计仅作辅助,不替代固定基线。数学适配、元数据、来源链接和实际限制见 [颜色决策](decisions/color-foundation.md) 与 [COLOR-01](migrations/COLOR-01-foundation.md)。
+9
View File
@@ -916,3 +916,12 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
- 真实浏览器 5176 `?range-calendar-foundation`:36×36 日期按钮;拖动 10–15 日一次提交;两次点击首击只预览;受控边界拖动重复拒绝两次且接受值不变;键盘前进焦点;228px 日/年份网格对齐且当前年可见;拖过 disabled 月外日期不翻月,外部释放恢复已接受范围。
- 浏览器实际发现并修复 capture 后微任务提前清手势、月外 disabled 指针仍触发导航、原生 button 未拉伸及旧 playground header/font 污染。jsdom 不能单独证明这些布局/原生派发行为。
- 尚未实现触屏长按拖选;tap/click 与原生滚动路径保留。公开部件、20 正式预览、范围读屏提示/公告及产物类型留给下一批;范围字段/Picker/Time 桥接与颜色内核仍待集成人验证。未完成逐像素、完整读屏、真机、多浏览器或 Nuxt,不扩大本轮结论。
## COLOR-01 颜色共享与二维输入基建(2026-10-25)
- 从 main `58ca16e` 新建 feat/color-foundation。私有不可变 Color、接受值 owner/继承与 token 事务、Area 控制器、18 个有序轴梯度及两类集成夹具已落地;范围和来源见 [COLOR-01](migrations/COLOR-01-foundation.md) / [颜色决策](decisions/color-foundation.md)。没有公开 ColorArea/Picker 或 parseColor 占位。
- 新增 **32** 项本库行为/集成/实际水合、**7** 项安装版 Reka 2.11 探针、**2** 项真正 node SSR;最终 **78 文件 / 962 项通过**。探针暴露的乐观坐标、hex 色相丢失、alpha 单位、键盘完成与交换轴梯度缺口不作为公共契约。
- vue-tsc(含颜色模型/格式/通道反例)、库/样式、文档 SSR 和 playground 构建通过;Prettier 与 diff 检查通过。文档既有大 chunk 提示保留,无新增运行时依赖。
- 真浏览器 5176 `?color-foundation` 验证 224×224、抓取偏移拖至 75%/75%、多次 change / 一次 changeEnd、受控父拒绝保持 50%/50%、灰色 hue/alpha、交换轴/RTL、Y hue 梯度、二维按键和单一 Tab 入口、原生 reset,以及 Teleport 内外共享值/Esc/焦点恢复。最终截图为临时 `/private/tmp/heroui-color-foundation-review.png`,不依赖该文件构建。
- 最终 tarball 安装在 `/private/tmp/heroui-color-foundation-consumer`,无源码 alias:新 ColorArea CSS 存在、无公共占位导出;Calendar/DateField/Select 的 Node ESM/SSR/CSS 与 strict NodeNext/bundler 类型正反例回归通过。私有颜色类型的正反例在工作区执行,不将其冒充颜色公共产物验收。
- 实际边界:Color 接口/格式是明确子集,不继承全 RAC;自动感知色名/全部 locale 文案未迁移。私有 Picker 的 hexa 隐藏值是八位序列化证明,完整公共字段格式/校验协议仍待接续。未完成物理触屏、完整读屏/全浏览器、逐像素和 Nuxt;完整 ColorArea/Swatch 公共迁移可按 [COLOR-02](migrations/COLOR-02-area-swatch-prompt.md) 交接。
+2 -2
View File
@@ -15,8 +15,8 @@
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
"typecheck": "vue-tsc --noEmit",
"test": "vitest run",
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts tests/range-calendar-foundation.test.ts",
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts tests/range-calendar-foundation-ssr.test.ts",
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts tests/range-calendar-foundation.test.ts tests/color-foundation.test.ts tests/color-foundation-probes.test.ts",
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts tests/range-calendar-foundation-ssr.test.ts tests/color-foundation-ssr.test.ts",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
+85
View File
@@ -0,0 +1,85 @@
/* Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE. */
/* ==========================================================================
ColorArea - 2D color picker for selecting colors from a gradient area
========================================================================== */
/* Base styles */
.hv-color-area {
@apply relative w-full max-w-56 shrink-0 rounded-2xl no-highlight;
/* Square aspect ratio */
aspect-ratio: 1 / 1;
/* Color gradient background from React Aria */
background: var(--color-area-background);
/* Inner shadow for depth */
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
/* Disabled state */
&[data-disabled="true"] {
@apply status-disabled;
}
}
/* ==========================================================================
Dots overlay variant
========================================================================== */
.hv-color-area--show-dots {
/* Dot pattern overlay using radial gradient */
&::after {
content: "";
@apply pointer-events-none absolute inset-0 rounded-[inherit];
background-image: radial-gradient(
circle,
rgba(255, 255, 255, 0.2) 1px,
transparent 1px
);
background-size: 8px 8px;
}
}
/* ==========================================================================
Thumb element
========================================================================== */
.hv-color-area__thumb {
@apply size-4 rounded-xl will-change-[width,height];
/* Current color from React Aria */
background-color: var(--color-area-thumb-color);
/* White border for visibility */
border: 3px solid white;
/* Inner shadow for depth */
box-shadow:
0 0 0 1px rgba(0, 0, 0, 0.1),
inset 0 0 0 1px rgba(0, 0, 0, 0.1);
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
width 150ms var(--ease-out),
height 150ms var(--ease-out);
@apply motion-reduce:transition-none;
/* Focus state */
&[data-focus-visible="true"] {
@apply status-focused;
}
/* Dragging state */
&[data-dragging="true"] {
@apply size-5;
}
/* Disabled state */
&[data-disabled="true"] {
@apply status-disabled;
}
}
+3
View File
@@ -160,3 +160,6 @@
@import "./components/range-calendar.css" layer(components);
@import "./components/calendar-year-picker.css" layer(components);
/* Private color interaction foundation; public components are not exported yet. */
@import "./components/color-area.css" layer(components);
+325
View File
@@ -0,0 +1,325 @@
import {
computed,
nextTick,
onBeforeUnmount,
shallowRef,
watch,
type ShallowRef,
} from "vue";
import {
Color,
colorAxes,
type ColorAxisChannel,
type ColorSpace,
} from "./value";
import type { ColorState } from "./model";
import { useChoiceForm } from "../choice/shared";
import { useConfig } from "../../providers/context";
export interface ColorAreaOptions {
colorSpace?: ColorSpace;
xChannel?: ColorAxisChannel;
yChannel?: ColorAxisChannel;
dir?: "ltr" | "rtl";
locale?: string;
xName?: string;
yName?: string;
form?: string;
}
const clamp = (v: number) => Math.max(0, Math.min(1, v));
/** Private two-axis controller; it never stores optimistic channel coordinates. */
export function useColorArea(
state: ColorState,
props: ColorAreaOptions,
elements: {
root: ShallowRef<HTMLElement | undefined>;
focusX: ShallowRef<HTMLInputElement | undefined>;
focusY: ShallowRef<HTMLInputElement | undefined>;
thumb?: ShallowRef<HTMLElement | undefined>;
},
) {
const { root, focusX: thumb, focusY, thumb: handle } = elements;
const focusedAxis = shallowRef<"x" | "y">("x");
const config = useConfig();
const locale = computed(
() => props.locale ?? config?.locale.value ?? "en-US",
);
const dir = computed(() => props.dir ?? config?.dir.value ?? "ltr");
const axes = computed(() =>
colorAxes(
state.value.value ??
new Color({ space: "hsb", h: 0, s: 100, b: 100, alpha: 1 }),
props.colorSpace,
props.xChannel,
props.yChannel,
),
);
const x = computed(() => axes.value.color.getChannelValue(axes.value.x)),
y = computed(() => axes.value.color.getChannelValue(axes.value.y));
const xr = computed(() => axes.value.color.getChannelRange(axes.value.x)),
yr = computed(() => axes.value.color.getChannelRange(axes.value.y));
const percent = computed(() => ({
x: x.value / xr.value.maxValue,
y: y.value / yr.value.maxValue,
}));
const dragging = shallowRef(false);
let pointer: number | undefined;
let owner: HTMLElement | undefined;
let pointerWindow: Window | null | undefined;
function windowBlur() {
stop();
}
let grab = { x: 0, y: 0 };
const token = Symbol("color-area");
const keys = new Set<string>();
let lastPoint: string | undefined;
function stop(commit = false) {
pointerWindow?.removeEventListener("blur", windowBlur);
pointerWindow = undefined;
const target = owner,
id = pointer;
pointer = undefined;
owner = undefined;
dragging.value = false;
keys.clear();
lastPoint = undefined;
if (id !== undefined && target?.hasPointerCapture?.(id))
target.releasePointerCapture(id);
if (commit) state.end(token);
else state.cancel(token);
}
function local(event: PointerEvent) {
const node = root.value;
if (!node) return;
const rect = node.getBoundingClientRect(),
css = getComputedStyle(node);
const sx = rect.width / node.offsetWidth || 1,
sy = rect.height / node.offsetHeight || 1;
const left = (parseFloat(css.borderLeftWidth) || 0) * sx,
right = (parseFloat(css.borderRightWidth) || 0) * sx;
const top = (parseFloat(css.borderTopWidth) || 0) * sy,
bottom = (parseFloat(css.borderBottomWidth) || 0) * sy;
const width = rect.width - left - right,
height = rect.height - top - bottom;
if (width <= 0 || height <= 0) return;
return {
x: (event.clientX - rect.left - left) / width,
y: (event.clientY - rect.top - top) / height,
};
}
function update(point: { x: number; y: number }) {
let px = clamp(point.x - grab.x),
py = clamp(point.y - grab.y);
if (dir.value === "rtl") px = 1 - px;
const { color, x: xc, y: yc } = axes.value;
const pointKey = `${px}:${py}`;
if (pointKey === lastPoint) return;
lastPoint = pointKey;
state.request(
color
.withChannelValue(xc, px * xr.value.maxValue)
.withChannelValue(yc, (1 - py) * yr.value.maxValue),
token,
);
}
function pointerdown(event: PointerEvent) {
if (
event.defaultPrevented ||
event.button !== 0 ||
(event.pointerType === "mouse" &&
(event.ctrlKey || event.altKey || event.metaKey)) ||
event.isPrimary === false ||
pointer !== undefined ||
state.disabled.value ||
state.readOnly.value
)
return;
const point = local(event);
if (!point || !root.value) return;
stop();
if (!state.begin(token)) return;
pointer = event.pointerId;
owner = root.value;
pointerWindow = owner.ownerDocument.defaultView;
pointerWindow?.addEventListener("blur", windowBlur);
dragging.value = true;
const inThumb = !!(handle?.value ?? thumb.value)?.contains(
event.target as Node,
);
grab = inThumb
? {
x:
point.x -
(dir.value === "rtl" ? 1 - percent.value.x : percent.value.x),
y: point.y - (1 - percent.value.y),
}
: { x: 0, y: 0 };
// Capture the stable area, never the transient child that received pointerdown.
owner.setPointerCapture?.(event.pointerId);
event.preventDefault();
thumb.value?.focus({ preventScroll: true });
if (!inThumb) update(point);
}
function pointermove(event: PointerEvent) {
if (
event.defaultPrevented ||
event.pointerId !== pointer ||
!dragging.value
)
return;
const point = local(event);
if (point) {
event.preventDefault();
update(point);
}
}
function pointerup(event: PointerEvent) {
if (event.pointerId !== pointer) return;
if (!event.defaultPrevented) {
const point = local(event);
if (point) update(point);
}
stop(!event.defaultPrevented);
}
function cancel(event?: PointerEvent) {
if (!event || event.pointerId === pointer) stop();
}
function keydown(event: KeyboardEvent) {
if (
event.defaultPrevented ||
event.isComposing ||
event.ctrlKey ||
event.metaKey ||
event.altKey ||
state.disabled.value ||
state.readOnly.value
)
return;
if (event.key === "Escape") {
if (state.active.value === token) {
event.preventDefault();
stop();
}
return;
}
if (
![
"ArrowLeft",
"ArrowRight",
"ArrowUp",
"ArrowDown",
"Home",
"End",
"PageUp",
"PageDown",
].includes(event.key)
)
return;
if (pointer !== undefined) return;
const { color, x: xc, y: yc } = axes.value;
let xx = x.value,
yy = y.value;
const xStep = event.shiftKey ? xr.value.pageSize : xr.value.step;
const yStep = event.shiftKey ? yr.value.pageSize : yr.value.step;
const sign = dir.value === "rtl" ? -1 : 1;
if (event.key === "ArrowLeft") xx -= xStep * sign;
if (event.key === "ArrowRight") xx += xStep * sign;
if (event.key === "ArrowUp") yy += yStep;
if (event.key === "ArrowDown") yy -= yStep;
if (event.key === "PageUp") yy += yr.value.pageSize;
if (event.key === "PageDown") yy -= yr.value.pageSize;
if (event.key === "Home") xx -= xr.value.pageSize * sign;
if (event.key === "End") xx += xr.value.pageSize * sign;
if (state.active.value !== token && !state.begin(token)) return;
keys.add(event.key);
event.preventDefault();
focusedAxis.value = ["ArrowUp", "ArrowDown", "PageUp", "PageDown"].includes(
event.key,
)
? "y"
: "x";
(focusedAxis.value === "y" ? focusY.value : thumb.value)?.focus({
preventScroll: true,
});
state.request(
color.withChannelValue(xc, xx).withChannelValue(yc, yy),
token,
);
}
function keyup(event: KeyboardEvent) {
if (!keys.has(event.key)) return;
keys.delete(event.key);
if (event.defaultPrevented) stop();
else if (!keys.size) stop(true);
}
function input(axis: "x" | "y", event: Event) {
const target = event.target as HTMLInputElement;
if (
!event.defaultPrevented &&
!state.disabled.value &&
!state.readOnly.value &&
state.begin(token)
) {
const value = Number(target.value);
if (Number.isFinite(value))
state.request(
axes.value.color.withChannelValue(axes.value[axis], value),
token,
);
}
void nextTick(() => {
target.value = String(axis === "x" ? x.value : y.value);
});
}
watch(
[
state.disabled,
state.readOnly,
() =>
[props.colorSpace, props.xChannel, props.yChannel, dir.value].join("|"),
root,
thumb,
focusY,
() => handle?.value,
],
() => stop(),
{ flush: "sync" },
);
watch(
state.active,
(value) => {
if (value !== token && (pointer !== undefined || keys.size)) stop();
},
{ flush: "sync" },
);
useChoiceForm(
thumb,
() => {
stop();
state.reset();
},
() => {
if (thumb.value) thumb.value.value = String(x.value);
if (focusY.value) focusY.value.value = String(y.value);
},
);
onBeforeUnmount(() => stop());
return {
axes,
dir,
focusedAxis,
locale,
x,
y,
percent,
dragging,
pointerdown,
pointermove,
pointerup,
cancel,
keydown,
keyup,
input,
commit: () => stop(true),
blur: () => stop(true),
};
}
@@ -0,0 +1,68 @@
import {
colorAxes,
Color,
type ColorAxisChannel,
type ColorSpace,
} from "./value";
/** All six ordered channel pairs per space, including swapped axes and RTL.
* Layers follow the same numerical channel mapping as the pointer controller. */
export function colorAreaBackground(
value: Color,
space?: ColorSpace,
x?: ColorAxisChannel,
y?: ColorAxisChannel,
dir: "ltr" | "rtl" = "ltr",
) {
const a = colorAxes(value, space, x, y),
c = a.color.withAlpha(1),
xd = dir === "rtl" ? "to left" : "to right";
const direction = (channel: ColorAxisChannel) =>
a.x === channel ? xd : "to top";
if (a.space === "rgb") {
const z = c
.getChannels()
.find((channel) => channel !== a.x && channel !== a.y)!;
const black = new Color({ space: "rgb", r: 0, g: 0, b: 0, alpha: 1 });
const background = black
.withChannelValue(z, c.getChannelValue(z))
.toString("css");
const layer = (channel: ColorAxisChannel) =>
`linear-gradient(${direction(channel)}, #000000, ${black.withChannelValue(channel, 255).toString("css")})`;
return {
backgroundColor: background,
backgroundImage: `${layer(a.y)}, ${layer(a.x)}`,
backgroundBlendMode: "screen",
};
}
const channels = [a.x, a.y];
const hueAxis = channels.includes("hue");
const level = a.space === "hsb" ? "brightness" : "lightness";
const levelAxis = channels.includes(level);
const satAxis = channels.includes("saturation");
let base = c;
if (levelAxis)
base = base.withChannelValue(level, a.space === "hsb" ? 100 : 50);
if (satAxis) base = base.withChannelValue("saturation", 100);
const layers: string[] = [];
if (levelAxis)
layers.push(
a.space === "hsb"
? `linear-gradient(${direction(level)}, #000000, transparent)`
: `linear-gradient(${direction(level)}, #000000, transparent 50%, #ffffff)`,
);
if (satAxis) {
const gray = base.withChannelValue("saturation", 0).toString("css");
layers.push(
`linear-gradient(${direction("saturation")}, ${gray}, transparent)`,
);
}
if (hueAxis)
layers.push(
`linear-gradient(${direction("hue")}, ${[0, 60, 120, 180, 240, 300, 360].map((h) => base.withChannelValue("hue", h).toString("css")).join(", ")})`,
);
return {
backgroundColor: base.toString("css"),
backgroundImage: layers.join(", "),
backgroundBlendMode: "normal",
};
}
+202
View File
@@ -0,0 +1,202 @@
import {
computed,
getCurrentInstance,
inject,
onBeforeUnmount,
onBeforeUpdate,
provide,
shallowRef,
watch,
type ComputedRef,
type InjectionKey,
} from "vue";
import { useChoiceValue } from "../choice/shared";
import { useInheritedDisabled } from "../field/disabled";
import { Color, copyColor, colorKey, type ColorValue } from "./value";
export interface ColorModelProps {
modelValue?: ColorValue | null;
value?: ColorValue | null;
defaultValue?: ColorValue | null;
isDisabled?: boolean;
disabled?: boolean;
isReadOnly?: boolean;
}
export interface ColorState {
value: ComputedRef<Color | null>;
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
active: ComputedRef<symbol | undefined>;
begin: (source: symbol) => boolean;
request: (value: Color | null, source?: symbol) => boolean;
end: (source: symbol) => void;
cancel: (source?: symbol) => void;
reset: () => void;
}
const colorStateKey: InjectionKey<ColorState> = Symbol("hv-color-state");
/** Read-only display parts may consume the nearest owner without creating one. */
export function useColorStateContext() {
return inject(colorStateKey, undefined);
}
/** A single accepted color owner. Children inherit only when they omit all own values. */
export function useColorState(
props: ColorModelProps,
options: {
fallback: () => Color | null;
inherit?: boolean;
provide?: boolean;
change: (value: Color | null) => void;
changeEnd?: (value: Color | null) => void;
},
): ColorState {
const instance = getCurrentInstance()!;
const own = () =>
[
"modelValue",
"model-value",
"value",
"defaultValue",
"default-value",
].some((k) => Object.hasOwn(instance.vnode.props ?? {}, k));
const ownValue = shallowRef(own());
onBeforeUpdate(() => {
ownValue.value = own();
});
const parent = useColorStateContext();
const localDisabled = useInheritedDisabled(
() => props.isDisabled || props.disabled,
);
const disabled = computed(
() => localDisabled.value || !!(options.inherit && parent?.disabled.value),
);
const readOnly = computed(
() => !!props.isReadOnly || !!(options.inherit && parent?.readOnly.value),
);
const has = (key: string) => Object.hasOwn(instance.vnode.props ?? {}, key);
const model = useChoiceValue<Color | null>(
() =>
copyColor(
has("modelValue") || has("model-value")
? props.modelValue
: props.value,
),
() =>
copyColor(
props.defaultValue === undefined
? options.fallback()
: props.defaultValue,
),
["modelValue", "model-value", "value"],
(value) => options.change(copyColor(value)),
);
const source = shallowRef<symbol>();
let proposal: Color | null | undefined;
const inherited = computed(
() => !!(options.inherit && parent && !ownValue.value),
);
const value = computed(() =>
copyColor(inherited.value ? parent!.value.value : model.value.value),
);
const active = computed(() =>
inherited.value ? parent!.active.value : source.value,
);
const delegated = new Map<symbol, ColorState>();
function clearDelegated() {
for (const [token, owner] of delegated) {
delegated.delete(token);
owner.cancel(token);
}
}
const state: ColorState = {
value,
disabled,
readOnly,
active,
begin(token) {
if (disabled.value || readOnly.value) return false;
if (inherited.value) {
if (!parent!.begin(token)) return false;
delegated.set(token, parent!);
return true;
}
source.value = token;
proposal = undefined;
return true;
},
request(next, token) {
if (disabled.value || readOnly.value || (token && active.value !== token))
return false;
const copied = copyColor(next);
if (inherited.value) return parent!.request(copied, token);
if (!token) state.cancel();
if (colorKey(model.value.value) === colorKey(copied)) return false;
if (token) proposal = copyColor(copied);
model.request(copyColor(copied));
return true;
},
end(token) {
const owner = delegated.get(token);
if (owner) {
delegated.delete(token);
owner.end(token);
return;
}
if (inherited.value) return;
if (source.value !== token) return;
const last = copyColor(proposal);
const changed = proposal !== undefined;
source.value = undefined;
proposal = undefined;
if (changed && !disabled.value && !readOnly.value)
options.changeEnd?.(last);
},
cancel(token) {
if (token) {
const owner = delegated.get(token);
if (owner) {
delegated.delete(token);
owner.cancel(token);
return;
}
} else clearDelegated();
if (inherited.value) return;
if (token && source.value !== token) return;
source.value = undefined;
proposal = undefined;
},
reset() {
if (inherited.value) return;
state.cancel();
model.reset();
},
};
// Parent acceptance is allowed during an interaction; unrelated replacements abort it.
watch(
() => colorKey(model.value.value),
(key) => {
if (source.value && key !== colorKey(proposal)) state.cancel();
},
{ flush: "sync" },
);
watch(
[disabled, readOnly],
([off, ro]) => {
if (off || ro) state.cancel();
},
{ flush: "sync" },
);
watch(
inherited,
() => {
clearDelegated();
source.value = undefined;
proposal = undefined;
},
{ flush: "sync" },
);
onBeforeUnmount(() => {
clearDelegated();
if (!inherited.value) state.cancel();
});
if (options.provide) provide(colorStateKey, state);
return state;
}
+324
View File
@@ -0,0 +1,324 @@
import {
convertToRgb,
convertToHsl,
convertToHsb,
parseColor as parseWireColor,
type Color as WireColor,
type ColorSpace,
type ColorChannel,
} from "reka-ui";
export type { ColorSpace, ColorChannel } from "reka-ui";
export type ColorFormat =
ColorSpace | "css" | "hex" | "hexa" | "rgba" | "hsla" | "hsba";
export type ColorAxisChannel = Exclude<ColorChannel, "alpha">;
const channels: Record<ColorSpace, readonly ColorAxisChannel[]> = {
rgb: ["red", "green", "blue"],
hsl: ["hue", "saturation", "lightness"],
hsb: ["hue", "saturation", "brightness"],
};
const keys = {
red: "r",
green: "g",
blue: "b",
hue: "h",
saturation: "s",
lightness: "l",
brightness: "b",
alpha: "alpha",
} as const;
function finite(value: number) {
if (!Number.isFinite(value))
throw new RangeError("Color channels must be finite.");
return value;
}
const clamp = (value: number, max: number) =>
Math.min(max, Math.max(0, finite(value)));
const round = (value: number) => Math.round(value * 100) / 100;
/** Immutable library color boundary; accepted state is never serialized through hex. */
export class Color {
readonly #value: WireColor;
constructor(value: WireColor) {
const alpha = clamp(value.alpha, 1);
if (value.space === "rgb")
this.#value = {
space: "rgb",
r: clamp(value.r, 255),
g: clamp(value.g, 255),
b: clamp(value.b, 255),
alpha,
};
else if (value.space === "hsl")
this.#value = {
space: "hsl",
h: clamp(value.h, 360),
s: clamp(value.s, 100),
l: clamp(value.l, 100),
alpha,
};
else if (value.space === "hsb")
this.#value = {
space: "hsb",
h: clamp(value.h, 360),
s: clamp(value.s, 100),
b: clamp(value.b, 100),
alpha,
};
else throw new RangeError("Unknown color space.");
Object.freeze(this);
}
clone() {
return new Color(this.#value);
}
getColorSpace() {
return this.#value.space;
}
getChannels() {
return [...channels[this.#value.space]];
}
getColorChannels() {
return this.getChannels();
}
getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {
this.getChannelRange(channel);
return channel === "hue"
? { style: "unit", unit: "degree", unitDisplay: "narrow" }
: channel === "alpha" ||
["saturation", "lightness", "brightness"].includes(channel)
? { style: "percent" }
: { style: "decimal" };
}
formatChannelValue(channel: ColorChannel, locale: string) {
const raw = this.getChannelValue(channel);
return new Intl.NumberFormat(
locale,
this.getChannelFormatOptions(channel),
).format(
["saturation", "lightness", "brightness"].includes(channel)
? raw / 100
: raw,
);
}
/** Internal conversion bridge, omitted from the public Color instance type. */
static toWire(value: Color): WireColor {
return { ...value.#value };
}
toFormat(space: ColorSpace): Color {
const v = this.#value;
if (space === v.space) return this.clone();
// Direct polar conversion retains the hue even at black/white/gray.
if (v.space === "hsb" && space === "hsl") {
const b = v.b / 100,
s = v.s / 100,
l = b * (1 - s / 2);
return new Color({
space: "hsl",
h: v.h,
s: l === 0 || l === 1 ? 0 : ((b - l) / Math.min(l, 1 - l)) * 100,
l: l * 100,
alpha: v.alpha,
});
}
if (v.space === "hsl" && space === "hsb") {
const l = v.l / 100,
b = l + (v.s / 100) * Math.min(l, 1 - l);
return new Color({
space: "hsb",
h: v.h,
s: b === 0 ? 0 : 2 * (1 - l / b) * 100,
b: b * 100,
alpha: v.alpha,
});
}
return new Color(
space === "rgb"
? convertToRgb(v)
: space === "hsl"
? convertToHsl(v)
: space === "hsb"
? convertToHsb(v)
: (() => {
throw new RangeError("Unknown color space.");
})(),
);
}
getChannelRange(channel: ColorChannel) {
if (channel === "alpha")
return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
if (!this.getChannels().includes(channel))
throw new RangeError(
`Channel ${channel} is not in ${this.getColorSpace()}.`,
);
return {
minValue: 0,
maxValue:
channel === "hue" ? 360 : this.#value.space === "rgb" ? 255 : 100,
step: 1,
pageSize: channel === "hue" ? 15 : this.#value.space === "rgb" ? 17 : 10,
};
}
getChannelValue(channel: ColorChannel): number {
this.getChannelRange(channel);
return (this.#value as unknown as Record<string, number>)[keys[channel]]!;
}
withChannelValue(channel: ColorChannel, value: number): Color {
const range = this.getChannelRange(channel);
return new Color({
...this.#value,
[keys[channel]]: clamp(value, range.maxValue),
});
}
withAlpha(value: number) {
return this.withChannelValue("alpha", value);
}
equals(other: Color) {
return colorKey(this) === colorKey(other);
}
toString(format: ColorFormat = "css"): string {
if (
![
"rgb",
"hsl",
"hsb",
"css",
"hex",
"hexa",
"rgba",
"hsla",
"hsba",
].includes(format)
)
throw new RangeError("Unknown color format.");
const alpha = this.#value.alpha;
if (format === "hex" || format === "hexa") {
const v = this.toFormat("rgb").#value as Extract<
WireColor,
{ space: "rgb" }
>;
const hex = (n: number) =>
Math.round(n).toString(16).padStart(2, "0").toUpperCase();
return `#${hex(v.r)}${hex(v.g)}${hex(v.b)}${format === "hexa" ? hex(alpha * 255) : ""}`;
}
const space: ColorSpace = format.startsWith("hsl")
? "hsl"
: format.startsWith("hsb")
? "hsb"
: "rgb";
const value = this.toFormat(space);
const values = value
.getChannels()
.map((c) => round(value.getChannelValue(c)));
const withAlpha =
(format === "css" && alpha !== 1) ||
["rgba", "hsla", "hsba"].includes(format);
const suffix = withAlpha ? `, ${alpha}` : "";
if (space === "rgb")
return `rgb${withAlpha ? "a" : ""}(${values.map(Math.round).join(", ")}${suffix})`;
return `${space}${withAlpha ? "a" : ""}(${values[0]}, ${values[1]}%, ${values[2]}%${suffix})`;
}
}
export function colorKey(color: Color | null | undefined) {
return color ? JSON.stringify(Color.toWire(color)) : "empty";
}
export type ColorValue = string | Color;
export function parseColor(value: string): Color {
let text = value.trim();
if (/^#[\da-f]{4}$/i.test(text))
text = "#" + [...text.slice(1)].map((c) => c + c).join("");
if (text.startsWith("#")) return new Color(parseWireColor(text));
const match = /^(rgba?|hsla?|hsba?|hsva?)\((.*)\)$/i.exec(text);
if (!match) throw new RangeError(`Unsupported color: ${value}`);
if (
/,,|\/\s*\/|,\s*\)|^\s*[,\/]/.test(match[2]!) ||
(match[2]!.match(/\//g)?.length ?? 0) > 1
)
throw new RangeError(`Invalid color: ${value}`);
const name = match[1]!.toLowerCase();
// Comma forms and CSS space/slash forms are normalized before the public Reka parser.
const parts = match[2]!.trim().split(/[\s,\/]+/);
if (
parts.length < 3 ||
parts.length > 4 ||
parts.some((p) => !/^[-+]?(?:\d+\.?\d*|\.\d+)%?$/.test(p))
)
throw new RangeError(`Invalid color: ${value}`);
const rgb = name.startsWith("rgb");
const nums = parts.map((p, i) => {
const n = finite(Number.parseFloat(p));
return p.endsWith("%")
? i === 3
? n / 100
: rgb
? (n * 255) / 100
: n
: n;
});
if (!rgb && nums[0] !== 360) nums[0] = ((nums[0]! % 360) + 360) % 360;
const alpha = nums[3] ?? 1;
if (rgb)
return new Color({
space: "rgb",
r: nums[0]!,
g: nums[1]!,
b: nums[2]!,
alpha,
});
return new Color(
name.startsWith("hsl")
? { space: "hsl", h: nums[0]!, s: nums[1]!, l: nums[2]!, alpha }
: { space: "hsb", h: nums[0]!, s: nums[1]!, b: nums[2]!, alpha },
);
}
export function copyColor(value: ColorValue | null | undefined): Color | null {
if (value == null) return null;
if (typeof value === "string") return parseColor(value);
if (!(value instanceof Color))
throw new TypeError("Expected a color string or library Color.");
return value.clone();
}
export function colorAxes(
color: Color,
space?: ColorSpace,
x?: ColorAxisChannel,
y?: ColorAxisChannel,
) {
const working =
space ??
(x === "red" ||
x === "green" ||
x === "blue" ||
y === "red" ||
y === "green" ||
y === "blue"
? "rgb"
: x === "lightness" || y === "lightness"
? "hsl"
: x === "brightness" || y === "brightness"
? "hsb"
: color.getColorSpace() === "rgb"
? "hsb"
: color.getColorSpace());
const native = channels[working];
const xChannel = x ?? (working === "rgb" ? "red" : "saturation");
const yChannel =
y ??
native.find(
(c) =>
c !== xChannel &&
(c === "brightness" || c === "lightness" || c === "green"),
) ??
native.find((c) => c !== xChannel)!;
if (
xChannel === yChannel ||
!native.includes(xChannel) ||
!native.includes(yChannel)
)
throw new RangeError(
"ColorArea requires two different channels in the chosen color space.",
);
return {
space: working,
x: xChannel,
y: yChannel,
color: color.toFormat(working),
};
}
+164
View File
@@ -0,0 +1,164 @@
<script setup lang="ts">
import { computed, shallowRef, ref, useAttrs, useId } from "vue";
import {
useColorState,
type ColorModelProps,
} from "../../src/components/color/model";
import {
useColorArea,
type ColorAreaOptions,
} from "../../src/components/color/area";
import { colorAreaBackground } from "../../src/components/color/gradient";
import { parseColor, type Color } from "../../src/components/color/value";
defineOptions({ inheritAttrs: false });
const props = defineProps<ColorModelProps & ColorAreaOptions>();
const emit = defineEmits<{
"update:modelValue": [Color | null];
change: [Color | null];
changeEnd: [Color | null];
}>();
const attrs = useAttrs();
const state = useColorState(props, {
fallback: () => parseColor("hsb(240, 50%, 50%)"),
inherit: true,
change: (value) => {
emit("update:modelValue", value);
emit("change", value);
},
changeEnd: (value) => emit("changeEnd", value),
});
const root = shallowRef<HTMLElement>(),
thumb = shallowRef<HTMLInputElement>(),
handle = shallowRef<HTMLElement>(),
focusY = shallowRef<HTMLInputElement>();
const control = useColorArea(state, props, {
root,
focusX: thumb,
focusY,
thumb: handle,
});
const { axes, x, y, percent, dragging, dir, focusedAxis, locale } = control;
const background = computed(() =>
colorAreaBackground(
axes.value.color,
axes.value.space,
axes.value.x,
axes.value.y,
dir.value,
),
);
const disabled = state.disabled,
readonly = state.readOnly;
const id = useId();
const hidden = {
position: "absolute" as const,
width: "1px",
height: "1px",
overflow: "hidden",
clipPath: "inset(50%)",
};
const focusVisible = ref(false);
function onFocusin(event: FocusEvent) {
focusVisible.value = (event.target as HTMLElement).matches(":focus-visible");
}
function onFocusout(event: FocusEvent) {
if (!root.value?.contains(event.relatedTarget as Node | null)) {
focusVisible.value = false;
control.blur();
}
}
function axis(event: Event) {
const value = (event.target as HTMLElement).getAttribute("data-axis");
return value === "x" || value === "y" ? value : undefined;
}
function onKeydown(event: KeyboardEvent) {
const channel = axis(event);
if (channel) control.keydown(event);
}
function onInput(event: Event) {
const channel = axis(event);
if (channel) control.input(channel, event);
}
defineExpose({ state, control });
</script>
<template>
<div
ref="root"
v-bind="attrs"
class="hv-color-area"
data-color-area
role="group"
:dir="dir"
:aria-label="(attrs['aria-label'] as string) ?? 'Color area'"
:data-disabled="disabled || undefined"
:style="{
...background,
touchAction: disabled || readonly ? 'auto' : 'none',
}"
@keydown="onKeydown"
@keyup="control.keyup"
@input="onInput"
@change="control.commit"
@focusin="onFocusin"
@focusout="onFocusout"
@pointerdown="control.pointerdown"
@pointermove="control.pointermove"
@pointerup="control.pointerup"
@pointercancel="control.cancel"
@lostpointercapture="control.cancel"
>
<div
ref="handle"
class="hv-color-area__thumb"
data-color-thumb
:data-dragging="dragging || undefined"
:data-focus-visible="focusVisible || undefined"
:data-disabled="disabled || undefined"
:style="{
position: 'absolute',
left: `${(dir === 'rtl' ? 1 - percent.x : percent.x) * 100}%`,
top: `${(1 - percent.y) * 100}%`,
transform: 'translate(-50%,-50%)',
'--color-area-thumb-color': axes.color.toString('css'),
}"
>
<input
:id="`color-${id}-x`"
ref="thumb"
type="range"
step="any"
data-axis="x"
:tabindex="focusedAxis === 'x' ? 0 : -1"
:name="xName"
:form="form"
:aria-label="axes.x"
:aria-valuetext="axes.color.formatChannelValue(axes.x, locale)"
:min="0"
:max="axes.color.getChannelRange(axes.x).maxValue"
:value="x"
:disabled="disabled"
:aria-readonly="readonly || undefined"
:style="hidden"
/>
<input
:id="`color-${id}-y`"
type="range"
step="any"
data-axis="y"
ref="focusY"
:tabindex="focusedAxis === 'y' ? 0 : -1"
:name="yName"
:form="form"
:aria-label="axes.y"
:aria-valuetext="axes.color.formatChannelValue(axes.y, locale)"
aria-orientation="vertical"
:min="0"
:max="axes.color.getChannelRange(axes.y).maxValue"
:value="y"
:disabled="disabled"
:aria-readonly="readonly || undefined"
:style="hidden"
/>
</div>
</div>
</template>
+125
View File
@@ -0,0 +1,125 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import {
useColorState,
type ColorModelProps,
} from "../../src/components/color/model";
import { Color, parseColor, colorKey } from "../../src/components/color/value";
import { useChoiceForm } from "../../src/components/choice/shared";
import Area from "./ColorAreaFoundation.vue";
const props = defineProps<ColorModelProps & { name?: string; form?: string }>();
const emit = defineEmits<{
"update:modelValue": [Color | null];
change: [Color | null];
changeEnd: [Color | null];
}>();
const state = useColorState(props, {
fallback: () => parseColor("hsb(240,50%,50%)"),
provide: true,
change: (value) => {
emit("update:modelValue", value);
emit("change", value);
},
changeEnd: (value) => emit("changeEnd", value),
});
const value = state.value,
disabled = state.disabled,
readOnly = state.readOnly;
const text = ref(value.value?.toString("hexa") ?? ""),
native = ref<HTMLInputElement>();
const serialized = computed(() => value.value?.toString("hexa") ?? "");
useChoiceForm(native, state.reset, () => {});
watch(
() => colorKey(value.value),
() => {
text.value = value.value?.toString("hexa") ?? "";
},
);
const edit = Symbol("color-text");
function commit(event: Event) {
const input = event.currentTarget as HTMLInputElement;
try {
if (state.begin(edit)) {
state.request(input.value.trim() ? parseColor(input.value) : null, edit);
state.end(edit);
}
} catch {
state.cancel(edit);
}
text.value = value.value?.toString("hexa") ?? "";
input.value = text.value;
}
const hue = Symbol("color-hue");
function setHue(event: Event) {
const input = event.currentTarget as HTMLInputElement;
if (state.begin(hue))
state.request(
(value.value ?? parseColor("#ff0000"))
.toFormat("hsb")
.withChannelValue("hue", Number(input.value)),
hue,
);
input.value = String(
value.value?.toFormat("hsb").getChannelValue("hue") ?? 0,
);
}
defineExpose({ state });
</script>
<template>
<div data-color-picker-foundation>
<slot :value="value">
<Area
aria-label="Shared HSB area"
color-space="hsb"
x-channel="saturation"
y-channel="brightness"
/>
<input
data-color-hue
type="range"
step="any"
min="0"
max="360"
:value="value?.toFormat('hsb').getChannelValue('hue') ?? 0"
aria-label="Hue"
:disabled="disabled"
:aria-readonly="readOnly || undefined"
@input="setHue"
@change="state.end(hue)"
@pointercancel="state.cancel(hue)"
@blur="state.end(hue)"
/>
<input
data-color-text
aria-label="Hex color"
:value="text"
:disabled="disabled"
:readonly="readOnly"
@change="commit"
/>
<output data-color-output>
{{
value?.toString(
value.getChannelValue("alpha") === 1 ? "hsb" : "hsba",
) ?? "empty"
}}
</output>
<div
data-color-swatch
:style="{
width: '32px',
height: '32px',
background: value?.toString('css'),
}"
/>
</slot>
<input
ref="native"
type="hidden"
:name="name"
:form="form"
:disabled="disabled"
:value="serialized"
/>
</div>
</template>
+10
View File
@@ -0,0 +1,10 @@
// Installed-version probes use only public exports, resolved from the component package.
export {
ColorAreaRoot,
ColorAreaArea,
ColorAreaThumb,
parseColor,
getChannelRange,
getChannelValue,
getAreaBackgroundStyle,
} from "reka-ui";
+66
View File
@@ -0,0 +1,66 @@
import { describe, it, expect, afterEach } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent } from "vue";
import {
ColorAreaRoot,
ColorAreaArea,
ColorAreaThumb,
parseColor,
getChannelRange,
getChannelValue,
getAreaBackgroundStyle,
} from "../packages/vue/tests/fixtures/color-probe";
const wrappers: ReturnType<typeof mount>[] = [];
afterEach(() => {
wrappers.splice(0).forEach((w) => w.unmount());
});
function area() {
const w = mount(
defineComponent({
components: { ColorAreaRoot, ColorAreaArea, ColorAreaThumb },
template:
'<ColorAreaRoot model-value="hsb(240, 50%, 50%)" color-space="hsb" x-channel="saturation" y-channel="brightness"><ColorAreaArea><ColorAreaThumb/></ColorAreaArea></ColorAreaRoot>',
}),
);
wrappers.push(w);
return w;
}
describe("Reka 2.11 installed color capability audit (not public acceptance)", () => {
it("emits hex and leaves a rejected channel at its optimistic thumb position", async () => {
const w = area();
await w.get('[role="slider"]').trigger("keydown", { key: "ArrowRight" });
await flushPromises();
expect(
w.getComponent(ColorAreaRoot).emitted("update:modelValue")?.[0]?.[0],
).toMatch(/^#/);
expect(w.get('[role="slider"]').attributes("aria-valuenow")).toBe("51");
});
it("does not emit keyboard changeEnd after releasing an arrow", async () => {
const w = area();
await w.get('[role="slider"]').trigger("keydown", { key: "ArrowRight" });
await w.get('[role="slider"]').trigger("keyup", { key: "ArrowRight" });
expect(w.getComponent(ColorAreaRoot).emitted("changeEnd")).toBeUndefined();
});
it("uses percent alpha channel metadata while color storage uses a fraction", () => {
expect(getChannelRange("alpha").max).toBe(100);
expect(parseColor("#ff000080").alpha).toBeCloseTo(128 / 255);
});
it("loses achromatic HSB hue through the generic hue getter", () => {
expect(getChannelValue(parseColor("hsb(240, 0%, 50%)"), "hue")).toBe(0);
});
it("accepts functional trailing junk and out-of-range values without normalization", () => {
expect(parseColor("rgb(999, 0, 0) trailing")).toMatchObject({ r: 999 });
});
it("does not parse the four-digit alpha shorthand", () => {
expect(() => parseColor("#f008")).toThrow();
});
it("falls back to no hue layer when hue is the y axis", () => {
const style = getAreaBackgroundStyle(
parseColor("hsb(240, 50%, 50%)"),
"saturation",
"hue",
"hsb",
);
expect(style.backgroundImage).not.toContain("#ff0000, #ffff00");
});
});
+52
View File
@@ -0,0 +1,52 @@
// @vitest-environment node
import { describe, it, expect } from "vitest";
import { createSSRApp, defineComponent, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import Picker from "../packages/vue/tests/fixtures/ColorPickerFoundation.vue";
import Area from "../packages/vue/tests/fixtures/ColorAreaFoundation.vue";
import { parseColor } from "../packages/vue/src/components/color/value";
describe("private color foundation actual Node SSR", () => {
it("renders accepted polar values, two native axes and one submission without browser globals", async () => {
const html = await renderToString(
createSSRApp(
defineComponent({
render: () =>
h(Picker, {
defaultValue: parseColor("hsb(270,0%,50%,.5)"),
name: "color",
}),
}),
),
);
expect(html).toContain("hsba(270, 0%, 50%, 0.5)");
expect(html).toContain('aria-label="saturation"');
expect(html).toContain('aria-label="brightness"');
expect(html.match(/name="color"/g)).toHaveLength(1);
expect(html).not.toContain('role="application"');
});
it("renders a swapped hue axis and RGB area deterministically", async () => {
const html = await renderToString(
createSSRApp(
defineComponent({
render: () =>
h("main", [
h(Area, {
defaultValue: "hsb(240,50%,50%)",
xChannel: "brightness",
yChannel: "hue",
colorSpace: "hsb",
}),
h(Area, {
defaultValue: "#123456",
colorSpace: "rgb",
dir: "rtl",
}),
]),
}),
),
);
expect(html).toContain("background-blend-mode:screen");
expect(html).toContain("linear-gradient(to top, rgb");
expect(html).not.toContain("NaN");
});
});
+565
View File
@@ -0,0 +1,565 @@
import { afterEach, describe, it, expect, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, shallowRef, createSSRApp } from "vue";
import { renderToString } from "@vue/server-renderer";
import Area from "../packages/vue/tests/fixtures/ColorAreaFoundation.vue";
import Picker from "../packages/vue/tests/fixtures/ColorPickerFoundation.vue";
import {
Color,
parseColor,
colorAxes,
copyColor,
} from "../packages/vue/src/components/color/value";
import { colorAreaBackground } from "../packages/vue/src/components/color/gradient";
const wrappers: ReturnType<typeof mount>[] = [];
afterEach(() => {
wrappers.splice(0).forEach((w) => w.unmount());
document.body.innerHTML = "";
vi.restoreAllMocks();
});
function fixture(attrs = "", setup = () => ({}), children = "") {
const w = mount(
defineComponent({
components: { Area, Picker },
setup,
template: `<form><Picker name="color" ${attrs}>${children}</Picker></form>`,
}),
{ attachTo: document.body },
);
wrappers.push(w);
return w;
}
const events = (w: ReturnType<typeof mount>) =>
(w.getComponent(Picker).emitted("change") ?? []).map(
([v]) => v as Color | null,
);
const ends = (w: ReturnType<typeof mount>) =>
w.getComponent(Picker).emitted("changeEnd") ?? [];
const x = (w: ReturnType<typeof mount>) =>
w.get<HTMLInputElement>('[data-axis="x"]');
const y = (w: ReturnType<typeof mount>) =>
w.get<HTMLInputElement>('[data-axis="y"]');
async function key(
w: ReturnType<typeof mount>,
key: string,
up = true,
extra = {},
axis = "x",
) {
const input = w.get(`[data-axis="${axis}"]`);
await input.trigger("keydown", { key, ...extra });
if (up) await input.trigger("keyup", { key, ...extra });
await flushPromises();
}
const data = (w: ReturnType<typeof mount>) =>
new FormData(w.get("form").element as HTMLFormElement).getAll("color");
function geometry(w: ReturnType<typeof mount>, selector = "[data-color-area]") {
const node = w.get<HTMLElement>(selector).element;
let captured: number | undefined;
Object.defineProperties(node, {
offsetWidth: { get: () => 224, configurable: true },
offsetHeight: { get: () => 224, configurable: true },
});
vi.spyOn(node, "getBoundingClientRect").mockReturnValue({
left: 0,
top: 0,
width: 224,
height: 224,
right: 224,
bottom: 224,
x: 0,
y: 0,
toJSON: () => ({}),
});
node.setPointerCapture = vi.fn((id) => {
captured = id;
});
node.hasPointerCapture = vi.fn((id) => captured === id);
node.releasePointerCapture = vi.fn(() => {
captured = undefined;
});
return node;
}
async function pointer(node: Element, type: string, extra = {}) {
const e = new Event(type, { bubbles: true, cancelable: true });
Object.assign(e, {
pointerId: 1,
pointerType: "mouse",
isPrimary: true,
button: 0,
clientX: 112,
clientY: 112,
...extra,
});
node.dispatchEvent(e);
await flushPromises();
return e;
}
describe("immutable private color value boundary", () => {
it("parses shorthand alpha, comma and CSS space/slash forms without using DOM", () => {
expect(parseColor("#f008").toString("hexa")).toBe("#FF000088");
expect(parseColor("rgb(100% 0% 0% / 50%)").toString("rgba")).toBe(
"rgba(255, 0, 0, 0.5)",
);
expect(parseColor("hsl(-120, 100%, 50%)").toString("hex")).toBe("#0000FF");
expect(parseColor("hsva(240, 100%, 100%, .25)").getColorSpace()).toBe(
"hsb",
);
});
it("rejects malformed/trailing/non-finite values, unsupported names and foreign objects", () => {
for (const value of [
"rgb(1,2,3) junk",
"rgb(1,,2,3)",
"hsl(NaN 0% 0%)",
"rebeccapurple",
"var(--accent)",
"#12",
"rgb(1 2)",
])
expect(() => parseColor(value)).toThrow();
expect(
() => new Color({ space: "rgb", r: Infinity, g: 0, b: 0, alpha: 1 }),
).toThrow();
expect(() =>
copyColor({
space: "rgb",
r: 0,
g: 0,
b: 0,
alpha: 1,
} as unknown as Color),
).toThrow();
});
it("clamps finite inputs and keeps fractional channels internally", () => {
const value = parseColor("hsb(240, 23.45678%, 70.12345%, 0.4321)");
expect(value.getChannelValue("saturation")).toBe(23.45678);
expect(
value.withChannelValue("saturation", 200).getChannelValue("saturation"),
).toBe(100);
expect(value.withAlpha(-1).getChannelValue("alpha")).toBe(0);
expect(value.getChannelRange("alpha")).toMatchObject({
maxValue: 1,
step: 0.01,
});
});
it("keeps black/gray hue, converts polar spaces directly and never mutates a parent", () => {
const original = parseColor("hsb(270, 0%, 50%)");
expect(original.toFormat("hsl").getChannelValue("hue")).toBe(270);
const next = original.withChannelValue("saturation", 100);
expect(next.toString("hex")).toBe("#400080");
expect(original.getChannelValue("saturation")).toBe(0);
const wire = Color.toWire(original);
wire.alpha = 0;
expect(original.getChannelValue("alpha")).toBe(1);
expect(Object.isFrozen(original)).toBe(true);
});
it("round trips representative RGB/HSL/HSB colors without hex quantization", () => {
for (const raw of [
"rgb(12.25, 69.125, 223.75, .12345)",
"hsl(207.5, 72.25%, 41.125%, .75)",
"hsb(342.25, 70.125%, 88.75%)",
]) {
const color = parseColor(raw).toFormat("rgb");
for (const space of ["hsl", "hsb"] as const) {
const restored = color.toFormat(space).toFormat("rgb");
for (const channel of ["red", "green", "blue", "alpha"] as const)
expect(restored.getChannelValue(channel)).toBeCloseTo(
color.getChannelValue(channel),
7,
);
}
}
});
it("resolves legal space defaults and rejects duplicate/mismatched axes", () => {
expect(colorAxes(parseColor("#f00"))).toMatchObject({
space: "hsb",
x: "saturation",
y: "brightness",
});
expect(colorAxes(parseColor("#f00"), "rgb")).toMatchObject({
x: "red",
y: "green",
});
expect(() =>
colorAxes(parseColor("#f00"), "hsl", "saturation", "saturation"),
).toThrow();
expect(() => colorAxes(parseColor("#f00"), "rgb", "hue", "blue")).toThrow();
});
it("builds every ordered axis pair in three spaces with real nonempty gradients", () => {
for (const space of ["rgb", "hsl", "hsb"] as const) {
const c = parseColor("hsb(210,60%,70%)").toFormat(space);
for (const a of c.getChannels())
for (const b of c.getChannels()) {
if (a === b) continue;
const style = colorAreaBackground(c, space, a, b);
expect(style.backgroundImage).toContain("linear-gradient");
expect(style.backgroundImage).not.toContain("NaN");
if (a === "hue" || b === "hue")
expect(style.backgroundImage.split("rgb").length).toBeGreaterThan(
6,
);
}
}
});
it("orients reversed axes and RTL backgrounds consistently with coordinates", () => {
const c = parseColor("hsb(240,50%,50%)");
expect(
colorAreaBackground(c, "hsb", "brightness", "saturation").backgroundImage,
).toContain("linear-gradient(to right, #000000, transparent)");
expect(
colorAreaBackground(c, "hsb", "saturation", "brightness", "rtl")
.backgroundImage,
).toContain("linear-gradient(to left, rgb(255, 255, 255), transparent)");
});
});
describe("one accepted color owner for picker children", () => {
it("shares area, hue, text and swatch state and creates only one native submission", async () => {
const w = fixture();
await key(w, "ArrowRight");
expect(events(w)).toHaveLength(1);
expect(x(w).element.value).toBe("51");
expect(w.get("[data-color-output]").text()).toBe("hsb(240, 51%, 50%)");
expect(data(w)).toHaveLength(1);
expect(w.findAll('[name="color"]')).toHaveLength(1);
expect(ends(w)).toHaveLength(1);
});
it("restores rejected coordinates, siblings and native values and allows identical retries", async () => {
const value = parseColor("hsb(240,50%,50%)");
const w = fixture(':model-value="value"', () => ({ value }));
for (let i = 0; i < 2; i++) await key(w, "ArrowRight");
expect(events(w).map((v) => v!.getChannelValue("saturation"))).toEqual([
51, 51,
]);
expect(x(w).element.value).toBe("50");
expect(ends(w)).toHaveLength(2);
expect((ends(w)[0]![0] as Color).getChannelValue("saturation")).toBe(51);
expect(data(w)).toEqual([value.toString("hexa")]);
});
it("preserves gray hue across a sibling hue change and area saturation edit", async () => {
const w = fixture('default-value="hsb(240,0%,50%)"');
const hue = w.get<HTMLInputElement>("[data-color-hue]");
hue.element.value = "270";
await hue.trigger("input");
await hue.trigger("change");
x(w).element.value = "100";
await x(w).trigger("input");
await x(w).trigger("change");
expect(events(w).at(-1)!.toString("hex")).toBe("#400080");
expect(w.get("[data-color-output]").text()).toContain("270");
});
it("keeps keyboard repetitions in one transaction and commits once after release", async () => {
const w = fixture();
await key(w, "ArrowRight", false);
await key(w, "ArrowRight", false, { repeat: true });
expect(ends(w)).toHaveLength(0);
await x(w).trigger("keyup", { key: "ArrowRight" });
expect(ends(w)).toHaveLength(1);
expect(x(w).element.value).toBe("52");
});
it("supports each native axis, Home/End, page keys, shift and RTL", async () => {
const w = fixture("", () => ({}), '<Area dir="rtl" color-space="hsb"/>');
await key(w, "ArrowRight");
expect(x(w).element.value).toBe("49");
await key(w, "ArrowUp", true, { shiftKey: true }, "y");
expect(y(w).element.value).toBe("60");
await key(w, "PageDown", true, {}, "y");
expect(y(w).element.value).toBe("50");
await key(w, "Home");
expect(x(w).element.value).toBe("59");
await key(w, "End");
expect(x(w).element.value).toBe("49");
});
it("honors native consumer cancellation and disabled/readonly inherited permissions", async () => {
const w = fixture("", () => ({}), "<Area @keydown.prevent/>");
await key(w, "ArrowRight");
expect(events(w)).toHaveLength(0);
for (const attrs of ["is-disabled", "is-read-only"]) {
const other = fixture(attrs);
await key(other, "ArrowRight");
expect(events(other)).toHaveLength(0);
}
});
it("keeps model precision and serializes an explicit hexa form boundary", async () => {
const value = parseColor("hsb(240,50.123%,50.567%,.321)");
const w = fixture(':default-value="value"', () => ({ value }));
expect(x(w).element.value).toBe("50.123");
await key(w, "ArrowUp", true, {}, "y");
expect(events(w)[0]!.getChannelValue("alpha")).toBe(0.321);
expect(events(w)[0]!.getChannelValue("saturation")).toBe(50.123);
expect(data(w)).toEqual([events(w)[0]!.toString("hexa")]);
});
it("cancels keyboard transaction on external replacement and does not end a stale gesture", async () => {
const value = shallowRef(parseColor("hsb(240,50%,50%)"));
const w = fixture('v-model="value"', () => ({ value }));
await key(w, "ArrowRight", false);
value.value = parseColor("hsb(90,25%,75%)");
await flushPromises();
await x(w).trigger("keyup", { key: "ArrowRight" });
expect(ends(w)).toHaveLength(0);
expect(x(w).element.value).toBe("25");
});
it("allows a child to opt out with an explicit value, then inherit again when removed", async () => {
const props = shallowRef<Record<string, unknown>>({
modelValue: "hsb(10,20%,30%)",
});
const w = fixture("", () => ({ props }), '<Area v-bind="props"/>');
await key(w, "ArrowRight");
expect(events(w)).toHaveLength(0);
expect(x(w).element.value).toBe("20");
props.value = {};
await flushPromises();
await key(w, "ArrowRight");
expect(events(w)).toHaveLength(1);
expect(x(w).element.value).toBe("51");
});
it("resets one owner and all children, with cancelled and controlled reset preserved", async () => {
const w = fixture();
await key(w, "ArrowRight");
(w.get("form").element as HTMLFormElement).reset();
await flushPromises();
expect(x(w).element.value).toBe("50");
expect(events(w)).toHaveLength(1);
w.get("form").element.addEventListener("reset", (e) => e.preventDefault());
await key(w, "ArrowRight");
(w.get("form").element as HTMLFormElement).reset();
await flushPromises();
expect(x(w).element.value).toBe("51");
const value = shallowRef(parseColor("hsb(20,30%,40%)"));
const controlled = fixture('v-model="value"', () => ({ value }));
await key(controlled, "ArrowRight");
(controlled.get("form").element as HTMLFormElement).reset();
await flushPromises();
expect(x(controlled).element.value).toBe("31");
});
it("rejects invalid text and restores a controlled native range input after AT input", async () => {
const w = fixture('model-value="hsb(240,50%,50%)"');
const text = w.get<HTMLInputElement>("[data-color-text]");
await text.setValue("rgb(1,2,3)junk");
expect(events(w)).toHaveLength(0);
expect(text.element.value).toBe("#404080FF");
x(w).element.value = "80";
await x(w).trigger("input");
await x(w).trigger("change");
await flushPromises();
expect(x(w).element.value).toBe("50");
expect(events(w)).toHaveLength(1);
expect(ends(w)).toHaveLength(1);
});
});
describe("private color area pointer ownership", () => {
it("captures the stable root, ignores other pointers and commits the last proposal once", async () => {
const w = fixture();
const root = geometry(w);
await pointer(root, "pointerdown", { clientX: 56, clientY: 56 });
await pointer(root, "pointermove", {
clientX: 168,
clientY: 112,
pointerId: 2,
});
await pointer(root, "pointermove", { clientX: 168, clientY: 112 });
await pointer(root, "pointerup", { clientX: 168, clientY: 112 });
expect(root.setPointerCapture).toHaveBeenCalledWith(1);
expect(events(w).map((v) => v!.getChannelValue("saturation"))).toEqual([
25, 75,
]);
expect(ends(w)).toHaveLength(1);
expect(root.releasePointerCapture).toHaveBeenCalledWith(1);
});
it("retains thumb grab offset and releases capture on lost/cancelled/disabled/unmounted interactions", async () => {
const disabled = shallowRef(false);
const w = fixture(':is-disabled="disabled"', () => ({ disabled }));
const root = geometry(w);
const handle = w.get("[data-color-thumb]").element;
await pointer(handle, "pointerdown", { clientX: 116, clientY: 116 });
expect(events(w)).toHaveLength(0);
await pointer(root, "pointermove", { clientX: 138.4, clientY: 116 });
expect(events(w)[0]!.getChannelValue("saturation")).toBeCloseTo(60);
await pointer(root, "pointercancel");
expect(ends(w)).toHaveLength(0);
await pointer(root, "pointerdown");
disabled.value = true;
await flushPromises();
expect(root.releasePointerCapture).toHaveBeenCalled();
expect(ends(w)).toHaveLength(0);
disabled.value = false;
await flushPromises();
await pointer(root, "pointerdown");
w.unmount();
expect(root.hasPointerCapture?.(1)).toBe(false);
});
it("preserves the accepted thumb under rejected pointer updates and retries on a new drag", async () => {
const w = fixture('model-value="hsb(240,50%,50%)"');
const root = geometry(w);
for (let n = 0; n < 2; n++) {
await pointer(root, "pointerdown", { clientX: 168 });
await pointer(root, "pointerup", { clientX: 168 });
}
expect(events(w)).toHaveLength(2);
expect(ends(w)).toHaveLength(2);
expect(w.get("[data-color-thumb]").attributes("style")).toContain(
"left: 50%",
);
});
it("does not start from cancelled/nonprimary/right pointers and ignores zero geometry", async () => {
const w = fixture("", () => ({}), "<Area @pointerdown.prevent/>");
const root = geometry(w);
await pointer(root, "pointerdown");
expect(events(w)).toHaveLength(0);
expect(root.setPointerCapture).not.toHaveBeenCalled();
const other = fixture();
const node = geometry(other);
await pointer(node, "pointerdown", { button: 2 });
await pointer(node, "pointerdown", { isPrimary: false });
await pointer(node, "pointerdown", { ctrlKey: true });
vi.spyOn(node, "getBoundingClientRect").mockReturnValue({
left: 0,
top: 0,
width: 0,
height: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
toJSON: () => ({}),
});
await pointer(node, "pointerdown");
expect(events(other)).toHaveLength(0);
});
it("does not let a disabled sibling cancel another area's active capture", async () => {
const disabled = shallowRef(false);
const w = fixture(
"",
() => ({ disabled }),
'<Area data-first :is-disabled="disabled"/><Area data-second/>',
);
const second = geometry(w, "[data-second]");
await pointer(second, "pointerdown", { clientX: 168 });
disabled.value = true;
await flushPromises();
await pointer(second, "pointerup", { clientX: 168 });
expect(ends(w)).toHaveLength(1);
expect(second.releasePointerCapture).toHaveBeenCalledWith(1);
});
it("cancels the old provider gesture when a child switches to its own controlled owner", async () => {
const props = shallowRef<Record<string, unknown>>({});
const w = fixture("", () => ({ props }), '<Area v-bind="props"/>');
const root = geometry(w);
await pointer(root, "pointerdown", { clientX: 168 });
props.value = { modelValue: "hsb(20,30%,40%)" };
await flushPromises();
await pointer(root, "pointerup", { clientX: 168 });
expect(ends(w)).toHaveLength(0);
expect(w.getComponent(Picker).vm.state.active.value).toBeUndefined();
expect(root.hasPointerCapture?.(1)).toBe(false);
expect(x(w).element.value).toBe("30");
});
it("maps the content box correctly with different ancestor scales and borders", async () => {
const w = fixture();
const root = geometry(w);
root.style.border = "4px solid black";
vi.spyOn(root, "getBoundingClientRect").mockReturnValue({
left: 100,
top: 200,
width: 448,
height: 224,
right: 548,
bottom: 424,
x: 100,
y: 200,
toJSON: () => ({}),
});
await pointer(root, "pointerdown", { clientX: 216, clientY: 258 });
await pointer(root, "pointerup", { clientX: 216, clientY: 258 });
expect(events(w)[0]!.getChannelValue("saturation")).toBeCloseTo(25);
expect(events(w)[0]!.getChannelValue("brightness")).toBeCloseTo(75);
});
it("cancels capture on window blur without manufacturing changeEnd", async () => {
const w = fixture();
const root = geometry(w);
await pointer(root, "pointerdown");
window.dispatchEvent(new Event("blur"));
await flushPromises();
expect(root.hasPointerCapture?.(1)).toBe(false);
expect(ends(w)).toHaveLength(0);
});
it("uses two native named axes and restores an uncontrolled standalone area on reset", async () => {
const w = mount(
defineComponent({
components: { Area },
template:
'<form><Area default-value="hsb(240,50%,50%)" x-name="s" y-name="b"/></form>',
}),
{ attachTo: document.body },
);
wrappers.push(w);
await key(w, "ArrowUp");
const form = w.get("form").element as HTMLFormElement;
expect(new FormData(form).get("s")).toBe("50");
expect(new FormData(form).get("b")).toBe("51");
form.reset();
await flushPromises();
expect(x(w).element.value).toBe("50");
expect(y(w).element.value).toBe("50");
});
it("restores accepted native axes on controlled reset even when Vue props do not change", async () => {
const value = shallowRef("hsb(240,50%,50%)");
const w = mount(
defineComponent({
components: { Area },
setup: () => ({ value }),
template:
'<form><Area :model-value="value" x-name="s" y-name="b"/></form>',
}),
{ attachTo: document.body },
);
wrappers.push(w);
value.value = "hsb(240,70%,80%)";
await flushPromises();
(w.get("form").element as HTMLFormElement).reset();
await flushPromises();
expect(x(w).element.value).toBe("70");
expect(y(w).element.value).toBe("80");
expect(w.getComponent(Area).emitted("change")).toBeUndefined();
});
it("keeps one Tab entry and moves focus to the axis operated by the keyboard", async () => {
const w = fixture();
expect(x(w).attributes("tabindex")).toBe("0");
expect(y(w).attributes("tabindex")).toBe("-1");
await key(w, "ArrowUp");
expect(document.activeElement).toBe(y(w).element);
expect(x(w).attributes("tabindex")).toBe("-1");
expect(y(w).attributes("tabindex")).toBe("0");
await key(w, "ArrowRight", true, {}, "y");
expect(document.activeElement).toBe(x(w).element);
expect(x(w).element.value).toBe("51");
expect(y(w).element.value).toBe("51");
});
it("uses channel-specific page steps, alpha units and explicit formatted output", () => {
expect(parseColor("#123456").getChannelRange("red").pageSize).toBe(17);
const color = parseColor("hsb(240,50%,50%,.5)");
expect(color.getChannelRange("hue").pageSize).toBe(15);
expect(color.toString("hsb")).toBe("hsb(240, 50%, 50%)");
expect(color.toString("hsba")).toBe("hsba(240, 50%, 50%, 0.5)");
expect(color.formatChannelValue("alpha", "en-US")).toBe("50%");
});
it("hydrates actual multiple picker nodes without replacing them or sharing IDs", async () => {
const App = defineComponent({
components: { Picker },
template: "<main><Picker/><Picker/></main>",
});
const html = await renderToString(createSSRApp(App));
const container = document.createElement("div");
container.innerHTML = html;
document.body.append(container);
const before = container.querySelector("[data-color-area]");
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const app = createSSRApp(App);
app.mount(container);
await flushPromises();
expect(container.querySelector("[data-color-area]")).toBe(before);
const ids = [...container.querySelectorAll("[id]")].map((e) => e.id);
expect(new Set(ids).size).toBe(ids.length);
expect(warn).not.toHaveBeenCalled();
app.unmount();
});
});
+2
View File
@@ -29,3 +29,5 @@ M35–M36 使用 `consume-m35-m36.mjs` / `m35-m36-contract.ts`,新建 `/privat
DATE-03 新增 `consume-calendar.mjs` / `calendar-contract.ts`,安装两份新 tarball 后运行 Node ESM/SSR/CSS 与 NodeNext/bundler 类型正反例,保留 DateField/Select 回归。Calendar 的泛型 Root 使用实际 SFC 参数类型核对单选、事件推断与错误模型,Cell/YearPicker Props 和作用域插槽不能退化为 any。
DATE-04 提取共享 Calendar 视图并完成私有范围内核,公共 RangeCalendar 尚未导出。最终 tarball 在 `/private/tmp/heroui-range-core-consumer` 运行 Calendar/DateField/Select 的 ESM/SSR/CSS 与两种解析模式正反类型回归;私有范围的 node SSR / 实际水合在工作区测试,不能据此声明公共范围产物已验收。公开范围下一轮须新增自己的完整消费契约。
COLOR-01 增加 `consume-color-foundation.mjs`:只验证准备好的 Area CSS 和没有提前暴露公共占位。独立目录 `/private/tmp/heroui-color-foundation-consumer` 同时运行旧 Calendar/DateField/Select 的运行与双解析模式类型回归。新颜色实现目前私有,其正反类型在 `tests/types/color-foundation.ts` 执行;公开批次必须另加自己的完整 ESM/SSR/Props/events/slots 产物契约。
@@ -0,0 +1,18 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import * as ui from "@heroui-vue/components";
const css = fs.readFileSync(
new URL(import.meta.resolve("@heroui-vue/styles/css")),
"utf8",
);
assert.ok(css.includes(".hv-color-area"));
assert.ok(css.includes(".hv-color-area__thumb"));
assert.ok(css.includes("--color-area-thumb-color"));
assert.ok(css.includes("data-dragging"));
// The new implementation is deliberately private until public contracts and demos land.
assert.equal("ColorArea" in ui, false);
assert.equal("ColorPicker" in ui, false);
assert.equal("parseColor" in ui, false);
console.log(
"Color foundation tarball: staged CSS present, no public placeholder exports.",
);
+24
View File
@@ -0,0 +1,24 @@
import {
parseColor,
type ColorValue,
} from "../../packages/vue/src/components/color/value";
import type { ColorAreaOptions } from "../../packages/vue/src/components/color/area";
const color = parseColor("hsb(240,50%,50%)");
const value: ColorValue = color.withAlpha(0.5).toFormat("rgb");
const options: ColorAreaOptions = {
colorSpace: "rgb",
xChannel: "blue",
yChannel: "red",
};
void value;
void options;
// @ts-expect-error nonexistent channel
color.withChannelValue("opacity", 1);
// @ts-expect-error unsupported color format
color.toString("oklch");
// @ts-expect-error two-dimensional area axes exclude alpha
const alpha: ColorAreaOptions = { xChannel: "alpha" };
// @ts-expect-error no arbitrary foreign mutable plain object as library model
const foreign: ColorValue = { space: "rgb", r: 0, g: 0, b: 0, alpha: 1 };
void alpha;
void foreign;