Files

86 lines
8.3 KiB
JavaScript

(function () {
'use strict';
window.industryRenderers ??= {};
function scene(svg, config, kit, title, subtitle, phases, note) {
const {anime,el}=kit;
const C={bg:'#0b1424',panel:'#15243a',line:'#68809d',ink:'#edf4ff',muted:'#b2c4da',cyan:'#57d9ed',green:'#82e0b0',amber:'#ffd078',red:'#ff8a94'};
const D=Number.isFinite(+config.duration)&&+config.duration>0?+config.duration:6000;
const tl=anime.createTimeline({autoplay:false,defaults:{ease:'linear'}});
function e(t,a={},text='',p=svg){return el(t,a,text,p);}
function g(){return e('g');}
function rect(x,y,w,h,fill=C.panel,stroke=C.line,p=svg,r=8){return e('rect',{x,y,width:w,height:h,rx:r,fill,stroke,'stroke-width':2},'',p);}
function text(x,y,s,fill=C.ink,size=18,p=svg){return e('text',{x,y,fill,'font-size':size,'font-family':'system-ui, sans-serif'},s,p);}
function path(d,color=C.line,width=3,p=svg){return e('path',{d,fill:'none',stroke:color,'stroke-width':width,'stroke-linecap':'round','stroke-linejoin':'round'},'',p);}
function circle(x,y,r,fill=C.cyan,p=svg){return e('circle',{cx:x,cy:y,r,fill},'',p);}
const tracks=new WeakMap();
function tween(o,attrs,start,end){
let previous=tracks.get(o);if(!previous){previous={};tracks.set(o,previous);}
for(const [key,values] of Object.entries(attrs)){
const old=previous[key];
// Anime v4 needs explicit holds across gaps for reverse seeking.
if(old && start>old.end)tl.add(o,{[key]:[old.value,old.value],duration:(start-old.end)*D/6000},old.end*D/6000);
previous[key]={end,value:values[values.length-1]};
}
tl.add(o,{...attrs,duration:(end-start)*D/6000},start*D/6000);
}
function reveal(o,start,end= start+650){o.setAttribute('opacity','0');tween(o,{opacity:[0,1]},start,end);}
function flow(d,start,end,color=C.cyan,width=5){const p=path(d,color,width);const len=p.getTotalLength();p.setAttribute('stroke-dasharray',len);p.setAttribute('stroke-dashoffset',len);tween(p,{strokeDashoffset:[len,0]},start,end);return p;}
function parcel(x,y,color=C.amber){const p=g();rect(x,y,36,28,color,'#0b1424',p,3);path(`M${x+18} ${y} V${y+28}`,'#736146',2,p);return p;}
function person(x,y,color=C.cyan){const p=g();circle(x,y,10,color,p);path(`M${x} ${y+15} V${y+43} M${x-15} ${y+25} H${x+15} M${x} ${y+43} L${x-12} ${y+60} M${x} ${y+43} L${x+12} ${y+60}`,color,6,p);return p;}
function gear(x,y,r,color=C.line){const p=g();for(let i=0;i<12;i++){const a=i*Math.PI/6;path(`M${x+Math.cos(a)*(r-5)} ${y+Math.sin(a)*(r-5)} L${x+Math.cos(a)*(r+7)} ${y+Math.sin(a)*(r+7)}`,color,8,p);}circle(x,y,r,color,p);circle(x,y,r*.45,C.bg,p);return p;}
rect(10,10,940,520,C.bg,C.panel,svg,16);
const heading=text(32,43,title,C.ink,25);
const words=subtitle.split(' ');let line='',row=0;for(const w of words){if((line+' '+w).length>104){text(32,70+row*19,line,C.muted,16);line=w;row++;}else line+=(line?' ':'')+w;}if(line)text(32,70+row*19,line,C.muted,16);
path('M32 426 H928',C.line,1);
phases.forEach((s,i)=>{const x=47+i*183;circle(x,455,13,C.panel);const dot=circle(x,455,11,C.cyan);dot.setAttribute('opacity','.18');tween(dot,{opacity:[.18,1]},i*1200,i*1200+700);text(x+21,461,s,C.ink,16);});
text(32,510,note,C.muted,16);
tween(heading,{opacity:[1,1]},0,6000);
return {C,D,tl,e,g,rect,text,path,circle,tween,reveal,flow,parcel,person,gear};
}
window.industryRenderers["energy-microgrid-storage"] = function(svg, config, kit) {
const s=scene(svg,config,kit,"Microgrid: balance generation with storage","Solar and wind feed a common bus; a renewable dip triggers storage dispatch before a flexible load rejoins.",["Renewables", "Serve load", "Output dips", "Discharge", "Load rejoins"],"Cyan = renewable supply \u00b7 Amber = storage dispatch \u00b7 Green = restored flexible load");
const {C,tl,g,rect,text,path,circle,tween,reveal,flow}=s;
// Tilted solar array, turbine, bus, battery cabinet, and real building loads.
path('M50 188 L82 132 H223 L193 188 Z',C.cyan,3);for(let i=0;i<4;i++)path(`M${82+i*35} 132 L${50+i*35} 188`,C.line,2);path('M66 160 H208 M90 189 V215 M174 189 V215',C.line,3);circle(51,116,15,C.amber);
text(40,244,'Solar array',C.cyan,17);
path('M313 210 V143 M313 143 L290 110 M313 143 L350 133 M313 143 L296 177',C.cyan,5);circle(313,143,7,C.ink);text(269,244,'Wind',C.cyan,17);
path('M65 283 H881',C.line,7);text(373,310,'LOCAL ENERGY BUS',C.muted,16);
path('M141 217 V283 M313 212 V283',C.line,3);
rect(417,120,107,109,C.panel,C.amber);rect(450,109,42,11,C.amber,C.amber);const bars=Math.max(1,Math.min(3,Math.round(+config.storageBars||3)));for(let i=0;i<3;i++){const bar=rect(433,139+i*24,75,15,i>=3-bars?C.amber:C.bg,C.amber,undefined,2);if(i===3-bars)tween(bar,{fill:[C.amber,C.bg]},3600,4900);}text(530,205,'Storage',C.amber,17);path('M470 229 V283',C.line,3);
function building(x,y,w,h,label,color){rect(x,y,w,h,C.panel,color);for(let xx=x+12;xx<x+w-10;xx+=24)for(let yy=y+15;yy<y+h-20;yy+=25)rect(xx,yy,12,12,color,color,undefined,1);text(x-6,117,label,color,16);}
building(652,145,92,87,'Steady load',C.cyan);path('M699 233 V283',C.line,3);
path('M784 165 L807 143 V165 L830 143 V165 L854 143 V165 H896 V232 H784 Z',C.green,3);path('M870 145 V119 H885 V165',C.green,4);text(769,117,'Flexible load',C.green,16);path('M840 233 V283',C.line,3);
const solarRoute=flow('M141 218 V283 H699 V234',0,2100);tween(solarRoute,{opacity:[1,.2]},2400,3100);flow('M313 212 V283 H700',600,2200);
const cloud=g();circle(142,122,22,C.muted,cloud);circle(172,113,26,C.muted,cloud);circle(202,124,20,C.muted,cloud);reveal(cloud,2400,3000);
text(49,344,'RENEWABLE DIP',C.amber,17);path('M50 383 H102 L129 359 L159 380 L186 380 L215 388 H323',C.amber,3);text(52,414,'Illustrative supply trend',C.muted,16);
flow('M470 228 V283 H699 V233',3600,4700,C.amber,6);flow('M700 283 H840 V234',4800,5800,C.green,5);
const dispatch=text(403,345,'Storage bridges the gap',C.amber,18);reveal(dispatch,3600,4300);text(403,375,'Flexible demand waits for headroom;',C.muted,17);text(403,402,'essential demand remains connected.',C.muted,17);
return tl;
};
window.industryRenderers["energy-feeder-restoration"] = function(svg, config, kit) {
const s=scene(svg,config,kit,"Feeder fault: isolate and restore service","A faulted feeder section is opened at both ends; a normally open tie restores healthy downstream service.",["Normal supply", "Fault appears", "Open section", "Close tie", "Restore branch"],"Red = isolated fault section \u00b7 Green = alternate feed \u00b7 Cyan = healthy normal feed");
const {C,tl,g,rect,text,path,circle,tween,reveal,flow}=s;const available=Number(config.tieAvailable)!==0;
text(40,118,'SOURCE A',C.cyan,17);text(754,118,'SOURCE B',C.green,17);
circle(98,173,38,C.panel);path('M71 173 Q84 141 98 173 T125 173',C.cyan,3);
circle(819,173,38,C.panel);path('M792 173 Q805 141 819 173 T846 173',C.green,3);
path('M137 173 H277 M315 173 H530 M568 173 H697 V344 H816 V212',C.line,5);
// Explicit isolator blades with rotation-like endpoint interpolation.
const sw1=path('M277 173 L315 173',C.cyan,5),sw2=path('M530 173 L568 173',C.cyan,5);
tween(sw1,{d:['M277 173 L315 173','M277 173 L308 143']},2400,3000);tween(sw2,{d:['M530 173 L568 173','M530 173 L561 143']},2850,3450);
for(const x of [277,315,530,568])circle(x,173,5,C.ink);
text(256,127,'S1',C.muted,16);text(524,127,'S2',C.muted,16);
path('M212 173 V301 M634 173 V301',C.line,4);
function house(x,label,color){path(`M${x} 328 L${x+38} 296 L${x+76} 328 V386 H${x} Z`,color,3);rect(x+28,350,20,36,C.panel,color);text(x-5,414,label,color,16);}
house(174,'Upstream served',C.cyan);house(596,available?'Service restored':'Await alternate feed',available?C.green:C.amber);
path('M697 344 H747 M782 344 H816',C.line,5);const tie=path('M747 344 L772 319',C.green,5);circle(747,344,5,C.ink);circle(782,344,5,C.ink);
if(available)tween(tie,{d:['M747 344 L772 319','M747 344 L782 344']},3900,4500);text(735,385,'Tie switch',C.green,17);
const fault=g();path('M431 143 L414 172 H437 L421 205',C.red,6,fault);reveal(fault,1200,1800);
const zone=rect(339,215,172,62,C.bg,C.red);reveal(zone,2400,3200);text(353,240,'Fault contained',C.red,17);text(353,263,'No re-energization',C.muted,16);
flow('M137 173 H212 V301',0,1100);if(available)flow('M819 212 V344 H697 V173 H634 V301',4500,5900,C.green);
path('M331 302 H505',C.red,2);text(337,329,'Only healthy sections',C.muted,16);text(337,354,available?'receive alternate supply.':'wait; no tie capacity assumed.',C.muted,16);
return tl;
};
})();