Add standalone DMPaint studio and refresh House colours artwork

This commit is contained in:
unimatrixgit 2026-11-20 00:33:06 +01:00
commit a2f5b8243d
381 changed files with 76391 additions and 4 deletions

View file

@ -0,0 +1,36 @@
import {readFile} from 'node:fs/promises';
import {identity} from '../node/auth.mjs';
import {can} from '../node/permissions.mjs';
const TYPES={html:'text/html',mjs:'text/javascript',js:'text/javascript',css:'text/css',svg:'image/svg+xml',png:'image/png',jpg:'image/jpeg',gif:'image/gif',json:'application/json',txt:'text/plain',woff:'font/woff',woff2:'font/woff2',ttf:'font/ttf'};
export const DMPAINT_CSP="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; worker-src 'self' blob:; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'self'";
export function createDMPaint(db,{authenticate=request=>identity(request,db),authorise=(user,node)=>can(db,user,node),load=readFile}={}){
return async request=>{
const url=new URL(request.url),path=url.pathname;
if(!['GET','HEAD'].includes(request.method))return new Response('Method not allowed',{status:405,headers:{Allow:'GET, HEAD'}});
// The icon is also used by the existing House colours field on other CP surfaces.
if(path==='/dmpaint/icon.png')return asset('./public/dmpaint/icon.png','png',request);
const user=await authenticate(request);
if(!user)return Response.json({message:'Sign in to use DMPaint.'},{status:401,headers:{'Cache-Control':'no-store'}});
const staff=await authorise(user,'web.accounts.assign');
if(path==='/api/dmpaint')return Response.json({name:'DMPaint',modes:staff?['clan','company','seal','award']:['clan','company']},{headers:{'Cache-Control':'private, no-store'}});
if(path==='/dmpaint'||path==='/dmpaint/'){
const mode=url.searchParams.get('mode')||'clan';
if(!['clan','company','seal','award'].includes(mode))return new Response('Unknown design type',{status:400});
if(['seal','award'].includes(mode)&&!staff)return new Response('Staff permission required',{status:403});
return asset('./public/dmpaint/index.html','html',request);
}
const own=path.match(/^\/dmpaint\/(entry\.mjs|theme\.css)$/);
if(own)return asset('./public/dmpaint/'+own[1],own[1].split('.').at(-1),request);
if(path.startsWith('/dmpaint/vendor/')||path.startsWith('/dmpaint/images/')){
const file=path.startsWith('/dmpaint/images/')?'images/'+path.slice('/dmpaint/images/'.length):path.slice('/dmpaint/vendor/'.length),extension=file.split('.').at(-1);
if(!file||!file.split('/').every(part=>/^[a-zA-Z0-9_@][a-zA-Z0-9_.@-]*$/.test(part))||!TYPES[extension]||extension==='html')return new Response('Not found',{status:404});
return asset('./public/vendor/svg-edit/'+file,extension,request);
}
return new Response('Not found',{status:404});
};
async function asset(path,extension,request){
try{return new Response(request.method==='HEAD'?null:await load(new URL(path,import.meta.url)),{headers:{'Content-Type':TYPES[extension]+(extension==='html'||extension==='js'||extension==='mjs'||extension==='css'?'; charset=utf-8':''),'Cache-Control':'private, no-store','X-Content-Type-Options':'nosniff','Content-Security-Policy':DMPAINT_CSP}});}
catch(error){if(error.code==='ENOENT')return new Response('DMPaint asset unavailable',{status:404});throw error;}
}
}

View file

