@enigmax/primitives 0.25.0 → 0.26.0

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.
Files changed (48) hide show
  1. package/dist/chunk-4SZ5N7BA.js +121 -0
  2. package/dist/chunk-EYZ366LP.js +189 -0
  3. package/dist/chunk-ISXB5RUH.js +380 -0
  4. package/dist/chunk-JJVZYW5C.js +946 -0
  5. package/dist/chunk-QIIV2QSV.js +108 -0
  6. package/dist/chunk-RUEQ3TGP.js +155 -0
  7. package/dist/clipboard-menu-BvXJCSFN.d.ts +93 -0
  8. package/dist/context-BfjYGPnH.d.ts +54 -0
  9. package/dist/{clipboard-menu-B_ouitfS.d.ts → context-menu-D3FtTn7v.d.ts} +1 -91
  10. package/dist/index.d.ts +266 -2
  11. package/dist/index.js +4 -2
  12. package/dist/menu-MSQSE6U5.js +54 -0
  13. package/dist/menu-PNQRTRNV.js +33 -0
  14. package/dist/next/index.d.ts +6 -2
  15. package/dist/next/index.js +10 -6
  16. package/dist/react/context-menu.d.ts +8 -54
  17. package/dist/react/image.d.ts +109 -0
  18. package/dist/react/image.js +3 -0
  19. package/dist/react/index.d.ts +6 -2
  20. package/dist/react/index.js +10 -6
  21. package/dist/react/input.js +1 -1
  22. package/dist/react/video.d.ts +120 -0
  23. package/dist/react/video.js +3 -0
  24. package/dist/react-router/index.d.ts +6 -2
  25. package/dist/react-router/index.js +10 -6
  26. package/dist/viewer-73LSE6RR.js +3 -0
  27. package/package.json +15 -2
  28. package/recipes/image/styles.css +182 -0
  29. package/recipes/video/styles.css +154 -0
  30. package/registry.json +465 -0
  31. package/src/core/image-viewer.ts +222 -0
  32. package/src/core/player.ts +303 -0
  33. package/src/index.ts +52 -0
  34. package/src/react/image/icons.tsx +55 -0
  35. package/src/react/image/index.tsx +185 -0
  36. package/src/react/image/menu.tsx +76 -0
  37. package/src/react/image/styles.ts +213 -0
  38. package/src/react/image/types.ts +113 -0
  39. package/src/react/image/viewer.tsx +571 -0
  40. package/src/react/index.ts +3 -0
  41. package/src/react/video/icons.tsx +135 -0
  42. package/src/react/video/index.tsx +724 -0
  43. package/src/react/video/menu.tsx +66 -0
  44. package/src/react/video/rail.tsx +99 -0
  45. package/src/react/video/styles.ts +161 -0
  46. package/src/react/video/types.ts +135 -0
  47. /package/dist/{chunk-3MGBZOAU.js → chunk-RMNXVWQ4.js} +0 -0
  48. /package/dist/{chunk-MSOCCQGH.js → chunk-T7I6WJSN.js} +0 -0
