@tensor_1/react 2.59.0 → 2.61.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.
@@ -0,0 +1,137 @@
1
+ "use client";
2
+ import { useEffect } from "react";
3
+ import { keyboardInitiated, watchInputModality } from "../motion.js";
4
+ function useHoverGlide(layerRef, itemSelector, enabled = true) {
5
+ useEffect(() => {
6
+ const layer = layerRef.current;
7
+ const container = layer?.parentElement;
8
+ if (!enabled || !container || !layer) return void 0;
9
+ let current = null;
10
+ let raf = 0;
11
+ let base = { w: 0, h: 0 };
12
+ watchInputModality();
13
+ const hide = () => {
14
+ current = null;
15
+ window.cancelAnimationFrame(raf);
16
+ layer.removeAttribute("data-shown");
17
+ layer.removeAttribute("data-gliding");
18
+ container.removeAttribute("data-uix-glide");
19
+ };
20
+ const place = (item) => {
21
+ const top = offsetWithin(item, container, "top");
22
+ const left = offsetWithin(item, container, "left");
23
+ const sx = base.w ? item.offsetWidth / base.w : 1;
24
+ const sy = base.h ? item.offsetHeight / base.h : 1;
25
+ layer.style.transform = `translate(${left}px, ${top}px) scale(${sx}, ${sy})`;
26
+ };
27
+ const settle = (item) => {
28
+ base = { w: item.offsetWidth, h: item.offsetHeight };
29
+ layer.style.width = `${base.w}px`;
30
+ layer.style.height = `${base.h}px`;
31
+ layer.style.borderRadius = window.getComputedStyle(item).borderTopLeftRadius || "0px";
32
+ };
33
+ const target = (event) => {
34
+ const el = event.target?.closest?.(itemSelector);
35
+ if (!el || !container.contains(el)) return null;
36
+ if (el.matches(':disabled, [aria-disabled="true"]')) return null;
37
+ return el;
38
+ };
39
+ const forced = () => !!window.matchMedia?.("(forced-colors: active)").matches;
40
+ const show = (item) => {
41
+ if (item === current) return;
42
+ const first = current === null;
43
+ current = item;
44
+ if (first) {
45
+ layer.removeAttribute("data-gliding");
46
+ settle(item);
47
+ place(item);
48
+ container.setAttribute("data-uix-glide", "");
49
+ window.cancelAnimationFrame(raf);
50
+ raf = window.requestAnimationFrame(() => {
51
+ layer.setAttribute("data-shown", "");
52
+ });
53
+ return;
54
+ }
55
+ layer.setAttribute("data-gliding", "");
56
+ place(item);
57
+ };
58
+ const onOver = (event) => {
59
+ if (event.pointerType === "touch" || forced()) return;
60
+ const item = target(event);
61
+ if (!item) {
62
+ if (current) hide();
63
+ return;
64
+ }
65
+ show(item);
66
+ };
67
+ const onFocus = (event) => {
68
+ if (!keyboardInitiated() || forced()) return;
69
+ const item = target(event);
70
+ if (item) show(item);
71
+ };
72
+ const active = typeof MutationObserver === "undefined" ? null : new MutationObserver((records) => {
73
+ if (!keyboardInitiated() || forced()) return;
74
+ for (const r of records) {
75
+ const el = r.target;
76
+ if (el.hasAttribute("data-active") && el.matches(itemSelector) && !el.matches(':disabled, [aria-disabled="true"]')) {
77
+ show(el);
78
+ return;
79
+ }
80
+ }
81
+ });
82
+ active?.observe(container, { subtree: true, attributes: true, attributeFilter: ["data-active"] });
83
+ const keyRow = () => {
84
+ const focused = document.activeElement;
85
+ if (focused instanceof HTMLElement && focused !== container && container.contains(focused) && focused.matches(itemSelector)) return focused;
86
+ const active2 = container.querySelector(`${itemSelector}[data-active]`);
87
+ return active2 && container.contains(active2) ? active2 : null;
88
+ };
89
+ const onLeave = (event) => {
90
+ if (event.pointerType === "touch") return;
91
+ const row = keyRow();
92
+ if (row && !forced()) show(row);
93
+ else hide();
94
+ };
95
+ const onFocusOut = (event) => {
96
+ const next = event.relatedTarget;
97
+ if (next && container.contains(next)) return;
98
+ if (!container.matches(":hover")) hide();
99
+ };
100
+ const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
101
+ if (current) hide();
102
+ });
103
+ resized?.observe(container);
104
+ container.addEventListener("pointerover", onOver);
105
+ container.addEventListener("pointerleave", onLeave);
106
+ container.addEventListener("focusin", onFocus);
107
+ container.addEventListener("focusout", onFocusOut);
108
+ return () => {
109
+ container.removeEventListener("focusout", onFocusOut);
110
+ resized?.disconnect();
111
+ active?.disconnect();
112
+ container.removeEventListener("pointerover", onOver);
113
+ container.removeEventListener("pointerleave", onLeave);
114
+ container.removeEventListener("focusin", onFocus);
115
+ hide();
116
+ };
117
+ }, [layerRef, itemSelector, enabled]);
118
+ }
119
+ function offsetWithin(item, container, side) {
120
+ let total = 0;
121
+ let el = item;
122
+ while (el && el !== container) {
123
+ total += side === "top" ? el.offsetTop : el.offsetLeft;
124
+ const parent = el.offsetParent;
125
+ if (parent === container) return total;
126
+ if (!parent || !container.contains(parent)) {
127
+ const a = item.getBoundingClientRect();
128
+ const b = container.getBoundingClientRect();
129
+ return side === "top" ? a.top - b.top + container.scrollTop - container.clientTop : a.left - b.left + container.scrollLeft - container.clientLeft;
130
+ }
131
+ el = parent;
132
+ }
133
+ return total;
134
+ }
135
+ export {
136
+ useHoverGlide
137
+ };
@@ -3,7 +3,7 @@ import { CSSProperties } from 'react';
3
3
  import { IconNode, UixIcon, IconProps } from './types.js';
