bertui-icons 1.0.1 → 1.0.2

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.
@@ -3,61 +3,59 @@ import React from 'react';
3
3
  import svgTemplates from './svg-templates.json' with { type: 'json' };
4
4
  import searchIndex from './search-index.json' with { type: 'json' };
5
5
 
6
- // Fast SVG rendering with dynamic attributes - Returns React element
7
- function renderSVG(template, options = {}) {
8
- const {
9
- size = 24,
10
- color = 'currentColor',
11
- strokeWidth = 2,
12
- className = '',
13
- style = {},
14
- children,
15
- x,
16
- y,
17
- fontSize = 12,
18
- fontWeight = 600,
19
- textColor,
20
- ...rest
21
- } = options;
22
-
23
- // Replace default attributes
24
- let svg = template
25
- .replace('width="24"', `width="${size}"`)
26
- .replace('height="24"', `height="${size}"`)
27
- .replace('stroke="currentColor"', `stroke="${color}"`)
28
- .replace('stroke-width="2"', `stroke-width="${strokeWidth}"`);
29
-
30
- // Add className
31
- if (className) {
32
- svg = svg.replace('<svg', `<svg class="${className}"`);
33
- }
34
-
35
- // Add text overlay
36
- if (children !== undefined && children !== null) {
37
- const textX = x ?? size + 4;
38
- const textY = y ?? size / 2;
39
- const finalTextColor = textColor || color;
40
- const textEl = `<text x="${textX}" y="${textY}" font-size="${fontSize}" font-weight="${fontWeight}" fill="${finalTextColor}" text-anchor="start" dominant-baseline="middle">${children}</text>`;
41
- svg = svg.replace('</svg>', `${textEl}</svg>`);
42
- }
43
-
44
- // Return React element instead of HTML string
45
- return React.createElement('span', {
46
- dangerouslySetInnerHTML: { __html: svg },
47
- className,
48
- style: { display: 'inline-block', lineHeight: 0, ...style },
49
- ...rest
50
- });
51
- }
52
-
6
+ // Create icon component - Returns a proper React functional component
53
7
  function createIcon(iconName) {
54
8
  const IconComponent = React.forwardRef((props, ref) => {
9
+ const {
10
+ size = 24,
11
+ color = 'currentColor',
12
+ strokeWidth = 2,
13
+ className = '',
14
+ style = {},
15
+ children,
16
+ x,
17
+ y,
18
+ fontSize = 12,
19
+ fontWeight = 600,
20
+ textColor,
21
+ ...rest
22
+ } = props;
23
+
55
24
  const template = svgTemplates[iconName];
56
25
  if (!template) {
57
26
  console.error(`Icon "${iconName}" not found`);
58
27
  return null;
59
28
  }
60
- return renderSVG(template, { ...props, ref });
29
+
30
+ // Replace default attributes
31
+ let svg = template
32
+ .replace('width="24"', `width="${size}"`)
33
+ .replace('height="24"', `height="${size}"`)
34
+ .replace('stroke="currentColor"', `stroke="${color}"`)
35
+ .replace('stroke-width="2"', `stroke-width="${strokeWidth}"`);
36
+
37
+ // Add className
38
+ if (className) {
39
+ svg = svg.replace('<svg', `<svg class="${className}"`);
40
+ }
41
+
42
+ // Add text overlay
43
+ if (children !== undefined && children !== null) {
44
+ const textX = x ?? size + 4;
45
+ const textY = y ?? size / 2;
46
+ const finalTextColor = textColor || color;
47
+ const textEl = `<text x="${textX}" y="${textY}" font-size="${fontSize}" font-weight="${fontWeight}" fill="${finalTextColor}" text-anchor="start" dominant-baseline="middle">${children}</text>`;
48
+ svg = svg.replace('</svg>', `${textEl}</svg>`);
49
+ }
50
+
51
+ // Return React element
52
+ return React.createElement('span', {
53
+ ref,
54
+ dangerouslySetInnerHTML: { __html: svg },
55
+ className,
56
+ style: { display: 'inline-block', lineHeight: 0, ...style },
57
+ ...rest
58
+ });
61
59
  });
62
60
 
63
61
  IconComponent.displayName = iconName;
@@ -15,46 +15,13 @@ const lib = dlopen(libPath, {
15
15
  },
16
16
  });
17
17
 
18
- function renderIconFFI(iconName, options = {}) {
19
- const iconData = JSON.stringify({ name: iconName });
20
- const optionsData = JSON.stringify(options);
21
-
22
- const iconBuf = Buffer.from(iconData);
23
- const optionsBuf = Buffer.from(optionsData);
24
- const outputBuf = Buffer.alloc(8192);
25
- const outLen = new Uint32Array(1);
26
- outLen[0] = outputBuf.length;
27
-
28
- const result = lib.symbols.renderIcon(
29
- iconBuf,
30
- iconBuf.length,
31
- optionsBuf,
32
- optionsBuf.length,
33
- outputBuf,
34
- outLen
35
- );
36
-
37
- if (result !== 0) {
38
- throw new Error(`Icon render failed: ${result}`);
39
- }
40
-
41
- const svgString = outputBuf.toString('utf-8', 0, outLen[0]);
42
-
43
- // Return React element instead of HTML string
44
- return React.createElement('span', {
45
- dangerouslySetInnerHTML: { __html: svgString },
46
- className: options.className,
47
- style: { display: 'inline-block', lineHeight: 0, ...options.style }
48
- });
49
- }
50
-
51
18
  function createIcon(iconName) {
52
19
  const IconComponent = React.forwardRef((props, ref) => {
53
20
  const { children, x, y, fontSize = 12, className = '', style = {}, ...rest } = props;
21
+
22
+ const iconData = JSON.stringify({ name: iconName });
54
23
  const options = {
55
24
  ...rest,
56
- className,
57
- style,
58
25
  overlay: children ? {
59
26
  text: String(children),
60
27
  x: x ?? 28,
@@ -62,8 +29,36 @@ function createIcon(iconName) {
62
29
  fontSize,
63
30
  } : null,
64
31
  };
32
+ const optionsData = JSON.stringify(options);
33
+
34
+ const iconBuf = Buffer.from(iconData);
35
+ const optionsBuf = Buffer.from(optionsData);
36
+ const outputBuf = Buffer.alloc(8192);
37
+ const outLen = new Uint32Array(1);
38
+ outLen[0] = outputBuf.length;
39
+
40
+ const result = lib.symbols.renderIcon(
41
+ iconBuf,
42
+ iconBuf.length,
43
+ optionsBuf,
44
+ optionsBuf.length,
45
+ outputBuf,
46
+ outLen
47
+ );
65
48
 
66
- return renderIconFFI(iconName, options);
49
+ if (result !== 0) {
50
+ console.error(`Icon render failed: ${result}`);
51
+ return null;
52
+ }
53
+
54
+ const svgString = outputBuf.toString('utf-8', 0, outLen[0]);
55
+
56
+ return React.createElement('span', {
57
+ ref,
58
+ dangerouslySetInnerHTML: { __html: svgString },
59
+ className,
60
+ style: { display: 'inline-block', lineHeight: 0, ...style }
61
+ });
67
62
  });
68
63
 
69
64
  IconComponent.displayName = iconName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bertui-icons",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Blazing fast icon library powered by Zig + Bun FFI. Lucide-compatible with text overlays.",
5
5
  "type": "module",
6
6
  "main": "./generated/index.js",