@shmidko61/lc-ui-kit 0.0.5 → 0.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.
@@ -8,5 +8,5 @@ import { PictureProps } from './picture.types';
8
8
  * внутреннего `img`, а остальные значения преобразуются в `source` с
9
9
  * min-width из общего responsive-конфига ui-kit.
10
10
  */
11
- export declare function Picture({ display, image, sources, ...props }: PictureProps): ReactNode;
12
- export type { PictureBreakpoint, PictureBreakpointSource, PictureBreakpointSources, PictureProps, } from './picture.types';
11
+ export declare function Picture({ display, fill, image, objectFit, objectPosition, sources, md, lg, xl, ...props }: PictureProps): ReactNode;
12
+ export type { PictureBreakpoint, PictureBreakpointProps, PictureBreakpointSource, PictureBreakpointSources, PictureImageLayoutProps, PictureObjectFit, PictureObjectPosition, PictureProps, } from './picture.types';
@@ -1,9 +1,27 @@
1
- import { SourceHTMLAttributes } from 'react';
2
- import { PictureBreakpoint, PictureBreakpointSource, PictureBreakpointSources } from './picture.types';
1
+ import { CSSProperties, SourceHTMLAttributes } from 'react';
2
+ import { BoxBreakpointProps } from '../box/box.types';
3
+ import { ResponsiveStyleBreakpoint } from '../shared/responsive-style/responsive-style.types';
4
+ import { PictureBreakpoint, PictureBreakpointProps, PictureBreakpointSource, PictureBreakpointSources, PictureImageLayoutProps } from './picture.types';
5
+ /** Результат преобразования image-layout props в responsive Tailwind-классы. */
6
+ export type PictureImageTailwindClassNamePlan = {
7
+ /** Классы, применяемые к внутреннему `img`. */
8
+ className: string;
9
+ /** CSS-переменные со значениями для base/md/lg/xl. */
10
+ style: CSSProperties;
11
+ };
12
+ type PictureImageStyleBuildProps = PictureImageLayoutProps & Partial<Record<ResponsiveStyleBreakpoint, PictureImageLayoutProps>>;
13
+ /**
14
+ * Преобразует публичные responsive props изображения в классы и CSS-переменные.
15
+ * Базовая высота `auto` сохраняет прежнее поведение `Picture`.
16
+ */
17
+ export declare function buildPictureImageTailwindClassNamePlan(props: PictureImageStyleBuildProps): PictureImageTailwindClassNamePlan;
18
+ /** Удаляет image-layout props перед передачей breakpoint-настроек в `Box`. */
19
+ export declare function getPictureBoxBreakpointProps({ fill: _fill, objectFit: _objectFit, objectPosition: _objectPosition, ...boxProps }: PictureBreakpointProps): BoxBreakpointProps;
3
20
  export type PictureResolvedBreakpointSource = {
4
21
  breakpoint: Exclude<PictureBreakpoint, 'sm'>;
5
22
  source: PictureBreakpointSource;
6
23
  };
7
- export declare function buildBreakpointSources(sources: PictureBreakpointSources): PictureResolvedBreakpointSource[];
24
+ export declare function buildBreakpointSources(sources: PictureBreakpointSources): Array<PictureResolvedBreakpointSource>;
8
25
  export declare function getSourceSrcSet(source: PictureBreakpointSource): string;
9
26
  export declare function getSourceProps(source: PictureBreakpointSource): SourceHTMLAttributes<HTMLSourceElement>;
