initial-logo 0.3.1 → 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',
@@ -78,17 +90,25 @@ npx initial-logo -t JS -s 200 --textColor "#000000" --backgroundColor "#f7df1e"
78
90
  npx initial-logo -t GR --textColor "#ff0000" --textColor "#0000ff" --backgroundColor "#222222" --backgroundColor "#444444" -o gradient.svg
79
91
  ```
80
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
+
81
101
  ### Options
82
102
 
83
103
  | Option | Alias | Description | Default |
84
104
  |---|---|---|---|
85
105
  | `--text` | `-t` | Logo text (required) | - |
86
- | `--size` | `-s` | Logo size in pixels | `512` |
87
- | `--output` | `-o` | Output file path | `stdout` |
88
- | `--textColor` | | Text color (repeat for gradient) | `#ffffff` |
89
- | `--backgroundColor` | | Background color (repeat for gradient) | `#000000` |
90
- | `--fontSource` | | Font source URL | - |
91
- | `--fontSize` | | Font size | - |
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 | - |
92
112
  | `--help` | `-h` | Display help message | - |
93
113
 
94
114
  ## API
@@ -97,10 +117,14 @@ npx initial-logo -t GR --textColor "#ff0000" --textColor "#0000ff" --backgroundC
97
117
 
98
118
  Generates a logo as an HTML `div` element.
99
119
 
100
- ### `generateSvg(options: LogoOptions): string`
120
+ ### `generateRawSvg(options: LogoOptions): string`
101
121
 
102
122
  Generates a logo as an SVG string.
103
123
 
124
+ ### `generateSvgDataUrl(options: LogoOptions): string`
125
+
126
+ Generates a logo as a data URL string (`data:image/svg+xml;...`).
127
+
104
128
  ### `generateSvgElement(options: LogoOptions): SVGElement`
105
129
 
106
130
  Generates a logo as an SVG DOM element.
@@ -109,12 +133,13 @@ Generates a logo as an SVG DOM element.
109
133
 
110
134
  | Property | Type | Default | Description |
111
135
  |---|---|---|---|
112
- | `text` | `string` | (Required) | The 2 characters to display. |
136
+ | `text` | `string` | (Required) | Exactly 2 characters to display. |
113
137
  | `size` | `number` | `100` | Size of the square in pixels. |
114
138
  | `textColor` | `string \| string[]` | `'#ffffff'` | Text color. Pass an array for gradient. |
115
139
  | `backgroundColor` | `string \| string[]` | `'#000000'` | Background color. Pass an array for gradient. |
116
140
  | `fontSource` | `string` | (Embedded JetBrains Mono) | URL to load the font from (WOFF2 format recommended). |