@ -0,0 +1 @@
.dmpaint-workspace{width:100%;min-width:0}.dmpaint-workspace>p{color:#c6d0bf;line-height:1.6}.dmpaint-modes{display:flex;gap:12px;flex-wrap:wrap;margin:18px 0}.dmpaint-modes button{border:1px solid #9e8547;border-radius:8px;padding:10px 18px;background:#112b22;color:#ecd38e;cursor:pointer}.dmpaint-modes button[aria-pressed=true]{background:#34513a;border-color:#e4c675;box-shadow:inset 0 -2px #e4c675}.dmpaint-workspace iframe{display:block;width:100%;height:850px;max-height:none;border:1px solid #a38c4e;border-radius:12px;background:#10251e}@media(max-width:700px){.dmpaint-workspace iframe{height:900px}.dmpaint-modes{gap:8px}}

View file

@ -0,0 +1,16 @@
const labels={clan:'Clan logo',company:'Company logo',seal:'Seals',award:'Awards'};
export async function mountDMPaint(host){
const link=document.createElement('link');link.rel='stylesheet';link.href='/v2/cp-v2-dmpaint.css';document.head.append(link);
const root=document.createElement('section');root.className='dmpaint-workspace';host.replaceChildren(root);
const state=document.createElement('p');state.setAttribute('role','status');state.textContent='Opening DMPaint…';root.append(state);
let dirty=false;const beforeLeave=event=>{if(dirty){event.preventDefault();event.returnValue='';}};
try{
const response=await fetch('/api/dmpaint',{credentials:'same-origin',cache:'no-store'}),data=await response.json();if(!response.ok)throw Error(data.message||'DMPaint is unavailable.');
const nav=document.createElement('nav');nav.className='dmpaint-modes';nav.setAttribute('aria-label','Design type');
const frame=document.createElement('iframe');frame.title='DMPaint graphics editor';frame.setAttribute('sandbox','allow-scripts allow-same-origin allow-downloads allow-modals');frame.src='/dmpaint/?mode=clan';
for(const mode of data.modes){const button=document.createElement('button');button.type='button';button.textContent=labels[mode];button.setAttribute('aria-pressed',String(mode==='clan'));button.onclick=()=>{if(dirty&&!confirm('Download your current design before switching. Leave this drawing?'))return;frame.src='/dmpaint/?mode='+mode;for(const b of nav.children)b.setAttribute('aria-pressed',String(b===button));};nav.append(button);}
frame.onload=()=>{try{const doc=frame.contentDocument;doc?.addEventListener('pointerdown',()=>{dirty=true;},{once:true});doc?.addEventListener('keydown',()=>{dirty=true;},{once:true});}catch{}};
state.textContent='Create your artwork, download it, then upload it using your existing clan or company settings.';root.append(nav,frame);window.addEventListener('beforeunload',beforeLeave);
}catch(error){state.textContent=error.message;}
return()=>{window.removeEventListener('beforeunload',beforeLeave);root.remove();link.remove();};
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,30 @@
import Editor from '/dmpaint/vendor/Editor.js';
const status=document.querySelector('#paint-status'),svgButton=document.querySelector('#download-svg'),pngButton=document.querySelector('#download-png');
const mode=new URL(location.href).searchParams.get('mode')||'clan';
const names={clan:'Clan logo',company:'Company logo',seal:'Staff seal',award:'Staff award'};
let editor;
const filename=()=>document.querySelector('#filename').value.replace(/[^a-zA-Z0-9_-]/g,'-').slice(0,64)||'dmpaint-design';
function download(blob,extension){const url=URL.createObjectURL(blob),link=document.createElement('a');link.href=url;link.download=filename()+'.'+extension;link.click();setTimeout(()=>URL.revokeObjectURL(url),30000);}
async function start(){
const response=await fetch('/api/dmpaint',{credentials:'same-origin',cache:'no-store'}),access=await response.json();
if(!response.ok||!access.modes?.includes(mode))throw Error(access.message||'You do not have access to this design type.');
document.querySelector('#design-kind').textContent=names[mode]+' · Design & download';
document.querySelector('#filename').value='my-'+mode;
editor=new Editor(document.querySelector('#editor-container'));
editor.setConfig({canvasName:'dmpaint',dimensions:[512,512],imgPath:'/dmpaint/vendor/images',extPath:'/dmpaint/vendor/extensions',lang:'en',initFill:{color:'D9BB69',opacity:1},initStroke:{color:'12362B',opacity:1,width:2},noDefaultExtensions:true,extensions:['ext-opensave','ext-polystar','ext-eyedropper','ext-layer_view','ext-panning','ext-grid'],userExtensions:[],allowedOrigins:[],preventAllURLConfig:true,preventURLContentLoading:true,lockExtensions:true,noStorageOnLoad:true,no_save_warning:false});
editor.ready(()=>{svgButton.disabled=pngButton.disabled=false;status.textContent='Draw, add text or open an existing image. Download before leaving this page.';});
await editor.init();
}
svgButton.onclick=()=>{try{download(new Blob([editor.svgCanvas.getSvgString()],{type:'image/svg+xml'}),'svg');status.textContent='SVG downloaded. Keep this editable file to continue your design later.';}catch(error){status.textContent=error.message;}};
pngButton.onclick=async()=>{
pngButton.disabled=true;let url;
try{
const svg=editor.svgCanvas.getSvgString(),doc=new DOMParser().parseFromString(svg,'image/svg+xml'),root=doc.documentElement,view=root.getAttribute('viewBox')?.split(/[ ,]+/).map(Number);
const width=Number.parseFloat(root.getAttribute('width'))||view?.[2]||512,height=Number.parseFloat(root.getAttribute('height'))||view?.[3]||512;
if(!(width>0&&height>0&&width<=4096&&height<=4096))throw Error('Use a canvas size up to 4096 × 4096 pixels for PNG export.');
url=URL.createObjectURL(new Blob([svg],{type:'image/svg+xml'}));const image=new Image();image.src=url;await image.decode();
const canvas=document.createElement('canvas');canvas.width=Math.ceil(width);canvas.height=Math.ceil(height);canvas.getContext('2d').drawImage(image,0,0,canvas.width,canvas.height);
const blob=await new Promise(resolve=>canvas.toBlob(resolve,'image/png'));if(!blob)throw Error('PNG export failed.');download(blob,'png');status.textContent='PNG downloaded. Upload it using the existing logo or artwork settings.';
}catch(error){status.textContent='PNG could not be exported: '+error.message;}finally{if(url)URL.revokeObjectURL(url);pngButton.disabled=false;}
};
start().catch(error=>{status.textContent='DMPaint could not open: '+error.message;});

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

View file

@ -0,0 +1,3 @@
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>DMPaint · DuneRealms</title><link rel="icon" href="/dmpaint/icon.png"><link rel="stylesheet" href="/dmpaint/vendor/svgedit.css"><link rel="stylesheet" href="/dmpaint/theme.css"><script type="module" src="/dmpaint/entry.mjs"></script></head>
<body><header class="paint-header"><img src="/dmpaint/icon.png" alt="" width="48" height="48"><div><h1>DMPaint</h1><p id="design-kind">Your colours. Your mark.</p></div><label>Filename <input id="filename" value="my-design" maxlength="64" autocomplete="off"></label><div class="paint-actions"><button id="download-svg" type="button" disabled>Download SVG</button><button id="download-png" type="button" disabled>Download PNG</button></div></header><p id="paint-status" role="status">Opening your drawing studio…</p><main id="editor-container" aria-label="DMPaint drawing editor"></main><footer>Design here. Download your artwork. Upload it where you want to use it. <span>Powered by SVG-Edit · <a href="/dmpaint/vendor/LICENSE.txt" target="_blank" rel="noopener">MIT licence</a></span></footer></body></html>

View file

@ -0,0 +1,3 @@
:root{color-scheme:dark;--main-bg-color:#17382e;--text-color:#f0e5c8;--border-color:#88703c;--canvas-bg-color:#10291f;--link-color:#e6c774;--ruler-color:#b8a56d;--icon-bg-color:#214438;--icon-bg-color-hover:#476345;--input-color:#10291f;--orange-color:#e6c774}*{box-sizing:border-box}html,body{height:100%;margin:0;background:#0b211a;color:#f0e5c8;font-family:Arial,sans-serif}body{display:flex;flex-direction:column}.paint-header{display:flex;align-items:center;gap:14px;padding:10px 18px;background:linear-gradient(110deg,#244b38,#112d24);border-bottom:1px solid #a88b47}.paint-header img{object-fit:contain}.paint-header h1{margin:0;color:#e6c774;font:700 25px Georgia,serif}.paint-header p{margin:4px 0 0;font-size:12px;color:#c7cfbb}.paint-header label{margin-left:auto;display:flex;align-items:center;gap:8px;font-size:12px}.paint-header input{width:150px;padding:8px}.paint-actions{display:flex;gap:8px}button,.paint-header input{border:1px solid #9f8548;border-radius:6px;background:#10291f;color:#f0e5c8}button{padding:9px 12px;font-weight:600;cursor:pointer}button:hover{background:#34563c}button:disabled{opacity:.5;cursor:wait}button:focus-visible,input:focus-visible{outline:2px solid #f1d88a;outline-offset:3px}#paint-status{font-size:12px;margin:0;padding:8px 18px;color:#d1d7c8;border-bottom:1px solid #6c5c33;min-height:30px}#editor-container{width:100%;height:calc(100vh - 150px);min-height:460px;flex:1;min-width:0}#workarea{background-color:#10251f;background-image:linear-gradient(45deg,#1d392e 25%,transparent 25%),linear-gradient(-45deg,#1d392e 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#1d392e 75%),linear-gradient(-45deg,transparent 75%,#1d392e 75%);background-size:24px 24px;background-position:0 0,0 12px,12px -12px,-12px 0}#tools_top,#tools_left,#tools_bottom,#sidepanels{background:#17382e}footer{display:flex;justify-content:space-between;gap:12px;padding:10px 18px;font-size:11px;color:#b8c6b4;border-top:1px solid #6c5c33}footer a{color:#e6c774}@media(max-width:740px){.paint-header{flex-wrap:wrap;padding:10px}.paint-header label{margin-left:0}.paint-actions{margin-left:auto}.paint-header h1{font-size:21px}footer{flex-direction:column}#editor-container{height:650px}}
html,body{overflow:hidden}.paint-header,body>footer,#paint-status{flex-shrink:0}#editor-container{flex:1 1 auto;height:auto;min-height:0;overflow:hidden}

View file

@ -1 +1,2 @@
.organisation-palette{display:grid;grid-template-columns:150px minmax(0,1fr);align-items:center;gap:18px 25px;min-width:0;margin:24px 0;padding:22px;border:1px solid #b69a55;border-radius:14px;background:radial-gradient(ellipse at top left,#b58e3226,transparent 70%),#102c26}.organisation-palette legend{font:700 21px Georgia,serif;color:#ecd28e;padding:0 12px}.organisation-palette>img{width:150px;height:150px;object-fit:contain;filter:drop-shadow(0 8px 12px #0007)}.organisation-paint-circles{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:20px;min-width:0}.organisation-paint-circles label{display:grid;justify-items:center;gap:12px;font-weight:600;color:#e7ce91}.organisation-paint-circles input[type=color]{display:block;appearance:none;-webkit-appearance:none;width:66px;height:66px;padding:0;border:3px solid #c7ac65;border-radius:50%;overflow:hidden;cursor:pointer;background:none;box-shadow:0 0 0 4px #182e24,0 0 0 5px #79653b,0 8px 16px #0006}.organisation-paint-circles input::-webkit-color-swatch-wrapper{padding:0}.organisation-paint-circles input::-webkit-color-swatch{border:0;border-radius:50%}.organisation-paint-circles input::-moz-color-swatch{border:0;border-radius:50%}.organisation-paint-circles input:focus-visible{outline:3px solid #fff0ae;outline-offset:5px}.organisation-palette>p{grid-column:1/-1;margin:0;color:#bdcbbb;font-size:.9rem;line-height:1.6}@media(max-width:700px){.organisation-palette{grid-template-columns:1fr;padding:20px}.organisation-palette>img{justify-self:center;width:120px;height:120px}.organisation-paint-circles{gap:14px}.organisation-paint-circles input[type=color]{width:54px;height:54px}}
.organisation-palette{grid-template-columns:minmax(0,1fr);justify-items:center;gap:24px;padding:24px}.organisation-palette>img{justify-self:center}.organisation-paint-circles{width:100%;max-width:360px;grid-template-columns:repeat(3,minmax(0,1fr));gap:24px}.organisation-paint-circles label{min-width:0;gap:14px;text-align:center}.organisation-paint-circles input[type=color]{width:clamp(42px,6vw,66px);height:auto;aspect-ratio:1}.organisation-palette>p{justify-self:stretch}@media(max-width:420px){.organisation-palette{padding:20px 16px}.organisation-paint-circles{gap:18px}.organisation-paint-circles label{font-size:.85rem}}

View file

@ -2,7 +2,7 @@ import {normalisePalette} from './organisation-palette-model.mjs';
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
export function createOrganisationPalette({colors,homeWorld}={}){
if(!document.querySelector('link[data-organisation-palette]')){const link=el('link');link.rel='stylesheet';link.href=new URL('./organisation-palette.css',import.meta.url).href;link.dataset.organisationPalette='';document.head.append(link);}
const root=el('fieldset');root.className='organisation-palette';root.append(el('legend','House colours'));const art=el('img');art.src='https://www.dunerealms.com/assets/imperial-painters-palette.svg';art.alt='';art.width=150;art.height=150;root.append(art);const paint=el('div');paint.className='organisation-paint-circles';const inputs={},initial=normalisePalette(colors,homeWorld);
const root=el('fieldset');root.className='organisation-palette';root.append(el('legend','House colours'));const art=el('img');art.src='https://cp.dunerealms.com/dmpaint/icon.png';art.alt='';art.width=150;art.height=150;root.append(art);const paint=el('div');paint.className='organisation-paint-circles';const inputs={},initial=normalisePalette(colors,homeWorld);
for(const [key,title]of [['primary','Primary'],['secondary','Secondary'],['trim','Trim']]){const label=el('label',title),input=el('input');input.type='color';input.name='houseColor_'+key;input.value=initial[key];input.setAttribute('aria-label',title+' house colour');label.prepend(input);paint.append(label);inputs[key]=input;}
root.append(paint,el('p','Your shared colours for clan heraldry and the clan/company sash.'));return {root,value:()=>normalisePalette(Object.fromEntries(Object.entries(inputs).map(([k,input])=>[k,input.value])),homeWorld)};
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,19 @@
Copyright (c) 2009-2022 by SVG-edit authors (see AUTHORS file)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,4 @@
SVG-Edit 7.4.2
https://github.com/SVG-Edit/svgedit
https://registry.npmjs.org/svgedit/-/svgedit-7.4.2.tgz
MIT license; bundled upstream browser distribution, source maps and test files omitted.

View file

@ -0,0 +1,8 @@
const supportsSvg = function () {
return Boolean(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect)
}
if (!supportsSvg()) {
window.location = './browser-not-supported.html'
}
export {}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

Some files were not shown because too many files have changed in this diff Show more