initial-logo 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ Generate JavaScript/TypeScript style logos (2 characters inside a square) easily
13
13
  - 🌈 **Gradients**: Support for gradient backgrounds and text.
14
14
  - 🔤 **Custom Fonts**: Easily load fonts from Google Fonts or other sources.
15
15
  - ⚡ **Lightweight**: Zero dependencies for the core logic.
16
- - 🖼️ **Multiple Formats**: Generate HTML Divs, SVG strings, or SVG Elements.
16
+ - 🖼️ **Multiple Formats**: Generate HTML Divs, SVG strings, SVG Elements, or data URLs.
17
17
 
18
18
  ## Installation
19
19
 
@@ -26,7 +26,12 @@ npm install initial-logo
26
26
  ## Usage
27
27
 
28
28
  ```typescript
29
- import { generateLogo, generateSvg, generateSvgElement } from 'initial-logo';
29
+ import {
30
+ generateLogo,
31
+ generateRawSvg,
32
+ generateSvgDataUrl,
33
+ generateSvgElement,
34
+ } from 'initial-logo';
30
35
 
31
36
  // Generate HTML Div Element
32
37
  const logo = generateLogo({
@@ -38,12 +43,19 @@ const logo = generateLogo({
38
43
  document.body.appendChild(logo);
39
44
 
40
45
  // Generate SVG String
41
- const svgString = generateSvg({
46
+ const svgString = generateRawSvg({
42
47
  text: 'JS',
43
48
  textColor: '#000000',
44
49
  backgroundColor: '#f7df1e',
45
50
  });
46
51
 
52
+ // Generate SVG Data URL string (usable in img/src, CSS, etc.)
53
+ const dataUrl = generateSvgDataUrl({
54
+ text: 'DN',
55
+ textColor: '#ffffff',
56
+ backgroundColor: '#000000',
57
+ });
58
+
47
59
  // Generate SVG Element
48
60
  const svgElement = generateSvgElement({
49
61
  text: 'JS',
@@ -63,16 +75,56 @@ const gradientLogo = generateLogo({
63
75
  });
64
76
  ```
65
77
 
78
+ ## CLI Usage
79
+
80
+ You can also use the CLI to generate logos directly from the terminal.
81
+
82
+ ```bash
83
+ # Generate a logo and save to file
84
+ npx initial-logo -t TS -o logo.svg
85
+
86
+ # Customize colors and size
87
+ npx initial-logo -t JS -s 200 --textColor "#000000" --backgroundColor "#f7df1e" -o js-logo.svg
88
+
89
+ # Gradient example
90
+ npx initial-logo -t GR --textColor "#ff0000" --textColor "#0000ff" --backgroundColor "#222222" --backgroundColor "#444444" -o gradient.svg
91
+ ```
92
+
93
+ Note: If `--output` is not specified, the CLI writes the generated SVG to `initial-logo.svg` in the current directory.
94
+
95
+ ```bash
96
+ # Generate using default output filename
97
+ npx initial-logo -t TS
98
+ # This will create ./initial-logo.svg
99
+ ```
100
+
101
+ ### Options
102
+
103
+ | Option | Alias | Description | Default |
104
+ |---|---|---|---|
105
+ | `--text` | `-t` | Logo text (required) | - |
106
+ | `--size` | `-s` | Logo size in pixels | `100` |
107
+ | `--output` | `-o` | Output file path | `initial-logo.svg` |
108
+ | `--textColor` | `-T` | Text color (repeat for gradient) | `#ffffff` |
109
+ | `--backgroundColor` | `-B` | Background color (repeat for gradient) | `#000000` |
110
+ | `--fontSource` | `-f` | Font source URL | - |
111
+ | `--fontSize` | `-F` | Font size | - |
112
+ | `--help` | `-h` | Display help message | - |
113
+
66
114
  ## API
67
115
 
68
116
  ### `generateLogo(options: LogoOptions): HTMLDivElement`
69
117
 
70
118
  Generates a logo as an HTML `div` element.
71
119
 
72
- ### `generateSvg(options: LogoOptions): string`
120
+ ### `generateRawSvg(options: LogoOptions): string`
73
121
 
74
122
  Generates a logo as an SVG string.
75
123
 
124
+ ### `generateSvgDataUrl(options: LogoOptions): string`
125
+
126
+ Generates a logo as a data URL string (`data:image/svg+xml;...`).
127
+
76
128
  ### `generateSvgElement(options: LogoOptions): SVGElement`