117
- | `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. |
118
143
  | `fontWeight` | `string \| number` | `'800'` | CSS font-weight. |
119
144
  | `lineHeight` | `string \| number` | `0.8` | CSS line-height. |
120
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
@@ -24,6 +24,9 @@ function validateOptions(options2) {
24
24
  }
25
25
 
26
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
+ }
27
30
  function getSvgNode(options2) {
28
31
  validateOptions(options2);
29
32
  const id = Math.random().toString(16).substring(2, 10);
@@ -121,21 +124,21 @@ function getSvgNode(options2) {
121
124
  children: [defs, bgRect, textNode]
122
125
  };
123
126
  }
124
- function buildSVG(svg) {
127
+ function buildRawSVG(svg) {
125
128
  const { tag, attrs, children } = svg;
126
- 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(" ") : "";
127
130
  const openingTag = attrString ? `<${tag} ${attrString}>` : `<${tag}>`;
128
131
  const childrenString = children ? children.map(
129
- (child) => typeof child === "string" ? child : buildSVG(child)
132
+ (child) => typeof child === "string" ? escapeXml(child) : buildRawSVG(child)
130
133
  ).join("") : "";
131
134
  const closingTag = `</${tag}>`;
132
135
  return `${openingTag}${childrenString}${closingTag}`;
133
136
  }
134
137
 
135
138
  // src/core.ts
136
- function generateSvg(options2) {
139
+ function generateRawSvg(options2) {
137
140
  const svg = getSvgNode(options2);
138
- return buildSVG(svg);
141
+ return buildRawSVG(svg);
139
142
  }
140
143
 
141
144
  // src/cli.ts
@@ -156,17 +159,21 @@ var { values, positionals } = (0, import_node_util.parseArgs)({
156
159
  },
157
160
  textColor: {
158
161
  type: "string",
162
+ short: "T",
159
163
  multiple: true
160
164
  },
161
165
  backgroundColor: {
162
166
  type: "string",
167
+ short: "B",
163
168
  multiple: true
164
169
  },
165
170
  fontSource: {
166
- type: "string"
171
+ type: "string",
172
+ short: "f"
167
173
  },
168
174
  fontSize: {
169
- type: "string"
175
+ type: "string",
176
+ short: "F"
170
177
  },
171
178
  help: {
172
179
  type: "boolean",
@@ -181,12 +188,12 @@ Usage: initial-logo [options]
181
188
 
182
189
  Options:
183
190
  -t, --text <text> Logo text (required)
184
- -s, --size <number> Logo size (default: 512)
185
- -o, --output <path> Output file path (default: stdout)
186
- --textColor <color> Text color (can be specified multiple times for gradient)
187
- --backgroundColor <color> Background color (can be specified multiple times for gradient)
188
- --fontSource <url> Font source URL
189
- --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
190
197
  -h, --help Display this help message
191
198
  `);
192
199
  process.exit(0);
@@ -207,13 +214,10 @@ var options = {
207
214
  fontSize: values.fontSize ? Number.parseInt(values.fontSize, 10) : void 0
208
215
  };
209
216
  try {
210
- const svg = generateSvg(options);
211
- if (values.output) {
212
- (0, import_node_fs.writeFileSync)(values.output, svg);
213
- console.log(`Generated SVG saved to ${values.output}`);
214
- } else {
215
- console.log(svg);
216
- }
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}`);
217
221
  } catch (error) {
218
222
  console.error("Error generating SVG:", error);
219
223
  process.exit(1);
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- generateSvg
4
- } from "./chunk-6FA2C7I6.js";
3
+ generateRawSvg
4
+ } from "./chunk-77RHYW77.js";
5
5
 
6
6
  // src/cli.ts
7
7
  import { writeFileSync } from "fs";
@@ -23,17 +23,21 @@ var { values, positionals } = parseArgs({
23
23
  },
24
24
  textColor: {
25
25
  type: "string",
26
+ short: "T",
26
27
  multiple: true
27
28
  },
28
29
  backgroundColor: {
29
30
  type: "string",
31
+ short: "B",
30
32
  multiple: true
31
33
  },
32
34
  fontSource: {
33
- type: "string"
35
+ type: "string",
36
+ short: "f"
34
37
  },
35
38
  fontSize: {
36
- type: "string"
39
+ type: "string",
40
+ short: "F"
37
41
  },
38
42
  help: {
39
43
  type: "boolean",
@@ -48,12 +52,12 @@ Usage: initial-logo [options]
48
52
 
49
53
  Options:
50
54
  -t, --text <text> Logo text (required)
51
- -s, --size <number> Logo size (default: 512)
52
- -o, --output <path> Output file path (default: stdout)
53
- --textColor <color> Text color (can be specified multiple times for gradient)
54
- --backgroundColor <color> Background color (can be specified multiple times for gradient)
55
- --fontSource <url> Font source URL
56
- --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
57
61
  -h, --help Display this help message
58
62
  `);
59
63
  process.exit(0);
@@ -74,13 +78,10 @@ var options = {
74
78
  fontSize: values.fontSize ? Number.parseInt(values.fontSize, 10) : void 0
75
79
  };
76
80
  try {
77
- const svg = generateSvg(options);
78
- if (values.output) {
79
- writeFileSync(values.output, svg);
80
- console.log(`Generated SVG saved to ${values.output}`);
81
- } else {
82
- console.log(svg);
83
- }
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}`);
84
85
  } catch (error) {
85
86
  console.error("Error generating SVG:", error);
86
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.1",
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",