promptbuilder7.md
Oct 17, 2026, 11:58 PM 16.0 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Modular Prompt Builder</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: #1a1a1a; color: #e0e0e0; padding: 20px; }
header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 14px; border-bottom: 1px solid #444; margin-bottom: 18px; }
h1 { margin: 0; font-size: 18px; color: #c9a86a; }
.sub { color: #888; font-size: 12px; }
.container { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; max-width: 1400px; align-items: start; }
@media (max-width: 860px) { .container { grid-template-columns: 1fr; } }
.panel { background: #232323; border: 1px solid #3d3d3d; border-radius: 8px; padding: 14px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 10px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #c9a86a; }
label { display: block; font-size: 11px; color: #999; margin: 9px 0 3px 0; }
input, textarea { width: 100%; background: #161616; color: #e8e8e8; border: 1px solid #444; border-radius: 5px; padding: 7px 8px; font-size: 13px; font-family: inherit; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus { outline: 2px solid #c9a86a; border-color: #c9a86a; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.buttons { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
button { background: #3a3a3a; color: #eee; border: 1px solid #555; border-radius: 5px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
button:hover { border-color: #c9a86a; }
button.primary { background: #c9a86a; color: #1a1a1a; border-color: #c9a86a; font-weight: bold; }
button.danger { background: #4a2a2a; border-color: #7a4444; }
button.tiny { padding: 3px 8px; font-size: 11px; }
#out { min-height: 420px; max-height: 70vh; overflow-y: auto; background: #141414; border: 1px solid #444; border-radius: 6px; padding: 10px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
#out:empty::before { content: 'Your assembled prompt appears here…'; color: #555; }
.counter { display: flex; justify-content: space-between; font-size: 12px; margin: 6px 0; padding: 6px 10px; background: #161616; border: 1px solid #3d3d3d; border-radius: 5px; }
.counter .num { font-weight: bold; font-variant-numeric: tabular-nums; }
.counter.ok .num { color: #7fd4a1; }
.counter.warn .num { color: #e0c060; }
.counter.over .num { color: #d47a7a; }
.counter.over { border-color: #7a4444; }
.bar { height: 4px; background: #333; border-radius: 2px; margin: 4px 0 10px 0; overflow: hidden; }
.bar > div { height: 100%; background: #7fd4a1; transition: width .15s; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #c9a86a; color: #1a1a1a; padding: 8px 16px; border-radius: 6px; font-weight: bold; font-size: 13px; display: none; z-index: 100; }
.hint { font-size: 11px; color: #666; margin-top: 6px; }
.libbar { display: flex; gap: 5px; margin-bottom: 3px; align-items: center; }
.libbar select { flex: 1; background: #1c1c1c; border: 1px solid #3a3a3a; color: #bbb; font-size: 11px; padding: 3px 6px; border-radius: 4px; }
.libbar select:focus { outline: 1px solid #c9a86a; }
</style>
</head>
<body>
<header>
<div>
<h1>Modular Prompt Builder</h1>
<div class="sub">Save & reuse each module from its dropdown</div>
</div>
<div>
<button class="tiny" id="expBtn" type="button">Export All</button>
<button class="tiny" id="impBtn" type="button">Import All</button>
</div>
</header>
<div class="toast" id="toast">Copied!</div>
<div class="container">
<div class="left">
<div class="panel">
<h2>Lock Blocks</h2>
<label>Identity Lock</label>
<textarea id="fIdentity" rows="4" placeholder="your identity lock text…"></textarea>
<label>Core Likeness Lock</label>
<textarea id="fCore" rows="2" placeholder="your core likeness text…"></textarea>
<label>Reference / Clothing Lock</label>
<textarea id="fReference" rows="3" placeholder="your reference retention text…"></textarea>
<label>Realism Lock</label>
<textarea id="fRealism" rows="3" placeholder="your realism text…"></textarea>
</div>
<div class="panel">
<h2>Subject</h2>
<div class="row">
<div><label>Costume / Outfit</label><input id="fCostume" placeholder="outfit…"></div>
<div><label>Pose</label><input id="fPose" placeholder="pose…"></div>
</div>
<div class="row">
<div><label>Body</label><input id="fBody" placeholder="body / bust…"></div>
<div><label>Expression</label><input id="fExpression" placeholder="expression…"></div>
</div>
<div class="row">
<div><label>Hair</label><input id="fHair" placeholder="hair…"></div>
<div><label>Toy / Prop</label><input id="fToy" placeholder="toy / prop…"></div>
</div>
<label>Extra Details</label>
<input id="fExtras" placeholder="extra details…">
</div>
<div class="panel">
<h2>Scene & Technical</h2>
<div class="row">
<div><label>Scene</label><input id="fScene" placeholder="scene…"></div>
<div><label>Style / Mood</label><input id="fStyle" placeholder="style…"></div>
</div>
<div class="row">
<div><label>Camera / Lens</label><input id="fCamera" placeholder="camera…"></div>
<div><label>Lighting</label><input id="fLighting" placeholder="lighting…"></div>
</div>
</div>
<div class="panel">
<h2>Output Blocks</h2>
<label>Enhancement</label>
<textarea id="fEnhance" rows="3" placeholder="enhancement text…"></textarea>
<label>Ending</label>
<textarea id="fEnding" rows="2" placeholder="ending text…"></textarea>
<label>Settings</label>
<textarea id="fSettings" rows="1" placeholder="denoise / sampler settings…"></textarea>
<label>Negative</label>
<textarea id="fNegative" rows="2" placeholder="negative prompt…"></textarea>
</div>
<div class="buttons">
<button class="danger" id="clearBtn" type="button">Clear All Fields</button>
</div>
</div>
<div class="right">
<div class="panel">
<h2>Assembled Prompt</h2>
<div class="counter" id="counter"><span>Characters</span><span class="num" id="charNum">0 / 2500</span></div>
<div class="bar"><div id="barFill" style="width:0%"></div></div>
<div id="out" contenteditable="true" spellcheck="false"></div>
<div class="buttons">
<button class="primary" id="copyBtn" type="button">Copy</button>
<button id="saveBtn" type="button">Save .txt</button>
<button id="fitBtn" type="button">Trim to 2500</button>
</div>
<div class="hint">Blank fields are skipped. Use each field's dropdown to load a saved snippet.</div>
</div>
</div>
</div>
<script>
"use strict";
const LIMIT = 2500;
const FIELDS = [
{ id: 'fIdentity', kind: 'block' },
{ id: 'fCore', kind: 'block' },
{ id: 'fReference', kind: 'block' },
{ id: 'fRealism', kind: 'block' },
{ id: 'fCostume', kind: 'group', group: 'subject' },
{ id: 'fPose', kind: 'group', group: 'subject' },
{ id: 'fBody', kind: 'group', group: 'subject' },
{ id: 'fExpression', kind: 'group', group: 'subject' },
{ id: 'fHair', kind: 'group', group: 'subject' },
{ id: 'fToy', kind: 'group', group: 'subject' },
{ id: 'fExtras', kind: 'group', group: 'subject' },
{ id: 'fScene', kind: 'group', group: 'scene' },
{ id: 'fStyle', kind: 'group', group: 'scene' },
{ id: 'fCamera', kind: 'group', group: 'scene' },
{ id: 'fLighting', kind: 'group', group: 'scene' },
{ id: 'fEnhance', kind: 'block' },
{ id: 'fEnding', kind: 'block' },
{ id: 'fSettings', kind: 'block' },
{ id: 'fNegative', kind: 'block' }
];
function $(id) { return document.getElementById(id); }
function val(id) { var el = $(id); return el ? el.value.trim() : ''; }
/* ---------- library storage ---------- */
function libKey(fieldId) { return 'mpb_lib_' + fieldId; }
function libLoad(fieldId) {
try { return JSON.parse(localStorage.getItem(libKey(fieldId)) || '[]'); } catch (e) { return []; }
}
function libStore(fieldId, arr) {
try { localStorage.setItem(libKey(fieldId), JSON.stringify(arr)); } catch (e) {}
}
/* ---------- build library bars ---------- */
FIELDS.forEach(function (f) {
var el = $(f.id); if (!el) return;
var bar = document.createElement('div');
bar.className = 'libbar';
var sel = document.createElement('select');
sel.id = 'lib_' + f.id;
var saveB = document.createElement('button');
saveB.type = 'button'; saveB.className = 'tiny'; saveB.textContent = 'Save';
saveB.title = 'Save current text as a named snippet';
var delB = document.createElement('button');
delB.type = 'button'; delB.className = 'tiny danger'; delB.textContent = '×';
delB.title = 'Delete selected snippet';
bar.appendChild(sel); bar.appendChild(saveB); bar.appendChild(delB);
el.parentNode.insertBefore(bar, el);
sel.addEventListener('change', function () { libPick(f.id); });
saveB.addEventListener('click', function () { libSaveCurrent(f.id); });
delB.addEventListener('click', function () { libDelete(f.id); });
refreshLib(f.id);
});
function refreshLib(fieldId) {
var sel = $('lib_' + fieldId); if (!sel) return;
var arr = libLoad(fieldId);
sel.innerHTML = '';
var ph = document.createElement('option');
ph.value = '';
ph.textContent = arr.length ? '— ' + arr.length + ' saved —' : '— saved —';
sel.appendChild(ph);
arr.forEach(function (e) {
var o = document.createElement('option');
o.value = e.name; o.textContent = e.name;
sel.appendChild(o);
});
}
function libPick(fieldId) {
var sel = $('lib_' + fieldId); if (!sel || !sel.value) return;
var arr = libLoad(fieldId);
var found = arr.filter(function (e) { return e.name === sel.value; })[0];
if (found) { $(fieldId).value = found.text; save(); build(); }
}
function libSaveCurrent(fieldId) {
var text = val(fieldId);
if (!text) { toast('Field is empty'); return; }
var def = text.replace(/\s+/g, ' ').slice(0, 40);
var name = prompt('Save this snippet as:', def);
if (!name) return;
name = name.trim(); if (!name) return;
var arr = libLoad(fieldId);
var idx = -1;
for (var i = 0; i < arr.length; i++) if (arr[i].name === name) { idx = i; break; }
if (idx >= 0) arr[idx].text = text; else arr.push({ name: name, text: text });
libStore(fieldId, arr);
refreshLib(fieldId);
$('lib_' + fieldId).value = name;
toast(idx >= 0 ? 'Updated' : 'Saved');
}
function libDelete(fieldId) {
var sel = $('lib_' + fieldId); if (!sel || !sel.value) { toast('Nothing selected'); return; }
var arr = libLoad(fieldId).filter(function (e) { return e.name !== sel.value; });
libStore(fieldId, arr);
refreshLib(fieldId);
toast('Deleted');
}
/* ---------- assembly ---------- */
function build() {
var subject = [], scene = [], blocks = [];
FIELDS.forEach(function (f) {
var v = val(f.id); if (!v) return;
if (f.kind === 'block') blocks.push(v);
else if (f.group === 'subject') subject.push(v);
else scene.push(v);
});
var paras = blocks.slice();
if (subject.length) paras.splice(Math.min(4, paras.length), 0, subject.join(', ') + '.');
if (scene.length) paras.splice(Math.min(5, paras.length), 0, scene.join(', ') + '.');
$('out').innerText = paras.join('\n\n');
updateCounter();
}
function updateCounter() {
var n = ($('out').innerText || '').length;
$('charNum').textContent = n + ' / ' + LIMIT;
var c = $('counter'), bar = $('barFill');
c.classList.remove('ok', 'warn', 'over');
bar.style.width = Math.min(100, (n / LIMIT) * 100) + '%';
if (n > LIMIT) { c.classList.add('over'); bar.style.background = '#d47a7a'; }
else if (n > LIMIT * 0.9) { c.classList.add('warn'); bar.style.background = '#e0c060'; }
else { c.classList.add('ok'); bar.style.background = '#7fd4a1'; }
}
/* ---------- working state ---------- */
function save() {
var data = {};
FIELDS.forEach(function (f) { data[f.id] = val(f.id); });
try { localStorage.setItem('mpb_fields', JSON.stringify(data)); } catch (e) {}
}
function load() {
var data = {};
try { data = JSON.parse(localStorage.getItem('mpb_fields') || '{}'); } catch (e) {}
FIELDS.forEach(function (f) { if (data[f.id] && $(f.id)) $(f.id).value = data[f.id]; });
}
function clearAll() {
FIELDS.forEach(function (f) { if ($(f.id)) $(f.id).value = ''; });
save(); build();
}
function trimToLimit() {
build();
if (($('out').innerText || '').length <= LIMIT) { toast('Already fits'); return; }
var order = ['fSettings', 'fEnding', 'fEnhance', 'fReference', 'fCore'];
var i = 0;
while (($('out').innerText || '').length > LIMIT && i < order.length) {
var el = $(order[i]);
if (el && el.value.trim()) { el.value = ''; build(); }
i++;
}
save();
toast(($('out').innerText || '').length <= LIMIT ? 'Trimmed to fit' : 'Trimmed what it could');
}
/* ---------- export / import all libraries ---------- */
function exportAll() {
var all = { fields: {}, libs: {} };
FIELDS.forEach(function (f) { all.fields[f.id] = val(f.id); all.libs[f.id] = libLoad(f.id); });
var json = JSON.stringify(all, null, 2);
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(json).then(function () { toast('All copied to clipboard'); }, function () { prompt('Copy this:', json); });
} else prompt('Copy this:', json);
}
function importAll() {
var json = prompt('Paste exported JSON:');
if (!json) return;
try {
var all = JSON.parse(json);
if (all.libs) for (var k in all.libs) { libStore(k, all.libs[k]); refreshLib(k); }
if (all.fields) for (var f in all.fields) if ($(f)) $(f).value = all.fields[f];
save(); build(); toast('Imported');
} catch (e) { alert('Invalid JSON'); }
}
/* ---------- copy / save ---------- */
function copyText() {
var text = $('out').innerText;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(function () { toast('Copied!'); }, function () { fb(text); });
} else fb(text);
}
function fb(text) {
var ta = document.createElement('textarea'); ta.value = text; document.body.appendChild(ta); ta.select();
try { document.execCommand('copy'); } catch (e) {}
document.body.removeChild(ta); toast('Copied!');
}
function saveTxt() {
var text = $('out').innerText; if (!text) return;
var b = new Blob([text], { type: 'text/plain' });
var u = URL.createObjectURL(b);
var a = document.createElement('a'); a.href = u; a.download = 'prompt.txt'; a.click();
URL.revokeObjectURL(u);
}
function toast(m) { var t = $('toast'); t.textContent = m; t.style.display = 'block'; setTimeout(function () { t.style.display = 'none'; }, 1600); }
/* ---------- wiring ---------- */
FIELDS.forEach(function (f) {
var el = $(f.id);
if (el) el.addEventListener('input', function () { save(); build(); });
});
$('copyBtn').addEventListener('click', copyText);
$('saveBtn').addEventListener('click', saveTxt);
$('clearBtn').addEventListener('click', clearAll);
$('fitBtn').addEventListener('click', trimToLimit);
$('expBtn').addEventListener('click', exportAll);
$('impBtn').addEventListener('click', importAll);
$('out').addEventListener('input', updateCounter);
load();
build();
</script>
</body>
</html>