feat: establish shared color state and area interaction foundation

This commit is contained in:
maoyingjie
2026-10-25 11:10:47 +08:00
parent 58ca16e774
commit 57d7cbb2d6
26 changed files with 2429 additions and 88 deletions
+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;