77
129
 
78
130
  Generates a logo as an SVG DOM element.
@@ -81,12 +133,13 @@ Generates a logo as an SVG DOM element.
81
133
 
82
134
  | Property | Type | Default | Description |
83
135
  |---|---|---|---|
84
- | `text` | `string` | (Required) | The 2 characters to display. |
136
+ | `text` | `string` | (Required) | Exactly 2 characters to display. |
85
137
  | `size` | `number` | `100` | Size of the square in pixels. |
86
138
  | `textColor` | `string \| string[]` | `'#ffffff'` | Text color. Pass an array for gradient. |
87
139
  | `backgroundColor` | `string \| string[]` | `'#000000'` | Background color. Pass an array for gradient. |
88
140
  | `fontSource` | `string` | (Embedded JetBrains Mono) | URL to load the font from (WOFF2 format recommended). |
89
- | `fontSize` | `number` | `Math.round(size * 0.65)` | Font size in pixels. |
141
+ | `fontFamily` | `string` | (Auto-generated) | Font family name to use. |
142
+ | `fontSize` | `number` | `Math.round(size * 0.65)` for HTML, `Math.round(size * 0.525)` for SVG | Font size in pixels. |
90
143
  | `fontWeight` | `string \| number` | `'800'` | CSS font-weight. |
91
144
  | `lineHeight` | `string \| number` | `0.8` | CSS line-height. |
92
145
 
@@ -17,6 +17,9 @@ function validateOptions(options) {
17
17
  }
18
18
 
19
19
  // src/svg.ts
20
+ function escapeXml(str) {
21
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
22
+ }
20
23
  function getSvgNode(options) {
21
24
  validateOptions(options);
22
25
  const id = Math.random().toString(16).substring(2, 10);
@@ -114,12 +117,12 @@ function getSvgNode(options) {
114
117
  children: [defs, bgRect, textNode]
115
118
  };
116
119
  }
