@cloud-ru/ds-ai-shimmer 1.0.1 → 1.1.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.
@@ -1,11 +1,9 @@
1
- @charset "UTF-8";
2
- @property --ai-shimmer-x{
1
+ @property --ai-shimmer-progress{
3
2
  inherits:true;
4
- initial-value:-124px;
5
- syntax:"<length>";
3
+ initial-value:-0.75;
4
+ syntax:"<number>";
6
5
  }
7
6
  .root{
8
- position:relative;
9
7
  display:block;
10
8
  box-sizing:border-box;
11
9
  width:100%;
@@ -14,12 +12,21 @@
14
12
  }
15
13
 
16
14
  .text{
15
+ animation:ai-shimmer-wave 5s linear infinite;
16
+ background-image:var(--ai-shimmer-wave-gradient), linear-gradient(var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))), var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))));
17
+ background-repeat:no-repeat;
18
+ background-position:calc(var(--ai-shimmer-progress) * var(--ai-shimmer-wave-width, 800px)) 0, 0 0;
19
+ background-origin:border-box;
20
+ background-size:var(--ai-shimmer-wave-width, 800px) 100%, 100% 100%;
17
21
  display:block;
18
22
  width:100%;
19
23
  min-width:0;
20
24
  max-width:100%;
25
+ color:transparent;
21
26
  overflow-wrap:anywhere;
22
27
  white-space:pre-line;
28
+ -webkit-background-clip:text;
29
+ background-clip:text;
23
30
  }
24
31
 
25
32
  .root[data-weight=regular][data-variant=display][data-size=s] .text{
@@ -385,76 +392,127 @@
385
392
  paragraph-spacing:var(--sn-mono-body-l-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize16, 8px));
386
393
  }
387
394
 
388
- .textGhost{
389
- color:transparent;
395
+ .lead{
396
+ animation:ai-shimmer-wave 5s linear infinite;
397
+ background-image:var(--ai-shimmer-wave-gradient), linear-gradient(var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))), var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))));
398
+ background-repeat:no-repeat;
399
+ background-position:calc(var(--ai-shimmer-progress) * var(--ai-shimmer-wave-width, 800px)) 0, 0 0;
400
+ background-origin:border-box;
401
+ background-size:var(--ai-shimmer-wave-width, 800px) 100%, 100% 100%;
402
+ display:block;
403
+ flex-shrink:0;
404
+ width:var(--ai-shimmer-icon-size, var(--sn-primitive-dimension-16, 16px));
405
+ height:var(--ai-shimmer-icon-size, var(--sn-primitive-dimension-16, 16px));
406
+ margin-right:var(--sn-primitive-dimension-4, 4px);
407
+ -webkit-mask-repeat:no-repeat;
408
+ mask-repeat:no-repeat;
409
+ -webkit-mask-position:center;
410
+ mask-position:center;
411
+ -webkit-mask-size:var(--ai-shimmer-icon-size) var(--ai-shimmer-icon-size);
412
+ mask-size:var(--ai-shimmer-icon-size) var(--ai-shimmer-icon-size);
390
413
  }
391
414
 
392
- .shimmer{
393
- pointer-events:none;
394
- position:absolute;
395
- inset:0;
415
+ .leadIcon{
416
+ display:block;
417
+ flex-shrink:0;
418
+ width:var(--ai-shimmer-icon-size, var(--sn-primitive-dimension-16, 16px));
419
+ height:var(--ai-shimmer-icon-size, var(--sn-primitive-dimension-16, 16px));
420
+ margin-right:var(--sn-primitive-dimension-4, 4px);
421
+ animation:ai-shimmer-wave 5s linear infinite;
396
422
  overflow:hidden;
423
+ color:var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8)));
424
+ }
425
+
426
+ .leadMask{
427
+ mask-type:alpha;
428
+ }
429
+
430
+ .leadBase{
431
+ fill:var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8)));
397
432
  }
398
433
 