@@ -0,0 +1,121 @@
1
+ import { injectImageStyles } from './chunk-EYZ366LP.js';
2
+ import { lazy, useLayoutEffect, useState, useMemo, useEffect, useRef, useCallback, Suspense } from 'react';
3
+ import { jsx, jsxs } from 'react/jsx-runtime';
4
+
5
+ // src/react/image/types.ts
6
+ function toItem(source) {
7
+ return typeof source === "string" ? { src: source } : source;
8
+ }
9
+ var ImageViewer = lazy(() => import('./viewer-73LSE6RR.js').then((module) => ({ default: module.ImageViewer })));
10
+ var prefetched = false;
11
+ function prefetchViewer() {
12
+ if (prefetched) return;
13
+ prefetched = true;
14
+ void import('./viewer-73LSE6RR.js');
15
+ }
16
+ var ZOOM_DEFAULTS = { min: 1, max: 8, wheel: true, doubleClick: true };
17
+ function Image(props) {
18
+ const {
19
+ src,
20
+ alt,
21
+ images,
22
+ index,
23
+ lightbox = true,
24
+ zoom = true,
25
+ animate = true,
26
+ navigation = false,
27
+ thumbnails = false,
28
+ menu = false,
29
+ discardable = false,
30
+ onDiscard,
31
+ loop = true,
32
+ caption,
33
+ onOpenChange,
34
+ onIndexChange,
35
+ styles = true,
36
+ labels = {},
37
+ wrapperProps,
38
+ ...rest
39
+ } = props;
40
+ useLayoutEffect(() => {
41
+ if (styles) injectImageStyles();
42
+ }, [styles]);
43
+ const [open, setOpen] = useState(false);
44
+ const items = useMemo(() => {
45
+ const set = (images ?? [src]).map(toItem);
46
+ return set.some((entry) => entry.src === src) ? set : [{ src, alt }, ...set];
47
+ }, [images, src, alt]);
48
+ const initial = useMemo(() => {
49
+ if (typeof index === "number" && index >= 0 && index < items.length) return index;
50
+ const found = items.findIndex((entry) => entry.src === src);
51
+ return found === -1 ? 0 : found;
52
+ }, [index, items, src]);
53
+ const [current, setCurrent] = useState(initial);
54
+ useEffect(() => setCurrent(initial), [initial]);
55
+ const triggerRef = useRef(null);
56
+ const thumbnailRef = useRef(null);
57
+ const shown = useRef(current);
58
+ shown.current = current;
59
+ const origin = useCallback(() => shown.current === initial ? thumbnailRef.current?.getBoundingClientRect() ?? null : null, [initial]);
60
+ const zoomOptions = useMemo(() => {
61
+ if (zoom === false) return null;
62
+ const given = zoom === true ? {} : zoom;
63
+ return { ...ZOOM_DEFAULTS, ...given, doubleClick: given.doubleClick !== false, wheel: given.wheel !== false };
64
+ }, [zoom]);
65
+ const menuOptions = useMemo(() => menu === false ? null : menu === true ? {} : menu, [menu]);
66
+ const show = useCallback(() => {
67
+ if (!lightbox) return;
68
+ setOpen(true);
69
+ onOpenChange?.(true);
70
+ }, [lightbox, onOpenChange]);
71
+ const close = useCallback(() => {
72
+ setOpen(false);
73
+ onOpenChange?.(false);
74
+ triggerRef.current?.focus();
75
+ }, [onOpenChange]);
76
+ const goTo = useCallback((next) => {
77
+ setCurrent(next);
78
+ const item = items[next];
79
+ if (item) onIndexChange?.(next, item);
80
+ }, [items, onIndexChange]);
81
+ const image = /* @__PURE__ */ jsx("img", { ref: thumbnailRef, src, alt, ...rest });
82
+ return /* @__PURE__ */ jsxs("span", { ...wrapperProps, "data-enigma-image": "", "data-clickable": lightbox ? "" : void 0, children: [
83
+ lightbox ? /* @__PURE__ */ jsx(
84
+ "button",
85
+ {
86
+ ref: triggerRef,
87
+ type: "button",
88
+ "data-enigma-image-trigger": "",
89
+ "aria-label": labels.open ? `${labels.open}: ${alt}` : alt,
90
+ "aria-haspopup": "dialog",
91
+ onClick: show,
92
+ onPointerEnter: prefetchViewer,
93
+ onFocus: prefetchViewer,
94
+ children: image
95
+ }
96
+ ) : image,
97
+ open && /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
98
+ ImageViewer,
99
+ {
100
+ items,
101
+ index: current,
102
+ onIndex: goTo,
103
+ onClose: close,
104
+ zoom: zoomOptions,
105
+ navigation,
106
+ thumbnails,
107
+ menu: menuOptions,
108
+ discardable,
109
+ onDiscard,
110
+ loop,
111
+ caption,
112
+ origin,
113
+ animate,
114
+ styles,
115
+ labels
116
+ }
117
+ ) })
118
+ ] });
119
+ }
120
+
121
+ export { Image };
@@ -0,0 +1,189 @@
1
+ // src/react/image/styles.ts
2
+ var IMAGE_STYLES = `
3
+ :root {
4
+ --enigma-image-backdrop: rgba(0, 0, 0, 0.92);
5
+ --enigma-image-text: #f5f5f5;
6
+ --enigma-image-muted: #a3a3a3;
7
+ --enigma-image-control-bg: rgba(23, 23, 23, 0.72);
8
+ --enigma-image-control-hover: rgba(64, 64, 64, 0.82);
9
+ --enigma-image-control-size: 2.25rem;
10
+ --enigma-image-radius: 0.625rem;
11
+ --enigma-image-gap: 0.75rem;
12
+ --enigma-image-thumb-size: 3.5rem;
13
+ --enigma-image-focus: #f5f5f5;
14
+ /* Above the page's own chrome, not merely above its content: a header or a sticky sidebar
15
+ with a z-index of its own would otherwise paint over the dialog covering it. */
16
+ --enigma-image-z: 9999;
17
+ /* How long the picture takes to fly out of the page and back into it, and the curve it
18
+ flies on. They are the numbers core/image-viewer.ts waits for, so a project that
19
+ changes one here changes it there - see the note above the keyframes. */
20
+ --enigma-image-flight: 300ms;
21
+ --enigma-image-flight-ease: cubic-bezier(0.2, 0, 0.2, 1);
22
+ }
23
+
24
+ /* The thumbnail in the page. Only what the behaviour needs: the pointer says it opens, and
25
+ the box is the caller's to size. */
26
+ [data-enigma-image] { display: inline-flex; max-width: 100%; }
27
+ [data-enigma-image][data-clickable] { cursor: zoom-in; }
28
+ /* Stated on the picture as well as inherited: a project that restyles the trigger button is
29
+ one cursor: pointer away from a thumbnail that no longer says it enlarges. */
30
+ [data-enigma-image][data-clickable] img { cursor: zoom-in; }
31
+ [data-enigma-image] img { display: block; max-width: 100%; height: auto; }
32
+ /* A real box, never display:contents: an element without one cannot be focused in Chromium,
33
+ so a viewer closed with Escape would hand focus to the body instead of back to the picture
34
+ it was opened from, and the next Tab would start at the top of the page. */
35
+ [data-enigma-image-trigger] {
36
+ display: inline-flex; max-width: 100%; padding: 0; margin: 0;
37
+ background: none; border: 0; color: inherit; font: inherit; cursor: inherit;
38
+ }
39
+ [data-enigma-image-trigger]:focus-visible img { outline: 2px solid var(--enigma-image-focus); outline-offset: 3px; }
40
+
41
+ /* The viewer. Fixed and portalled: a lightbox inside the page's own stacking context is a
42
+ lightbox some ancestor's overflow or transform will clip. */
43
+ [data-enigma-image-viewer] {
44
+ position: fixed; inset: 0; z-index: var(--enigma-image-z);
45
+ display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
46
+ background: var(--enigma-image-backdrop);
47
+ color: var(--enigma-image-text);
48
+ }
49
+
50
+ /* The opening: the backdrop arrives while the picture flies out of the page, and the toolbar
51
+ and the strip arrive with it rather than being there first over a picture that is still on
52
+ its way. data-state is only ever "opening" or "closing" while an animation is meant to be
53
+ running, so a viewer that skipped the flight - reduced motion, animate={false} - matches
54
+ none of these rules and simply exists. */
55
+ @keyframes enigma-image-in { from { background-color: transparent; } to { background-color: var(--enigma-image-backdrop); } }
56
+ @keyframes enigma-image-chrome { from { opacity: 0; } to { opacity: 1; } }
57
+ [data-enigma-image-viewer][data-state="opening"] { animation: enigma-image-in var(--enigma-image-flight) ease-out; }
58
+ [data-enigma-image-viewer][data-state="opening"] [data-enigma-image-bar],
59
+ [data-enigma-image-viewer][data-state="opening"] [data-enigma-image-foot],
60
+ [data-enigma-image-viewer][data-state="opening"] [data-enigma-image-nav] {
61
+ animation: enigma-image-chrome var(--enigma-image-flight) ease-out;
62
+ }
63
+ /* On the way out the backdrop drains, and the dialog stops taking presses: it is over the
64
+ page again, so a click through it would land on whatever is now under the pointer. */
65
+ [data-enigma-image-viewer][data-state="closing"] {
66
+ background-color: transparent; pointer-events: none;
67
+ transition: background-color var(--enigma-image-flight) var(--enigma-image-flight-ease);
68
+ }
69
+ [data-enigma-image-viewer][data-state="closing"] [data-enigma-image-bar],
70
+ [data-enigma-image-viewer][data-state="closing"] [data-enigma-image-foot],
71
+ [data-enigma-image-viewer][data-state="closing"] [data-enigma-image-nav] {
72
+ opacity: 0; transition: opacity calc(var(--enigma-image-flight) / 2) ease-in;
73
+ }
74
+
75
+ [data-enigma-image-bar] {
76
+ display: flex; align-items: center; gap: 0.5rem;
77
+ padding: var(--enigma-image-gap);
78
+ }
79
+ [data-enigma-image-counter] {
80
+ font-size: 0.8125rem; font-variant-numeric: tabular-nums; color: var(--enigma-image-muted);
81
+ margin-inline-end: auto;
82
+ }
83
+
84
+ [data-enigma-image-button] {
85
+ display: grid; place-items: center; flex: none;
86
+ width: var(--enigma-image-control-size); height: var(--enigma-image-control-size);
87
+ padding: 0; color: var(--enigma-image-text);
88
+ background: var(--enigma-image-control-bg); border: 0; border-radius: 999px;
89
+ cursor: pointer;
90
+ }
91
+ [data-enigma-image-button]:hover { background: var(--enigma-image-control-hover); }
92
+ [data-enigma-image-button]:focus-visible { outline: 2px solid var(--enigma-image-focus); outline-offset: 2px; }
93
+ [data-enigma-image-button][disabled] { opacity: 0.35; cursor: not-allowed; }
94
+
95
+ /* The frame the picture is fitted into, and the surface every gesture is measured against. */
96
+ [data-enigma-image-frame] {
97
+ position: relative; overflow: hidden;
98
+ display: grid; place-items: center;
99
+ /* Room for the arrows down each side, so they sit beside the picture rather than on it. */
100
+ padding: 0 calc(var(--enigma-image-control-size) + var(--enigma-image-gap) * 1.5);
101
+ /* The drag IS the control once zoomed, so the page must not scroll under it. */
102
+ touch-action: none;
103
+ -webkit-user-select: none; user-select: none;
104
+ }
105
+ [data-enigma-image-frame] img {
106
+ max-width: 100%; max-height: 100%;
107
+ -webkit-user-drag: none;
108
+ will-change: transform;
109
+ }
110
+ /* Only while it is MOVING, which is not the same as "during the flight".
111
+ A transition left on permanently would put 300ms of lag between the wheel and the zoom, and
112
+ turn every pan into a drag the picture follows late. And one left on during "pending" is
113
+ worse than useless: putting the picture on the thumbnail is itself a transform change, so it
114
+ animated there over 300ms - behind a hidden element - and by the time anybody could see it
115
+ the flight was nearly over. */
116
+ [data-enigma-image-frame][data-flying="moving"] img { transition: transform var(--enigma-image-flight) var(--enigma-image-flight-ease); }
117
+ /* Not drawn until there is somewhere to fly from - see the note on the attribute. The spinner
118
+ is what stands in for it, the same one a slow picture gets. */
119
+ [data-enigma-image-frame][data-flying="pending"] img { visibility: hidden; }
120
+ @media (prefers-reduced-motion: reduce) {
121
+ [data-enigma-image-frame][data-flying="moving"] img { transition: none; }
122
+ }
123
+
124
+ /* The cursor says what a press does, which in a lightbox is three different things. The empty
125
+ part of the frame IS the backdrop and closes it; the picture at rest takes a double press to
126
+ enlarge; once it is enlarged the gesture is a drag. */
127
+ [data-enigma-image-frame] { cursor: zoom-out; }
128
+ [data-enigma-image-frame][data-zoom] img { cursor: zoom-in; }
129
+ [data-enigma-image-frame][data-zoomed],
130
+ [data-enigma-image-frame][data-zoomed] img { cursor: grab; }
131
+ [data-enigma-image-frame][data-panning],
132
+ [data-enigma-image-frame][data-panning] img { cursor: grabbing; }
133
+ [data-enigma-image-frame][data-loading] img { opacity: 0.35; }
134
+
135
+ /* Left and right sit over the picture rather than beside it: the frame is the biggest thing
136
+ on screen and the arrows have to be reachable without hunting for an edge. */
137
+ [data-enigma-image-nav] {
138
+ position: absolute; top: 50%; translate: 0 -50%;
139
+ width: var(--enigma-image-control-size); height: var(--enigma-image-control-size);
140
+ }
141
+ [data-enigma-image-nav="previous"] { left: var(--enigma-image-gap); }
142
+ [data-enigma-image-nav="next"] { right: var(--enigma-image-gap); }
143
+
144
+ [data-enigma-image-spinner] {
145
+ position: absolute; width: 1.75rem; height: 1.75rem;
146
+ border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: var(--enigma-image-text);
147
+ border-radius: 999px; animation: enigma-image-spin 700ms linear infinite;
148
+ }
149
+ @keyframes enigma-image-spin { to { rotate: 360deg; } }
150
+ @media (prefers-reduced-motion: reduce) {
151
+ [data-enigma-image-spinner] { animation-duration: 2s; }
152
+ }
153
+
154
+ [data-enigma-image-foot] { display: grid; gap: 0.5rem; padding: var(--enigma-image-gap); }
155
+ [data-enigma-image-caption] {
156
+ margin: 0; text-align: center; font-size: 0.8125rem; line-height: 1.5;
157
+ color: var(--enigma-image-muted);
158
+ }
159
+
160
+ /* The strip. Scrolls on its own rather than wrapping: a gallery of forty is one row you drag
161
+ through, not five rows that push the picture off the screen. */
162
+ [data-enigma-image-strip] {
163
+ display: flex; gap: 0.5rem; overflow-x: auto; scrollbar-width: thin;
164
+ justify-content: safe center;
165
+ padding-bottom: 0.25rem;
166
+ }
167
+ [data-enigma-image-thumb] {
168
+ flex: none; width: var(--enigma-image-thumb-size); height: var(--enigma-image-thumb-size);
169
+ padding: 0; overflow: hidden;
170
+ background: none; border: 0; border-radius: 0.375rem;
171
+ opacity: 0.55; cursor: pointer;
172
+ }
173
+ [data-enigma-image-thumb] img { width: 100%; height: 100%; object-fit: cover; }
174
+ [data-enigma-image-thumb]:hover { opacity: 0.85; }
175
+ [data-enigma-image-thumb][aria-current="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--enigma-image-focus); }
176
+ [data-enigma-image-thumb]:focus-visible { outline: 2px solid var(--enigma-image-focus); outline-offset: 2px; }
177
+ `;
178
+ var injected = false;
179
+ function injectImageStyles() {
180
+ if (injected || typeof document === "undefined") return;
181
+ injected = true;
182
+ if (document.querySelector("[data-enigma-image-styles]")) return;
183
+ const element = document.createElement("style");
184
+ element.setAttribute("data-enigma-image-styles", "");
185
+ element.textContent = IMAGE_STYLES;
186
+ document.head.prepend(element);
187
+ }
188
+
189
+ export { injectImageStyles };