@alulore/kumiko 0.15.0 → 0.16.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 (36) hide show
  1. package/dist/card/card.d.ts +16 -1
  2. package/dist/card/card.js +12 -4
  3. package/dist/card/item-card.d.ts +9 -1
  4. package/dist/card/item-card.js +10 -4
  5. package/dist/list-row/list-row-motion.js +2 -1
  6. package/dist/media-viewer/icons.d.ts +4 -0
  7. package/dist/media-viewer/icons.js +18 -0
  8. package/dist/media-viewer/index.d.ts +4 -0
  9. package/dist/media-viewer/index.js +3 -0
  10. package/dist/media-viewer/media-slide.d.ts +14 -0
  11. package/dist/media-viewer/media-slide.js +67 -0
  12. package/dist/media-viewer/media-viewer.css +611 -0
  13. package/dist/media-viewer/media-viewer.d.ts +17 -0
  14. package/dist/media-viewer/media-viewer.js +241 -0
  15. package/dist/media-viewer/pager-drag.d.ts +10 -0
  16. package/dist/media-viewer/pager-drag.js +53 -0
  17. package/dist/media-viewer/types.d.ts +58 -0
  18. package/dist/media-viewer/types.js +17 -0
  19. package/dist/media-viewer/video-controls.d.ts +3 -0
  20. package/dist/media-viewer/video-controls.js +62 -0
  21. package/dist/media-viewer/view-gesture.d.ts +74 -0
  22. package/dist/media-viewer/view-gesture.js +465 -0
  23. package/dist/media-viewer/viewer-chrome.d.ts +13 -0
  24. package/dist/media-viewer/viewer-chrome.js +35 -0
  25. package/dist/media-viewer/viewer-motion.d.ts +9 -0
  26. package/dist/media-viewer/viewer-motion.js +126 -0
  27. package/dist/media-viewer/zoom-pan.d.ts +35 -0
  28. package/dist/media-viewer/zoom-pan.js +102 -0
  29. package/dist/titlebar/index.d.ts +2 -0
  30. package/dist/titlebar/index.js +2 -0
  31. package/dist/titlebar/titlebar-looks.d.ts +53 -0
  32. package/dist/titlebar/titlebar-looks.js +26 -0
  33. package/dist/titlebar/titlebar.css +561 -0
  34. package/dist/titlebar/titlebar.d.ts +54 -0
  35. package/dist/titlebar/titlebar.js +68 -0
  36. package/package.json +19 -1
@@ -45,6 +45,14 @@ export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
45
45
  over?: boolean;
46
46
  /** A well with a solid fill, for use as a drop target on a busy background. */
47
47
  solid?: boolean;
48
+ /**
49
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
50
+ * `onClick`) is pressable and a plain `div` is not. `true` makes a plain card react too, for a card that something
51
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
52
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
53
+ * props is ignored.
54
+ */
55
+ pressable?: boolean;
48
56
  /** The lamp at the start of a banner. */
49
57
  lamp?: React.ReactNode;
50
58
  /** The actions at the end of a banner. */
@@ -54,9 +62,16 @@ export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
54
62
  };
55
63
  /** An empty data attribute when on, and none when off. */
56
64
  export declare function flag(on: boolean | undefined): string | undefined;
65
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
66
+ export declare function isPressable(pressable: boolean | undefined, natural: boolean, off: {
67
+ disabled: boolean;
68
+ readOnly: boolean;
69
+ }): boolean;
70
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
71
+ export declare function withoutPressable(props: object): Record<string, unknown>;
57
72
  /**
58
73
  * A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
59
74
  * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
60
75
  * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
61
76
  */