399
- .shimmerText{
400
- background-image:radial-gradient(ellipse at 66% 22%, rgb(51, 140, 235) 15%, rgb(59, 174, 209) 30%, rgb(67, 208, 183) 45%, rgb(52, 203, 151) 55%, rgb(36, 198, 118) 65%, rgba(36, 198, 118, 0) 100%), linear-gradient(var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))), var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))));
434
+ .leadWave{
435
+ transform:translateX(calc(var(--ai-shimmer-progress) * var(--ai-shimmer-wave-width, 800px)));
436
+ width:var(--ai-shimmer-wave-width, 800px);
437
+ }
438
+
439
+ .slot{
440
+ animation:ai-shimmer-wave 5s linear infinite;
441
+ background-image:var(--ai-shimmer-wave-gradient), linear-gradient(var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))), var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))));
401
442
  background-repeat:no-repeat;
402
- background-position:-124px 0, 0 0;
443
+ background-position:calc(var(--ai-shimmer-progress) * var(--ai-shimmer-wave-width, 800px)) 0, 0 0;
403
444
  background-origin:border-box;
404
- background-size:108px var(--ai-shimmer-spread-start-height), 100% 100%;
405
- animation:shimmer-text-move 3.75s linear infinite;
445
+ background-size:var(--ai-shimmer-wave-width, 800px) 100%, 100% 100%;
446
+ flex-shrink:0;
406
447
  color:transparent;
448
+ background-position:calc(calc(var(--ai-shimmer-progress) * var(--ai-shimmer-wave-width, 800px)) - var(--ai-shimmer-slot-offset, 0px)) 0, 0 0;
407
449
  -webkit-background-clip:text;
408
450
  background-clip:text;
409
451
  }
410
- .lead{
411
- display:inline-block;
412
- width:var(--ai-shimmer-icon-size, 16px);
413
- height:var(--ai-shimmer-icon-size, 16px);
414
- margin-right:var(--sn-primitive-dimension-4, 4px);
415
- vertical-align:middle;
416
- }
417
452
 
418
- .shimmerIcon{
419
- background-image:radial-gradient(ellipse at 66% 22%, rgb(51, 140, 235) 15%, rgb(59, 174, 209) 30%, rgb(67, 208, 183) 45%, rgb(52, 203, 151) 55%, rgb(36, 198, 118) 65%, rgba(36, 198, 118, 0) 100%), linear-gradient(var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))), var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))));
420
- background-repeat:no-repeat;
421
- background-position:-124px 0, 0 0;
422
- background-origin:border-box;
423
- background-size:108px var(--ai-shimmer-spread-start-height), 100% 100%;
424
- animation:shimmer-text-move 3.75s linear infinite;
425
- -webkit-mask-repeat:no-repeat;
426
- mask-repeat:no-repeat;
427
- -webkit-mask-position:center;
428
- mask-position:center;
429
- -webkit-mask-size:var(--ai-shimmer-icon-size) var(--ai-shimmer-icon-size);
430
- mask-size:var(--ai-shimmer-icon-size) var(--ai-shimmer-icon-size);
453
+ .root[data-has-icon],
454
+ .root[data-has-slot]{
455
+ display:flex;
456
+ align-items:center;
457
+ width:-moz-fit-content;
458
+ width:fit-content;
459
+ max-width:100%;
431
460
  }
432
- .root[data-has-icon] .shimmerText,
433
- .root[data-has-icon] .shimmerIcon{
434
- background-position:var(--ai-shimmer-x) 0, 0 0;
435
- background-size:108px var(--ai-shimmer-spread-start-height), 100% 100%;
436
- animation-name:shimmer-line-move;
461
+ .root[data-has-icon] .text,
462
+ .root[data-has-slot] .text{
463
+ display:flex;
464
+ align-items:center;
465
+ width:auto;
466
+ max-width:100%;
467
+ overflow-wrap:normal;
468
+ white-space:nowrap;
437
469
  }
438
470
 
439
- @keyframes shimmer-text-move{
471
+ @keyframes ai-shimmer-wave{
440
472
  0%{
441
- background-position:-124px 0, 0 0;
442
- background-size:108px var(--ai-shimmer-spread-start-height), 100% 100%;
473
+ --ai-shimmer-progress:-0.75;
474
+ }
475
+ 60%, 100%{
476
+ --ai-shimmer-progress:0.25;
477
+ }
478
+ }
479
+ @media (prefers-reduced-motion: reduce){
480
+ .text,
481
+ .lead,
482
+ .leadIcon,
483
+ .slot{
484
+ animation:none;
443
485
  }
444
- 50%{
445
- background-position:calc(100% + 124px) 0, 0 0;
446
- background-size:108px var(--ai-shimmer-spread-end-height), 100% 100%;
486
+ .text,
487
+ .lead{
488
+ background-image:linear-gradient(var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))), var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(65, 66, 78, 0.8))));
447
489
  }