4
4
 
5
5
  /** Renders a glyph as an inline SVG; the props contract shared by every icon. */
6
- declare function renderIcon(node: IconNode, { size, tone, label, strokeWidth, className, style, ...rest }: IconProps, ref?: unknown): react.ReactElement<{
6
+ declare function renderIcon(node: IconNode, { size, tone, label, strokeWidth, animate, className, style, ...rest }: IconProps, ref?: unknown, name?: string): react.ReactElement<{
7
7
  string?: number | string | undefined | undefined;
8
8
  filter?: string | undefined | undefined;
9
9
  values?: string | undefined | undefined;
@@ -269,11 +269,11 @@ declare function renderIcon(node: IconNode, { size, tone, label, strokeWidth, cl
269
269
  clip?: number | string | undefined | undefined;
270
270
  stroke: string;
271
271
  href?: string | undefined | undefined;
272
+ d?: string | undefined | undefined;
272
273
  mask?: string | undefined | undefined;
273
274
  path?: string | undefined | undefined;
274
275
  key?: react.Key | null | undefined;
275
276
  format?: number | string | undefined | undefined;
276
- d?: string | undefined | undefined;
277
277
  capHeight?: number | string | undefined | undefined;
278
278
  dy?: number | string | undefined | undefined;
279
279
  dx?: number | string | undefined | undefined;
@@ -482,6 +482,8 @@ declare function renderIcon(node: IconNode, { size, tone, label, strokeWidth, cl
482
482
  strokeWidth: string | number;
483
483
  className: string;
484
484
  style: CSSProperties | undefined;
485
+ 'data-icon': string | undefined;
486
+ 'data-animate': string | undefined;
485
487
  }, string | react.JSXElementConstructor<any>>;
486
488
  /** Makes a named, ref-forwarding component for one glyph (the generated `<Name>Icon` exports). */
487
489
  declare function createIcon(displayName: string, node: IconNode): UixIcon;
@@ -1,7 +1,7 @@
1
1
  import { createElement, forwardRef } from "react";
2
2
  import { cx } from "../cx.js";
3
3
  const SIZES = /* @__PURE__ */ new Set(["sm", "md", "lg"]);
4
- function renderIcon(node, { size = "md", tone = "current", label, strokeWidth = 2, className, style, ...rest }, ref) {
4
+ function renderIcon(node, { size = "md", tone = "current", label, strokeWidth = 2, animate, className, style, ...rest }, ref, name) {
5
5
  const tokenSize = typeof size === "string" && SIZES.has(size);
6
6
  const length = typeof size === "number" ? `${size}px` : tokenSize ? void 0 : size;
7
7
  return createElement(
@@ -21,13 +21,17 @@ function renderIcon(node, { size = "md", tone = "current", label, strokeWidth =
21
21
  role: label ? "img" : void 0,
22
22
  "aria-label": label || void 0,
23
23
  "aria-hidden": label ? void 0 : true,
24
+ // the animated icons (2.60): icon.css keys each motion on the glyph's name
25
+ "data-icon": animate && name ? name : void 0,
26
+ "data-animate": animate ? "" : void 0,
24
27
  ...rest
25
28
  },
26
29
  node.map(([tag, attrs], i) => createElement(tag, { key: i, ...attrs }))
27
30
  );
28
31
  }
29
32
  function createIcon(displayName, node) {
30
- const Component = forwardRef((props, ref) => renderIcon(node, props, ref));
33
+ const name = displayName.replace(/Icon$/, "").replace(/([a-z0-9])([A-Z])|([a-zA-Z])(\d)/g, (_, a, b, c, d) => a ? `${a}-${b}` : `${c}-${d}`).toLowerCase();
34
+ const Component = forwardRef((props, ref) => renderIcon(node, props, ref, name));
31
35
  Component.displayName = displayName;
32
36
  return Component;
33
37
  }
@@ -2,7 +2,7 @@ import { forwardRef } from "react";
2
2
  import { renderIcon } from "./Icon.js";
3
3
  import { ICON_GLYPHS } from "./glyphs.js";
4
4
  const Icon = forwardRef(function Icon2({ name, ...props }, ref) {
5
- return renderIcon(ICON_GLYPHS[name], props, ref);
5
+ return renderIcon(ICON_GLYPHS[name], props, ref, name);
6
6
  });
7
7
  export {
8
8
  Icon
@@ -19,6 +19,17 @@ interface IconProps extends Omit<SVGProps<SVGSVGElement>, 'ref'> {
19
19
  label?: string;
20
20
  /** Stroke width in the 24-unit box. Default 2. */
21
21
  strokeWidth?: number | string;
22
+ /**
23
+ * Let the icon answer its control (2.60, the kit's animated icons). On a pointer hover over the
24
+ * button, link, menu item or tab around it, an icon with a motion of its own plays it once: the
25
+ * arrow nudges forward, plus and close turn a quarter, the gear turns one tooth, refresh turns
26
+ * half, the bell tips, send lifts off, download and upload move their arrow, the bin lifts its lid,
27
+ * copy shifts its front sheet, the star pops. A check draws itself when it appears (a copied or
28
+ * saved state). Icons without a motion stay still. Off by default: keep it for occasional
29
+ * actions, never for rows people pass a hundred times a day. Keyboard focus and reduced motion
30
+ * never animate it.
31
+ */
32
+ animate?: boolean;
22
33
  }
23
34
  /** An icon component, e.g. `ShieldCheckIcon`. Replaces Lucide's `LucideIcon` type. */
24
35
  type UixIcon = ForwardRefExoticComponent<IconProps & RefAttributes<SVGSVGElement>>;
package/dist/icons.cjs CHANGED
@@ -295,7 +295,7 @@ function cx(...args) {
295
295
 
296
296
  // src/icons/Icon.tsx
297
297
  var SIZES = /* @__PURE__ */ new Set(["sm", "md", "lg"]);
298
- function renderIcon(node, { size = "md", tone = "current", label, strokeWidth = 2, className, style, ...rest }, ref) {
298
+ function renderIcon(node, { size = "md", tone = "current", label, strokeWidth = 2, animate, className, style, ...rest }, ref, name) {
299
299
  const tokenSize = typeof size === "string" && SIZES.has(size);
300
300
  const length = typeof size === "number" ? `${size}px` : tokenSize ? void 0 : size;
301
301
  return (0, import_react.createElement)(
@@ -315,13 +315,17 @@ function renderIcon(node, { size = "md", tone = "current", label, strokeWidth =
315
315
  role: label ? "img" : void 0,
316
316
  "aria-label": label || void 0,
317
317
  "aria-hidden": label ? void 0 : true,
318
+ // the animated icons (2.60): icon.css keys each motion on the glyph's name
319
+ "data-icon": animate && name ? name : void 0,
320
+ "data-animate": animate ? "" : void 0,
318
321
  ...rest
319
322
  },
320
323
  node.map(([tag, attrs], i) => (0, import_react.createElement)(tag, { key: i, ...attrs }))
321
324
  );
322
325
  }
323
326
  function createIcon(displayName, node) {
324
- const Component = (0, import_react.forwardRef)((props, ref) => renderIcon(node, props, ref));
327
+ const name = displayName.replace(/Icon$/, "").replace(/([a-z0-9])([A-Z])|([a-zA-Z])(\d)/g, (_, a, b, c, d) => a ? `${a}-${b}` : `${c}-${d}`).toLowerCase();
328
+ const Component = (0, import_react.forwardRef)((props, ref) => renderIcon(node, props, ref, name));
325
329
  Component.displayName = displayName;
326
330
  return Component;
327
331
  }
@@ -806,7 +810,7 @@ var ICON_GLYPHS = {
806
810
 
807
811
  // src/icons/NamedIcon.tsx
808
812
  var Icon = (0, import_react2.forwardRef)(function Icon2({ name, ...props }, ref) {
809
- return renderIcon(ICON_GLYPHS[name], props, ref);
813
+ return renderIcon(ICON_GLYPHS[name], props, ref, name);
810
814
  });
811
815
 
812
816
  // src/icons/components.ts
package/dist/icons.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { I as IconNode, a as IconProps, U as UixIcon } from './types-B593xJNf.cjs';
3
- export { b as IconSize, c as IconTone } from './types-B593xJNf.cjs';
2
+ import { I as IconNode, a as IconProps, U as UixIcon } from './types-B7OIndwg.cjs';
3
+ export { b as IconSize, c as IconTone } from './types-B7OIndwg.cjs';
4
4
 
5
5
  /** Every glyph by its UIx name (the Lucide kebab-case name). Importing this pulls in the whole set. */
6
6
  declare const ICON_GLYPHS: {