domma-cms 1.51.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,9 @@
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
+
3
7
  ## [1.51.0] - 2026-11-10
4
8
 
5
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.
@@ -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)}})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "1.51.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",