27
+ export {};
@@ -1,5 +1,6 @@
1
- import { ImgHTMLAttributes, SourceHTMLAttributes } from 'react';
2
- import { BoxProps } from '../box/box.types';
1
+ import { CSSProperties, ImgHTMLAttributes, SourceHTMLAttributes } from 'react';
2
+ import { BoxBreakpointProps, BoxProps } from '../box/box.types';
3
+ import { ResponsiveStyleBreakpoint } from '../shared/responsive-style/responsive-style.types';
3
4
  /**
4
5
  * Поддерживаемые проектные брейкпоинты для компонента `Picture`.
5
6
  *
@@ -31,13 +32,34 @@ export type PictureBreakpointSource = string | (Omit<SourceHTMLAttributes<HTMLSo
31
32
  export type PictureBreakpointSources = {
32
33
  sm: PictureBreakpointSource;
33
34
  } & Partial<Record<Exclude<PictureBreakpoint, 'sm'>, PictureBreakpointSource>>;
35
+ /** Допустимое CSS-значение способа масштабирования внутреннего `img`. */
36
+ export type PictureObjectFit = NonNullable<CSSProperties['objectFit']>;
37
+ /** Допустимое CSS-положение внутреннего изображения относительно его области. */
38
+ export type PictureObjectPosition = NonNullable<CSSProperties['objectPosition']>;
39
+ /**
40
+ * Настройки отображения внутреннего `img`.
41
+ *
42
+ * `fill` растягивает изображение по высоте и ширине `picture`. Для заметного
43
+ * результата у внешнего `Picture` должна быть задана высота.
44
+ */
45
+ export type PictureImageLayoutProps = {
46
+ /** Растянуть внутренний `img` на всю ширину и высоту `picture`. */
47
+ fill?: boolean;
48
+ /** Способ масштабирования изображения внутри доступной области. */
49
+ objectFit?: PictureObjectFit;
50
+ /** Положение изображения внутри доступной области. */
51
+ objectPosition?: PictureObjectPosition;
52
+ };
53
+ /** Свойства `Picture`, которые можно переопределить на одном breakpoint. */
54
+ export type PictureBreakpointProps = BoxBreakpointProps & PictureImageLayoutProps;
55
+ type PictureResponsiveProps = Partial<Record<ResponsiveStyleBreakpoint, PictureBreakpointProps>>;
34
56
  /**
35
57
  * Свойства компонента `Picture`.
36
58
  *
37
59
  * Компонент наследует свойства `Box`, кроме `as` и `children`: тег всегда
38
60
  * фиксирован как `picture`, а содержимое формируется из `sources` и `image`.
39
61
  */
