domma-cms 1.50.0 → 1.51.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.51.1] - 2026-11-10
4
+
5
+ - Save photo crops drawn directly on the image, and keep the crop toolbar toggle in sync with the selection. Previously these crops were silently ignored unless the toolbar had been used first.
6
+
7
+ ## [1.51.0] - 2026-11-10
8
+
9
+ - Dot and Daisy character packs are available to Site Builder and Tool Builder. Each tool can save its artwork choice through an authenticated, permission-checked character API. Site Settings controls builder visibility and the individual character choices, alongside animation and reduced motion.
10
+
11
+ - Chat launchers can opt into Della with **Use Della**, adding her portrait and activity poses while preserving custom branding. Site Settings > General > Builders and Bots controls artwork visibility in launcher buttons and chat windows, and animation. Reduced-motion preferences take priority; human handoffs step her aside.
12
+
3
13
  ## [1.50.0] - 2026-11-10
4
14
 
5
15
  - **Della, the chat bot, can answer with AI what the Knowledge does not** (Pro plan, hosted sites). Claude answers only from the Knowledge, Site Settings > General > AI assistant (About the business, Rules) and each chat launcher's own context and rules, and says it does not know rather than guess. Switch it off per launcher. The bot's default name is now Della. `services/chat/ai.js`, `services/assistant.js`.
