initial-logo 0.0.0 β 0.1.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/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index.cjs +107 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +80 -0
- package/package.json +46 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 saitogo555
|
|
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
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# initial-logo.js
|
|
2
|
+
|
|
3
|
+
[πΊπΈ English](README.md) | [π―π΅ ζ₯ζ¬θͺ](docs/README.ja.md)
|
|
4
|
+
|
|
5
|
+
Generate JavaScript/TypeScript style logos (2 characters inside a square) easily.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- π¨ **Customizable**: Change colors, size, fonts, and more.
|
|
10
|
+
- π **Gradients**: Support for gradient backgrounds and text.
|
|
11
|
+
- π€ **Custom Fonts**: Easily load fonts from Google Fonts or other sources.
|
|
12
|
+
- β‘ **Lightweight**: Zero dependencies for the core logic.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun add initial-logo
|
|
18
|
+
# or
|
|
19
|
+
npm install initial-logo
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { generateLogo } from 'initial-logo';
|
|
26
|
+
|
|
27
|
+
const logo = generateLogo({
|
|
28
|
+
text: 'TS',
|
|
29
|
+
size: 100,
|
|
30
|
+
textColor: '#ffffff',
|
|
31
|
+
backgroundColor: '#3178c6',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
document.body.appendChild(logo);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Gradient Example
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const gradientLogo = generateLogo({
|
|
41
|
+
text: 'GR',
|
|
42
|
+
textColor: ['#ff0000', '#0000ff'], // Gradient text
|
|
43
|
+
backgroundColor: ['#222222', '#444444'], // Gradient background
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### `generateLogo(options: LogoOptions): HTMLDivElement`
|
|
50
|
+
|
|
51
|
+
Generates a logo element.
|
|
52
|
+
|
|
53
|
+
#### `LogoOptions`
|
|
54
|
+
|
|
55
|
+
| Property | Type | Default | Description |
|
|
56
|
+
|---|---|---|---|
|
|
57
|
+
| `text` | `string` | (Required) | The 2 characters to display. |
|
|
58
|
+
| `size` | `number` | `100` | Size of the square in pixels. |
|
|
59
|
+
| `textColor` | `string \| string[]` | `'#ffffff'` | Text color. Pass an array for gradient. |
|
|
60
|
+
| `backgroundColor` | `string \| string[]` | `'#000000'` | Background color. Pass an array for gradient. |
|
|
61
|
+
| `fontSource` | `string` | Google Fonts URL | URL to load the font from. |
|
|
62
|
+
| `fontFamily` | `string` | `'Inconsolata, monospace'` | CSS font-family. |
|
|
63
|
+
| `fontSize` | `number` | `Math.round(size * 0.65)` | Font size in pixels. |
|
|
64
|
+
| `fontWeight` | `string \| number` | `'bold'` | CSS font-weight. |
|
|
65
|
+
| `lineHeight` | `string \| number` | `0.8` | CSS line-height. |
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Install dependencies
|
|
71
|
+
bun install
|
|
72
|
+
|
|
73
|
+
# Start playground
|
|
74
|
+
bun run playground
|
|
75
|
+
|
|
76
|
+
# Build
|
|
77
|
+
bun run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Disclaimer
|
|
81
|
+
|
|
82
|
+
This tool is an unofficial project and is not affiliated with, endorsed by, or connected to Oracle, Microsoft, or the OpenJS Foundation. Users are solely responsible for the trademark and copyright compliance of any logos generated using this tool.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
generateLogo: () => generateLogo
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/core.ts
|
|
28
|
+
var DEFAULT_SIZE = 100;
|
|
29
|
+
var DEFAULT_TEXT_COLOR = "#ffffff";
|
|
30
|
+
var DEFAULT_FONT_SOURCE = "https://fonts.googleapis.com/css2?family=Inconsolata:wght@200..900&display=swap";
|
|
31
|
+
var DEFAULT_FONT_FAMILY = "Inconsolata, monospace";
|
|
32
|
+
var DEFAULT_FONT_WEIGHT = "bold";
|
|
33
|
+
var DEFAULT_LINE_HEIGHT = 0.8;
|
|
34
|
+
var DEFAULT_BG_COLOR = "#000000";
|
|
35
|
+
function validateOptions(options) {
|
|
36
|
+
if (options.text.length !== 2) {
|
|
37
|
+
throw new Error("Text must be exactly 2 characters.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getGradientStyle(colors) {
|
|
41
|
+
return `linear-gradient(90deg, ${colors.join(", ")})`;
|
|
42
|
+
}
|
|
43
|
+
function getContainerStyle(options) {
|
|
44
|
+
const size = options.size ?? DEFAULT_SIZE;
|
|
45
|
+
const backgroundColor = options.backgroundColor ?? DEFAULT_BG_COLOR;
|
|
46
|
+
const style = {
|
|
47
|
+
display: "flex",
|
|
48
|
+
alignItems: "flex-end",
|
|
49
|
+
justifyContent: "flex-end",
|
|
50
|
+
width: `${size}px`,
|
|
51
|
+
height: `${size}px`
|
|
52
|
+
};
|
|
53
|
+
if (Array.isArray(backgroundColor)) {
|
|
54
|
+
style.backgroundImage = getGradientStyle(backgroundColor);
|
|
55
|
+
} else {
|
|
56
|
+
style.backgroundColor = backgroundColor;
|
|
57
|
+
}
|
|
58
|
+
return style;
|
|
59
|
+
}
|
|
60
|
+
function loadFont(source) {
|
|
61
|
+
if (typeof document === "undefined") return;
|
|
62
|
+
const existingLink = document.querySelector(`link[href="${source}"]`);
|
|
63
|
+
if (existingLink) return;
|
|
64
|
+
const link = document.createElement("link");
|
|
65
|
+
link.href = source;
|
|
66
|
+
link.rel = "stylesheet";
|
|
67
|
+
document.head.appendChild(link);
|
|
68
|
+
}
|
|
69
|
+
function getTextStyle(options) {
|
|
70
|
+
const size = options.size ?? DEFAULT_SIZE;
|
|
71
|
+
const textColor = options.textColor ?? DEFAULT_TEXT_COLOR;
|
|
72
|
+
const fontFamily = options.fontFamily ?? DEFAULT_FONT_FAMILY;
|
|
73
|
+
const fontSize = options.fontSize ?? Math.round(size * 0.65);
|
|
74
|
+
const fontWeight = options.fontWeight ?? DEFAULT_FONT_WEIGHT;
|
|
75
|
+
const lineHeight = options.lineHeight ?? DEFAULT_LINE_HEIGHT;
|
|
76
|
+
const style = {
|
|
77
|
+
fontFamily,
|
|
78
|
+
fontSize: `${fontSize}px`,
|
|
79
|
+
fontWeight: fontWeight.toString(),
|
|
80
|
+
lineHeight: lineHeight.toString()
|
|
81
|
+
};
|
|
82
|
+
if (Array.isArray(textColor)) {
|
|
83
|
+
style.backgroundImage = getGradientStyle(textColor);
|
|
84
|
+
style.backgroundClip = "text";
|
|
85
|
+
style.color = "transparent";
|
|
86
|
+
} else {
|
|
87
|
+
style.color = textColor;
|
|
88
|
+
}
|
|
89
|
+
return style;
|
|
90
|
+
}
|
|
91
|
+
function generateLogo(options) {
|
|
92
|
+
validateOptions(options);
|
|
93
|
+
loadFont(options.fontSource ?? DEFAULT_FONT_SOURCE);
|
|
94
|
+
const containerElement = document.createElement("div");
|
|
95
|
+
const textElement = document.createElement("span");
|
|
96
|
+
const containerStyles = getContainerStyle(options);
|
|
97
|
+
const textStyles = getTextStyle(options);
|
|
98
|
+
Object.assign(containerElement.style, containerStyles);
|
|
99
|
+
Object.assign(textElement.style, textStyles);
|
|
100
|
+
textElement.textContent = options.text;
|
|
101
|
+
containerElement.appendChild(textElement);
|
|
102
|
+
return containerElement;
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
generateLogo
|
|
107
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface LogoOptions {
|
|
2
|
+
size?: number;
|
|
3
|
+
text: string;
|
|
4
|
+
textColor?: string | string[];
|
|
5
|
+
fontSource?: string;
|
|
6
|
+
fontFamily?: string;
|
|
7
|
+
fontSize?: number;
|
|
8
|
+
fontWeight?: string | number;
|
|
9
|
+
lineHeight?: string | number;
|
|
10
|
+
backgroundColor?: string | string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function generateLogo(options: LogoOptions): HTMLDivElement;
|
|
14
|
+
|
|
15
|
+
export { type LogoOptions, generateLogo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface LogoOptions {
|
|
2
|
+
size?: number;
|
|
3
|
+
text: string;
|
|
4
|
+
textColor?: string | string[];
|
|
5
|
+
fontSource?: string;
|
|
6
|
+
fontFamily?: string;
|
|
7
|
+
fontSize?: number;
|
|
8
|
+
fontWeight?: string | number;
|
|
9
|
+
lineHeight?: string | number;
|
|
10
|
+
backgroundColor?: string | string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function generateLogo(options: LogoOptions): HTMLDivElement;
|
|
14
|
+
|
|
15
|
+
export { type LogoOptions, generateLogo };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
var DEFAULT_SIZE = 100;
|
|
3
|
+
var DEFAULT_TEXT_COLOR = "#ffffff";
|
|
4
|
+
var DEFAULT_FONT_SOURCE = "https://fonts.googleapis.com/css2?family=Inconsolata:wght@200..900&display=swap";
|
|
5
|
+
var DEFAULT_FONT_FAMILY = "Inconsolata, monospace";
|
|
6
|
+
var DEFAULT_FONT_WEIGHT = "bold";
|
|
7
|
+
var DEFAULT_LINE_HEIGHT = 0.8;
|
|
8
|
+
var DEFAULT_BG_COLOR = "#000000";
|
|
9
|
+
function validateOptions(options) {
|
|
10
|
+
if (options.text.length !== 2) {
|
|
11
|
+
throw new Error("Text must be exactly 2 characters.");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getGradientStyle(colors) {
|
|
15
|
+
return `linear-gradient(90deg, ${colors.join(", ")})`;
|
|
16
|
+
}
|
|
17
|
+
function getContainerStyle(options) {
|
|
18
|
+
const size = options.size ?? DEFAULT_SIZE;
|
|
19
|
+
const backgroundColor = options.backgroundColor ?? DEFAULT_BG_COLOR;
|
|
20
|
+
const style = {
|
|
21
|
+
display: "flex",
|
|
22
|
+
alignItems: "flex-end",
|
|
23
|
+
justifyContent: "flex-end",
|
|
24
|
+
width: `${size}px`,
|
|
25
|
+
height: `${size}px`
|
|
26
|
+
};
|
|
27
|
+
if (Array.isArray(backgroundColor)) {
|
|
28
|
+
style.backgroundImage = getGradientStyle(backgroundColor);
|
|
29
|
+
} else {
|
|
30
|
+
style.backgroundColor = backgroundColor;
|
|
31
|
+
}
|
|
32
|
+
return style;
|
|
33
|
+
}
|
|
34
|
+
function loadFont(source) {
|
|
35
|
+
if (typeof document === "undefined") return;
|
|
36
|
+
const existingLink = document.querySelector(`link[href="${source}"]`);
|
|
37
|
+
if (existingLink) return;
|
|
38
|
+
const link = document.createElement("link");
|
|
39
|
+
link.href = source;
|
|
40
|
+
link.rel = "stylesheet";
|
|
41
|
+
document.head.appendChild(link);
|
|
42
|
+
}
|
|
43
|
+
function getTextStyle(options) {
|
|
44
|
+
const size = options.size ?? DEFAULT_SIZE;
|
|
45
|
+
const textColor = options.textColor ?? DEFAULT_TEXT_COLOR;
|
|
46
|
+
const fontFamily = options.fontFamily ?? DEFAULT_FONT_FAMILY;
|
|
47
|
+
const fontSize = options.fontSize ?? Math.round(size * 0.65);
|
|
48
|
+
const fontWeight = options.fontWeight ?? DEFAULT_FONT_WEIGHT;
|
|
49
|
+
const lineHeight = options.lineHeight ?? DEFAULT_LINE_HEIGHT;
|
|
50
|
+
const style = {
|
|
51
|
+
fontFamily,
|
|
52
|
+
fontSize: `${fontSize}px`,
|
|
53
|
+
fontWeight: fontWeight.toString(),
|
|
54
|
+
lineHeight: lineHeight.toString()
|
|
55
|
+
};
|
|
56
|
+
if (Array.isArray(textColor)) {
|
|
57
|
+
style.backgroundImage = getGradientStyle(textColor);
|
|
58
|
+
style.backgroundClip = "text";
|
|
59
|
+
style.color = "transparent";
|
|
60
|
+
} else {
|
|
61
|
+
style.color = textColor;
|
|
62
|
+
}
|
|
63
|
+
return style;
|
|
64
|
+
}
|
|
65
|
+
function generateLogo(options) {
|
|
66
|
+
validateOptions(options);
|
|
67
|
+
loadFont(options.fontSource ?? DEFAULT_FONT_SOURCE);
|
|
68
|
+
const containerElement = document.createElement("div");
|
|
69
|
+
const textElement = document.createElement("span");
|
|
70
|
+
const containerStyles = getContainerStyle(options);
|
|
71
|
+
const textStyles = getTextStyle(options);
|
|
72
|
+
Object.assign(containerElement.style, containerStyles);
|
|
73
|
+
Object.assign(textElement.style, textStyles);
|
|
74
|
+
textElement.textContent = options.text;
|
|
75
|
+
containerElement.appendChild(textElement);
|
|
76
|
+
return containerElement;
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
generateLogo
|
|
80
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "initial-logo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate JavaScript/TypeScript style logo",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"logo",
|
|
7
|
+
"generator",
|
|
8
|
+
"typescript",
|
|
9
|
+
"javascript",
|
|
10
|
+
"initials",
|
|
11
|
+
"browser"
|
|
12
|
+
],
|
|
13
|
+
"author": "saitogo555",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/saitogo555/initial-logo.js.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/saitogo555/initial-logo.js/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/saitogo555/initial-logo.js#readme",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
5
40
|
"scripts": {
|
|
6
|
-
"
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"dev": "tsup --watch",
|
|
43
|
+
"playground": "vite playground",
|
|
44
|
+
"prepublishOnly": "bun run build"
|
|
7
45
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"tsup": "^8.5.1",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"vite": "^7.3.0"
|
|
50
|
+
}
|
|
11
51
|
}
|