448
- 100%{
449
- background-position:calc(100% + 124px) 0, 0 0;
450
- background-size:108px var(--ai-shimmer-spread-end-height), 100% 100%;
490
+ .slot{
491
+ background-image:linear-gradient(var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))), var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078))));
492
+ }
493
+ .leadWave{
494
+ display:none;
451
495
  }
452
496
  }
453
- @keyframes shimmer-line-move{
454
- 0%{
455
- --ai-shimmer-x:-124px;
497
+ @media (forced-colors: active){
498
+ .text,
499
+ .slot{
500
+ color:CanvasText;
501
+ background-image:none;
502
+ animation:none;
503
+ }
504
+ .lead{
505
+ background-color:CanvasText;
506
+ background-image:none;
507
+ animation:none;
508
+ }
509
+ .leadIcon{
510
+ animation:none;
511
+ }
512
+ .leadBase{
513
+ fill:CanvasText;
456
514
  }
457
- 50%, 100%{
458
- --ai-shimmer-x:calc(var(--ai-shimmer-line-width, 400px) + 124px);
515
+ .leadWave{
516
+ display:none;
459
517
  }
460
518
  }
@@ -1,12 +1,8 @@
1
1
  import { WithSupportProps } from '@cloud-ru/ds-utils';
2
+ import { ReactNode } from 'react';
2
3
  export type AiShimmerVariant = 'display' | 'headline' | 'title' | 'label' | 'body';
3
4
  export type AiShimmerSize = 's' | 'm' | 'l';
4
5
  export type AiShimmerWeight = 'regular' | 'thin' | 'mono';
5
- export type AiShimmerFontMetrics = {
6
- fontSize: number;
7
- lineHeight: number;
8
- fontWeight: string;
9
- };
10
6
  export type AiShimmerProps = WithSupportProps<{
11
7
  /** Текст, по которому рендерится shimmer. Поддерживает переносы строк через `\n`. */
12
8
  text: string;
@@ -19,16 +15,25 @@ export type AiShimmerProps = WithSupportProps<{
19
15
  size?: AiShimmerSize;
20
16
  /** Начертание шрифта, как в `@cloud-ru/ds-typography`. Задаёт `data-weight`. */
21
17
  weight?: AiShimmerWeight;
18
+ /**
19
+ * Ведущая иконка узлом — любой компонент, рендерящий `<svg>`: иконка из `@cloud-ru/ds-icons`,
20
+ * `AiIconGiga`, `Sun` из `@cloud-ru/ds-loader`. Узел становится маской и заливается той же волной,
21
+ * что текст; его собственные цвета не важны, анимация внутри иконки сохраняется. Размер
22
+ * узла должен совпадать с `iconSize`. Имеет приоритет над `iconMask`.
23
+ */
24
+ icon?: ReactNode;
22
25
  /**
23
26
  * Силуэт ведущей иконки как CSS `mask-image` (обычно `url("data:image/svg+xml,…")`).
24
- * Если задан — перед текстом рисуется иконка, залитая тем же бегущим градиентом,
25
- * что и текст: блеск проходит сплошной полосой «иконка → конец строки», как будто
26
- * иконка — часть текста. Иконка не несёт собственного цвета, она наследует
27
- * shimmer-покрытие (приглушённая база + блик).
27
+ * Заливается той же волной, что текст. Используется, когда `icon` не передан.
28
28
  */
29
29
  iconMask?: string;
30
- /** Размер ведущей иконки в px (квадрат). Действует только с `iconMask`. По умолчанию `16`. */
30
+ /** Размер ведущей иконки в px (квадрат). Действует с `icon` или `iconMask`. По умолчанию `16`. */
31
31
  iconSize?: number;
32
+ /**
33
+ * Хвостовой слот справа от текста — например счётчик или длительность. Волна идёт
34
+ * по нему той же полосой; база слота на тон светлее текста. Свой цвет слоту не задавать.
35
+ */
36
+ slotAfter?: ReactNode;
32
37
  /** Дополнительный класс корневого контейнера. */
33
38
  className?: string;
34
39
  }>;
@@ -1,2 +1,2 @@
1
1
  import { AiShimmerProps } from './types.js';
2
- export declare function AiShimmer({ text, variant, size, weight, iconMask, iconSize, className, 'data-test-id': dataTestId, ...rest }: AiShimmerProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function AiShimmer({ text, variant, size, weight, icon, iconMask, iconSize, slotAfter, className, 'data-test-id': dataTestId, ...rest }: AiShimmerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,51 +1,49 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { extractSupportProps, useLayoutEffect } from '@cloud-ru/ds-utils';
2
+ import { extractSupportProps } from '@cloud-ru/ds-utils';
3
3
  import cn from 'classnames';
4
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import { DEFAULT_ICON_SIZE, DEFAULT_ROOT_WIDTH, DEFAULT_SIZE, DEFAULT_VARIANT, DEFAULT_WEIGHT, END_HEIGHT_EXTRA, fontMetricsForTypography, TEST_IDS, } from './constants.js';
4
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
5
+ import { DEFAULT_ICON_SIZE, DEFAULT_ROOT_WIDTH, DEFAULT_SIZE, DEFAULT_VARIANT, DEFAULT_WEIGHT, TEST_IDS, WAVE_GRADIENT, WAVE_STOPS, waveStopColor, } from './constants.js';
6
6
  import styles from './styles.module.css';
7
- export function AiShimmer({ text, variant = DEFAULT_VARIANT, size = DEFAULT_SIZE, weight = DEFAULT_WEIGHT, iconMask, iconSize = DEFAULT_ICON_SIZE, className, 'data-test-id': dataTestId = TEST_IDS.root, ...rest }) {
7
+ export function AiShimmer({ text, variant = DEFAULT_VARIANT, size = DEFAULT_SIZE, weight = DEFAULT_WEIGHT, icon, iconMask, iconSize = DEFAULT_ICON_SIZE, slotAfter, className, 'data-test-id': dataTestId = TEST_IDS.root, ...rest }) {
8
8
  const rootRef = useRef(null);
9
9
  const textRef = useRef(null);
10
- const fallbackHeight = fontMetricsForTypography(variant, size, weight).lineHeight;
11
- const [contentHeight, setContentHeight] = useState(fallbackHeight);
10
+ const slotRef = useRef(null);
12
11
  const [lineWidth, setLineWidth] = useState(DEFAULT_ROOT_WIDTH);
13
- const hasIcon = Boolean(iconMask);
12
+ const [slotOffset, setSlotOffset] = useState(0);
13
+ const gradientId = useId();
14
+ const maskId = useId();
15
+ const hasIconNode = icon != null && icon !== false;
16
+ const hasIcon = hasIconNode || Boolean(iconMask);
17
+ const hasSlotAfter = slotAfter != null && slotAfter !== false;
18
+ // Волна задана в пикселях строки, поэтому ширину и отступ слота нужно замерить.
14
19
  const measureLayout = useCallback(() => {
15
- const textNode = textRef.current;
16
- if (textNode) {
17
- const measuredContentHeight = Math.ceil(textNode.getBoundingClientRect().height);
18
- setContentHeight(prev => (Math.abs(prev - measuredContentHeight) > 0.5 ? measuredContentHeight : prev));
19
- }
20
20
  const rootNode = rootRef.current;
21
- if (rootNode) {
22
- const measuredWidth = Math.ceil(rootNode.getBoundingClientRect().width);
23
- setLineWidth(prev => (measuredWidth > 0 && Math.abs(prev - measuredWidth) > 0.5 ? measuredWidth : prev));
21
+ if (!rootNode) {
22
+ return;
23
+ }
24
+ const rootRect = rootNode.getBoundingClientRect();
25
+ const measuredWidth = Math.ceil(rootRect.width);
26
+ setLineWidth(prev => (measuredWidth > 0 && Math.abs(prev - measuredWidth) > 0.5 ? measuredWidth : prev));
27
+ const slotNode = slotRef.current;
28
+ if (slotNode) {
29
+ const measuredOffset = slotNode.getBoundingClientRect().left - rootRect.left;
30
+ setSlotOffset(prev => (Math.abs(prev - measuredOffset) > 0.5 ? measuredOffset : prev));
24
31
  }
25
32
  }, []);
26
- useLayoutEffect(() => {
27
- setContentHeight(fallbackHeight);
28
- measureLayout();
29
- const frameId = requestAnimationFrame(() => {
30
- measureLayout();
31
- });
32
- return () => cancelAnimationFrame(frameId);
33
- }, [fallbackHeight, measureLayout, size, text, variant, weight]);
34
33
  useEffect(() => {
35
- const textNode = textRef.current;
36
- const parentNode = textRef.current?.parentElement ?? null;
37
- if (typeof ResizeObserver === 'undefined') {
34
+ measureLayout();
35
+ const rootNode = rootRef.current;
36
+ if (typeof ResizeObserver === 'undefined' || !rootNode) {
38
37
  return undefined;
39
38
  }
40
39
  const observer = new ResizeObserver(() => measureLayout());
41
- if (textNode) {
42
- observer.observe(textNode);
43
- }
44
- if (parentNode) {
45
- observer.observe(parentNode);
40
+ observer.observe(rootNode);
41
+ const slotNode = slotRef.current;
42
+ if (slotNode) {
43
+ observer.observe(slotNode);
46
44
  }
47
45
  return () => observer.disconnect();
48
- }, [measureLayout]);
46
+ }, [measureLayout, hasSlotAfter]);
49
47
  useEffect(() => {
50
48
  if (typeof document === 'undefined' || !document.fonts?.ready) {
51
49
  return undefined;
@@ -62,15 +60,18 @@ export function AiShimmer({ text, variant = DEFAULT_VARIANT, size = DEFAULT_SIZE
62
60
  cancelled = true;
63
61
  };
64
62
  }, [measureLayout, size, text, variant, weight]);
65
- const spreadStartHeight = Math.max(contentHeight, fallbackHeight);
66
- const spreadEndHeight = spreadStartHeight + END_HEIGHT_EXTRA;
67
63
  const rootStyle = useMemo(() => ({
68
- '--ai-shimmer-spread-start-height': `${spreadStartHeight}px`,
69
- '--ai-shimmer-spread-end-height': `${spreadEndHeight}px`,
70
- ...(hasIcon && {
71
- '--ai-shimmer-icon-size': `${iconSize}px`,
72
- '--ai-shimmer-line-width': `${lineWidth}px`,
73
- }),
74
- }), [hasIcon, iconSize, lineWidth, spreadEndHeight, spreadStartHeight]);
75
- return (_jsxs("div", { ref: rootRef, className: cn(styles.root, className), style: rootStyle, "data-variant": variant, "data-size": size, "data-weight": weight, "data-has-icon": hasIcon || undefined, "data-test-id": dataTestId, ...extractSupportProps(rest), children: [_jsxs("span", { ref: textRef, className: cn(styles.text, styles.textGhost), "data-test-id": TEST_IDS.text, children: [hasIcon && _jsx("span", { className: styles.lead, "aria-hidden": true }), text] }), _jsx("span", { className: styles.shimmer, "data-test-id": TEST_IDS.shimmer, "aria-hidden": true, children: _jsxs("span", { className: cn(styles.text, styles.shimmerText), "data-test-id": TEST_IDS.spread, children: [hasIcon && (_jsx("span", { className: cn(styles.lead, styles.shimmerIcon), style: { maskImage: iconMask, WebkitMaskImage: iconMask }, "data-test-id": TEST_IDS.icon })), text] }) })] }));
64
+ '--ai-shimmer-wave-gradient': WAVE_GRADIENT,
65
+ '--ai-shimmer-wave-width': `${2 * lineWidth}px`,
66
+ ...(hasIcon && { '--ai-shimmer-icon-size': `${iconSize}px` }),
67
+ ...(hasSlotAfter && { '--ai-shimmer-slot-offset': `${slotOffset}px` }),
68
+ }), [hasIcon, hasSlotAfter, iconSize, lineWidth, slotOffset]);
69
+ let lead = null;
70
+ if (hasIconNode) {
71
+ lead = (_jsxs("svg", { className: styles.leadIcon, "data-test-id": TEST_IDS.icon, "aria-hidden": true, children: [_jsxs("defs", { children: [_jsx("linearGradient", { id: gradientId, x1: '0', y1: '0', x2: '1', y2: '0', children: WAVE_STOPS.map(stop => (_jsx("stop", { offset: stop.offset, stopColor: waveStopColor(stop), stopOpacity: stop.opacity }, stop.offset))) }), _jsx("mask", { id: maskId, className: styles.leadMask, maskUnits: 'userSpaceOnUse', x: '0', y: '0', width: '100%', height: '100%', children: icon })] }), _jsxs("g", { mask: `url(#${maskId})`, children: [_jsx("rect", { className: styles.leadBase, width: '100%', height: '100%' }), _jsx("rect", { className: styles.leadWave, height: '100%', fill: `url(#${gradientId})` })] })] }));
72
+ }
73
+ else if (iconMask) {
74
+ lead = (_jsx("span", { className: styles.lead, style: { maskImage: iconMask, WebkitMaskImage: iconMask }, "data-test-id": TEST_IDS.icon, "aria-hidden": true }));
75
+ }
76
+ return (_jsxs("div", { ref: rootRef, className: cn(styles.root, className), style: rootStyle, "data-variant": variant, "data-size": size, "data-weight": weight, "data-has-icon": hasIcon || undefined, "data-has-slot": hasSlotAfter || undefined, "data-test-id": dataTestId, ...extractSupportProps(rest), children: [_jsxs("span", { ref: textRef, className: styles.text, "data-test-id": TEST_IDS.text, children: [lead, text] }), hasSlotAfter && (_jsx("span", { ref: slotRef, className: styles.slot, "data-test-id": TEST_IDS.slot, children: slotAfter }))] }));
76
77
  }
@@ -1,10 +1,9 @@
1
- import { AiShimmerFontMetrics, AiShimmerSize, AiShimmerVariant, AiShimmerWeight } from './types.js';
1
+ import { AiShimmerSize, AiShimmerVariant, AiShimmerWeight } from './types.js';
2
2
  export declare const TEST_IDS: {
3
3
  readonly root: "ai-shimmer";
4
4
  readonly text: "ai-shimmer__text";
5
- readonly shimmer: "ai-shimmer__shimmer";
6
- readonly spread: "ai-shimmer__spread";
7
5
  readonly icon: "ai-shimmer__icon";
6
+ readonly slot: "ai-shimmer__slot";
8
7
  };
9
8
  /** Варианты типографики. */
10
9
  export declare const VARIANT: Record<AiShimmerVariant, AiShimmerVariant>;
@@ -20,28 +19,50 @@ export declare const DEFAULT_SIZE: AiShimmerSize;
20
19
  export declare const DEFAULT_WEIGHT: AiShimmerWeight;
21
20
  /** Размер ведущей иконки по умолчанию (px), когда задан `iconMask`. */
22
21
  export declare const DEFAULT_ICON_SIZE = 16;
23
- /** Fallback-метрики body regular для расчёта высоты до замера DOM. */
24
- export declare const TYPOGRAPHY_FONT_METRICS: Partial<Record<string, AiShimmerFontMetrics>>;
25
- export declare function fontMetricsForTypography(variant?: AiShimmerVariant, size?: AiShimmerSize, weight?: AiShimmerWeight): AiShimmerFontMetrics;
22
+ /** Ширина строки до первого замера DOM (SSR и первый рендер). */
23
+ export declare const DEFAULT_ROOT_WIDTH = 400;
26
24
  /**
27
- * Геометрия SVG-маски shimmer: ширина/смещение маски, типографские метрики строк
28
- * и ограничения по высоте контейнера и "хвоста" анимации.
25
+ * Стопы волны: единственный источник для CSS-градиента текста и SVG-градиента иконки.
26
+ * Цвета литералами — токенов под них в `@cloud-ru/ds-figma-variables` пока нет.
29
27
  */
30
- /** Ширина корня по умолчанию: используется до первого замера (SSR/первый рендер). */
31
- export declare const DEFAULT_ROOT_WIDTH = 400;
32
- /** Горизонтальное смещение маски относительно контейнера. */
33
- export declare const MASK_OFFSET_X = 0.6;
34
- /** Вертикальное смещение маски относительно контейнера. */
35
- export declare const MASK_OFFSET_Y = 3.892;
36
- /** Базовая линия первой текстовой строки в SVG. */
37
- export declare const BASELINE_FIRST_LINE = 9.24;
38
- /** Базовая высота маски для одной строки текста. */
39
- export declare const BASE_MASK_HEIGHT = 11.268;
40
- /** Дополнительная высота для конечной фазы spread-анимации. */
41
- export declare const END_HEIGHT_EXTRA = 40;
42
- /** Размер шрифта текста в SVG-маске. */
43
- export declare const MASK_TEXT_FONT_SIZE = 12;
44
- /** Межбуквенный интервал текста в SVG-маске. */
45
- export declare const MASK_TEXT_LETTER_SPACING = 0.1;
46
- /** Семейство шрифтов текста в SVG-маске. */
47
- export declare const MASK_TEXT_FONT_FAMILY = "'SB Sans Interface','Inter','Segoe UI',sans-serif";
28
+ export declare const WAVE_STOPS: readonly [{
29
+ readonly offset: 0;
30
+ readonly rgb: readonly [51, 140, 235];
31
+ readonly opacity: 0;
32
+ }, {
33
+ readonly offset: 0.3;
34
+ readonly rgb: readonly [51, 140, 235];
35
+ readonly opacity: 0;
36
+ }, {
37
+ readonly offset: 0.4;
38
+ readonly rgb: readonly [51, 140, 235];
39
+ readonly opacity: 1;
40
+ }, {
41
+ readonly offset: 0.48;
42
+ readonly rgb: readonly [59, 174, 209];
43
+ readonly opacity: 1;
44
+ }, {
45
+ readonly offset: 0.54;
46
+ readonly rgb: readonly [67, 208, 183];
47
+ readonly opacity: 1;
48
+ }, {
49
+ readonly offset: 0.6;
50
+ readonly rgb: readonly [52, 203, 151];
51
+ readonly opacity: 1;
52
+ }, {
53
+ readonly offset: 0.68;
54
+ readonly rgb: readonly [36, 198, 118];
55
+ readonly opacity: 1;
56
+ }, {
57
+ readonly offset: 0.78;
58
+ readonly rgb: readonly [36, 198, 118];
59
+ readonly opacity: 0;
60
+ }, {
61
+ readonly offset: 1;
62
+ readonly rgb: readonly [36, 198, 118];
63
+ readonly opacity: 0;
64
+ }];
65
+ /** Цвет стопа как CSS `rgb()`: без альфы для SVG `stop-color`, с альфой — для градиента. */
66
+ export declare function waveStopColor({ rgb: [r, g, b], opacity }: (typeof WAVE_STOPS)[number], withAlpha?: boolean): string;
67
+ /** Те же стопы как CSS `linear-gradient` — уходит в стили через `--ai-shimmer-wave-gradient`. */
68
+ export declare const WAVE_GRADIENT: string;
@@ -1,9 +1,8 @@
1
1
  export const TEST_IDS = {
2
2
  root: 'ai-shimmer',
3
3
  text: 'ai-shimmer__text',
4
- shimmer: 'ai-shimmer__shimmer',
5
- spread: 'ai-shimmer__spread',
6
4
  icon: 'ai-shimmer__icon',
5
+ slot: 'ai-shimmer__slot',
7
6
  };
8
7
  /** Варианты типографики. */
9
8
  export const VARIANT = {
@@ -33,40 +32,26 @@ export const DEFAULT_SIZE = SIZE.m;
33
32
  export const DEFAULT_WEIGHT = WEIGHT.regular;
34
33
  /** Размер ведущей иконки по умолчанию (px), когда задан `iconMask`. */
35
34
  export const DEFAULT_ICON_SIZE = 16;
36
- const DEFAULT_FONT_METRICS = {
37
- fontSize: 16,
38
- lineHeight: 24,
39
- fontWeight: '400',
40
- };
41
- /** Fallback-метрики body regular для расчёта высоты до замера DOM. */
42
- export const TYPOGRAPHY_FONT_METRICS = {
43
- 'regular-body-s': { fontSize: 14, lineHeight: 20, fontWeight: '400' },
44
- 'regular-body-m': DEFAULT_FONT_METRICS,
45
- 'regular-body-l': { fontSize: 20, lineHeight: 28, fontWeight: '400' },
46
- };
47
- export function fontMetricsForTypography(variant = DEFAULT_VARIANT, size = DEFAULT_SIZE, weight = DEFAULT_WEIGHT) {
48
- const key = `${weight}-${variant}-${size}`;
49
- return TYPOGRAPHY_FONT_METRICS[key] ?? DEFAULT_FONT_METRICS;
50
- }
35
+ /** Ширина строки до первого замера DOM (SSR и первый рендер). */
36
+ export const DEFAULT_ROOT_WIDTH = 400;
51
37
  /**
52
- * Геометрия SVG-маски shimmer: ширина/смещение маски, типографские метрики строк
53
- * и ограничения по высоте контейнера и "хвоста" анимации.
38
+ * Стопы волны: единственный источник для CSS-градиента текста и SVG-градиента иконки.
39
+ * Цвета литералами — токенов под них в `@cloud-ru/ds-figma-variables` пока нет.
54
40
  */
55
- /** Ширина корня по умолчанию: используется до первого замера (SSR/первый рендер). */
56
- export const DEFAULT_ROOT_WIDTH = 400;
57
- /** Горизонтальное смещение маски относительно контейнера. */
58
- export const MASK_OFFSET_X = 0.6;
59
- /** Вертикальное смещение маски относительно контейнера. */
60
- export const MASK_OFFSET_Y = 3.892;
61
- /** Базовая линия первой текстовой строки в SVG. */
62
- export const BASELINE_FIRST_LINE = 9.24;
63
- /** Базовая высота маски для одной строки текста. */
64
- export const BASE_MASK_HEIGHT = 11.268;
65
- /** Дополнительная высота для конечной фазы spread-анимации. */
66
- export const END_HEIGHT_EXTRA = 40;
67
- /** Размер шрифта текста в SVG-маске. */
68
- export const MASK_TEXT_FONT_SIZE = 12;
69
- /** Межбуквенный интервал текста в SVG-маске. */
70
- export const MASK_TEXT_LETTER_SPACING = 0.1;
71
- /** Семейство шрифтов текста в SVG-маске. */
72
- export const MASK_TEXT_FONT_FAMILY = "'SB Sans Interface','Inter','Segoe UI',sans-serif";
41
+ export const WAVE_STOPS = [
42
+ { offset: 0, rgb: [51, 140, 235], opacity: 0 },
43
+ { offset: 0.3, rgb: [51, 140, 235], opacity: 0 },
44
+ { offset: 0.4, rgb: [51, 140, 235], opacity: 1 },
45
+ { offset: 0.48, rgb: [59, 174, 209], opacity: 1 },
46
+ { offset: 0.54, rgb: [67, 208, 183], opacity: 1 },
47
+ { offset: 0.6, rgb: [52, 203, 151], opacity: 1 },
48
+ { offset: 0.68, rgb: [36, 198, 118], opacity: 1 },
49
+ { offset: 0.78, rgb: [36, 198, 118], opacity: 0 },
50
+ { offset: 1, rgb: [36, 198, 118], opacity: 0 },
51
+ ];
52
+ /** Цвет стопа как CSS `rgb()`: без альфы для SVG `stop-color`, с альфой — для градиента. */
53
+ export function waveStopColor({ rgb: [r, g, b], opacity }, withAlpha = false) {
54
+ return withAlpha ? `rgb(${r} ${g} ${b} / ${opacity * 100}%)` : `rgb(${r} ${g} ${b})`;
55
+ }
56
+ /** Те же стопы как CSS `linear-gradient` — уходит в стили через `--ai-shimmer-wave-gradient`. */
57
+ export const WAVE_GRADIENT = `linear-gradient(90deg, ${WAVE_STOPS.map(stop => `${waveStopColor(stop, true)} ${stop.offset * 100}%`).join(', ')})`;