Init
Browse files- README.md +2 -2
- am +0 -0
- effects.js +67 -0
- effects/base.js +387 -0
- effects/gold.js +28 -0
- effects/gradient.js +19 -0
- effects/metallic.js +28 -0
- effects/multiline-neon.js +38 -0
- effects/neon.js +24 -0
- effects/simple.js +6 -0
- index.html +119 -19
- index.js +160 -0
- styles.css +117 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: LogoMaker
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
license: other
|
|
|
1 |
---
|
2 |
title: LogoMaker
|
3 |
+
emoji: 🏃
|
4 |
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
license: other
|
am
DELETED
File without changes
|
effects.js
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { SimpleEffect } from './effects/simple.js';
|
2 |
+
import { NeonEffect } from './effects/neon.js';
|
3 |
+
import { GoldEffect } from './effects/gold.js';
|
4 |
+
import { MultilineNeonEffect } from './effects/multiline-neon.js';
|
5 |
+
import { GradientEffect } from './effects/gradient.js';
|
6 |
+
import { MetallicEffect } from './effects/metallic.js';
|
7 |
+
|
8 |
+
// エフェクトのインスタンスを作成
|
9 |
+
const effects = {
|
10 |
+
simple: new SimpleEffect(),
|
11 |
+
neon: new NeonEffect(),
|
12 |
+
gold: new GoldEffect(),
|
13 |
+
multilineNeon: new MultilineNeonEffect(),
|
14 |
+
gradient: new GradientEffect(),
|
15 |
+
metallic: new MetallicEffect(),
|
16 |
+
};
|
17 |
+
|
18 |
+
/**
|
19 |
+
* 利用可能なエフェクトのリストを返す
|
20 |
+
* @returns {Array<{name: string, description: string}>}
|
21 |
+
*/
|
22 |
+
export function getAvailableEffects() {
|
23 |
+
return [
|
24 |
+
{
|
25 |
+
name: 'simple',
|
26 |
+
description: 'シンプルなテキストレンダリング'
|
27 |
+
},
|
28 |
+
{
|
29 |
+
name: 'neon',
|
30 |
+
description: 'ネオングローエフェクト'
|
31 |
+
},
|
32 |
+
{
|
33 |
+
name: 'gold',
|
34 |
+
description: 'ゴールドエフェクト'
|
35 |
+
},
|
36 |
+
{
|
37 |
+
name: 'multilineNeon',
|
38 |
+
description: 'マルチラインネオンエフェクト'
|
39 |
+
},
|
40 |
+
{
|
41 |
+
name: 'gradient',
|
42 |
+
description: 'グラデーションエフェクト'
|
43 |
+
},
|
44 |
+
{
|
45 |
+
name: 'metallic',
|
46 |
+
description: 'メタリック調エフェクト'
|
47 |
+
}
|
48 |
+
];
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* テキストにエフェクトを適用して画像URLを生成
|
53 |
+
* @param {string} effectType - エフェクトの種類
|
54 |
+
* @param {string} text - レンダリングするテキスト
|
55 |
+
* @param {Object} options - オプション
|
56 |
+
* @param {string} options.font - フォントファミリー
|
57 |
+
* @param {number} options.fontSize - フォントサイズ
|
58 |
+
* @returns {Promise<string>} - 生成された画像のData URL
|
59 |
+
*/
|
60 |
+
export async function applyEffect(effectType, text, options) {
|
61 |
+
const effect = effects[effectType];
|
62 |
+
if (!effect) {
|
63 |
+
throw new Error(`Unknown effect type: ${effectType}`);
|
64 |
+
}
|
65 |
+
|
66 |
+
return effect.apply(text, options);
|
67 |
+
}
|
effects/base.js
ADDED
@@ -0,0 +1,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* エフェクト開発規約
|
3 |
+
* ================
|
4 |
+
*
|
5 |
+
* 1. 基本方針
|
6 |
+
* -----------
|
7 |
+
* - BaseEffectクラスは全てのエフェクトの基底クラスとして機能します
|
8 |
+
* - 文字の配置や描画に関する基本ロジックは全てBaseEffectクラスで管理します
|
9 |
+
* - 継承先のエフェクトクラスでは、見た目に関する設定のみを行います
|
10 |
+
*
|
11 |
+
* 2. 継承時のルール
|
12 |
+
* ----------------
|
13 |
+
* - getPaddingメソッドは継承先でオーバーライドしないでください
|
14 |
+
* - renderText, renderGlow, renderMainText, renderStrokeメソッドは継承先でオーバーライドしないでください
|
15 |
+
* - calculateSize, calculateCoordinatesメソッドは継承先でオーバーライドしないでください
|
16 |
+
*
|
17 |
+
* 3. 継承先での実装
|
18 |
+
* ----------------
|
19 |
+
* 以下のメソッドのみを実装/カスタマイズしてください:
|
20 |
+
*
|
21 |
+
* a) constructor
|
22 |
+
* - グローエフェクト(this.glowOptions)の設定
|
23 |
+
* - 縁取り(this.strokeOptions)の設定
|
24 |
+
*
|
25 |
+
* b) setupContext
|
26 |
+
* - フォントの基本設定(必須)
|
27 |
+
* - グラデーションなどの塗りつぶしスタイルの設定
|
28 |
+
*
|
29 |
+
* c) applySpecialEffect
|
30 |
+
* - 追加の特殊効果が必要な場合のみ実装
|
31 |
+
* - 基本的な描画が完了した後に呼び出されます
|
32 |
+
*
|
33 |
+
* 4. オプション設定
|
34 |
+
* ----------------
|
35 |
+
* glowOptions = {
|
36 |
+
* color: string, // グローの色(16進カラーコード)
|
37 |
+
* blur: number, // ぼかしの強さ
|
38 |
+
* iterations: number // 重ねがけの回数
|
39 |
+
* }
|
40 |
+
*
|
41 |
+
* strokeOptions = {
|
42 |
+
* color: string, // 縁取りの色(16進カラーコード)
|
43 |
+
* width: number // 縁取りの太さ
|
44 |
+
* }
|
45 |
+
*
|
46 |
+
* 5. 縦書き対応
|
47 |
+
* ------------
|
48 |
+
* - 縦書きの処理は全てBaseEffectクラスで管理されています
|
49 |
+
* - 継承先で縦書き用の特別な処理は実装しないでください
|
50 |
+
*/
|
51 |
+
|
52 |
+
/**
|
53 |
+
* 基本的なエフェクトクラス
|
54 |
+
*/
|
55 |
+
export class BaseEffect {
|
56 |
+
constructor() {
|
57 |
+
this.coordinates = [];
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @param {CanvasRenderingContext2D} ctx - キャンバスコンテキスト
|
62 |
+
* @param {string} text - レンダリングするテキスト
|
63 |
+
* @param {Object} options - オプション
|
64 |
+
* @param {string} options.font - フォントファミリー
|
65 |
+
* @param {number} options.fontSize - フォントサイズ
|
66 |
+
* @param {boolean} options.vertical - 縦書きモード
|
67 |
+
* @returns {Object} - キャンバスのサイズ情報
|
68 |
+
*/
|
69 |
+
calculateSize(ctx, text, options) {
|
70 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
71 |
+
|
72 |
+
// テキストを行に分割
|
73 |
+
const lines = text.split('\n');
|
74 |
+
let maxWidth = 0;
|
75 |
+
let totalHeight = 0;
|
76 |
+
const lineMetrics = [];
|
77 |
+
|
78 |
+
// 各行のメトリクスを計算
|
79 |
+
for (const line of lines) {
|
80 |
+
const metrics = ctx.measureText(line);
|
81 |
+
const lineHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
82 |
+
maxWidth = Math.max(maxWidth, metrics.width);
|
83 |
+
totalHeight += lineHeight;
|
84 |
+
lineMetrics.push({ metrics, lineHeight });
|
85 |
+
}
|
86 |
+
|
87 |
+
// 行間を追加(行数 - 1)* 行間スペース
|
88 |
+
const lineSpacing = options.fontSize * 0.2;
|
89 |
+
totalHeight += (lines.length - 1) * lineSpacing;
|
90 |
+
|
91 |
+
// 縦書きモードの場合、幅と高さを入れ替え
|
92 |
+
if (options.vertical) {
|
93 |
+
// 縦書きの場合、最大幅は各文字の高さの最大値を使用
|
94 |
+
const maxCharHeight = Math.max(...lines.map(line => {
|
95 |
+
return Math.max(...[...line].map(char => {
|
96 |
+
const metrics = ctx.measureText(char);
|
97 |
+
return metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
98 |
+
}));
|
99 |
+
}));
|
100 |
+
|
101 |
+
return {
|
102 |
+
width: totalHeight,
|
103 |
+
height: maxWidth * 1.5,
|
104 |
+
metrics: lineMetrics,
|
105 |
+
lineSpacing,
|
106 |
+
lines,
|
107 |
+
maxCharHeight
|
108 |
+
};
|
109 |
+
}
|
110 |
+
|
111 |
+
return {
|
112 |
+
width: maxWidth,
|
113 |
+
height: totalHeight,
|
114 |
+
metrics: lineMetrics,
|
115 |
+
lineSpacing,
|
116 |
+
lines
|
117 |
+
};
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* 特殊文字(縦書き時に回転が必要な文字)かどうかを判定
|
122 |
+
* @private
|
123 |
+
*/
|
124 |
+
isRotatableCharacter(char) {
|
125 |
+
// 長音記号、ハイフン、チルダ、マイナス記号など
|
126 |
+
const rotatableChars = ['ー', '-', '~', '―', '‐', '−', '─', 'ー'];
|
127 |
+
return rotatableChars.includes(char);
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* 文字の座標を計算
|
132 |
+
* @private
|
133 |
+
*/
|
134 |
+
calculateCoordinates(ctx, lines, metrics, lineSpacing, padding) {
|
135 |
+
this.coordinates = [];
|
136 |
+
|
137 |
+
if (ctx.canvas.dataset.vertical === 'true') {
|
138 |
+
// 右端から開始(文字の右端がここに来るようにする)
|
139 |
+
let currentX = ctx.canvas.width - padding/2; // パディングを半分にして右に寄せる
|
140 |
+
|
141 |
+
for (let i = 0; i < lines.length; i++) {
|
142 |
+
const line = lines[i];
|
143 |
+
const { lineHeight } = metrics[i];
|
144 |
+
const lineCoords = [];
|
145 |
+
|
146 |
+
// 各行の高さを計算
|
147 |
+
let totalLineHeight = 0;
|
148 |
+
for (const char of line) {
|
149 |
+
const metrics = ctx.measureText(char);
|
150 |
+
const charHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
151 |
+
const shouldRotate = this.isRotatableCharacter(char);
|
152 |
+
totalLineHeight += shouldRotate ? metrics.width : charHeight;
|
153 |
+
if (char !== line[line.length - 1]) {
|
154 |
+
totalLineHeight += lineSpacing;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
// 行の開始位置を中央揃えに
|
159 |
+
let charY = padding + (ctx.canvas.height - totalLineHeight - padding * 2) / 2;
|
160 |
+
|
161 |
+
for (const char of line) {
|
162 |
+
const metrics = ctx.measureText(char);
|
163 |
+
const charHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent * 1.3;
|
164 |
+
const shouldRotate = this.isRotatableCharacter(char);
|
165 |
+
|
166 |
+
// 文字の配置を調整
|
167 |
+
if (shouldRotate) {
|
168 |
+
lineCoords.push({
|
169 |
+
char,
|
170 |
+
x: currentX - charHeight,
|
171 |
+
y: charY + metrics.width/2,
|
172 |
+
width: metrics.width,
|
173 |
+
height: charHeight,
|
174 |
+
rotate: true
|
175 |
+
});
|
176 |
+
charY += metrics.width + lineSpacing;
|
177 |
+
} else {
|
178 |
+
lineCoords.push({
|
179 |
+
char,
|
180 |
+
x: currentX - metrics.width - metrics.width/4, // 通常文字を少し左に寄せる
|
181 |
+
y: charY - metrics.width/8,
|
182 |
+
width: metrics.width,
|
183 |
+
height: charHeight,
|
184 |
+
rotate: false
|
185 |
+
});
|
186 |
+
charY += charHeight + lineSpacing;
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
this.coordinates.push(lineCoords);
|
191 |
+
currentX -= lineHeight + lineSpacing;
|
192 |
+
}
|
193 |
+
} else {
|
194 |
+
let currentY = padding;
|
195 |
+
|
196 |
+
for (let i = 0; i < lines.length; i++) {
|
197 |
+
const line = lines[i];
|
198 |
+
const { lineHeight } = metrics[i];
|
199 |
+
const lineWidth = ctx.measureText(line).width;
|
200 |
+
|
201 |
+
// 水平方向の中央揃え
|
202 |
+
const x = (ctx.canvas.width - lineWidth) / 2;
|
203 |
+
|
204 |
+
this.coordinates.push([{
|
205 |
+
char: line,
|
206 |
+
x: x,
|
207 |
+
y: currentY,
|
208 |
+
width: lineWidth,
|
209 |
+
height: lineHeight,
|
210 |
+
rotate: false
|
211 |
+
}]);
|
212 |
+
|
213 |
+
currentY += lineHeight + lineSpacing;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* テキストの描画
|
220 |
+
*/
|
221 |
+
async renderText(ctx, lines, metrics, lineSpacing, padding) {
|
222 |
+
// 座標を計算
|
223 |
+
this.calculateCoordinates(ctx, lines, metrics, lineSpacing, padding);
|
224 |
+
|
225 |
+
// グローエフェクトを描画(設定されている場合)
|
226 |
+
await this.renderGlow(ctx);
|
227 |
+
|
228 |
+
// メインのテキストを描画
|
229 |
+
await this.renderMainText(ctx);
|
230 |
+
|
231 |
+
// 縁取りを描画(設定されている場合)
|
232 |
+
await this.renderStroke(ctx);
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* グローエフェクトの描画
|
237 |
+
*/
|
238 |
+
async renderGlow(ctx) {
|
239 |
+
if (!this.glowOptions) return;
|
240 |
+
|
241 |
+
const { color, blur, iterations } = this.glowOptions;
|
242 |
+
ctx.shadowColor = color;
|
243 |
+
ctx.shadowOffsetX = 0;
|
244 |
+
ctx.shadowOffsetY = 0;
|
245 |
+
|
246 |
+
for (let j = 0; j < iterations; j++) {
|
247 |
+
ctx.shadowBlur = blur - (blur * j / iterations);
|
248 |
+
ctx.fillStyle = `rgba(${this.hexToRgb(color)}, ${1/iterations})`;
|
249 |
+
|
250 |
+
for (const lineCoords of this.coordinates) {
|
251 |
+
for (const coord of lineCoords) {
|
252 |
+
ctx.save();
|
253 |
+
if (coord.rotate) {
|
254 |
+
ctx.translate(coord.x, coord.y);
|
255 |
+
ctx.rotate(Math.PI/2);
|
256 |
+
ctx.fillText(coord.char, -coord.width/2, 0);
|
257 |
+
} else {
|
258 |
+
ctx.fillText(coord.char, coord.x, coord.y);
|
259 |
+
}
|
260 |
+
ctx.restore();
|
261 |
+
}
|
262 |
+
}
|
263 |
+
}
|
264 |
+
|
265 |
+
// シャドウをリセット
|
266 |
+
ctx.shadowBlur = 0;
|
267 |
+
ctx.shadowColor = 'transparent';
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* メインテキストの描画
|
272 |
+
*/
|
273 |
+
async renderMainText(ctx) {
|
274 |
+
for (const lineCoords of this.coordinates) {
|
275 |
+
for (const coord of lineCoords) {
|
276 |
+
ctx.save();
|
277 |
+
if (coord.rotate) {
|
278 |
+
ctx.translate(coord.x, coord.y);
|
279 |
+
ctx.rotate(Math.PI/2);
|
280 |
+
ctx.fillText(coord.char, -coord.width/2, 0);
|
281 |
+
} else {
|
282 |
+
ctx.fillText(coord.char, coord.x, coord.y);
|
283 |
+
}
|
284 |
+
ctx.restore();
|
285 |
+
}
|
286 |
+
}
|
287 |
+
}
|
288 |
+
|
289 |
+
/**
|
290 |
+
* 縁取りの描画
|
291 |
+
*/
|
292 |
+
async renderStroke(ctx) {
|
293 |
+
if (!this.strokeOptions) return;
|
294 |
+
|
295 |
+
const { color, width } = this.strokeOptions;
|
296 |
+
ctx.strokeStyle = color;
|
297 |
+
ctx.lineWidth = width;
|
298 |
+
|
299 |
+
for (const lineCoords of this.coordinates) {
|
300 |
+
for (const coord of lineCoords) {
|
301 |
+
ctx.save();
|
302 |
+
if (coord.rotate) {
|
303 |
+
ctx.translate(coord.x, coord.y);
|
304 |
+
ctx.rotate(Math.PI/2);
|
305 |
+
ctx.strokeText(coord.char, -coord.width/2, 0);
|
306 |
+
} else {
|
307 |
+
ctx.strokeText(coord.char, coord.x, coord.y);
|
308 |
+
}
|
309 |
+
ctx.restore();
|
310 |
+
}
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* 16進カラーコードをRGB形式に変換
|
316 |
+
*/
|
317 |
+
hexToRgb(hex) {
|
318 |
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
319 |
+
return result ?
|
320 |
+
`${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}` :
|
321 |
+
'0, 0, 0';
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* エフェクトを適用する
|
326 |
+
* @param {string} text - レンダリングするテキスト
|
327 |
+
* @param {Object} options - オプション
|
328 |
+
* @returns {Promise<string>} - 生成された画像のData URL
|
329 |
+
*/
|
330 |
+
async apply(text, options) {
|
331 |
+
const canvas = document.createElement('canvas');
|
332 |
+
const ctx = canvas.getContext('2d');
|
333 |
+
|
334 |
+
// 縦書きモードの状態を保存
|
335 |
+
canvas.dataset.vertical = options.vertical;
|
336 |
+
|
337 |
+
// キャンバスサイズの設定
|
338 |
+
const padding = this.getPadding();
|
339 |
+
const { width, height, metrics, lineSpacing, lines } = this.calculateSize(ctx, text, options);
|
340 |
+
|
341 |
+
canvas.width = width + padding * 2;
|
342 |
+
canvas.height = height + padding * 2;
|
343 |
+
|
344 |
+
// 背景を透明に
|
345 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
346 |
+
|
347 |
+
// テキストの基本設定
|
348 |
+
await this.setupContext(ctx, options);
|
349 |
+
|
350 |
+
// テキストの描画
|
351 |
+
await this.renderText(ctx, lines, metrics, lineSpacing, padding);
|
352 |
+
|
353 |
+
// エフェクト固有の処理
|
354 |
+
await this.applySpecialEffect(ctx, canvas, options);
|
355 |
+
|
356 |
+
return canvas.toDataURL('image/png');
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* パディング値を取得
|
361 |
+
* @returns {number} パディング値
|
362 |
+
*/
|
363 |
+
getPadding() {
|
364 |
+
return 60;
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* コンテキストの基本設定
|
369 |
+
* @param {CanvasRenderingContext2D} ctx
|
370 |
+
* @param {Object} options
|
371 |
+
*/
|
372 |
+
async setupContext(ctx, options) {
|
373 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
374 |
+
ctx.fillStyle = '#000000';
|
375 |
+
ctx.textBaseline = 'top';
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* エフェクト固有の処理
|
380 |
+
* @param {CanvasRenderingContext2D} ctx
|
381 |
+
* @param {HTMLCanvasElement} canvas
|
382 |
+
* @param {Object} options
|
383 |
+
*/
|
384 |
+
async applySpecialEffect(ctx, canvas, options) {
|
385 |
+
// デフォルトでは何もしない
|
386 |
+
}
|
387 |
+
}
|
effects/gold.js
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class GoldEffect extends BaseEffect {
|
4 |
+
constructor() {
|
5 |
+
super();
|
6 |
+
this.glowOptions = {
|
7 |
+
color: '#ffd700',
|
8 |
+
blur: 15,
|
9 |
+
iterations: 10
|
10 |
+
};
|
11 |
+
this.strokeOptions = {
|
12 |
+
color: '#b8860b',
|
13 |
+
width: 2
|
14 |
+
};
|
15 |
+
}
|
16 |
+
|
17 |
+
async setupContext(ctx, options) {
|
18 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
19 |
+
ctx.textBaseline = 'top';
|
20 |
+
|
21 |
+
// ゴールドグラデーションの作成
|
22 |
+
const gradient = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);
|
23 |
+
gradient.addColorStop(0, '#ffd700');
|
24 |
+
gradient.addColorStop(0.5, '#ffb700');
|
25 |
+
gradient.addColorStop(1, '#ffd700');
|
26 |
+
ctx.fillStyle = gradient;
|
27 |
+
}
|
28 |
+
}
|
effects/gradient.js
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class GradientEffect extends BaseEffect {
|
4 |
+
constructor() {
|
5 |
+
super();
|
6 |
+
}
|
7 |
+
|
8 |
+
async setupContext(ctx, options) {
|
9 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
10 |
+
ctx.textBaseline = 'top';
|
11 |
+
|
12 |
+
// グラデーションの作成
|
13 |
+
const gradient = ctx.createLinearGradient(0, 0, ctx.canvas.width, ctx.canvas.height);
|
14 |
+
gradient.addColorStop(0, '#ff0000');
|
15 |
+
gradient.addColorStop(0.5, '#00ff00');
|
16 |
+
gradient.addColorStop(1, '#0000ff');
|
17 |
+
ctx.fillStyle = gradient;
|
18 |
+
}
|
19 |
+
}
|
effects/metallic.js
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class MetallicEffect extends BaseEffect {
|
4 |
+
constructor() {
|
5 |
+
super();
|
6 |
+
this.glowOptions = {
|
7 |
+
color: '#c0c0c0',
|
8 |
+
blur: 15,
|
9 |
+
iterations: 10
|
10 |
+
};
|
11 |
+
this.strokeOptions = {
|
12 |
+
color: '#808080',
|
13 |
+
width: 1.5
|
14 |
+
};
|
15 |
+
}
|
16 |
+
|
17 |
+
async setupContext(ctx, options) {
|
18 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
19 |
+
ctx.textBaseline = 'top';
|
20 |
+
|
21 |
+
// メタリックグラデーションの作成
|
22 |
+
const gradient = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);
|
23 |
+
gradient.addColorStop(0, '#e8e8e8');
|
24 |
+
gradient.addColorStop(0.5, '#a0a0a0');
|
25 |
+
gradient.addColorStop(1, '#c0c0c0');
|
26 |
+
ctx.fillStyle = gradient;
|
27 |
+
}
|
28 |
+
}
|
effects/multiline-neon.js
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class MultilineNeonEffect extends BaseEffect {
|
4 |
+
constructor() {
|
5 |
+
super();
|
6 |
+
this.glowOptions = {
|
7 |
+
color: '#00ffff',
|
8 |
+
blur: 25,
|
9 |
+
iterations: 25
|
10 |
+
};
|
11 |
+
this.strokeOptions = {
|
12 |
+
color: '#ffffff',
|
13 |
+
width: 0.5
|
14 |
+
};
|
15 |
+
}
|
16 |
+
|
17 |
+
async setupContext(ctx, options) {
|
18 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
19 |
+
ctx.textBaseline = 'top';
|
20 |
+
ctx.fillStyle = '#00ffff'; // シアン色のメインカラー
|
21 |
+
}
|
22 |
+
|
23 |
+
async applySpecialEffect(ctx, canvas, options) {
|
24 |
+
// 追加のネオン効果(オプション)
|
25 |
+
ctx.globalCompositeOperation = 'lighter';
|
26 |
+
ctx.shadowBlur = 10;
|
27 |
+
ctx.shadowColor = '#00ffff';
|
28 |
+
ctx.globalAlpha = 0.3;
|
29 |
+
|
30 |
+
// 既に描画されたテキストの上に薄く重ねて光る効果を追加
|
31 |
+
await this.renderMainText(ctx);
|
32 |
+
|
33 |
+
// 設定を元に戻す
|
34 |
+
ctx.globalCompositeOperation = 'source-over';
|
35 |
+
ctx.shadowBlur = 0;
|
36 |
+
ctx.globalAlpha = 1.0;
|
37 |
+
}
|
38 |
+
}
|
effects/neon.js
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class NeonEffect extends BaseEffect {
|
4 |
+
constructor() {
|
5 |
+
super();
|
6 |
+
// グローエフェクトの設定
|
7 |
+
this.glowOptions = {
|
8 |
+
color: '#ff69b4',
|
9 |
+
blur: 20,
|
10 |
+
iterations: 20
|
11 |
+
};
|
12 |
+
// 縁取りの設定
|
13 |
+
this.strokeOptions = {
|
14 |
+
color: '#ffffff',
|
15 |
+
width: 0.5
|
16 |
+
};
|
17 |
+
}
|
18 |
+
|
19 |
+
async setupContext(ctx, options) {
|
20 |
+
ctx.font = `${options.fontSize}px "${options.font}"`;
|
21 |
+
ctx.textBaseline = 'top';
|
22 |
+
ctx.fillStyle = '#ff69b4'; // メインのテキストカラー
|
23 |
+
}
|
24 |
+
}
|
effects/simple.js
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseEffect } from './base.js';
|
2 |
+
|
3 |
+
export class SimpleEffect extends BaseEffect {
|
4 |
+
// シンプルエフェクトは基本実装をそのまま使用するため、
|
5 |
+
// オーバーライドする必要がありません
|
6 |
+
}
|
index.html
CHANGED
@@ -1,19 +1,119 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="ja">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>ロゴジェネレーター</title>
|
8 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
9 |
+
<link href="https://fonts.googleapis.com/css?family=Noto+Sans+JP" rel="stylesheet">
|
10 |
+
<link href="styles.css" rel="stylesheet">
|
11 |
+
<script type="module" src="effects.js"></script>
|
12 |
+
<script type="module" src="index.js"></script>
|
13 |
+
</head>
|
14 |
+
|
15 |
+
<body>
|
16 |
+
<div class="container py-5">
|
17 |
+
<div class="row justify-content-center">
|
18 |
+
<div class="col-md-8">
|
19 |
+
<div class="card">
|
20 |
+
<div class="card-header">
|
21 |
+
<h2 class="h4 mb-0">ロゴジェネレーター</h2>
|
22 |
+
</div>
|
23 |
+
<div class="card-body">
|
24 |
+
<div class="mb-3">
|
25 |
+
<label for="textInput" class="form-label">テキスト</label>
|
26 |
+
<textarea class="form-control" id="textInput" rows="3" placeholder="テキストを入力してください">プレビュー</textarea>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
<div class="mb-3">
|
30 |
+
<label for="googleFontInput" class="form-label">フォント</label>
|
31 |
+
<select name="googleFontInput" class="form-select" id="googleFontInput">
|
32 |
+
<option>Aoboshi One</option>
|
33 |
+
<option>BIZ UDGothic</option>
|
34 |
+
<option>BIZ UDMincho</option>
|
35 |
+
<option>BIZ UDPGothic</option>
|
36 |
+
<option>BIZ UDPMincho</option>
|
37 |
+
<option>Cherry Bomb One</option>
|
38 |
+
<option>Chokokutai</option>
|
39 |
+
<option>Darumadrop One</option>
|
40 |
+
<option>Dela Gothic One</option>
|
41 |
+
<option>DotGothic16</option>
|
42 |
+
<option>Hachi Maru Pop</option>
|
43 |
+
<option>Hina Mincho</option>
|
44 |
+
<option>IBM Plex Sans JP</option>
|
45 |
+
<option>Kaisei Decol</option>
|
46 |
+
<option>Kaisei HarunoUmi</option>
|
47 |
+
<option>Kaisei Opti</option>
|
48 |
+
<option>Kaisei Tokumin</option>
|
49 |
+
<option>Kiwi Maru</option>
|
50 |
+
<option>Klee One</option>
|
51 |
+
<option>Kosugi</option>
|
52 |
+
<option>Kosugi Maru</option>
|
53 |
+
<option>M PLUS 1</option>
|
54 |
+
<option>M PLUS 1 Code</option>
|
55 |
+
<option>M PLUS 1p</option>
|
56 |
+
<option>M PLUS 2</option>
|
57 |
+
<option>M PLUS Rounded 1c</option>
|
58 |
+
<option selected="selected">Mochiy Pop One</option>
|
59 |
+
<option>Mochiy Pop P One</option>
|
60 |
+
<option>Monomaniac One</option>
|
61 |
+
<option>Murecho</option>
|
62 |
+
<option>New Tegomin</option>
|
63 |
+
<option>Noto Sans JP</option>
|
64 |
+
<option>Noto Serif JP</option>
|
65 |
+
<option>Palette Mosaic</option>
|
66 |
+
<option>Potta One</option>
|
67 |
+
<option>Rampart One</option>
|
68 |
+
<option>Reggae One</option>
|
69 |
+
<option>Rock 3D</option>
|
70 |
+
<option>RocknRoll One</option>
|
71 |
+
<option>Sawarabi Gothic</option>
|
72 |
+
<option>Sawarabi Mincho</option>
|
73 |
+
<option>Shippori Antique</option>
|
74 |
+
<option>Shippori Antique B1</option>
|
75 |
+
<option>Shippori Mincho</option>
|
76 |
+
<option>Shippori Mincho B1</option>
|
77 |
+
<option>Shizuru</option>
|
78 |
+
<option>Slackside One</option>
|
79 |
+
<option>Stick</option>
|
80 |
+
<option>Train One</option>
|
81 |
+
<option>Tsukimi Rounded</option>
|
82 |
+
<option>Yomogi</option>
|
83 |
+
<option>Yuji Boku</option>
|
84 |
+
<option>Yuji Hentaigana Akari</option>
|
85 |
+
<option>Yuji Hentaigana Akebono</option>
|
86 |
+
<option>Yuji Mai</option>
|
87 |
+
<option>Yuji Syuku</option>
|
88 |
+
<option>Yusei Magic</option>
|
89 |
+
<option>Zen Antique</option>
|
90 |
+
<option>Zen Antique Soft</option>
|
91 |
+
<option>Zen Kaku Gothic Antique</option>
|
92 |
+
<option>Zen Kaku Gothic New</option>
|
93 |
+
<option>Zen Kurenaido</option>
|
94 |
+
<option>Zen Maru Gothic</option>
|
95 |
+
<option>Zen Old Mincho</option>
|
96 |
+
</select>
|
97 |
+
</div>
|
98 |
+
|
99 |
+
<div class="mb-3 d-none">
|
100 |
+
<label for="fontSize" class="form-label">フォントサイズ</label>
|
101 |
+
<input type="number" class="form-control" id="fontSize" value="128" min="8" max="128">
|
102 |
+
</div>
|
103 |
+
|
104 |
+
<div class="mb-3 form-switch">
|
105 |
+
<input type="checkbox" class="form-check-input" id="verticalText" role="switch">
|
106 |
+
<label class="form-check-label" for="verticalText">縦書き</label>
|
107 |
+
</div>
|
108 |
+
|
109 |
+
<div class="effect-grid">
|
110 |
+
<!-- プリセットギャラリーはJavaScriptで動的に追加されます -->
|
111 |
+
</div>
|
112 |
+
</div>
|
113 |
+
</div>
|
114 |
+
</div>
|
115 |
+
</div>
|
116 |
+
</div>
|
117 |
+
</body>
|
118 |
+
|
119 |
+
</html>
|
index.js
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { applyEffect, getAvailableEffects } from './effects.js';
|
2 |
+
|
3 |
+
// フォントの読み込みを管理する関数
|
4 |
+
async function loadGoogleFont(fontFamily) {
|
5 |
+
// フォントファミリー名を正しく整形
|
6 |
+
const formattedFamily = fontFamily.replace(/ /g, '+');
|
7 |
+
|
8 |
+
// Google Fonts APIのURLを構築
|
9 |
+
const url = `https://fonts.googleapis.com/css2?family=${formattedFamily}&display=swap`;
|
10 |
+
|
11 |
+
// 既存のリンクタグがあれば削除
|
12 |
+
const existingLink = document.querySelector(`link[href*="${formattedFamily}"]`);
|
13 |
+
if (existingLink) {
|
14 |
+
existingLink.remove();
|
15 |
+
}
|
16 |
+
|
17 |
+
// 新しいリンクタグを追加
|
18 |
+
const link = document.createElement('link');
|
19 |
+
link.href = url;
|
20 |
+
link.rel = 'stylesheet';
|
21 |
+
document.head.appendChild(link);
|
22 |
+
|
23 |
+
// フォントの読み込みを待つ
|
24 |
+
await new Promise((resolve, reject) => {
|
25 |
+
link.onload = async () => {
|
26 |
+
try {
|
27 |
+
// フォントの読み込みを確認
|
28 |
+
await document.fonts.load(`16px "${fontFamily}"`);
|
29 |
+
// 少し待機して確実にフォントを利用可能にする
|
30 |
+
setTimeout(resolve, 100);
|
31 |
+
} catch (error) {
|
32 |
+
reject(error);
|
33 |
+
}
|
34 |
+
};
|
35 |
+
link.onerror = reject;
|
36 |
+
});
|
37 |
+
}
|
38 |
+
|
39 |
+
// テキストを画像に変換する関数を更新
|
40 |
+
async function textToImage(text, fontFamily, fontSize = '48px', effectType = 'simple') {
|
41 |
+
console.debug(`テキスト描画開始: ${effectType}`, { text, fontFamily, fontSize });
|
42 |
+
try {
|
43 |
+
await document.fonts.load(`${fontSize} "${fontFamily}"`);
|
44 |
+
const fontSizeNum = parseInt(fontSize);
|
45 |
+
const verticalText = document.getElementById('verticalText').checked;
|
46 |
+
|
47 |
+
// エフェクトを適用
|
48 |
+
const imageUrl = await applyEffect(effectType, text, {
|
49 |
+
font: fontFamily,
|
50 |
+
fontSize: fontSizeNum,
|
51 |
+
vertical: verticalText
|
52 |
+
});
|
53 |
+
|
54 |
+
return imageUrl;
|
55 |
+
} catch (error) {
|
56 |
+
console.error('フォント描画エラー:', error);
|
57 |
+
throw error;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
// デバウンス関数の実装
|
62 |
+
let renderTimeout = null;
|
63 |
+
let isRendering = false;
|
64 |
+
|
65 |
+
function debounceRender(callback, delay = 200) {
|
66 |
+
if (renderTimeout) {
|
67 |
+
clearTimeout(renderTimeout);
|
68 |
+
}
|
69 |
+
|
70 |
+
if (isRendering) {
|
71 |
+
return;
|
72 |
+
}
|
73 |
+
|
74 |
+
renderTimeout = setTimeout(async () => {
|
75 |
+
isRendering = true;
|
76 |
+
try {
|
77 |
+
await callback();
|
78 |
+
} finally {
|
79 |
+
isRendering = false;
|
80 |
+
}
|
81 |
+
}, delay);
|
82 |
+
}
|
83 |
+
|
84 |
+
// イベントリスナーの設定を更新
|
85 |
+
document.addEventListener('DOMContentLoaded', async () => {
|
86 |
+
const fontSelect = document.getElementById('googleFontInput');
|
87 |
+
const textInput = document.getElementById('textInput');
|
88 |
+
const fontSizeInput = document.getElementById('fontSize');
|
89 |
+
const verticalTextInput = document.getElementById('verticalText');
|
90 |
+
const effectGrid = document.querySelector('.effect-grid');
|
91 |
+
|
92 |
+
await loadGoogleFont(fontSelect.value);
|
93 |
+
|
94 |
+
// 縦書きモードの状態をグリッドに反映
|
95 |
+
verticalTextInput.addEventListener('change', (e) => {
|
96 |
+
effectGrid.dataset.vertical = e.target.checked;
|
97 |
+
renderAllPresets();
|
98 |
+
});
|
99 |
+
|
100 |
+
// すべてのプリセットを描画する関数
|
101 |
+
async function renderAllPresets() {
|
102 |
+
effectGrid.innerHTML = '';
|
103 |
+
const text = textInput.value || 'プレビュー';
|
104 |
+
const fontFamily = fontSelect.value;
|
105 |
+
const fontSize = fontSizeInput.value + 'px';
|
106 |
+
|
107 |
+
const effects = getAvailableEffects();
|
108 |
+
for (const effect of effects) {
|
109 |
+
try {
|
110 |
+
const imageUrl = await textToImage(text, fontFamily, fontSize, effect.name);
|
111 |
+
|
112 |
+
const presetCard = document.createElement('div');
|
113 |
+
presetCard.className = 'effect-item';
|
114 |
+
presetCard.innerHTML = `
|
115 |
+
<div class="effect-name">${effect.name}</div>
|
116 |
+
<div class="preview-container">
|
117 |
+
<img src="${imageUrl}" alt="${effect.name}">
|
118 |
+
</div>
|
119 |
+
`;
|
120 |
+
|
121 |
+
effectGrid.appendChild(presetCard);
|
122 |
+
} catch (error) {
|
123 |
+
console.error(`プリセット ${effect.name} の描画エラー:`, error);
|
124 |
+
|
125 |
+
const errorCard = document.createElement('div');
|
126 |
+
errorCard.className = 'effect-item error';
|
127 |
+
errorCard.innerHTML = `
|
128 |
+
<div class="effect-name text-danger">${effect.name}</div>
|
129 |
+
<div class="preview-container">
|
130 |
+
<div class="text-danger">
|
131 |
+
<small>エラー: ${error.message}</small>
|
132 |
+
</div>
|
133 |
+
</div>
|
134 |
+
`;
|
135 |
+
effectGrid.appendChild(errorCard);
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
// フォント変更時の処理
|
141 |
+
fontSelect.addEventListener('change', async (e) => {
|
142 |
+
try {
|
143 |
+
const fontFamily = e.target.value;
|
144 |
+
await loadGoogleFont(fontFamily);
|
145 |
+
await renderAllPresets();
|
146 |
+
} catch (error) {
|
147 |
+
console.error('フォント読み込みエラー:', error);
|
148 |
+
}
|
149 |
+
});
|
150 |
+
|
151 |
+
// テキストとフォントサイズの変更時にすべてのプリセットを再描画
|
152 |
+
[textInput, fontSizeInput, verticalTextInput].forEach(element => {
|
153 |
+
element.addEventListener('input', () => {
|
154 |
+
debounceRender(renderAllPresets);
|
155 |
+
});
|
156 |
+
});
|
157 |
+
|
158 |
+
// 初期描画
|
159 |
+
await renderAllPresets();
|
160 |
+
});
|
styles.css
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.preview-container {
|
2 |
+
position: relative;
|
3 |
+
padding: 1rem;
|
4 |
+
min-height: 100px;
|
5 |
+
display: flex;
|
6 |
+
align-items: center;
|
7 |
+
justify-content: center;
|
8 |
+
background: repeating-conic-gradient(#80808010 0% 25%, transparent 0% 50%) 50% / 20px 20px;
|
9 |
+
}
|
10 |
+
|
11 |
+
.preview-container img {
|
12 |
+
max-width: 100%;
|
13 |
+
max-height: 300px;
|
14 |
+
height: auto;
|
15 |
+
object-fit: contain;
|
16 |
+
}
|
17 |
+
|
18 |
+
.effect-grid {
|
19 |
+
display: grid;
|
20 |
+
gap: 1rem;
|
21 |
+
margin-top: 2rem;
|
22 |
+
}
|
23 |
+
|
24 |
+
/* 横書き時のグリッドレイアウト */
|
25 |
+
.effect-grid:not([data-vertical="true"]) {
|
26 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
27 |
+
}
|
28 |
+
|
29 |
+
/* 縦書き時のグリッドレイアウト */
|
30 |
+
.effect-grid[data-vertical="true"] {
|
31 |
+
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
32 |
+
}
|
33 |
+
|
34 |
+
.effect-item {
|
35 |
+
background: #f8f9fa;
|
36 |
+
border: 1px solid #dee2e6;
|
37 |
+
border-radius: 0.5rem;
|
38 |
+
padding: 1rem;
|
39 |
+
text-align: center;
|
40 |
+
display: flex;
|
41 |
+
flex-direction: column;
|
42 |
+
}
|
43 |
+
|
44 |
+
.effect-name {
|
45 |
+
font-size: 1.1rem;
|
46 |
+
margin-bottom: 1rem;
|
47 |
+
font-weight: 500;
|
48 |
+
}
|
49 |
+
|
50 |
+
.effect-item.error {
|
51 |
+
background: #fff3f3;
|
52 |
+
border-color: #ffcdd2;
|
53 |
+
}
|
54 |
+
|
55 |
+
.text-danger {
|
56 |
+
color: #dc3545;
|
57 |
+
}
|
58 |
+
|
59 |
+
/* エフェクトレンダリング用のスタイル */
|
60 |
+
.effect-renderer {
|
61 |
+
position: absolute;
|
62 |
+
top: 0;
|
63 |
+
left: 0;
|
64 |
+
width: 100%;
|
65 |
+
height: 100%;
|
66 |
+
pointer-events: none;
|
67 |
+
}
|
68 |
+
|
69 |
+
.effect-renderer canvas {
|
70 |
+
position: absolute;
|
71 |
+
top: 0;
|
72 |
+
left: 0;
|
73 |
+
}
|
74 |
+
|
75 |
+
/* パーティクルエフェクト用のスタイル */
|
76 |
+
.particle-container {
|
77 |
+
position: absolute;
|
78 |
+
top: 0;
|
79 |
+
left: 0;
|
80 |
+
width: 100%;
|
81 |
+
height: 100%;
|
82 |
+
pointer-events: none;
|
83 |
+
z-index: 1;
|
84 |
+
}
|
85 |
+
|
86 |
+
/* 3Dエフェクト用のスタイル */
|
87 |
+
.three-container {
|
88 |
+
position: absolute;
|
89 |
+
top: 0;
|
90 |
+
left: 0;
|
91 |
+
width: 100%;
|
92 |
+
height: 100%;
|
93 |
+
pointer-events: none;
|
94 |
+
z-index: 2;
|
95 |
+
}
|
96 |
+
|
97 |
+
/* アニメーションエフェクト用のスタイル */
|
98 |
+
@keyframes sparkle {
|
99 |
+
0%, 100% { opacity: 0; }
|
100 |
+
50% { opacity: 1; }
|
101 |
+
}
|
102 |
+
|
103 |
+
@keyframes fire {
|
104 |
+
0% { transform: translateY(0) scale(1); }
|
105 |
+
100% { transform: translateY(-20px) scale(0.8); opacity: 0; }
|
106 |
+
}
|
107 |
+
|
108 |
+
@keyframes electric {
|
109 |
+
0%, 100% { opacity: 1; }
|
110 |
+
50% { opacity: 0.7; }
|
111 |
+
}
|
112 |
+
|
113 |
+
@keyframes underwater {
|
114 |
+
0% { transform: translateY(0) translateX(0); }
|
115 |
+
50% { transform: translateY(-10px) translateX(5px); }
|
116 |
+
100% { transform: translateY(0) translateX(0); }
|
117 |
+
}
|