@a2f0/agent-tool 0.1.62 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -533,6 +533,12 @@
|
|
|
533
533
|
cursor: pointer;
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
+
/* At the start or end of the row, a step button stays focusable but reads as unavailable. */
|
|
537
|
+
.shots-carousel-step:where([aria-disabled="true"]) {
|
|
538
|
+
opacity: 0.4;
|
|
539
|
+
cursor: default;
|
|
540
|
+
}
|
|
541
|
+
|
|
536
542
|
@media (prefers-reduced-motion: no-preference) {
|
|
537
543
|
:is(.shots-track, .shots-carousel-track, .shots-filmstrip) {
|
|
538
544
|
scroll-behavior: smooth;
|
|
@@ -60,17 +60,12 @@ export function nearestSlide(scrollLeft: number, offset: number, pitch: number,
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* Whether a horizontal scroller can still move back toward its start or
|
|
64
|
+
* forward toward its end. The 1px tolerance absorbs fractional scroll
|
|
65
|
+
* positions, so a scroller resting at an edge reads as at that edge.
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** How many copies each side needs so a full viewport of clones is always ready. */
|
|
72
|
-
export function loopCopies(viewportWidth: number, copyWidth: number): number {
|
|
73
|
-
return copyWidth > 0 ? Math.max(1, Math.ceil(viewportWidth / copyWidth)) : 1;
|
|
67
|
+
function scrollRoom(scrollLeft: number, scrollWidth: number, clientWidth: number): { back: boolean; forward: boolean } {
|
|
68
|
+
return { back: scrollLeft > 1, forward: scrollLeft < scrollWidth - clientWidth - 1 };
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
/** Wheel travel, in CSS pixels on a gesture's dominant axis, that steps one screen. */
|
|
@@ -183,7 +178,7 @@ export interface ScreenshotGalleryElement extends HTMLElement {
|
|
|
183
178
|
}
|
|
184
179
|
export interface ScreenshotCarouselElement extends HTMLElement {
|
|
185
180
|
manifestData: ScreenshotManifest | null;
|
|
186
|
-
/** Scrolls `delta` pages of slides,
|
|
181
|
+
/** Scrolls `delta` pages of slides, stopping at the first and last slide. */
|
|
187
182
|
step(delta: number): void;
|
|
188
183
|
}
|
|
189
184
|
|
|
@@ -733,10 +728,8 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
733
728
|
#data: ScreenshotManifest | null = null;
|
|
734
729
|
#abort: AbortController | null = null;
|
|
735
730
|
#track: HTMLDivElement | null = null;
|
|
736
|
-
#count = 0;
|
|
737
|
-
#copies = 1;
|
|
738
731
|
#slides: HTMLElement[] = [];
|
|
739
|
-
#
|
|
732
|
+
#steps: { previous: HTMLButtonElement; next: HTMLButtonElement } | null = null;
|
|
740
733
|
|
|
741
734
|
constructor() {
|
|
742
735
|
super();
|
|
@@ -785,69 +778,65 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
785
778
|
}
|
|
786
779
|
|
|
787
780
|
#render(manifest: ScreenshotManifest): void {
|
|
788
|
-
this.#manifest = manifest;
|
|
789
781
|
const slides = this.#slidesFor(manifest);
|
|
790
782
|
const signal = this.#abort!.signal;
|
|
791
|
-
this.#
|
|
783
|
+
this.#track = null;
|
|
784
|
+
this.#slides = [];
|
|
785
|
+
this.#steps = null;
|
|
792
786
|
if (!slides.length) { this.replaceChildren(); this.hidden = true; this.dataset["state"] = "empty"; return; }
|
|
793
787
|
this.hidden = false;
|
|
794
788
|
this.dataset["state"] = "ready";
|
|
795
789
|
const project = slides[0]!.light.project;
|
|
796
790
|
const frame = projectFrame(manifest, project);
|
|
797
|
-
const
|
|
798
|
-
const track = element("div", { class: "shots-carousel-track", tabindex: "0" }, [
|
|
791
|
+
const list = this.#list(manifest, slides);
|
|
792
|
+
const track = element("div", { class: "shots-carousel-track", tabindex: "0" }, [list]);
|
|
799
793
|
this.#track = track;
|
|
800
794
|
const root = element("div", { class: "shots-carousel", role: "region", "aria-roledescription": "carousel", "aria-label": this.getAttribute("label") ?? "Screenshots", "data-frame": frame }, [track]);
|
|
801
795
|
const controls = element("div", { class: "shots-carousel-controls" });
|
|
802
796
|
const viewAll = this.getAttribute("view-all-href");
|
|
803
797
|
if (viewAll) controls.append(element("a", { class: "shots-carousel-view-all", href: viewAll, text: this.getAttribute("view-all-label") || "View all screenshots" }));
|
|
804
|
-
if (
|
|
798
|
+
if (slides.length > 1) {
|
|
805
799
|
const previous = element("button", { type: "button", class: "shots-carousel-step", "data-step": "-1", "aria-label": "Previous screens" }, [icon("prev")]);
|
|
806
800
|
const next = element("button", { type: "button", class: "shots-carousel-step", "data-step": "1", "aria-label": "Next screens" }, [icon("next")]);
|
|
807
801
|
previous.addEventListener("click", () => this.step(-1), { signal });
|
|
808
802
|
next.addEventListener("click", () => this.step(1), { signal });
|
|
809
803
|
controls.append(previous, next);
|
|
810
|
-
|
|
804
|
+
this.#steps = { previous, next };
|
|
805
|
+
// Touch, trackpad, keyboard, and the buttons all scroll the track; a resize moves its end.
|
|
806
|
+
track.addEventListener("scroll", () => this.#updateSteps(), { passive: true, signal });
|
|
811
807
|
if (typeof ResizeObserver === "function") {
|
|
812
|
-
const observer = new ResizeObserver(() => this.#
|
|
808
|
+
const observer = new ResizeObserver(() => this.#updateSteps());
|
|
813
809
|
observer.observe(track);
|
|
810
|
+
observer.observe(list);
|
|
814
811
|
signal.addEventListener("abort", () => observer.disconnect());
|
|
815
812
|
}
|
|
816
813
|
}
|
|
817
814
|
if (controls.childElementCount) root.append(controls);
|
|
818
815
|
this.replaceChildren(root);
|
|
819
|
-
|
|
816
|
+
this.#updateSteps();
|
|
820
817
|
}
|
|
821
818
|
|
|
822
|
-
/**
|
|
823
|
-
#list(manifest: ScreenshotManifest, slides: { name: string; light: ScreenshotEntry; dark: ScreenshotEntry | undefined }[]
|
|
819
|
+
/** One list item per slide, each shown once. */
|
|
820
|
+
#list(manifest: ScreenshotManifest, slides: { name: string; light: ScreenshotEntry; dark: ScreenshotEntry | undefined }[]): HTMLUListElement {
|
|
824
821
|
const project = slides[0]!.light.project;
|
|
825
822
|
const linkBase = this.getAttribute("link-base");
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const item = element("li", { class: "shots-carousel-slide", "data-index": index, "aria-hidden": clone ? "true" : undefined, "data-clone": clone || undefined }, [
|
|
844
|
-
element("figure", {}, [device, element("figcaption", { text: screen.label })]),
|
|
845
|
-
]);
|
|
846
|
-
this.#slides.push(item);
|
|
847
|
-
list.append(item);
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
return list;
|
|
823
|
+
this.#slides = slides.map((slide, index) => {
|
|
824
|
+
const screen = screenInfo(manifest, slide.name);
|
|
825
|
+
const picture = element("picture", {}, slide.dark ? [element("source", { media: "(prefers-color-scheme: dark)", srcset: slide.dark.src, width: slide.dark.width, height: slide.dark.height })] : []);
|
|
826
|
+
picture.append(element("img", {
|
|
827
|
+
src: slide.light.src, alt: screen.alt ?? `${screen.label}, ${projectInfo(manifest, project).label.toLowerCase()} screenshot`,
|
|
828
|
+
width: slide.light.width, height: slide.light.height, decoding: "async",
|
|
829
|
+
// The first slide rests at the start edge on load: fetch it first, and the rest as they near the viewport.
|
|
830
|
+
loading: index === 0 ? "eager" : "lazy", fetchpriority: index === 0 ? "high" : undefined,
|
|
831
|
+
}));
|
|
832
|
+
const device = linkBase
|
|
833
|
+
? element("a", { class: "shots-device", href: screenshotPath(linkBase, project, slide.name) }, [picture])
|
|
834
|
+
: element("div", { class: "shots-device" }, [picture]);
|
|
835
|
+
return element("li", { class: "shots-carousel-slide", "data-index": index }, [
|
|
836
|
+
element("figure", {}, [device, element("figcaption", { text: screen.label })]),
|
|
837
|
+
]);
|
|
838
|
+
});
|
|
839
|
+
return element("ul", { class: "shots-carousel-list", role: "list" }, this.#slides);
|
|
851
840
|
}
|
|
852
841
|
|
|
853
842
|
#pitch(): number {
|
|
@@ -859,49 +848,34 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
859
848
|
const track = this.#track!, padding = parseFloat(getComputedStyle(track).scrollPaddingLeft);
|
|
860
849
|
return this.#slides[0]!.offsetLeft - (Number.isFinite(padding) ? padding : 0);
|
|
861
850
|
}
|
|
862
|
-
#current(): number { return nearestSlide(this.#track!.scrollLeft, this.#offset(), this.#pitch(), this.#slides.length); }
|
|
863
|
-
#jump(slide: number): void {
|
|
864
|
-
const track = this.#track;
|
|
865
|
-
if (!track || !this.#pitch()) return;
|
|
866
|
-
track.scrollTo({ left: this.#offset() + slide * this.#pitch(), behavior: "instant" });
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/** Silently moves a settled track back to the same slide in the middle copy. */
|
|
870
|
-
#normalize(): void {
|
|
871
|
-
const track = this.#track, pitch = this.#pitch();
|
|
872
|
-
if (!track || !pitch) return;
|
|
873
|
-
const current = this.#current(), target = loopSlide(current, this.#count, this.#copies);
|
|
874
|
-
// Only a track resting on a slide jumps; a snap still in progress settles again.
|
|
875
|
-
if (Math.abs(track.scrollLeft - (this.#offset() + current * pitch)) > 2) return;
|
|
876
|
-
if (target !== current) this.#jump(target);
|
|
877
|
-
}
|
|
878
851
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
});
|
|
894
|
-
} else this.#normalize();
|
|
852
|
+
/**
|
|
853
|
+
* Marks the step button for a direction the track cannot move in with
|
|
854
|
+
* `aria-disabled`, read from the scroll position each time. Unlike
|
|
855
|
+
* `disabled`, it keeps the button focusable, so a keyboard user who steps
|
|
856
|
+
* onto the last page keeps focus there; a click on it does nothing.
|
|
857
|
+
*/
|
|
858
|
+
#updateSteps(): void {
|
|
859
|
+
const track = this.#track, steps = this.#steps;
|
|
860
|
+
if (!track || !steps) return;
|
|
861
|
+
const room = scrollRoom(track.scrollLeft, track.scrollWidth, track.clientWidth);
|
|
862
|
+
for (const [button, open] of [[steps.previous, room.back], [steps.next, room.forward]] as const) {
|
|
863
|
+
if (open) button.removeAttribute("aria-disabled");
|
|
864
|
+
else if (button.getAttribute("aria-disabled") !== "true") button.setAttribute("aria-disabled", "true");
|
|
865
|
+
}
|
|
895
866
|
}
|
|
896
867
|
|
|
897
868
|
step(delta: number): void {
|
|
898
869
|
const track = this.#track, pitch = this.#pitch();
|
|
899
|
-
if (!track || !pitch) return;
|
|
900
|
-
|
|
901
|
-
|
|
870
|
+
if (!track || !pitch || !delta) return;
|
|
871
|
+
const room = scrollRoom(track.scrollLeft, track.scrollWidth, track.clientWidth);
|
|
872
|
+
if (!(delta < 0 ? room.back : room.forward)) return;
|
|
902
873
|
const visible = Math.max(1, Math.floor((track.clientWidth + 1) / pitch));
|
|
903
|
-
const
|
|
904
|
-
|
|
874
|
+
const offset = this.#offset(), position = (track.scrollLeft - offset) / pitch;
|
|
875
|
+
// The last page can end mid-slide; stepping back from it counts from the first slide fully in view.
|
|
876
|
+
const from = delta < 0 ? Math.ceil(position - 0.1) : Math.round(position);
|
|
877
|
+
const end = Math.max(0, track.scrollWidth - track.clientWidth);
|
|
878
|
+
track.scrollTo({ left: Math.min(end, Math.max(0, offset + (from + delta * visible) * pitch)), behavior: scrollBehavior() });
|
|
905
879
|
}
|
|
906
880
|
};
|
|
907
881
|
}
|