@@ -1 +1 @@
1
- import{api as Oe}from"../api.js";function Te(){const o={"rotate-cw":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M21 2v6h-6M21 8A9 9 0 1 0 19.07 14.4"},"rotate-ccw":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M3 2v6h6M3 8a9 9 0 1 1 1.93 6.4"},"flip-h":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M12 3v18","M4 6l4 6-4 6","M20 6l-4 6 4 6"]},"flip-v":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M3 12h18","M6 4l6 4 6-4","M6 20l6-4 6 4"]},lock:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M17 11H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2z","M12 8a4 4 0 0 0-4 4"],path:"M12 8V5a4 4 0 0 1 4 4v2"},unlock:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M17 11H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2z","M8 11V7a4 4 0 0 1 8 0"]},"crop-icon":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M6 2v14a2 2 0 0 0 2 2h14","M18 22V8a2 2 0 0 0-2-2H2"]},sliders:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M4 21v-7","M4 10V3","M12 21v-9","M12 8V3","M20 21v-5","M20 12V3","M1 14h6","M9 8h6","M17 16h6"]},droplet:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z"},"image-plus":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7","M16 5h6","M19 2v6","M3 15l5-5 4 4 3-3 4 4"]},frame:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M7 3H3v4","M17 3h4v4","M7 21H3v-4","M17 21h4v-4"]},"file-type":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z","M14 2v6h6","M10 13l-2 4h8l-2-4"]}};for(const[y,j]of Object.entries(o))try{I.register(y,j)}catch{}}function se(o){const y=document.createElement("span");return y.setAttribute("data-icon",o),y}function U(o,y,j){const d=document.createElement("button");return d.className=o,d.type="button",d.title=j,d.appendChild(se(y)),d}function $e(){const o=document.createElement("span");return o.className="image-editor-sep",o}const ze=o=>String(o??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function Qe(o){for(;o.firstChild;)o.removeChild(o.firstChild)}export async function openImageEditor(o,{api:y=null}={}){Te();const j=y||Oe.media;let d;try{d=await j.info(o.name)}catch(le){return E.toast(`Cannot open editor: ${le.message}`,{type:"error"}),!1}return new Promise(le=>{let m=null,D=!1,O=0,q=!1,A=!1,$=!0;const ke=d.width/d.height;let re=null,k=null;const r={brightness:1,contrast:1,saturation:1,blur:0,sharpen:0,gamma:1},u={image:null,position:"bottom-right",opacity:50,scale:15},L={width:0,colour:"#000000",mode:"solid"},v={type:null,quality:85},x=document.createElement("div");x.className="image-editor";const C=document.createElement("div");C.className="image-editor-toolbar";const ie=U("btn btn-sm btn-ghost editor-toolbar-btn","crop-icon","Toggle crop"),xe=U("btn btn-sm btn-ghost editor-toolbar-btn","rotate-cw","Rotate clockwise"),Ne=U("btn btn-sm btn-ghost editor-toolbar-btn","rotate-ccw","Rotate counter-clockwise"),ce=U("btn btn-sm btn-ghost editor-toolbar-btn","flip-h","Flip horizontal"),de=U("btn btn-sm btn-ghost editor-toolbar-btn","flip-v","Flip vertical");C.appendChild(ie),C.appendChild($e()),C.appendChild(Ne),C.appendChild(xe),C.appendChild($e()),C.appendChild(ce),C.appendChild(de);const X=document.createElement("div");X.className="image-editor-canvas";const z=document.createElement("img");z.src=o.url+"?t="+Date.now(),z.alt=o.name,z.style.maxWidth="100%",X.appendChild(z);const N=document.createElement("div");N.className="image-editor-resize";const Me=document.createElement("label");Me.textContent="W";const g=document.createElement("input");g.type="number",g.className="form-input",g.value=d.width,g.min=1;const h=document.createElement("button");h.type="button",h.className="btn btn-sm btn-ghost editor-toolbar-btn active",h.title="Lock aspect ratio",h.appendChild(se("lock"));const Le=document.createElement("label");Le.textContent="H";const w=document.createElement("input");w.type="number",w.className="form-input",w.value=d.height,w.min=1;const Y=document.createElement("span");Y.className="text-muted",Y.style.marginLeft="auto",Y.textContent=`Original: ${d.width}\xD7${d.height}`,N.appendChild(Me),N.appendChild(g),N.appendChild(h),N.appendChild(Le),N.appendChild(w),N.appendChild(Y);const _=document.createElement("div");_.className="image-editor-effects";const pe=document.createElement("div");pe.className="image-editor-tab-bar";const me=[{id:"filters",label:"Filters",icon:"droplet"},{id:"adjust",label:"Adjust",icon:"sliders"},{id:"watermark",label:"Watermark",icon:"image-plus"},{id:"border",label:"Border",icon:"frame"},{id:"format",label:"Format",icon:"file-type"}],i={},Be={};me.forEach(({id:e,label:t,icon:a},s)=>{const n=document.createElement("button");n.type="button",n.className="image-editor-tab-btn"+(s===0?" active":""),n.dataset.tab=e,n.appendChild(se(a));const p=document.createElement("span");p.textContent=t,n.appendChild(p),n.addEventListener("click",()=>He(e)),pe.appendChild(n),Be[e]=n;const l=document.createElement("div");l.className="image-editor-tab-panel",l.style.display=s===0?"block":"none",i[e]=l});function He(e){me.forEach(({id:t})=>{i[t].style.display=t===e?"block":"none",Be[t].classList.toggle("active",t===e)})}_.appendChild(pe),me.forEach(({id:e})=>_.appendChild(i[e]));const Pe=[{id:"grayscale",label:"Grayscale",cssPreview:!0},{id:"sepia",label:"Sepia",cssPreview:!0},{id:"warm",label:"Warm",cssPreview:!1},{id:"cool",label:"Cool",cssPreview:!1},{id:"enhance",label:"Enhance",cssPreview:!1},{id:"sharpen",label:"Sharpen",cssPreview:!1},{id:"soften",label:"Soften",cssPreview:!1},{id:"invert",label:"Invert",cssPreview:!0}],ue=document.createElement("div");ue.className="ie-presets-grid";const Se={};Pe.forEach(({id:e,label:t})=>{const a=document.createElement("button");a.type="button",a.className="btn btn-sm btn-ghost ie-preset-btn",a.textContent=t,a.addEventListener("click",()=>{k=k===e?null:e,Pe.forEach(({id:s})=>{Se[s].classList.toggle("active",s===k)}),oe()}),Se[e]=a,ue.appendChild(a)});const he=document.createElement("p");he.className="ie-server-note",he.textContent="Warm, Cool, Enhance, Sharpen, and Soften have no live preview - applied on save only.",i.filters.appendChild(ue),i.filters.appendChild(he);const We={};function V(e,t,a,s,n,p){const l=document.createElement("div");l.className="ie-slider-row";const b=document.createElement("label");b.className="ie-slider-label",b.textContent=e;const c=document.createElement("input");c.type="range",c.min=t,c.max=a,c.step=s,c.value=n,c.className="ie-slider";const f=document.createElement("span");return f.className="ie-slider-val",f.textContent=n,c.addEventListener("input",()=>{const R=parseFloat(c.value);f.textContent=s<1?R.toFixed(1):String(Math.round(R)),p(R)}),l.appendChild(b),l.appendChild(c),l.appendChild(f),{row:l,slider:c,valDisplay:f,defaultVal:n,reset(){c.value=n,f.textContent=n}}}const Re=[{key:"brightness",label:"Brightness",min:.2,max:3,step:.1,def:1},{key:"contrast",label:"Contrast",min:.2,max:3,step:.1,def:1},{key:"saturation",label:"Saturation",min:0,max:3,step:.1,def:1},{key:"blur",label:"Blur",min:0,max:10,step:.5,def:0},{key:"sharpen",label:"Sharpen",min:0,max:10,step:.5,def:0},{key:"gamma",label:"Gamma",min:.5,max:3,step:.1,def:1}];Re.forEach(({key:e,label:t,min:a,max:s,step:n,def:p})=>{const l=V(t,a,s,n,p,b=>{r[e]=b,oe()});We[e]=l,i.adjust.appendChild(l.row)});const H=document.createElement("button");H.type="button",H.className="btn btn-sm btn-ghost",H.style.marginTop="0.5rem",H.textContent="Reset adjustments",H.addEventListener("click",()=>{Re.forEach(({key:e,def:t})=>{r[e]=t,We[e].reset()}),oe()}),i.adjust.appendChild(H);const B=document.createElement("button");B.type="button",B.className="btn btn-sm btn-secondary",B.textContent="Choose watermark image\u2026";const M=document.createElement("div");M.className="ie-wm-preview-row",M.style.display="none";const be=document.createElement("img");be.className="ie-wm-preview-img";const fe=document.createElement("span");fe.className="ie-wm-preview-name";const G=document.createElement("button");G.type="button",G.className="btn btn-sm btn-ghost",G.textContent="Remove",G.addEventListener("click",()=>{u.image=null,M.style.display="none",B.style.display=""}),M.appendChild(be),M.appendChild(fe),M.appendChild(G),B.addEventListener("click",async()=>{const e=await Ve();e&&(u.image=e.name,be.src=e.url,fe.textContent=e.name,M.style.display="flex",B.style.display="none")});const Z=document.createElement("div");Z.className="ie-slider-row";const ve=document.createElement("label");ve.className="ie-slider-label",ve.textContent="Position";const T=document.createElement("select");T.className="form-select ie-select",["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"].forEach(e=>{const t=document.createElement("option");t.value=e,t.textContent=e.replace(/-/g," ").replace(/\b\w/g,a=>a.toUpperCase()),e==="bottom-right"&&(t.selected=!0),T.appendChild(t)}),T.addEventListener("change",()=>{u.position=T.value}),Z.appendChild(ve),Z.appendChild(T);const Fe=V("Opacity %",0,100,1,50,e=>{u.opacity=e}),De=V("Scale %",5,50,1,15,e=>{u.scale=e});i.watermark.appendChild(B),i.watermark.appendChild(M),i.watermark.appendChild(Z),i.watermark.appendChild(Fe.row),i.watermark.appendChild(De.row);const qe=V("Width (px)",0,200,1,0,e=>{L.width=e}),ee=document.createElement("div");ee.className="ie-slider-row";const Ce=document.createElement("label");Ce.className="ie-slider-label",Ce.textContent="Colour";const F=document.createElement("input");F.type="color",F.value="#000000",F.className="ie-colour-input",F.addEventListener("input",()=>{L.colour=F.value}),ee.appendChild(Ce),ee.appendChild(F);const te=document.createElement("div");te.className="ie-slider-row";const ge=document.createElement("label");ge.className="ie-slider-label",ge.textContent="Mode";const Q=document.createElement("select");Q.className="form-select ie-select",[["solid","Solid"],["mirror","Mirror"],["repeat","Repeat"]].forEach(([e,t])=>{const a=document.createElement("option");a.value=e,a.textContent=t,Q.appendChild(a)}),Q.addEventListener("change",()=>{L.mode=Q.value}),te.appendChild(ge),te.appendChild(Q),i.border.appendChild(qe.row),i.border.appendChild(ee),i.border.appendChild(te);const ne=document.createElement("div");ne.className="ie-slider-row";const we=document.createElement("label");we.className="ie-slider-label",we.textContent="Output format";const P=document.createElement("select");P.className="form-select ie-select",[["","Keep original"],["jpeg","JPEG"],["png","PNG"],["webp","WebP"]].forEach(([e,t])=>{const a=document.createElement("option");a.value=e,a.textContent=t,P.appendChild(a)}),ne.appendChild(we),ne.appendChild(P);const Ee=V("Quality",1,100,1,85,e=>{v.quality=e});Ee.row.style.display="none",P.addEventListener("change",()=>{v.type=P.value||null,Ee.row.style.display=P.value==="jpeg"||P.value==="webp"?"flex":"none"}),i.format.appendChild(ne),i.format.appendChild(Ee.row);const ae=document.createElement("div");ae.className="image-editor-footer";const J=document.createElement("button");J.type="button",J.className="btn btn-ghost",J.textContent="Cancel";const K=document.createElement("div");K.style.display="flex",K.style.gap="0.5rem";const S=document.createElement("button");S.type="button",S.className="btn btn-secondary",S.textContent="Save as copy";const W=document.createElement("button");W.type="button",W.className="btn btn-primary",W.textContent="Overwrite",K.appendChild(S),K.appendChild(W),ae.appendChild(J),ae.appendChild(K),x.appendChild(C),x.appendChild(X),x.appendChild(N),x.appendChild(_),x.appendChild(ae);const ye=E.slideover({title:`Edit: ${ze(o.name)}`,size:"lg",position:"right"});ye.element.appendChild(x),ye.open(),z.addEventListener("ready",()=>{re=X.querySelector(".cropper-canvas"),oe()},{once:!0}),requestAnimationFrame(()=>{m=new Cropper(z,{viewMode:1,autoCrop:!1,zoomable:!1,movable:!0}),Domma.icons.scan(x)}),ie.addEventListener("click",()=>{D=!D,D?m.crop():m.clear(),ie.classList.toggle("active",D)}),xe.addEventListener("click",()=>{m.rotate(90),O=(O+90)%360}),Ne.addEventListener("click",()=>{m.rotate(-90),O=(O-90+360)%360}),ce.addEventListener("click",()=>{q=!q,m.scaleX(q?-1:1),ce.classList.toggle("active",q)}),de.addEventListener("click",()=>{A=!A,m.scaleY(A?-1:1),de.classList.toggle("active",A)}),h.addEventListener("click",()=>{$=!$,h.classList.toggle("active",$),Qe(h),h.appendChild(se($?"lock":"unlock")),Domma.icons.scan(h)}),g.addEventListener("input",()=>{if(!$)return;const e=parseInt(g.value,10);e>0&&(w.value=Math.round(e/ke))}),w.addEventListener("input",()=>{if(!$)return;const e=parseInt(w.value,10);e>0&&(g.value=Math.round(e*ke))});function Ae(){const e=[];return k==="grayscale"&&e.push("grayscale(1)"),k==="sepia"&&e.push("sepia(1)"),k==="invert"&&e.push("invert(1)"),r.brightness!==1&&e.push(`brightness(${r.brightness})`),r.contrast!==1&&e.push(`contrast(${r.contrast})`),r.saturation!==1&&e.push(`saturate(${r.saturation})`),r.blur>0&&e.push(`blur(${r.blur}px)`),e.join(" ")}function oe(){re&&(re.style.filter=Ae())}async function Ve(){return new Promise(async e=>{let t;try{t=await Oe.media.list()}catch(l){E.toast(`Failed to load media: ${l.message}`,{type:"error"}),e(null);return}const a=t.filter(l=>/\.(jpg|jpeg|png|webp|gif)$/i.test(l.name)),s=document.createElement("div");if(s.className="ie-media-picker",a.length===0){const l=document.createElement("p");l.className="text-muted",l.style.padding="1rem 0",l.textContent="No images in media library.",s.appendChild(l)}else{const l=document.createElement("div");l.className="ie-media-picker-grid",a.forEach(b=>{const c=document.createElement("div");c.className="ie-media-thumb";const f=document.createElement("img");f.src=b.url,f.alt=b.name;const R=document.createElement("span");R.className="ie-media-thumb-name",R.textContent=b.name,c.appendChild(f),c.appendChild(R),c.addEventListener("click",()=>{p.close(),e(b)}),l.appendChild(c)}),s.appendChild(l)}const n=document.createElement("button");n.type="button",n.className="btn btn-sm btn-ghost",n.style.marginTop="0.75rem",n.textContent="Cancel",n.addEventListener("click",()=>{p.close(),e(null)}),s.appendChild(n);const p=E.slideover({title:"Choose watermark image",size:"md",position:"right"});p.element.appendChild(s),p.open()})}function Ge(){const e={};if(O&&(e.rotate=O),A&&(e.flip=!0),q&&(e.flop=!0),D){const n=m.getData(!0);n.width>0&&n.height>0&&(e.crop={left:n.x,top:n.y,width:n.width,height:n.height})}const t=parseInt(g.value,10)||null,a=parseInt(w.value,10)||null;(t!==d.width||a!==d.height)&&(e.resize={width:t,height:a}),k&&(e.preset=k);const s={};return r.brightness!==1&&(s.brightness=r.brightness),r.contrast!==1&&(s.contrast=r.contrast),r.saturation!==1&&(s.saturation=r.saturation),r.blur>0&&(s.blur=r.blur),r.sharpen>0&&(s.sharpen=r.sharpen),r.gamma!==1&&(s.gamma=r.gamma),Object.keys(s).length>0&&(e.adjustments=s),u.image&&(e.watermark={image:u.image,position:u.position,opacity:u.opacity/100,scale:u.scale/100}),L.width>0&&(e.border={width:L.width,colour:L.colour,mode:L.mode}),v.type&&(e.format={type:v.type,quality:v.quality}),e}async function Ie(e){W.disabled=!0,S.disabled=!0;try{const t=Ge();let a=e;if(!e&&v.type){const s=o.name.substring(o.name.lastIndexOf(".")).toLowerCase(),n="."+v.type;s!==n&&(a=o.name.slice(0,o.name.lastIndexOf("."))+n,t._deleteOriginal=o.name)}await j.transform(o.name,{operations:t,saveAs:a||void 0}),E.toast("Image saved.",{type:"success"}),je(!0)}catch(t){E.toast(`Save failed: ${t.message}`,{type:"error"}),W.disabled=!1,S.disabled=!1}}W.addEventListener("click",async()=>{await E.confirm(`Overwrite "${ze(o.name)}"? This cannot be undone.`)&&await Ie(null)}),S.addEventListener("click",async()=>{const e=v.type?"."+v.type:o.name.substring(o.name.lastIndexOf(".")),t=o.name.slice(0,o.name.lastIndexOf("."));await Ie(`${t}-edited${e}`)}),J.addEventListener("click",()=>je(!1));function je(e){m&&(m.destroy(),m=null),ye.close(),le(e)}})}
1
+ import{api as Oe}from"../api.js";function Te(){const o={"rotate-cw":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M21 2v6h-6M21 8A9 9 0 1 0 19.07 14.4"},"rotate-ccw":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M3 2v6h6M3 8a9 9 0 1 1 1.93 6.4"},"flip-h":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M12 3v18","M4 6l4 6-4 6","M20 6l-4 6 4 6"]},"flip-v":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M3 12h18","M6 4l6 4 6-4","M6 20l6-4 6 4"]},lock:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M17 11H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2z","M12 8a4 4 0 0 0-4 4"],path:"M12 8V5a4 4 0 0 1 4 4v2"},unlock:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M17 11H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2z","M8 11V7a4 4 0 0 1 8 0"]},"crop-icon":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M6 2v14a2 2 0 0 0 2 2h14","M18 22V8a2 2 0 0 0-2-2H2"]},sliders:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M4 21v-7","M4 10V3","M12 21v-9","M12 8V3","M20 21v-5","M20 12V3","M1 14h6","M9 8h6","M17 16h6"]},droplet:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,path:"M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z"},"image-plus":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7","M16 5h6","M19 2v6","M3 15l5-5 4 4 3-3 4 4"]},frame:{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M7 3H3v4","M17 3h4v4","M7 21H3v-4","M17 21h4v-4"]},"file-type":{viewBox:"0 0 24 24",stroke:"currentColor",fill:"none",strokeWidth:2,paths:["M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z","M14 2v6h6","M10 13l-2 4h8l-2-4"]}};for(const[y,j]of Object.entries(o))try{I.register(y,j)}catch{}}function le(o){const y=document.createElement("span");return y.setAttribute("data-icon",o),y}function U(o,y,j){const d=document.createElement("button");return d.className=o,d.type="button",d.title=j,d.appendChild(le(y)),d}function $e(){const o=document.createElement("span");return o.className="image-editor-sep",o}const ze=o=>String(o??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function Qe(o){for(;o.firstChild;)o.removeChild(o.firstChild)}export async function openImageEditor(o,{api:y=null}={}){Te();const j=y||Oe.media;let d;try{d=await j.info(o.name)}catch(re){return E.toast(`Cannot open editor: ${re.message}`,{type:"error"}),!1}return new Promise(re=>{let m=null,O=!1,$=0,q=!1,A=!1,z=!0;const ke=d.width/d.height;let ie=null,k=null;const l={brightness:1,contrast:1,saturation:1,blur:0,sharpen:0,gamma:1},u={image:null,position:"bottom-right",opacity:50,scale:15},L={width:0,colour:"#000000",mode:"solid"},f={type:null,quality:85},x=document.createElement("div");x.className="image-editor";const C=document.createElement("div");C.className="image-editor-toolbar";const X=U("btn btn-sm btn-ghost editor-toolbar-btn","crop-icon","Toggle crop"),xe=U("btn btn-sm btn-ghost editor-toolbar-btn","rotate-cw","Rotate clockwise"),Ne=U("btn btn-sm btn-ghost editor-toolbar-btn","rotate-ccw","Rotate counter-clockwise"),ce=U("btn btn-sm btn-ghost editor-toolbar-btn","flip-h","Flip horizontal"),de=U("btn btn-sm btn-ghost editor-toolbar-btn","flip-v","Flip vertical");C.appendChild(X),C.appendChild($e()),C.appendChild(Ne),C.appendChild(xe),C.appendChild($e()),C.appendChild(ce),C.appendChild(de);const Y=document.createElement("div");Y.className="image-editor-canvas";const H=document.createElement("img");H.src=o.url+"?t="+Date.now(),H.alt=o.name,H.style.maxWidth="100%",Y.appendChild(H);const N=document.createElement("div");N.className="image-editor-resize";const Me=document.createElement("label");Me.textContent="W";const g=document.createElement("input");g.type="number",g.className="form-input",g.value=d.width,g.min=1;const h=document.createElement("button");h.type="button",h.className="btn btn-sm btn-ghost editor-toolbar-btn active",h.title="Lock aspect ratio",h.appendChild(le("lock"));const Le=document.createElement("label");Le.textContent="H";const w=document.createElement("input");w.type="number",w.className="form-input",w.value=d.height,w.min=1;const _=document.createElement("span");_.className="text-muted",_.style.marginLeft="auto",_.textContent=`Original: ${d.width}\xD7${d.height}`,N.appendChild(Me),N.appendChild(g),N.appendChild(h),N.appendChild(Le),N.appendChild(w),N.appendChild(_);const Z=document.createElement("div");Z.className="image-editor-effects";const pe=document.createElement("div");pe.className="image-editor-tab-bar";const me=[{id:"filters",label:"Filters",icon:"droplet"},{id:"adjust",label:"Adjust",icon:"sliders"},{id:"watermark",label:"Watermark",icon:"image-plus"},{id:"border",label:"Border",icon:"frame"},{id:"format",label:"Format",icon:"file-type"}],i={},Be={};me.forEach(({id:e,label:t,icon:a},r)=>{const n=document.createElement("button");n.type="button",n.className="image-editor-tab-btn"+(r===0?" active":""),n.dataset.tab=e,n.appendChild(le(a));const p=document.createElement("span");p.textContent=t,n.appendChild(p),n.addEventListener("click",()=>He(e)),pe.appendChild(n),Be[e]=n;const s=document.createElement("div");s.className="image-editor-tab-panel",s.style.display=r===0?"block":"none",i[e]=s});function He(e){me.forEach(({id:t})=>{i[t].style.display=t===e?"block":"none",Be[t].classList.toggle("active",t===e)})}Z.appendChild(pe),me.forEach(({id:e})=>Z.appendChild(i[e]));const Pe=[{id:"grayscale",label:"Grayscale",cssPreview:!0},{id:"sepia",label:"Sepia",cssPreview:!0},{id:"warm",label:"Warm",cssPreview:!1},{id:"cool",label:"Cool",cssPreview:!1},{id:"enhance",label:"Enhance",cssPreview:!1},{id:"sharpen",label:"Sharpen",cssPreview:!1},{id:"soften",label:"Soften",cssPreview:!1},{id:"invert",label:"Invert",cssPreview:!0}],ue=document.createElement("div");ue.className="ie-presets-grid";const Se={};Pe.forEach(({id:e,label:t})=>{const a=document.createElement("button");a.type="button",a.className="btn btn-sm btn-ghost ie-preset-btn",a.textContent=t,a.addEventListener("click",()=>{k=k===e?null:e,Pe.forEach(({id:r})=>{Se[r].classList.toggle("active",r===k)}),se()}),Se[e]=a,ue.appendChild(a)});const he=document.createElement("p");he.className="ie-server-note",he.textContent="Warm, Cool, Enhance, Sharpen, and Soften have no live preview - applied on save only.",i.filters.appendChild(ue),i.filters.appendChild(he);const We={};function V(e,t,a,r,n,p){const s=document.createElement("div");s.className="ie-slider-row";const b=document.createElement("label");b.className="ie-slider-label",b.textContent=e;const c=document.createElement("input");c.type="range",c.min=t,c.max=a,c.step=r,c.value=n,c.className="ie-slider";const v=document.createElement("span");return v.className="ie-slider-val",v.textContent=n,c.addEventListener("input",()=>{const R=parseFloat(c.value);v.textContent=r<1?R.toFixed(1):String(Math.round(R)),p(R)}),s.appendChild(b),s.appendChild(c),s.appendChild(v),{row:s,slider:c,valDisplay:v,defaultVal:n,reset(){c.value=n,v.textContent=n}}}const Re=[{key:"brightness",label:"Brightness",min:.2,max:3,step:.1,def:1},{key:"contrast",label:"Contrast",min:.2,max:3,step:.1,def:1},{key:"saturation",label:"Saturation",min:0,max:3,step:.1,def:1},{key:"blur",label:"Blur",min:0,max:10,step:.5,def:0},{key:"sharpen",label:"Sharpen",min:0,max:10,step:.5,def:0},{key:"gamma",label:"Gamma",min:.5,max:3,step:.1,def:1}];Re.forEach(({key:e,label:t,min:a,max:r,step:n,def:p})=>{const s=V(t,a,r,n,p,b=>{l[e]=b,se()});We[e]=s,i.adjust.appendChild(s.row)});const F=document.createElement("button");F.type="button",F.className="btn btn-sm btn-ghost",F.style.marginTop="0.5rem",F.textContent="Reset adjustments",F.addEventListener("click",()=>{Re.forEach(({key:e,def:t})=>{l[e]=t,We[e].reset()}),se()}),i.adjust.appendChild(F);const B=document.createElement("button");B.type="button",B.className="btn btn-sm btn-secondary",B.textContent="Choose watermark image\u2026";const M=document.createElement("div");M.className="ie-wm-preview-row",M.style.display="none";const be=document.createElement("img");be.className="ie-wm-preview-img";const ve=document.createElement("span");ve.className="ie-wm-preview-name";const G=document.createElement("button");G.type="button",G.className="btn btn-sm btn-ghost",G.textContent="Remove",G.addEventListener("click",()=>{u.image=null,M.style.display="none",B.style.display=""}),M.appendChild(be),M.appendChild(ve),M.appendChild(G),B.addEventListener("click",async()=>{const e=await Ve();e&&(u.image=e.name,be.src=e.url,ve.textContent=e.name,M.style.display="flex",B.style.display="none")});const ee=document.createElement("div");ee.className="ie-slider-row";const fe=document.createElement("label");fe.className="ie-slider-label",fe.textContent="Position";const T=document.createElement("select");T.className="form-select ie-select",["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right"].forEach(e=>{const t=document.createElement("option");t.value=e,t.textContent=e.replace(/-/g," ").replace(/\b\w/g,a=>a.toUpperCase()),e==="bottom-right"&&(t.selected=!0),T.appendChild(t)}),T.addEventListener("change",()=>{u.position=T.value}),ee.appendChild(fe),ee.appendChild(T);const Fe=V("Opacity %",0,100,1,50,e=>{u.opacity=e}),De=V("Scale %",5,50,1,15,e=>{u.scale=e});i.watermark.appendChild(B),i.watermark.appendChild(M),i.watermark.appendChild(ee),i.watermark.appendChild(Fe.row),i.watermark.appendChild(De.row);const qe=V("Width (px)",0,200,1,0,e=>{L.width=e}),te=document.createElement("div");te.className="ie-slider-row";const Ce=document.createElement("label");Ce.className="ie-slider-label",Ce.textContent="Colour";const D=document.createElement("input");D.type="color",D.value="#000000",D.className="ie-colour-input",D.addEventListener("input",()=>{L.colour=D.value}),te.appendChild(Ce),te.appendChild(D);const ne=document.createElement("div");ne.className="ie-slider-row";const ge=document.createElement("label");ge.className="ie-slider-label",ge.textContent="Mode";const Q=document.createElement("select");Q.className="form-select ie-select",[["solid","Solid"],["mirror","Mirror"],["repeat","Repeat"]].forEach(([e,t])=>{const a=document.createElement("option");a.value=e,a.textContent=t,Q.appendChild(a)}),Q.addEventListener("change",()=>{L.mode=Q.value}),ne.appendChild(ge),ne.appendChild(Q),i.border.appendChild(qe.row),i.border.appendChild(te),i.border.appendChild(ne);const ae=document.createElement("div");ae.className="ie-slider-row";const we=document.createElement("label");we.className="ie-slider-label",we.textContent="Output format";const P=document.createElement("select");P.className="form-select ie-select",[["","Keep original"],["jpeg","JPEG"],["png","PNG"],["webp","WebP"]].forEach(([e,t])=>{const a=document.createElement("option");a.value=e,a.textContent=t,P.appendChild(a)}),ae.appendChild(we),ae.appendChild(P);const Ee=V("Quality",1,100,1,85,e=>{f.quality=e});Ee.row.style.display="none",P.addEventListener("change",()=>{f.type=P.value||null,Ee.row.style.display=P.value==="jpeg"||P.value==="webp"?"flex":"none"}),i.format.appendChild(ae),i.format.appendChild(Ee.row);const oe=document.createElement("div");oe.className="image-editor-footer";const J=document.createElement("button");J.type="button",J.className="btn btn-ghost",J.textContent="Cancel";const K=document.createElement("div");K.style.display="flex",K.style.gap="0.5rem";const S=document.createElement("button");S.type="button",S.className="btn btn-secondary",S.textContent="Save as copy";const W=document.createElement("button");W.type="button",W.className="btn btn-primary",W.textContent="Overwrite",K.appendChild(S),K.appendChild(W),oe.appendChild(J),oe.appendChild(K),x.appendChild(C),x.appendChild(Y),x.appendChild(N),x.appendChild(Z),x.appendChild(oe);const ye=E.slideover({title:`Edit: ${ze(o.name)}`,size:"lg",position:"right"});ye.element.appendChild(x),ye.open(),H.addEventListener("ready",()=>{ie=Y.querySelector(".cropper-canvas"),se()},{once:!0}),requestAnimationFrame(()=>{m=new Cropper(H,{viewMode:1,autoCrop:!1,zoomable:!1,movable:!0,crop(e){O=e.detail.width>0&&e.detail.height>0,X.classList.toggle("active",O)}}),Domma.icons.scan(x)}),X.addEventListener("click",()=>{O=!O,O?m.crop():m.clear(),X.classList.toggle("active",O)}),xe.addEventListener("click",()=>{m.rotate(90),$=($+90)%360}),Ne.addEventListener("click",()=>{m.rotate(-90),$=($-90+360)%360}),ce.addEventListener("click",()=>{q=!q,m.scaleX(q?-1:1),ce.classList.toggle("active",q)}),de.addEventListener("click",()=>{A=!A,m.scaleY(A?-1:1),de.classList.toggle("active",A)}),h.addEventListener("click",()=>{z=!z,h.classList.toggle("active",z),Qe(h),h.appendChild(le(z?"lock":"unlock")),Domma.icons.scan(h)}),g.addEventListener("input",()=>{if(!z)return;const e=parseInt(g.value,10);e>0&&(w.value=Math.round(e/ke))}),w.addEventListener("input",()=>{if(!z)return;const e=parseInt(w.value,10);e>0&&(g.value=Math.round(e*ke))});function Ae(){const e=[];return k==="grayscale"&&e.push("grayscale(1)"),k==="sepia"&&e.push("sepia(1)"),k==="invert"&&e.push("invert(1)"),l.brightness!==1&&e.push(`brightness(${l.brightness})`),l.contrast!==1&&e.push(`contrast(${l.contrast})`),l.saturation!==1&&e.push(`saturate(${l.saturation})`),l.blur>0&&e.push(`blur(${l.blur}px)`),e.join(" ")}function se(){ie&&(ie.style.filter=Ae())}async function Ve(){return new Promise(async e=>{let t;try{t=await Oe.media.list()}catch(s){E.toast(`Failed to load media: ${s.message}`,{type:"error"}),e(null);return}const a=t.filter(s=>/\.(jpg|jpeg|png|webp|gif)$/i.test(s.name)),r=document.createElement("div");if(r.className="ie-media-picker",a.length===0){const s=document.createElement("p");s.className="text-muted",s.style.padding="1rem 0",s.textContent="No images in media library.",r.appendChild(s)}else{const s=document.createElement("div");s.className="ie-media-picker-grid",a.forEach(b=>{const c=document.createElement("div");c.className="ie-media-thumb";const v=document.createElement("img");v.src=b.url,v.alt=b.name;const R=document.createElement("span");R.className="ie-media-thumb-name",R.textContent=b.name,c.appendChild(v),c.appendChild(R),c.addEventListener("click",()=>{p.close(),e(b)}),s.appendChild(c)}),r.appendChild(s)}const n=document.createElement("button");n.type="button",n.className="btn btn-sm btn-ghost",n.style.marginTop="0.75rem",n.textContent="Cancel",n.addEventListener("click",()=>{p.close(),e(null)}),r.appendChild(n);const p=E.slideover({title:"Choose watermark image",size:"md",position:"right"});p.element.appendChild(r),p.open()})}function Ge(){const e={};$&&(e.rotate=$),A&&(e.flip=!0),q&&(e.flop=!0);const t=m.getData(!0);t.width>0&&t.height>0&&(e.crop={left:t.x,top:t.y,width:t.width,height:t.height});const a=parseInt(g.value,10)||null,r=parseInt(w.value,10)||null;(a!==d.width||r!==d.height)&&(e.resize={width:a,height:r}),k&&(e.preset=k);const n={};return l.brightness!==1&&(n.brightness=l.brightness),l.contrast!==1&&(n.contrast=l.contrast),l.saturation!==1&&(n.saturation=l.saturation),l.blur>0&&(n.blur=l.blur),l.sharpen>0&&(n.sharpen=l.sharpen),l.gamma!==1&&(n.gamma=l.gamma),Object.keys(n).length>0&&(e.adjustments=n),u.image&&(e.watermark={image:u.image,position:u.position,opacity:u.opacity/100,scale:u.scale/100}),L.width>0&&(e.border={width:L.width,colour:L.colour,mode:L.mode}),f.type&&(e.format={type:f.type,quality:f.quality}),e}async function Ie(e){W.disabled=!0,S.disabled=!0;try{const t=Ge();let a=e;if(!e&&f.type){const r=o.name.substring(o.name.lastIndexOf(".")).toLowerCase(),n="."+f.type;r!==n&&(a=o.name.slice(0,o.name.lastIndexOf("."))+n,t._deleteOriginal=o.name)}await j.transform(o.name,{operations:t,saveAs:a||void 0}),E.toast("Image saved.",{type:"success"}),je(!0)}catch(t){E.toast(`Save failed: ${t.message}`,{type:"error"}),W.disabled=!1,S.disabled=!1}}W.addEventListener("click",async()=>{await E.confirm(`Overwrite "${ze(o.name)}"? This cannot be undone.`)&&await Ie(null)}),S.addEventListener("click",async()=>{const e=f.type?"."+f.type:o.name.substring(o.name.lastIndexOf(".")),t=o.name.slice(0,o.name.lastIndexOf("."));await Ie(`${t}-edited${e}`)}),J.addEventListener("click",()=>je(!1));function je(e){m&&(m.destroy(),m=null),ye.close(),re(e)}})}
@@ -1,5 +1,5 @@
1
- import{LAUNCHER_DEFAULTS as b,LAUNCHER_LIMITS as r,LAUNCHER_POSITION_LABEL as u,launcherColourCss as l,launcherReady as x,launcherSpot as f,launcherAvatar as y,normaliseLauncher as p,normaliseLauncherPath as g}from"../../../public/js/launcher-settings.mjs";export const FILTERS=["all","on","off"];const m={modal:"Modal",slideover:"Slideover",chat:"Chat"},w={page:"page",form:"form",block:"block"};export function describeAction(e){const t=e.action;return t.type==="chat"?`Chat${e.chat.bot?" (bot first)":""}`:t.ref?`${m[t.type]}: ${t.kind==="page"?t.ref:`${w[t.kind]} ${t.ref}`}`:`${m[t.type]}: nothing chosen yet`}export function describeWhere(e){const t=e.pages.paths.length,o=e.pages.mode==="all"?"every page":e.pages.mode==="only"?t?`${t} page rule${t===1?"":"s"}`:"no pages":`every page but ${t} rule${t===1?"":"s"}`,a=e.audience==="signed-in"?", signed-in only":e.audience==="signed-out"?", signed-out only":"",n=e.devices==="desktop"?", desktop only":e.devices==="phone"?", phones only":"";return`${o}${a}${n}`}export function launcherProblem(e){return x(e)?e.pages.mode==="only"&&!e.pages.paths.length?"Shows on no pages":"":"Choose what it opens"}export function launcherRow(e){const t=launcherProblem(e),o=e.triggerStyle==="icon-text",a=l(e.colours.background)||"var(--dm-primary)",n=l(e.colours.text)||"var(--dm-primary-text)";return{id:e.id,name:e.name,meta:`${e.showDisc?u[e.position]:"No disc - opened from links"} \xB7 ${describeAction(e)} \xB7 ${describeWhere(e)}`,label:e.label,icon:e.icon,pill:o,off:!e.enabled,on:e.enabled,problem:t,rowCls:[e.enabled?"":"is-off",t&&e.enabled?"is-warn":""].filter(Boolean).join(" "),discStyle:{"--lnx-bg":a,"--lnx-fg":n,"border-radius":o?"999px":`${Math.round(e.radius/e.size*100)}%`}}}export function arrangeLaunchers(e,{filter:t="all",query:o=""}={}){const a=String(o||"").trim().toLowerCase();return e.filter(n=>t==="on"?n.enabled:t==="off"?!n.enabled:!0).filter(n=>!a||[n.name,n.label,n.action.ref,n.action.title].some(i=>String(i||"").toLowerCase().includes(a)))}export function countLaunchers(e){const t=e.filter(o=>o.enabled).length;return{all:e.length,on:t,off:e.length-t}}export function moveItem(e,t,o){const a=[...e];if(t<0||t>=a.length||o<0||o>=a.length||t===o)return a;const[n]=a.splice(t,1);return a.splice(o,0,n),a}export function blankLauncher(e=[]){const t=new Set(e.map(a=>a.name));let o="New launcher";for(let a=2;t.has(o);a++)o=`New launcher ${a}`;return p({name:o})}export function duplicateLauncher(e,t=[]){const o=new Set(t.map(n=>n.name));let a=`${e.name} (copy)`.slice(0,r.nameMax);for(let n=2;o.has(a);n++)a=`${e.name} (copy ${n})`.slice(0,r.nameMax);return p({...structuredClone(e),id:"",name:a,enabled:!1})}export function formFromLauncher(e){const t=p(e);return{enabled:t.enabled,showDisc:t.showDisc,name:t.name,label:t.label,tooltipMode:t.tooltipMode,tooltip:t.tooltip,icon:t.icon,triggerStyle:t.triggerStyle,position:t.position,offsetX:t.offsetX,offsetY:t.offsetY,size:t.size,radius:t.radius,devices:t.devices,phoneOverride:t.phone.override,phonePosition:t.phone.position,phoneOffsetX:t.phone.offsetX,phoneOffsetY:t.phone.offsetY,phoneSize:t.phone.size,background:t.colours.background,text:t.colours.text,cls:t.class,pagesMode:t.pages.mode,paths:t.pages.paths.join(`
2
- `),audience:t.audience,actionType:t.action.type,kind:t.action.kind,ref:t.action.ref,title:t.action.title,modalSize:t.action.size,side:t.action.side,width:t.action.width,customWidth:t.action.customWidth,widthUnit:t.action.widthUnit,modalHeight:t.action.height,customHeight:t.action.customHeight,heightUnit:t.action.heightUnit,greeting:t.chat.greeting,botName:t.chat.botName,bot:t.chat.bot,staff:t.chat.staff,askDetails:t.chat.askDetails,ai:t.chat.ai,aiUseSite:t.chat.aiUseSite,aiContext:t.chat.aiContext,aiRules:t.chat.aiRules,accent:t.chat.accent,accentText:t.chat.accentText,avatar:t.chat.avatar,chatSize:t.chat.size,chatWidth:t.chat.width,chatHeight:t.chat.height,chatResizable:t.chat.resizable,starters:t.chat.starters.join(`
3
- `),aiMaxPerChat:t.chat.aiMaxPerChat,personButton:t.chat.personButton,keepOwn:t.chat.keepDays>0,keepDays:t.chat.keepDays||90,times:t.chat.times}}export function launcherFromForm(e,t=""){return p({id:t,enabled:e.enabled,showDisc:e.showDisc,name:e.name,label:e.label,tooltipMode:e.tooltipMode,tooltip:e.tooltip,icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:{override:e.phoneOverride,position:e.phonePosition,offsetX:e.phoneOffsetX,offsetY:e.phoneOffsetY,size:e.phoneSize},colours:{background:e.background,text:e.text},class:e.cls,pages:{mode:e.pagesMode,paths:String(e.paths||"").split(/\n+/)},audience:e.audience,action:{type:e.actionType,kind:e.kind,ref:e.ref,title:e.title,size:e.modalSize,side:e.side,width:e.width,customWidth:e.customWidth,widthUnit:e.widthUnit,height:e.modalHeight,customHeight:e.customHeight,heightUnit:e.heightUnit},chat:{greeting:e.greeting,botName:e.botName,bot:e.bot,staff:e.staff,askDetails:e.askDetails,ai:e.ai,aiUseSite:e.aiUseSite,aiContext:e.aiContext,aiRules:e.aiRules,accent:e.accent,accentText:e.accentText,avatar:e.avatar,size:e.chatSize,width:e.chatWidth,height:e.chatHeight,resizable:e.chatResizable,starters:String(e.starters||"").split(`
4
- `),aiMaxPerChat:e.aiMaxPerChat,personButton:e.personButton,keepDays:e.keepOwn?e.keepDays:0,times:e.times}})}export function checkLauncherForm(e){const t={},o={};if(String(e.name||"").trim()||(t.name="Give it a name - only you see it."),String(e.label||"").trim()||(t.label="Visitors need words for it: they are read out, and shown on a pill."),e.actionType!=="chat"){const i=String(e.ref||"").trim();i?e.kind==="page"&&(!g(i)||i.includes("*"))?t.ref="A page address starts with / - e.g. /about.":e.kind!=="page"&&!/^[a-z0-9][a-z0-9_-]*$/i.test(i)&&(t.ref="Choose one from the list."):o.ref="Nothing chosen yet - the launcher stays off the page until it opens something."}const a=String(e.paths||"").split(/\n+/).map(i=>i.trim()).filter(Boolean),n=a.filter(i=>!g(i));n.length?t.paths=`Not an address: ${n.slice(0,3).join(", ")}`:a.length>r.pathsMax?t.paths=`At most ${r.pathsMax} rules.`:e.pagesMode==="only"&&!a.length&&(o.paths="With no pages listed it shows nowhere.");for(const i of["background","text","accent","accentText"]){const s=String(e[i]||"").trim();s&&!l(s)&&(t[i]="A theme colour, or a hex colour such as #3366ff.")}if(e.actionType==="chat"){const i=String(e.starters||"").split(`
1
+ import{LAUNCHER_DEFAULTS as b,LAUNCHER_LIMITS as r,LAUNCHER_POSITION_LABEL as u,launcherColourCss as p,launcherReady as x,launcherSpot as f,launcherAvatar as y,normaliseLauncher as l,normaliseLauncherPath as g}from"../../../public/js/launcher-settings.mjs";export const FILTERS=["all","on","off"];const m={modal:"Modal",slideover:"Slideover",chat:"Chat"},w={page:"page",form:"form",block:"block"};export function describeAction(e){const t=e.action;return t.type==="chat"?`Chat${e.chat.bot?" (bot first)":""}`:t.ref?`${m[t.type]}: ${t.kind==="page"?t.ref:`${w[t.kind]} ${t.ref}`}`:`${m[t.type]}: nothing chosen yet`}export function describeWhere(e){const t=e.pages.paths.length,o=e.pages.mode==="all"?"every page":e.pages.mode==="only"?t?`${t} page rule${t===1?"":"s"}`:"no pages":`every page but ${t} rule${t===1?"":"s"}`,a=e.audience==="signed-in"?", signed-in only":e.audience==="signed-out"?", signed-out only":"",n=e.devices==="desktop"?", desktop only":e.devices==="phone"?", phones only":"";return`${o}${a}${n}`}export function launcherProblem(e){return x(e)?e.pages.mode==="only"&&!e.pages.paths.length?"Shows on no pages":"":"Choose what it opens"}export function launcherRow(e){const t=launcherProblem(e),o=e.triggerStyle==="icon-text",a=p(e.colours.background)||"var(--dm-primary)",n=p(e.colours.text)||"var(--dm-primary-text)";return{id:e.id,name:e.name,meta:`${e.showDisc?u[e.position]:"No disc - opened from links"} \xB7 ${describeAction(e)} \xB7 ${describeWhere(e)}`,label:e.label,icon:e.icon,pill:o,off:!e.enabled,on:e.enabled,problem:t,rowCls:[e.enabled?"":"is-off",t&&e.enabled?"is-warn":""].filter(Boolean).join(" "),discStyle:{"--lnx-bg":a,"--lnx-fg":n,"border-radius":o?"999px":`${Math.round(e.radius/e.size*100)}%`}}}export function arrangeLaunchers(e,{filter:t="all",query:o=""}={}){const a=String(o||"").trim().toLowerCase();return e.filter(n=>t==="on"?n.enabled:t==="off"?!n.enabled:!0).filter(n=>!a||[n.name,n.label,n.action.ref,n.action.title].some(i=>String(i||"").toLowerCase().includes(a)))}export function countLaunchers(e){const t=e.filter(o=>o.enabled).length;return{all:e.length,on:t,off:e.length-t}}export function moveItem(e,t,o){const a=[...e];if(t<0||t>=a.length||o<0||o>=a.length||t===o)return a;const[n]=a.splice(t,1);return a.splice(o,0,n),a}export function blankLauncher(e=[]){const t=new Set(e.map(a=>a.name));let o="New launcher";for(let a=2;t.has(o);a++)o=`New launcher ${a}`;return l({name:o})}export function duplicateLauncher(e,t=[]){const o=new Set(t.map(n=>n.name));let a=`${e.name} (copy)`.slice(0,r.nameMax);for(let n=2;o.has(a);n++)a=`${e.name} (copy ${n})`.slice(0,r.nameMax);return l({...structuredClone(e),id:"",name:a,enabled:!1})}export function formFromLauncher(e){const t=l(e);return{enabled:t.enabled,showDisc:t.showDisc,name:t.name,label:t.label,tooltipMode:t.tooltipMode,tooltip:t.tooltip,icon:t.icon,triggerStyle:t.triggerStyle,position:t.position,offsetX:t.offsetX,offsetY:t.offsetY,size:t.size,radius:t.radius,devices:t.devices,phoneOverride:t.phone.override,phonePosition:t.phone.position,phoneOffsetX:t.phone.offsetX,phoneOffsetY:t.phone.offsetY,phoneSize:t.phone.size,background:t.colours.background,text:t.colours.text,cls:t.class,pagesMode:t.pages.mode,paths:t.pages.paths.join(`
2
+ `),audience:t.audience,actionType:t.action.type,kind:t.action.kind,ref:t.action.ref,title:t.action.title,modalSize:t.action.size,side:t.action.side,width:t.action.width,customWidth:t.action.customWidth,widthUnit:t.action.widthUnit,modalHeight:t.action.height,customHeight:t.action.customHeight,heightUnit:t.action.heightUnit,useDella:t.chat.character==="della",greeting:t.chat.greeting,botName:t.chat.botName,bot:t.chat.bot,staff:t.chat.staff,askDetails:t.chat.askDetails,ai:t.chat.ai,aiUseSite:t.chat.aiUseSite,aiContext:t.chat.aiContext,aiRules:t.chat.aiRules,accent:t.chat.accent,accentText:t.chat.accentText,avatar:t.chat.avatar,chatSize:t.chat.size,chatWidth:t.chat.width,chatHeight:t.chat.height,chatResizable:t.chat.resizable,starters:t.chat.starters.join(`
3
+ `),aiMaxPerChat:t.chat.aiMaxPerChat,personButton:t.chat.personButton,keepOwn:t.chat.keepDays>0,keepDays:t.chat.keepDays||90,times:t.chat.times}}export function launcherFromForm(e,t=""){return l({id:t,enabled:e.enabled,showDisc:e.showDisc,name:e.name,label:e.label,tooltipMode:e.tooltipMode,tooltip:e.tooltip,icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:{override:e.phoneOverride,position:e.phonePosition,offsetX:e.phoneOffsetX,offsetY:e.phoneOffsetY,size:e.phoneSize},colours:{background:e.background,text:e.text},class:e.cls,pages:{mode:e.pagesMode,paths:String(e.paths||"").split(/\n+/)},audience:e.audience,action:{type:e.actionType,kind:e.kind,ref:e.ref,title:e.title,size:e.modalSize,side:e.side,width:e.width,customWidth:e.customWidth,widthUnit:e.widthUnit,height:e.modalHeight,customHeight:e.customHeight,heightUnit:e.heightUnit},chat:{character:e.useDella?"della":"",greeting:e.greeting,botName:e.botName,bot:e.bot,staff:e.staff,askDetails:e.askDetails,ai:e.ai,aiUseSite:e.aiUseSite,aiContext:e.aiContext,aiRules:e.aiRules,accent:e.accent,accentText:e.accentText,avatar:e.avatar,size:e.chatSize,width:e.chatWidth,height:e.chatHeight,resizable:e.chatResizable,starters:String(e.starters||"").split(`
4
+ `),aiMaxPerChat:e.aiMaxPerChat,personButton:e.personButton,keepDays:e.keepOwn?e.keepDays:0,times:e.times}})}export function checkLauncherForm(e){const t={},o={};if(String(e.name||"").trim()||(t.name="Give it a name - only you see it."),String(e.label||"").trim()||(t.label="Visitors need words for it: they are read out, and shown on a pill."),e.actionType!=="chat"){const i=String(e.ref||"").trim();i?e.kind==="page"&&(!g(i)||i.includes("*"))?t.ref="A page address starts with / - e.g. /about.":e.kind!=="page"&&!/^[a-z0-9][a-z0-9_-]*$/i.test(i)&&(t.ref="Choose one from the list."):o.ref="Nothing chosen yet - the launcher stays off the page until it opens something."}const a=String(e.paths||"").split(/\n+/).map(i=>i.trim()).filter(Boolean),n=a.filter(i=>!g(i));n.length?t.paths=`Not an address: ${n.slice(0,3).join(", ")}`:a.length>r.pathsMax?t.paths=`At most ${r.pathsMax} rules.`:e.pagesMode==="only"&&!a.length&&(o.paths="With no pages listed it shows nowhere.");for(const i of["background","text","accent","accentText"]){const s=String(e[i]||"").trim();s&&!p(s)&&(t[i]="A theme colour, or a hex colour such as #3366ff.")}if(e.actionType==="chat"){const i=String(e.starters||"").split(`
5
5
  `).map(s=>s.trim()).filter(Boolean);if(i.length>r.startersMax?t.starters=`At most ${r.startersMax} questions.`:i.some(s=>s.length>r.starterMax)&&(t.starters=`Keep each to ${r.starterMax} characters.`),e.keepOwn&&!(Number(e.keepDays)>=1&&Number(e.keepDays)<=730)&&(t.keepDays="Between 1 and 730 days."),e.chatSize==="custom"){const[s,c]=r.chatWidth,[h,d]=r.chatHeight;Number(e.chatWidth)>=s&&Number(e.chatWidth)<=c||(t.chatWidth=`Between ${s} and ${c} pixels.`),Number(e.chatHeight)>=h&&Number(e.chatHeight)<=d||(t.chatHeight=`Between ${h} and ${d} pixels.`)}}return e.actionType==="chat"&&String(e.avatar||"").trim()&&!y(e.avatar)&&(t.avatar="Choose a picture from Media (an address on this site)."),{errors:t,warnings:o}}export function previewSpot(e,{vw:t=320,vh:o=200,scale:a=.5,phone:n=!1}={}){const i=n&&e.phoneOverride,s=Math.max(10,Math.round((i?e.phoneSize:e.size)*a)),c=e.triggerStyle==="icon-text"?Math.round(s*2.4):s,h=f(i?e.phonePosition:e.position,{w:c,h:s,vw:t,vh:o,offsetX:Math.round((i?e.phoneOffsetX:e.offsetX)*a),offsetY:Math.round((i?e.phoneOffsetY:e.offsetY)*a)});return{left:Math.max(0,Math.min(t-c,h.left)),top:Math.max(0,Math.min(o-s,h.top)),size:s,w:c}}export{b as LAUNCHER_DEFAULTS,u as LAUNCHER_POSITION_LABEL};
@@ -1,3 +1,3 @@
1
- export const TAB_FIELDS={general:["title","tagline","siteUrl","adminHome","spacerSize","bodyClass","aiContext","aiRules"],branding:["brandEnabled","brandText","brandLogo","brandIcon","brandUrl","adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandLogoDark","adminBrandIcon"],favicon:["favicon"],footer:["footerCopyright","footerLayout","footerBlurb","footerBlocks","footerClass","footerSocialClass","footerLook","footerCtaText","footerCtaHighlight","footerCtaUrl","footerCtaSub","footerWatermark","footerStatus","footerFacts","footerTagline","footerEmail","footerAddress","footerGradFrom","footerGradTo","socialTwitter","socialFacebook","socialInstagram","socialLinkedin","socialGithub","socialYoutube"],email:["smtpHost","smtpPort","smtpUser","smtpPass","smtpSecure","smtpInsecureTLS","smtpFromAddress","smtpFromName"],pageNavigation:["bttEnabled","bttSmooth","bttLabel","bttThreshold","bttPosition","bttOffset","bttBottomOffset","gtbEnabled","gtbSmooth","gtbLabel","gtbThreshold","gtbPosition","gtbOffset","gtbBottomOffset"],cookies:["ccEnabled","ccMessage","ccAcceptAll","ccRejectAll","ccCustomize","ccSavePrefs","ccPrivacyText","ccPrivacyUrl","ccCookieText","ccCookieUrl","ccPosition","ccLayout","ccTheme","ccShowFunctional","ccShowAnalytics","ccShowMarketing","ccVersion","ccSettingsLink","ccSettingsLinkText"],breadcrumbs:["bcEnabled","bcHomeLabel","bcPosition","bcOffsetX","bcOffsetY"],motion:["mtEnabled","mtLabel","mtDefault","mtControl","mtPlacement","mtTriggerStyle","mtPosition","mtOffsetX","mtOffsetY","mtIconSize","mtIconRadius","mtClass"]},SECRET_FIELDS=["smtpPass"],BREADCRUMB_POSITIONS=["TL","TR","BL","BR"],MOTION_PLACEMENTS=["footer","floating","navbar"],MOTION_LABEL="Reduce motion";const d=["system","off","on"],c=(t,r,n,o)=>{const a=Number.parseInt(t,10);return Number.isFinite(a)?Math.min(o,Math.max(n,a)):r};export function motionFromSettings(t={}){const r=t.motion&&typeof t.motion=="object"?t.motion:{},n=t.footer||{},o=m=>r[m]!==void 0&&r[m]!==null,a=o("default")?r.default:n.motionDefault,i=o("control")?r.control:n.motionControl,l=c(r.iconSize,52,32,96);return{mtEnabled:(o("enabled")?r.enabled:n.showMotionToggle)!==!1,mtLabel:typeof r.label=="string"&&r.label.trim()?r.label.trim():MOTION_LABEL,mtDefault:d.includes(a)?a:"system",mtControl:i==="checkbox"?"checkbox":"switch",mtPlacement:MOTION_PLACEMENTS.includes(r.placement)?r.placement:"footer",mtTriggerStyle:r.triggerStyle==="icon-text"?"icon-text":"icon",mtPosition:BREADCRUMB_POSITIONS.includes(r.position)?r.position:"BL",mtOffsetX:e(c(r.offsetX,32,0,500)),mtOffsetY:e(c(r.offsetY,32,0,500)),mtIconSize:e(l),mtIconRadius:e(c(r.iconRadius,26,0,Math.floor(l/2))),mtClass:e(r.class)}}export function motionFromForm(t){const r=c(t.mtIconSize,52,32,96);return{enabled:t.mtEnabled===!0,default:d.includes(t.mtDefault)?t.mtDefault:"system",placement:MOTION_PLACEMENTS.includes(t.mtPlacement)?t.mtPlacement:"footer",control:t.mtControl==="checkbox"?"checkbox":"switch",triggerStyle:t.mtTriggerStyle==="icon-text"?"icon-text":"icon",label:e(t.mtLabel).trim().replace(/\s+/g," ").slice(0,40)||MOTION_LABEL,position:BREADCRUMB_POSITIONS.includes(t.mtPosition)?t.mtPosition:"BL",offsetX:c(t.mtOffsetX,32,0,500),offsetY:c(t.mtOffsetY,32,0,500),iconSize:r,iconRadius:c(t.mtIconRadius,26,0,Math.floor(r/2)),class:e(t.mtClass).trim()}}export function footerBlockNames(t){return[...new Set(String(t??"").split(/[\s,]+/).map(r=>r.trim().toLowerCase()).filter(Boolean))]}export function gaIdError(t){const r=e(t).trim();return!r||/^G-[A-Z0-9]{4,20}$/i.test(r)?"":"A measurement ID looks like G-XXXXXXXXXX (Google Analytics > Admin > Data streams)."}export const FOOTER_LAYOUTS=["auto","columns","row"],FOOTER_LOOKS=["","showcase"],FOOTER_FACTS_MAX=4;const p=/^(\/|#|https?:\/\/|mailto:)/,g=/^#[0-9a-f]{6}$/i;export function footerShowcaseErrors(t){const r=[],n=e(t.footerCtaUrl).trim();n&&!p.test(n)&&r.push("The footer call to action link must start with /, #, https:// or mailto: (Footer tool).");for(const[o,a]of[["from",t.footerGradFrom],["to",t.footerGradTo]]){const i=e(a).trim();i&&!g.test(i)&&r.push(`The footer gradient "${o}" colour must look like #f26b3a (Footer tool).`)}return r}const e=(t,r="")=>t==null?r:String(t),s=(t,r)=>{const n=Number.parseInt(t,10);return Number.isFinite(n)?n:r};export function homeValue(t){return/^\/[A-Za-z0-9\-_/]*$/.test(t||"")&&String(t).replace(/\/+$/,"")||"/"}export function formFromSettings(t={}){const r=t.backToTop||{},n=t.goToBottom||{},o=t.cookieConsent||{},a=t.breadcrumbs||{};return{title:e(t.title),tagline:e(t.tagline),siteUrl:e(t.baseUrl),adminHome:homeValue(t.adminHome),spacerSize:e(t.layoutOptions?.spacerSize??40),bodyClass:e(t.bodyClass),aiContext:e(t.assistant?.context),aiRules:e(t.assistant?.rules),brandEnabled:t.brand?.enabled!==!1,brandText:e(t.brand?.text),brandLogo:e(t.brand?.logo),brandIcon:e(t.brand?.icon),brandUrl:e(t.brand?.url,"/"),favicon:e(t.favicon),adminBrandEnabled:t.adminBrand?.enabled!==!1,adminBrandTitle:e(t.adminBrand?.title),adminBrandLogo:e(t.adminBrand?.logo),adminBrandLogoDark:e(t.adminBrand?.logoDark),adminBrandIcon:e(t.adminBrand?.icon),footerCopyright:e(t.footer?.copyright),footerLayout:FOOTER_LAYOUTS.includes(t.footer?.layout)?t.footer.layout:"auto",footerBlurb:e(t.footer?.blurb),footerBlocks:Array.isArray(t.footer?.blocks)?t.footer.blocks.filter(i=>typeof i=="string").join(", "):"",footerClass:e(t.footer?.class),footerSocialClass:e(t.footer?.socialClass),footerLook:FOOTER_LOOKS.includes(t.footer?.look)?t.footer.look:"",footerCtaText:e(t.footer?.cta?.text),footerCtaHighlight:e(t.footer?.cta?.highlight),footerCtaUrl:e(t.footer?.cta?.url),footerCtaSub:e(t.footer?.cta?.sub),footerWatermark:e(t.footer?.watermark),footerStatus:e(t.footer?.status),footerFacts:Array.isArray(t.footer?.facts)?t.footer.facts.filter(i=>typeof i=="string").join(`
2
- `):"",footerTagline:e(t.footer?.tagline),footerEmail:e(t.footer?.email),footerAddress:e(t.footer?.address),footerGradFrom:e(t.footer?.gradient?.from),footerGradTo:e(t.footer?.gradient?.to),socialTwitter:e(t.social?.twitter),socialFacebook:e(t.social?.facebook),socialInstagram:e(t.social?.instagram),socialLinkedin:e(t.social?.linkedin),socialGithub:e(t.social?.github),socialYoutube:e(t.social?.youtube),smtpHost:e(t.smtp?.host),smtpPort:e(t.smtp?.port||587),smtpUser:e(t.smtp?.user),smtpPass:"",smtpSecure:t.smtp?.secure===!0,smtpInsecureTLS:t.smtp?.allowInsecureTLS===!0,smtpFromAddress:e(t.smtp?.fromAddress),smtpFromName:e(t.smtp?.fromName),bttEnabled:r.enabled!==!1,bttSmooth:r.smooth!==!1,bttLabel:e(r.label),bttThreshold:e(r.scrollThreshold??300),bttPosition:e(r.position,"bottom-right"),bttOffset:e(r.offset??32),bttBottomOffset:e(r.bottomOffset??r.offset??32),gtbEnabled:n.enabled===!0,gtbSmooth:n.smooth!==!1,gtbLabel:e(n.label),gtbThreshold:e(n.scrollThreshold??300),gtbPosition:e(n.position,"bottom-right"),gtbOffset:e(n.offset??32),gtbBottomOffset:e(n.bottomOffset??n.offset??32),ccEnabled:o.enabled!==!1,ccMessage:e(o.message),ccAcceptAll:e(o.acceptAllText,"Accept All"),ccRejectAll:e(o.rejectAllText,"Reject All"),ccCustomize:e(o.customizeText,"Customize"),ccSavePrefs:e(o.savePreferencesText,"Save Preferences"),ccPrivacyText:e(o.privacyPolicyText,"Privacy Policy"),ccPrivacyUrl:e(o.privacyPolicyUrl),ccCookieText:e(o.cookiePolicyText,"Cookie Policy"),ccCookieUrl:e(o.cookiePolicyUrl),ccPosition:e(o.position,"bottom"),ccLayout:e(o.layout,"bar"),ccTheme:e(o.theme,"dark"),ccShowFunctional:o.showFunctional!==!1,ccShowAnalytics:o.showAnalytics!==!1,ccShowMarketing:o.showMarketing!==!1,ccVersion:e(o.consentVersion,"1.0"),ccSettingsLink:o.showSettingsLink!==!1,ccSettingsLinkText:e(o.settingsLinkText,"Cookie settings"),bcEnabled:a.enabled===!0,bcHomeLabel:e(a.homeLabel,"Home"),bcPosition:BREADCRUMB_POSITIONS.includes(a.position)?a.position:"TL",bcOffsetX:e(a.offsetX??8),bcOffsetY:e(a.offsetY??8),...motionFromSettings(t)}}export function payloadFromForm(t,r={},{adminHomeReady:n=!0}={}){const o=i=>e(i).trim(),a=motionFromForm(t);return{title:o(t.title),tagline:o(t.tagline),baseUrl:o(t.siteUrl).replace(/\/+$/,""),...n&&{adminHome:o(t.adminHome)||"/"},layoutOptions:{spacerSize:s(t.spacerSize,40)||40},bodyClass:o(t.bodyClass),assistant:{context:o(t.aiContext),rules:o(t.aiRules)},brand:{...r.brand,enabled:t.brandEnabled!==!1,text:o(t.brandText),logo:o(t.brandLogo),icon:o(t.brandIcon),url:o(t.brandUrl)||"/"},favicon:o(t.favicon),adminBrand:{...r.adminBrand,enabled:t.adminBrandEnabled!==!1,title:o(t.adminBrandTitle),logo:o(t.adminBrandLogo),logoDark:o(t.adminBrandLogoDark),icon:o(t.adminBrandIcon)},footer:{copyright:o(t.footerCopyright),layout:FOOTER_LAYOUTS.includes(t.footerLayout)?t.footerLayout:"auto",blurb:o(t.footerBlurb),blocks:footerBlockNames(t.footerBlocks),links:r.footer?.links||[],showMotionToggle:a.enabled,motionDefault:a.default,motionControl:a.control,class:o(t.footerClass),socialClass:o(t.footerSocialClass),look:FOOTER_LOOKS.includes(t.footerLook)?t.footerLook:"",cta:{text:o(t.footerCtaText),highlight:o(t.footerCtaHighlight),url:o(t.footerCtaUrl),sub:o(t.footerCtaSub)},watermark:o(t.footerWatermark),status:o(t.footerStatus),facts:String(t.footerFacts??"").split(`
3
- `).map(i=>i.trim()).filter(Boolean).slice(0,FOOTER_FACTS_MAX),tagline:o(t.footerTagline),email:o(t.footerEmail),address:o(t.footerAddress),gradient:{from:o(t.footerGradFrom),to:o(t.footerGradTo)}},social:{twitter:o(t.socialTwitter),facebook:o(t.socialFacebook),instagram:o(t.socialInstagram),linkedin:o(t.socialLinkedin),github:o(t.socialGithub),youtube:o(t.socialYoutube)},smtp:{host:o(t.smtpHost),port:s(t.smtpPort,587)||587,user:o(t.smtpUser),pass:e(t.smtpPass),secure:t.smtpSecure===!0,allowInsecureTLS:t.smtpInsecureTLS===!0,fromAddress:o(t.smtpFromAddress),fromName:o(t.smtpFromName)},backToTop:{enabled:t.bttEnabled===!0,scrollThreshold:s(t.bttThreshold,300),position:e(t.bttPosition)||"bottom-right",offset:s(t.bttOffset,32),bottomOffset:s(t.bttBottomOffset,32),label:o(t.bttLabel),smooth:t.bttSmooth===!0},goToBottom:{enabled:t.gtbEnabled===!0,scrollThreshold:s(t.gtbThreshold,300),position:e(t.gtbPosition)||"bottom-right",offset:s(t.gtbOffset,32),bottomOffset:s(t.gtbBottomOffset,32),label:o(t.gtbLabel),smooth:t.gtbSmooth===!0},cookieConsent:{enabled:t.ccEnabled===!0,message:o(t.ccMessage),acceptAllText:o(t.ccAcceptAll),rejectAllText:o(t.ccRejectAll),customizeText:o(t.ccCustomize),savePreferencesText:o(t.ccSavePrefs),privacyPolicyText:o(t.ccPrivacyText),privacyPolicyUrl:o(t.ccPrivacyUrl),cookiePolicyText:o(t.ccCookieText),cookiePolicyUrl:o(t.ccCookieUrl),position:e(t.ccPosition)||"bottom",layout:e(t.ccLayout)||"bar",theme:e(t.ccTheme)||"dark",showFunctional:t.ccShowFunctional===!0,showAnalytics:t.ccShowAnalytics===!0,showMarketing:t.ccShowMarketing===!0,consentVersion:o(t.ccVersion)||"1.0",showSettingsLink:t.ccSettingsLink===!0,settingsLinkText:o(t.ccSettingsLinkText)||"Cookie settings"},breadcrumbs:{enabled:t.bcEnabled===!0,homeLabel:o(t.bcHomeLabel)||"Home",position:BREADCRUMB_POSITIONS.includes(t.bcPosition)?t.bcPosition:"TL",offsetX:s(t.bcOffsetX,8),offsetY:s(t.bcOffsetY,8)},motion:a}}export function siteUrlError(t){const r=e(t).trim().replace(/\/+$/,"");return r?/^https?:\/\//i.test(r)?/^https?:\/\/([a-z0-9.\-]+|\[[0-9a-f:.]+\])(:\d{1,5})?$/i.test(r)?"":"Just the address, like https://example.com - no page path after it.":"Start with https:// (or http://).":""}const b=t=>typeof t=="boolean"?t:e(t);export function snapshot(t){return JSON.stringify(Object.keys(t).sort().map(r=>[r,b(t[r])]))}export function changedTabs(t,r){const n=[];for(const[o,a]of Object.entries(TAB_FIELDS))a.some(i=>b(t[i])!==b(r[i]))&&n.push(o);return n}export function draftOf(t){return Object.fromEntries(Object.entries(t).filter(([r])=>!SECRET_FIELDS.includes(r)))}const h={footerMotionToggle:"mtEnabled",footerMotionDefault:"mtDefault",footerMotionControl:"mtControl"};export function formFromDraft(t,r={}){const n={...r};for(const[a,i]of Object.entries(h))a in n&&!(i in n)&&(n[i]=n[a]),delete n[a];const o={...t};for(const[a,i]of Object.entries(n))a in o&&!SECRET_FIELDS.includes(a)&&(o[a]=i);return o}export function settingsProblems(t,r={}){const n=[];return e(t.smtpHost).trim()?e(t.smtpFromAddress).trim()||n.push({tone:"warn",tab:"email",text:"No From address - mail has no sender and many servers refuse it."}):n.push({tone:"danger",tab:"email",text:"No SMTP host - mail goes to a throwaway test inbox and reaches no one (password resets, form notifications)."}),(t.ccEnabled===!0||e(r.googleAnalytics?.measurementId).trim())&&!e(t.ccPrivacyUrl).trim()&&n.push({tone:"warn",tab:"cookies",text:"The cookie banner is on but links to no privacy policy."}),n}export function describeCacheKey(t){const r=/^page:(.*?):m\d+:role([^:]*):/.exec(String(t||""));return r?{path:r[1]||"/",role:r[2]||"anon",page:!0}:{path:String(t||""),role:"",page:!1}}export function expiresIn(t,r=Date.now()){if(t==null)return"no expiry";const n=t-r;return n<=0?"expired":n<6e4?`${Math.round(n/1e3)}s`:n<36e5?`${Math.round(n/6e4)}m`:`${Math.round(n/36e5)}h`}export function footerForm(t={}){const r=formFromSettings(t);return Object.fromEntries(TAB_FIELDS.footer.map(n=>[n,r[n]]))}export function footerPayload(t){const{footer:r,social:n}=payloadFromForm(t);return delete r.links,delete r.showMotionToggle,delete r.motionDefault,delete r.motionControl,{footer:r,social:n}}export function siteSettingsForm(t={}){return Object.fromEntries(Object.entries(formFromSettings(t)).filter(([r])=>!TAB_FIELDS.footer.includes(r)&&!u.includes(r)))}export function siteSettingsPayload(...t){const{footer:r,social:n,favicon:o,backToTop:a,goToBottom:i,breadcrumbs:l,motion:m,...f}=payloadFromForm(...t);return f}export const APPEARANCE_TABS=["favicon","pageNavigation","breadcrumbs","motion","search"];const u=APPEARANCE_TABS.flatMap(t=>TAB_FIELDS[t]||[]);export function appearanceForm(t={}){const r=formFromSettings(t);return Object.fromEntries(u.map(n=>[n,r[n]]))}export function appearancePayload(t){const{favicon:r,backToTop:n,goToBottom:o,breadcrumbs:a,motion:i}=payloadFromForm(t);return{favicon:r,backToTop:n,goToBottom:o,breadcrumbs:a,motion:i}}
1
+ export const TAB_FIELDS={general:["title","tagline","siteUrl","adminHome","spacerSize","bodyClass","aiContext","aiRules","charactersEnabled","charactersAnimated","charactersLaunchers","charactersChats","charactersBuilders","charactersDot","charactersDaisy"],branding:["brandEnabled","brandText","brandLogo","brandIcon","brandUrl","adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandLogoDark","adminBrandIcon"],favicon:["favicon"],footer:["footerCopyright","footerLayout","footerBlurb","footerBlocks","footerClass","footerSocialClass","footerLook","footerCtaText","footerCtaHighlight","footerCtaUrl","footerCtaSub","footerWatermark","footerStatus","footerFacts","footerTagline","footerEmail","footerAddress","footerGradFrom","footerGradTo","socialTwitter","socialFacebook","socialInstagram","socialLinkedin","socialGithub","socialYoutube"],email:["smtpHost","smtpPort","smtpUser","smtpPass","smtpSecure","smtpInsecureTLS","smtpFromAddress","smtpFromName"],pageNavigation:["bttEnabled","bttSmooth","bttLabel","bttThreshold","bttPosition","bttOffset","bttBottomOffset","gtbEnabled","gtbSmooth","gtbLabel","gtbThreshold","gtbPosition","gtbOffset","gtbBottomOffset"],cookies:["ccEnabled","ccMessage","ccAcceptAll","ccRejectAll","ccCustomize","ccSavePrefs","ccPrivacyText","ccPrivacyUrl","ccCookieText","ccCookieUrl","ccPosition","ccLayout","ccTheme","ccShowFunctional","ccShowAnalytics","ccShowMarketing","ccVersion","ccSettingsLink","ccSettingsLinkText"],breadcrumbs:["bcEnabled","bcHomeLabel","bcPosition","bcOffsetX","bcOffsetY"],motion:["mtEnabled","mtLabel","mtDefault","mtControl","mtPlacement","mtTriggerStyle","mtPosition","mtOffsetX","mtOffsetY","mtIconSize","mtIconRadius","mtClass"]},SECRET_FIELDS=["smtpPass"],BREADCRUMB_POSITIONS=["TL","TR","BL","BR"],MOTION_PLACEMENTS=["footer","floating","navbar"],MOTION_LABEL="Reduce motion";const b=["system","off","on"],i=(t,r,a,o)=>{const n=Number.parseInt(t,10);return Number.isFinite(n)?Math.min(o,Math.max(a,n)):r};export function motionFromSettings(t={}){const r=t.motion&&typeof t.motion=="object"?t.motion:{},a=t.footer||{},o=m=>r[m]!==void 0&&r[m]!==null,n=o("default")?r.default:a.motionDefault,s=o("control")?r.control:a.motionControl,l=i(r.iconSize,52,32,96);return{mtEnabled:(o("enabled")?r.enabled:a.showMotionToggle)!==!1,mtLabel:typeof r.label=="string"&&r.label.trim()?r.label.trim():MOTION_LABEL,mtDefault:b.includes(n)?n:"system",mtControl:s==="checkbox"?"checkbox":"switch",mtPlacement:MOTION_PLACEMENTS.includes(r.placement)?r.placement:"footer",mtTriggerStyle:r.triggerStyle==="icon-text"?"icon-text":"icon",mtPosition:BREADCRUMB_POSITIONS.includes(r.position)?r.position:"BL",mtOffsetX:e(i(r.offsetX,32,0,500)),mtOffsetY:e(i(r.offsetY,32,0,500)),mtIconSize:e(l),mtIconRadius:e(i(r.iconRadius,26,0,Math.floor(l/2))),mtClass:e(r.class)}}export function motionFromForm(t){const r=i(t.mtIconSize,52,32,96);return{enabled:t.mtEnabled===!0,default:b.includes(t.mtDefault)?t.mtDefault:"system",placement:MOTION_PLACEMENTS.includes(t.mtPlacement)?t.mtPlacement:"footer",control:t.mtControl==="checkbox"?"checkbox":"switch",triggerStyle:t.mtTriggerStyle==="icon-text"?"icon-text":"icon",label:e(t.mtLabel).trim().replace(/\s+/g," ").slice(0,40)||MOTION_LABEL,position:BREADCRUMB_POSITIONS.includes(t.mtPosition)?t.mtPosition:"BL",offsetX:i(t.mtOffsetX,32,0,500),offsetY:i(t.mtOffsetY,32,0,500),iconSize:r,iconRadius:i(t.mtIconRadius,26,0,Math.floor(r/2)),class:e(t.mtClass).trim()}}export function footerBlockNames(t){return[...new Set(String(t??"").split(/[\s,]+/).map(r=>r.trim().toLowerCase()).filter(Boolean))]}export function gaIdError(t){const r=e(t).trim();return!r||/^G-[A-Z0-9]{4,20}$/i.test(r)?"":"A measurement ID looks like G-XXXXXXXXXX (Google Analytics > Admin > Data streams)."}export const FOOTER_LAYOUTS=["auto","columns","row"],FOOTER_LOOKS=["","showcase"],FOOTER_FACTS_MAX=4;const h=/^(\/|#|https?:\/\/|mailto:)/,p=/^#[0-9a-f]{6}$/i;export function footerShowcaseErrors(t){const r=[],a=e(t.footerCtaUrl).trim();a&&!h.test(a)&&r.push("The footer call to action link must start with /, #, https:// or mailto: (Footer tool).");for(const[o,n]of[["from",t.footerGradFrom],["to",t.footerGradTo]]){const s=e(n).trim();s&&!p.test(s)&&r.push(`The footer gradient "${o}" colour must look like #f26b3a (Footer tool).`)}return r}const e=(t,r="")=>t==null?r:String(t),c=(t,r)=>{const a=Number.parseInt(t,10);return Number.isFinite(a)?a:r};export function homeValue(t){return/^\/[A-Za-z0-9\-_/]*$/.test(t||"")&&String(t).replace(/\/+$/,"")||"/"}export function formFromSettings(t={}){const r=t.backToTop||{},a=t.goToBottom||{},o=t.cookieConsent||{},n=t.breadcrumbs||{};return{title:e(t.title),tagline:e(t.tagline),siteUrl:e(t.baseUrl),adminHome:homeValue(t.adminHome),spacerSize:e(t.layoutOptions?.spacerSize??40),bodyClass:e(t.bodyClass),aiContext:e(t.assistant?.context),aiRules:e(t.assistant?.rules),charactersEnabled:t.characters?.enabled!==!1,charactersAnimated:t.characters?.animated!==!1,charactersLaunchers:t.characters?.launchers!==!1,charactersChats:t.characters?.chats!==!1,charactersBuilders:t.characters?.builders!==!1,charactersDot:t.characters?.dot!==!1,charactersDaisy:t.characters?.daisy!==!1,brandEnabled:t.brand?.enabled!==!1,brandText:e(t.brand?.text),brandLogo:e(t.brand?.logo),brandIcon:e(t.brand?.icon),brandUrl:e(t.brand?.url,"/"),favicon:e(t.favicon),adminBrandEnabled:t.adminBrand?.enabled!==!1,adminBrandTitle:e(t.adminBrand?.title),adminBrandLogo:e(t.adminBrand?.logo),adminBrandLogoDark:e(t.adminBrand?.logoDark),adminBrandIcon:e(t.adminBrand?.icon),footerCopyright:e(t.footer?.copyright),footerLayout:FOOTER_LAYOUTS.includes(t.footer?.layout)?t.footer.layout:"auto",footerBlurb:e(t.footer?.blurb),footerBlocks:Array.isArray(t.footer?.blocks)?t.footer.blocks.filter(s=>typeof s=="string").join(", "):"",footerClass:e(t.footer?.class),footerSocialClass:e(t.footer?.socialClass),footerLook:FOOTER_LOOKS.includes(t.footer?.look)?t.footer.look:"",footerCtaText:e(t.footer?.cta?.text),footerCtaHighlight:e(t.footer?.cta?.highlight),footerCtaUrl:e(t.footer?.cta?.url),footerCtaSub:e(t.footer?.cta?.sub),footerWatermark:e(t.footer?.watermark),footerStatus:e(t.footer?.status),footerFacts:Array.isArray(t.footer?.facts)?t.footer.facts.filter(s=>typeof s=="string").join(`
2
+ `):"",footerTagline:e(t.footer?.tagline),footerEmail:e(t.footer?.email),footerAddress:e(t.footer?.address),footerGradFrom:e(t.footer?.gradient?.from),footerGradTo:e(t.footer?.gradient?.to),socialTwitter:e(t.social?.twitter),socialFacebook:e(t.social?.facebook),socialInstagram:e(t.social?.instagram),socialLinkedin:e(t.social?.linkedin),socialGithub:e(t.social?.github),socialYoutube:e(t.social?.youtube),smtpHost:e(t.smtp?.host),smtpPort:e(t.smtp?.port||587),smtpUser:e(t.smtp?.user),smtpPass:"",smtpSecure:t.smtp?.secure===!0,smtpInsecureTLS:t.smtp?.allowInsecureTLS===!0,smtpFromAddress:e(t.smtp?.fromAddress),smtpFromName:e(t.smtp?.fromName),bttEnabled:r.enabled!==!1,bttSmooth:r.smooth!==!1,bttLabel:e(r.label),bttThreshold:e(r.scrollThreshold??300),bttPosition:e(r.position,"bottom-right"),bttOffset:e(r.offset??32),bttBottomOffset:e(r.bottomOffset??r.offset??32),gtbEnabled:a.enabled===!0,gtbSmooth:a.smooth!==!1,gtbLabel:e(a.label),gtbThreshold:e(a.scrollThreshold??300),gtbPosition:e(a.position,"bottom-right"),gtbOffset:e(a.offset??32),gtbBottomOffset:e(a.bottomOffset??a.offset??32),ccEnabled:o.enabled!==!1,ccMessage:e(o.message),ccAcceptAll:e(o.acceptAllText,"Accept All"),ccRejectAll:e(o.rejectAllText,"Reject All"),ccCustomize:e(o.customizeText,"Customize"),ccSavePrefs:e(o.savePreferencesText,"Save Preferences"),ccPrivacyText:e(o.privacyPolicyText,"Privacy Policy"),ccPrivacyUrl:e(o.privacyPolicyUrl),ccCookieText:e(o.cookiePolicyText,"Cookie Policy"),ccCookieUrl:e(o.cookiePolicyUrl),ccPosition:e(o.position,"bottom"),ccLayout:e(o.layout,"bar"),ccTheme:e(o.theme,"dark"),ccShowFunctional:o.showFunctional!==!1,ccShowAnalytics:o.showAnalytics!==!1,ccShowMarketing:o.showMarketing!==!1,ccVersion:e(o.consentVersion,"1.0"),ccSettingsLink:o.showSettingsLink!==!1,ccSettingsLinkText:e(o.settingsLinkText,"Cookie settings"),bcEnabled:n.enabled===!0,bcHomeLabel:e(n.homeLabel,"Home"),bcPosition:BREADCRUMB_POSITIONS.includes(n.position)?n.position:"TL",bcOffsetX:e(n.offsetX??8),bcOffsetY:e(n.offsetY??8),...motionFromSettings(t)}}export function payloadFromForm(t,r={},{adminHomeReady:a=!0}={}){const o=s=>e(s).trim(),n=motionFromForm(t);return{title:o(t.title),tagline:o(t.tagline),baseUrl:o(t.siteUrl).replace(/\/+$/,""),...a&&{adminHome:o(t.adminHome)||"/"},layoutOptions:{spacerSize:c(t.spacerSize,40)||40},bodyClass:o(t.bodyClass),assistant:{context:o(t.aiContext),rules:o(t.aiRules)},characters:{enabled:t.charactersEnabled!==!1,animated:t.charactersAnimated!==!1,launchers:t.charactersLaunchers!==!1,chats:t.charactersChats!==!1,builders:t.charactersBuilders!==!1,dot:t.charactersDot!==!1,daisy:t.charactersDaisy!==!1},brand:{...r.brand,enabled:t.brandEnabled!==!1,text:o(t.brandText),logo:o(t.brandLogo),icon:o(t.brandIcon),url:o(t.brandUrl)||"/"},favicon:o(t.favicon),adminBrand:{...r.adminBrand,enabled:t.adminBrandEnabled!==!1,title:o(t.adminBrandTitle),logo:o(t.adminBrandLogo),logoDark:o(t.adminBrandLogoDark),icon:o(t.adminBrandIcon)},footer:{copyright:o(t.footerCopyright),layout:FOOTER_LAYOUTS.includes(t.footerLayout)?t.footerLayout:"auto",blurb:o(t.footerBlurb),blocks:footerBlockNames(t.footerBlocks),links:r.footer?.links||[],showMotionToggle:n.enabled,motionDefault:n.default,motionControl:n.control,class:o(t.footerClass),socialClass:o(t.footerSocialClass),look:FOOTER_LOOKS.includes(t.footerLook)?t.footerLook:"",cta:{text:o(t.footerCtaText),highlight:o(t.footerCtaHighlight),url:o(t.footerCtaUrl),sub:o(t.footerCtaSub)},watermark:o(t.footerWatermark),status:o(t.footerStatus),facts:String(t.footerFacts??"").split(`
3
+ `).map(s=>s.trim()).filter(Boolean).slice(0,FOOTER_FACTS_MAX),tagline:o(t.footerTagline),email:o(t.footerEmail),address:o(t.footerAddress),gradient:{from:o(t.footerGradFrom),to:o(t.footerGradTo)}},social:{twitter:o(t.socialTwitter),facebook:o(t.socialFacebook),instagram:o(t.socialInstagram),linkedin:o(t.socialLinkedin),github:o(t.socialGithub),youtube:o(t.socialYoutube)},smtp:{host:o(t.smtpHost),port:c(t.smtpPort,587)||587,user:o(t.smtpUser),pass:e(t.smtpPass),secure:t.smtpSecure===!0,allowInsecureTLS:t.smtpInsecureTLS===!0,fromAddress:o(t.smtpFromAddress),fromName:o(t.smtpFromName)},backToTop:{enabled:t.bttEnabled===!0,scrollThreshold:c(t.bttThreshold,300),position:e(t.bttPosition)||"bottom-right",offset:c(t.bttOffset,32),bottomOffset:c(t.bttBottomOffset,32),label:o(t.bttLabel),smooth:t.bttSmooth===!0},goToBottom:{enabled:t.gtbEnabled===!0,scrollThreshold:c(t.gtbThreshold,300),position:e(t.gtbPosition)||"bottom-right",offset:c(t.gtbOffset,32),bottomOffset:c(t.gtbBottomOffset,32),label:o(t.gtbLabel),smooth:t.gtbSmooth===!0},cookieConsent:{enabled:t.ccEnabled===!0,message:o(t.ccMessage),acceptAllText:o(t.ccAcceptAll),rejectAllText:o(t.ccRejectAll),customizeText:o(t.ccCustomize),savePreferencesText:o(t.ccSavePrefs),privacyPolicyText:o(t.ccPrivacyText),privacyPolicyUrl:o(t.ccPrivacyUrl),cookiePolicyText:o(t.ccCookieText),cookiePolicyUrl:o(t.ccCookieUrl),position:e(t.ccPosition)||"bottom",layout:e(t.ccLayout)||"bar",theme:e(t.ccTheme)||"dark",showFunctional:t.ccShowFunctional===!0,showAnalytics:t.ccShowAnalytics===!0,showMarketing:t.ccShowMarketing===!0,consentVersion:o(t.ccVersion)||"1.0",showSettingsLink:t.ccSettingsLink===!0,settingsLinkText:o(t.ccSettingsLinkText)||"Cookie settings"},breadcrumbs:{enabled:t.bcEnabled===!0,homeLabel:o(t.bcHomeLabel)||"Home",position:BREADCRUMB_POSITIONS.includes(t.bcPosition)?t.bcPosition:"TL",offsetX:c(t.bcOffsetX,8),offsetY:c(t.bcOffsetY,8)},motion:n}}export function siteUrlError(t){const r=e(t).trim().replace(/\/+$/,"");return r?/^https?:\/\//i.test(r)?/^https?:\/\/([a-z0-9.\-]+|\[[0-9a-f:.]+\])(:\d{1,5})?$/i.test(r)?"":"Just the address, like https://example.com - no page path after it.":"Start with https:// (or http://).":""}const d=t=>typeof t=="boolean"?t:e(t);export function snapshot(t){return JSON.stringify(Object.keys(t).sort().map(r=>[r,d(t[r])]))}export function changedTabs(t,r){const a=[];for(const[o,n]of Object.entries(TAB_FIELDS))n.some(s=>d(t[s])!==d(r[s]))&&a.push(o);return a}export function draftOf(t){return Object.fromEntries(Object.entries(t).filter(([r])=>!SECRET_FIELDS.includes(r)))}const g={footerMotionToggle:"mtEnabled",footerMotionDefault:"mtDefault",footerMotionControl:"mtControl"};export function formFromDraft(t,r={}){const a={...r};for(const[n,s]of Object.entries(g))n in a&&!(s in a)&&(a[s]=a[n]),delete a[n];const o={...t};for(const[n,s]of Object.entries(a))n in o&&!SECRET_FIELDS.includes(n)&&(o[n]=s);return o}export function settingsProblems(t,r={}){const a=[];return e(t.smtpHost).trim()?e(t.smtpFromAddress).trim()||a.push({tone:"warn",tab:"email",text:"No From address - mail has no sender and many servers refuse it."}):a.push({tone:"danger",tab:"email",text:"No SMTP host - mail goes to a throwaway test inbox and reaches no one (password resets, form notifications)."}),(t.ccEnabled===!0||e(r.googleAnalytics?.measurementId).trim())&&!e(t.ccPrivacyUrl).trim()&&a.push({tone:"warn",tab:"cookies",text:"The cookie banner is on but links to no privacy policy."}),a}export function describeCacheKey(t){const r=/^page:(.*?):m\d+:role([^:]*):/.exec(String(t||""));return r?{path:r[1]||"/",role:r[2]||"anon",page:!0}:{path:String(t||""),role:"",page:!1}}export function expiresIn(t,r=Date.now()){if(t==null)return"no expiry";const a=t-r;return a<=0?"expired":a<6e4?`${Math.round(a/1e3)}s`:a<36e5?`${Math.round(a/6e4)}m`:`${Math.round(a/36e5)}h`}export function footerForm(t={}){const r=formFromSettings(t);return Object.fromEntries(TAB_FIELDS.footer.map(a=>[a,r[a]]))}export function footerPayload(t){const{footer:r,social:a}=payloadFromForm(t);return delete r.links,delete r.showMotionToggle,delete r.motionDefault,delete r.motionControl,{footer:r,social:a}}export function siteSettingsForm(t={}){return Object.fromEntries(Object.entries(formFromSettings(t)).filter(([r])=>!TAB_FIELDS.footer.includes(r)&&!u.includes(r)))}export function siteSettingsPayload(...t){const{footer:r,social:a,favicon:o,backToTop:n,goToBottom:s,breadcrumbs:l,motion:m,...f}=payloadFromForm(...t);return f}export const APPEARANCE_TABS=["favicon","pageNavigation","breadcrumbs","motion","search"];const u=APPEARANCE_TABS.flatMap(t=>TAB_FIELDS[t]||[]);export function appearanceForm(t={}){const r=formFromSettings(t);return Object.fromEntries(u.map(a=>[a,r[a]]))}export function appearancePayload(t){const{favicon:r,backToTop:a,goToBottom:o,breadcrumbs:n,motion:s}=payloadFromForm(t);return{favicon:r,backToTop:a,goToBottom:o,breadcrumbs:n,motion:s}}
@@ -81,3 +81,5 @@
81
81
  </div>
82
82
  </div>
83
83
  </div>
84
+
85
+ <p><strong>Use Della:</strong> choose her presentation in a chat launcher. Control character visibility and animation in Site Settings &gt; General &gt; Builders and Bots. Your custom branding is kept when you switch her off.</p>
@@ -89,6 +89,22 @@
89
89
  </div>
90
90
  </div>
91
91
  </div>
92
+ <div class="stx-card dm-settings-section">
93
+ <div class="stx-card-title dm-settings-section-title"><span data-icon="smile" data-icon-size="16" aria-hidden="true"></span>Builders and Bots</div>
94
+ <p class="text-muted">Choose where character artwork appears. Select Use Della in a chat launcher, or Use Dot and Use Daisy in their tools. Hiding artwork keeps the tools and chats working.</p>
95
+ <div class="stx-grid">
96
+ <div class="stx-setting"><label class="form-label" for="stx-characters">Show characters</label><input id="stx-characters" type="checkbox" class="form-switch" data-model="charactersEnabled.value"></div>
97
+ <div class="stx-setting"><label class="form-label" for="stx-character-motion">Animate characters</label><input id="stx-character-motion" type="checkbox" class="form-switch" data-model="charactersAnimated.value" data-bind-disabled="!charactersEnabled.value"></div>
98
+ <div class="stx-setting"><label class="form-label" for="stx-character-launchers">Launcher buttons</label><input id="stx-character-launchers" type="checkbox" class="form-switch" data-model="charactersLaunchers.value" data-bind-disabled="!charactersEnabled.value"></div>
99
+ <div class="stx-setting"><label class="form-label" for="stx-character-chats">Chat windows</label><input id="stx-character-chats" type="checkbox" class="form-switch" data-model="charactersChats.value" data-bind-disabled="!charactersEnabled.value"></div>
100
+ </div>
101
+ <div class="stx-grid">
102
+ <div class="stx-setting"><label class="form-label" for="stx-character-builders">Builder tools</label><input id="stx-character-builders" type="checkbox" class="form-switch" data-model="charactersBuilders.value" data-bind-disabled="!charactersEnabled.value"></div>
103
+ <div class="stx-setting"><label class="form-label" for="stx-character-dot">Use Dot in Site Builder</label><input id="stx-character-dot" type="checkbox" class="form-switch" data-model="charactersDot.value" data-bind-disabled="!charactersEnabled.value || !charactersBuilders.value"></div>
104
+ <div class="stx-setting"><label class="form-label" for="stx-character-daisy">Use Daisy in Tool Builder</label><input id="stx-character-daisy" type="checkbox" class="form-switch" data-model="charactersDaisy.value" data-bind-disabled="!charactersEnabled.value || !charactersBuilders.value"></div>
105
+ </div>
106
+ <small class="text-muted">Reduced-motion preferences always take priority. Changes apply when the page is next opened or refreshed.</small>
107
+ </div>
92
108
  <div class="stx-card stx-moved dm-settings-section">
93
109
  <span data-icon="droplet"></span>
94
110
  <div class="stx-moved-text">
@@ -1,4 +1,4 @@
1
- import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}from"../lib/plugin-chrome.js";import{helpPopovers as ke}from"../lib/help-popover.js";import{onceClosed as Ve,openMenuAt as Se,sidebarCount as Ce,viewLifetime as Ge}from"../lib/tool-kit.js";import{rowPlaceKeeper as Je}from"../lib/menu-drag.js";import{FILTERS as Qe,LAUNCHER_POSITION_LABEL as Te,arrangeLaunchers as Ze,blankLauncher as ea,checkLauncherForm as aa,countLaunchers as ta,duplicateLauncher as la,formFromLauncher as na,launcherFromForm as sa,launcherRow as ia,moveItem as oa,previewSpot as da}from"../lib/launchers-arrange.js";import{LAUNCHER_LIMITS as s,LAUNCHER_TOKENS as G,launcherChatAccentCss as ra,launcherColourCss as $e,launcherHref as J}from"../../../public/js/launcher-settings.mjs";const Me=/^#\/launchers\/?(\?.*)?$/,Ee="#/launchers",Q="launchers.filter",F="launchers.draft",ca=`
1
+ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}from"../lib/plugin-chrome.js";import{helpPopovers as ke}from"../lib/help-popover.js";import{onceClosed as Ve,openMenuAt as Se,sidebarCount as Ce,viewLifetime as Ge}from"../lib/tool-kit.js";import{rowPlaceKeeper as Je}from"../lib/menu-drag.js";import{FILTERS as Qe,LAUNCHER_POSITION_LABEL as Te,arrangeLaunchers as Ze,blankLauncher as ea,checkLauncherForm as aa,countLaunchers as ta,duplicateLauncher as la,formFromLauncher as na,launcherFromForm as sa,launcherRow as ia,moveItem as oa,previewSpot as da}from"../lib/launchers-arrange.js";import{LAUNCHER_LIMITS as s,LAUNCHER_TOKENS as G,launcherChatAccentCss as ra,launcherColourCss as $e,launcherHref as J}from"../../../public/js/launcher-settings.mjs";const Me=/^#\/launchers\/?(\?.*)?$/,Ee="#/launchers",Q="launchers.filter",D="launchers.draft",ca=`
2
2
  <div class="lnx-row" data-id="{{id}}" tabindex="0" data-bind-class="rowCls">
3
3
  <span class="lnx-grip" title="Drag to reorder" aria-hidden="true"><span data-icon="menu" data-icon-size="14"></span></span>
4
4
  <span class="lnx-disc" data-bind-class="pill && 'is-pill'" data-bind-style="discStyle" aria-hidden="true"><span data-icon="{{icon}}"></span><span data-bind-hidden="!pill">{{label}}</span></span>
@@ -138,12 +138,14 @@ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}fr
138
138
  </div>
139
139
  <div class="lnx-grid2" data-bind-hidden="actionType.value !== 'chat'">
140
140
  <div class="lnx-field" style="grid-column: 1 / -1">
141
+ <label class="lnx-check"><input id="lnx-f-della" type="checkbox" class="form-switch" data-model="useDella.value"> Use Della</label>
142
+ <small>Use Della's name, portrait and animated character. Site Settings controls visibility and motion. Your custom name and picture are kept when this is switched off.</small>
141
143
  <label class="form-label" for="lnx-f-greeting">Greeting <span data-help-title="Greeting" data-help="The first message a visitor sees when the chat opens. Words in braces are filled in from the visitor's own clock: {greeting} (Good morning / afternoon / evening), {timeofday} (morning / afternoon / evening), {day} (Monday...), {date} (10 November), {time} (09:42), {botname} and {site}. For example: {greeting}! I'm {botname} - how can I help this {timeofday}?"></span></label>
142
144
  <textarea id="lnx-f-greeting" class="form-input" rows="2" maxlength="${s.greetingMax}" data-model="greeting.value"></textarea>
143
145
  </div>
144
146
  <div class="lnx-field">
145
147
  <label class="form-label" for="lnx-f-botname">Bot's name <span data-help="Shown on the bot's answers."></span></label>
146
- <input id="lnx-f-botname" class="form-input" maxlength="${s.botNameMax}" data-model="botName.value">
148
+ <input id="lnx-f-botname" data-bind-disabled="useDella.value" class="form-input" maxlength="${s.botNameMax}" data-model="botName.value">
147
149
  </div>
148
150
  <div class="lnx-field">
149
151
  <label class="form-label" for="lnx-f-accent">Chat colour <span data-help="This chat's own colour: its heading, the visitor's messages and the send button. Theme uses the site's primary colour, so each chat can carry its own branding."></span></label>
@@ -299,4 +301,4 @@ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}fr
299
301
  <button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="cannot.value">
300
302
  <span data-icon="check" data-icon-size="13"></span> <span data-bind-text="saveText"></span></button>
301
303
  </div>
302
- </div>`,Z=i=>String(i??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function ua(i){const p=document.createElement("template");return p.innerHTML=i.trim(),p.content.firstElementChild}const T=i=>i?G.includes(i)?i:"custom":"",x=Ge(Me),ee={list:()=>V("/launchers/items",{method:"GET"}),save:i=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:i})}),patch:(i,p)=>V(`/launchers/items/${encodeURIComponent(i)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(i){x.reset();const p=i.get(0).querySelector(".lnx")||i.get(0),A=()=>p.isConnected&&Me.test(location.hash),u=M.observable([]),ae=M.observable(!0),B=M.observable(""),D=M.observable(!0);let te="all";try{te=Qe.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=Ze(u.value,{filter:$.value,query:W.value}).map(ia)}));const Oe=M.computed(()=>ta(u.value)),ze=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let L=null;const Ne=async()=>{if(L)return L;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],B.value="",D.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?D.value=!1:B.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Ce(Ee),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Ce(Ee),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Pe(a){const t=u.peek(),l=t.findIndex(o=>o.id===a.id),m=la(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function Ie(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function He(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function Re(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>He(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Pe(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Ie(t)}]:[]}let w=null;const j=new Set;function Ue(a,t,l){const m=a.close.bind(a);let o=!1,b=!1;return a.close=async r=>{if(!o&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return o=!0,m()},()=>{o=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(w){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,o=na(l||ea(u.peek())),b={...o,refPage:o.kind==="page"?o.ref:"",refForm:o.kind==="form"?o.ref:"",refBlock:o.kind==="block"?o.ref:"",bgChoice:T(o.background),bgHex:T(o.background)==="custom"?o.background:"",fgChoice:T(o.text),fgHex:T(o.text)==="custom"?o.text:"",accentChoice:T(o.accent),accentHex:T(o.accent)==="custom"?o.accent:"",accentTextChoice:T(o.accentText),accentTextHex:T(o.accentText)==="custom"?o.accentText:"",...t||{}};delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),De=de(b),re=()=>de(N())!==De||!!t,ce=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>ce(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),Y=M.computed(()=>aa(H())),R=M.observable(!1),he=(e,d)=>{const n=da({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":$e(e.background)||"var(--dm-primary)","--lnx-fg":$e(e.text)||"var(--dm-primary-text)"}},pe={...r,saving:R,err:M.computed(()=>Y.value.errors),warn:M.computed(()=>Y.value.warnings),cannot:M.computed(()=>R.value||Object.keys(Y.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>he(H(),!1)),phonePreviewStyle:M.computed(()=>he(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ra(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},We=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),ue=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},Ke=ue(r.widthUnit,r.customWidth,e=>e==="%"?90:900),qe=ue(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ua(pa),me=await Ne().catch(()=>({forms:[],blocks:[]})),fe=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(U=>U.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const U of C){const X=document.createElement("option");X.value=U.value,X.textContent=U.text,e.appendChild(X)}};fe(v.querySelector(".lnx-form-select"),me.forms,b.refForm),fe(v.querySelector(".lnx-block-select"),me.blocks,b.refBlock);let be=()=>{};async function ve(){if(!pe.cannot.peek()){R.value=!0;try{const e=sa(ce(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{R.value=!1}}}k.element.appendChild(v);const je=ke(v),Ye=M.applyBindings(pe,v,{methods:{save:ve,cancel:()=>k.close()}}),_e=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",_e);const xe=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),ge={id:l?.id??null,dirty:re,values:N};w=ge,j.add(k),Ve(k,()=>{Ye.dispose(),je(),We?.(),Ke?.(),qe?.(),Xe?.(),v.removeEventListener("click",xe),j.delete(k),w===ge&&(w=null)}),be=Ue(k,re,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=ca;const Fe=M.applyBindings({launchers:u,loading:ae,loadError:B,toolOn:D,filter:$,query:W,rows:K,counts:Oe,emptyText:ze,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>Fe.dispose()),x.add(ke(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Be=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Re(a.dataset.id)});x.add(()=>Be?.destroy?.());const ne=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Se(l);return}z(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},ie=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",ie),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",ie)}),typeof E.sortable=="function"){const a=Je(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:o})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=oa(u.peek(),m,o);u.value=b,P(b)}});x.add(()=>t.destroy())}we(i,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),we(i,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const oe=a=>{w?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",oe),x.add(()=>window.removeEventListener("beforeunload",oe)),x.add(()=>{if(w?.dirty())try{S.set(F,{id:w.id,values:w.values(),at:new Date().toISOString()})}catch{}[...j].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let y=null;try{y=S.get(F)}catch{}if(y?.values){try{S.remove?S.remove(F):S.set(F,null)}catch{}const a=y.id&&O(y.id)?`your changes to "${Z(O(y.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(y.id&&O(y.id)?y.id:null,y.values)}}};
304
+ </div>`,Z=i=>String(i??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function ua(i){const p=document.createElement("template");return p.innerHTML=i.trim(),p.content.firstElementChild}const T=i=>i?G.includes(i)?i:"custom":"",x=Ge(Me),ee={list:()=>V("/launchers/items",{method:"GET"}),save:i=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:i})}),patch:(i,p)=>V(`/launchers/items/${encodeURIComponent(i)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(i){x.reset();const p=i.get(0).querySelector(".lnx")||i.get(0),A=()=>p.isConnected&&Me.test(location.hash),u=M.observable([]),ae=M.observable(!0),F=M.observable(""),B=M.observable(!0);let te="all";try{te=Qe.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=Ze(u.value,{filter:$.value,query:W.value}).map(ia)}));const Oe=M.computed(()=>ta(u.value)),ze=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let L=null;const Ne=async()=>{if(L)return L;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],F.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:F.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Ce(Ee),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Ce(Ee),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Pe(a){const t=u.peek(),l=t.findIndex(o=>o.id===a.id),m=la(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function Ie(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function He(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function Re(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>He(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Pe(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Ie(t)}]:[]}let w=null;const Y=new Set;function Ue(a,t,l){const m=a.close.bind(a);let o=!1,b=!1;return a.close=async r=>{if(!o&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return o=!0,m()},()=>{o=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(w){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,o=na(l||ea(u.peek())),b={...o,refPage:o.kind==="page"?o.ref:"",refForm:o.kind==="form"?o.ref:"",refBlock:o.kind==="block"?o.ref:"",bgChoice:T(o.background),bgHex:T(o.background)==="custom"?o.background:"",fgChoice:T(o.text),fgHex:T(o.text)==="custom"?o.text:"",accentChoice:T(o.accent),accentHex:T(o.accent)==="custom"?o.accent:"",accentTextChoice:T(o.accentText),accentTextHex:T(o.accentText)==="custom"?o.accentText:"",...t||{}};delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),Be=de(b),re=()=>de(N())!==Be||!!t,ce=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>ce(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),j=M.computed(()=>aa(H())),R=M.observable(!1),he=(e,d)=>{const n=da({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":$e(e.background)||"var(--dm-primary)","--lnx-fg":$e(e.text)||"var(--dm-primary-text)"}},pe={...r,saving:R,err:M.computed(()=>j.value.errors),warn:M.computed(()=>j.value.warnings),cannot:M.computed(()=>R.value||Object.keys(j.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>he(H(),!1)),phonePreviewStyle:M.computed(()=>he(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ra(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},We=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),ue=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},Ke=ue(r.widthUnit,r.customWidth,e=>e==="%"?90:900),qe=ue(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ua(pa),me=await Ne().catch(()=>({forms:[],blocks:[]})),fe=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(U=>U.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const U of C){const X=document.createElement("option");X.value=U.value,X.textContent=U.text,e.appendChild(X)}};fe(v.querySelector(".lnx-form-select"),me.forms,b.refForm),fe(v.querySelector(".lnx-block-select"),me.blocks,b.refBlock);let be=()=>{};async function ve(){if(!pe.cannot.peek()){R.value=!0;try{const e=sa(ce(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{R.value=!1}}}k.element.appendChild(v);const Ye=ke(v),je=M.applyBindings(pe,v,{methods:{save:ve,cancel:()=>k.close()}}),_e=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",_e);const xe=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),ge={id:l?.id??null,dirty:re,values:N};w=ge,Y.add(k),Ve(k,()=>{je.dispose(),Ye(),We?.(),Ke?.(),qe?.(),Xe?.(),v.removeEventListener("click",xe),Y.delete(k),w===ge&&(w=null)}),be=Ue(k,re,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=ca;const De=M.applyBindings({launchers:u,loading:ae,loadError:F,toolOn:B,filter:$,query:W,rows:K,counts:Oe,emptyText:ze,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>De.dispose()),x.add(ke(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Fe=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Re(a.dataset.id)});x.add(()=>Fe?.destroy?.());const ne=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Se(l);return}z(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},ie=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",ie),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",ie)}),typeof E.sortable=="function"){const a=Je(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:o})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=oa(u.peek(),m,o);u.value=b,P(b)}});x.add(()=>t.destroy())}we(i,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),we(i,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const oe=a=>{w?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",oe),x.add(()=>window.removeEventListener("beforeunload",oe)),x.add(()=>{if(w?.dirty())try{S.set(D,{id:w.id,values:w.values(),at:new Date().toISOString()})}catch{}[...Y].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let y=null;try{y=S.get(D)}catch{}if(y?.values){try{S.remove?S.remove(D):S.set(D,null)}catch{}const a=y.id&&O(y.id)?`your changes to "${Z(O(y.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(y.id&&O(y.id)?y.id:null,y.values)}}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "1.50.0",
3
+ "version": "1.51.1",
4
4
  "description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
5
5
  "type": "module",
6
6
  "main": "server/server.js",
@@ -18,6 +18,7 @@
18
18
  "admin/dist/domma/domma-tools.min.js",
19
19
  "public/js/",
20
20
  "public/css/",
21
+ "public/images/characters/",
21
22
  "config/",
22
23
  "!config/connections.json",
23
24
  "!config/theme.json",
@@ -0,0 +1 @@
1
+ .dm-character{display:inline-block;position:relative;width:112px;height:112px;flex:none;overflow:hidden;vertical-align:middle}.dm-character-sprite{display:block;width:100%;height:100%;background-image:var(--dm-character-art);background-size:300% 200%;background-repeat:no-repeat;transform-origin:50% 95%}.dm-character[data-state=greeting] .dm-character-sprite{background-position:50% 0}.dm-character[data-state=working] .dm-character-sprite{background-position:100% 0}.dm-character[data-state=thinking] .dm-character-sprite{background-position:0 100%}.dm-character[data-state=success] .dm-character-sprite{background-position:50% 100%}.dm-character[data-state=help] .dm-character-sprite{background-position:100% 100%}.dm-character[data-animated=true] .dm-character-sprite{animation:dm-character-breathe 5s ease-in-out infinite}.dm-character[data-animated=true][data-state=greeting] .dm-character-sprite{animation:dm-character-hello 1.4s ease-in-out 2}.dm-character[data-animated=true][data-state=thinking] .dm-character-sprite{animation:dm-character-think 3.5s ease-in-out infinite}.dm-character[data-animated=true][data-state=success] .dm-character-sprite{animation:dm-character-success .85s ease-out both}.dm-character--portrait{width:100%;height:100%;border-radius:inherit;background:#f0e3ef}.dm-character--portrait .dm-character-sprite{position:absolute;width:240%;height:240%;left:-70%;top:0;background-position:0 0!important;animation:none!important}.dm-character-disc>.dm-launcher-icon{display:none}.dm-character-disc>.dm-character{width:var(--launcher-size);height:var(--launcher-size);border-radius:50%}.dm-character-avatar>.dm-chat-avatar-img,.dm-character-avatar>.dm-chat-avatar-letter{display:none}.dm-chat-character{display:flex;align-items:center;gap:8px;padding:0 12px;border-bottom:1px solid var(--dm-border,#e7dfe6);background:var(--dm-surface,#fff)}.dm-chat-character[hidden]{display:none}.dm-chat-character-copy{min-width:0;font-size:12px;line-height:1.5;color:var(--dm-text-muted,#766d73)}.dm-chat-character-copy strong{display:block;font-size:15px;color:var(--dm-text,#382337);margin-bottom:3px}.dm-chat.has-character .dm-chat-msg--bot .dm-chat-avatar{overflow:hidden;position:relative;background:#f0e3ef}.dm-chat.has-character .dm-chat-msg--bot .dm-chat-avatar>img,.dm-chat.has-character .dm-chat-msg--bot .dm-chat-avatar>.dm-chat-avatar-letter{display:none}.dm-chat.has-character .dm-chat-msg--bot .dm-chat-avatar:before{content:"";position:absolute;width:240%;height:240%;left:-70%;top:0;background-image:var(--dm-character-art);background-size:300% 200%;background-repeat:no-repeat}.dm-reduced-motion .dm-character-sprite{animation:none!important}.dm-builder-character{border:1px solid var(--dm-border,#e7dfe6);border-radius:var(--dm-radius,10px);margin-bottom:16px;background:var(--dm-surface,#fff);overflow:hidden}.dm-builder-character-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 16px;font-size:13px}.dm-builder-character-toolbar label{display:flex;align-items:center;gap:9px;white-space:nowrap;cursor:pointer;font-weight:600}.dm-builder-character-toolbar small{color:var(--dm-text-muted,#766d73);font-size:11px;line-height:1.5}.dm-builder-character-content{display:flex;align-items:center;gap:18px;padding:0 20px 6px;border-top:1px solid var(--dm-border,#e7dfe6)}.dm-builder-character-content[hidden]{display:none}.dm-builder-character-content .dm-character{width:124px;height:124px}.dm-builder-character-content strong{display:block;font-size:21px;color:var(--dm-text,#382337);margin-bottom:6px}.dm-builder-character-content div>span{display:block;font-size:13px;line-height:1.6;color:var(--dm-text-muted,#766d73)}@media(max-width:640px){.dm-builder-character-toolbar{align-items:flex-start;flex-direction:column;gap:5px}.dm-builder-character-content{gap:6px;padding:0 12px 5px}.dm-builder-character-content .dm-character{width:100px;height:100px}}@keyframes dm-character-breathe{50%{transform:translateY(-1px) scale(1.006)}}@keyframes dm-character-hello{35%{transform:rotate(-1.5deg)}70%{transform:rotate(1deg)}}@keyframes dm-character-think{50%{transform:rotate(-1.2deg)}}@keyframes dm-character-success{35%{transform:translateY(-4px) scale(1.015)}65%{transform:scale(.995)}}@media(prefers-reduced-motion:reduce){.dm-character-sprite{animation:none!important}}@media(max-height:650px){.dm-chat-character .dm-character{width:76px;height:76px}}
@@ -0,0 +1,2 @@
1
+ import{CHARACTERS as p,builderCharacterState as f,normaliseCharacterSettings as w}from"./characters.mjs?v=20261110-builder-characters";import{mountCharacter as R,ensureCharacterCss as T}from"./character-view.mjs?v=20261110-builder-characters";export async function mountBuilderCharacter(d,{id:e,getState:m=()=>({})}={}){const u={destroy(){}};if(!d||!["dot","daisy"].includes(e))return u;const{apiRequest:b}=await import("/admin/js/api.js");let i;try{i=await b("/characters",{method:"GET"})}catch{return u}if(!d.isConnected)return u;const t=M.observable(w(i.settings)),o=M.observable(t.peek()[e]),l=M.observable(!1),c={value:!0};T();const a=document.createElement("section");a.className="dm-builder-character",a.setAttribute("aria-label",`${p[e].name} presentation`),a.innerHTML=`<div class="dm-builder-character-toolbar"><label><input type="checkbox" class="form-switch" data-model="selected.value" data-bind-disabled="disabled.value"><span>Use ${p[e].name}</span></label><small data-bind-text="note.value"></small></div>
2
+ <div class="dm-builder-character-content" data-bind-hidden="!visible.value"><span class="dm-builder-character-stage"></span><div><strong>${p[e].name}</strong><span data-bind-text="words.value"></span></div></div>`,d.prepend(a);const k=()=>i.canUpdate?!t.value.enabled||!t.value.builders?"Character artwork is hidden in Site Settings.":"Saved for this site. Visibility and motion follow Site Settings.":"Only people who can change Site Settings can change this choice.",h=()=>o.value&&t.value.enabled&&t.value.builders,S={selected:o,disabled:M.computed(()=>l.value||!i.canUpdate),visible:M.computed(h),note:M.computed(k),words:M.computed(()=>{const s=m();return s.words?s.words:{greeting:"Ready when you are.",ready:"Here to help with your next step.",working:"Working on your request.",thinking:"Taking a moment to think.",help:"A little input or attention is needed.",success:"Ready for you to review."}[f(s)]})},C=M.applyBindings(S,a);let n=null;const x=M.effect(()=>{const s=m(),r=h(),g=t.value.animated;r&&!n&&(n=R(a.querySelector(".dm-builder-character-stage"),{id:e,animated:g})),!r&&n&&(n.destroy(),n=null),n?.setState(f(s),g)}),v=a.querySelector("input"),y=async()=>{if(l.peek()||!i.canUpdate)return;const s=v.checked;l.value=!0;try{const r=await b(`/characters/${e}`,{method:"PUT",body:JSON.stringify({enabled:s})});if(!c.value)return;t.value=w(r.settings),o.value=t.peek()[e]}catch(r){if(!c.value)return;o.value=t.peek()[e],E.toast(`Not saved: ${r.message||r}`,{type:"error"})}finally{c.value&&(l.value=!1)}};return v.addEventListener("change",y),{destroy(){c.value=!1,v.removeEventListener("change",y),x?.(),n?.destroy(),C?.dispose?.(),a.remove()}}}
@@ -0,0 +1 @@
1
+ import{CHARACTERS as i,characterId as o}from"./characters.mjs?v=20261110-builder-characters";export function ensureCharacterCss(){if(!document.querySelector("link[data-dm-character-css]")){const t=document.createElement("link");t.rel="stylesheet",t.href="/public/css/characters.css?v=20261110-builder-characters",t.dataset.dmCharacterCss="",document.head.appendChild(t)}}export function mountCharacter(t,{id:a,portrait:n=!1,animated:r=!0}={}){if(!t||!o(a))return{setState(){},destroy(){}};ensureCharacterCss();const e=document.createElement("span");e.className=`dm-character${n?" dm-character--portrait":""}`,e.setAttribute("aria-hidden","true"),e.dataset.character=a,e.dataset.state="ready",e.dataset.animated=String(r),e.style.setProperty("--dm-character-art",`url("${i[a].artwork}")`);const s=document.createElement("span");return s.className="dm-character-sprite",e.appendChild(s),t.appendChild(e),{setState(c,d=r){e.dataset.state=["ready","greeting","working","thinking","success","help"].includes(c)?c:"ready",e.dataset.animated=String(d)},destroy(){e.remove()}}}
@@ -0,0 +1 @@
1
+ export const CHARACTERS=Object.freeze({dot:Object.freeze({id:"dot",name:"Dot",artwork:"/public/images/characters/dot-poses.png"}),daisy:Object.freeze({id:"daisy",name:"Daisy",artwork:"/public/images/characters/daisy-poses.png"}),della:Object.freeze({id:"della",name:"Della",artwork:"/public/images/characters/della-poses.png"})});export function characterId(e){return typeof e=="string"&&Object.hasOwn(CHARACTERS,e)?e:""}export function normaliseCharacterSettings(e){const r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return{enabled:r.enabled!==!1,animated:r.animated!==!1,launchers:r.launchers!==!1,chats:r.chats!==!1,builders:r.builders!==!1,dot:r.dot!==!1,daisy:r.daisy!==!1}}export function builderCharacterState({working:e=!1,busy:r=!1,error:a="",status:t="",hasContent:n=!1}={}){return a||["waiting","failed","stopped"].includes(t)?"help":e||t==="building"?"working":r?"thinking":["ready","released"].includes(t)?"success":n||t==="review"?"ready":"greeting"}export function characterChat(e={},r){const a=characterId(e.character);return{...e,character:a,...a?{botName:CHARACTERS[a].name}:{},characterOptions:normaliseCharacterSettings(r)}}export function chatCharacterState({busy:e=!1,error:r="",ended:a=!1,status:t="none",askDetails:n=!1,replied:i=!1}={}){return r||n?"help":e?"thinking":a||t==="message"?"success":i?"ready":"greeting"}
@@ -1,5 +1,9 @@
1
- import{fillGreeting as ye,launcherChatAccentCss as ke}from"/public/js/launcher-settings.mjs?v=20261110-chat-times-settings";const we={waiting:3e3,open:3e3,bot:9e3,message:2e4},Me=6e3,Te="/public/css/launcher-chat.css?v=20261110-chat-greeting",Z=()=>document.documentElement.classList.contains("dm-reduced-motion")||!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;function xe(){if(document.querySelector("link[data-dm-chat-css]"))return;const t=document.createElement("link");t.rel="stylesheet",t.href=Te,t.dataset.dmChatCss="",document.head.appendChild(t)}const ee={get:t=>{try{return globalThis.S?.get?.(t)??null}catch{return null}},set:(t,c)=>{try{globalThis.S?.set?.(t,c)}catch{}},remove:t=>{try{globalThis.S?.remove?globalThis.S.remove(t):globalThis.S?.set?.(t,null)}catch{}}};async function I(t,c,o,n){const p=n?{"X-Chat-Token":n}:{};let r;try{r=t==="GET"?await H.get(c,{headers:p}):await H.post(c,o,{headers:p})}catch(l){const w=l?.data||l?.response?.data;throw new Error(w?.error||"The chat could not be reached. Check your connection and try again.")}if(r&&r.error)throw new Error(r.error);return r}const pe=(t,c="time")=>{if(c==="none")return"";const o=t?new Date(t):null;if(!o||Number.isNaN(o.getTime()))return"";const n=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return c!=="datetime"?n:`${new Date().toDateString()===o.toDateString()?"Today":o.toLocaleDateString([],{day:"numeric",month:"short"})}, ${n}`},te=t=>(String(t||"").trim().match(/[\p{L}\p{N}]/u)?.[0]||"?").toUpperCase();function Ee(t,c=!1,o="",n="time"){const p=Array.isArray(t.suggestions)&&t.suggestions.length?[...t.suggestions.map(l=>({key:`${t.n}-${l.i}`,n:t.n,i:l.i,label:l.label})),{key:`${t.n}-none`,n:t.n,i:-1,label:"None of these"}]:[],r=t.from==="visitor"?"You":t.name||(t.from==="system"?"":"The team");return{key:`m${t.n}`,n:t.n,from:t.from,fresh:c,cls:M.observable(`dm-chat-msg dm-chat-msg--${t.from}`),name:r,initial:te(r),avatar:t.from==="bot"?o:"",text:typeof t.text=="string"?t.text:"",html:typeof t.html=="string"?t.html:"",links:(Array.isArray(t.links)?t.links:[]).map(l=>{const w=/^https?:/i.test(l.url);return{url:l.url,label:l.label,target:w?"_blank":"_self",rel:w?"noopener noreferrer":""}}),choices:p,starters:[],time:pe(t.at,n)}}function Se(t){const c=o=>o?`${o.from}|${o.name}`:"";return t.forEach((o,n)=>{const p=l=>l&&l.from!=="system"&&c(l)===c(o),r=[`dm-chat-msg dm-chat-msg--${o.from}`];o.from!=="system"&&p(t[n-1])&&r.push("is-cont"),o.from!=="system"&&p(t[n+1])&&r.push("has-next"),o.fresh&&r.push("is-new"),o.cls.value=r.join(" ")}),t}const Le=`
1
+ import{fillGreeting as Ce,launcherChatAccentCss as Ae}from"/public/js/launcher-settings.mjs?v=20261110-builder-characters";import{CHARACTERS as Ne,characterId as ae,normaliseCharacterSettings as G,chatCharacterState as $e}from"./characters.mjs?v=20261110-builder-characters";import{mountCharacter as we}from"./character-view.mjs?v=20261110-builder-characters";const De={waiting:3e3,open:3e3,bot:9e3,message:2e4},Be=6e3,He="/public/css/launcher-chat.css?v=20261110-builder-characters",se=()=>document.documentElement.classList.contains("dm-reduced-motion")||!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;function Oe(){if(document.querySelector("link[data-dm-chat-css]"))return;const t=document.createElement("link");t.rel="stylesheet",t.href=He,t.dataset.dmChatCss="",document.head.appendChild(t)}const ne={get:t=>{try{return globalThis.S?.get?.(t)??null}catch{return null}},set:(t,d)=>{try{globalThis.S?.set?.(t,d)}catch{}},remove:t=>{try{globalThis.S?.remove?globalThis.S.remove(t):globalThis.S?.set?.(t,null)}catch{}}};async function Y(t,d,o,n){const f=n?{"X-Chat-Token":n}:{};let i;try{i=t==="GET"?await H.get(d,{headers:f}):await H.post(d,o,{headers:f})}catch(l){const w=l?.data||l?.response?.data;throw new Error(w?.error||"The chat could not be reached. Check your connection and try again.")}if(i&&i.error)throw new Error(i.error);return i}const Me=(t,d="time")=>{if(d==="none")return"";const o=t?new Date(t):null;if(!o||Number.isNaN(o.getTime()))return"";const n=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return d!=="datetime"?n:`${new Date().toDateString()===o.toDateString()?"Today":o.toLocaleDateString([],{day:"numeric",month:"short"})}, ${n}`},re=t=>(String(t||"").trim().match(/[\p{L}\p{N}]/u)?.[0]||"?").toUpperCase();function Pe(t,d=!1,o="",n="time"){const f=Array.isArray(t.suggestions)&&t.suggestions.length?[...t.suggestions.map(l=>({key:`${t.n}-${l.i}`,n:t.n,i:l.i,label:l.label})),{key:`${t.n}-none`,n:t.n,i:-1,label:"None of these"}]:[],i=t.from==="visitor"?"You":t.name||(t.from==="system"?"":"The team");return{key:`m${t.n}`,n:t.n,from:t.from,fresh:d,cls:M.observable(`dm-chat-msg dm-chat-msg--${t.from}`),name:i,initial:re(i),avatar:t.from==="bot"?o:"",text:typeof t.text=="string"?t.text:"",html:typeof t.html=="string"?t.html:"",links:(Array.isArray(t.links)?t.links:[]).map(l=>{const w=/^https?:/i.test(l.url);return{url:l.url,label:l.label,target:w?"_blank":"_self",rel:w?"noopener noreferrer":""}}),choices:f,starters:[],time:Me(t.at,n)}}function _e(t){const d=o=>o?`${o.from}|${o.name}`:"";return t.forEach((o,n)=>{const f=l=>l&&l.from!=="system"&&d(l)===d(o),i=[`dm-chat-msg dm-chat-msg--${o.from}`];o.from!=="system"&&f(t[n-1])&&i.push("is-cont"),o.from!=="system"&&f(t[n+1])&&i.push("has-next"),o.fresh&&i.push("is-new"),o.cls.value=i.join(" ")}),t}const qe=`
2
2
  <div class="dm-chat" data-bind-class="rootClass.value">
3
+ <div class="dm-chat-character" hidden>
4
+ <span class="dm-chat-character-stage"></span>
5
+ <span class="dm-chat-character-copy"><strong data-bind-text="botName.value"></strong><span data-bind-text="characterStatus.value"></span></span>
6
+ </div>
3
7
  <p class="dm-chat-status" data-bind-text="statusText.value" data-bind-hidden="inPanel"></p>
4
8
  <div class="dm-chat-log" role="log" aria-live="polite" aria-relevant="additions" tabindex="0">
5
9
  <div class="dm-chat-items" data-each="items.value key=key"></div>
@@ -43,11 +47,11 @@ import{fillGreeting as ye,launcherChatAccentCss as ke}from"/public/js/launcher-s
43
47
  </div>
44
48
  </form>
45
49
  <p class="dm-chat-foot" data-bind-hidden="ended.value" data-bind-text="footText.value"></p>
46
- </div>`,Ae=`<div data-bind-class="cls.value" data-n="{{n}}">
50
+ </div>`,Ie=`<div data-bind-class="cls.value" data-n="{{n}}">
47
51
  <span class="dm-chat-avatar" aria-hidden="true"><img class="dm-chat-avatar-img" alt="" src="{{avatar}}"><span class="dm-chat-avatar-letter">{{initial}}</span></span>
48
52
  <div class="dm-chat-who"><span>{{name}}</span> <time>{{time}}</time></div>
49
53
  <div class="dm-chat-bubble"><span class="dm-chat-text">{{text}}</span><div class="dm-chat-html">{{{html}}}</div></div>
50
54
  <div class="dm-chat-links">{{#each links key=url}}<a class="dm-chat-link" href="{{url}}" target="{{target}}" rel="{{rel}}">{{label}}</a>{{/each}}</div>
51
55
  <div class="dm-chat-choices">{{#each choices key=key}}<button type="button" class="dm-chat-choice" data-n="{{n}}" data-i="{{i}}">{{label}}</button>{{/each}}</div>
52
56
  <div class="dm-chat-choices dm-chat-starters">{{#each starters key=key}}<button type="button" class="dm-chat-choice dm-chat-starter" data-text="{{text}}">{{text}}</button>{{/each}}</div>
53
- </div>`;export function mountChat(t,{launcherId:c,title:o="Chat",chat:n={}}={}){if(!t||!c||!globalThis.M)return{destroy(){}};xe();const p=`chat:${c}`,r=Date.now(),l="/api/chat",w=`launcher=${encodeURIComponent(c)}`,i=M.observable({greeting:n.greeting||"Hi! How can we help?",botName:n.botName||"Assistant",bot:n.bot!==!1,staff:n.staff!==!1,askDetails:n.askDetails||"offline",staffOnline:!1,ai:!1,accent:n.accent||"",accentText:n.accentText||"",avatar:n.avatar||"",starters:Array.isArray(n.starters)?n.starters:[],personButton:n.personButton==="header"?"header":"below",times:["time","datetime","none"].includes(n.times)?n.times:"time"}),C=M.observable([]),v=M.observable(null),L=M.observable(""),$=M.observable(""),R=M.observable(!1),T=M.observable(!1),N=M.observable(""),A=M.observable(!1),ae=M.observable(""),se=M.observable(""),z=M.observable("");let f=ee.get(p),x=0,d=!0,E=0,G=0,Y=!1;const b=()=>v.value?.status||"none",K=()=>({key:"greet",n:0,from:"bot",fresh:!1,cls:M.observable("dm-chat-msg dm-chat-msg--bot"),name:i.value.botName,initial:te(i.value.botName),avatar:i.value.avatar||"",text:ye(i.value.greeting,{botName:i.value.botName,site:globalThis.__CMS_SITE__?.title||""}),html:"",links:[],choices:[],time:pe(new Date(r).toISOString(),i.value.times),starters:v.peek()?[]:(i.value.starters||[]).map((e,a)=>({key:`s${a}`,text:e}))}),B=e=>{C.value=Se(e)},h=t.closest?.(".dm-launcher-chat")?.querySelector(".dm-launcher-chat-head")||null,W=()=>{const e=i.value,a=b();return v.value?.askDetails||!(a==="none"||a==="bot")?!1:e.staff||e.askDetails!=="never"},fe=M.computed(W),D={items:C,draft:L,hp:$,typing:R,busy:T,error:N,detailsName:ae,detailsEmail:se,detailsMessage:z,ended:M.computed(()=>A.value||b()==="closed"),hasChat:M.computed(()=>!!v.value&&b()!=="closed"),showDetails:M.computed(()=>!!v.value?.askDetails&&b()!=="closed"),detailsWantsMessage:M.computed(()=>b()==="bot"),detailsIntro:M.computed(()=>b()==="waiting"?"So we can reach you if we get cut off:":"Leave your details and we will get back to you."),canAskPerson:fe,personLabel:M.computed(()=>i.value.staff?"Talk to a person":"Leave a message"),personBelow:M.computed(()=>W()&&!(h&&i.value.personButton==="header")),personInHead:M.computed(()=>W()&&!!h&&i.value.personButton==="header"),canSend:M.computed(()=>!T.value&&L.value.trim().length>0&&!(A.value||b()==="closed")),rootClass:M.computed(()=>[Z()?"is-still":"",v.value?"has-chat":""].filter(Boolean).join(" ")),inPanel:!!h,botInitial:M.computed(()=>te(i.value.botName)),botAvatar:M.computed(()=>i.value.avatar||""),footText:M.computed(()=>{const e=i.value;return!e.bot||!(b()==="none"||b()==="bot")?"":e.ai?`${e.botName} is an AI assistant and can get things wrong.`:`${e.botName} is an automated assistant.`}),online:M.computed(()=>{const e=i.value,a=b();return a==="open"?!0:a==="closed"||a==="message"?!1:e.bot||e.staff&&e.staffOnline}),statusText:M.computed(()=>{const e=i.value;switch(b()){case"waiting":return"Waiting for a person - they will reply here.";case"open":return"You are chatting with our team.";case"message":return"Message left - we will get back to you by email.";case"closed":return"Chat ended.";default:return e.bot?`${e.botName} answers straight away${e.staff&&e.staffOnline?" - a person is available too.":"."}`:e.staff?e.staffOnline?"Someone is available to chat.":"Nobody is available right now - leave a message.":""}})};t.innerHTML=Le;const g=t.firstElementChild;g.setAttribute("aria-label",o),g.querySelector(".dm-chat-items").innerHTML=Ae;const m=g.querySelector(".dm-chat-log"),y=g.querySelector(".dm-chat-input");function ne(e){N.value=e,clearTimeout(G),G=setTimeout(()=>{d&&(N.value="")},Me)}let O=!0;const ie=()=>m.scrollHeight-m.scrollTop-m.clientHeight<80;function oe(e=!1){!e&&!O&&!ie()||(O=!0,requestAnimationFrame(()=>{m.scrollTop=m.scrollHeight}))}function j(e){if(!d||!e)return;e.token&&(f=e.token,ee.set(p,f)),e.state&&(v.value=e.state),typeof e.state?.staffOnline=="boolean"&&(i.value={...i.peek(),staffOnline:e.state.staffOnline});const a=(Array.isArray(e.messages)?e.messages:[]).filter(s=>s.n>x);a.length&&(x=Math.max(x,...a.map(s=>s.n)),B([...C.peek(),...a.map(s=>Ee(s,Y,i.peek().avatar,i.peek().times))]),oe(a.some(s=>s.from==="visitor"))),re()}function re(){if(clearTimeout(E),!d||!f)return;const e=we[b()];e&&(E=setTimeout(F,e))}async function F(){if(!(!d||!f)){if(document.hidden||!g.isConnected){re();return}try{const e=await I("GET",`${l}/state?${w}&after=${x}`,null,f);if(!d)return;if(!e.state){U();return}j(e)}catch{clearTimeout(E),d&&(E=setTimeout(F,15e3))}}}function U(){f=null,ee.remove(p),v.value=null,x=0,B([K()])}async function S(e,a,{thinking:s=!1}={}){if(T.peek())return!1;T.value=!0,N.value="",s&&!Z()&&(R.value=!0);const k=Date.now();try{const u=await I("POST",`${l}/${e}`,{launcher:c,after:x,...a},f);if(s&&!Z()){const q=450-(Date.now()-k);q>0&&await new Promise(Q=>setTimeout(Q,q))}return j(u),!0}catch(u){return d&&ne(u.message),!1}finally{d&&(T.value=!1,R.value=!1)}}async function V(){const e=L.peek().trim();if(!e||T.peek()||A.peek())return!1;if(!f){const s=1700-(Date.now()-r);if(s>0&&await new Promise(k=>setTimeout(k,s)),!d)return!1}return await S("send",{text:e,page:location.pathname,_hp:$.peek(),_t:r},{thinking:!0})&&(L.value="",y.focus()),!1}const _=h?h.closest(".dm-launcher-chat"):g,X=M.effect(()=>{const e=ke(i.value);for(const[a,s]of[["--chat-accent",e.accent],["--chat-accent-text",e.accentText]])s?_.style.setProperty(a,s):_.style.removeProperty(a)}),be=M.applyBindings(D,g,{methods:{send:()=>(V(),!1),sendDetails:()=>(S("details",{name:ae.peek(),email:se.peek(),message:z.peek()}).then(e=>{e&&(z.value="")}),!1),askPerson:()=>S("person",{page:location.pathname,_hp:$.peek(),_t:r},{thinking:!0}),end:async()=>{f&&await S("end",{})&&(A.value=!0,clearTimeout(E))},restart:()=>{A.value=!1,U(),y.focus()}}});window.Domma?.icons?.scan?.(g);let P=null,le=[];if(h){const e=h.querySelector(".dm-launcher-chat-title"),a=document.createElement("span");a.className="dm-launcher-chat-avatar",a.setAttribute("aria-hidden","true"),a.innerHTML='<img class="dm-chat-avatar-img" alt="" data-bind-src="botAvatar.value"><span class="dm-chat-avatar-letter" data-bind-text="botInitial.value"></span>',a.setAttribute("data-bind-class","online.value ? 'is-online' : ''");const s=document.createElement("span");s.className="dm-launcher-chat-heading";const k=document.createElement("span");k.className="dm-launcher-chat-sub",k.setAttribute("data-bind-text","statusText.value"),h.insertBefore(a,h.firstChild),e?(h.insertBefore(s,e),s.appendChild(e)):h.insertBefore(s,a.nextSibling),s.appendChild(k);const u=document.createElement("button");u.type="button",u.className="dm-launcher-chat-person",u.setAttribute("data-bind-hidden","!personInHead.value"),u.setAttribute("data-bind-title","personLabel.value"),u.setAttribute("data-bind-aria-label","personLabel.value"),u.setAttribute("data-bind-disabled","busy.value"),u.innerHTML='<span data-icon="headphones" data-icon-size="18" aria-hidden="true"></span>',h.insertBefore(u,h.querySelector(".dm-launcher-chat-close")),u.addEventListener("click",()=>S("person",{page:location.pathname,_hp:$.peek(),_t:r},{thinking:!0})),window.Domma?.icons?.scan?.(u),le=[a,k,u],P=M.applyBindings(D,a)||null;const q=M.applyBindings(D,k),Q=M.applyBindings(D,u),ve=[P,q,Q];P={dispose:()=>ve.forEach(ge=>ge?.dispose?.())}}const ce=e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),V())};y.addEventListener("keydown",ce);const de=()=>{y.style.height="auto",y.style.height=Math.min(y.scrollHeight,120)+"px"};y.addEventListener("input",de);const ue=e=>{const a=e.target.closest(".dm-chat-starter");if(a&&m.contains(a)){L.value=a.dataset.text||"",V();return}const s=e.target.closest(".dm-chat-choice");!s||!m.contains(s)||S("pick",{n:Number(s.dataset.n),i:Number(s.dataset.i)},{thinking:!0})};m.addEventListener("click",ue);const me=()=>{O=ie()};m.addEventListener("scroll",me,{passive:!0});const J=typeof ResizeObserver=="function"?new ResizeObserver(()=>{O&&(m.scrollTop=m.scrollHeight)}):null;J?.observe(m),J?.observe(g.querySelector(".dm-chat-items"));const he=()=>{!document.hidden&&d&&f&&F()};return document.addEventListener("visibilitychange",he),B([K()]),(async()=>{try{const e=await I("GET",`${l}/config?${w}`);if(!d)return;i.value={...i.peek(),...e},v.peek()||B([K(),...C.peek().filter(a=>a.key!=="greet")])}catch(e){d&&ne(e.message)}if(!f||!d){Y=!0;return}try{const e=await I("GET",`${l}/state?${w}&after=0`,null,f);if(!d)return;if(!e.state){U();return}j(e),oe(!0)}catch{}Y=!0})(),{destroy(){d&&(d=!1,clearTimeout(E),clearTimeout(G),y.removeEventListener("keydown",ce),y.removeEventListener("input",de),m.removeEventListener("click",ue),m.removeEventListener("scroll",me),J?.disconnect(),document.removeEventListener("visibilitychange",he),be?.dispose?.(),P?.dispose?.(),X?.dispose?.(),typeof X=="function"&&X(),_.style.removeProperty("--chat-accent"),_.style.removeProperty("--chat-accent-text"),le.forEach(e=>e.remove()),t.innerHTML="")}}}
57
+ </div>`;export function mountChat(t,{launcherId:d,title:o="Chat",chat:n={}}={}){if(!t||!d||!globalThis.M)return{destroy(){}};Oe();const f=`chat:${d}`,i=Date.now(),l="/api/chat",w=`launcher=${encodeURIComponent(d)}`,r=M.observable({greeting:n.greeting||"Hi! How can we help?",botName:n.botName||"Assistant",bot:n.bot!==!1,staff:n.staff!==!1,askDetails:n.askDetails||"offline",staffOnline:!1,ai:!1,accent:n.accent||"",accentText:n.accentText||"",avatar:n.avatar||"",character:ae(n.character),characterOptions:G(n.characterOptions),starters:Array.isArray(n.starters)?n.starters:[],personButton:n.personButton==="header"?"header":"below",times:["time","datetime","none"].includes(n.times)?n.times:"time"}),D=M.observable([]),y=M.observable(null),B=M.observable(""),P=M.observable(""),K=M.observable(!1),T=M.observable(!1),O=M.observable(""),S=M.observable(!1),oe=M.observable(""),ie=M.observable(""),W=M.observable("");let b=ne.get(f),L=0,u=!0,C=0,j=0,F=!1;const m=()=>y.value?.status||"none",U=()=>({key:"greet",n:0,from:"bot",fresh:!1,cls:M.observable("dm-chat-msg dm-chat-msg--bot"),name:r.value.botName,initial:re(r.value.botName),avatar:r.value.avatar||"",text:Ce(r.value.greeting,{botName:r.value.botName,site:globalThis.__CMS_SITE__?.title||""}),html:"",links:[],choices:[],time:Me(new Date(i).toISOString(),r.value.times),starters:y.peek()?[]:(r.value.starters||[]).map((e,a)=>({key:`s${a}`,text:e}))}),_=e=>{D.value=_e(e)},h=t.closest?.(".dm-launcher-chat")?.querySelector(".dm-launcher-chat-head")||null,V=()=>{const e=r.value,a=m();return y.value?.askDetails||!(a==="none"||a==="bot")?!1:e.staff||e.askDetails!=="never"},Te=M.computed(V),le=()=>{const e=r.value;return!!(e.bot&&ae(e.character)&&G(e.characterOptions).enabled&&G(e.characterOptions).chats&&!["open","waiting"].includes(m()))},ce=()=>$e({busy:T.value,error:O.value,ended:S.value||m()==="closed",status:m(),askDetails:y.value?.askDetails,replied:D.value.some(e=>e.from==="bot"&&e.n>0)}),q={items:D,draft:B,hp:P,typing:K,busy:T,error:O,detailsName:oe,detailsEmail:ie,detailsMessage:W,ended:M.computed(()=>S.value||m()==="closed"),hasChat:M.computed(()=>!!y.value&&m()!=="closed"),showDetails:M.computed(()=>!!y.value?.askDetails&&m()!=="closed"),detailsWantsMessage:M.computed(()=>m()==="bot"),detailsIntro:M.computed(()=>m()==="waiting"?"So we can reach you if we get cut off:":"Leave your details and we will get back to you."),canAskPerson:Te,personLabel:M.computed(()=>r.value.staff?"Talk to a person":"Leave a message"),personBelow:M.computed(()=>V()&&!(h&&r.value.personButton==="header")),personInHead:M.computed(()=>V()&&!!h&&r.value.personButton==="header"),canSend:M.computed(()=>!T.value&&B.value.trim().length>0&&!(S.value||m()==="closed")),rootClass:M.computed(()=>[se()?"is-still":"",y.value?"has-chat":"",le()?"has-character":""].filter(Boolean).join(" ")),inPanel:!!h,botName:M.computed(()=>r.value.botName),characterStatus:M.computed(()=>({greeting:"Hello. How can I help?",ready:"Here when you need me.",thinking:"Taking a moment to think.",help:"A little input from you, please.",success:"Thank you for chatting."})[ce()]||"Here to help."),botInitial:M.computed(()=>re(r.value.botName)),botAvatar:M.computed(()=>r.value.avatar||""),footText:M.computed(()=>{const e=r.value;return!e.bot||!(m()==="none"||m()==="bot")?"":e.ai?`${e.botName} is an AI assistant and can get things wrong.`:`${e.botName} is an automated assistant.`}),online:M.computed(()=>{const e=r.value,a=m();return a==="open"?!0:a==="closed"||a==="message"?!1:e.bot||e.staff&&e.staffOnline}),statusText:M.computed(()=>{const e=r.value;switch(m()){case"waiting":return"Waiting for a person - they will reply here.";case"open":return"You are chatting with our team.";case"message":return"Message left - we will get back to you by email.";case"closed":return"Chat ended.";default:return e.bot?`${e.botName} answers straight away${e.staff&&e.staffOnline?" - a person is available too.":"."}`:e.staff?e.staffOnline?"Someone is available to chat.":"Nobody is available right now - leave a message.":""}})};t.innerHTML=qe;const v=t.firstElementChild;v.setAttribute("aria-label",o),v.querySelector(".dm-chat-items").innerHTML=Ie;const p=v.querySelector(".dm-chat-log"),k=v.querySelector(".dm-chat-input");function de(e){O.value=e,clearTimeout(j),j=setTimeout(()=>{u&&(O.value="")},Be)}let I=!0;const ue=()=>p.scrollHeight-p.scrollTop-p.clientHeight<80;function me(e=!1){!e&&!I&&!ue()||(I=!0,requestAnimationFrame(()=>{p.scrollTop=p.scrollHeight}))}function X(e){if(!u||!e)return;e.token&&(b=e.token,ne.set(f,b)),e.state&&(y.value=e.state),typeof e.state?.staffOnline=="boolean"&&(r.value={...r.peek(),staffOnline:e.state.staffOnline});const a=(Array.isArray(e.messages)?e.messages:[]).filter(s=>s.n>L);a.length&&(L=Math.max(L,...a.map(s=>s.n)),_([...D.peek(),...a.map(s=>Pe(s,F,r.peek().avatar,r.peek().times))]),me(a.some(s=>s.from==="visitor"))),he()}function he(){if(clearTimeout(C),!u||!b)return;const e=De[m()];e&&(C=setTimeout(J,e))}async function J(){if(!(!u||!b)){if(document.hidden||!v.isConnected){he();return}try{const e=await Y("GET",`${l}/state?${w}&after=${L}`,null,b);if(!u)return;if(!e.state){Q();return}X(e)}catch{clearTimeout(C),u&&(C=setTimeout(J,15e3))}}}function Q(){b=null,ne.remove(f),y.value=null,L=0,_([U()])}async function A(e,a,{thinking:s=!1}={}){if(T.peek())return!1;T.value=!0,O.value="",s&&!se()&&(K.value=!0);const g=Date.now();try{const c=await Y("POST",`${l}/${e}`,{launcher:d,after:L,...a},b);if(s&&!se()){const x=450-(Date.now()-g);x>0&&await new Promise(E=>setTimeout(E,x))}return X(c),!0}catch(c){return u&&de(c.message),!1}finally{u&&(T.value=!1,K.value=!1)}}async function Z(){const e=B.peek().trim();if(!e||T.peek()||S.peek())return!1;if(!b){const s=1700-(Date.now()-i);if(s>0&&await new Promise(g=>setTimeout(g,s)),!u)return!1}return await A("send",{text:e,page:location.pathname,_hp:P.peek(),_t:i},{thinking:!0})&&(B.value="",k.focus()),!1}const R=h?h.closest(".dm-launcher-chat"):v,ee=M.effect(()=>{const e=Ae(r.value);for(const[a,s]of[["--chat-accent",e.accent],["--chat-accent-text",e.accentText]])s?R.style.setProperty(a,s):R.style.removeProperty(a)}),xe=M.applyBindings(q,v,{methods:{send:()=>(Z(),!1),sendDetails:()=>(A("details",{name:oe.peek(),email:ie.peek(),message:W.peek()}).then(e=>{e&&(W.value="")}),!1),askPerson:()=>A("person",{page:location.pathname,_hp:P.peek(),_t:i},{thinking:!0}),end:async()=>{b&&await A("end",{})&&(S.value=!0,clearTimeout(C))},restart:()=>{S.value=!1,Q(),k.focus()}}});window.Domma?.icons?.scan?.(v);let z=null,pe=[];if(h){const e=h.querySelector(".dm-launcher-chat-title"),a=document.createElement("span");a.className="dm-launcher-chat-avatar",a.setAttribute("aria-hidden","true"),a.innerHTML='<img class="dm-chat-avatar-img" alt="" data-bind-src="botAvatar.value"><span class="dm-chat-avatar-letter" data-bind-text="botInitial.value"></span>',a.setAttribute("data-bind-class","online.value ? 'is-online' : ''");const s=document.createElement("span");s.className="dm-launcher-chat-heading";const g=document.createElement("span");g.className="dm-launcher-chat-sub",g.setAttribute("data-bind-text","statusText.value"),h.insertBefore(a,h.firstChild),e?(h.insertBefore(s,e),s.appendChild(e)):h.insertBefore(s,a.nextSibling),s.appendChild(g);const c=document.createElement("button");c.type="button",c.className="dm-launcher-chat-person",c.setAttribute("data-bind-hidden","!personInHead.value"),c.setAttribute("data-bind-title","personLabel.value"),c.setAttribute("data-bind-aria-label","personLabel.value"),c.setAttribute("data-bind-disabled","busy.value"),c.innerHTML='<span data-icon="headphones" data-icon-size="18" aria-hidden="true"></span>',h.insertBefore(c,h.querySelector(".dm-launcher-chat-close")),c.addEventListener("click",()=>A("person",{page:location.pathname,_hp:P.peek(),_t:i},{thinking:!0})),window.Domma?.icons?.scan?.(c),pe=[a,g,c],z=M.applyBindings(q,a)||null;const x=M.applyBindings(q,g),E=M.applyBindings(q,c),Se=[z,x,E];z={dispose:()=>Se.forEach(Le=>Le?.dispose?.())}}let N=[],fe="",$=null;const Ee=M.effect(()=>{const e=r.value,a=le(),s=a?ae(e.character):"",g=G(e.characterOptions),c=ce(),x=v.querySelector(".dm-chat-character");x.hidden=!a,s!==fe&&(N.forEach(E=>E.destroy()),N=[],$?.classList.remove("dm-character-avatar"),fe=s,s?(N.push(we(x.querySelector(".dm-chat-character-stage"),{id:s,animated:g.animated})),$=h?.querySelector(".dm-launcher-chat-avatar"),$&&($.classList.add("dm-character-avatar"),N.push(we($,{id:s,portrait:!0,animated:!1}))),v.style.setProperty("--dm-character-art",`url("${Ne[s].artwork}")`)):v.style.removeProperty("--dm-character-art")),N.forEach(E=>E.setState(c,g.animated))}),be=e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Z())};k.addEventListener("keydown",be);const ve=()=>{k.style.height="auto",k.style.height=Math.min(k.scrollHeight,120)+"px"};k.addEventListener("input",ve);const ge=e=>{const a=e.target.closest(".dm-chat-starter");if(a&&p.contains(a)){B.value=a.dataset.text||"",Z();return}const s=e.target.closest(".dm-chat-choice");!s||!p.contains(s)||A("pick",{n:Number(s.dataset.n),i:Number(s.dataset.i)},{thinking:!0})};p.addEventListener("click",ge);const ye=()=>{I=ue()};p.addEventListener("scroll",ye,{passive:!0});const te=typeof ResizeObserver=="function"?new ResizeObserver(()=>{I&&(p.scrollTop=p.scrollHeight)}):null;te?.observe(p),te?.observe(v.querySelector(".dm-chat-items"));const ke=()=>{!document.hidden&&u&&b&&J()};return document.addEventListener("visibilitychange",ke),_([U()]),(async()=>{try{const e=await Y("GET",`${l}/config?${w}`);if(!u)return;r.value={...r.peek(),...e},y.peek()||_([U(),...D.peek().filter(a=>a.key!=="greet")])}catch(e){u&&de(e.message)}if(!b||!u){F=!0;return}try{const e=await Y("GET",`${l}/state?${w}&after=0`,null,b);if(!u)return;if(!e.state){Q();return}X(e),me(!0)}catch{}F=!0})(),{destroy(){u&&(u=!1,clearTimeout(C),clearTimeout(j),k.removeEventListener("keydown",be),k.removeEventListener("input",ve),p.removeEventListener("click",ge),p.removeEventListener("scroll",ye),te?.disconnect(),document.removeEventListener("visibilitychange",ke),xe?.dispose?.(),z?.dispose?.(),Ee?.(),N.forEach(e=>e.destroy()),$?.classList.remove("dm-character-avatar"),ee?.dispose?.(),typeof ee=="function"&&ee(),R.style.removeProperty("--chat-accent"),R.style.removeProperty("--chat-accent-text"),pe.forEach(e=>e.remove()),t.innerHTML="")}}}
@@ -1,6 +1,6 @@
1
- import{cssClasses as M}from"./css-classes.mjs";export const LAUNCHER_POSITIONS=["TL","TC","TR","ML","MR","BL","BC","BR"],LAUNCHER_POSITION_LABEL={TL:"Top left",TC:"Top centre",TR:"Top right",ML:"Middle left",MR:"Middle right",BL:"Bottom left",BC:"Bottom centre",BR:"Bottom right"},LAUNCHER_TRIGGER_STYLES=["icon","icon-text"],LAUNCHER_TOOLTIP_MODES=["label","custom","off"],LAUNCHER_DEVICES=["all","desktop","phone"],LAUNCHER_AUDIENCES=["everyone","signed-in","signed-out"],LAUNCHER_PAGE_MODES=["all","only","except"],LAUNCHER_ACTIONS=["modal","slideover","chat"],LAUNCHER_MODAL_KINDS=["page","form","block"],LAUNCHER_SLIDEOVER_KINDS=["page","form","block"],LAUNCHER_MODAL_SIZES=["xs","sm","md","lg","xl","xxl","full","screen","custom"],LAUNCHER_MODAL_HEIGHTS=["auto","sm","md","lg","full","custom"],LAUNCHER_WIDTH_UNITS=["px","%"],LAUNCHER_HEIGHT_UNITS=["px","vh"],LAUNCHER_MODAL_WIDTH_CSS=Object.freeze({xs:"320px",sm:"400px",md:"600px",lg:"800px",xl:"1140px",xxl:"1400px",full:"90vw"}),LAUNCHER_MODAL_HEIGHT_CSS=Object.freeze({sm:"40vh",md:"60vh",lg:"80vh",full:"90vh"}),LAUNCHER_SLIDEOVER_WIDTHS=["sm","md","lg","xl"],LAUNCHER_SIDES=["left","right"],LAUNCHER_ASK_DETAILS=["offline","always","never"],LAUNCHER_TOKENS=["primary","secondary","success","danger","warning","info","surface","text","background"],LAUNCHER_LIMITS=Object.freeze({nameMax:60,labelMax:40,tooltipMax:120,titleMax:80,iconMax:40,idMax:40,sizeMin:32,sizeMax:96,offsetMax:500,pathsMax:50,pathMax:200,greetingMax:300,botNameMax:40,aiContextMax:4e3,aiRulesMax:2e3,avatarMax:300,chatWidth:[300,720],chatHeight:[380,900],startersMax:4,starterMax:80,aiMaxPerChat:[0,100],keepDays:[0,730],widthPx:[240,2400],widthPct:[20,100],heightPx:[160,2e3],heightVh:[20,100]}),LAUNCHER_DEFAULTS=Object.freeze({enabled:!0,showDisc:!0,name:"New launcher",label:"Open",tooltipMode:"label",tooltip:"",icon:"message-circle",triggerStyle:"icon",position:"BR",offsetX:32,offsetY:32,size:52,radius:26,devices:"all",phone:Object.freeze({override:!1,position:"BR",offsetX:16,offsetY:16,size:48}),colours:Object.freeze({background:"",text:""}),class:"",pages:Object.freeze({mode:"all",paths:Object.freeze([])}),audience:"everyone",action:Object.freeze({type:"modal",kind:"page",ref:"",title:"",size:"lg",side:"right",width:"md",customWidth:900,widthUnit:"px",height:"auto",customHeight:70,heightUnit:"vh"}),chat:Object.freeze({greeting:"Hi! How can we help?",botName:"Della",bot:!0,staff:!0,askDetails:"offline",ai:!0,aiUseSite:!0,aiContext:"",aiRules:"",accent:"",accentText:"",avatar:"",size:"md",width:400,height:600,resizable:!0,starters:Object.freeze([]),aiMaxPerChat:20,personButton:"below",keepDays:0,times:"time"})});const c=(e,t,i)=>t.includes(e)?e:i;function f(e,t,i,o){const r=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isFinite(r)?Math.min(o,Math.max(i,Math.round(r))):Math.min(o,Math.max(i,t))}function l(e,t,i=""){return typeof e!="string"?i:e.replace(/[\u0000-\u001f\u007f]/g," ").trim().replace(/\s+/g," ").slice(0,t)||i}const d=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{};export const LAUNCHER_ID_RE=/^[a-z0-9][a-z0-9-]{0,39}$/;const b=/^[a-z0-9][a-z0-9-]{0,39}$/,A=/^\/[A-Za-z0-9._~\-/]*$/,y=/^[a-z0-9][a-z0-9_-]{0,99}$/i;export function launcherColour(e){if(typeof e!="string")return"";const t=e.trim().toLowerCase();return LAUNCHER_TOKENS.includes(t)||/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(t)?t:""}export function launcherColourCss(e){const t=launcherColour(e);return t?LAUNCHER_TOKENS.includes(t)?`var(--dm-${t})`:t:""}export function normaliseLauncherPath(e){if(typeof e!="string")return"";let t=e.trim().split(/[?#]/)[0].replace(/\s+/g,"");return!t||(t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/"),t.length>1&&(t=t.replace(/\/+$/,"")),t.length>LAUNCHER_LIMITS.pathMax||!/^\/[A-Za-z0-9._~\-/*]*$/.test(t))?"":t}export function launcherPathMatches(e,t){const i=normaliseLauncherPath(e||"/")||"/",o=normaliseLauncherPath(t);return o?o.endsWith("/*")&&i===(o.slice(0,-2)||"/")?!0:new RegExp("^"+o.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(i):!1}export function launcherShowsOn(e,t,i){if(!e||e.enabled===!1||e.audience==="signed-in"&&!i||e.audience==="signed-out"&&i)return!1;const o=e.pages.paths.some(r=>launcherPathMatches(t,r));return e.pages.mode==="only"?o:e.pages.mode==="except"?!o:!0}function C(e,t){const i=d(e);return{override:i.override===!0,position:c(i.position,LAUNCHER_POSITIONS,LAUNCHER_DEFAULTS.phone.position),offsetX:f(i.offsetX,LAUNCHER_DEFAULTS.phone.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(i.offsetY,LAUNCHER_DEFAULTS.phone.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:f(i.size,Math.min(t,LAUNCHER_DEFAULTS.phone.size),LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax)}}function E(e){const t=d(e),i=c(t.type,LAUNCHER_ACTIONS,LAUNCHER_DEFAULTS.action.type),o=i==="modal"?LAUNCHER_MODAL_KINDS:LAUNCHER_SLIDEOVER_KINDS,r=i==="chat"?"page":c(t.kind,o,"page");let n=typeof t.ref=="string"?t.ref.trim():"";r==="page"?(n=n?normaliseLauncherPath(n):"",n.includes("*")&&(n="")):y.test(n)||(n=""),i==="chat"&&(n="");const s=LAUNCHER_DEFAULTS.action,h=c(t.widthUnit,LAUNCHER_WIDTH_UNITS,s.widthUnit),a=c(t.heightUnit,LAUNCHER_HEIGHT_UNITS,s.heightUnit);return{type:i,kind:r,ref:n,title:l(t.title,LAUNCHER_LIMITS.titleMax),size:c(t.size,LAUNCHER_MODAL_SIZES,s.size),side:c(t.side,LAUNCHER_SIDES,s.side),width:c(t.width,LAUNCHER_SLIDEOVER_WIDTHS,s.width),customWidth:f(t.customWidth,h==="%"?90:s.customWidth,...h==="%"?LAUNCHER_LIMITS.widthPct:LAUNCHER_LIMITS.widthPx),widthUnit:h,height:c(t.height,LAUNCHER_MODAL_HEIGHTS,s.height),customHeight:f(t.customHeight,a==="px"?600:s.customHeight,...a==="px"?LAUNCHER_LIMITS.heightPx:LAUNCHER_LIMITS.heightVh),heightUnit:a}}export function launcherModalBox(e){const t=e||LAUNCHER_DEFAULTS.action;if(t.size==="screen")return{width:"100vw",height:"100vh",screen:!0};const i=t.size==="custom"?t.widthUnit==="%"?`${t.customWidth}vw`:`${t.customWidth}px`:LAUNCHER_MODAL_WIDTH_CSS[t.size]||LAUNCHER_MODAL_WIDTH_CSS.lg,o=t.height==="custom"?`${t.customHeight}${t.heightUnit==="px"?"px":"vh"}`:LAUNCHER_MODAL_HEIGHT_CSS[t.height]||"";return{width:i,height:o,screen:!1}}export function normaliseLauncherChat(e){const t=d(e),i=LAUNCHER_DEFAULTS.chat;return{greeting:typeof t.greeting=="string"?t.greeting.replace(/\r\n?/g,`
2
- `).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").trim().slice(0,LAUNCHER_LIMITS.greetingMax):i.greeting,botName:l(t.botName,LAUNCHER_LIMITS.botNameMax,i.botName),bot:t.bot!==!1,staff:t.staff!==!1,askDetails:c(t.askDetails,LAUNCHER_ASK_DETAILS,i.askDetails),ai:t.ai!==!1,aiUseSite:t.aiUseSite!==!1,aiContext:m(t.aiContext,LAUNCHER_LIMITS.aiContextMax),aiRules:m(t.aiRules,LAUNCHER_LIMITS.aiRulesMax),accent:launcherColour(t.accent),accentText:launcherColour(t.accentText),avatar:launcherAvatar(t.avatar),size:c(t.size,LAUNCHER_CHAT_SIZES,i.size),width:f(t.width,i.width,...LAUNCHER_LIMITS.chatWidth),height:f(t.height,i.height,...LAUNCHER_LIMITS.chatHeight),resizable:t.resizable!==!1,starters:(Array.isArray(t.starters)?t.starters:typeof t.starters=="string"?t.starters.split(`
3
- `):[]).map(r=>l(r,LAUNCHER_LIMITS.starterMax)).filter(Boolean).slice(0,LAUNCHER_LIMITS.startersMax),aiMaxPerChat:f(t.aiMaxPerChat,i.aiMaxPerChat,...LAUNCHER_LIMITS.aiMaxPerChat),personButton:c(t.personButton,LAUNCHER_PERSON_BUTTON,i.personButton),keepDays:f(t.keepDays,i.keepDays,...LAUNCHER_LIMITS.keepDays),times:c(t.times,LAUNCHER_CHAT_TIMES,i.times)}}export const LAUNCHER_PERSON_BUTTON=["below","header"],LAUNCHER_CHAT_TIMES=["time","datetime","none"],GREETING_PLACEHOLDERS=["greeting","timeofday","day","date","time","botname","site"];export function fillGreeting(e,{now:t=new Date,botName:i="",site:o=""}={}){const r=t.getHours(),n=r<12?"morning":r<18?"afternoon":"evening",s={greeting:`Good ${n}`,timeofday:n,day:t.toLocaleDateString("en-GB",{weekday:"long"}),date:t.toLocaleDateString("en-GB",{day:"numeric",month:"long"}),time:t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),botname:i,site:o};return String(e??"").replace(/\{\s*([a-z]+)\s*\}/gi,(h,a)=>{const u=s[a.toLowerCase()];return u===void 0?h:u})}export const LAUNCHER_CHAT_SIZES=["sm","md","lg","custom"];const x={sm:[340,500],md:[400,600],lg:[480,720]};export function launcherChatBox(e={}){if(e.size==="custom")return{width:f(e.width,400,...LAUNCHER_LIMITS.chatWidth),height:f(e.height,600,...LAUNCHER_LIMITS.chatHeight)};const[t,i]=x[e.size]||x.md;return{width:t,height:i}}export function launcherAvatar(e){if(typeof e!="string")return"";const t=e.trim();return!t||t.length>LAUNCHER_LIMITS.avatarMax||t.startsWith("//")?"":/^\/[A-Za-z0-9._~\-/%]+$/.test(t)?t:""}export function launcherChatAccentCss(e={}){const t=launcherColourCss(e.accent);if(!t)return{accent:"",accentText:""};let i=launcherColourCss(e.accentText);if(!i){const o=launcherColour(e.accent);if(o.startsWith("#")){const r=o.length<=5?o.slice(1,4).split("").map(a=>a+a).join(""):o.slice(1,7),[n,s,h]=[0,2,4].map(a=>parseInt(r.slice(a,a+2),16)/255).map(a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4);i=.2126*n+.7152*s+.0722*h>.179?"#111111":"#ffffff"}else i=o==="primary"?"var(--dm-primary-text, #fff)":`var(--dm-${o}-text, #fff)`}return{accent:t,accentText:i}}function m(e,t){return typeof e=="string"?e.replace(/\r\n?/g,`
1
+ import{cssClasses as M}from"./css-classes.mjs";import{characterId as b}from"./characters.mjs";export const LAUNCHER_POSITIONS=["TL","TC","TR","ML","MR","BL","BC","BR"],LAUNCHER_POSITION_LABEL={TL:"Top left",TC:"Top centre",TR:"Top right",ML:"Middle left",MR:"Middle right",BL:"Bottom left",BC:"Bottom centre",BR:"Bottom right"},LAUNCHER_TRIGGER_STYLES=["icon","icon-text"],LAUNCHER_TOOLTIP_MODES=["label","custom","off"],LAUNCHER_DEVICES=["all","desktop","phone"],LAUNCHER_AUDIENCES=["everyone","signed-in","signed-out"],LAUNCHER_PAGE_MODES=["all","only","except"],LAUNCHER_ACTIONS=["modal","slideover","chat"],LAUNCHER_MODAL_KINDS=["page","form","block"],LAUNCHER_SLIDEOVER_KINDS=["page","form","block"],LAUNCHER_MODAL_SIZES=["xs","sm","md","lg","xl","xxl","full","screen","custom"],LAUNCHER_MODAL_HEIGHTS=["auto","sm","md","lg","full","custom"],LAUNCHER_WIDTH_UNITS=["px","%"],LAUNCHER_HEIGHT_UNITS=["px","vh"],LAUNCHER_MODAL_WIDTH_CSS=Object.freeze({xs:"320px",sm:"400px",md:"600px",lg:"800px",xl:"1140px",xxl:"1400px",full:"90vw"}),LAUNCHER_MODAL_HEIGHT_CSS=Object.freeze({sm:"40vh",md:"60vh",lg:"80vh",full:"90vh"}),LAUNCHER_SLIDEOVER_WIDTHS=["sm","md","lg","xl"],LAUNCHER_SIDES=["left","right"],LAUNCHER_ASK_DETAILS=["offline","always","never"],LAUNCHER_TOKENS=["primary","secondary","success","danger","warning","info","surface","text","background"],LAUNCHER_LIMITS=Object.freeze({nameMax:60,labelMax:40,tooltipMax:120,titleMax:80,iconMax:40,idMax:40,sizeMin:32,sizeMax:96,offsetMax:500,pathsMax:50,pathMax:200,greetingMax:300,botNameMax:40,aiContextMax:4e3,aiRulesMax:2e3,avatarMax:300,chatWidth:[300,720],chatHeight:[380,900],startersMax:4,starterMax:80,aiMaxPerChat:[0,100],keepDays:[0,730],widthPx:[240,2400],widthPct:[20,100],heightPx:[160,2e3],heightVh:[20,100]}),LAUNCHER_DEFAULTS=Object.freeze({enabled:!0,showDisc:!0,name:"New launcher",label:"Open",tooltipMode:"label",tooltip:"",icon:"message-circle",triggerStyle:"icon",position:"BR",offsetX:32,offsetY:32,size:52,radius:26,devices:"all",phone:Object.freeze({override:!1,position:"BR",offsetX:16,offsetY:16,size:48}),colours:Object.freeze({background:"",text:""}),class:"",pages:Object.freeze({mode:"all",paths:Object.freeze([])}),audience:"everyone",action:Object.freeze({type:"modal",kind:"page",ref:"",title:"",size:"lg",side:"right",width:"md",customWidth:900,widthUnit:"px",height:"auto",customHeight:70,heightUnit:"vh"}),chat:Object.freeze({greeting:"Hi! How can we help?",botName:"Della",bot:!0,staff:!0,askDetails:"offline",ai:!0,aiUseSite:!0,aiContext:"",aiRules:"",accent:"",accentText:"",avatar:"",character:"",size:"md",width:400,height:600,resizable:!0,starters:Object.freeze([]),aiMaxPerChat:20,personButton:"below",keepDays:0,times:"time"})});const c=(e,t,i)=>t.includes(e)?e:i;function f(e,t,i,o){const r=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isFinite(r)?Math.min(o,Math.max(i,Math.round(r))):Math.min(o,Math.max(i,t))}function l(e,t,i=""){return typeof e!="string"?i:e.replace(/[\u0000-\u001f\u007f]/g," ").trim().replace(/\s+/g," ").slice(0,t)||i}const d=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{};export const LAUNCHER_ID_RE=/^[a-z0-9][a-z0-9-]{0,39}$/;const y=/^[a-z0-9][a-z0-9-]{0,39}$/,R=/^\/[A-Za-z0-9._~\-/]*$/,C=/^[a-z0-9][a-z0-9_-]{0,99}$/i;export function launcherColour(e){if(typeof e!="string")return"";const t=e.trim().toLowerCase();return LAUNCHER_TOKENS.includes(t)||/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(t)?t:""}export function launcherColourCss(e){const t=launcherColour(e);return t?LAUNCHER_TOKENS.includes(t)?`var(--dm-${t})`:t:""}export function normaliseLauncherPath(e){if(typeof e!="string")return"";let t=e.trim().split(/[?#]/)[0].replace(/\s+/g,"");return!t||(t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/"),t.length>1&&(t=t.replace(/\/+$/,"")),t.length>LAUNCHER_LIMITS.pathMax||!/^\/[A-Za-z0-9._~\-/*]*$/.test(t))?"":t}export function launcherPathMatches(e,t){const i=normaliseLauncherPath(e||"/")||"/",o=normaliseLauncherPath(t);return o?o.endsWith("/*")&&i===(o.slice(0,-2)||"/")?!0:new RegExp("^"+o.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(i):!1}export function launcherShowsOn(e,t,i){if(!e||e.enabled===!1||e.audience==="signed-in"&&!i||e.audience==="signed-out"&&i)return!1;const o=e.pages.paths.some(r=>launcherPathMatches(t,r));return e.pages.mode==="only"?o:e.pages.mode==="except"?!o:!0}function E(e,t){const i=d(e);return{override:i.override===!0,position:c(i.position,LAUNCHER_POSITIONS,LAUNCHER_DEFAULTS.phone.position),offsetX:f(i.offsetX,LAUNCHER_DEFAULTS.phone.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(i.offsetY,LAUNCHER_DEFAULTS.phone.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:f(i.size,Math.min(t,LAUNCHER_DEFAULTS.phone.size),LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax)}}function L(e){const t=d(e),i=c(t.type,LAUNCHER_ACTIONS,LAUNCHER_DEFAULTS.action.type),o=i==="modal"?LAUNCHER_MODAL_KINDS:LAUNCHER_SLIDEOVER_KINDS,r=i==="chat"?"page":c(t.kind,o,"page");let n=typeof t.ref=="string"?t.ref.trim():"";r==="page"?(n=n?normaliseLauncherPath(n):"",n.includes("*")&&(n="")):C.test(n)||(n=""),i==="chat"&&(n="");const a=LAUNCHER_DEFAULTS.action,h=c(t.widthUnit,LAUNCHER_WIDTH_UNITS,a.widthUnit),s=c(t.heightUnit,LAUNCHER_HEIGHT_UNITS,a.heightUnit);return{type:i,kind:r,ref:n,title:l(t.title,LAUNCHER_LIMITS.titleMax),size:c(t.size,LAUNCHER_MODAL_SIZES,a.size),side:c(t.side,LAUNCHER_SIDES,a.side),width:c(t.width,LAUNCHER_SLIDEOVER_WIDTHS,a.width),customWidth:f(t.customWidth,h==="%"?90:a.customWidth,...h==="%"?LAUNCHER_LIMITS.widthPct:LAUNCHER_LIMITS.widthPx),widthUnit:h,height:c(t.height,LAUNCHER_MODAL_HEIGHTS,a.height),customHeight:f(t.customHeight,s==="px"?600:a.customHeight,...s==="px"?LAUNCHER_LIMITS.heightPx:LAUNCHER_LIMITS.heightVh),heightUnit:s}}export function launcherModalBox(e){const t=e||LAUNCHER_DEFAULTS.action;if(t.size==="screen")return{width:"100vw",height:"100vh",screen:!0};const i=t.size==="custom"?t.widthUnit==="%"?`${t.customWidth}vw`:`${t.customWidth}px`:LAUNCHER_MODAL_WIDTH_CSS[t.size]||LAUNCHER_MODAL_WIDTH_CSS.lg,o=t.height==="custom"?`${t.customHeight}${t.heightUnit==="px"?"px":"vh"}`:LAUNCHER_MODAL_HEIGHT_CSS[t.height]||"";return{width:i,height:o,screen:!1}}export function normaliseLauncherChat(e){const t=d(e),i=LAUNCHER_DEFAULTS.chat;return{greeting:typeof t.greeting=="string"?t.greeting.replace(/\r\n?/g,`
2
+ `).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").trim().slice(0,LAUNCHER_LIMITS.greetingMax):i.greeting,botName:l(t.botName,LAUNCHER_LIMITS.botNameMax,i.botName),bot:t.bot!==!1,staff:t.staff!==!1,askDetails:c(t.askDetails,LAUNCHER_ASK_DETAILS,i.askDetails),ai:t.ai!==!1,aiUseSite:t.aiUseSite!==!1,aiContext:m(t.aiContext,LAUNCHER_LIMITS.aiContextMax),aiRules:m(t.aiRules,LAUNCHER_LIMITS.aiRulesMax),accent:launcherColour(t.accent),accentText:launcherColour(t.accentText),avatar:launcherAvatar(t.avatar),character:b(t.character),size:c(t.size,LAUNCHER_CHAT_SIZES,i.size),width:f(t.width,i.width,...LAUNCHER_LIMITS.chatWidth),height:f(t.height,i.height,...LAUNCHER_LIMITS.chatHeight),resizable:t.resizable!==!1,starters:(Array.isArray(t.starters)?t.starters:typeof t.starters=="string"?t.starters.split(`
3
+ `):[]).map(r=>l(r,LAUNCHER_LIMITS.starterMax)).filter(Boolean).slice(0,LAUNCHER_LIMITS.startersMax),aiMaxPerChat:f(t.aiMaxPerChat,i.aiMaxPerChat,...LAUNCHER_LIMITS.aiMaxPerChat),personButton:c(t.personButton,LAUNCHER_PERSON_BUTTON,i.personButton),keepDays:f(t.keepDays,i.keepDays,...LAUNCHER_LIMITS.keepDays),times:c(t.times,LAUNCHER_CHAT_TIMES,i.times)}}export const LAUNCHER_PERSON_BUTTON=["below","header"],LAUNCHER_CHAT_TIMES=["time","datetime","none"],GREETING_PLACEHOLDERS=["greeting","timeofday","day","date","time","botname","site"];export function fillGreeting(e,{now:t=new Date,botName:i="",site:o=""}={}){const r=t.getHours(),n=r<12?"morning":r<18?"afternoon":"evening",a={greeting:`Good ${n}`,timeofday:n,day:t.toLocaleDateString("en-GB",{weekday:"long"}),date:t.toLocaleDateString("en-GB",{day:"numeric",month:"long"}),time:t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),botname:i,site:o};return String(e??"").replace(/\{\s*([a-z]+)\s*\}/gi,(h,s)=>{const u=a[s.toLowerCase()];return u===void 0?h:u})}export const LAUNCHER_CHAT_SIZES=["sm","md","lg","custom"];const x={sm:[340,500],md:[400,600],lg:[480,720]};export function launcherChatBox(e={}){if(e.size==="custom")return{width:f(e.width,400,...LAUNCHER_LIMITS.chatWidth),height:f(e.height,600,...LAUNCHER_LIMITS.chatHeight)};const[t,i]=x[e.size]||x.md;return{width:t,height:i}}export function launcherAvatar(e){if(typeof e!="string")return"";const t=e.trim();return!t||t.length>LAUNCHER_LIMITS.avatarMax||t.startsWith("//")?"":/^\/[A-Za-z0-9._~\-/%]+$/.test(t)?t:""}export function launcherChatAccentCss(e={}){const t=launcherColourCss(e.accent);if(!t)return{accent:"",accentText:""};let i=launcherColourCss(e.accentText);if(!i){const o=launcherColour(e.accent);if(o.startsWith("#")){const r=o.length<=5?o.slice(1,4).split("").map(s=>s+s).join(""):o.slice(1,7),[n,a,h]=[0,2,4].map(s=>parseInt(r.slice(s,s+2),16)/255).map(s=>s<=.03928?s/12.92:((s+.055)/1.055)**2.4);i=.2126*n+.7152*a+.0722*h>.179?"#111111":"#ffffff"}else i=o==="primary"?"var(--dm-primary-text, #fff)":`var(--dm-${o}-text, #fff)`}return{accent:t,accentText:i}}function m(e,t){return typeof e=="string"?e.replace(/\r\n?/g,`
4
4
  `).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").replace(/\n{3,}/g,`
5
5
 
6
- `).trim().slice(0,t):""}export function normaliseLauncher(e){const t=d(e),i=LAUNCHER_DEFAULTS,o=f(t.size,i.size,LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax),r=Math.floor(o/2),n=d(t.pages),s=(Array.isArray(n.paths)?n.paths:typeof n.paths=="string"?n.paths.split(/[\n,]+/):[]).map(normaliseLauncherPath).filter(Boolean).filter((a,u,p)=>p.indexOf(a)===u).slice(0,LAUNCHER_LIMITS.pathsMax),h=d(t.colours);return{id:typeof t.id=="string"&&LAUNCHER_ID_RE.test(t.id)?t.id:"",enabled:t.enabled!==!1,showDisc:t.showDisc!==!1,name:l(t.name,LAUNCHER_LIMITS.nameMax,i.name),label:l(t.label,LAUNCHER_LIMITS.labelMax,i.label),tooltipMode:c(t.tooltipMode,LAUNCHER_TOOLTIP_MODES,i.tooltipMode),tooltip:l(t.tooltip,LAUNCHER_LIMITS.tooltipMax,""),icon:typeof t.icon=="string"&&b.test(t.icon.trim())?t.icon.trim():i.icon,triggerStyle:c(t.triggerStyle,LAUNCHER_TRIGGER_STYLES,i.triggerStyle),position:c(t.position,LAUNCHER_POSITIONS,i.position),offsetX:f(t.offsetX,i.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(t.offsetY,i.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:o,radius:Math.min(r,f(t.radius,i.radius,0,r)),devices:c(t.devices,LAUNCHER_DEVICES,i.devices),phone:C(t.phone,o),colours:{background:launcherColour(h.background),text:launcherColour(h.text)},class:M(typeof t.class=="string"?t.class:"").join(" "),pages:{mode:c(n.mode,LAUNCHER_PAGE_MODES,i.pages.mode),paths:s},audience:c(t.audience,LAUNCHER_AUDIENCES,i.audience),action:E(t.action),chat:normaliseLauncherChat(t.chat)}}export function launcherTooltip(e){return!e||e.tooltipMode==="off"?"":e.tooltipMode==="custom"?e.tooltip||e.label:e.triggerStyle==="icon-text"?"":e.label}export function launcherHref(e){return`#launcher-${e}`}export function newLauncherId(e=new Set,t=Math.random){for(let i=0;i<1e3;i++){const o="l-"+Math.floor(t()*2176782336).toString(36).padStart(6,"0");if(!e.has(o))return o}return"l-"+Date.now().toString(36)}export function normaliseLaunchers(e,t=Math.random){const i=Array.isArray(e)?e:Array.isArray(e?.launchers)?e.launchers:[],o=new Set;return i.filter(r=>r&&typeof r=="object"&&!Array.isArray(r)).map(r=>{const n=normaliseLauncher(r);return(!n.id||o.has(n.id))&&(n.id=newLauncherId(o,t)),o.add(n.id),n})}export function launcherReady(e){return e?e.action.type==="chat"?!0:!!e.action.ref:!1}export function publicLauncher(e){const t={id:e.id,disc:e.showDisc,label:e.label,tooltip:launcherTooltip(e),icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:e.phone,colours:{background:launcherColourCss(e.colours.background),text:launcherColourCss(e.colours.text)},class:e.class,action:{type:e.action.type,title:e.action.title||e.label,size:e.action.size,side:e.action.side,width:e.action.width,customWidth:e.action.customWidth,widthUnit:e.action.widthUnit,height:e.action.height,customHeight:e.action.customHeight,heightUnit:e.action.heightUnit}};if(e.action.type==="chat"){const{aiContext:i,aiRules:o,aiUseSite:r,aiMaxPerChat:n,keepDays:s,...h}=e.chat;t.chat=h}return t}export function launcherSpot(e,{w:t,h:i,vw:o,vh:r,offsetX:n,offsetY:s}){const h=e[1]==="L"?"L":e[1]==="R"?"R":"C",a=e[0],u=h==="L"?n:h==="R"?o-t-n:Math.round((o-t)/2+n),p=a==="T"?s:a==="B"?r-i-s:Math.round((r-i)/2+s);return{left:u,top:p}}const g=12,L=(e,t)=>e.left<t.right+g&&t.left<e.right+g&&e.top<t.bottom+g&&t.top<e.bottom+g;export function launcherStack(e,t,{w:i,h:o},r){const n=e[0]==="B";let s=t.top;for(let h=0;h<=r.length;h++){const a={left:t.left,top:s,right:t.left+i,bottom:s+o},u=r.find(p=>p&&p.right>p.left&&p.bottom>p.top&&L(a,p));if(!u)break;s=Math.round(n?u.top-g-o:u.bottom+g)}return{left:t.left,top:s}}
6
+ `).trim().slice(0,t):""}export function normaliseLauncher(e){const t=d(e),i=LAUNCHER_DEFAULTS,o=f(t.size,i.size,LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax),r=Math.floor(o/2),n=d(t.pages),a=(Array.isArray(n.paths)?n.paths:typeof n.paths=="string"?n.paths.split(/[\n,]+/):[]).map(normaliseLauncherPath).filter(Boolean).filter((s,u,p)=>p.indexOf(s)===u).slice(0,LAUNCHER_LIMITS.pathsMax),h=d(t.colours);return{id:typeof t.id=="string"&&LAUNCHER_ID_RE.test(t.id)?t.id:"",enabled:t.enabled!==!1,showDisc:t.showDisc!==!1,name:l(t.name,LAUNCHER_LIMITS.nameMax,i.name),label:l(t.label,LAUNCHER_LIMITS.labelMax,i.label),tooltipMode:c(t.tooltipMode,LAUNCHER_TOOLTIP_MODES,i.tooltipMode),tooltip:l(t.tooltip,LAUNCHER_LIMITS.tooltipMax,""),icon:typeof t.icon=="string"&&y.test(t.icon.trim())?t.icon.trim():i.icon,triggerStyle:c(t.triggerStyle,LAUNCHER_TRIGGER_STYLES,i.triggerStyle),position:c(t.position,LAUNCHER_POSITIONS,i.position),offsetX:f(t.offsetX,i.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(t.offsetY,i.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:o,radius:Math.min(r,f(t.radius,i.radius,0,r)),devices:c(t.devices,LAUNCHER_DEVICES,i.devices),phone:E(t.phone,o),colours:{background:launcherColour(h.background),text:launcherColour(h.text)},class:M(typeof t.class=="string"?t.class:"").join(" "),pages:{mode:c(n.mode,LAUNCHER_PAGE_MODES,i.pages.mode),paths:a},audience:c(t.audience,LAUNCHER_AUDIENCES,i.audience),action:L(t.action),chat:normaliseLauncherChat(t.chat)}}export function launcherTooltip(e){return!e||e.tooltipMode==="off"?"":e.tooltipMode==="custom"?e.tooltip||e.label:e.triggerStyle==="icon-text"?"":e.label}export function launcherHref(e){return`#launcher-${e}`}export function newLauncherId(e=new Set,t=Math.random){for(let i=0;i<1e3;i++){const o="l-"+Math.floor(t()*2176782336).toString(36).padStart(6,"0");if(!e.has(o))return o}return"l-"+Date.now().toString(36)}export function normaliseLaunchers(e,t=Math.random){const i=Array.isArray(e)?e:Array.isArray(e?.launchers)?e.launchers:[],o=new Set;return i.filter(r=>r&&typeof r=="object"&&!Array.isArray(r)).map(r=>{const n=normaliseLauncher(r);return(!n.id||o.has(n.id))&&(n.id=newLauncherId(o,t)),o.add(n.id),n})}export function launcherReady(e){return e?e.action.type==="chat"?!0:!!e.action.ref:!1}export function publicLauncher(e){const t={id:e.id,disc:e.showDisc,label:e.label,tooltip:launcherTooltip(e),icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:e.phone,colours:{background:launcherColourCss(e.colours.background),text:launcherColourCss(e.colours.text)},class:e.class,action:{type:e.action.type,title:e.action.title||e.label,size:e.action.size,side:e.action.side,width:e.action.width,customWidth:e.action.customWidth,widthUnit:e.action.widthUnit,height:e.action.height,customHeight:e.action.customHeight,heightUnit:e.action.heightUnit}};if(e.action.type==="chat"){const{aiContext:i,aiRules:o,aiUseSite:r,aiMaxPerChat:n,keepDays:a,...h}=e.chat;t.chat=h}return t}export function launcherSpot(e,{w:t,h:i,vw:o,vh:r,offsetX:n,offsetY:a}){const h=e[1]==="L"?"L":e[1]==="R"?"R":"C",s=e[0],u=h==="L"?n:h==="R"?o-t-n:Math.round((o-t)/2+n),p=s==="T"?a:s==="B"?r-i-a:Math.round((r-i)/2+a);return{left:u,top:p}}const g=12,_=(e,t)=>e.left<t.right+g&&t.left<e.right+g&&e.top<t.bottom+g&&t.top<e.bottom+g;export function launcherStack(e,t,{w:i,h:o},r){const n=e[0]==="B";let a=t.top;for(let h=0;h<=r.length;h++){const s={left:t.left,top:a,right:t.left+i,bottom:a+o},u=r.find(p=>p&&p.right>p.left&&p.bottom>p.top&&_(s,p));if(!u)break;a=Math.round(n?u.top-g-o:u.bottom+g)}return{left:t.left,top:a}}
@@ -1,12 +1,12 @@
1
- import{LAUNCHER_LIMITS as C,launcherChatBox as ut,launcherModalBox as mt,launcherSpot as pt,launcherStack as ft}from"/public/js/launcher-settings.mjs?v=20261110-chat-times-settings";const V=i=>`launcher-chat-size:${i}`,vt=i=>{try{const c=globalThis.S?.get?.(V(i));return c&&Number(c.width)&&Number(c.height)?c:null}catch{return null}},Z=(i,c)=>{try{globalThis.S?.set?.(V(i),c)}catch{}},J="(max-width: 640px)",Q=[".site-search-floating-trigger","#back-to-top-btn","#go-to-bottom-btn",".dm-theme-switcher:not(.dm-ts-inline)","nav.dm-breadcrumbs",".dm-motion-fab"].join(","),tt={sm:"360px",md:"480px",lg:"640px",xl:"860px"},gt=i=>String(i??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),et=()=>document.documentElement.classList.contains("dm-reduced-motion")||matchMedia("(prefers-reduced-motion: reduce)").matches,bt=`
1
+ import{LAUNCHER_LIMITS as C,launcherChatBox as mt,launcherModalBox as pt,launcherSpot as ft,launcherStack as vt}from"/public/js/launcher-settings.mjs?v=20261110-builder-characters";const V=i=>`launcher-chat-size:${i}`,bt=i=>{try{const c=globalThis.S?.get?.(V(i));return c&&Number(c.width)&&Number(c.height)?c:null}catch{return null}},Z=(i,c)=>{try{globalThis.S?.set?.(V(i),c)}catch{}};import{mountCharacter as gt}from"./character-view.mjs?v=20261110-builder-characters";const J="(max-width: 640px)",Q=[".site-search-floating-trigger","#back-to-top-btn","#go-to-bottom-btn",".dm-theme-switcher:not(.dm-ts-inline)","nav.dm-breadcrumbs",".dm-motion-fab"].join(","),tt={sm:"360px",md:"480px",lg:"640px",xl:"860px"},yt=i=>String(i??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),et=()=>document.documentElement.classList.contains("dm-reduced-motion")||matchMedia("(prefers-reduced-motion: reduce)").matches,wt=`
2
2
  <button type="button" class="dm-launcher" data-id="{{id}}" data-bind-class="cls" data-bind-style="style.value"
3
3
  data-bind-aria-expanded="expanded.value" data-bind-hidden="hidden.value" aria-haspopup="dialog" aria-label="{{label}}">
4
4
  <span class="dm-launcher-icon" data-icon="{{icon}}" aria-hidden="true"></span>
5
5
  <span class="dm-launcher-label" data-bind-hidden="!pill">{{label}}</span>
6
- </button>`,yt=`
6
+ </button>`,xt=`
7
7
  <div class="dm-launcher-chat-head">
8
8
  <strong class="dm-launcher-chat-title" data-bind-text="title"></strong>
9
9
  <button type="button" class="dm-launcher-chat-close" data-on-click="close" aria-label="Close"><span data-icon="x" aria-hidden="true"></span></button>
10
10
  </div>
11
11
  <div class="dm-launcher-chat-body"></div>
12
- <p class="dm-launcher-note" data-bind-hidden="!note.value" data-bind-text="note.value"></p>`;function wt(i){const c=i.getBoundingClientRect();return getComputedStyle(i).opacity!=="0"||i.offsetParent!==null?c:{top:Math.min(c.top,i.offsetTop),left:Math.min(c.left,i.offsetLeft),right:Math.max(c.right,i.offsetLeft+i.offsetWidth),bottom:Math.max(c.bottom,i.offsetTop+i.offsetHeight)}}function nt(i){window.Domma?.icons?.scan&&window.Domma.icons.scan(i)}function ot(i,{fill:c}){const l=document.createElement("iframe");if(l.className="dm-launcher-frame"+(c?" is-fill":""),l.title=i.action.title,l.src=`/_launcher/${encodeURIComponent(i.id)}`,l.setAttribute("loading","eager"),!c){let f=null;l.addEventListener("load",()=>{const H=l.contentDocument;if(!H?.body)return;const $=H.querySelector(".site-content")||H.body,N=()=>{l.style.height=`${Math.ceil($.getBoundingClientRect().height)}px`};N(),f?.disconnect(),f=new ResizeObserver(N),f.observe($)})}return l}export function mountLaunchers(i){if(!Array.isArray(i)||!i.length||document.querySelector(".dm-launchers"))return null;const c=M.observable(matchMedia(J).matches),l=document.createElement("div");l.className="dm-launchers";const f=i.map(t=>{const n=o=>o&&t.phone?.override?{...t,...t.phone}:t,e=t.triggerStyle==="icon-text",a=o=>{const v=n(o),x={"--launcher-size":`${v.size}px`,"--launcher-radius":`${e?999:Math.min(t.radius,Math.floor(v.size/2))}px`,"--launcher-glyph":`${Math.round(v.size*20/52)}px`};return t.colours.background&&(x["--launcher-bg"]=t.colours.background),t.colours.text&&(x["--launcher-fg"]=t.colours.text),x},h=M.observable(-9999),u=M.observable(-9999);return{id:t.id,label:t.label,icon:t.icon,pill:e,launcher:t,look:n,left:h,top:u,cls:["dm-launcher--"+t.action.type,e?"dm-launcher--pill":"",t.class].filter(Boolean).join(" "),style:M.computed(()=>({...a(c.value),left:`${h.value}px`,top:`${u.value}px`})),expanded:M.observable("false"),hidden:M.computed(()=>t.disc===!1||t.devices==="desktop"&&c.value||t.devices==="phone"&&!c.value)}});l.innerHTML='<div class="dm-launchers-list" data-each="rows.value key=id"></div>',l.firstElementChild.innerHTML=bt;const H=M.applyBindings({rows:M.observable(f)},l);document.body.appendChild(l),nt(l);const $=t=>l.querySelector(`.dm-launcher[data-id="${CSS.escape(t)}"]`),N={TL:"right",ML:"right",BL:"right",TR:"left",MR:"left",BR:"left",TC:"bottom",BC:"top"},B=new Map;for(const t of f){const n=t.launcher.tooltip,e=$(t.id);if(!(!n||!e||typeof E.tooltip!="function"))try{B.set(t.id,E.tooltip(e,{content:n,position:N[t.launcher.position]||"top",trigger:"hover focus",className:"dm-launcher-tip"}))}catch{}}function O(){const t=document.documentElement.clientWidth,n=window.innerHeight,e=[...document.querySelectorAll(Q)].filter(a=>!l.contains(a)&&getComputedStyle(a).position==="fixed"&&getComputedStyle(a).display!=="none").map(wt);for(const a of f){const h=$(a.id);if(!h||h.hidden)continue;const u=a.look(c.peek()),o=h.offsetWidth,v=h.offsetHeight,x=pt(u.position,{w:o,h:v,vw:t,vh:n,offsetX:u.offsetX,offsetY:u.offsetY}),S=ft(u.position,x,{w:o,h:v},e),T=Math.max(0,Math.min(t-o,S.left)),R=Math.max(0,Math.min(n-v,S.top));a.left.value=T,a.top.value=R,e.push({left:T,top:R,right:T+o,bottom:R+v})}}let P=0;const A=()=>{cancelAnimationFrame(P),P=requestAnimationFrame(O)},K=new MutationObserver(t=>{t.some(n=>[...n.addedNodes].some(e=>e.nodeType===1&&e.matches?.(Q)))&&A()});K.observe(document.body,{childList:!0});const W=matchMedia(J),U=()=>{c.value=W.matches,A()};W.addEventListener?.("change",U),window.addEventListener("resize",A),window.addEventListener("load",A,{once:!0}),O();let b=null;const at=M.effect(()=>{const t=f.some(n=>n.expanded.value==="true"&&(n.launcher.action.type!=="chat"||c.value));document.documentElement.classList.toggle("dm-launcher-covering",t)});function Y(){const t=b;b=null,t&&(t.row.expanded.value="false",t.close())}function it(t){const n=t.launcher,e=mt(n.action),a=E.modal({title:n.action.title,size:e.width,content:ot(n,{fill:!!e.height}),className:"dm-launcher-modal",bodyClass:"dm-launcher-modal-body",buttons:[],animation:et()?!1:"fade",onClosed:()=>{b?.row===t&&(b=null,t.expanded.value="false"),setTimeout(()=>{try{a.destroy()}catch{}},0)}});return a.element?.classList.add("dm-launcher-modal",`dm-launcher-modal--${n.action.size}`),a.element?.style.setProperty("--launcher-modal-w",e.width),e.height&&(a.element?.classList.add("dm-launcher-modal--fixed"),a.element?.style.setProperty("--launcher-modal-h",e.height)),a.open(),()=>{try{a.close()}catch{}}}function ct(t){const n=t.launcher,e=E.slideover({title:gt(n.action.title),position:n.action.side,size:c.peek()?"full":tt[n.action.width]||tt.md,content:ot(n,{fill:!0}),bodyClass:"dm-launcher-so-body",animation:!et(),onClosed:()=>{b?.row===t&&(b=null,t.expanded.value="false"),setTimeout(()=>{try{e.destroy?.()}catch{}e.element?.remove()},0)}});return e.element?.classList.add("dm-launcher-so"),e.open(),()=>{try{e.close()}catch{}}}function st(t,n){const e=t.launcher,a=$(t.id),h=a&&!a.hidden?a:null,u=h||(n?.isConnected?n:null),o=document.createElement("div");o.className="dm-launcher-chat",o.setAttribute("role","dialog"),o.setAttribute("aria-label",e.action.title),o.innerHTML=yt;const v=M.observable("");let x=null,S=!1;const T=()=>{if(!S){S=!0;try{x?.destroy?.()}catch{}R.dispose?.(),o.remove(),document.removeEventListener("keydown",G),window.removeEventListener("resize",D),b?.row===t&&(b=null,t.expanded.value="false"),(u?.isConnected?u:null)?.focus()}},R=M.applyBindings({title:e.action.title,note:v,close:T},o),G=r=>{r.key!=="Escape"||r.defaultPrevented||!o.contains(document.activeElement)||(r.preventDefault(),T())},D=()=>{if(c.peek()){o.classList.add("is-full"),o.removeAttribute("style");return}o.classList.remove("is-full");const r=document.documentElement.clientWidth,s=window.innerHeight,_=e.chat?.resizable!==!1&&vt(e.id)||ut(e.chat||{}),y=Math.min(Math.max(C.chatWidth[0],Number(_.width)),C.chatWidth[1],r-24),w=Math.min(Math.max(C.chatHeight[0],Number(_.height)),C.chatHeight[1],s-24),m=L=>Math.max(12,Math.min(r-y-12,L)),d=L=>Math.max(12,Math.min(s-w-12,L));let g,z;if(!h){g=m(e.position[1]==="L"?24:r-y-24),z=d(s-w-24),Object.assign(o.style,{left:`${g}px`,top:`${z}px`,width:`${y}px`,height:`${w}px`});return}const p=h.getBoundingClientRect(),k=p.left+p.width/2>r/2;e.position[0]==="M"?(g=m(k?p.left-y-12:p.right+12),z=d(p.top+p.height/2-w/2)):(g=m(k?p.right-y:p.left),z=e.position[0]==="T"?d(p.bottom+12):d(p.top-w-12)),Object.assign(o.style,{left:`${g}px`,top:`${z}px`,width:`${y}px`,height:`${w}px`})};if(document.body.appendChild(o),D(),e.chat?.resizable!==!1){const r=document.createElement("div");r.className="dm-launcher-chat-grip",r.setAttribute("role","separator"),r.setAttribute("aria-label","Resize the chat"),r.title="Drag to resize",o.appendChild(r);let s=null;const _=m=>{if(!s)return;const d=document.documentElement.clientWidth,g=window.innerHeight,z=(m.clientX-s.x)*(s.fromLeft?-1:1),p=(m.clientY-s.y)*(s.fromTop?-1:1),k=Math.round(Math.min(Math.max(C.chatWidth[0],s.w+z),C.chatWidth[1],d-24)),L=Math.round(Math.min(Math.max(C.chatHeight[0],s.h+p),C.chatHeight[1],g-24)),dt=s.fromLeft?s.right-k:s.left,ht=s.fromTop?s.bottom-L:s.top;Object.assign(o.style,{width:`${k}px`,height:`${L}px`,left:`${Math.max(12,Math.min(d-k-12,dt))}px`,top:`${Math.max(12,Math.min(g-L-12,ht))}px`}),s.size={width:k,height:L}},y=()=>{s&&(s.size&&Z(e.id,s.size),s=null,o.classList.remove("is-resizing"),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",y))},w=()=>{const[m,d]=String(e.position||"BR");r.dataset.corner=`${m==="T"?"b":"t"}${d==="L"?"r":"l"}`};w(),r.addEventListener("pointerdown",m=>{if(c.peek())return;m.preventDefault();const d=o.getBoundingClientRect(),g=r.dataset.corner;s={x:m.clientX,y:m.clientY,w:d.width,h:d.height,left:d.left,top:d.top,right:d.right,bottom:d.bottom,fromLeft:g[1]==="l",fromTop:g[0]==="t"},o.classList.add("is-resizing"),window.addEventListener("pointermove",_),window.addEventListener("pointerup",y)}),r.addEventListener("dblclick",()=>{Z(e.id,null),D(),w()})}nt(o),document.addEventListener("keydown",G),window.addEventListener("resize",D);const rt=o.querySelector(".dm-launcher-chat-body");return import("/public/js/launcher-chat.mjs").then(r=>{if(!S){if(typeof r.mountChat!="function")throw new Error("no mountChat");x=r.mountChat(rt,{launcherId:e.id,title:e.action.title,chat:e.chat||{}})}}).catch(()=>{S||(v.value="Chat is unavailable right now. Please try again later.")}),o.querySelector(".dm-launcher-chat-close")?.focus(),T}function I(t,n=null){const e=f.find(o=>o.id===t);if(!e)return;const a=b?.row===e;if(Y(),a)return;e.expanded.value="true";try{B.get(e.id)?.close()}catch{}const h=e.launcher.action.type,u=h==="chat"?st(e,n):h==="slideover"?ct(e):it(e);b={row:e,close:u}}const j=t=>{const n=t.target.closest(".dm-launcher");n&&I(n.dataset.id)};l.addEventListener("click",j);const F=/^#launcher-([a-z0-9][a-z0-9-]{0,39})$/,lt=t=>{const n=t.closest("[data-launcher]");if(n)return{el:n,id:n.dataset.launcher};const e=t.closest("a[href]"),a=e&&F.exec(e.getAttribute("href")||"");return a?{el:e,id:a[1]}:null},X=t=>{if(t.button>0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||l.contains(t.target))return;const n=t.target instanceof Element?lt(t.target):null;!n||!f.some(e=>e.id===n.id)||(t.preventDefault(),I(n.id,n.el))};document.addEventListener("click",X);const q=F.exec(location.hash);return q&&f.some(t=>t.id===q[1])&&(history.replaceState(history.state,"",location.pathname+location.search),setTimeout(()=>I(q[1]),0)),{place:O,launch:I,destroy(){Y(),at?.(),document.documentElement.classList.remove("dm-launcher-covering");for(const t of B.values())try{t.destroy()}catch{}B.clear(),cancelAnimationFrame(P),K.disconnect(),W.removeEventListener?.("change",U),window.removeEventListener("resize",A),window.removeEventListener("load",A),l.removeEventListener("click",j),document.removeEventListener("click",X),H?.dispose?.(),l.remove()}}}typeof window<"u"&&Array.isArray(window.__CMS_LAUNCHERS__)&&window.M&&window.E&&(window.DommaLaunchers=mountLaunchers(window.__CMS_LAUNCHERS__));
12
+ <p class="dm-launcher-note" data-bind-hidden="!note.value" data-bind-text="note.value"></p>`;function Mt(i){const c=i.getBoundingClientRect();return getComputedStyle(i).opacity!=="0"||i.offsetParent!==null?c:{top:Math.min(c.top,i.offsetTop),left:Math.min(c.left,i.offsetLeft),right:Math.max(c.right,i.offsetLeft+i.offsetWidth),bottom:Math.max(c.bottom,i.offsetTop+i.offsetHeight)}}function nt(i){window.Domma?.icons?.scan&&window.Domma.icons.scan(i)}function ot(i,{fill:c}){const r=document.createElement("iframe");if(r.className="dm-launcher-frame"+(c?" is-fill":""),r.title=i.action.title,r.src=`/_launcher/${encodeURIComponent(i.id)}`,r.setAttribute("loading","eager"),!c){let u=null;r.addEventListener("load",()=>{const H=r.contentDocument;if(!H?.body)return;const S=H.querySelector(".site-content")||H.body,R=()=>{r.style.height=`${Math.ceil(S.getBoundingClientRect().height)}px`};R(),u?.disconnect(),u=new ResizeObserver(R),u.observe(S)})}return r}export function mountLaunchers(i){if(!Array.isArray(i)||!i.length||document.querySelector(".dm-launchers"))return null;const c=M.observable(matchMedia(J).matches),r=document.createElement("div");r.className="dm-launchers";const u=i.map(t=>{const n=o=>o&&t.phone?.override?{...t,...t.phone}:t,e=t.triggerStyle==="icon-text",a=o=>{const v=n(o),x={"--launcher-size":`${v.size}px`,"--launcher-radius":`${e?999:Math.min(t.radius,Math.floor(v.size/2))}px`,"--launcher-glyph":`${Math.round(v.size*20/52)}px`};return t.colours.background&&(x["--launcher-bg"]=t.colours.background),t.colours.text&&(x["--launcher-fg"]=t.colours.text),x},d=M.observable(-9999),m=M.observable(-9999);return{id:t.id,label:t.label,icon:t.icon,pill:e,launcher:t,look:n,left:d,top:m,cls:["dm-launcher--"+t.action.type,e?"dm-launcher--pill":"",t.class].filter(Boolean).join(" "),style:M.computed(()=>({...a(c.value),left:`${d.value}px`,top:`${m.value}px`})),expanded:M.observable("false"),hidden:M.computed(()=>t.disc===!1||t.devices==="desktop"&&c.value||t.devices==="phone"&&!c.value)}});r.innerHTML='<div class="dm-launchers-list" data-each="rows.value key=id"></div>',r.firstElementChild.innerHTML=wt;const H=M.applyBindings({rows:M.observable(u)},r);document.body.appendChild(r),nt(r);const S=t=>r.querySelector(`.dm-launcher[data-id="${CSS.escape(t)}"]`),R=[];for(const t of u){const n=t.launcher.chat;if(!n?.bot||!n.character||n.characterOptions?.enabled===!1||n.characterOptions?.launchers===!1)continue;const e=S(t.id);if(!e)continue;e.classList.add("dm-character-disc");const a=e.querySelector(".dm-launcher-label"),d=gt(e,{id:n.character,portrait:!0,animated:!1});a&&e.appendChild(a),R.push(d)}const at={TL:"right",ML:"right",BL:"right",TR:"left",MR:"left",BR:"left",TC:"bottom",BC:"top"},B=new Map;for(const t of u){const n=t.launcher.tooltip,e=S(t.id);if(!(!n||!e||typeof E.tooltip!="function"))try{B.set(t.id,E.tooltip(e,{content:n,position:at[t.launcher.position]||"top",trigger:"hover focus",className:"dm-launcher-tip"}))}catch{}}function D(){const t=document.documentElement.clientWidth,n=window.innerHeight,e=[...document.querySelectorAll(Q)].filter(a=>!r.contains(a)&&getComputedStyle(a).position==="fixed"&&getComputedStyle(a).display!=="none").map(Mt);for(const a of u){const d=S(a.id);if(!d||d.hidden)continue;const m=a.look(c.peek()),o=d.offsetWidth,v=d.offsetHeight,x=ft(m.position,{w:o,h:v,vw:t,vh:n,offsetX:m.offsetX,offsetY:m.offsetY}),T=vt(m.position,x,{w:o,h:v},e),z=Math.max(0,Math.min(t-o,T.left)),_=Math.max(0,Math.min(n-v,T.top));a.left.value=z,a.top.value=_,e.push({left:z,top:_,right:z+o,bottom:_+v})}}let q=0;const A=()=>{cancelAnimationFrame(q),q=requestAnimationFrame(D)},K=new MutationObserver(t=>{t.some(n=>[...n.addedNodes].some(e=>e.nodeType===1&&e.matches?.(Q)))&&A()});K.observe(document.body,{childList:!0});const P=matchMedia(J),U=()=>{c.value=P.matches,A()};P.addEventListener?.("change",U),window.addEventListener("resize",A),window.addEventListener("load",A,{once:!0}),D();let g=null;const it=M.effect(()=>{const t=u.some(n=>n.expanded.value==="true"&&(n.launcher.action.type!=="chat"||c.value));document.documentElement.classList.toggle("dm-launcher-covering",t)});function Y(){const t=g;g=null,t&&(t.row.expanded.value="false",t.close())}function ct(t){const n=t.launcher,e=pt(n.action),a=E.modal({title:n.action.title,size:e.width,content:ot(n,{fill:!!e.height}),className:"dm-launcher-modal",bodyClass:"dm-launcher-modal-body",buttons:[],animation:et()?!1:"fade",onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{a.destroy()}catch{}},0)}});return a.element?.classList.add("dm-launcher-modal",`dm-launcher-modal--${n.action.size}`),a.element?.style.setProperty("--launcher-modal-w",e.width),e.height&&(a.element?.classList.add("dm-launcher-modal--fixed"),a.element?.style.setProperty("--launcher-modal-h",e.height)),a.open(),()=>{try{a.close()}catch{}}}function st(t){const n=t.launcher,e=E.slideover({title:yt(n.action.title),position:n.action.side,size:c.peek()?"full":tt[n.action.width]||tt.md,content:ot(n,{fill:!0}),bodyClass:"dm-launcher-so-body",animation:!et(),onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{e.destroy?.()}catch{}e.element?.remove()},0)}});return e.element?.classList.add("dm-launcher-so"),e.open(),()=>{try{e.close()}catch{}}}function rt(t,n){const e=t.launcher,a=S(t.id),d=a&&!a.hidden?a:null,m=d||(n?.isConnected?n:null),o=document.createElement("div");o.className="dm-launcher-chat",o.setAttribute("role","dialog"),o.setAttribute("aria-label",e.action.title),o.innerHTML=xt;const v=M.observable("");let x=null,T=!1;const z=()=>{if(!T){T=!0;try{x?.destroy?.()}catch{}_.dispose?.(),o.remove(),document.removeEventListener("keydown",G),window.removeEventListener("resize",O),g?.row===t&&(g=null,t.expanded.value="false"),(m?.isConnected?m:null)?.focus()}},_=M.applyBindings({title:e.action.title,note:v,close:z},o),G=l=>{l.key!=="Escape"||l.defaultPrevented||!o.contains(document.activeElement)||(l.preventDefault(),z())},O=()=>{if(c.peek()){o.classList.add("is-full"),o.removeAttribute("style");return}o.classList.remove("is-full");const l=document.documentElement.clientWidth,s=window.innerHeight,N=e.chat?.resizable!==!1&&bt(e.id)||mt(e.chat||{}),y=Math.min(Math.max(C.chatWidth[0],Number(N.width)),C.chatWidth[1],l-24),w=Math.min(Math.max(C.chatHeight[0],Number(N.height)),C.chatHeight[1],s-24),p=L=>Math.max(12,Math.min(l-y-12,L)),h=L=>Math.max(12,Math.min(s-w-12,L));let b,k;if(!d){b=p(e.position[1]==="L"?24:l-y-24),k=h(s-w-24),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`});return}const f=d.getBoundingClientRect(),$=f.left+f.width/2>l/2;e.position[0]==="M"?(b=p($?f.left-y-12:f.right+12),k=h(f.top+f.height/2-w/2)):(b=p($?f.right-y:f.left),k=e.position[0]==="T"?h(f.bottom+12):h(f.top-w-12)),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`})};if(document.body.appendChild(o),O(),e.chat?.resizable!==!1){const l=document.createElement("div");l.className="dm-launcher-chat-grip",l.setAttribute("role","separator"),l.setAttribute("aria-label","Resize the chat"),l.title="Drag to resize",o.appendChild(l);let s=null;const N=p=>{if(!s)return;const h=document.documentElement.clientWidth,b=window.innerHeight,k=(p.clientX-s.x)*(s.fromLeft?-1:1),f=(p.clientY-s.y)*(s.fromTop?-1:1),$=Math.round(Math.min(Math.max(C.chatWidth[0],s.w+k),C.chatWidth[1],h-24)),L=Math.round(Math.min(Math.max(C.chatHeight[0],s.h+f),C.chatHeight[1],b-24)),ht=s.fromLeft?s.right-$:s.left,ut=s.fromTop?s.bottom-L:s.top;Object.assign(o.style,{width:`${$}px`,height:`${L}px`,left:`${Math.max(12,Math.min(h-$-12,ht))}px`,top:`${Math.max(12,Math.min(b-L-12,ut))}px`}),s.size={width:$,height:L}},y=()=>{s&&(s.size&&Z(e.id,s.size),s=null,o.classList.remove("is-resizing"),window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",y))},w=()=>{const[p,h]=String(e.position||"BR");l.dataset.corner=`${p==="T"?"b":"t"}${h==="L"?"r":"l"}`};w(),l.addEventListener("pointerdown",p=>{if(c.peek())return;p.preventDefault();const h=o.getBoundingClientRect(),b=l.dataset.corner;s={x:p.clientX,y:p.clientY,w:h.width,h:h.height,left:h.left,top:h.top,right:h.right,bottom:h.bottom,fromLeft:b[1]==="l",fromTop:b[0]==="t"},o.classList.add("is-resizing"),window.addEventListener("pointermove",N),window.addEventListener("pointerup",y)}),l.addEventListener("dblclick",()=>{Z(e.id,null),O(),w()})}nt(o),document.addEventListener("keydown",G),window.addEventListener("resize",O);const dt=o.querySelector(".dm-launcher-chat-body");return import("/public/js/launcher-chat.mjs?v=20261110-builder-characters").then(l=>{if(!T){if(typeof l.mountChat!="function")throw new Error("no mountChat");x=l.mountChat(dt,{launcherId:e.id,title:e.action.title,chat:e.chat||{}})}}).catch(()=>{T||(v.value="Chat is unavailable right now. Please try again later.")}),o.querySelector(".dm-launcher-chat-close")?.focus(),z}function I(t,n=null){const e=u.find(o=>o.id===t);if(!e)return;const a=g?.row===e;if(Y(),a)return;e.expanded.value="true";try{B.get(e.id)?.close()}catch{}const d=e.launcher.action.type,m=d==="chat"?rt(e,n):d==="slideover"?st(e):ct(e);g={row:e,close:m}}const j=t=>{const n=t.target.closest(".dm-launcher");n&&I(n.dataset.id)};r.addEventListener("click",j);const F=/^#launcher-([a-z0-9][a-z0-9-]{0,39})$/,lt=t=>{const n=t.closest("[data-launcher]");if(n)return{el:n,id:n.dataset.launcher};const e=t.closest("a[href]"),a=e&&F.exec(e.getAttribute("href")||"");return a?{el:e,id:a[1]}:null},X=t=>{if(t.button>0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||r.contains(t.target))return;const n=t.target instanceof Element?lt(t.target):null;!n||!u.some(e=>e.id===n.id)||(t.preventDefault(),I(n.id,n.el))};document.addEventListener("click",X);const W=F.exec(location.hash);return W&&u.some(t=>t.id===W[1])&&(history.replaceState(history.state,"",location.pathname+location.search),setTimeout(()=>I(W[1]),0)),{place:D,launch:I,destroy(){Y(),it?.(),document.documentElement.classList.remove("dm-launcher-covering"),R.forEach(t=>t.destroy());for(const t of B.values())try{t.destroy()}catch{}B.clear(),cancelAnimationFrame(q),K.disconnect(),P.removeEventListener?.("change",U),window.removeEventListener("resize",A),window.removeEventListener("load",A),r.removeEventListener("click",j),document.removeEventListener("click",X),H?.dispose?.(),r.remove()}}}typeof window<"u"&&Array.isArray(window.__CMS_LAUNCHERS__)&&window.M&&window.E&&(window.DommaLaunchers=mountLaunchers(window.__CMS_LAUNCHERS__));
package/scripts/build.js CHANGED
@@ -28,6 +28,7 @@ const COPY_AS_IS = [
28
28
  'public/js/celebrations/licenses',
29
29
  // Third-party browser files, shipped byte-for-byte as their authors built them.
30
30
  'public/js/vendor',
31
+ 'public/images/characters',
31
32
  'public/examples/new-celebrations.html',
32
33
  'CLAUDE.md',
33
34
  'LICENSE',
@@ -118,8 +118,8 @@ export async function chatPublicRoutes(fastify) {
118
118
  fastify.get('/config', limit(60), async (request, reply) => {
119
119
  const launcher = await launcherOf(request, reply);
120
120
  if (!launcher) return;
121
- const {greeting, botName, bot, staff, askDetails, accent, accentText, avatar, starters, personButton, times} = launcher.chat;
122
- return {greeting, botName, bot, staff, askDetails, accent, accentText, avatar, starters, personButton, times, ai: bot && launcher.chat.ai && aiAvailable(),
121
+ const {greeting, botName, bot, staff, askDetails, accent, accentText, avatar, starters, personButton, times, character, characterOptions} = launcher.chat;
122
+ return {greeting, botName, bot, staff, askDetails, accent, accentText, avatar, starters, personButton, times, character, characterOptions, ai: bot && launcher.chat.ai && aiAvailable(),
123
123
  staffOnline: staff && staffAvailable().length > 0};
124
124
  });
125
125
 
@@ -18,11 +18,13 @@ import fs from 'fs/promises';
18
18
  import path from 'path';
19
19
  import {fileURLToPath} from 'url';
20
20
  import * as cache from '../../services/cache/index.js';
21
- import {normaliseAdminPath} from '../../services/roles.js';
21
+ import {normaliseAdminPath, getPermissionsFor} from '../../services/roles.js';
22
+ import {getEffectiveRoles} from '../../services/userRoles.js';
22
23
  import {cssClassProblems} from '../../../public/js/css-classes.mjs';
23
24
  import {motionFooterMirror, normaliseMotionSettings} from '../../services/motionSettings.js';
24
25
  import {invalidateMeasurementId, measurementIdOf, normaliseMeasurementId} from '../../services/googleAnalytics.js';
25
26
  import {assistantProblem, normaliseAssistant} from '../../services/assistant.js';
27
+ import {normaliseCharacterSettings} from '../../../public/js/characters.mjs';
26
28
 
27
29
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
28
30
  const CUSTOM_CSS_FILE = path.resolve(__dirname, '../../../content/custom.css');
@@ -94,6 +96,24 @@ export async function settingsRoutes(fastify) {
94
96
  }
95
97
  });
96
98
 
99
+ // Tools may read presentation preferences without access to SMTP or other site settings.
100
+ fastify.get('/characters', {preHandler: [authenticate]}, async (request) => ({
101
+ settings: normaliseCharacterSettings(getConfig('site').characters),
102
+ canUpdate: getEffectiveRoles(request.user).some(role => getPermissionsFor('settings', 'update').includes(role))
103
+ }));
104
+ fastify.put('/characters/:id', canUpdate, async (request, reply) => {
105
+ const id = request.params.id;
106
+ if (!['dot', 'daisy'].includes(id)) return reply.code(404).send({error: 'No such builder character.'});
107
+ if (!request.body || typeof request.body.enabled !== 'boolean' || Object.keys(request.body).some(key => key !== 'enabled')) {
108
+ return reply.code(400).send({error: 'Send an enabled checkbox value.'});
109
+ }
110
+ const site = getConfig('site');
111
+ site.characters = normaliseCharacterSettings({...site.characters, [id]: request.body.enabled});
112
+ saveConfig('site', site);
113
+ await cache.invalidateTags(['site']);
114
+ return {settings: site.characters, canUpdate: true};
115
+ });
116
+
97
117
  fastify.get('/settings', canRead, async (request, reply) => {
98
118
  const config = getConfig('site');
99
119
  const safeConfig = { ...config };
@@ -130,7 +150,7 @@ export async function settingsRoutes(fastify) {
130
150
  // The "Reduce motion" control (Site Settings > Reduce motion) - services/motionSettings.js.
131
151
  'motion',
132
152
  // What every AI answer knows about the site and the rules it keeps (services/assistant.js).
133
- 'assistant'
153
+ 'assistant', 'characters'
134
154
  ]);
135
155
  const unknownKeys = Object.keys(data).filter(k => !ALLOWED_KEYS.has(k));
136
156
  if (unknownKeys.length > 0) {
@@ -170,6 +190,9 @@ export async function settingsRoutes(fastify) {
170
190
  if (raw && !id) return reply.status(400).send({error: 'Google Analytics: a measurement ID looks like G-XXXXXXXXXX.'});
171
191
  data.googleAnalytics = {measurementId: id};
172
192
  }
193
+ if ('characters' in data && (!data.characters || typeof data.characters !== 'object' || Array.isArray(data.characters))) {
194
+ return reply.status(400).send({error: 'Builders and Bots: send an object.'});
195
+ }
173
196
  if ('assistant' in data) {
174
197
  const a = data.assistant;
175
198
  if (!a || typeof a !== 'object' || Array.isArray(a)) return reply.status(400).send({error: 'AI assistant: send {context, rules}.'});
@@ -200,6 +223,7 @@ export async function settingsRoutes(fastify) {
200
223
  // The Reduce motion control: stored whitelisted, with the footer keys it used to live
201
224
  // under kept in step for older readers. A client that still writes only those footer
202
225
  // keys (fleet tooling) moves the block with them, so its change is not overruled.
226
+ if ('characters' in data) merged.characters = normaliseCharacterSettings(merged.characters);
203
227
  if ('motion' in data) {
204
228
  if (data.motion !== null && (typeof data.motion !== 'object' || Array.isArray(data.motion))) {
205
229
  return reply.status(400).send({error: 'Reduce motion: send an object.'});
@@ -12,6 +12,8 @@
12
12
  * @module services/chat/launcher-bridge
13
13
  */
14
14
  import {normaliseLauncherChat} from './settings.js';
15
+ import {getConfig} from '../../config.js';
16
+ import {characterChat} from '../../../public/js/characters.mjs';
15
17
 
16
18
  let loader = () => import('../launchers.js');
17
19
 
@@ -54,7 +56,7 @@ export async function chatLauncher(id) {
54
56
  // Launchers ships with the engine now: no module means no chat, never "allow any id".
55
57
  if (list === null) return null;
56
58
  const found = list.find(l => l && String(l.id) === id);
57
- return found ? {id, chat: normaliseLauncherChat(found.chat)} : null;
59
+ return found ? {id, chat: characterChat(normaliseLauncherChat(found.chat), getConfig('site').characters)} : null;
58
60
  }
59
61
 
60
62
  /**
@@ -96,6 +96,7 @@ export function normaliseLauncherChat(raw) {
96
96
  accent: launcherColour(r.accent),
97
97
  accentText: launcherColour(r.accentText),
98
98
  avatar: launcherAvatar(r.avatar),
99
+ character: storedChat(r).character,
99
100
  aiMaxPerChat: Number.isFinite(Number(r.aiMaxPerChat)) && String(r.aiMaxPerChat ?? '').trim() !== ''
100
101
  ? Math.min(100, Math.max(0, Math.round(Number(r.aiMaxPerChat)))) : LAUNCHER_CHAT_DEFAULTS.aiMaxPerChat,
101
102
  starters: storedChat(r).starters,
@@ -15,6 +15,7 @@
15
15
  * @module services/launchers
16
16
  */
17
17
  import {getConfig, saveConfig} from '../config.js';
18
+ import {characterChat} from '../../public/js/characters.mjs';
18
19
  import * as cache from './cache/index.js';
19
20
  import {isToolEnabled} from './tools.js';
20
21
  import {
@@ -25,7 +26,7 @@ import {
25
26
  export const LAUNCHERS_CACHE_TAG = 'site';
26
27
 
27
28
  /** Bumped by hand when launchers.mjs or launchers.css changes - the updater replaces public/ wholesale. */
28
- export const LAUNCHERS_ASSET_V = '20261110-chat-times';
29
+ export const LAUNCHERS_ASSET_V = '20261110-builder-characters';
29
30
 
30
31
  /** @returns {object[]} the stored launchers, normalised, in order; none when the file is missing or broken */
31
32
  export function getLaunchers() {
@@ -98,7 +99,11 @@ export function launchersForPage(urlPath, user) {
98
99
  if (!launchersOn()) return [];
99
100
  return getLaunchers()
100
101
  .filter(l => launcherReady(l) && launcherShowsOn(l, urlPath, Boolean(user)))
101
- .map(publicLauncher);
102
+ .map(l => {
103
+ const out = publicLauncher(l);
104
+ if (out.chat) out.chat = characterChat(out.chat, getConfig('site').characters);
105
+ return out;
106
+ });
102
107
  }
103
108
 
104
109
  /**