40
- export type PictureProps = Omit<BoxProps<'picture'>, 'as' | 'children'> & {
62
+ export type PictureProps = Omit<BoxProps<'picture'>, 'as' | 'children' | 'md' | 'lg' | 'xl' | keyof PictureImageLayoutProps> & PictureImageLayoutProps & PictureResponsiveProps & {
41
63
  /**
42
64
  * Атрибуты для внутреннего элемента `img`.
43
65
  *
@@ -54,3 +76,4 @@ export type PictureProps = Omit<BoxProps<'picture'>, 'as' | 'children'> & {
54
76
  */
55
77
  sources: PictureBreakpointSources;
56
78
  };
79
+ export {};
package/dist/picture.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),f=require("./box.cjs"),p=require("./responsive-style.config-B2m9jVlX.cjs");function S(e){return[...p.responsiveBreakpoints].reverse().flatMap(t=>{const i=e[t];return i?[{breakpoint:t,source:i}]:[]})}function o(e){return typeof e=="string"?e:e.srcSet}function y(e){if(typeof e!="string")return e;const t=e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase(),i={avif:"image/avif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",webp:"image/webp"};return t&&i[t]?{type:i[t]}:{}}function d({display:e="block",image:t,sources:i,...c}){const{alt:a="",style:g,...u}=t??{},l=o(i.sm),m=S(i);return n.jsxs(f.Box,{...c,as:"picture",display:e,children:[m.map(({breakpoint:r,source:s})=>n.jsx("source",{...y(s),media:`(min-width: ${p.responsiveBreakpointMinWidth[r]})`,srcSet:o(s)},r)),n.jsx("img",{alt:a,src:l,style:{display:"block",height:"auto",width:"100%",...g},...u})]})}exports.Picture=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),B=require("./box.cjs"),g=require("./responsive-style.config-B2m9jVlX.cjs");function d({fill:e,objectFit:t,objectPosition:i},o,s,{classPrefix:c,isBase:n=!1,variablePrefix:r}){const a={height:e===void 0?n?"auto":void 0:e?"100%":"auto",objectFit:t,objectPosition:i},m={height:"height",objectFit:"object-fit",objectPosition:"object-position"};for(const[f,p]of Object.entries(a)){if(p===void 0)continue;const l=m[f],u=`${r}picture-image-${l}`;s[`--${u}`]=String(p),o.push(`${c}[${l}:var(--${u})]`)}}function k(e){const t=[],i={};d(e,t,i,{classPrefix:"",isBase:!0,variablePrefix:""});for(const o of g.responsiveBreakpoints){const s=e[o];s&&d(s,t,i,{classPrefix:`${o}:`,variablePrefix:`${o}-`})}return{className:t.join(" "),style:i}}function P({fill:e,objectFit:t,objectPosition:i,...o}){return o}function N(e){return[...g.responsiveBreakpoints].reverse().flatMap(t=>{const i=e[t];return i?[{breakpoint:t,source:i}]:[]})}function S(e){return typeof e=="string"?e:e.srcSet}function $(e){if(typeof e!="string")return e;const t=e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase(),i={avif:"image/avif",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",webp:"image/webp"};return t&&i[t]?{type:i[t]}:{}}function w({display:e="block",fill:t,image:i,objectFit:o,objectPosition:s,sources:c,md:n,lg:r,xl:a,...m}){const{alt:f="",className:p,style:l,...u}=i??{},x=S(c.sm),h=N(c),j=k({fill:t,objectFit:o,objectPosition:s,md:n,lg:r,xl:a});return b.jsxs(B.Box,{...m,as:"picture",display:e,md:n?P(n):void 0,lg:r?P(r):void 0,xl:a?P(a):void 0,children:[h.map(({breakpoint:v,source:y})=>b.jsx("source",{...$(y),media:`(min-width: ${g.responsiveBreakpointMinWidth[v]})`,srcSet:S(y)},v)),b.jsx("img",{alt:f,className:g.cn(j.className,p),src:x,style:{display:"block",width:"100%",...j.style,...l},...u})]})}exports.Picture=w;
package/dist/picture.js CHANGED
@@ -1,16 +1,60 @@
1
- import { jsxs as f, jsx as o } from "react/jsx-runtime";
2
- import { Box as u } from "./box.js";
3
- import { a as S, r as y } from "./responsive-style.config-DFuATrIM.js";
4
- function d(e) {
5
- return [...S].reverse().flatMap((t) => {
1
+ import { jsxs as B, jsx as v } from "react/jsx-runtime";
2
+ import { Box as N } from "./box.js";
3
+ import { a as h, r as k, c as $ } from "./responsive-style.config-DFuATrIM.js";
4
+ function y({ fill: e, objectFit: t, objectPosition: i }, o, s, { classPrefix: c, isBase: n = !1, variablePrefix: a }) {
5
+ const r = {
6
+ height: e === void 0 ? n ? "auto" : void 0 : e ? "100%" : "auto",
7
+ objectFit: t,
8
+ objectPosition: i
9
+ }, f = {
10
+ height: "height",
11
+ objectFit: "object-fit",
12
+ objectPosition: "object-position"
13
+ };
14
+ for (const [u, p] of Object.entries(r)) {
15
+ if (p === void 0)
16
+ continue;
17
+ const l = f[u], m = `${a}picture-image-${l}`;
18
+ s[`--${m}`] = String(p), o.push(`${c}[${l}:var(--${m})]`);
19
+ }
20
+ }
21
+ function w(e) {
22
+ const t = [], i = {};
23
+ y(e, t, i, {
24
+ classPrefix: "",
25
+ isBase: !0,
26
+ variablePrefix: ""
27
+ });
28
+ for (const o of h) {
29
+ const s = e[o];
30
+ s && y(s, t, i, {
31
+ classPrefix: `${o}:`,
32
+ variablePrefix: `${o}-`
33
+ });
34
+ }
35
+ return {
36
+ className: t.join(" "),
37
+ style: i
38
+ };
39
+ }
40
+ function g({
41
+ fill: e,
42
+ objectFit: t,
43
+ objectPosition: i,
44
+ ...o
45
+ }) {
46
+ return o;
47
+ }
48
+ function C(e) {
49
+ return [...h].reverse().flatMap((t) => {
6
50
  const i = e[t];
7
51
  return i ? [{ breakpoint: t, source: i }] : [];
8
52
  });
9
53
  }
10
- function s(e) {
54
+ function d(e) {
11
55
  return typeof e == "string" ? e : e.srcSet;
12
56
  }
13
- function h(e) {
57
+ function F(e) {
14
58
  if (typeof e != "string")
15
59
  return e;
16
60
  const t = e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase(), i = {
@@ -22,34 +66,64 @@ function h(e) {
22
66
  };
23
67
  return t && i[t] ? { type: i[t] } : {};
24
68
  }
25
- function k({ display: e = "block", image: t, sources: i, ...p }) {
26
- const { alt: a = "", style: c, ...m } = t ?? {}, g = s(i.sm), l = d(i);
27
- return /* @__PURE__ */ f(u, { ...p, as: "picture", display: e, children: [
28
- l.map(({ breakpoint: r, source: n }) => /* @__PURE__ */ o(
29
- "source",
30
- {
31
- ...h(n),
32
- media: `(min-width: ${y[r]})`,
33
- srcSet: s(n)
34
- },
35
- r
36
- )),
37
- /* @__PURE__ */ o(
38
- "img",
39
- {
40
- alt: a,
41
- src: g,
42
- style: {
43
- display: "block",
44
- height: "auto",
45
- width: "100%",
46
- ...c
47
- },
48
- ...m
49
- }
50
- )
51
- ] });
69
+ function T({
70
+ display: e = "block",
71
+ fill: t,
72
+ image: i,
73
+ objectFit: o,
74
+ objectPosition: s,
75
+ sources: c,
76
+ md: n,
77
+ lg: a,
78
+ xl: r,
79
+ ...f
80
+ }) {
81
+ const { alt: u = "", className: p, style: l, ...m } = i ?? {}, S = d(c.sm), x = C(c), b = w({
82
+ fill: t,
83
+ objectFit: o,
84
+ objectPosition: s,
85
+ md: n,
86
+ lg: a,
87
+ xl: r
88
+ });
89
+ return /* @__PURE__ */ B(
90
+ N,
91
+ {
92
+ ...f,
93
+ as: "picture",
94
+ display: e,
95
+ md: n ? g(n) : void 0,
96
+ lg: a ? g(a) : void 0,
97
+ xl: r ? g(r) : void 0,
98
+ children: [
99
+ x.map(({ breakpoint: P, source: j }) => /* @__PURE__ */ v(
100
+ "source",
101
+ {
102
+ ...F(j),
103
+ media: `(min-width: ${k[P]})`,
104
+ srcSet: d(j)
105
+ },
106
+ P
107
+ )),
108
+ /* @__PURE__ */ v(
109
+ "img",
110
+ {
111
+ alt: u,
112
+ className: $(b.className, p),
113
+ src: S,
114
+ style: {
115
+ display: "block",
116
+ width: "100%",
117
+ ...b.style,
118
+ ...l
119
+ },
120
+ ...m
121
+ }
122
+ )
123
+ ]
124
+ }
125
+ );
52
126
  }
53
127
  export {
54
- k as Picture
128
+ T as Picture
55
129
  };