117
- function buildSVG(svg) {
120
+ function buildRawSVG(svg) {
118
121
  const { tag, attrs, children } = svg;
119
- const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ") : "";
122
+ const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${escapeXml(String(value))}"`).join(" ") : "";
120
123
  const openingTag = attrString ? `<${tag} ${attrString}>` : `<${tag}>`;
121
124
  const childrenString = children ? children.map(
122
- (child) => typeof child === "string" ? child : buildSVG(child)
125
+ (child) => typeof child === "string" ? escapeXml(child) : buildRawSVG(child)
123
126
  ).join("") : "";
124
127
  const closingTag = `</${tag}>`;
125
128
  return `${openingTag}${childrenString}${closingTag}`;
@@ -204,9 +207,15 @@ function generateLogo(options) {
204
207
  containerElement.appendChild(textElement);
205
208
  return containerElement;
206
209
  }
207
- function generateSvg(options) {
210
+ function generateRawSvg(options) {
208
211
  const svg = getSvgNode(options);
209
- return buildSVG(svg);
212
+ return buildRawSVG(svg);
213
+ }
214
+ function generateSvgDataUrl(options) {
215
+ const svgNode = getSvgNode(options);
216
+ const rawSvg = buildRawSVG(svgNode);
217
+ const encodedSvg = encodeURIComponent(rawSvg).replace(/'/g, "%27").replace(/"/g, "%22").replace(/\(/g, "%28").replace(/\)/g, "%29");
218
+ return `data:image/svg+xml;charset=UTF-8,${encodedSvg}`;
210
219
  }
211
220
  function generateSvgElement(options) {
212
221
  const svg = getSvgNode(options);
@@ -215,6 +224,7 @@ function generateSvgElement(options) {
215
224
 
216
225
  export {
217
226
  generateLogo,
218
- generateSvg,
227
+ generateRawSvg,
228
+ generateSvgDataUrl,
219
229
  generateSvgElement
220
230
  };
package/dist/cli.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
 
3
4
  // src/cli.ts
@@ -23,6 +24,9 @@ function validateOptions(options2) {
23
24
  }
24
25
 
25
26
  // src/svg.ts
27
+ function escapeXml(str) {
28
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
29
+ }
26
30
  function getSvgNode(options2) {
27
31
  validateOptions(options2);
28
32
  const id = Math.random().toString(16).substring(2, 10);
@@ -120,21 +124,21 @@ function getSvgNode(options2) {
120
124
  children: [defs, bgRect, textNode]
121
125
  };
122
126
  }
123
- function buildSVG(svg) {
127
+ function buildRawSVG(svg) {
124
128
  const { tag, attrs, children } = svg;
125
- const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ") : "";
129
+ const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${escapeXml(String(value))}"`).join(" ") : "";
126
130
  const openingTag = attrString ? `<${tag} ${attrString}>` : `<${tag}>`;
127
131
  const childrenString = children ? children.map(
128
- (child) => typeof child === "string" ? child : buildSVG(child)
132
+ (child) => typeof child === "string" ? escapeXml(child) : buildRawSVG(child)
129
133
  ).join("") : "";
130
134
  const closingTag = `</${tag}>`;
131
135
  return `${openingTag}${childrenString}${closingTag}`;
132
136
  }
133
137
 
134
138
  // src/core.ts
135
- function generateSvg(options2) {
139
+ function generateRawSvg(options2) {
136
140
  const svg = getSvgNode(options2);
137
- return buildSVG(svg);
141
+ return buildRawSVG(svg);
138
142
  }
139
143
 
140
144
  // src/cli.ts
@@ -155,17 +159,21 @@ var { values, positionals } = (0, import_node_util.parseArgs)({
155
159
  },
156
160
  textColor: {
157
161
  type: "string",
162
+ short: "T",
158
163
  multiple: true
159
164
  },
160
165
  backgroundColor: {
161
166
  type: "string",
167
+ short: "B",
162
168
  multiple: true
163
169
  },
164
170
  fontSource: {
165
- type: "string"
171
+ type: "string",
172
+ short: "f"
166
173
  },
167
174
  fontSize: {
168
- type: "string"
175
+ type: "string",
176
+ short: "F"
169
177
  },
170
178
  help: {
171
179
  type: "boolean",
@@ -180,12 +188,12 @@ Usage: initial-logo [options]
180
188
 
181
189
  Options:
182
190
  -t, --text <text> Logo text (required)
183
- -s, --size <number> Logo size (default: 512)
184
- -o, --output <path> Output file path (default: stdout)
185
- --textColor <color> Text color (can be specified multiple times for gradient)
186
- --backgroundColor <color> Background color (can be specified multiple times for gradient)
187
- --fontSource <url> Font source URL
188
- --fontSize <number> Font size
191
+ -s, --size <number> Logo size (default: 100)
192
+ -o, --output <path> Output file path (default: initial-logo.svg)
193
+ -T, --textColor <color> Text color (can be specified multiple times for gradient)
194
+ -B, --backgroundColor <color> Background color (can be specified multiple times for gradient)
195
+ -f, --fontSource <url> Font source URL
196
+ -F, --fontSize <number> Font size
189
197
  -h, --help Display this help message
190
198
  `);
191
199
  process.exit(0);
@@ -206,13 +214,10 @@ var options = {
206
214
  fontSize: values.fontSize ? Number.parseInt(values.fontSize, 10) : void 0
207
215
  };
208
216
  try {
209
- const svg = generateSvg(options);
210
- if (values.output) {
211
- (0, import_node_fs.writeFileSync)(values.output, svg);
212
- console.log(`Generated SVG saved to ${values.output}`);
213
- } else {
214
- console.log(svg);
215
- }
217
+ const rawSvg = generateRawSvg(options);
218
+ const outputPath = values.output ?? "initial-logo.svg";
219
+ (0, import_node_fs.writeFileSync)(outputPath, rawSvg);
220
+ console.log(`Generated SVG saved to ${outputPath}`);
216
221
  } catch (error) {
217
222
  console.error("Error generating SVG:", error);
218
223
  process.exit(1);
package/dist/cli.d.cts CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ #!/usr/bin/env node
package/dist/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ #!/usr/bin/env node
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
+ #!/usr/bin/env node
1
2
  import {
2
- generateSvg
3
- } from "./chunk-6FA2C7I6.js";
3
+ generateRawSvg
4
+ } from "./chunk-77RHYW77.js";
4
5
 
5
6
  // src/cli.ts
6
7
  import { writeFileSync } from "fs";
@@ -22,17 +23,21 @@ var { values, positionals } = parseArgs({
22
23
  },
23
24
  textColor: {
24
25
  type: "string",
26
+ short: "T",
25
27
  multiple: true
26
28
  },
27
29
  backgroundColor: {
28
30
  type: "string",
31
+ short: "B",
29
32
  multiple: true
30
33
  },
31
34
  fontSource: {
32
- type: "string"
35
+ type: "string",
36
+ short: "f"
33
37
  },
34
38
  fontSize: {
35
- type: "string"
39
+ type: "string",
40
+ short: "F"
36
41
  },
37
42
  help: {
38
43
  type: "boolean",
@@ -47,12 +52,12 @@ Usage: initial-logo [options]
47
52
 
48
53
  Options:
49
54
  -t, --text <text> Logo text (required)
50
- -s, --size <number> Logo size (default: 512)
51
- -o, --output <path> Output file path (default: stdout)
52
- --textColor <color> Text color (can be specified multiple times for gradient)
53
- --backgroundColor <color> Background color (can be specified multiple times for gradient)
54
- --fontSource <url> Font source URL
55
- --fontSize <number> Font size
55
+ -s, --size <number> Logo size (default: 100)
56
+ -o, --output <path> Output file path (default: initial-logo.svg)
57
+ -T, --textColor <color> Text color (can be specified multiple times for gradient)
58
+ -B, --backgroundColor <color> Background color (can be specified multiple times for gradient)
59
+ -f, --fontSource <url> Font source URL
60
+ -F, --fontSize <number> Font size
56
61
  -h, --help Display this help message
57
62
  `);
58
63
  process.exit(0);
@@ -73,13 +78,10 @@ var options = {
73
78
  fontSize: values.fontSize ? Number.parseInt(values.fontSize, 10) : void 0
74
79
  };
75
80
  try {
76
- const svg = generateSvg(options);
77
- if (values.output) {
78
- writeFileSync(values.output, svg);
79
- console.log(`Generated SVG saved to ${values.output}`);
80
- } else {
81
- console.log(svg);
82
- }
81
+ const rawSvg = generateRawSvg(options);
82
+ const outputPath = values.output ?? "initial-logo.svg";
83
+ writeFileSync(outputPath, rawSvg);
84
+ console.log(`Generated SVG saved to ${outputPath}`);
83
85
  } catch (error) {
84
86
  console.error("Error generating SVG:", error);
85
87
  process.exit(1);
package/dist/index.cjs CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  generateLogo: () => generateLogo,
24
- generateSvg: () => generateSvg,
24
+ generateRawSvg: () => generateRawSvg,
25
+ generateSvgDataUrl: () => generateSvgDataUrl,
25
26
  generateSvgElement: () => generateSvgElement
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
@@ -45,6 +46,9 @@ function validateOptions(options) {
45
46
  }
46
47
 
47
48
  // src/svg.ts
49
+ function escapeXml(str) {
50
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
51
+ }
48
52
  function getSvgNode(options) {
49
53
  validateOptions(options);
50
54
  const id = Math.random().toString(16).substring(2, 10);
@@ -142,12 +146,12 @@ function getSvgNode(options) {
142
146
  children: [defs, bgRect, textNode]
143
147
  };
144
148
  }
145
- function buildSVG(svg) {
149
+ function buildRawSVG(svg) {
146
150
  const { tag, attrs, children } = svg;
147
- const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ") : "";
151
+ const attrString = attrs ? Object.entries(attrs).map(([key, value]) => `${key}="${escapeXml(String(value))}"`).join(" ") : "";
148
152
  const openingTag = attrString ? `<${tag} ${attrString}>` : `<${tag}>`;
149
153
  const childrenString = children ? children.map(
150
- (child) => typeof child === "string" ? child : buildSVG(child)
154
+ (child) => typeof child === "string" ? escapeXml(child) : buildRawSVG(child)
151
155
  ).join("") : "";
152
156
  const closingTag = `</${tag}>`;
153
157
  return `${openingTag}${childrenString}${closingTag}`;
@@ -232,9 +236,15 @@ function generateLogo(options) {
232
236
  containerElement.appendChild(textElement);
233
237
  return containerElement;
234
238
  }
235
- function generateSvg(options) {
239
+ function generateRawSvg(options) {
236
240
  const svg = getSvgNode(options);
237
- return buildSVG(svg);
241
+ return buildRawSVG(svg);
242
+ }
243
+ function generateSvgDataUrl(options) {
244
+ const svgNode = getSvgNode(options);
245
+ const rawSvg = buildRawSVG(svgNode);
246
+ const encodedSvg = encodeURIComponent(rawSvg).replace(/'/g, "%27").replace(/"/g, "%22").replace(/\(/g, "%28").replace(/\)/g, "%29");
247
+ return `data:image/svg+xml;charset=UTF-8,${encodedSvg}`;
238
248
  }
239
249
  function generateSvgElement(options) {
240
250
  const svg = getSvgNode(options);
@@ -243,6 +253,7 @@ function generateSvgElement(options) {
243
253
  // Annotate the CommonJS export names for ESM import in node:
244
254
  0 && (module.exports = {
245
255
  generateLogo,
246
- generateSvg,
256
+ generateRawSvg,
257
+ generateSvgDataUrl,
247
258
  generateSvgElement
248
259
  });
package/dist/index.d.cts CHANGED
@@ -101,7 +101,8 @@ interface SVGNode<T extends SVGTagName = SVGTagName> {
101
101
  }
102
102
 
103
103
  declare function generateLogo(options: LogoOptions): HTMLDivElement;
104
- declare function generateSvg(options: LogoOptions): string;
104
+ declare function generateRawSvg(options: LogoOptions): string;
105
+ declare function generateSvgDataUrl(options: LogoOptions): string;
105
106
  declare function generateSvgElement(options: LogoOptions): SVGElement;
106
107
 
107
- export { type LogoOptions, type NumberProp, type SVGBaseAttrs, type SVGCoreAttrs, type SVGGradientBaseAttrs, type SVGLinearGradientAttrs, type SVGNode, type SVGPresentationAttrs, type SVGRadialGradientAttrs, type SVGRectAttrs, type SVGSVGAttrs, type SVGStopAttrs, type SVGTagMap, type SVGTagName, type SVGTextAttrs, generateLogo, generateSvg, generateSvgElement };
108
+ export { type LogoOptions, type NumberProp, type SVGBaseAttrs, type SVGCoreAttrs, type SVGGradientBaseAttrs, type SVGLinearGradientAttrs, type SVGNode, type SVGPresentationAttrs, type SVGRadialGradientAttrs, type SVGRectAttrs, type SVGSVGAttrs, type SVGStopAttrs, type SVGTagMap, type SVGTagName, type SVGTextAttrs, generateLogo, generateRawSvg, generateSvgDataUrl, generateSvgElement };
package/dist/index.d.ts CHANGED
@@ -101,7 +101,8 @@ interface SVGNode<T extends SVGTagName = SVGTagName> {
101
101
  }
102
102
 
103
103
  declare function generateLogo(options: LogoOptions): HTMLDivElement;
104
- declare function generateSvg(options: LogoOptions): string;
104
+ declare function generateRawSvg(options: LogoOptions): string;
105
+ declare function generateSvgDataUrl(options: LogoOptions): string;
105
106
  declare function generateSvgElement(options: LogoOptions): SVGElement;
106
107
 
107
- export { type LogoOptions, type NumberProp, type SVGBaseAttrs, type SVGCoreAttrs, type SVGGradientBaseAttrs, type SVGLinearGradientAttrs, type SVGNode, type SVGPresentationAttrs, type SVGRadialGradientAttrs, type SVGRectAttrs, type SVGSVGAttrs, type SVGStopAttrs, type SVGTagMap, type SVGTagName, type SVGTextAttrs, generateLogo, generateSvg, generateSvgElement };
108
+ export { type LogoOptions, type NumberProp, type SVGBaseAttrs, type SVGCoreAttrs, type SVGGradientBaseAttrs, type SVGLinearGradientAttrs, type SVGNode, type SVGPresentationAttrs, type SVGRadialGradientAttrs, type SVGRectAttrs, type SVGSVGAttrs, type SVGStopAttrs, type SVGTagMap, type SVGTagName, type SVGTextAttrs, generateLogo, generateRawSvg, generateSvgDataUrl, generateSvgElement };
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  generateLogo,
3
- generateSvg,
3
+ generateRawSvg,
4
+ generateSvgDataUrl,
4
5
  generateSvgElement
5
- } from "./chunk-6FA2C7I6.js";
6
+ } from "./chunk-77RHYW77.js";
6
7
  export {
7
8
  generateLogo,
8
- generateSvg,
9
+ generateRawSvg,
10
+ generateSvgDataUrl,
9
11
  generateSvgElement
10
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "initial-logo",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Generate JavaScript/TypeScript style logo",
5
5
  "keywords": [
6
6
  "logo",
@@ -47,7 +47,7 @@
47
47
  "format": "biome format --write",
48
48
  "lint": "biome lint --write",
49
49
  "check": "biome check --write",
50
- "prepublishOnly": "bun run build"
50
+ "prepare": "bun run build"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@biomejs/biome": "2.3.10",