@2hoch1/pixel-icon-library-react 1.1.1 → 1.1.3

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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 2hoch1
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 2hoch1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,9 +8,7 @@ Icons are pulled directly from `@hackernoon/pixel-icon-library` at build time. T
8
8
 
9
9
  ```bash
10
10
  npm install @2hoch1/pixel-icon-library-react react
11
- # or
12
11
  yarn add @2hoch1/pixel-icon-library-react react
13
- # or
14
12
  pnpm add @2hoch1/pixel-icon-library-react react
15
13
  ```
16
14
 
package/dist/index.cjs CHANGED
@@ -460,36 +460,39 @@ var dynamicIconImports = {
460
460
  "window-close-solid": () => loadIcon("@hackernoon/pixel-icon-library/icons/SVG/solid/window-close-solid.svg")
461
461
  };
462
462
  var dynamicIconImports_default = dynamicIconImports;
463
- var defaultSize = 24;
463
+
464
+ // src/utils/resolveIconName.ts
465
+ function resolveIconName(name, variant) {
466
+ const hasBrandsSuffix = name.endsWith("-brands");
467
+ const hasPurcatsSuffix = name.endsWith("-purcats");
468
+ const hasSolidSuffix = name.endsWith("-solid");
469
+ const baseName = name.replace(/-brands$/, "").replace(/-purcats$/, "").replace(/-solid$/, "");
470
+ let targetVariant;
471
+ if (variant) {
472
+ targetVariant = variant;
473
+ } else if (hasBrandsSuffix) {
474
+ targetVariant = "brands";
475
+ } else if (hasPurcatsSuffix) {
476
+ targetVariant = "purcats";
477
+ } else if (hasSolidSuffix) {
478
+ targetVariant = "solid";
479
+ } else {
480
+ targetVariant = "regular";
481
+ }
482
+ const candidate = targetVariant === "regular" ? baseName : `${baseName}-${targetVariant}`;
483
+ return dynamicIconImports_default[candidate] ? candidate : void 0;
484
+ }
485
+ var DEFAULT_SIZE = 24;
464
486
  function PixelIcon({
465
487
  name,
466
488
  variant,
467
- size = defaultSize,
489
+ size = DEFAULT_SIZE,
468
490
  title,
469
491
  fallback = null,
470
492
  ...rest
471
493
  }) {
472
494
  const [IconComponent, setIconComponent] = react.useState();
473
- const resolvedName = react.useMemo(() => {
474
- const hasBrandsSuffix = name.endsWith("-brands");
475
- const hasPurcatsSuffix = name.endsWith("-purcats");
476
- const hasSolidSuffix = name.endsWith("-solid");
477
- let baseName = name.replace(/-brands$/, "").replace(/-purcats$/, "").replace(/-solid$/, "");
478
- let targetVariant;
479
- if (variant) {
480
- targetVariant = variant;
481
- } else if (hasBrandsSuffix) {
482
- targetVariant = "brands";
483
- } else if (hasPurcatsSuffix) {
484
- targetVariant = "purcats";
485
- } else if (hasSolidSuffix) {
486
- targetVariant = "solid";
487
- } else {
488
- targetVariant = "regular";
489
- }
490
- const candidate = targetVariant === "regular" ? baseName : `${baseName}-${targetVariant}`;
491
- return dynamicIconImports_default[candidate] ? candidate : void 0;
492
- }, [name, variant]);
495
+ const resolvedName = react.useMemo(() => resolveIconName(name, variant), [name, variant]);
493
496
  react.useEffect(() => {
494
497
  let cancelled = false;
495
498
  if (!resolvedName) {
@@ -510,7 +513,7 @@ function PixelIcon({
510
513
  };
511
514
  }, [resolvedName]);
512
515
  if (!IconComponent) return fallback ?? null;
513
- const dimension = typeof size === "number" ? `${size}px` : size ?? `${defaultSize}px`;
516
+ const dimension = typeof size === "number" ? `${size}px` : size ?? `${DEFAULT_SIZE}px`;
514
517
  return /* @__PURE__ */ jsxRuntime.jsx(
515
518
  IconComponent,
516
519
  {
@@ -524,41 +527,38 @@ function PixelIcon({
524
527
  }
525
528
  );
526
529
  }
530
+ var lazyCache = /* @__PURE__ */ new Map();
531
+ var DEFAULT_SIZE2 = 24;
527
532
  var DynamicPixelIcon = ({
528
533
  name,
529
534
  variant,
530
- size = 24,
535
+ size = DEFAULT_SIZE2,
536
+ title,
531
537
  fallback = null,
532
538
  ...props
533
539
  }) => {
534
- const dimension = typeof size === "number" ? `${size}px` : size ?? "24px";
535
- const resolvedName = react.useMemo(() => {
536
- const hasBrandsSuffix = name.endsWith("-brands");
537
- const hasPurcatsSuffix = name.endsWith("-purcats");
538
- const hasSolidSuffix = name.endsWith("-solid");
539
- let baseName = name.replace(/-brands$/, "").replace(/-purcats$/, "").replace(/-solid$/, "");
540
- let targetVariant;
541
- if (variant) {
542
- targetVariant = variant;
543
- } else if (hasBrandsSuffix) {
544
- targetVariant = "brands";
545
- } else if (hasPurcatsSuffix) {
546
- targetVariant = "purcats";
547
- } else if (hasSolidSuffix) {
548
- targetVariant = "solid";
549
- } else {
550
- targetVariant = "regular";
551
- }
552
- const candidate = targetVariant === "regular" ? baseName : `${baseName}-${targetVariant}`;
553
- return dynamicIconImports_default[candidate] ? candidate : void 0;
554
- }, [name, variant]);
540
+ const dimension = typeof size === "number" ? `${size}px` : size ?? `${DEFAULT_SIZE2}px`;
541
+ const resolvedName = react.useMemo(() => resolveIconName(name, variant), [name, variant]);
555
542
  const LazyIcon = react.useMemo(() => {
556
543
  if (!resolvedName) return void 0;
557
- const importer = dynamicIconImports_default[resolvedName];
558
- return react.lazy(importer);
544
+ if (lazyCache.has(resolvedName)) return lazyCache.get(resolvedName);
545
+ const component = react.lazy(dynamicIconImports_default[resolvedName]);
546
+ lazyCache.set(resolvedName, component);
547
+ return component;
559
548
  }, [resolvedName]);
560
549
  if (!LazyIcon) return fallback ?? null;
561
- return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(LazyIcon, { ...props, width: dimension, height: dimension }) });
550
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(
551
+ LazyIcon,
552
+ {
553
+ ...props,
554
+ width: props.width ?? dimension,
555
+ height: props.height ?? dimension,
556
+ "aria-label": props["aria-label"] ?? title ?? name,
557
+ role: props.role ?? "img",
558
+ focusable: props.focusable ?? "false",
559
+ title
560
+ }
561
+ ) });
562
562
  };
563
563
  var SvgAndroid = (props) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { id: "Android", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: [
564
564
  /* @__PURE__ */ jsxRuntime.jsx("rect", { x: 5, y: 10, width: 1, height: 2 }),