strata-react 1.0.3 → 1.0.4
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/README.md +1 -0
- package/dist/components/compare.d.ts +42 -0
- package/dist/components/fullscreen-frame.d.ts +16 -0
- package/dist/components/viewport.d.ts +41 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +563 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/viewport.d.ts +29 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, History, ImageOff, Info, LoaderCircle, Minus, RotateCcw, Search, Trash2, TriangleAlert, X } from "lucide-react";
|
|
6
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, History, ImageOff, Info, LoaderCircle, Maximize, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
7
7
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
8
8
|
import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
9
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
@@ -4156,6 +4156,567 @@ function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...op
|
|
|
4156
4156
|
poll
|
|
4157
4157
|
};
|
|
4158
4158
|
}
|
|
4159
|
-
|
|
4159
|
+
// src/lib/viewport.ts
|
|
4160
|
+
/** The picture fitted in its frame, not panned. */
|
|
4161
|
+
var FIT = {
|
|
4162
|
+
scale: 1,
|
|
4163
|
+
x: 0,
|
|
4164
|
+
y: 0
|
|
4165
|
+
};
|
|
4166
|
+
/** The least zoom: the whole picture fitted. */
|
|
4167
|
+
var MIN_SCALE = 1;
|
|
4168
|
+
/** The most zoom, 32 times the fit. */
|
|
4169
|
+
var MAX_SCALE = 32;
|
|
4170
|
+
/** Keeps the picture from being dragged out of its frame: at most half the extra width or height past each edge. */
|
|
4171
|
+
function clampViewport(v, frame) {
|
|
4172
|
+
const scale = Math.min(32, Math.max(1, v.scale));
|
|
4173
|
+
if (scale === 1) return FIT;
|
|
4174
|
+
const mx = (scale - 1) * frame.width / 2;
|
|
4175
|
+
const my = (scale - 1) * frame.height / 2;
|
|
4176
|
+
return {
|
|
4177
|
+
scale,
|
|
4178
|
+
x: Math.min(mx, Math.max(-mx, v.x)),
|
|
4179
|
+
y: Math.min(my, Math.max(-my, v.y))
|
|
4180
|
+
};
|
|
4181
|
+
}
|
|
4182
|
+
/** A new scale with the point under `at` (pixels from the frame's centre) staying under it. */
|
|
4183
|
+
function zoomAt(v, nextScale, at, frame) {
|
|
4184
|
+
const scale = Math.min(32, Math.max(1, nextScale));
|
|
4185
|
+
const k = scale / v.scale;
|
|
4186
|
+
return clampViewport({
|
|
4187
|
+
scale,
|
|
4188
|
+
x: at.x - k * (at.x - v.x),
|
|
4189
|
+
y: at.y - k * (at.y - v.y)
|
|
4190
|
+
}, frame);
|
|
4191
|
+
}
|
|
4192
|
+
/** The scale at which the picture's own pixels are drawn one to one: its natural width over the width it is fitted at. */
|
|
4193
|
+
function actualPixelsScale(naturalWidth, fittedWidth) {
|
|
4194
|
+
if (!naturalWidth || !fittedWidth) return 1;
|
|
4195
|
+
return Math.min(32, Math.max(1, naturalWidth / fittedWidth));
|
|
4196
|
+
}
|
|
4197
|
+
/** The CSS transform for a viewport. */
|
|
4198
|
+
function viewportTransform(v) {
|
|
4199
|
+
return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
|
|
4200
|
+
}
|
|
4201
|
+
// src/components/fullscreen-frame.tsx
|
|
4202
|
+
/** Whether this browser can show an element full screen. False in jsdom and on iPhone, where the modal fallback is used. */
|
|
4203
|
+
function canFullscreen() {
|
|
4204
|
+
return typeof document !== "undefined" && document.fullscreenEnabled === true && typeof Element.prototype.requestFullscreen === "function";
|
|
4205
|
+
}
|
|
4206
|
+
/** Shows its children full screen while `active`: the browser's Fullscreen API where there is one, a window-filling modal where there is not. */
|
|
4207
|
+
function FullscreenFrame({ label, active, onActiveChange, children, className }) {
|
|
4208
|
+
const ref = React.useRef(null);
|
|
4209
|
+
const [native, setNative] = React.useState(false);
|
|
4210
|
+
const [refused, setRefused] = React.useState(false);
|
|
4211
|
+
const change = React.useRef(onActiveChange);
|
|
4212
|
+
change.current = onActiveChange;
|
|
4213
|
+
React.useEffect(() => {
|
|
4214
|
+
const el = ref.current;
|
|
4215
|
+
if (!active) {
|
|
4216
|
+
setNative(false);
|
|
4217
|
+
setRefused(false);
|
|
4218
|
+
if (document.fullscreenElement && document.fullscreenElement === el) document.exitFullscreen();
|
|
4219
|
+
return;
|
|
4220
|
+
}
|
|
4221
|
+
if (!el || !canFullscreen()) return;
|
|
4222
|
+
let cancelled = false;
|
|
4223
|
+
el.requestFullscreen().then(() => !cancelled && setNative(true), () => !cancelled && setRefused(true));
|
|
4224
|
+
const onChange = () => {
|
|
4225
|
+
if (document.fullscreenElement !== el && !cancelled) change.current(false);
|
|
4226
|
+
};
|
|
4227
|
+
document.addEventListener("fullscreenchange", onChange);
|
|
4228
|
+
return () => {
|
|
4229
|
+
cancelled = true;
|
|
4230
|
+
document.removeEventListener("fullscreenchange", onChange);
|
|
4231
|
+
};
|
|
4232
|
+
}, [active]);
|
|
4233
|
+
const modal = active && !native && (!canFullscreen() || refused);
|
|
4234
|
+
const inner = /* @__PURE__ */ jsx("div", {
|
|
4235
|
+
ref,
|
|
4236
|
+
className: cn(active && "flex h-full min-h-0 flex-col bg-background p-4", className),
|
|
4237
|
+
children
|
|
4238
|
+
});
|
|
4239
|
+
if (!modal) return inner;
|
|
4240
|
+
return /* @__PURE__ */ jsx(ModalOverlay, {
|
|
4241
|
+
isOpen: true,
|
|
4242
|
+
onOpenChange: (o) => !o && onActiveChange(false),
|
|
4243
|
+
isDismissable: true,
|
|
4244
|
+
className: "layer-overlay fixed inset-0 bg-foreground/40",
|
|
4245
|
+
children: /* @__PURE__ */ jsx(Modal, {
|
|
4246
|
+
className: cn("h-full w-full outline-none", overlaySurface, "rounded-none"),
|
|
4247
|
+
children: /* @__PURE__ */ jsx(Dialog$1, {
|
|
4248
|
+
"aria-label": label,
|
|
4249
|
+
className: "h-full outline-none",
|
|
4250
|
+
children: inner
|
|
4251
|
+
})
|
|
4252
|
+
})
|
|
4253
|
+
});
|
|
4254
|
+
}
|
|
4255
|
+
// src/components/viewport.tsx
|
|
4256
|
+
/** Zoom and pan held in React state, to give to every `ViewportFrame` that should move together. */
|
|
4257
|
+
function useViewport(initial = FIT) {
|
|
4258
|
+
const [viewport, setViewport] = React.useState(initial);
|
|
4259
|
+
return {
|
|
4260
|
+
viewport,
|
|
4261
|
+
setViewport
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
4264
|
+
var PAN_STEP = 48;
|
|
4265
|
+
/** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
|
|
4266
|
+
var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, viewport, setViewport, children, cover, overlay, className }, forwardedRef) {
|
|
4267
|
+
const ref = React.useRef(null);
|
|
4268
|
+
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
4269
|
+
const latest = React.useRef(viewport);
|
|
4270
|
+
latest.current = viewport;
|
|
4271
|
+
const drag = React.useRef(null);
|
|
4272
|
+
const size = () => {
|
|
4273
|
+
const r = ref.current.getBoundingClientRect();
|
|
4274
|
+
return {
|
|
4275
|
+
width: r.width,
|
|
4276
|
+
height: r.height
|
|
4277
|
+
};
|
|
4278
|
+
};
|
|
4279
|
+
const fromCentre = (clientX, clientY) => {
|
|
4280
|
+
const r = ref.current.getBoundingClientRect();
|
|
4281
|
+
return {
|
|
4282
|
+
x: clientX - r.left - r.width / 2,
|
|
4283
|
+
y: clientY - r.top - r.height / 2
|
|
4284
|
+
};
|
|
4285
|
+
};
|
|
4286
|
+
const setViewportRef = React.useRef(setViewport);
|
|
4287
|
+
setViewportRef.current = setViewport;
|
|
4288
|
+
React.useEffect(() => {
|
|
4289
|
+
const el = ref.current;
|
|
4290
|
+
if (!el) return;
|
|
4291
|
+
const onWheel = (e) => {
|
|
4292
|
+
if (!e.ctrlKey && !e.metaKey) return;
|
|
4293
|
+
e.preventDefault();
|
|
4294
|
+
const r = el.getBoundingClientRect();
|
|
4295
|
+
const at = {
|
|
4296
|
+
x: e.clientX - r.left - r.width / 2,
|
|
4297
|
+
y: e.clientY - r.top - r.height / 2
|
|
4298
|
+
};
|
|
4299
|
+
setViewportRef.current(zoomAt(latest.current, latest.current.scale * Math.exp(-e.deltaY / 200), at, {
|
|
4300
|
+
width: r.width,
|
|
4301
|
+
height: r.height
|
|
4302
|
+
}));
|
|
4303
|
+
};
|
|
4304
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
4305
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
4306
|
+
}, []);
|
|
4307
|
+
const onKeyDown = (e) => {
|
|
4308
|
+
const v = latest.current;
|
|
4309
|
+
const centre = {
|
|
4310
|
+
x: 0,
|
|
4311
|
+
y: 0
|
|
4312
|
+
};
|
|
4313
|
+
if (e.key === "+" || e.key === "=") setViewport(zoomAt(v, v.scale * 1.5, centre, size()));
|
|
4314
|
+
else if (e.key === "-") setViewport(zoomAt(v, v.scale / 1.5, centre, size()));
|
|
4315
|
+
else if (e.key === "0") setViewport(FIT);
|
|
4316
|
+
else if (v.scale > 1 && e.key.startsWith("Arrow")) {
|
|
4317
|
+
const dx = e.key === "ArrowRight" ? -48 : e.key === "ArrowLeft" ? PAN_STEP : 0;
|
|
4318
|
+
const dy = e.key === "ArrowDown" ? -48 : e.key === "ArrowUp" ? PAN_STEP : 0;
|
|
4319
|
+
setViewport(clampViewport({
|
|
4320
|
+
...v,
|
|
4321
|
+
x: v.x + dx,
|
|
4322
|
+
y: v.y + dy
|
|
4323
|
+
}, size()));
|
|
4324
|
+
} else return;
|
|
4325
|
+
e.preventDefault();
|
|
4326
|
+
e.stopPropagation();
|
|
4327
|
+
};
|
|
4328
|
+
const zoomed = viewport.scale > 1;
|
|
4329
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4330
|
+
ref,
|
|
4331
|
+
role: "group",
|
|
4332
|
+
"aria-label": label,
|
|
4333
|
+
"aria-roledescription": "zoomable picture",
|
|
4334
|
+
tabIndex: 0,
|
|
4335
|
+
onKeyDown,
|
|
4336
|
+
onPointerDown: (e) => {
|
|
4337
|
+
if (!zoomed || e.button !== 0) return;
|
|
4338
|
+
drag.current = {
|
|
4339
|
+
x: e.clientX,
|
|
4340
|
+
y: e.clientY
|
|
4341
|
+
};
|
|
4342
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
4343
|
+
},
|
|
4344
|
+
onPointerMove: (e) => {
|
|
4345
|
+
if (!drag.current) return;
|
|
4346
|
+
const dx = e.clientX - drag.current.x;
|
|
4347
|
+
const dy = e.clientY - drag.current.y;
|
|
4348
|
+
drag.current = {
|
|
4349
|
+
x: e.clientX,
|
|
4350
|
+
y: e.clientY
|
|
4351
|
+
};
|
|
4352
|
+
setViewport(clampViewport({
|
|
4353
|
+
...latest.current,
|
|
4354
|
+
x: latest.current.x + dx,
|
|
4355
|
+
y: latest.current.y + dy
|
|
4356
|
+
}, size()));
|
|
4357
|
+
},
|
|
4358
|
+
onPointerUp: () => drag.current = null,
|
|
4359
|
+
onPointerCancel: () => drag.current = null,
|
|
4360
|
+
onDoubleClick: (e) => {
|
|
4361
|
+
const v = latest.current;
|
|
4362
|
+
setViewport(v.scale > 1 ? FIT : zoomAt(v, 2, fromCentre(e.clientX, e.clientY), size()));
|
|
4363
|
+
},
|
|
4364
|
+
style: {
|
|
4365
|
+
aspectRatio: String(aspect),
|
|
4366
|
+
touchAction: zoomed ? "none" : "pan-y"
|
|
4367
|
+
},
|
|
4368
|
+
className: cn("relative w-full overflow-hidden rounded-surface border border-border bg-muted select-none", zoomed ? "cursor-grab active:cursor-grabbing" : "cursor-zoom-in", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", className),
|
|
4369
|
+
children: [
|
|
4370
|
+
/* @__PURE__ */ jsx("div", {
|
|
4371
|
+
className: "absolute inset-0",
|
|
4372
|
+
style: {
|
|
4373
|
+
transform: viewportTransform(viewport),
|
|
4374
|
+
transformOrigin: "center"
|
|
4375
|
+
},
|
|
4376
|
+
children
|
|
4377
|
+
}),
|
|
4378
|
+
cover && /* @__PURE__ */ jsx("div", {
|
|
4379
|
+
className: "absolute inset-0",
|
|
4380
|
+
style: { clipPath: `inset(0 ${100 - cover.shown}% 0 0)` },
|
|
4381
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4382
|
+
className: "absolute inset-0",
|
|
4383
|
+
style: {
|
|
4384
|
+
transform: viewportTransform(viewport),
|
|
4385
|
+
transformOrigin: "center"
|
|
4386
|
+
},
|
|
4387
|
+
children: cover.content
|
|
4388
|
+
})
|
|
4389
|
+
}),
|
|
4390
|
+
overlay != null && /* @__PURE__ */ jsx("div", {
|
|
4391
|
+
className: "pointer-events-none absolute inset-0",
|
|
4392
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
4393
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
4394
|
+
onDoubleClick: (e) => e.stopPropagation(),
|
|
4395
|
+
children: overlay
|
|
4396
|
+
})
|
|
4397
|
+
]
|
|
4398
|
+
});
|
|
4399
|
+
});
|
|
4400
|
+
// src/components/compare.tsx
|
|
4401
|
+
var MODE_LABEL = {
|
|
4402
|
+
side: "Side by side",
|
|
4403
|
+
swipe: "Swipe",
|
|
4404
|
+
fade: "Fade",
|
|
4405
|
+
blink: "Blink"
|
|
4406
|
+
};
|
|
4407
|
+
var ALL_MODES = [
|
|
4408
|
+
"side",
|
|
4409
|
+
"swipe",
|
|
4410
|
+
"fade",
|
|
4411
|
+
"blink"
|
|
4412
|
+
];
|
|
4413
|
+
/** A word for a picture's name on the page: its label, with its note unless blind. */
|
|
4414
|
+
function Caption({ c, blind }) {
|
|
4415
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4416
|
+
className: "flex items-baseline gap-2",
|
|
4417
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4418
|
+
className: "type-label",
|
|
4419
|
+
children: c.label
|
|
4420
|
+
}), !blind && c.note && /* @__PURE__ */ jsx("span", {
|
|
4421
|
+
className: "type-caption text-muted-foreground",
|
|
4422
|
+
children: c.note
|
|
4423
|
+
})]
|
|
4424
|
+
});
|
|
4425
|
+
}
|
|
4426
|
+
/** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
|
|
4427
|
+
function Picture({ c, blind, missing, onNatural, imgRef }) {
|
|
4428
|
+
const [state, setState] = React.useState("loading");
|
|
4429
|
+
React.useEffect(() => setState("loading"), [c.media.src]);
|
|
4430
|
+
const alt = blind ? c.label : c.media.alt;
|
|
4431
|
+
if (state === "failed") return /* @__PURE__ */ jsxs("div", {
|
|
4432
|
+
role: "img",
|
|
4433
|
+
"aria-label": `${alt}: ${missing}`,
|
|
4434
|
+
className: "absolute inset-0 grid place-content-center justify-items-center gap-2 text-muted-foreground",
|
|
4435
|
+
children: [/* @__PURE__ */ jsx(ImageOff, {
|
|
4436
|
+
"aria-hidden": true,
|
|
4437
|
+
className: "size-6"
|
|
4438
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4439
|
+
className: "type-body-sm",
|
|
4440
|
+
children: missing
|
|
4441
|
+
})]
|
|
4442
|
+
});
|
|
4443
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [state === "loading" && /* @__PURE__ */ jsx(Skeleton, {
|
|
4444
|
+
"aria-hidden": true,
|
|
4445
|
+
className: "absolute inset-0 size-full rounded-none"
|
|
4446
|
+
}), /* @__PURE__ */ jsx("img", {
|
|
4447
|
+
ref: imgRef,
|
|
4448
|
+
src: c.media.src,
|
|
4449
|
+
alt,
|
|
4450
|
+
draggable: false,
|
|
4451
|
+
onLoad: (e) => {
|
|
4452
|
+
setState("ready");
|
|
4453
|
+
onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
|
|
4454
|
+
},
|
|
4455
|
+
onError: () => setState("failed"),
|
|
4456
|
+
className: "absolute inset-0 size-full object-contain"
|
|
4457
|
+
})] });
|
|
4458
|
+
}
|
|
4459
|
+
/** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
|
|
4460
|
+
function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, keys = true, className }) {
|
|
4461
|
+
const { viewport, setViewport } = useViewport();
|
|
4462
|
+
const [full, setFull] = React.useState(false);
|
|
4463
|
+
const pairKey = `${a.media.src}|${b.media.src}`;
|
|
4464
|
+
const [learned, setLearned] = React.useState(null);
|
|
4465
|
+
const natural = a.media.size ?? (learned?.key === pairKey ? learned.size : null);
|
|
4466
|
+
const [divider, setDivider] = React.useState(50);
|
|
4467
|
+
const [blend, setBlend] = React.useState(50);
|
|
4468
|
+
const [showing, setShowing] = React.useState("a");
|
|
4469
|
+
const frameRef = React.useRef(null);
|
|
4470
|
+
const imgRef = React.useRef(null);
|
|
4471
|
+
const aspect = natural ? natural[0] / natural[1] : 3 / 2;
|
|
4472
|
+
const frameSize = () => {
|
|
4473
|
+
const r = frameRef.current?.getBoundingClientRect();
|
|
4474
|
+
return {
|
|
4475
|
+
width: r?.width ?? 0,
|
|
4476
|
+
height: r?.height ?? 0
|
|
4477
|
+
};
|
|
4478
|
+
};
|
|
4479
|
+
const zoomBy = (k) => setViewport(zoomAt(viewport, viewport.scale * k, {
|
|
4480
|
+
x: 0,
|
|
4481
|
+
y: 0
|
|
4482
|
+
}, frameSize()));
|
|
4483
|
+
const actual = () => {
|
|
4484
|
+
const f = frameSize();
|
|
4485
|
+
const fitted = natural ? Math.min(f.width, f.height * (natural[0] / natural[1])) : f.width;
|
|
4486
|
+
setViewport(zoomAt(viewport, actualPixelsScale(natural?.[0] ?? 0, fitted), {
|
|
4487
|
+
x: 0,
|
|
4488
|
+
y: 0
|
|
4489
|
+
}, f));
|
|
4490
|
+
};
|
|
4491
|
+
const flip = () => setShowing((s) => s === "a" ? "b" : "a");
|
|
4492
|
+
const offered = modes.includes(mode) ? modes : [mode, ...modes];
|
|
4493
|
+
const shortcuts = [
|
|
4494
|
+
...offered.map((m, i) => ({
|
|
4495
|
+
keys: [String(i + 1)],
|
|
4496
|
+
label: MODE_LABEL[m],
|
|
4497
|
+
run: () => onModeChange(m)
|
|
4498
|
+
})),
|
|
4499
|
+
{
|
|
4500
|
+
keys: ["x"],
|
|
4501
|
+
label: "Flip A and B",
|
|
4502
|
+
run: flip,
|
|
4503
|
+
disabled: mode !== "blink"
|
|
4504
|
+
},
|
|
4505
|
+
{
|
|
4506
|
+
keys: ["+", "="],
|
|
4507
|
+
label: "Zoom in",
|
|
4508
|
+
run: () => zoomBy(1.5),
|
|
4509
|
+
repeat: true
|
|
4510
|
+
},
|
|
4511
|
+
{
|
|
4512
|
+
keys: ["-"],
|
|
4513
|
+
label: "Zoom out",
|
|
4514
|
+
run: () => zoomBy(1 / 1.5),
|
|
4515
|
+
repeat: true
|
|
4516
|
+
},
|
|
4517
|
+
{
|
|
4518
|
+
keys: ["0"],
|
|
4519
|
+
label: "Fit",
|
|
4520
|
+
run: () => setViewport(FIT)
|
|
4521
|
+
},
|
|
4522
|
+
{
|
|
4523
|
+
keys: ["f"],
|
|
4524
|
+
label: full ? "Leave full screen" : "Full screen",
|
|
4525
|
+
run: () => setFull((f) => !f)
|
|
4526
|
+
}
|
|
4527
|
+
];
|
|
4528
|
+
useHotkeys(shortcuts, { enabled: keys });
|
|
4529
|
+
const pane = (c, ref, onNatural) => /* @__PURE__ */ jsx(Picture, {
|
|
4530
|
+
c,
|
|
4531
|
+
blind,
|
|
4532
|
+
missing,
|
|
4533
|
+
imgRef: ref,
|
|
4534
|
+
onNatural
|
|
4535
|
+
});
|
|
4536
|
+
const learn = (w, h) => setLearned({
|
|
4537
|
+
key: pairKey,
|
|
4538
|
+
size: [w, h]
|
|
4539
|
+
});
|
|
4540
|
+
const frameProps = {
|
|
4541
|
+
viewport,
|
|
4542
|
+
setViewport,
|
|
4543
|
+
aspect
|
|
4544
|
+
};
|
|
4545
|
+
let body;
|
|
4546
|
+
if (mode === "side") body = /* @__PURE__ */ jsx("div", {
|
|
4547
|
+
className: "grid gap-3 sm:grid-cols-2",
|
|
4548
|
+
children: [a, b].map((c, i) => /* @__PURE__ */ jsxs("figure", {
|
|
4549
|
+
className: "grid gap-1.5",
|
|
4550
|
+
children: [/* @__PURE__ */ jsx(Caption, {
|
|
4551
|
+
c,
|
|
4552
|
+
blind
|
|
4553
|
+
}), /* @__PURE__ */ jsx(ViewportFrame, {
|
|
4554
|
+
...frameProps,
|
|
4555
|
+
label: blind ? `Picture ${c.label}` : `${c.label}`,
|
|
4556
|
+
ref: i === 0 ? frameRef : void 0,
|
|
4557
|
+
children: pane(c, i === 0 ? imgRef : void 0, i === 0 ? learn : void 0)
|
|
4558
|
+
})]
|
|
4559
|
+
}, i))
|
|
4560
|
+
});
|
|
4561
|
+
else {
|
|
4562
|
+
const top = mode === "blink" ? showing === "a" ? a : b : a;
|
|
4563
|
+
const bottom = b;
|
|
4564
|
+
body = /* @__PURE__ */ jsxs("figure", {
|
|
4565
|
+
className: "grid gap-1.5",
|
|
4566
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
4567
|
+
className: "flex justify-between gap-4",
|
|
4568
|
+
children: [mode === "blink" ? /* @__PURE__ */ jsx(Caption, {
|
|
4569
|
+
c: top,
|
|
4570
|
+
blind
|
|
4571
|
+
}) : /* @__PURE__ */ jsx(Caption, {
|
|
4572
|
+
c: a,
|
|
4573
|
+
blind
|
|
4574
|
+
}), mode !== "blink" && /* @__PURE__ */ jsx(Caption, {
|
|
4575
|
+
c: b,
|
|
4576
|
+
blind
|
|
4577
|
+
})]
|
|
4578
|
+
}), /* @__PURE__ */ jsxs(ViewportFrame, {
|
|
4579
|
+
...frameProps,
|
|
4580
|
+
ref: frameRef,
|
|
4581
|
+
cover: mode === "swipe" ? {
|
|
4582
|
+
content: pane(a, imgRef, learn),
|
|
4583
|
+
shown: divider
|
|
4584
|
+
} : void 0,
|
|
4585
|
+
label: mode === "blink" ? `Picture ${top.label}` : `${a.label} over ${b.label}`,
|
|
4586
|
+
overlay: mode === "swipe" && /* @__PURE__ */ jsx(Slider$1, {
|
|
4587
|
+
"aria-label": `Divider between ${a.label} and ${b.label}`,
|
|
4588
|
+
value: divider,
|
|
4589
|
+
onChange: (v) => setDivider(v),
|
|
4590
|
+
minValue: 0,
|
|
4591
|
+
maxValue: 100,
|
|
4592
|
+
step: 1,
|
|
4593
|
+
className: "absolute inset-0",
|
|
4594
|
+
children: /* @__PURE__ */ jsx(SliderTrack, {
|
|
4595
|
+
className: "pointer-events-none h-full w-full",
|
|
4596
|
+
children: /* @__PURE__ */ jsxs(SliderThumb, {
|
|
4597
|
+
className: "pointer-events-auto grid h-full w-8 cursor-ew-resize place-items-center data-[focus-visible]:outline-2 data-[focus-visible]:outline-ring",
|
|
4598
|
+
style: { top: "50%" },
|
|
4599
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4600
|
+
"aria-hidden": true,
|
|
4601
|
+
className: "col-start-1 row-start-1 h-full w-1 border-x border-background bg-foreground"
|
|
4602
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4603
|
+
"aria-hidden": true,
|
|
4604
|
+
className: "col-start-1 row-start-1 size-6 rounded-pill border-2 border-foreground bg-background"
|
|
4605
|
+
})]
|
|
4606
|
+
})
|
|
4607
|
+
})
|
|
4608
|
+
}),
|
|
4609
|
+
children: [pane(bottom), mode !== "swipe" && /* @__PURE__ */ jsx("div", {
|
|
4610
|
+
className: "absolute inset-0",
|
|
4611
|
+
style: mode === "fade" ? { opacity: 1 - blend / 100 } : void 0,
|
|
4612
|
+
children: pane(top, imgRef, learn)
|
|
4613
|
+
})]
|
|
4614
|
+
})]
|
|
4615
|
+
});
|
|
4616
|
+
}
|
|
4617
|
+
return /* @__PURE__ */ jsx(FullscreenFrame, {
|
|
4618
|
+
label,
|
|
4619
|
+
active: full,
|
|
4620
|
+
onActiveChange: setFull,
|
|
4621
|
+
className,
|
|
4622
|
+
children: /* @__PURE__ */ jsxs("section", {
|
|
4623
|
+
"aria-label": label,
|
|
4624
|
+
className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
|
|
4625
|
+
children: [
|
|
4626
|
+
/* @__PURE__ */ jsxs(Toolbar, {
|
|
4627
|
+
label: "Comparison view",
|
|
4628
|
+
className: "items-center gap-2",
|
|
4629
|
+
children: [
|
|
4630
|
+
/* @__PURE__ */ jsx(ToggleGroup, {
|
|
4631
|
+
label: "View",
|
|
4632
|
+
options: offered.map((m) => ({
|
|
4633
|
+
value: m,
|
|
4634
|
+
label: MODE_LABEL[m]
|
|
4635
|
+
})),
|
|
4636
|
+
value: mode,
|
|
4637
|
+
onChange: (v) => onModeChange(v),
|
|
4638
|
+
size: "sm"
|
|
4639
|
+
}),
|
|
4640
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
4641
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4642
|
+
icon: ZoomOut,
|
|
4643
|
+
label: "Zoom out",
|
|
4644
|
+
onPress: () => zoomBy(1 / 1.5),
|
|
4645
|
+
disabled: viewport.scale <= 1
|
|
4646
|
+
}),
|
|
4647
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4648
|
+
icon: ZoomIn,
|
|
4649
|
+
label: "Zoom in",
|
|
4650
|
+
onPress: () => zoomBy(1.5)
|
|
4651
|
+
}),
|
|
4652
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4653
|
+
icon: Scan,
|
|
4654
|
+
label: "Fit",
|
|
4655
|
+
onPress: () => setViewport(FIT),
|
|
4656
|
+
disabled: viewport.scale === 1
|
|
4657
|
+
}),
|
|
4658
|
+
/* @__PURE__ */ jsx(Button, {
|
|
4659
|
+
size: "sm",
|
|
4660
|
+
variant: "ghost",
|
|
4661
|
+
onPress: actual,
|
|
4662
|
+
disabled: !natural,
|
|
4663
|
+
children: "1:1"
|
|
4664
|
+
}),
|
|
4665
|
+
/* @__PURE__ */ jsx("span", {
|
|
4666
|
+
"aria-live": "off",
|
|
4667
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
4668
|
+
children: viewport.scale === 1 ? "Fit" : `${viewport.scale.toFixed(1)}×`
|
|
4669
|
+
}),
|
|
4670
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
4671
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4672
|
+
icon: full ? Minimize : Maximize,
|
|
4673
|
+
label: full ? "Leave full screen" : "Full screen",
|
|
4674
|
+
onPress: () => setFull(!full)
|
|
4675
|
+
})
|
|
4676
|
+
]
|
|
4677
|
+
}),
|
|
4678
|
+
mode === "fade" && /* @__PURE__ */ jsxs("div", {
|
|
4679
|
+
className: "flex items-center gap-3",
|
|
4680
|
+
children: [
|
|
4681
|
+
/* @__PURE__ */ jsx("span", {
|
|
4682
|
+
className: "type-caption text-muted-foreground",
|
|
4683
|
+
children: a.label
|
|
4684
|
+
}),
|
|
4685
|
+
/* @__PURE__ */ jsx(Slider, {
|
|
4686
|
+
"aria-label": `Blend from ${a.label} to ${b.label}`,
|
|
4687
|
+
value: blend,
|
|
4688
|
+
onChange: setBlend,
|
|
4689
|
+
min: 0,
|
|
4690
|
+
max: 100,
|
|
4691
|
+
unit: "%",
|
|
4692
|
+
hideValue: true,
|
|
4693
|
+
className: "flex-1"
|
|
4694
|
+
}),
|
|
4695
|
+
/* @__PURE__ */ jsx("span", {
|
|
4696
|
+
className: "type-caption text-muted-foreground",
|
|
4697
|
+
children: b.label
|
|
4698
|
+
})
|
|
4699
|
+
]
|
|
4700
|
+
}),
|
|
4701
|
+
mode === "blink" && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(ToggleGroup, {
|
|
4702
|
+
label: "Showing",
|
|
4703
|
+
options: [{
|
|
4704
|
+
value: "a",
|
|
4705
|
+
label: a.label
|
|
4706
|
+
}, {
|
|
4707
|
+
value: "b",
|
|
4708
|
+
label: b.label
|
|
4709
|
+
}],
|
|
4710
|
+
value: showing,
|
|
4711
|
+
onChange: (v) => setShowing(v),
|
|
4712
|
+
size: "sm"
|
|
4713
|
+
}) }),
|
|
4714
|
+
body,
|
|
4715
|
+
keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
|
|
4716
|
+
]
|
|
4717
|
+
})
|
|
4718
|
+
});
|
|
4719
|
+
}
|
|
4720
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MIN_SCALE, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, NumberField, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, Slider, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable, useViewport, zoomAt };
|
|
4160
4721
|
|
|
4161
4722
|
//# sourceMappingURL=index.js.map
|