62
- export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
77
+ export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, pressable, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
package/dist/card/card.js CHANGED
@@ -12,6 +12,14 @@ export function lookAttributes(looks) {
12
12
  export function flag(on) {
13
13
  return on ? "" : undefined;
14
14
  }
15
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
16
+ export function isPressable(pressable, natural, off) {
17
+ return !off.disabled && !off.readOnly && (pressable ?? natural);
18
+ }
19
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
20
+ export function withoutPressable(props) {
21
+ return Object.fromEntries(Object.entries(props).filter(([name]) => name !== "data-pressable"));
22
+ }
15
23
  /** A banner's row: the lamp, the body and the actions. */
16
24
  function banner(lamp, children, actions) {
17
25
  return (_jsxs(_Fragment, { children: [lamp ? _jsx("div", { "data-slot": "card-lamp", children: lamp }) : null, _jsx("div", { "data-slot": "card-body", children: children }), actions ? _jsx("div", { "data-slot": "card-actions", children: actions }) : null] }));
@@ -21,7 +29,7 @@ function banner(lamp, children, actions) {
21
29
  * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
22
30
  * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
23
31
  */
24
- export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
32
+ export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, pressable, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
25
33
  const asButton = !readOnly && (variant === "add" || (variant === "interactive" && onClick !== undefined));
26
34
  const common = {
27
35
  "data-slot": "card",
@@ -31,8 +39,7 @@ export function Card({ variant = "surface", surface, hover, press, addLook, disa
31
39
  "data-over": flag(over),
32
40
  "data-solid": flag(solid),
33
41
  "data-readonly": flag(readOnly),
34
- "data-disabled": flag(disabled),
35
- "data-pressable": flag(asButton && !disabled)
42
+ "data-disabled": flag(disabled)
36
43
  };
37
44
  const kind = asButton
38
45
  ? { type: "button", disabled, onClick }
@@ -41,7 +48,8 @@ export function Card({ variant = "surface", surface, hover, press, addLook, disa
41
48
  return renderElement(asButton ? "button" : "div", {
42
49
  ...common,
43
50
  ...kind,
44
- ...props,
51
+ ...withoutPressable(props),
52
+ "data-pressable": flag(isPressable(pressable, asButton, { disabled, readOnly })),
45
53
  ref,
46
54
  children: body
47
55
  });
@@ -19,6 +19,14 @@ export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
19
19
  disabled?: boolean;
20
20
  /** Shown as it is, with no hover, press or pointer cursor, and not dimmed. */
21
21
  readOnly?: boolean;
22
+ /**
23
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
24
+ * `onClick`) is pressable and a plain box is not. `true` makes a plain card react too, for a card that something
25
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
26
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
27
+ * props is ignored.
28
+ */
29
+ pressable?: boolean;
22
30
  /** Draws the card on its only child, which receives the props. */
23
31
  asChild?: boolean;
24
32
  /** The card's element. With `asChild` it goes to the child. */
@@ -49,7 +57,7 @@ export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
49
57
  * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
50
58
  * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
51
59
  */
52
- export declare function ItemCard({ asChild, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
60
+ export declare function ItemCard({ asChild, pressable: pressableProp, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
53
61
  export type ItemCardEyebrowProps = React.ComponentPropsWithoutRef<"span"> & {
54
62
  /** The colour of the small diamond, any CSS colour. */
55
63
  dot?: string;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { mergeProps, renderElement } from "@ui-sdk/react/primitive";
3
3
  import { Children, isValidElement } from "react";
4
4
  import { Badge } from "../badge/badge";
5
- import { flag, lookAttributes } from "./card";
5
+ import { flag, isPressable, lookAttributes, withoutPressable } from "./card";
6
6
  /** Splits the props into the data attributes that carry the state and looks, and the rest for the element. */
7
7
  function splitProps(props) {
8
8
  const { tone, selected, done, dragging, disabled, readOnly, ...more } = props;
@@ -22,17 +22,23 @@ function splitProps(props) {
22
22
  "aria-disabled": disabled ? true : undefined,
23
23
  ...lookAttributes({ surface, hover, press })
24
24
  };
25
- return { state, dom, disabled: disabled === true, readOnly: readOnly === true };
25
+ return {
26
+ state,
27
+ dom: withoutPressable(dom),
28
+ disabled: disabled === true,
29
+ readOnly: readOnly === true
30
+ };
26
31
  }
27
32
  /**
28
33
  * A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
29
34
  * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
30
35
  * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
31
36
  */
32
- export function ItemCard({ asChild = false, onClick, children, ref, ...props }) {
37
+ export function ItemCard({ asChild = false, pressable: pressableProp, onClick, children, ref, ...props }) {
33
38
  const { state, dom, disabled, readOnly } = splitProps(props);
34
39
  const clickable = onClick !== undefined && !readOnly;
35
- const pressable = { ...state, "data-pressable": flag(clickable && !disabled) };
40
+ const on = isPressable(pressableProp, clickable, { disabled, readOnly });
41
+ const pressable = { ...state, "data-pressable": flag(on) };
36
42
  if (asChild && isValidElement(children)) {
37
43
  const own = { onClick: clickable && !disabled ? onClick : undefined, ref };
38
44
  return renderElement("div", mergeProps(dom, own, pressable), children);
@@ -48,7 +48,8 @@ function syncRoving(list, stop) {
48
48
  return;
49
49
  }
50
50
  const kept = stop && rows.includes(stop) ? stop : null;
51
- const start = kept ?? rows.find((row) => Object.hasOwn(row.dataset, "current")) ?? rows[0];
51
+ const marked = (name) => rows.find((row) => Object.hasOwn(row.dataset, name));
52
+ const start = kept ?? marked("current") ?? marked("selected") ?? rows[0];
52
53
  for (const row of rows) {
53
54
  row.dataset.roving = "";
54
55
  row.tabIndex = row === start ? 0 : -1;
@@ -0,0 +1,4 @@
1
+ export type IconName = "close" | "previous" | "next" | "fullscreen" | "download" | "play" | "pause" | "sound" | "muted" | "plus" | "minus";
2
+ export declare function Icon({ name }: {
3
+ name: IconName;
4
+ }): React.JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const paths = {
3
+ close: "M6 6l12 12M18 6L6 18",
4
+ previous: "M15 5l-7 7 7 7",
5
+ next: "M9 5l7 7-7 7",
6
+ fullscreen: "M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5",
7
+ download: "M12 3v12m0 0l-4-4m4 4l4-4M4 19h16",
8
+ play: "M8 5l11 7-11 7z",
9
+ pause: "M8 5v14M16 5v14",
10
+ sound: "M4 9v6h4l5 4V5L8 9zM17 8c1.5 1.2 1.5 6.8 0 8",
11
+ muted: "M4 9v6h4l5 4V5L8 9zM17 9l4 6M21 9l-4 6",
12
+ plus: "M12 5v14M5 12h14",
13
+ minus: "M5 12h14"
14
+ };
15
+ /* Strokes in the text colour, so they follow forced colours and any token. */
16
+ export function Icon({ name }) {
17
+ return (_jsx("svg", { "data-mv-icon": "", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: paths[name] }) }));
18
+ }
@@ -0,0 +1,4 @@
1
+ export { MediaViewer, type MediaViewerProps } from "./media-viewer";
2
+ export { behaviourDefaults, lookDefaults, type Background, type Chrome, type DoubleTap, type Indicator, type Layout, type MediaViewerBehaviour, type MediaViewerItem, type MediaViewerLook, type OpenMotion, type PagingMotion, type VideoControls, type WheelMode, type ZoomedDrag } from "./types";
3
+ export { FIT, actualScale, clampPan, fitSize, maxScale, panLimits, zoomTo, type View, type ZoomAnchor } from "./zoom-pan";
4
+ export type { OriginOf } from "./viewer-motion";
@@ -0,0 +1,3 @@
1
+ export { MediaViewer } from "./media-viewer";
2
+ export { behaviourDefaults, lookDefaults } from "./types";
3
+ export { FIT, actualScale, clampPan, fitSize, maxScale, panLimits, zoomTo } from "./zoom-pan";
@@ -0,0 +1,14 @@
1
+ import type { MediaViewerItem, VideoControls as VideoControlsMode } from "./types";
2
+ import { ViewGesture, type GestureHooks, type GestureOptions } from "./view-gesture";
3
+ export type SlideSignals = Omit<GestureHooks, "natural">;
4
+ export interface MediaSlideProps {
5
+ item: MediaViewerItem;
6
+ /** Only the slide in view takes gestures; the others rest at fit. */
7
+ active: boolean;
8
+ options: GestureOptions;
9
+ signals: SlideSignals;
10
+ videoControls: VideoControlsMode;
11
+ /** Receives the slide's gesture while it is active, so buttons and keys can zoom it. */
12
+ gestureRef: React.RefObject<ViewGesture | null>;
13
+ }
14
+ export declare function MediaSlide(props: MediaSlideProps): React.JSX.Element;
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { VideoControls } from "./video-controls";
4
+ import { ViewGesture } from "./view-gesture";
5
+ function naturalOf(item, media) {
6
+ if (media instanceof HTMLImageElement && media.naturalWidth > 0) {
7
+ return { w: media.naturalWidth, h: media.naturalHeight };
8
+ }
9
+ if (media instanceof HTMLVideoElement && media.videoWidth > 0) {
10
+ return { w: media.videoWidth, h: media.videoHeight };
11
+ }
12
+ return { w: item.width ?? 0, h: item.height ?? 0 };
13
+ }
14
+ /* Keeps the newest value in a ref, so a gesture made once always reads current props. */
15
+ function useLatest(value) {
16
+ const ref = useRef(value);
17
+ useEffect(() => {
18
+ ref.current = value;
19
+ });
20
+ return ref;
21
+ }
22
+ function useGesture(stage, media, props) {
23
+ const options = useLatest(props.options);
24
+ const signals = useLatest(props.signals);
25
+ const { active, item, gestureRef } = props;
26
+ useEffect(() => {
27
+ const el = stage.current;
28
+ if (!active || !el) {
29
+ return undefined;
30
+ }
31
+ const hooks = () => ({
32
+ ...signals.current,
33
+ natural: () => naturalOf(item, media.current)
34
+ });
35
+ const gesture = new ViewGesture(el, () => options.current, hooks);
36
+ gestureRef.current = gesture;
37
+ return () => {
38
+ gesture.destroy();
39
+ gestureRef.current = null;
40
+ };
41
+ }, [active, item, gestureRef, stage, media, options, signals]);
42
+ }
43
+ function useVideoPause(video, active) {
44
+ useEffect(() => {
45
+ if (!active) {
46
+ video.current?.pause();
47
+ }
48
+ }, [active, video]);
49
+ }
50
+ function Picture({ item, media }) {
51
+ return (_jsx("img", { ref: media, "data-mv-media": "", src: item.src, alt: item.name, width: item.width, height: item.height, draggable: false }));
52
+ }
53
+ function Clip({ item, video, controls }) {
54
+ const ratio = item.width && item.height ? item.width / item.height : 16 / 9;
55
+ const style = { "--mv-ratio": String(ratio) };
56
+ return (_jsxs("div", { "data-mv-clip": "", style: style, children: [_jsx("video", { ref: video, "data-mv-media": "", src: item.src, poster: item.poster, "aria-label": item.name, controls: controls === "native", playsInline: true, loop: true, preload: "metadata" }), controls === "custom" ? _jsx(VideoControls, { video: video }) : null] }));
57
+ }
58
+ export function MediaSlide(props) {
59
+ const { item, active, videoControls } = props;
60
+ const stage = useRef(null);
61
+ const image = useRef(null);
62
+ const video = useRef(null);
63
+ const isVideo = item.kind === "video";
64
+ useGesture(stage, isVideo ? video : image, props);
65
+ useVideoPause(video, active);
66
+ return (_jsx("div", { ref: stage, "data-mv-stage": "", "data-active": active ? "" : undefined, "data-kind": isVideo ? "video" : "image", "data-native-controls": isVideo && videoControls === "native" ? "" : undefined, children: isVideo ? (_jsx(Clip, { item: item, video: video, controls: videoControls })) : (_jsx(Picture, { item: item, media: image })) }));
67
+ }