Replace layout workbenches with native editable pages and server-loaded designs
studio CI and deployment / verify-and-deploy (push) Failing after 2m55s

This commit is contained in:
2026-10-27 16:46:27 +08:00
parent e6a10ff855
commit 3ffe457be4
10 changed files with 237 additions and 35 deletions
+20
View File
@@ -0,0 +1,20 @@
import type {IncomingMessage} from 'node:http';
import {parameters,uuid} from './layout-parameters';
import layouts from '../content/templates/layouts.json';
import type {Design} from './native-layout';
/** Only forward the session to our fixed private Wiki service, never a request Host. */
export async function readDesign(id:unknown,req:IncomingMessage):Promise<Design|null>{
if(!uuid(id))return null;
const origin=process.env.STUDIO_WIKI_ORIGIN||'http://waterfall-wiki:3000';
const headers:Record<string,string>={};
if(req.headers.cookie)headers.cookie=req.headers.cookie;
if(req.headers.authorization)headers.authorization=req.headers.authorization;
const response=await fetch(`${origin}/api/studio/designs/${id}`,{headers,redirect:'error',cache:'no-store',signal:AbortSignal.timeout(8000)});
if(response.status===404||response.status===400)return null;
if(!response.ok)throw new Error('Saved layout service unavailable');
const {design}=await response.json() as {design:Design};
const layout=layouts.find(l=>l.id===design.layoutId);
if(!layout||design.id!==id)throw new Error('Invalid saved layout');
return {...design,parameters:parameters(layout,design.parameters)};
}
+54
View File
@@ -0,0 +1,54 @@
import type {CSSProperties} from 'react';
import type {Layout,Parameters,Slot} from './layout-parameters';
export type Design={id:string;name:string;layoutId:string;parameters:Parameters;revision:number;url:string};
export const emptyParameters=():Parameters=>({texts:{},images:{},decorations:{}});
export const designUrl=(layoutId:string,id:string)=>`/studio/layouts/${layoutId}?id=${id}`;
export function nativeLayout(layout:Layout):Layout {
return {id:layout.id,name:layout.name,width:layout.width,height:layout.height,elements:layout.elements.map(({id,kind,role,box,direction,text,reading})=>({id,kind,role,box,direction,text,reading}))};
}
export function paperColor(id:string){return ['ref-04','ref-22'].includes(id)?'#a8b0ae':'#f5f5ef'}
export function textColor(id:string,slot:Slot){return (id==='ref-04'&&['T01','T02'].includes(slot.id))||(id==='ref-22'&&slot.id==='T01')||(id==='ref-27'&&slot.id==='T01')||(id==='ref-10'&&slot.id==='T03')?'#f9faf5':'#28312e'}
// The screenshot's illegible small print is replaced with editable editorial copy.
export function defaultText(layout:Layout,slot:Slot):string {
if(slot.text)return slot.text;
if(slot.direction==='curved')return 'BULUBLUE DESIGN · FORM AND SPACE · EDITORIAL DESIGN ·';
if(slot.role.includes('日期'))return '2025 / 03 / 25';
if(slot.role.includes('英文')||slot.role.includes('品牌')||slot.role.includes('标识'))return 'BULUBLUE DESIGN';
if(slot.role.includes('图注')||slot.role.includes('标签')||slot.box[3]<10)return 'FORM / SPACE / DESIGN';
if(slot.direction==='vertical')return '设计灵感 · 日常观察';
return '在留白之间,\n寻找新的秩序。\n让文字与形状相遇,\n记录日常的设计灵感。';
}
export function slotPosition(layout:Layout,slot:Slot):CSSProperties {
const [x,y,w,h]=slot.box;return {left:`${x/layout.width*100}%`,top:`${y/layout.height*100}%`,width:`${w/layout.width*100}%`,height:`${h/layout.height*100}%`};
}
export function textSize(layout:Layout,slot:Slot,text:string):number {
const [, ,w,h]=slot.box,lines=text.split('\n');
const length=(s:string)=>Array.from(s).reduce((n,c)=>n+(/[\u3400-\u9fff]/.test(c)?1:.56),0);
if(slot.direction==='vertical')return Math.min(w*.9,h/Math.max(1,Array.from(text.replaceAll('\n','')).length)*.95);
if(slot.direction==='rotated')return Math.min(w*.85,h/Math.max(1,length(text)));
if(slot.direction==='curved')return Math.min(2.2,w/Math.max(1,length(text)));
return Math.min(h/(lines.length*1.15),w/Math.max(1,...lines.map(length)))*.92;
}
export function imageShape(layout:Layout,slot:Slot):CSSProperties {
const n=Number(layout.id.slice(4)),s:CSSProperties={backgroundColor:slot.id==='I01'?'#9ba6a3':'#788785'};
if([4,5,7,13,19,20].includes(n)||(n===17&&slot.id==='I02'))s.borderRadius='50%';
if(n===4)s.transform='rotate(-9deg)';
if(n===15&&slot.id==='I01')s.borderRadius='100% 0 0 0';
if(n===22)s.clipPath=slot.id==='I01'?'polygon(0 0,100% 0,100% 48%,0 100%)':slot.id==='I02'?'polygon(0 30%,100% 0,100% 70%,0 100%)':'polygon(0 50%,100% 0,100% 100%,0 100%)';
if(n===27)s.clipPath=slot.id==='I01'?'polygon(0 0,100% 35%,100% 100%,0 68%)':'polygon(0 40%,100% 0,100% 100%,0 100%)';
if(n===10)s.backgroundColor='#596c67';
if(n===16)s.backgroundColor=slot.id==='I01'?'#b6bfba':'#7e8e87';
if(n===20&&slot.id==='I02')s.backgroundColor='#e3e6dc';
return s;
}
export function decorationKind(slot:Slot){
if(slot.role.includes('同心'))return 'rings';
if(slot.role.includes('圆节点'))return 'node';
if(slot.role.includes('椭圆'))return 'oval';
if(slot.role.includes('曲线'))return 'curve';
if(slot.role.includes('贴条')||slot.role.includes('浅带'))return 'band';
if(slot.role.includes('斜'))return 'diagonal';
if(slot.box[3]>slot.box[2]*2)return 'vertical-lines';
return 'lines';
}