feat: establish color slider geometry and picker composition
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
import { afterEach, beforeEach, 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 Picker from "../packages/vue/tests/fixtures/ColorPickerComposition.vue";
|
||||
import { parseColor, Color } from "../packages/vue/src/components/color/value";
|
||||
import { serializeColorValue } from "../packages/vue/src/components/color/submission";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
beforeEach(() =>
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
},
|
||||
),
|
||||
);
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
await flushPromises();
|
||||
document.body.innerHTML = "";
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
function view(attrs = "", setup = () => ({})) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Picker },
|
||||
setup,
|
||||
template: `<form><Picker name="color" ${attrs}/></form>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const native = (w: ReturnType<typeof mount>) =>
|
||||
w.get<HTMLInputElement>("input[type=hidden]");
|
||||
const values = (w: ReturnType<typeof mount>) =>
|
||||
new FormData(w.get("form").element as HTMLFormElement).getAll("color");
|
||||
async function open(w: ReturnType<typeof mount>) {
|
||||
await w.get("button").trigger("click");
|
||||
await flushPromises();
|
||||
expect(document.querySelector("[role=dialog]")).not.toBeNull();
|
||||
}
|
||||
async function key(input: HTMLInputElement, key: string) {
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }),
|
||||
);
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keyup", { key, bubbles: true, cancelable: true }),
|
||||
);
|
||||
await flushPromises();
|
||||
}
|
||||
describe("private color owner and Popover composition", () => {
|
||||
it("restores a dirty text draft on Escape, then lets Escape close the popup", async () => {
|
||||
const w = view();
|
||||
await open(w);
|
||||
const text = document.querySelector<HTMLInputElement>(
|
||||
'[aria-label="Color hex text"]',
|
||||
)!;
|
||||
text.focus();
|
||||
text.value = "#abc";
|
||||
text.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await flushPromises();
|
||||
await key(text, "Escape");
|
||||
expect(document.querySelector("[role=dialog]")).not.toBeNull();
|
||||
expect(text.value).toBe("#808080");
|
||||
expect(w.getComponent(Picker).emitted("change")).toBeUndefined();
|
||||
await key(text, "Escape");
|
||||
expect(document.querySelector("[role=dialog]")).toBeNull();
|
||||
expect(document.activeElement).toBe(w.get("button").element);
|
||||
});
|
||||
|
||||
it("serializes all spaces without numeric precision loss or an 8-bit alpha round trip", () => {
|
||||
for (const c of [
|
||||
parseColor("hsba(270,0%,50%,.123456789012345)"),
|
||||
parseColor(
|
||||
"hsla(21.123456789,67.987654321%,45.333333333%,.23456789012345)",
|
||||
),
|
||||
new Color({
|
||||
space: "rgb",
|
||||
r: 0.00000001,
|
||||
g: 2.3456789012345,
|
||||
b: 255,
|
||||
alpha: 5e-324,
|
||||
}),
|
||||
])
|
||||
expect(parseColor(serializeColorValue(c)).equals(c)).toBe(true);
|
||||
expect(serializeColorValue(null)).toBe("");
|
||||
});
|
||||
it("has one named submission while closed and with every popup child mounted", async () => {
|
||||
const w = view();
|
||||
expect(values(w)).toEqual(["hsba(270, 0%, 50%, 0.123456789)"]);
|
||||
await open(w);
|
||||
expect(document.querySelectorAll("input[name=color]")).toHaveLength(1);
|
||||
expect(document.querySelectorAll("[role=dialog]")).toHaveLength(1);
|
||||
expect(native(w).element.value).toBe("hsba(270, 0%, 50%, 0.123456789)");
|
||||
});
|
||||
it("updates hue and alpha through Teleport while preserving gray hue and one owner", async () => {
|
||||
const w = view();
|
||||
await open(w);
|
||||
const sliders = document.querySelectorAll<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
);
|
||||
await key(sliders[0]!, "ArrowUp");
|
||||
const text = document.querySelector<HTMLInputElement>(
|
||||
'[aria-label="Color alpha text"]',
|
||||
)!;
|
||||
text.value = "25";
|
||||
text.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await key(text, "Enter");
|
||||
const c = parseColor(String(values(w)[0]));
|
||||
expect(c.getChannelValue("hue")).toBe(271);
|
||||
expect(c.getChannelValue("alpha")).toBe(0.25);
|
||||
expect(sliders[1]!.value).toBe("0.25");
|
||||
expect(w.getComponent(Picker).emitted("change")).toHaveLength(2);
|
||||
expect(w.getComponent(Picker).emitted("changeEnd")).toHaveLength(2);
|
||||
});
|
||||
it("restores accepted color after rejection and retries an identical edit after reopening", async () => {
|
||||
const w = view('model-value="hsba(270,0%,50%,.123456789)"');
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await open(w);
|
||||
const slider = document.querySelector<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
)!;
|
||||
await key(slider, "ArrowUp");
|
||||
expect(slider.value).toBe("270");
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "Escape",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
}
|
||||
expect(w.getComponent(Picker).emitted("change")).toHaveLength(2);
|
||||
expect(values(w)).toEqual(["hsba(270, 0%, 50%, 0.123456789)"]);
|
||||
});
|
||||
it("cancels an unfinished accepted close immediately and restores trigger focus", async () => {
|
||||
const w = view();
|
||||
await open(w);
|
||||
const slider = document.querySelector<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
)!;
|
||||
slider.focus();
|
||||
slider.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowUp",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "Escape",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(document.querySelector("[role=dialog]")).toBeNull();
|
||||
expect(w.getComponent(Picker).emitted("changeEnd")).toBeUndefined();
|
||||
expect(document.activeElement).toBe(w.get("button").element);
|
||||
});
|
||||
it("does not cancel the input transaction when controlled overlay close is rejected", async () => {
|
||||
const w = view(':open="true"');
|
||||
await flushPromises();
|
||||
const slider = document.querySelector<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
)!;
|
||||
slider.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowUp",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "Escape",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(document.querySelector("[role=dialog]")).not.toBeNull();
|
||||
slider.dispatchEvent(
|
||||
new KeyboardEvent("keyup", {
|
||||
key: "ArrowUp",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(w.getComponent(Picker).emitted("changeEnd")).toHaveLength(1);
|
||||
});
|
||||
it("resets one owner while the popup is open and retains controlled accepted values", async () => {
|
||||
const w = view();
|
||||
await open(w);
|
||||
const slider = document.querySelector<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
)!;
|
||||
await key(slider, "ArrowUp");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await flushPromises();
|
||||
expect(slider.value).toBe("270");
|
||||
expect(values(w)).toEqual(["hsba(270, 0%, 50%, 0.123456789)"]);
|
||||
expect(w.getComponent(Picker).emitted("change")).toHaveLength(1);
|
||||
});
|
||||
it("inherits disabled/readOnly and permits later accepted programmatic values", async () => {
|
||||
const off = shallowRef(false),
|
||||
value = shallowRef(parseColor("hsba(270,0%,50%,.123456789)"));
|
||||
const w = view(
|
||||
':model-value="value" :is-disabled="off" is-read-only',
|
||||
() => ({ off, value }),
|
||||
);
|
||||
await open(w);
|
||||
const slider = document.querySelector<HTMLInputElement>(
|
||||
"[data-color-slider-input]",
|
||||
)!;
|
||||
await key(slider, "ArrowUp");
|
||||
expect(w.getComponent(Picker).emitted("change")).toBeUndefined();
|
||||
value.value = parseColor("hsba(90,50%,50%,.125)");
|
||||
await flushPromises();
|
||||
expect(slider.value).toBe("90");
|
||||
off.value = true;
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual([]);
|
||||
expect(w.get("button").element.disabled).toBe(true);
|
||||
});
|
||||
it("hydrates closed owners with one stable submission and no popup duplication", async () => {
|
||||
const App = defineComponent({
|
||||
components: { Picker },
|
||||
template: '<main><Picker name="first"/><Picker name="second"/></main>',
|
||||
});
|
||||
const container = document.createElement("div");
|
||||
container.innerHTML = await renderToString(createSSRApp(App));
|
||||
document.body.append(container);
|
||||
const nodes = [...container.querySelectorAll("input")];
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {}),
|
||||
error = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const app = createSSRApp(App);
|
||||
app.mount(container);
|
||||
await flushPromises();
|
||||
expect([...container.querySelectorAll("input")]).toEqual(nodes);
|
||||
const ids = [...container.querySelectorAll("[id]")].map((n) => n.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
expect(error).not.toHaveBeenCalled();
|
||||
app.unmount();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
// @vitest-environment node
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { createSSRApp, defineComponent } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import Slider from "../packages/vue/tests/fixtures/ColorSliderFoundation.vue";
|
||||
import Picker from "../packages/vue/tests/fixtures/ColorPickerComposition.vue";
|
||||
describe("private custom color track and picker actual Node SSR", () => {
|
||||
it("renders direction, gradient, native value and accepted thumb consistently without layout globals", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
components: { Slider },
|
||||
template:
|
||||
'<Slider channel="alpha" name="alpha" orientation="vertical" dir="rtl" default-value="hsba(270,0%,50%,.12345)" aria-label="Alpha"/>',
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(html).toContain('value="0.12345"');
|
||||
expect(html).toContain("top:87.655%");
|
||||
expect(html).toContain('aria-orientation="vertical"');
|
||||
expect(html).toContain("linear-gradient(to top");
|
||||
expect(html.match(/name="alpha"/g)).toHaveLength(1);
|
||||
expect(html).not.toContain("NaN");
|
||||
});
|
||||
it("renders a single exact owner submission while closed, without popup controls", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
components: { Picker },
|
||||
template:
|
||||
'<Picker name="color" default-value="hsba(270,0%,50%,.123456789012345)"/>',
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(html).toContain('value="hsba(270, 0%, 50%, 0.123456789012345)"');
|
||||
expect(html.match(/name="color"/g)).toHaveLength(1);
|
||||
expect(html).toContain('aria-expanded="false"');
|
||||
expect(html).not.toContain("data-color-slider-track");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,348 @@
|
||||
import { afterEach, describe, it, expect, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, shallowRef } from "vue";
|
||||
import Slider from "../packages/vue/tests/fixtures/ColorSliderFoundation.vue";
|
||||
import Picker from "../packages/vue/tests/fixtures/ColorPickerFoundation.vue";
|
||||
import {
|
||||
parseColor,
|
||||
type Color,
|
||||
} from "../packages/vue/src/components/color/value";
|
||||
import {
|
||||
colorSliderBackground,
|
||||
colorSliderDisplay,
|
||||
} from "../packages/vue/src/components/color/slider-gradient";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
function fixture(attrs = "", setup = () => ({})) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Slider, Picker },
|
||||
setup,
|
||||
template: `<form><Slider channel="hue" default-value="hsb(240,50%,50%,.12345)" aria-label="Hue" ${attrs}/></form>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const input = (w: ReturnType<typeof mount>) =>
|
||||
w.get<HTMLInputElement>("[data-color-slider-input]");
|
||||
const changes = (w: ReturnType<typeof mount>) =>
|
||||
(w.getComponent(Slider).emitted("change") ?? []).map(([v]) => v as Color);
|
||||
const ends = (w: ReturnType<typeof mount>) =>
|
||||
w.getComponent(Slider).emitted("changeEnd") ?? [];
|
||||
function geometry(
|
||||
w: ReturnType<typeof mount>,
|
||||
vertical = false,
|
||||
scale = 1,
|
||||
border = 0,
|
||||
) {
|
||||
const track = w.get<HTMLElement>("[data-color-slider-track]").element;
|
||||
const width = vertical ? 20 : 220,
|
||||
height = vertical ? 220 : 20;
|
||||
track.style.border = `${border}px solid transparent`;
|
||||
Object.defineProperties(track, {
|
||||
offsetWidth: { get: () => width, configurable: true },
|
||||
offsetHeight: { get: () => height, configurable: true },
|
||||
});
|
||||
vi.spyOn(track, "getBoundingClientRect").mockReturnValue({
|
||||
left: 10,
|
||||
top: 20,
|
||||
width: width * scale,
|
||||
height: height * scale,
|
||||
right: 10 + width * scale,
|
||||
bottom: 20 + height * scale,
|
||||
x: 10,
|
||||
y: 20,
|
||||
toJSON: () => ({}),
|
||||
});
|
||||
let capture: number | undefined;
|
||||
track.setPointerCapture = vi.fn((id) => {
|
||||
capture = id;
|
||||
});
|
||||
track.hasPointerCapture = vi.fn((id) => capture === id);
|
||||
track.releasePointerCapture = vi.fn(() => {
|
||||
capture = undefined;
|
||||
});
|
||||
return track;
|
||||
}
|
||||
async function pointer(node: Element, type: string, extra = {}) {
|
||||
const e = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.assign(e, {
|
||||
pointerId: 1,
|
||||
pointerType: "mouse",
|
||||
button: 0,
|
||||
isPrimary: true,
|
||||
clientX: 120,
|
||||
clientY: 30,
|
||||
...extra,
|
||||
});
|
||||
node.dispatchEvent(e);
|
||||
await flushPromises();
|
||||
return e;
|
||||
}
|
||||
describe("color slider custom track", () => {
|
||||
it("uses content coordinates through borders and ancestor scaling and commits once", async () => {
|
||||
const w = fixture(),
|
||||
track = geometry(w, false, 2, 10);
|
||||
await pointer(track, "pointerdown", { clientX: 330, clientY: 40 });
|
||||
expect(changes(w).at(-1)?.getChannelValue("hue")).toBe(270);
|
||||
await pointer(track, "pointerup", { clientX: 330, clientY: 40 });
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
expect(ends(w)).toHaveLength(1);
|
||||
expect(track.releasePointerCapture).toHaveBeenCalledWith(1);
|
||||
expect(changes(w)[0]?.getChannelValue("alpha")).toBe(0.12345);
|
||||
});
|
||||
it("retains grab offset, clamps outside and consumes final pointerup coordinate", async () => {
|
||||
const w = fixture(),
|
||||
track = geometry(w);
|
||||
const thumb = w.get("[data-color-slider-thumb]").element;
|
||||
const start = 10 + 220 * (240 / 360) + 3;
|
||||
await pointer(thumb, "pointerdown", { clientX: start });
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await pointer(track, "pointermove", { clientX: start + 22 });
|
||||
expect(changes(w).at(-1)?.getChannelValue("hue")).toBe(276);
|
||||
await pointer(track, "pointerup", { clientX: 1000 });
|
||||
expect(changes(w).at(-1)?.getChannelValue("hue")).toBe(360);
|
||||
expect(ends(w)).toHaveLength(1);
|
||||
});
|
||||
it("maps RTL and vertical independently", async () => {
|
||||
const rtl = fixture('dir="rtl"'),
|
||||
rt = geometry(rtl);
|
||||
await pointer(rt, "pointerdown", { clientX: 65 });
|
||||
await pointer(rt, "pointerup", { clientX: 65 });
|
||||
expect(changes(rtl)[0]?.getChannelValue("hue")).toBe(270);
|
||||
const vertical = fixture('orientation="vertical" dir="rtl"'),
|
||||
vt = geometry(vertical, true);
|
||||
await pointer(vt, "pointerdown", { clientX: 20, clientY: 75 });
|
||||
await pointer(vt, "pointerup", { clientX: 20, clientY: 75 });
|
||||
expect(changes(vertical)[0]?.getChannelValue("hue")).toBe(270);
|
||||
expect(input(vertical).attributes("aria-orientation")).toBe("vertical");
|
||||
expect(
|
||||
vertical.get("[data-color-slider-thumb]").attributes("style"),
|
||||
).toContain("top: 25%");
|
||||
});
|
||||
it("keeps accepted geometry on rejection, de-duplicates points, and retries next gesture", async () => {
|
||||
const w = fixture('model-value="hsb(240,50%,50%,.12345)"'),
|
||||
track = geometry(w);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
await pointer(track, "pointermove", { clientX: 65 });
|
||||
await pointer(track, "pointerup", { clientX: 65 });
|
||||
}
|
||||
expect(changes(w)).toHaveLength(2);
|
||||
expect(ends(w)).toHaveLength(2);
|
||||
expect((ends(w)[0]?.[0] as Color).getChannelValue("hue")).toBe(90);
|
||||
expect(input(w).element.value).toBe("240");
|
||||
expect(w.get("[data-color-slider-thumb]").attributes("style")).toContain(
|
||||
"66.666",
|
||||
);
|
||||
});
|
||||
it("shares pointer and keyboard lifecycle without double end and preserves accepted gray hue", async () => {
|
||||
const w = fixture('model-value="hsb(270,0%,50%,.125)"'),
|
||||
track = geometry(w);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
await input(w).trigger("keydown", { key: "ArrowRight" });
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
await input(w).trigger("keydown", { key: "Escape" });
|
||||
await pointer(track, "pointerup", { clientX: 100 });
|
||||
expect(ends(w)).toHaveLength(0);
|
||||
expect(track.releasePointerCapture).toHaveBeenCalledWith(1);
|
||||
await input(w).trigger("keydown", { key: "ArrowRight" });
|
||||
await input(w).trigger("keyup", { key: "ArrowRight" });
|
||||
expect(changes(w).at(-1)?.getChannelValue("hue")).toBe(271);
|
||||
expect(ends(w)).toHaveLength(1);
|
||||
});
|
||||
it.each(["pointercancel", "lostpointercapture"])(
|
||||
"cancels %s and ignores unrelated pointers",
|
||||
async (type) => {
|
||||
const w = fixture(),
|
||||
track = geometry(w);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
await pointer(track, "pointermove", { clientX: 180, pointerId: 2 });
|
||||
await pointer(track, type, { pointerId: 2 });
|
||||
expect(track.hasPointerCapture(1)).toBe(true);
|
||||
await pointer(track, type);
|
||||
await pointer(track, "pointerup");
|
||||
expect(ends(w)).toHaveLength(0);
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
},
|
||||
);
|
||||
it("ignores canceled down/move and canceled completion does not emit end", async () => {
|
||||
const w = fixture(),
|
||||
track = geometry(w);
|
||||
track.addEventListener("pointerdown", (e) => e.preventDefault(), {
|
||||
capture: true,
|
||||
once: true,
|
||||
});
|
||||
await pointer(track, "pointerdown");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
track.addEventListener("pointermove", (e) => e.preventDefault(), {
|
||||
capture: true,
|
||||
once: true,
|
||||
});
|
||||
await pointer(track, "pointermove", { clientX: 180 });
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
track.addEventListener("pointerup", (e) => e.preventDefault(), {
|
||||
capture: true,
|
||||
once: true,
|
||||
});
|
||||
await pointer(track, "pointerup");
|
||||
expect(ends(w)).toHaveLength(0);
|
||||
});
|
||||
it("cleans original capture on disable, mode changes, blur and unmount", async () => {
|
||||
const off = shallowRef(false),
|
||||
orientation = shallowRef<"horizontal" | "vertical">("horizontal");
|
||||
const w = fixture(':is-disabled="off" :orientation="orientation"', () => ({
|
||||
off,
|
||||
orientation,
|
||||
})),
|
||||
track = geometry(w);
|
||||
await pointer(track, "pointerdown");
|
||||
off.value = true;
|
||||
await flushPromises();
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
off.value = false;
|
||||
await flushPromises();
|
||||
await pointer(track, "pointerdown");
|
||||
orientation.value = "vertical";
|
||||
await flushPromises();
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
orientation.value = "horizontal";
|
||||
await flushPromises();
|
||||
await pointer(track, "pointerdown");
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
await flushPromises();
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
await pointer(track, "pointerdown");
|
||||
const slider = w.getComponent(Slider);
|
||||
w.unmount();
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
expect(slider.emitted("changeEnd")).toBeUndefined();
|
||||
});
|
||||
it("aborts drag on unrelated parent replacement but accepts synchronous echoes", async () => {
|
||||
const value = shallowRef(parseColor("hsb(240,50%,50%)"));
|
||||
const w = fixture(':model-value="value"', () => ({ value })),
|
||||
track = geometry(w);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
value.value = parseColor("hsb(180,50%,50%)");
|
||||
await flushPromises();
|
||||
expect(track.hasPointerCapture(1)).toBe(false);
|
||||
await pointer(track, "pointerup");
|
||||
expect(ends(w)).toHaveLength(0);
|
||||
const e = fixture('v-model="value"', () => ({
|
||||
value: shallowRef(parseColor("hsb(240,50%,50%)")),
|
||||
})),
|
||||
et = geometry(e);
|
||||
await pointer(et, "pointerdown", { clientX: 65 });
|
||||
await pointer(et, "pointermove", { clientX: 120 });
|
||||
await pointer(et, "pointerup", { clientX: 175 });
|
||||
expect(ends(e)).toHaveLength(1);
|
||||
expect(changes(e).at(-1)?.getChannelValue("hue")).toBe(270);
|
||||
});
|
||||
it("rejects non-primary, modified/right-button and zero-size tracks", async () => {
|
||||
const w = fixture(),
|
||||
track = geometry(w);
|
||||
for (const attrs of [
|
||||
{ isPrimary: false },
|
||||
{ button: 2 },
|
||||
{ ctrlKey: true },
|
||||
{ altKey: true },
|
||||
{ metaKey: true },
|
||||
])
|
||||
await pointer(track, "pointerdown", attrs);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
vi.spyOn(track, "getBoundingClientRect").mockReturnValue(new DOMRect());
|
||||
await pointer(track, "pointerdown");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("submits one native accepted channel value and resets it without synthetic changes", async () => {
|
||||
const w = fixture('name="hue"'),
|
||||
track = geometry(w);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
await pointer(track, "pointerup", { clientX: 65 });
|
||||
const form = w.get("form").element as HTMLFormElement;
|
||||
expect(new FormData(form).getAll("hue")).toEqual(["90"]);
|
||||
form.reset();
|
||||
await flushPromises();
|
||||
expect(input(w).element.value).toBe("240");
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
expect(ends(w)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
describe("color track replacement", () => {
|
||||
it("keeps vertical left/right semantics independent of RTL", async () => {
|
||||
const w = fixture('orientation="vertical" dir="rtl"');
|
||||
for (const [key, value] of [
|
||||
["ArrowLeft", "239"],
|
||||
["ArrowRight", "240"],
|
||||
["ArrowUp", "241"],
|
||||
]) {
|
||||
await input(w).trigger("keydown", { key });
|
||||
await input(w).trigger("keyup", { key });
|
||||
expect(input(w).element.value).toBe(value);
|
||||
}
|
||||
});
|
||||
it("releases the original node and does not keep an old gesture after replacement", async () => {
|
||||
const trackKey = shallowRef("first");
|
||||
const w = fixture(':track-key="trackKey"', () => ({ trackKey }));
|
||||
const old = geometry(w);
|
||||
await pointer(old, "pointerdown", { clientX: 65 });
|
||||
trackKey.value = "second";
|
||||
await flushPromises();
|
||||
expect(old.hasPointerCapture(1)).toBe(false);
|
||||
expect(w.get("[data-color-slider-track]").element).not.toBe(old);
|
||||
await pointer(old, "pointerup", { clientX: 180 });
|
||||
expect(ends(w)).toHaveLength(0);
|
||||
});
|
||||
it("blocks readonly pointer edits while accepted parent changes still render", async () => {
|
||||
const value = shallowRef(parseColor("hsb(240,0%,50%)"));
|
||||
const w = fixture('is-read-only :model-value="value"', () => ({ value }));
|
||||
const track = geometry(w);
|
||||
await pointer(track, "pointerdown", { clientX: 65 });
|
||||
await pointer(track, "pointerup", { clientX: 65 });
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
value.value = parseColor("hsb(90,0%,50%)");
|
||||
await flushPromises();
|
||||
expect(input(w).element.value).toBe("90");
|
||||
});
|
||||
});
|
||||
describe("channel display ramps", () => {
|
||||
it("renders a full opaque hue spectrum even for an accepted transparent gray", () => {
|
||||
const c = parseColor("hsb(270,0%,50%,.1)");
|
||||
expect(colorSliderDisplay(c, "hue").toString("css")).toBe(
|
||||
"rgb(128, 0, 255)",
|
||||
);
|
||||
const ramp = colorSliderBackground(c, "hue");
|
||||
expect(ramp.background).toContain("rgb(255, 0, 0) 0%");
|
||||
expect(ramp.background).toContain("rgb(0, 255, 0)");
|
||||
expect(ramp.background).not.toContain("rgba(");
|
||||
expect(c.getChannelValue("alpha")).toBe(0.1);
|
||||
});
|
||||
it("has the HSL midpoint and keeps alpha checkerboard with correctly directed caps", () => {
|
||||
const c = parseColor("hsla(0,100%,50%,.25)");
|
||||
const light = colorSliderBackground(c, "lightness");
|
||||
expect(light.background).toContain("rgb(255, 0, 0) 50%");
|
||||
expect(light.background).toContain("rgb(255, 255, 255) 100%");
|
||||
const alpha = colorSliderBackground(
|
||||
c,
|
||||
"alpha",
|
||||
undefined,
|
||||
"horizontal",
|
||||
"rtl",
|
||||
);
|
||||
expect(alpha.background).toContain("to left");
|
||||
expect(alpha["--track-start-color"]).toBe("rgba(255, 0, 0, 0)");
|
||||
expect(alpha["--track-end-color"]).toBe("rgb(255, 0, 0)");
|
||||
expect(alpha.background).toContain("repeating-conic-gradient");
|
||||
expect(
|
||||
colorSliderBackground(c, "alpha", undefined, "vertical", "rtl")
|
||||
.background,
|
||||
).toContain("to top");
|
||||
});
|
||||
});
|
||||
@@ -31,3 +31,5 @@ DATE-03 新增 `consume-calendar.mjs` / `calendar-contract.ts`,安装两份新
|
||||
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 产物契约。
|
||||
|
||||
COLOR-04 增加 `consume-color-slider-foundation.mjs`,在 `/private/tmp/heroui-color-slider-consumer` 用最终两份 tarball 验证暂存 Slider CSS、端帽变量、公共 Popover 高度/滚动约束与无公共颜色占位导出,同时保留 Calendar/DateField/Select 的 ESM/SSR/CSS 和 strict NodeNext/bundler 正反类型回归。私有 Slider/Picker 的实际交互/SSR/水合在工作区验收,公开组件仍需另写完整产物契约。
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
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",
|
||||
);
|
||||
for (const marker of [
|
||||
".hv-color-slider",
|
||||
".hv-color-slider__track",
|
||||
".hv-color-slider__thumb",
|
||||
"--track-start-color",
|
||||
"--track-end-color",
|
||||
"--reka-popover-content-available-height",
|
||||
"max-height:inherit",
|
||||
"overscroll-behavior:contain",
|
||||
])
|
||||
assert.ok(css.includes(marker), marker);
|
||||
for (const name of ["ColorSlider", "ColorField", "ColorPicker"])
|
||||
assert.equal(name in ui, false);
|
||||
console.log(
|
||||
"Color slider foundation CSS and Popover constraints present; private components stay private.",
|
||||
);
|
||||
@@ -41,3 +41,17 @@ void hueSlider;
|
||||
void missingChannel;
|
||||
void invalidChannel;
|
||||
void invalidSpace;
|
||||
|
||||
import type { ColorSliderOptions } from "../../packages/vue/src/components/color/slider";
|
||||
const verticalSlider: ColorSliderOptions = {
|
||||
channel: "alpha",
|
||||
orientation: "vertical",
|
||||
dir: "rtl",
|
||||
};
|
||||
const invalidOrientation: ColorSliderOptions = {
|
||||
channel: "hue",
|
||||
// @ts-expect-error no third orientation
|
||||
orientation: "diagonal",
|
||||
};
|
||||
void verticalSlider;
|
||||
void invalidOrientation;
|
||||
|
||||
Reference in New Issue
Block a user