@dubium/icons 0.0.2-alpha.0 → 0.0.2-alpha.1

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.
@@ -7,56 +7,56 @@ var s = /* @__PURE__ */ new Map(), c = n(({ name: n, size: c = 24, width: l, hei
7
7
  let { icons: h } = e(), g = i(() => ({
8
8
  ...t,
9
9
  ...h
10
- }), [h]), [_, v] = a(() => s.get(n) || null), [y, b] = a(!1), x = l ?? c, S = u ?? c, C = i(() => ({
10
+ }), [h]), _ = g[n], [v, y] = a(() => _ ? s.get(_) ?? null : null), [b, x] = a(!1), S = l ?? c, C = u ?? c, w = i(() => ({
11
11
  display: "inline-flex",
12
12
  alignItems: "center",
13
13
  justifyContent: "center",
14
- width: x,
15
- height: S,
14
+ width: S,
15
+ height: C,
16
16
  transform: `rotate(${f}deg)`
17
17
  }), [
18
- x,
19
18
  S,
19
+ C,
20
20
  f
21
21
  ]);
22
22
  return r(() => {
23
23
  let e = !1;
24
24
  return (async () => {
25
- let t = String(n), r = s.get(t);
26
- if (r) {
27
- v(() => r);
25
+ let t = String(n), r = g[n];
26
+ if (!r) {
27
+ console.warn(`Иконка "${t}" не найдена`), y(() => null);
28
28
  return;
29
29
  }
30
- let i = g[n];
31
- if (!i) {
32
- console.warn(`Иконка "${t}" не найдена`), v(() => null);
30
+ let i = s.get(r);
31
+ if (i) {
32
+ y(() => i);
33
33
  return;
34
34
  }
35
- b(!0), v(() => null), i().then((n) => {
35
+ x(!0), y(() => null), r().then((t) => {
36
36
  if (e) return;
37
- let r = n.default;
38
- s.set(t, r), v(() => r);
37
+ let n = t.default;
38
+ s.set(r, n), y(() => n);
39
39
  }).catch((n) => {
40
- e || (console.error(`Ошибка загрузки иконки "${t}":`, n), v(() => null));
40
+ e || (console.error(`Ошибка загрузки иконки "${t}":`, n), y(() => null));
41
41
  }).finally(() => {
42
- e || b(!1);
42
+ e || x(!1);
43
43
  });
44
44
  })(), () => {
45
45
  e = !0;
46
46
  };
47
- }, [n, g]), y || !_ ? /* @__PURE__ */ o("div", {
47
+ }, [n, g]), b || !v ? /* @__PURE__ */ o("div", {
48
48
  "aria-hidden": "true",
49
49
  role: "img",
50
50
  style: {
51
- ...C,
51
+ ...w,
52
52
  visibility: "hidden"
53
53
  }
54
54
  }) : /* @__PURE__ */ o("div", {
55
55
  "aria-label": m || n,
56
56
  onClick: p,
57
57
  role: "img",
58
- style: C,
59
- children: _ ? /* @__PURE__ */ o(_, { color: d }) : null
58
+ style: w,
59
+ children: v ? /* @__PURE__ */ o(v, { color: d }) : null
60
60
  });
61
61
  });
62
62
  c.displayName = "Icon";
@@ -1,4 +1,4 @@
1
1
  //#region src/icons/spa/icon/Icon.registry.ts
2
- var e = { Close: () => import("../../collection/UserIcon.js") };
2
+ var e = { User: () => import("../../collection/UserIcon.js") };
3
3
  //#endregion
4
4
  export { e as defaultIcons };
@@ -0,0 +1,23 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ //#region src/icons/ssr/icon/Icon.container.tsx
3
+ var t = ({ ariaLabel: t, children: n, deg: r = 0, height: i, size: a = 24, style: o, width: s }) => {
4
+ let c = {
5
+ display: "inline-flex",
6
+ alignItems: "center",
7
+ justifyContent: "center",
8
+ flex: "0 0 auto",
9
+ width: s ?? a,
10
+ height: i ?? a,
11
+ transform: `rotate(${r}deg)`,
12
+ ...o
13
+ };
14
+ return /* @__PURE__ */ e("span", {
15
+ "aria-hidden": !t || void 0,
16
+ "aria-label": t,
17
+ role: t ? "img" : void 0,
18
+ style: c,
19
+ children: n
20
+ });
21
+ };
22
+ //#endregion
23
+ export { t as IconContainer };
@@ -1,9 +1,8 @@
1
- import { Icon as e } from "./Icon.js";
2
- import { jsx as t } from "react/jsx-runtime";
1
+ import { renderIconWithRegistry as e } from "./Icon.js";
3
2
  //#region src/icons/ssr/icon/Icon.create.tsx
4
- var n = () => {
5
- let n = (n) => /* @__PURE__ */ t(e, { ...n });
3
+ var t = (t) => {
4
+ let n = (n) => e(n, t);
6
5
  return n.displayName = "SSRIcon", n;
7
- }, r = (e) => e;
6
+ }, n = (e) => e;
8
7
  //#endregion
9
- export { n as createIcon, r as defineIcons };
8
+ export { t as createIcon, n as defineIcons };
@@ -1,31 +1,26 @@
1
- import { useIconRegistry as e } from "../provider/useIconRegistry.js";
2
- import { jsx as t } from "react/jsx-runtime";
1
+ import { defaultIcons as e } from "./Icon.registry.js";
2
+ import { IconContainer as t } from "./Icon.container.js";
3
+ import { jsx as n } from "react/jsx-runtime";
3
4
  //#region src/icons/ssr/icon/Icon.tsx
4
- var n = ({ name: n, size: r = 24, width: i, height: a, color: o = "currentColor", deg: s = 0, onClick: c, ariaLabel: l, style: u }) => {
5
- let d = e()[String(n)];
6
- if (!d) return console.warn(`Иконка "${String(n)}" не найдена`), null;
7
- let f = {
8
- display: "inline-flex",
9
- alignItems: "center",
10
- justifyContent: "center",
11
- flex: "0 0 auto",
12
- width: i ?? r,
13
- height: a ?? r,
14
- transform: `rotate(${s}deg)`,
15
- ...u
16
- };
17
- return /* @__PURE__ */ t("span", {
18
- "aria-hidden": !l || void 0,
19
- "aria-label": l,
20
- onClick: c,
21
- role: l ? "img" : void 0,
22
- style: f,
23
- children: /* @__PURE__ */ t(d, {
5
+ var r = (e, t) => Object.prototype.hasOwnProperty.call(e, t), i = async (t) => {
6
+ if (!r(e, t)) return null;
7
+ let n = e[t];
8
+ return (await n()).default;
9
+ }, a = async (e, a) => {
10
+ let { name: o, size: s = 24, width: c, height: l, color: u = "currentColor", deg: d = 0, ariaLabel: f, style: p } = e, m = String(o), h = (a && r(a, m) ? a[m] : void 0) ?? await i(m);
11
+ return h ? /* @__PURE__ */ n(t, {
12
+ ariaLabel: f,
13
+ deg: d,
14
+ height: l,
15
+ size: s,
16
+ style: p,
17
+ width: c,
18
+ children: /* @__PURE__ */ n(h, {
24
19
  "aria-hidden": "true",
25
- color: o,
20
+ color: u,
26
21
  focusable: "false"
27
22
  })
28
- });
29
- };
23
+ }) : (console.warn(`Иконка "${m}" не найдена`), null);
24
+ }, o = (e) => a(e), s = a;
30
25
  //#endregion
31
- export { n as Icon };
26
+ export { o as Icon, s as renderIconWithRegistry };
@@ -0,0 +1,4 @@
1
+ //#region src/icons/ssr/icon/Icon.registry.ts
2
+ var e = { User: () => import("../../collection/UserIcon.js") };
3
+ //#endregion
4
+ export { e as defaultIcons };
package/dist/ssr/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import { useIconRegistry as e } from "./provider/useIconRegistry.js";
1
+ import { IconContainer as e } from "./icon/Icon.container.js";
2
2
  import { Icon as t } from "./icon/Icon.js";
3
3
  import { createIcon as n, defineIcons as r } from "./icon/Icon.create.js";
4
- import { IconProvider as i } from "./provider/IconProvider.js";
5
- export { t as Icon, i as IconProvider, n as createIcon, r as defineIcons, e as useIconRegistry };
4
+ export { t as Icon, e as IconContainer, n as createIcon, r as defineIcons };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dubium/icons",
3
- "version": "0.0.2-alpha.0",
3
+ "version": "0.0.2-alpha.1",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist"
@@ -1,7 +0,0 @@
1
- /**
2
- * React-контекст для хранения реестра иконок при серверном рендеринге (SSR).
3
- *
4
- * Значение по умолчанию — пустой реестр. Фактический реестр иконок
5
- * передаётся через `IconProvider`.
6
- */
7
- export declare const IconRegistryContext: import("react").Context<Readonly<Record<string, import("../index.js").TIcon>>>;
@@ -1,5 +0,0 @@
1
- import { createContext as e } from "react";
2
- //#region src/icons/ssr/provider/IconProvider.context.ts
3
- var t = e({});
4
- //#endregion
5
- export { t as IconRegistryContext };
@@ -1,33 +0,0 @@
1
- import type { TIconRegistry } from "../icon/Icon.types.js";
2
- import type { IIconProviderProps } from "./IconProvider.types.js";
3
- /**
4
- * Провайдер реестра иконок для серверного рендеринга (SSR).
5
- *
6
- * Передаёт реестр синхронных иконок вниз по дереву компонентов
7
- * через `IconRegistryContext`, объединяя его с родительским реестром.
8
- *
9
- * @typeParam TIcons - Тип реестра иконок
10
- *
11
- * @param props - Свойства провайдера
12
- * @param props.children - Дочерние React-элементы
13
- * @param props.icons - Реестр иконок (синхронные React-компоненты)
14
- *
15
- * @returns Провайдер контекста с доступом к иконкам
16
- *
17
- * @example
18
- * ```tsx
19
- * const appIcons = defineIcons({
20
- * User: UserIcon,
21
- * });
22
- *
23
- * <IconProvider icons={appIcons}>
24
- * <App />
25
- * </IconProvider>
26
- * ```
27
- *
28
- * @remarks
29
- * - Позволяет вкладывать провайдеры: дочерний реестр наследует родительский
30
- * - При совпадении имён иконки дочернего провайдера переопределяют родительские
31
- * - Использует `useMemo` для предотвращения лишних перерисовок
32
- */
33
- export declare const IconProvider: <TIcons extends TIconRegistry>({ children, icons }: IIconProviderProps<TIcons>) => import("react").JSX.Element;
@@ -1,16 +0,0 @@
1
- import { IconRegistryContext as e } from "./IconProvider.context.js";
2
- import { useContext as t, useMemo as n } from "react";
3
- import { jsx as r } from "react/jsx-runtime";
4
- //#region src/icons/ssr/provider/IconProvider.tsx
5
- var i = ({ children: i, icons: a }) => {
6
- let o = t(e), s = n(() => ({
7
- ...o,
8
- ...a
9
- }), [o, a]);
10
- return /* @__PURE__ */ r(e, {
11
- value: s,
12
- children: i
13
- });
14
- };
15
- //#endregion
16
- export { i as IconProvider };
@@ -1,13 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { TIconRegistry } from "../icon/Icon.types.js";
3
- /**
4
- * Свойства компонента `IconProvider` для серверного рендеринга (SSR).
5
- *
6
- * @template TIcons - Тип реестра иконок
7
- */
8
- export interface IIconProviderProps<TIcons extends TIconRegistry = TIconRegistry> {
9
- /** Дочерние React-элементы, которые получат доступ к реестру иконок */
10
- children: ReactNode;
11
- /** Реестр иконок (синхронные React-компоненты) */
12
- icons: TIcons;
13
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Публичный API модуля провайдера иконок для серверного рендеринга (SSR).
3
- *
4
- * Экспортирует `IconProvider`, хук `useIconRegistry` и связанные типы.
5
- */
6
- export { IconProvider } from "./IconProvider.js";
7
- export { useIconRegistry } from "./useIconRegistry.js";
8
- export type { IIconProviderProps } from "./IconProvider.types.js";
@@ -1,18 +0,0 @@
1
- import type { TIconRegistry } from "../icon/Icon.types.js";
2
- /**
3
- * Хук для доступа к реестру иконок при серверном рендеринге (SSR).
4
- *
5
- * Возвращает текущий реестр иконок из `IconRegistryContext`.
6
- *
7
- * @returns Реестр иконок, переданный через `IconProvider`
8
- *
9
- * @example
10
- * ```ts
11
- * const registry = useIconRegistry();
12
- * ```
13
- *
14
- * @remarks
15
- * - Без `IconProvider` вернёт пустой реестр `{}`
16
- * - Используется внутри компонента `Icon` для поиска иконки по имени
17
- */
18
- export declare const useIconRegistry: () => TIconRegistry;
@@ -1,6 +0,0 @@
1
- import { IconRegistryContext as e } from "./IconProvider.context.js";
2
- import { useContext as t } from "react";
3
- //#region src/icons/ssr/provider/useIconRegistry.ts
4
- var n = () => t(e);
5
- //#endregion
6
- export { n as useIconRegistry };