Spaces:
Running
Running
Add collapsible emoji picker
Browse files- index.html +60 -24
index.html
CHANGED
|
@@ -50,6 +50,11 @@ input,select{accent-color:var(--button)} input[type=range]{margin:3px 0;width:10
|
|
| 50 |
.primary{background:var(--button);color:var(--on);border-color:var(--button);padding:8px 16px}
|
| 51 |
button:disabled{opacity:.45;cursor:default} textarea{resize:vertical;min-height:118px;font:14px/1.6 "Segoe UI",Meiryo,sans-serif}
|
| 52 |
#notice{font-size:13px}.symbols{gap:5px}.symbols button{min-width:34px;padding:3px 6px;font-size:17px}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
.pal{gap:6px}.pal button{width:26px;height:26px;padding:0;border:1px solid #8888;border-radius:50%;background:var(--sample)}
|
| 54 |
.pal button[aria-pressed=true]{outline:2px solid var(--accent);outline-offset:2px}
|
| 55 |
.color-slot{display:flex;align-items:center;gap:8px}
|
|
@@ -95,10 +100,12 @@ input[type=color]{width:39px;height:32px;border:1px solid var(--line);border-rad
|
|
| 95 |
<div id="palette" class="pal full" role="group" aria-label="色見本"></div>
|
| 96 |
<label class="check full"><input type="checkbox" id="linked" checked>ルビは親文字と同じ色</label>
|
| 97 |
</div></fieldset>
|
| 98 |
-
<details><summary>記号・絵文字</summary><div class="fields">
|
| 99 |
<label>挿入先<select id="symbolTarget"><option value="base">親文字の中</option><option value="reading">ルビの中</option><option value="ornament">右側の飾り</option></select></label>
|
| 100 |
<label>右側の飾り<input type="text" id="ornament" placeholder="例:🔥"></label>
|
| 101 |
-
<div class="symbols full" id="symbols"></div>
|
|
|
|
|
|
|
| 102 |
</section>
|
| 103 |
<section class="results" aria-label="確認とコピー">
|
| 104 |
<div class="bar"><h2>組版プレビュー</h2><div class="tools"><label>確認用の背景<select id="paper"><option value="#ffffff">白</option><option value="#262626">墨色</option></select></label></div></div>
|
|
@@ -297,7 +304,7 @@ document.addEventListener("keydown", e => {
|
|
| 297 |
if (e.key==="Enter" && e.target===readingInput) { e.preventDefault(); applyReading(); }
|
| 298 |
});
|
| 299 |
document.addEventListener("pointerdown", e => {
|
| 300 |
-
if (!rubyBox.contains(e.target) && !editor.contains(e.target) && !e.target.closest("#
|
| 301 |
});
|
| 302 |
window.addEventListener("scroll", e => {
|
| 303 |
if (e.target===document || e.target.contains?.(editor)) positionBox();
|
|
@@ -589,27 +596,56 @@ for (const [hex,label] of palette){
|
|
| 589 |
const b=document.createElement("button"); b.type="button"; b.title=label; b.setAttribute("aria-label",label); b.dataset.hex=hex;
|
| 590 |
b.style.setProperty("--sample",hex); b.onclick=()=>editColor(hex); el("palette").append(b);
|
| 591 |
}
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
el("
|
| 612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
function update(){
|
| 614 |
const s=settings(), format=el("format").value, useLayout=format==="layout";
|
| 615 |
const w=useLayout ? el("width").valueAsNumber : canvas.clientWidth, h=useLayout ? el("height").valueAsNumber : canvas.clientHeight;
|
|
|
|
| 50 |
.primary{background:var(--button);color:var(--on);border-color:var(--button);padding:8px 16px}
|
| 51 |
button:disabled{opacity:.45;cursor:default} textarea{resize:vertical;min-height:118px;font:14px/1.6 "Segoe UI",Meiryo,sans-serif}
|
| 52 |
#notice{font-size:13px}.symbols{gap:5px}.symbols button{min-width:34px;padding:3px 6px;font-size:17px}
|
| 53 |
+
#emojiList{margin:0;padding:0;border:0}
|
| 54 |
+
#emojiList summary{width:fit-content;cursor:pointer;font-size:14px}
|
| 55 |
+
#emojiList h3{margin:12px 0 5px;font-size:13px;color:var(--sub)}
|
| 56 |
+
#emojiList .symbols{display:grid;grid-template-columns:repeat(auto-fill,minmax(34px,1fr))}
|
| 57 |
+
#emojiList button{padding:3px 0}
|
| 58 |
.pal{gap:6px}.pal button{width:26px;height:26px;padding:0;border:1px solid #8888;border-radius:50%;background:var(--sample)}
|
| 59 |
.pal button[aria-pressed=true]{outline:2px solid var(--accent);outline-offset:2px}
|
| 60 |
.color-slot{display:flex;align-items:center;gap:8px}
|
|
|
|
| 100 |
<div id="palette" class="pal full" role="group" aria-label="色見本"></div>
|
| 101 |
<label class="check full"><input type="checkbox" id="linked" checked>ルビは親文字と同じ色</label>
|
| 102 |
</div></fieldset>
|
| 103 |
+
<details id="symbolPicker"><summary>記号・絵文字</summary><div class="fields">
|
| 104 |
<label>挿入先<select id="symbolTarget"><option value="base">親文字の中</option><option value="reading">ルビの中</option><option value="ornament">右側の飾り</option></select></label>
|
| 105 |
<label>右側の飾り<input type="text" id="ornament" placeholder="例:🔥"></label>
|
| 106 |
+
<div class="symbols full" id="symbols"></div>
|
| 107 |
+
<details class="full" id="emojiList"><summary>絵文字一覧</summary><div id="emojiGroups"></div></details>
|
| 108 |
+
</div></details>
|
| 109 |
</section>
|
| 110 |
<section class="results" aria-label="確認とコピー">
|
| 111 |
<div class="bar"><h2>組版プレビュー</h2><div class="tools"><label>確認用の背景<select id="paper"><option value="#ffffff">白</option><option value="#262626">墨色</option></select></label></div></div>
|
|
|
|
| 304 |
if (e.key==="Enter" && e.target===readingInput) { e.preventDefault(); applyReading(); }
|
| 305 |
});
|
| 306 |
document.addEventListener("pointerdown", e => {
|
| 307 |
+
if (!rubyBox.contains(e.target) && !editor.contains(e.target) && !e.target.closest("#symbolPicker")) closeEditor();
|
| 308 |
});
|
| 309 |
window.addEventListener("scroll", e => {
|
| 310 |
if (e.target===document || e.target.contains?.(editor)) positionBox();
|
|
|
|
| 596 |
const b=document.createElement("button"); b.type="button"; b.title=label; b.setAttribute("aria-label",label); b.dataset.hex=hex;
|
| 597 |
b.style.setProperty("--sample",hex); b.onclick=()=>editColor(hex); el("palette").append(b);
|
| 598 |
}
|
| 599 |
+
const emojiCategories = [
|
| 600 |
+
["顔・気持ち","😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 🥰 😘 😋 😜 🤪 🤭 🤫 🤔 🫡 🤐 😐 😏 😒 🙄 😳 🥺 😢 😭 😤 😡 🤯 😱 😴 🥳 😎 🤓 😈 👻 🤖 👽 💀 😺 😻"],
|
| 601 |
+
["手・人","👋 🤚 🖐️ ✋ 🖖 👌 🤌 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 👇 ☝️ 👍 👎 ✊ 👊 👏 🙌 🫶 👐 🤝 🙏 ✍️ 💪 👀 🧑🎨 🧑🚀 🥷 🧙 🧚 🧜♀️ 💃 🕺"],
|
| 602 |
+
["ハート・効果","❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 🩷 🩵 🩶 💔 ❤️🔥 ❤️🩹 ❣️ 💕 💞 💓 💗 💖 💘 💝 💟 💋 💯 💢 💥 💫 💦 💨 💬 💭 ✨ 🌟 ⭐ 🔥 🎉 🎊"],
|
| 603 |
+
["動物","🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐨 🐯 🦁 🐮 🐷 🐸 🐵 🐔 🐧 🐦 🐤 🦆 🦉 🦄 🐝 🦋 🐞 🐢 🐍 🐙 🦑 🐠 🐬 🐳 🦈 🦭 🐘 🦒 🦔 🐾 🐉"],
|
| 604 |
+
["花・自然・天気","🌸 🌷 🌹 🥀 🌺 🌻 �� 🪻 🪷 💐 🍀 🌱 🌿 🍃 🍁 🍂 🌾 🌵 🌴 🌲 🍄 🪨 🌍 🌙 🌕 🌛 ☀️ 🌤️ ☁️ 🌧️ ⛈️ 🌩️ ❄️ ☃️ 🌈 ☄️ 🌊 💧 🫧"],
|
| 605 |
+
["食べ物・飲み物","🍎 🍊 🍋 🍌 🍉 🍇 🍓 🍒 🍑 🥝 🍅 🌽 🍞 🥐 🥞 🍔 🍟 🍕 🍝 🍛 🍜 🍣 🍙 🍱 🍤 🍡 🍥 🍦 🍩 🍪 🎂 🍰 🧁 🍫 🍬 🍭 ☕ 🍵 🧋 🥤 🍹 🥂"],
|
| 606 |
+
["音楽・遊び・行事","🎵 🎶 🎼 🎤 🎧 🎹 🥁 🎷 🎺 🎸 🎻 🪈 🎨 🖌️ 🎭 🎬 🎥 📷 📚 🖋️ 🎮 🎲 🧩 ♟️ 🧸 🎁 🎈 🎀 🎆 🎇 🎐 🎏 🎎 🎑 🎃 🎄 🏆 🥇 ⚽ ⚾ 🏀 🎾"],
|
| 607 |
+
["場所・乗り物・道具","🏠 🏯 🏰 ⛩️ 🗼 🗻 🏝️ 🏕️ 🎡 🎢 🌃 🚗 🚕 🚌 🚲 🚃 🚄 🚢 ✈️ 🚁 🚀 🛸 ⚓ 🧳 🗺️ 🧭 ⏰ ⌛ 💡 🔦 🕯️ 🔮 💎 👑 🗝️ 🔑 🔔 📌 ✉️ 📣"],
|
| 608 |
+
["記号・矢印","⬅️ ➡️ ⬆️ ⬇️ ↗️ ↘️ ↙️ ↖️ ↔️ ↕️ 🔄 ▶️ ⏸️ ⏩ ⏪ ➕ ➖ ✖️ ➗ ♾️ ✔️ ✅ ❌ ⭕ ❗ ❓ ⁉️ ⚠️ ⛔ 🚫 🔴 🟠 🟡 🟢 🔵 🟣 ⚫ ⚪ 🔷 🔶 🔺 🔻 🏁 🚩"]
|
| 609 |
+
];
|
| 610 |
+
function symbolButton(symbol) {
|
| 611 |
+
const b=document.createElement("button");
|
| 612 |
+
b.type="button"; b.textContent=symbol; b.setAttribute("aria-label",symbol+"を挿入");
|
| 613 |
+
return b;
|
| 614 |
+
}
|
| 615 |
+
el("symbols").append(...Object.keys(symbolNames).map(symbolButton));
|
| 616 |
+
el("emojiList").addEventListener("toggle", () => {
|
| 617 |
+
const groups=el("emojiGroups");
|
| 618 |
+
if (!el("emojiList").open || groups.childElementCount) return;
|
| 619 |
+
for (const [name, symbols] of emojiCategories) {
|
| 620 |
+
const heading=document.createElement("h3"), grid=document.createElement("div");
|
| 621 |
+
heading.textContent=name; grid.className="symbols";
|
| 622 |
+
grid.append(...symbols.split(" ").map(symbolButton));
|
| 623 |
+
groups.append(heading,grid);
|
| 624 |
+
}
|
| 625 |
+
});
|
| 626 |
+
const picker=el("symbolPicker");
|
| 627 |
+
picker.addEventListener("mousedown", e => {
|
| 628 |
+
if (e.target.closest(".symbols button")) e.preventDefault();
|
| 629 |
+
});
|
| 630 |
+
picker.addEventListener("click", e => {
|
| 631 |
+
const button=e.target.closest(".symbols button");
|
| 632 |
+
if (!button) return;
|
| 633 |
+
const symbol=button.textContent, target=el("symbolTarget").value;
|
| 634 |
+
if(target==="base"){
|
| 635 |
+
const range=editorRange() || lastCaret || document.createRange();
|
| 636 |
+
if(!editor.contains(range.commonAncestorContainer)){range.selectNodeContents(editor);range.collapse(false);}
|
| 637 |
+
closeEditor(); selectRange(range); insertPlain(symbol);
|
| 638 |
+
lastCaret=editorRange();
|
| 639 |
+
return;
|
| 640 |
+
}
|
| 641 |
+
if(target==="reading" && !editing){
|
| 642 |
+
editor.focus(); el("notice").textContent="先に本文の文字を選択してください。"; return;
|
| 643 |
+
}
|
| 644 |
+
const input=el(target);
|
| 645 |
+
input.setRangeText(symbol,input.selectionStart,input.selectionEnd,"end");
|
| 646 |
+
input.focus({preventScroll:true});
|
| 647 |
+
input.dispatchEvent(new Event("input",{bubbles:true}));
|
| 648 |
+
});
|
| 649 |
function update(){
|
| 650 |
const s=settings(), format=el("format").value, useLayout=format==="layout";
|
| 651 |
const w=useLayout ? el("width").valueAsNumber : canvas.clientWidth, h=useLayout ? el("height").valueAsNumber : canvas.clientHeight;
|