Update utils/api.py
Browse files- utils/api.py +315 -26
utils/api.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import json
|
|
|
|
| 2 |
from typing import Dict, Any, Optional
|
| 3 |
from groq import Groq
|
| 4 |
|
|
@@ -18,28 +19,61 @@ def generate_fancy_text(
|
|
| 18 |
Returns:
|
| 19 |
装飾スタイルの辞書。エラーが発生した場合はNone
|
| 20 |
"""
|
| 21 |
-
# システムプロンプトを
|
| 22 |
system_prompt = """あなたはテキスト装飾の専門家です。
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
try:
|
| 45 |
# Groq APIクライアントを初期化
|
|
@@ -78,6 +112,9 @@ def get_fallback_styles(text):
|
|
| 78 |
Returns:
|
| 79 |
スタイルの辞書
|
| 80 |
"""
|
|
|
|
|
|
|
|
|
|
| 81 |
# 全角変換用の関数
|
| 82 |
def to_fullwidth(text):
|
| 83 |
result = ""
|
|
@@ -89,9 +126,241 @@ def get_fallback_styles(text):
|
|
| 89 |
result += char
|
| 90 |
return result
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
# 事前定義したスタイル
|
| 93 |
fallback_styles = {
|
| 94 |
"styles": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
{"name": "シンプル星", "text": f"★ {text} ★"},
|
| 96 |
{"name": "波線", "text": f"〜{text}〜"},
|
| 97 |
{"name": "ドット", "text": f"・{text}・"},
|
|
@@ -102,16 +371,12 @@ def get_fallback_styles(text):
|
|
| 102 |
{"name": "矢印", "text": f"→{text}←"},
|
| 103 |
{"name": "四角", "text": f"■{text}■"},
|
| 104 |
{"name": "丸", "text": f"●{text}●"},
|
| 105 |
-
{"name": "全角", "text": to_fullwidth(text)},
|
| 106 |
-
{"name": "二重線", "text": f"==={text}==="},
|
| 107 |
-
{"name": "点線", "text": f"・・・{text}・・・"},
|
| 108 |
{"name": "キラキラ", "text": f"✨{text}✨"},
|
| 109 |
{"name": "シンプル装飾", "text": f"▶ {text} ◀"},
|
| 110 |
{"name": "花装飾", "text": f"❀ {text} ❀"},
|
| 111 |
{"name": "音符", "text": f"♪ {text} ♪"},
|
| 112 |
{"name": "サンダーマーク", "text": f"⚡ {text} ⚡"},
|
| 113 |
{"name": "ハートフレーム", "text": f"❤️ {text} ❤️"},
|
| 114 |
-
{"name": "シャープ", "text": f"# {text} #"},
|
| 115 |
{"name": "丸括弧", "text": f"({text})"},
|
| 116 |
{"name": "角括弧", "text": f"[{text}]"},
|
| 117 |
{"name": "波括弧", "text": f"{{{text}}}"},
|
|
@@ -121,7 +386,31 @@ def get_fallback_styles(text):
|
|
| 121 |
{"name": "二重鉤括弧", "text": f"『{text}』"},
|
| 122 |
{"name": "下線", "text": f"_{text}_"},
|
| 123 |
{"name": "スパークル", "text": f"*:・゚{text}*:・゚"},
|
| 124 |
-
{"name": "チェック", "text": f"✓ {text} ✓"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
]
|
| 126 |
}
|
| 127 |
return fallback_styles
|
|
|
|
| 1 |
import json
|
| 2 |
+
import re
|
| 3 |
from typing import Dict, Any, Optional
|
| 4 |
from groq import Groq
|
| 5 |
|
|
|
|
| 19 |
Returns:
|
| 20 |
装飾スタイルの辞書。エラーが発生した場合はNone
|
| 21 |
"""
|
| 22 |
+
# システムプロンプトを改善 - 複雑なコンビニング文字も含める
|
| 23 |
system_prompt = """あなたはテキスト装飾の専門家です。
|
| 24 |
+
与えられたテキストを35種類以上の異なるスタイルに変換してください。
|
| 25 |
+
以下のような多様な装飾スタイルを必ず含めてください:
|
| 26 |
+
|
| 27 |
+
1. Unicode変換スタイル:
|
| 28 |
+
- 数学体(𝐟𝐨𝐥𝐥𝐨𝐰)
|
| 29 |
+
- フラクトゥール(𝔣𝔬𝔩𝔩𝔬𝔴)
|
| 30 |
+
- 太字フラクトゥール(𝖋𝖔𝖑𝖑𝖔𝖜)
|
| 31 |
+
- スクリプト体(𝓯𝓸𝓵𝓵𝓸𝔀)
|
| 32 |
+
- 太字(𝗳𝗼𝗹𝗹𝗼𝘄)
|
| 33 |
+
- イタリック(𝘧𝘰𝘭𝘭𝘰𝘸)
|
| 34 |
+
- 太字イタリック(𝙛𝙤𝙡𝙡𝙤𝙬)
|
| 35 |
+
- サンセリフ(𝚏𝚘𝚕𝚕𝚘𝚠)
|
| 36 |
+
- 小型大文字(ꜰᴏʟʟᴏᴡ)
|
| 37 |
+
|
| 38 |
+
2. 装飾スタイル:
|
| 39 |
+
- 囲み文字(【f】【o】【l】【l】【o】【w】)
|
| 40 |
+
- 波線付き(f̴o̴l̴l̴o̴w̴)
|
| 41 |
+
- 取り消し線(f̶o̶l̶l̶o̶w̶)
|
| 42 |
+
- 下線付き(f̲o̲l̲l̲o̲w̲)
|
| 43 |
+
- 点付き(ḟöḷḷöẇ)
|
| 44 |
+
|
| 45 |
+
3. クリエイティブな変換:
|
| 46 |
+
- 反転テキスト(ʍolloɟ)
|
| 47 |
+
- ブロック文字(🅵🅾🅻🅻🅾🆆)
|
| 48 |
+
- サークル文字(ⓕⓞⓛⓛⓞⓦ)
|
| 49 |
+
- 装飾フレーム(✿ follow ✿)
|
| 50 |
+
- 絵文字装飾(💖 follow 💖)
|
| 51 |
+
- かわいい装飾(🎀 follow 🎀)
|
| 52 |
+
|
| 53 |
+
4. 文字間に記号を挿入するスタイルも含めてください(f♥o♥l♥l♥o♥w)
|
| 54 |
+
|
| 55 |
+
5. 高度なコンビニング文字スタイル:
|
| 56 |
+
- 複雑な重ね合わせ(例:⨍ᨵׁׅᥣׁׅ֪ᥣׁׅ֪ᨵׁׅᨰׁׅ)
|
| 57 |
+
- グリッチ風装飾(例:あ̸̰͕͈̹̃̇た̷̗̼͛̒̑͂̃̐̄し̷̡̻͖̣̲̰̼̲̎̈́̈́́̈͝͝を̶̲̯͓͖͍̜̻͒͗f̵̻̤̯͎̠͉̼̬̘͉͗́̍͋̅̋͛̀o̸̡̤̺̭̿̄͒̎̔̈́͆̐̇̂ͅl̸̡̪̭͗̓̄̀̑̉̓͑ḻ̷͙̞̤̰̗̍̅̿ơ̴̯̙̠̜̠̐̚͝w̴̢̻̰̱͉̣̍̈́͐̈́)
|
| 58 |
+
- ブロック文字によるマーキング(例:あ⃞ た⃞ し⃞ を⃞ f⃞ o⃞ l⃞ l⃞ o⃞ w⃞)
|
| 59 |
+
- サークル付き(例:あ⃝ た⃝ し⃝ を⃝)
|
| 60 |
+
- 国旗文字装飾(例:🇫🇴🇱🇱🇴🇼)
|
| 61 |
+
- 数字や文字エンクロージング(例:あ⃣ た⃣ し⃣ を⃣ f⃣ o⃣ l⃣ l⃣ o⃣ w⃣)
|
| 62 |
+
- 二重打ち消し線、波線など複数のコンビニング文字の組み合わせ
|
| 63 |
+
- 縦書きスタイル(例:あ︎た︎し︎を︎f︎o︎l︎l︎o︎w︎)
|
| 64 |
+
|
| 65 |
+
必ず日本語部分と英語/記号部分の両方を適切に装飾してください。
|
| 66 |
+
日本語はそのままに、英語/記号部分(例:follow)だけを変換するスタイルも含めてください。
|
| 67 |
+
|
| 68 |
+
出力は必ず以下のJSON形式で返してください:
|
| 69 |
+
{
|
| 70 |
+
"styles": [
|
| 71 |
+
{"name": "スタイル名1", "text": "装飾されたテキスト1"},
|
| 72 |
+
{"name": "スタイル名2", "text": "装飾されたテキスト2"},
|
| 73 |
+
...
|
| 74 |
+
]
|
| 75 |
+
}
|
| 76 |
+
"""
|
| 77 |
|
| 78 |
try:
|
| 79 |
# Groq APIクライアントを初期化
|
|
|
|
| 112 |
Returns:
|
| 113 |
スタイルの辞書
|
| 114 |
"""
|
| 115 |
+
# 英数字部分の抽出
|
| 116 |
+
alphanum_parts = re.findall(r'[a-zA-Z0-9]+', text)
|
| 117 |
+
|
| 118 |
# 全角変換用の関数
|
| 119 |
def to_fullwidth(text):
|
| 120 |
result = ""
|
|
|
|
| 126 |
result += char
|
| 127 |
return result
|
| 128 |
|
| 129 |
+
# テキストの数字→装飾文字変換関数
|
| 130 |
+
def to_unicode_style(text, start_code, is_alpha_only=True):
|
| 131 |
+
result = ""
|
| 132 |
+
for char in text:
|
| 133 |
+
if 'a' <= char.lower() <= 'z':
|
| 134 |
+
# アルファベットをUnicode装飾フォントに変換
|
| 135 |
+
offset = ord(char.lower()) - ord('a')
|
| 136 |
+
result += chr(start_code + offset)
|
| 137 |
+
elif '0' <= char <= '9' and not is_alpha_only:
|
| 138 |
+
# 数字を変換(一部のスタイルのみ)
|
| 139 |
+
offset = ord(char) - ord('0')
|
| 140 |
+
result += chr(start_code + 26 + offset)
|
| 141 |
+
else:
|
| 142 |
+
# その他の文字はそのまま
|
| 143 |
+
result += char
|
| 144 |
+
return result
|
| 145 |
+
|
| 146 |
+
# 数学フォント(𝐚-𝐳)
|
| 147 |
+
def to_math_bold(text):
|
| 148 |
+
return to_unicode_style(text, 0x1D41A)
|
| 149 |
+
|
| 150 |
+
# フラクトゥール(𝔞-𝔷)
|
| 151 |
+
def to_fraktur(text):
|
| 152 |
+
return to_unicode_style(text, 0x1D51E)
|
| 153 |
+
|
| 154 |
+
# 太字フラクトゥール(𝖆-𝖟)
|
| 155 |
+
def to_bold_fraktur(text):
|
| 156 |
+
return to_unicode_style(text, 0x1D586)
|
| 157 |
+
|
| 158 |
+
# スクリプト(𝓪-𝔃)
|
| 159 |
+
def to_script(text):
|
| 160 |
+
return to_unicode_style(text, 0x1D4EA)
|
| 161 |
+
|
| 162 |
+
# 太字(𝗮-𝘇)
|
| 163 |
+
def to_bold(text):
|
| 164 |
+
return to_unicode_style(text, 0x1D5EE)
|
| 165 |
+
|
| 166 |
+
# イタリック(𝘢-𝘻)
|
| 167 |
+
def to_italic(text):
|
| 168 |
+
return to_unicode_style(text, 0x1D622)
|
| 169 |
+
|
| 170 |
+
# 太字イタリック(𝙖-𝙯)
|
| 171 |
+
def to_bold_italic(text):
|
| 172 |
+
return to_unicode_style(text, 0x1D656)
|
| 173 |
+
|
| 174 |
+
# サンセリフ(𝚊-𝚣)
|
| 175 |
+
def to_sans(text):
|
| 176 |
+
return to_unicode_style(text, 0x1D68A)
|
| 177 |
+
|
| 178 |
+
# 小型大文字
|
| 179 |
+
def to_small_caps(text):
|
| 180 |
+
result = ""
|
| 181 |
+
for char in text:
|
| 182 |
+
if 'a' <= char.lower() <= 'z':
|
| 183 |
+
if char.lower() in 'abcdefghijklmnopqrstuvwxyz':
|
| 184 |
+
small_caps_map = {
|
| 185 |
+
'a': 'ᴀ', 'b': 'ʙ', 'c': 'ᴄ', 'd': 'ᴅ', 'e': 'ᴇ', 'f': 'ꜰ',
|
| 186 |
+
'g': 'ɢ', 'h': 'ʜ', 'i': 'ɪ', 'j': 'ᴊ', 'k': 'ᴋ', 'l': 'ʟ',
|
| 187 |
+
'm': 'ᴍ', 'n': 'ɴ', 'o': 'ᴏ', 'p': 'ᴘ', 'q': 'ǫ', 'r': 'ʀ',
|
| 188 |
+
's': 's', 't': 'ᴛ', 'u': 'ᴜ', 'v': 'ᴠ', 'w': 'ᴡ', 'x': 'x',
|
| 189 |
+
'y': 'ʏ', 'z': 'ᴢ'
|
| 190 |
+
}
|
| 191 |
+
result += small_caps_map[char.lower()]
|
| 192 |
+
else:
|
| 193 |
+
result += char
|
| 194 |
+
else:
|
| 195 |
+
result += char
|
| 196 |
+
return result
|
| 197 |
+
|
| 198 |
+
# 元のテキストから英数字部分のみを装飾するヘルパー関数
|
| 199 |
+
def decorate_alphanum(text, decorator_func):
|
| 200 |
+
if not alphanum_parts:
|
| 201 |
+
return decorator_func(text)
|
| 202 |
+
|
| 203 |
+
result = text
|
| 204 |
+
for part in alphanum_parts:
|
| 205 |
+
decorated = decorator_func(part)
|
| 206 |
+
# 元のテキスト内の英数字部分を置換
|
| 207 |
+
result = result.replace(part, decorated, 1)
|
| 208 |
+
return result
|
| 209 |
+
|
| 210 |
+
# 様々な囲み文字
|
| 211 |
+
def surround_with(text, prefix, suffix=None):
|
| 212 |
+
if suffix is None:
|
| 213 |
+
suffix = prefix
|
| 214 |
+
return f"{prefix}{text}{suffix}"
|
| 215 |
+
|
| 216 |
+
def add_symbols_between(text, symbol):
|
| 217 |
+
return symbol.join(text)
|
| 218 |
+
|
| 219 |
+
# 様々な装飾文字生成
|
| 220 |
+
def decorate_with_emojis(text, prefix, suffix=None):
|
| 221 |
+
if suffix is None:
|
| 222 |
+
suffix = prefix
|
| 223 |
+
return f"{prefix} {text} {suffix}"
|
| 224 |
+
|
| 225 |
+
# テキストを反転する
|
| 226 |
+
def reverse_text(text):
|
| 227 |
+
# 文字反転マッピング
|
| 228 |
+
flip_map = {
|
| 229 |
+
'a': 'ɐ', 'b': 'q', 'c': 'ɔ', 'd': 'p', 'e': 'ǝ', 'f': 'ɟ', 'g': 'ƃ',
|
| 230 |
+
'h': 'ɥ', 'i': 'ᴉ', 'j': 'ɾ', 'k': 'ʞ', 'l': 'l', 'm': 'ɯ', 'n': 'u',
|
| 231 |
+
'o': 'o', 'p': 'd', 'q': 'b', 'r': 'ɹ', 's': 's', 't': 'ʇ', 'u': 'n',
|
| 232 |
+
'v': 'ʌ', 'w': 'ʍ', 'x': 'x', 'y': 'ʎ', 'z': 'z'
|
| 233 |
+
}
|
| 234 |
+
result = ""
|
| 235 |
+
for char in reversed(text):
|
| 236 |
+
if char.lower() in flip_map:
|
| 237 |
+
result += flip_map[char.lower()]
|
| 238 |
+
else:
|
| 239 |
+
result += char
|
| 240 |
+
return result
|
| 241 |
+
|
| 242 |
+
# グリッチ風テキスト生成
|
| 243 |
+
def create_glitch_text(text):
|
| 244 |
+
# ランダムなコンビニング文字を追加
|
| 245 |
+
import random
|
| 246 |
+
combining_marks = [
|
| 247 |
+
'\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305',
|
| 248 |
+
'\u0306', '\u0307', '\u0308', '\u0309', '\u030A', '\u030B',
|
| 249 |
+
'\u030C', '\u030D', '\u030E', '\u030F', '\u0310', '\u0311',
|
| 250 |
+
'\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317',
|
| 251 |
+
'\u0318', '\u0319', '\u031A', '\u031B', '\u031C', '\u031D',
|
| 252 |
+
'\u031E', '\u031F', '\u0320', '\u0321', '\u0322', '\u0323',
|
| 253 |
+
'\u0324', '\u0325', '\u0326', '\u0327', '\u0328', '\u0329',
|
| 254 |
+
'\u032A', '\u032B', '\u032C', '\u032D', '\u032E', '\u032F'
|
| 255 |
+
]
|
| 256 |
+
result = ""
|
| 257 |
+
for char in text:
|
| 258 |
+
result += char
|
| 259 |
+
# 各文字に1-3個のコンビニング文字をランダムに追加
|
| 260 |
+
marks_count = random.randint(1, 3)
|
| 261 |
+
for _ in range(marks_count):
|
| 262 |
+
result += random.choice(combining_marks)
|
| 263 |
+
return result
|
| 264 |
+
|
| 265 |
+
# 強めのグリッチ効果
|
| 266 |
+
def create_heavy_glitch_text(text):
|
| 267 |
+
import random
|
| 268 |
+
# より多くのコンビニング文字と線を追加
|
| 269 |
+
combining_marks = [
|
| 270 |
+
'\u0300', '\u0301', '\u0302', '\u0303', '\u0304', '\u0305',
|
| 271 |
+
'\u0306', '\u0307', '\u0308', '\u0309', '\u030A', '\u030B',
|
| 272 |
+
'\u030C', '\u030D', '\u030E', '\u030F', '\u0310', '\u0311',
|
| 273 |
+
'\u0312', '\u0313', '\u0314', '\u0315', '\u0316', '\u0317',
|
| 274 |
+
'\u0334', '\u0335', '\u0336', '\u0337', '\u0338', '\u0339',
|
| 275 |
+
'\u033A', '\u033B', '\u033C', '\u033D', '\u033E', '\u033F'
|
| 276 |
+
]
|
| 277 |
+
result = ""
|
| 278 |
+
for char in text:
|
| 279 |
+
result += char
|
| 280 |
+
# 各文字に3-5個のコンビニング文字をランダムに追加
|
| 281 |
+
marks_count = random.randint(3, 5)
|
| 282 |
+
for _ in range(marks_count):
|
| 283 |
+
result += random.choice(combining_marks)
|
| 284 |
+
return result
|
| 285 |
+
|
| 286 |
+
# ブロック付きテキスト (文字ごとに四角で囲む)
|
| 287 |
+
def create_square_enclosed_text(text):
|
| 288 |
+
result = ""
|
| 289 |
+
for char in text:
|
| 290 |
+
if char.strip(): # 空白文字でない場合
|
| 291 |
+
result += char + "\u20DE " # U+20DE COMBINING ENCLOSING SQUARE
|
| 292 |
+
else:
|
| 293 |
+
result += char + " "
|
| 294 |
+
return result
|
| 295 |
+
|
| 296 |
+
# サークル付きテキスト (文字ごとに丸で囲む)
|
| 297 |
+
def create_circle_enclosed_text(text):
|
| 298 |
+
result = ""
|
| 299 |
+
for char in text:
|
| 300 |
+
if char.strip(): # 空白文字でない場合
|
| 301 |
+
result += char + "\u20DD " # U+20DD COMBINING ENCLOSING CIRCLE
|
| 302 |
+
else:
|
| 303 |
+
result += char + " "
|
| 304 |
+
return result
|
| 305 |
+
|
| 306 |
+
# キーキャップ付きテキスト(数字やアルファベットに四角)
|
| 307 |
+
def create_keycap_text(text):
|
| 308 |
+
result = ""
|
| 309 |
+
for char in text:
|
| 310 |
+
# 数字または英字の場合
|
| 311 |
+
if char.isalnum():
|
| 312 |
+
result += char + "\u20E3 " # U+20E3 COMBINING ENCLOSING KEYCAP
|
| 313 |
+
else:
|
| 314 |
+
result += char + " "
|
| 315 |
+
return result
|
| 316 |
+
|
| 317 |
+
# 地域インジケーター文字装飾(アルファベットを国旗風に)
|
| 318 |
+
def create_regional_indicator_text(text):
|
| 319 |
+
result = ""
|
| 320 |
+
for char in text.lower():
|
| 321 |
+
if 'a' <= char <= 'z':
|
| 322 |
+
# 地域インジケーター文字 (🇦 🇧 🇨など)
|
| 323 |
+
regional_indicator = chr(0x1F1E6 + ord(char) - ord('a'))
|
| 324 |
+
result += regional_indicator + "\u200B" # ゼロ幅スペースで区切る
|
| 325 |
+
else:
|
| 326 |
+
result += char
|
| 327 |
+
return result
|
| 328 |
+
|
| 329 |
+
# 複数のコンビニング文字スタイル
|
| 330 |
+
def text_with_multiple_combining(text):
|
| 331 |
+
# 下線と上線の両方を適用
|
| 332 |
+
result = ""
|
| 333 |
+
for char in text:
|
| 334 |
+
if char.strip():
|
| 335 |
+
# 下線 + 上線 + 打ち消し線
|
| 336 |
+
result += char + "\u0332\u0305\u0336"
|
| 337 |
+
else:
|
| 338 |
+
result += char
|
| 339 |
+
return result
|
| 340 |
+
|
| 341 |
+
# 縦書きスタイルのテキスト
|
| 342 |
+
def create_vertical_text(text):
|
| 343 |
+
result = ""
|
| 344 |
+
for char in text:
|
| 345 |
+
if char.strip():
|
| 346 |
+
result += char + "\uFE0E " # U+FE0E VARIATION SELECTOR-15 (テキスト表示)
|
| 347 |
+
else:
|
| 348 |
+
result += char + " "
|
| 349 |
+
return result
|
| 350 |
+
|
| 351 |
# 事前定義したスタイル
|
| 352 |
fallback_styles = {
|
| 353 |
"styles": [
|
| 354 |
+
{"name": "数学体", "text": decorate_alphanum(text, to_math_bold)},
|
| 355 |
+
{"name": "フラクトゥール", "text": decorate_alphanum(text, to_fraktur)},
|
| 356 |
+
{"name": "太字フラクトゥール", "text": decorate_alphanum(text, to_bold_fraktur)},
|
| 357 |
+
{"name": "スクリプト体", "text": decorate_alphanum(text, to_script)},
|
| 358 |
+
{"name": "太字", "text": decorate_alphanum(text, to_bold)},
|
| 359 |
+
{"name": "イタリック", "text": decorate_alphanum(text, to_italic)},
|
| 360 |
+
{"name": "太字イタリック", "text": decorate_alphanum(text, to_bold_italic)},
|
| 361 |
+
{"name": "サンセリフ", "text": decorate_alphanum(text, to_sans)},
|
| 362 |
+
{"name": "小型大文字", "text": decorate_alphanum(text, to_small_caps)},
|
| 363 |
+
{"name": "全角変換", "text": to_fullwidth(text)},
|
| 364 |
{"name": "シンプル星", "text": f"★ {text} ★"},
|
| 365 |
{"name": "波線", "text": f"〜{text}〜"},
|
| 366 |
{"name": "ドット", "text": f"・{text}・"},
|
|
|
|
| 371 |
{"name": "矢印", "text": f"→{text}←"},
|
| 372 |
{"name": "四角", "text": f"■{text}■"},
|
| 373 |
{"name": "丸", "text": f"●{text}●"},
|
|
|
|
|
|
|
|
|
|
| 374 |
{"name": "キラキラ", "text": f"✨{text}✨"},
|
| 375 |
{"name": "シンプル装飾", "text": f"▶ {text} ◀"},
|
| 376 |
{"name": "花装飾", "text": f"❀ {text} ❀"},
|
| 377 |
{"name": "音符", "text": f"♪ {text} ♪"},
|
| 378 |
{"name": "サンダーマーク", "text": f"⚡ {text} ⚡"},
|
| 379 |
{"name": "ハートフレーム", "text": f"❤️ {text} ❤️"},
|
|
|
|
| 380 |
{"name": "丸括弧", "text": f"({text})"},
|
| 381 |
{"name": "角括弧", "text": f"[{text}]"},
|
| 382 |
{"name": "波括弧", "text": f"{{{text}}}"},
|
|
|
|
| 386 |
{"name": "二重鉤括弧", "text": f"『{text}』"},
|
| 387 |
{"name": "下線", "text": f"_{text}_"},
|
| 388 |
{"name": "スパークル", "text": f"*:・゚{text}*:・゚"},
|
| 389 |
+
{"name": "チェック", "text": f"✓ {text} ✓"},
|
| 390 |
+
{"name": "囲み文字", "text": ''.join([f"【{c}】" for c in text])},
|
| 391 |
+
{"name": "ドット区切り", "text": '•'.join(text)},
|
| 392 |
+
{"name": "ハート区切り", "text": '♥'.join(text)},
|
| 393 |
+
{"name": "星区切り", "text": '★'.join(text)},
|
| 394 |
+
{"name": "花区切り", "text": '✿'.join(text)},
|
| 395 |
+
{"name": "虹装飾", "text": f"🌈 {text} 🌈"},
|
| 396 |
+
{"name": "キラキラハート", "text": f"💖 {text} 💖"},
|
| 397 |
+
{"name": "クラウン", "text": f"👑 {text} 👑"},
|
| 398 |
+
{"name": "バブル", "text": f"🫧 {text} 🫧"},
|
| 399 |
+
{"name": "かわいい花", "text": f"🌸 {text} 🌸"},
|
| 400 |
+
{"name": "リボン装飾", "text": f"🎀 {text} 🎀"},
|
| 401 |
+
{"name": "クラシック", "text": f"『 {text} 』"},
|
| 402 |
+
{"name": "ピース", "text": f"✌️ {text} ✌️"},
|
| 403 |
+
{"name": "レインボー", "text": f"🌈✨ {text} ✨🌈"},
|
| 404 |
+
# 追加のコンビニング文字スタイル
|
| 405 |
+
{"name": "グリッチ風", "text": create_glitch_text(text)},
|
| 406 |
+
{"name": "激しいグリッチ", "text": create_heavy_glitch_text(text)},
|
| 407 |
+
{"name": "四角囲み", "text": create_square_enclosed_text(text)},
|
| 408 |
+
{"name": "丸囲み", "text": create_circle_enclosed_text(text)},
|
| 409 |
+
{"name": "キーキャップ", "text": create_keycap_text(text)},
|
| 410 |
+
{"name": "リージョナルインジケーター", "text": create_regional_indicator_text(text)},
|
| 411 |
+
{"name": "多重装飾", "text": text_with_multiple_combining(text)},
|
| 412 |
+
{"name": "テキスト反転", "text": reverse_text(text)},
|
| 413 |
+
{"name": "縦書きスタイル", "text": create_vertical_text(text)},
|
| 414 |
]
|
| 415 |
}
|
| 416 |
return fallback_styles
|