@mosaicoo/svg-engine 0.1.0

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.
@@ -0,0 +1,11 @@
1
+ import*as v from"@angular/core";import{signal as P,computed as Ye,Injectable as ce,runInInjectionContext as Pt,effect as Kt,InjectionToken as Ge,inject as we}from"@angular/core";import{CommandBus as _,SetStylePropertyOnManyCommand as Ve,EditorStateService as K,ResizeNodeCommand as Be,ReorderNodeCommand as Ut,DivideCommand as Ft,ExcludeCommand as Ht,SubtractCommand as Yt,IntersectCommand as Gt,UnionCommand as Vt,findNodeById as Bt,MoveNodeCommand as We,RotateNodeCommand as Wt,collectNodes as Xt,ConvertNodeToPathCommand as Jt,RemoveNodeCommand as Zt,generateNodeId as Qt,createText as en,InsertNodeCommand as N,AUTO_PARENT as A,createPath as tn,createPolyline as nn,createLine as on,createPolygon as Xe,createEllipse as Je,createRect as rn,DuplicateNodeCommand as sn}from"@mosaicoo/svg-engine/core";import{SelectionService as j,buildGradientMarkup as an,GradientLibraryService as cn,MenuContributionRegistry as ln,PLUGIN_API_VERSION as dn,ImportPlacementService as un}from"@mosaicoo/svg-engine/edit";import{svgImporter as fn}from"@mosaicoo/svg-engine/io";const ke=Object.freeze({create:"create",add:"create",draw:"create",insert:"create",put:"create",place:"create",generate:"create",make:"create",new:"create",spawn:"create",build:"create",delete:"delete",remove:"delete",erase:"delete",clear:"delete",eliminate:"delete",destroy:"delete",trash:"delete",discard:"delete",drop:"delete",select:"select",mark:"select",choose:"select",pick:"select",focus:"select",highlight:"select",target:"select",all:"select-all",everything:"select-all",deselect:"deselect",unselect:"deselect",unmark:"deselect",unfocus:"deselect",group:"group",join:"group",merge:"group",unite:"group",combine:"group",bundle:"group",ungroup:"ungroup",separate:"ungroup",split:"ungroup",detach:"ungroup",break:"ungroup",undo:"undo",revert:"undo",rollback:"undo",cancel:"undo",back:"undo",redo:"redo",repeat:"redo",restore:"redo",forward:"redo",reapply:"redo",zoomin:"zoom-in",closer:"zoom-in",magnify:"zoom-in",enlarge:"zoom-in",zoomout:"zoom-out",shrink:"zoom-out",zoomreset:"zoom-reset",reset:"zoom-reset",fit:"zoom-reset",copy:"copy",paste:"paste",cut:"cut",duplicate:"duplicate",clone:"duplicate",dupe:"duplicate",move:"move",drag:"move",shift:"move",position:"move",translate:"move",nudge:"move",rotate:"rotate",spin:"rotate",turn:"rotate",twist:"rotate",resize:"resize",scale:"resize",rescale:"resize",adjust:"resize",stretch:"resize",flip:"flip",mirror:"flip",reflect:"flip",reverse:"flip",align:"align",distribute:"distribute",space:"distribute",spread:"distribute",bring:"bring-forward",raise:"bring-forward",send:"send-backward",lower:"send-backward",show:"show",display:"show",reveal:"show",visible:"show",unhide:"show",hide:"hide",conceal:"hide",invisible:"hide",toggle:"toggle",switch:"toggle",union:"union",unify:"union",weld:"union",fuse:"union",intersect:"intersect",cross:"intersect",subtract:"subtract",minus:"subtract",exclude:"exclude",xor:"exclude",divide:"divide",slice:"divide",convert:"convert",transform:"convert",turninto:"convert",lock:"lock",freeze:"lock",unlock:"unlock",unfreeze:"unlock",export:"export",download:"export",save:"export",saveas:"export",import:"import",load:"import",open:"import",upload:"import"}),xe=Object.freeze({criar:"create",crie:"create",cria:"create",adicionar:"create",adicione:"create",desenhar:"create",desenhe:"create",inserir:"create",insira:"create",colocar:"create",coloque:"create",gerar:"create",gere:"create",montar:"create",monte:"create",novo:"create",nova:"create",construir:"create",construa:"create",fazer:"create",faca:"create",faz:"create",deletar:"delete",deleta:"delete",delete:"delete",excluir:"delete",exclua:"delete",remover:"delete",remova:"delete",apagar:"delete",apague:"delete",eliminar:"delete",elimine:"delete",limpar:"delete",limpe:"delete",destruir:"delete",destrua:"delete",sumir:"delete",suma:"delete",sem:"delete",selecionar:"select",selecione:"select",seleciona:"select",marcar:"select",marque:"select",escolher:"select",escolha:"select",pegar:"select",pegue:"select",focar:"select",foque:"select",tudo:"select-all",todos:"select-all",todas:"select-all",ambos:"select-all",ambas:"select-all",desselecionar:"deselect",desselecione:"deselect",deselecionar:"deselect",desmarcar:"deselect",desmarque:"deselect",desfocar:"deselect",desfoque:"deselect",agrupar:"group",agrupe:"group",juntar:"group",junte:"group",unir:"group",una:"group",combinar:"group",combine:"group",desagrupar:"ungroup",desagrupe:"ungroup",separar:"ungroup",separe:"ungroup",dividir:"ungroup",divida:"ungroup",desmembrar:"ungroup",desmembre:"ungroup",desfazer:"undo",desfaca:"undo",voltar:"undo",volte:"undo",reverter:"undo",reverta:"undo",cancelar:"undo",cancele:"undo",refazer:"redo",refaca:"redo",repetir:"redo",repita:"redo",restaurar:"redo",restaure:"redo",avancar:"redo",avance:"redo",aproximar:"zoom-in",aproxime:"zoom-in",ampliar:"zoom-in",amplie:"zoom-in",aumentar:"zoom-in",aumente:"zoom-in",achegar:"zoom-in",achegue:"zoom-in",afastar:"zoom-out",afaste:"zoom-out",diminuir:"zoom-out",diminua:"zoom-out",reduzir:"zoom-out",reduza:"zoom-out",distanciar:"zoom-out",distancie:"zoom-out",resetar:"zoom-reset",resete:"zoom-reset",ajustar:"zoom-reset",ajuste:"zoom-reset",encaixar:"zoom-reset",encaixe:"zoom-reset",copiar:"copy",copie:"copy",colar:"paste",cole:"paste",recortar:"cut",recorte:"cut",cortar:"cut",corte:"cut",duplicar:"duplicate",duplique:"duplicate",clonar:"duplicate",clone:"duplicate",mover:"move",mova:"move",movem:"move",movimenta:"move",movimente:"move",movimentar:"move",movimentem:"move",arrastar:"move",arraste:"move",arrasta:"move",deslocar:"move",desloque:"move",desloca:"move",translada:"move",translade:"move",transladar:"move",posicionar:"move",posicione:"move",posiciona:"move",rotacionar:"rotate",rotacione:"rotate",girar:"rotate",gire:"rotate",rodar:"rotate",rode:"rotate",virar:"rotate",vire:"rotate",redimensionar:"resize",redimensione:"resize",escalar:"resize",escale:"resize",dimensionar:"resize",dimensione:"resize",espelhar:"flip",espelhe:"flip",inverter:"flip",inverta:"flip",refletir:"flip",reflita:"flip",alinhar:"align",alinhe:"align",distribuir:"distribute",distribua:"distribute",espacar:"distribute",espace:"distribute",trazer:"bring-forward",traga:"bring-forward",avancar1:"bring-forward",enviar:"send-backward",envie:"send-backward",recuar:"send-backward",recue:"send-backward",mostrar:"show",mostre:"show",exibir:"show",exiba:"show",visualizar:"show",visualize:"show",revelar:"show",revele:"show",esconder:"hide",esconda:"hide",ocultar:"hide",oculte:"hide",alternar:"toggle",alterne:"toggle",trocar:"toggle",troque:"toggle",habilitar:"toggle",habilite:"toggle",desabilitar:"toggle",desabilite:"toggle",unificar:"union",unifique:"union",fundir:"union",funda:"union",intersectar:"intersect",intersecte:"intersect",cruzar:"intersect",cruze:"intersect",subtrair:"subtract",subtraia:"subtract",excluir2:"exclude",excluda:"exclude",fatiar:"divide",fatie:"divide",recortar2:"divide",converter:"convert",converta:"convert",transformar:"convert",transforme:"convert",bloquear:"lock",bloqueie:"lock",travar:"lock",trave:"lock",desbloquear:"unlock",desbloqueie:"unlock",destravar:"unlock",destrave:"unlock",exportar:"export",exporte:"export",baixar:"export",baixe:"export",salvar:"export",salve:"export",importar:"import",importe:"import",carregar:"import",carregue:"import",abrir:"import",abra:"import"}),J=Object.freeze({...xe,...ke}),pn=Object.freeze(Object.keys(J));function G(e){return J[e]??null}const Ie=Object.freeze({red:"#e53935",reds:"#e53935",crimson:"#dc143c",scarlet:"#ff2400",maroon:"#800000",ruby:"#9b111e",brick:"#cb4154",blood:"#8b0000",cherry:"#de3163",rose:"#ff007f",blue:"#1e88e5",blues:"#1e88e5",navy:"#0d47a1",royalblue:"#4169e1",skyblue:"#87ceeb",turquoise:"#26c6da",cobalt:"#0047ab",darkblue:"#1565c0",lightblue:"#42a5f5",midnightblue:"#191970",steelblue:"#4682b4",azure:"#f0ffff",cerulean:"#007ba7",green:"#43a047",greens:"#43a047",lightgreen:"#66bb6a",darkgreen:"#2e7d32",lime:"#cddc39",olive:"#808000",emerald:"#2ecc71",mint:"#98ff98",moss:"#8a9a5b",pistachio:"#93c572",forestgreen:"#228b22",seagreen:"#2e8b57",teal:"#008080",yellow:"#fdd835",yellows:"#fdd835",gold:"#fbc02d",beige:"#d7ccc8",cream:"#fff3e0",mustard:"#ffb300",wheat:"#f5deb3",ivory:"#fffff0",amber:"#ffbf00",lemon:"#fff700",orange:"#fb8c00",oranges:"#fb8c00",coral:"#ff7043",salmon:"#ff8a65",peach:"#ffccbc",pumpkin:"#ff7518",rust:"#b7410e",copper:"#b87333",tangerine:"#f28500",purple:"#8e24aa",purples:"#8e24aa",violet:"#7e57c2",lavender:"#b39ddb",indigo:"#3949ab",plum:"#8e4585",eggplant:"#3b001e",mauve:"#e0b0ff",pink:"#ec407a",pinks:"#ec407a",lightpink:"#f8bbd0",hotpink:"#ff69b4",deeppink:"#ff1493",fuchsia:"#ff00ff",magenta:"#d81b60",brown:"#6d4c41",browns:"#6d4c41",chocolate:"#4e342e",sand:"#bcaaa4",terracotta:"#a0522d",caramel:"#af6e4d",cinnamon:"#d2691e",walnut:"#5d4e37",tan:"#d2b48c",sienna:"#a0522d",black:"#000000",blacks:"#000000",graphite:"#424242",charcoal:"#36454f",jet:"#343434",white:"#ffffff",whites:"#ffffff",ice:"#f5f5f5",snow:"#fafafa",offwhite:"#f8f8f2",pearl:"#eae0c8",gray:"#9e9e9e",grays:"#9e9e9e",grey:"#9e9e9e",greys:"#9e9e9e",lightgray:"#cfd8dc",lightgrey:"#cfd8dc",darkgray:"#616161",darkgrey:"#616161",silver:"#b0bec5",slate:"#708090",ash:"#b2beb5",cyan:"#00acc1",aqua:"#00bcd4",aquamarine:"#4dd0e1",success:"#43a047",warning:"#fbc02d",danger:"#e53935",error:"#e53935",info:"#1e88e5",primary:"#1e88e5",secondary:"#9e9e9e",tertiary:"#b26500",transparent:"transparent",none:"none",nocolor:"none",nofill:"none",invisible:"none",currentcolor:"currentColor",inherit:"inherit"}),Se=Object.freeze({vermelho:"#e53935",vermelhos:"#e53935",vermelha:"#e53935",vermelhas:"#e53935",vermelhoescuro:"#b71c1c",vermelhoclaro:"#ef5350",carmesim:"#dc143c",vinho:"#7b1e3a",vinhos:"#7b1e3a",bordo:"#800020",bordeaux:"#800020",rubi:"#9b111e",tijolo:"#cb4154",sangue:"#8b0000",azul:"#1e88e5",azuis:"#1e88e5",azulclaro:"#42a5f5",azulescuro:"#1565c0",azulmarinho:"#0d47a1",marinho:"#0d47a1",azulceleste:"#87ceeb",azulroyal:"#4169e1",turquesa:"#26c6da",turquesas:"#26c6da",petroleo:"#003f5c",cobalto:"#0047ab",anil:"#3949ab",verde:"#43a047",verdes:"#43a047",verdeclaro:"#66bb6a",verdeescuro:"#2e7d32",limao:"#cddc39",oliva:"#808000",esmeralda:"#2ecc71",esmeraldas:"#2ecc71",menta:"#98ff98",musgo:"#8a9a5b",jade:"#00a86b",pistache:"#93c572",verdeagua:"#a4dded",amarelo:"#fdd835",amarelos:"#fdd835",amarela:"#fdd835",amarelas:"#fdd835",dourado:"#fbc02d",dourados:"#fbc02d",ouro:"#fbc02d",bege:"#d7ccc8",beges:"#d7ccc8",creme:"#fff3e0",cremes:"#fff3e0",mostarda:"#ffb300",trigo:"#f5deb3",marfim:"#fffff0",laranja:"#fb8c00",laranjas:"#fb8c00",salmao:"#ff8a65",pessego:"#ffccbc",abobora:"#ff7518",ferrugem:"#b7410e",cobre:"#b87333",roxo:"#8e24aa",roxos:"#8e24aa",roxa:"#8e24aa",roxas:"#8e24aa",violeta:"#7e57c2",violetas:"#7e57c2",lilas:"#b39ddb",lavanda:"#b39ddb",uva:"#522d80",uvas:"#522d80",ameixa:"#8e4585",ameixas:"#8e4585",berinjela:"#3b001e",rosa:"#ec407a",rosas:"#ec407a",rosaclaro:"#f8bbd0",rosachoque:"#ff1493",rosaquente:"#ff69b4",fucsia:"#ff00ff",marrom:"#6d4c41",marrons:"#6d4c41",cafe:"#5d4037",chocolate:"#4e342e",chocolates:"#4e342e",areia:"#bcaaa4",terracota:"#a0522d",caramelo:"#af6e4d",canela:"#d2691e",noz:"#5d4e37",nozes:"#5d4e37",preto:"#000000",pretos:"#000000",preta:"#000000",pretas:"#000000",grafite:"#424242",grafites:"#424242",carvao:"#36454f",fumaca:"#738276",branco:"#ffffff",brancos:"#ffffff",branca:"#ffffff",brancas:"#ffffff",gelo:"#f5f5f5",neve:"#fafafa",perola:"#eae0c8",perolas:"#eae0c8",cinza:"#9e9e9e",cinzas:"#9e9e9e",cinzaclaro:"#cfd8dc",cinzaescuro:"#616161",prata:"#b0bec5",pratas:"#b0bec5",chumbo:"#7a8288",acoescovado:"#8c8c8c",ciano:"#00acc1",sucesso:"#43a047",alerta:"#fbc02d",aviso:"#fbc02d",perigo:"#e53935",erro:"#e53935",informacao:"#1e88e5",primaria:"#1e88e5",secundaria:"#9e9e9e",transparente:"transparent",nenhum:"none",nenhuma:"none",semcor:"none",semfundo:"none",sempreenchimento:"none"}),ze=Object.freeze({...Se,...Ie}),Ze=Object.freeze(Object.keys(ze));function Z(e){return ze[e]??null}const Me=Object.freeze({rectangle:"rect",rectangles:"rect",rect:"rect",rects:"rect",square:"rect",squares:"rect",box:"rect",boxes:"rect",block:"rect",blocks:"rect",panel:"rect",panels:"rect",card:"rect",cards:"rect",frame:"rect",frames:"rect",table:"rect",tables:"rect",bar:"rect",bars:"rect",stripe:"rect",stripes:"rect",circle:"circle",circles:"circle",round:"circle",rounds:"circle",dot:"circle",dots:"circle",node:"circle",nodes:"circle",disc:"circle",discs:"circle",disk:"circle",disks:"circle",ball:"circle",balls:"circle",sphere:"circle",spheres:"circle",coin:"circle",coins:"circle",wheel:"circle",wheels:"circle",ellipse:"ellipse",ellipses:"ellipse",oval:"ellipse",ovals:"ellipse",egg:"ellipse",eggs:"ellipse",line:"line",lines:"line",segment:"line",segments:"line",connector:"line",connectors:"line",connection:"line",connections:"line",arrow:"line",arrows:"line",rule:"line",rules:"line",divider:"line",dividers:"line",wire:"line",wires:"line",edge:"line",edges:"line",path:"path",paths:"path",curve:"path",curves:"path",route:"path",routes:"path",contour:"path",contours:"path",vector:"path",vectors:"path",freehand:"path",scribble:"path",scribbles:"path",trail:"path",trails:"path",outline:"path",outlines:"path",silhouette:"path",silhouettes:"path",triangle:"triangle",triangles:"triangle",diamond:"rhombus",diamonds:"rhombus",rhombus:"rhombus",pentagon:"pentagon",pentagons:"pentagon",hexagon:"hexagon",hexagons:"hexagon",octagon:"octagon",octagons:"octagon",star:"star",stars:"star",heart:"star",hearts:"star",polygon:"polygon",polygons:"polygon",polyline:"polyline",polylines:"polyline",brokenline:"polyline",brokenlines:"polyline",text:"text",texts:"text",label:"text",labels:"text",title:"text",titles:"text",caption:"text",captions:"text",word:"text",words:"text",paragraph:"text",paragraphs:"text",sentence:"text",sentences:"text",tag:"text",tags:"text",string:"text",strings:"text",image:"image",images:"image",picture:"image",pictures:"image",photo:"image",photos:"image",icon:"image",icons:"image",bitmap:"image",bitmaps:"image",raster:"image",rasters:"image",group:"group",groups:"group",bundle:"group",bundles:"group",container:"group",containers:"group",layer:"group",layers:"group",folder:"group",folders:"group",set:"group",sets:"group",cluster:"group",clusters:"group",tooltip:"group",tooltips:"group",svg:"svg",document:"svg",artboard:"svg",workspace:"svg",canvas:"svg"}),Oe=Object.freeze({retangulo:"rect",retangulos:"rect",quadrado:"rect",quadrados:"rect",caixa:"rect",caixas:"rect",bloco:"rect",blocos:"rect",painel:"rect",paineis:"rect",area:"rect",areas:"rect",moldura:"rect",molduras:"rect",mesa:"rect",mesas:"rect",faixa:"rect",faixas:"rect",barra:"rect",barras:"rect",tabela:"rect",tabelas:"rect",circulo:"circle",circulos:"circle",bola:"circle",bolas:"circle",esfera:"circle",esferas:"circle",ponto:"circle",pontos:"circle",no:"circle",nos:"circle",bolinha:"circle",bolinhas:"circle",disco:"circle",discos:"circle",roda:"circle",rodas:"circle",moeda:"circle",moedas:"circle",elipse:"ellipse",elipses:"ellipse",oval:"ellipse",ovais:"ellipse",ovoide:"ellipse",ovo:"ellipse",ovos:"ellipse",linha:"line",linhas:"line",risco:"line",riscos:"line",traco:"line",tracos:"line",segmento:"line",segmentos:"line",eixo:"line",eixos:"line",conexao:"line",conexoes:"line",ligacao:"line",ligacoes:"line",conector:"line",conectores:"line",seta:"line",setas:"line",reta:"line",retas:"line",fio:"line",fios:"line",caminho:"path",caminhos:"path",trajeto:"path",trajetos:"path",curva:"path",curvas:"path",trilha:"path",trilhas:"path",desenho:"path",desenhos:"path",rabisco:"path",rabiscos:"path",vetor:"path",vetores:"path",forma:"path",formas:"path",contorno:"path",contornos:"path",silhueta:"path",silhuetas:"path",triangulo:"triangle",triangulos:"triangle",losango:"rhombus",losangos:"rhombus",diamante:"rhombus",diamantes:"rhombus",pentagono:"pentagon",pentagonos:"pentagon",hexagono:"hexagon",hexagonos:"hexagon",octogono:"octagon",octogonos:"octagon",estrela:"star",estrelas:"star",coracao:"star",coracoes:"star",poligono:"polygon",poligonos:"polygon",setapoligono:"polygon",polilinha:"polyline",polilinhas:"polyline",linhaquebrada:"polyline",linhapoligonal:"polyline",zigzag:"polyline",ziguezague:"polyline",texto:"text",textos:"text",letra:"text",letras:"text",legenda:"text",legendas:"text",rotulo:"text",rotulos:"text",titulo:"text",titulos:"text",palavra:"text",palavras:"text",nome:"text",nomes:"text",paragrafo:"text",paragrafos:"text",frase:"text",frases:"text",etiqueta:"text",etiquetas:"text",imagem:"image",imagens:"image",foto:"image",fotos:"image",icone:"image",icones:"image",figura:"image",figuras:"image",logotipo:"image",logotipos:"image",logo:"image",logos:"image",bitmap:"image",bitmaps:"image",grupo:"group",grupos:"group",agrupamento:"group",agrupamentos:"group",conjunto:"group",conjuntos:"group",camada:"group",camadas:"group",balao:"group",baloes:"group",caixaagrupada:"group",pasta:"group",pastas:"group",documento:"svg",tela:"svg",prancheta:"svg"}),Qe=Object.freeze({triangle:3,rhombus:4,pentagon:5,hexagon:6,octagon:8,polygon:6});function hn(e,t,r,o){const n=Math.max(3,Math.floor(o)),s=[],i=-Math.PI/2;for(let a=0;a<n;a++){const c=i+2*Math.PI*a/n;s.push({x:e+r*Math.cos(c),y:t+r*Math.sin(c)})}return s}function gn(e,t,r,o=r*.4,n=5){const s=Math.max(3,Math.floor(n)),i=[],a=-Math.PI/2;for(let c=0;c<s*2;c++){const l=c%2===0?r:o,d=a+Math.PI*c/s;i.push({x:e+l*Math.cos(d),y:t+l*Math.sin(d)})}return i}const _e=Object.freeze({...Oe,...Me}),Q=Object.freeze(Object.keys(_e));function R(e){return _e[e]??null}const $e=new Set(["a","an","the","of","in","on","at","to","from","with","without","about","for","over","under","into","onto","upon","and","or","but","nor","yet","that","this","these","those","it","its","there","here","where","when","which","who","what","please","kindly","okay","ok","well","just","maybe","perhaps","sure","fine","cool","want","wants","wanted","need","needs","needed","would","could","should","might","may","can","will","shall","now","soon","later","before","after","always","never","often","equals","equal","is","are","value","object","objects","element","elements","selected","current"]),Ee=new Set(["o","a","os","as","um","uma","uns","umas","de","do","da","dos","das","em","no","na","nos","nas","por","para","pra","pro","pros","pras","com","sem","sobre","sob","entre","ate","desde","e","ou","mas","porem","tambem","que","quem","qual","isso","esse","essa","este","esta","aquele","aquela","aqui","la","ali","ai","onde","quando","enquanto","porque","porfavor","favor","gentileza","tipo","meio","ok","okey","beleza","massa","show","entao","enfim","pois","pode","poderia","quero","queria","preciso","precisava","gostaria","gostei","pretendo","pretendia","agora","ja","logo","depois","antes","sempre","nunca","talvez","igual","iguais","eh","sao","fica","fique","vale","valor","objeto","objetos","item","itens","elemento","elementos","selecionado","selecionada","selecionados","selecionadas","atual","atuais","corrente","correntes"]),le=new Set([...Ee,...$e]);function E(e){return le.has(e)}function de(e,t,r=1/0){if(e===t)return 0;const o=e.length,n=t.length;if(o===0)return n>r?1/0:n;if(n===0)return o>r?1/0:o;if(Math.abs(o-n)>r)return 1/0;let i=e,a=t;o>n&&(i=t,a=e);const c=i.length,l=a.length;let d=new Array(c+1),f=new Array(c+1);for(let u=0;u<=c;u++)d[u]=u;for(let u=1;u<=l;u++){f[0]=u;let m=f[0];for(let g=1;g<=c;g++){const x=i.charCodeAt(g-1)===a.charCodeAt(u-1)?0:1;f[g]=Math.min(d[g]+1,f[g-1]+1,d[g-1]+x),f[g]<m&&(m=f[g])}if(m>r)return 1/0;const p=d;d=f,f=p}const h=d[c];return h>r?1/0:h}function mn(e,t,r){if(t.length===0)return null;let o=null,n=r+1;for(const s of t){if(s===e)return{match:s,distance:0};const i=de(e,s,r);if(i<n&&(n=i,o=s,i===0))return{match:s,distance:0}}return o===null?null:{match:o,distance:n}}function je(e){return e<=3?0:e<=6?1:2}function C(e,t){if(e.length===0||t.length===0)return null;let r=null;for(const o of t){if(o.length===0)continue;const n=je(o.length);if(o===e)return{term:o,token:e,distance:0,score:1,tokenIndex:-1};if(Math.abs(e.length-o.length)>n)continue;const s=de(e,o,n);if(s===1/0)continue;const i=1-s/Math.max(o.length,1);(r===null||s<r.distance||s===r.distance&&i>r.score)&&(r={term:o,token:e,distance:s,score:i,tokenIndex:-1})}return r}function ue(e,t){let r=null;for(let o=0;o<e.length;o++){const n=e[o],s=C(n,t);if(s===null)continue;const i={...s,tokenIndex:o};if(i.distance===0)return i;(r===null||i.score>r.score)&&(r=i)}return r}function bn(e,t,r){if(e.length===0)return[];const o=[];for(const n of t){if(n.length===0)continue;const s=r??je(n.length);if(Math.abs(e.length-n.length)>s)continue;const i=n===e?0:de(e,n,s);i!==1/0&&o.push({term:n,token:e,distance:i,score:1-i/Math.max(n.length,1),tokenIndex:-1})}return o.sort((n,s)=>s.score-n.score)}const et=Object.freeze({zero:0,um:1,uma:1,dois:2,duas:2,tres:3,quatro:4,cinco:5,seis:6,sete:7,oito:8,nove:9,dez:10,onze:11,doze:12,treze:13,catorze:14,quatorze:14,quinze:15,dezesseis:16,dezessete:17,dezoito:18,dezenove:19,vinte:20,trinta:30,quarenta:40,cinquenta:50,sessenta:60,setenta:70,oitenta:80,noventa:90,cem:100,cento:100,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12,thirteen:13,fourteen:14,fifteen:15,sixteen:16,seventeen:17,eighteen:18,nineteen:19,twenty:20,thirty:30,forty:40,fifty:50,sixty:60,seventy:70,eighty:80,ninety:90,hundred:100});function Te(e){const t=et[e];return typeof t=="number"?t:null}const ee=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,vn=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*([\d.]+)\s*)?\)$/i,yn=/^hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*(?:,\s*([\d.]+)\s*)?\)$/i;function tt(e){const t=vn.exec(e);if(!t)return null;const r=he(Number.parseInt(t[1],10)),o=he(Number.parseInt(t[2],10)),n=he(Number.parseInt(t[3],10));return Ae(r,o,n)}function nt(e){const t=yn.exec(e);if(!t)return null;const r=(Number.parseFloat(t[1])%360+360)%360,o=Ne(Number.parseFloat(t[2])/100),n=Ne(Number.parseFloat(t[3])/100),[s,i,a]=Re(r,o,n);return Ae(s,i,a)}const fe=Object.freeze({claro:.18,clara:.18,escuro:-.18,escura:-.18,pastel:.25,vibrante:-.05,light:.18,lighter:.24,dark:-.18,darker:-.24,pale:.25}),pe=Object.freeze({bem:1.6,muito:1.5,mais:1.3,very:1.6,really:1.5,super:1.7});function V(e,t){const r=ot(e);if(r===null)return e;const[o,n,s]=rt(r[0],r[1],r[2]),i=Ne(s+t),[a,c,l]=Re(o,n,i);return Ae(a,c,l)}function wn(e,t=.18){return V(e,+Math.abs(t))}function kn(e,t=.18){return V(e,-Math.abs(t))}function Ne(e){return e<0?0:e>1?1:e}function he(e){return e<0?0:e>255?255:e|0}function ot(e){if(!ee.test(e))return null;let t=e.slice(1).toLowerCase();(t.length===3||t.length===4)&&(t=t.split("").map(s=>s+s).join(""));const r=Number.parseInt(t.slice(0,2),16),o=Number.parseInt(t.slice(2,4),16),n=Number.parseInt(t.slice(4,6),16);return!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(n)?null:[r,o,n]}function Ae(e,t,r){const o=n=>he(Math.round(n)).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(r)}`}function rt(e,t,r){const o=e/255,n=t/255,s=r/255,i=Math.max(o,n,s),a=Math.min(o,n,s),c=(i+a)/2;let l=0,d=0;if(i!==a){const f=i-a;switch(d=c>.5?f/(2-i-a):f/(i+a),i){case o:l=(n-s)/f+(n<s?6:0);break;case n:l=(s-o)/f+2;break;case s:l=(o-n)/f+4;break}l*=60}return[l,d,c]}function Re(e,t,r){if(t===0){const i=r*255;return[i,i,i]}const o=r<.5?r*(1+t):r+t-r*t,n=2*r-o,s=e/360;return[Ce(n,o,s+1/3)*255,Ce(n,o,s)*255,Ce(n,o,s-1/3)*255]}function Ce(e,t,r){let o=r;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?e+(t-e)*6*o:o<1/2?t:o<2/3?e+(t-e)*(2/3-o)*6:e}const xn=/^(-?\d+(?:[.,]\d+)?)(?:px|pt)?$/,st=/^(\d+(?:[.,]\d+)?)x(\d+(?:[.,]\d+)?)$/;function D(e){const t=st.exec(e);if(t){const o=Number.parseFloat(t[1].replace(",","."));return Number.isFinite(o)?o:null}const r=xn.exec(e);if(r!==null){const o=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(o)?o:null}return Te(e)}function te(e){if(ee.test(e))return e.toLowerCase();const t=tt(e);if(t!==null)return t;const r=nt(e);if(r!==null)return r;const o=Z(e);if(o!==null)return o;const n=C(e,Ze);return n===null?null:Z(n.term)}function ge(e,t){if(t<0||t>=e.length)return null;const r=[e[t],e[t+1]??"",e[t+2]??""];let o=-1,n=null,s=0;for(let p=0;p<r.length-1;p++){const g=r[p],x=r[p+1];if(g.length===0||x.length===0)continue;const S=te(g+x);if(S!==null){o=p,n=S,s=2;break}const H=te(x+g);if(H!==null){o=p,n=H,s=2;break}}if(o===-1)for(let p=0;p<r.length;p++){const g=r[p];if(g.length===0)continue;const x=te(g);if(x!==null){o=p,n=x;break}}if(o===-1||n===null)return null;let i=0,a=1,c=0,l=0;for(let p=o-1;p>=0;p--){const g=r[p],x=fe[g],S=pe[g];if(x!==void 0)i+=x,l++;else if(S!==void 0)a*=S,l++;else break}const d=o+(s>0?s:1);for(let p=d;p<r.length;p++){const g=r[p];if(g.length===0)break;const x=fe[g],S=pe[g];if(x!==void 0)i+=x,c++;else if(S!==void 0)a*=S,c++;else break}let f=n;const h=i*a;h!==0&&ee.test(n)&&(f=V(n,h));const u=s>0?s:1,m=l+u+c;return{color:f,tokensConsumed:m}}function Le(e){const t=st.exec(e);if(!t)return null;const r=Number.parseFloat(t[1].replace(",",".")),o=Number.parseFloat(t[2].replace(",","."));return!Number.isFinite(r)||!Number.isFinite(o)?null:{width:r,height:o}}function it(e,t,r={consumedIndices:new Set}){const o={},n=Object.entries(t);if(t.width?.kind==="number"&&t.height?.kind==="number")for(let a=0;a<e.length;a++){if(r.consumedIndices.has(a))continue;const c=Le(e[a]);if(c!==null){o.width=c.width,o.height=c.height,r.consumedIndices.add(a);break}}const s=t.count;if(s?.kind==="number"&&s.positional===!1)for(let a=0;a<e.length-1;a++){if(r.consumedIndices.has(a))continue;const c=D(e[a]);if(c===null)continue;let l=a+1;for(;l<e.length&&(r.consumedIndices.has(l)||E(e[l]));)l++;if(l>=e.length)continue;if(R(e[l])!==null||C(e[l],Q)!==null){o.count=c,r.consumedIndices.add(a);break}}if(t.gradient?.kind==="gradient"){let a=-1;for(let c=0;c<e.length;c++){if(r.consumedIndices.has(c))continue;const l=e[c];if(l==="gradiente"||l==="degrade"||l==="gradient"){a=c;break}}if(a!==-1){r.consumedIndices.add(a);const c=new Set;for(const u of Object.values(t))if(u.kind==="color"&&u.anchorKeywords)for(const m of u.anchorKeywords)c.add(m);let l=e.length;for(let u=0;u<e.length;u++)if(c.has(e[u])){l=u;break}let d="linear",f="horizontal";for(let u=0;u<e.length;u++)if(!r.consumedIndices.has(u))switch(e[u]){case"radial":d="radial",r.consumedIndices.add(u);break;case"linear":d="linear",r.consumedIndices.add(u);break;case"vertical":f="vertical",r.consumedIndices.add(u);break;case"horizontal":f="horizontal",r.consumedIndices.add(u);break;case"diagonal":f="diagonal",r.consumedIndices.add(u);break}const h=[];for(let u=0;u<l;u++){if(r.consumedIndices.has(u)||E(e[u])||!(te(e[u])!==null||fe[e[u]]!==void 0||pe[e[u]]!==void 0))continue;const p=ge(e,u);if(p!==null){h.push(p.color);for(let g=0;g<p.tokensConsumed;g++)r.consumedIndices.add(u+g)}}h.length>0&&(o.gradient={kind:d,direction:f,colors:h})}}for(const[a,c]of n){if(a in o)continue;const l=c.anchorKeywords;if(!(!l||l.length===0))for(let d=0;d<e.length;d++){if(r.consumedIndices.has(d))continue;const f=e[d];if(E(f)||C(f,l)===null)continue;const u=In(c,e,d+1,r);if(u!==null){o[a]=u.value,r.consumedIndices.add(d);for(const m of u.consumedIndices)r.consumedIndices.add(m);break}}}for(const[a,c]of n){if(a in o)continue;if(c.kind==="number"&&c.positional===!1){c.optional===!0&&c.default!==void 0&&(o[a]=c.default);continue}if(c.kind==="gradient")continue;if(c.anchorKeywords!==void 0&&c.anchorKeywords.length>0){c.optional===!0&&"default"in c&&c.default!==void 0&&(o[a]=c.default);continue}let l,d=-1,f=1;for(let h=0;h<e.length;h++){if(r.consumedIndices.has(h))continue;const u=e[h];if(!E(u)){switch(c.kind){case"number":{const m=D(u);m!==null&&(l=m,d=h);break}case"color":{if(D(u)!==null)break;const m=ge(e,h);m!==null&&(l=m.color,d=h,f=m.tokensConsumed);break}case"shape":{if(D(u)!==null)break;const m=R(u);if(m!==null)l=m,d=h;else{const p=C(u,Q);if(p!==null){const g=R(p.term);g!==null&&(l=g,d=h)}}break}case"enum":{const m=c.values;if(m.includes(u))l=u,d=h;else if(c.fuzzy!==!1){const p=C(u,m);p!==null&&(l=p.term,d=h)}break}case"string":{l=u,d=h;break}case"point":{const m=at(e,h,r);if(m!==null){l=m.value,d=h;for(const p of m.consumedIndices)r.consumedIndices.add(p);f=0}break}}if(d!==-1)break}}if(d!==-1){o[a]=l;for(let h=0;h<f;h++)r.consumedIndices.add(d+h)}else c.optional===!0&&"default"in c&&c.default!==void 0&&(o[a]=c.default)}return o}function In(e,t,r,o){for(let n=r;n<Math.min(r+4,t.length);n++){if(o.consumedIndices.has(n))continue;const s=t[n];if(!E(s))switch(e.kind){case"number":{const i=D(s);return i!==null?{value:i,consumedIndices:[n]}:null}case"color":{const i=ge(t,n);if(i!==null){const a=[];for(let c=0;c<i.tokensConsumed;c++)a.push(n+c);return{value:i.color,consumedIndices:a}}return null}case"shape":{const i=R(s);if(i!==null)return{value:i,consumedIndices:[n]};const a=C(s,Q);if(a!==null){const c=R(a.term);if(c!==null)return{value:c,consumedIndices:[n]}}return null}case"enum":{if(e.values.includes(s))return{value:s,consumedIndices:[n]};if(e.fuzzy!==!1){const i=C(s,e.values);if(i!==null)return{value:i.term,consumedIndices:[n]}}return null}case"string":return{value:s,consumedIndices:[n]};case"point":{const i=at(t,n,o);return i!==null?{value:i.value,consumedIndices:i.consumedIndices}:null}}}return null}function at(e,t,r){const o=e[t];if(o===void 0)return null;const n=Le(o);if(n!==null)return{value:{x:n.width,y:n.height},consumedIndices:[t]};const s=D(o);if(s===null)return null;for(let i=t+1;i<Math.min(t+4,e.length);i++){if(r.consumedIndices.has(i)||E(e[i]))continue;const a=D(e[i]);return a!==null?{value:{x:s,y:a},consumedIndices:[t,i]}:null}return null}const Sn=/[\s;!?()\\[\]{}"'`]/;function ct(e){return e.normalize("NFD").replace(/[̀-ͯ]/g,"")}function De(e){return ct(e.toLowerCase())}function lt(e){return e>="0"&&e<="9"}function T(e){if(typeof e!="string"||e.length===0)return[];const t=De(e),r=[];let o="";for(let n=0;n<t.length;n++){const s=t[n],i=n>0?t[n-1]:"",a=n<t.length-1?t[n+1]:"",c=(s===","||s===".")&&lt(i)&&lt(a);Sn.test(s)||(s===","||s===".")&&!c?o.length>0&&(r.push(o),o=""):o+=s}return o.length>0&&r.push(o),r}function qe(e,t){return T(e).filter(r=>!t.has(r))}const dt=.5,ut=.55,ft=.65,pt=.75,ht=.25,gt=.2,mt=.15,bt=.05,vt=.1,yt=.1,me=.04,wt=.2,zn=.3,kt=.7,Mn=.05,On=5;function mo(e){const t=e.kwScore??1;let o=(e.hasAction&&e.hasSlots?dt:e.hasAction?ut:e.hasSlots?ft:pt)*t;const n=e.actionMatched??"none";n==="direct"?o+=ht*(e.actionScore??1):n==="canonical"&&(o+=gt),o-=(e.requiredMissing??0)*mt,o+=(e.optionalFilled??0)*bt,o+=(e.requiredFilled??0)*vt,o+=(e.anchoredFilled??0)*yt;const s=Math.min(e.descHits??0,wt/me);return o+=s*me,Math.max(0,Math.min(1,o))}class L{_intents=P([],...ngDevMode?[{debugName:"_intents"}]:[]);intents=this._intents.asReadonly();intentsCount=Ye(()=>this._intents().length,...ngDevMode?[{debugName:"intentsCount"}]:[]);descriptionTokensCache=new Map;registerIntent(t){if(typeof t.id!="string"||t.id.length===0)throw new Error("NaturalLanguageService.registerIntent: intent.id must be non-empty");if(!Array.isArray(t.keywords)||t.keywords.length===0)throw new Error(`NaturalLanguageService.registerIntent: intent "${t.id}" must declare at least one keyword`);if(this._intents().some(r=>r.id===t.id))throw new Error(`NaturalLanguageService.registerIntent: intent "${t.id}" is already registered`);return this._intents.set([...this._intents(),t]),this.populateDescriptionCache(t),{dispose:()=>{this._intents.set(this._intents().filter(r=>r.id!==t.id)),this.descriptionTokensCache.delete(t.id)}}}populateDescriptionCache(t){if(this.descriptionTokensCache.has(t.id))return;const r=t.description;if(typeof r!="string"||r.length===0){this.descriptionTokensCache.set(t.id,new Set);return}const o=T(r),n=new Set(o.filter(s=>!E(s)&&s.length>=3));this.descriptionTokensCache.set(t.id,n)}descriptionBoost(t,r){let o=this.descriptionTokensCache.get(t.id);if(o===void 0&&(this.populateDescriptionCache(t),o=this.descriptionTokensCache.get(t.id)),o===void 0||o.size===0)return 0;let n=0;const s=new Set;for(const a of r)s.has(a)||E(a)||o.has(a)&&(n++,s.add(a));const i=wt/me;return Math.min(i,n)*me}getIntent(t){return this._intents().find(r=>r.id===t)??null}parse(t,r,o={}){const n=o.threshold??zn,s=o.maxResults??On,i=T(t);if(i.length===0)return[];const a=i.map(l=>G(l)),c=[];for(const l of this._intents()){const d=[],f=ue(i,l.keywords);if(f===null)continue;if(l.requiredAllGroups!==void 0&&l.requiredAllGroups.length>0){let y=!0;for(const I of l.requiredAllGroups){if(I.length===0)continue;if(ue(i,I)===null){y=!1;break}}if(!y)continue}d.push({kind:"keyword",term:f.term,token:f.token,distance:f.distance,tokenIndex:f.tokenIndex});const h=(l.actionKeywords?.length??0)>0,u=Object.keys(l.slots??{}).length>0;let p=(h&&u?dt:h?ut:u?ft:pt)*f.score;const g=l.actionKeywords;if(g!==void 0&&g.length>0){const y=ue(i,g);if(y!==null)d.push({kind:"action",term:y.term,token:y.token,distance:y.distance,tokenIndex:y.tokenIndex}),p=Math.min(1,p+ht*y.score);else{const I=new Set(g.map(z=>G(z)).filter(z=>z!==null));if(I.size>0)for(let z=0;z<a.length;z++){const Y=a[z];if(Y!==null&&I.has(Y)){d.push({kind:"action",term:Y,token:i[z],distance:0,tokenIndex:z}),p=Math.min(1,p+gt);break}}}}const x=new Set;for(const y of d)if(y.kind==="action"){const I=y.tokenIndex;typeof I=="number"&&I>=0&&I<i.length&&x.add(I)}else if(y.kind==="keyword"){if(R(y.token)!==null||Z(y.token)!==null)continue;const I=y.tokenIndex;typeof I=="number"&&I>=0&&I<i.length&&x.add(I)}const S=l.slots??{},H=Object.keys(S),W=it(i,S,{consumedIndices:x});let se=0,w=0,X=0,ie=0;for(const y of H){const I=W[y]!==void 0,z=S[y];I?(d.push({kind:"slot",term:y,token:String(W[y]),distance:0,tokenIndex:-1}),z.optional===!0?w++:X++,z.anchorKeywords!==void 0&&z.anchorKeywords.length>0&&ie++):z.optional!==!0&&se++}p-=se*mt,p+=w*bt,p+=X*vt,p+=ie*yt,p+=this.descriptionBoost(l,i),p=Math.max(0,Math.min(1,p)),p>=n&&c.push({intent:l,confidence:p,slots:W,matches:d})}return c.sort((l,d)=>{const f=d.confidence-l.confidence;return Math.abs(f)>Mn?f:d.matches.length-l.matches.length}),c.slice(0,s)}async execute(t,r,o={}){const n=this.parse(t,r,o),s=o.autoExecuteThreshold??kt,i=o.confirmGate??null;if(n.length===0)return{executed:!1,candidate:null,alternatives:[],rejection:"no-match"};const a=n[0],c=n.slice(1);if(a.intent.destructive===!0&&i===null)return{executed:!1,candidate:a,alternatives:c,rejection:"destructive-no-gate"};if(a.intent.destructive===!0||a.confidence<s){if(i===null)return{executed:!1,candidate:a,alternatives:c,rejection:"below-threshold"};if(!await i(a))return{executed:!1,candidate:a,alternatives:c,rejection:"confirmation-declined"}}try{return await a.intent.execute(a.slots,r),{executed:!0,candidate:a,alternatives:c,rejection:null}}catch(d){const f=d instanceof Error?d:new Error(String(d));return typeof console<"u"&&console.error(`[svge.nlu] execute failed in intent "${a.intent.id}":`,f),{executed:!1,candidate:a,alternatives:c,rejection:"execute-error",error:f}}}static CLAUSE_SPLIT_RE=/\s*[;,]\s*|\s+e\s+|\s+depois\s+|\s+tamb[eé]m\s+|\s+and\s+|\s+then\s+/i;static COMMAND_VERBS=new Set(["criar","crie","cria","desenhar","desenhe","desenha","adicionar","adicione","adiciona","fazer","faca","inserir","insira","create","draw","add","make","insert"]);async executeSequence(t,r,o={}){const n=this.splitIntoClauses(t);if(n.length<=1)return[await this.execute(t,r,o)];const s=[];for(const i of n)s.push(await this.execute(i,r,o));return s}splitIntoClauses(t){const r=t.split(L.CLAUSE_SPLIT_RE).map(n=>n.trim()).filter(n=>n.length>0);if(r.length<=1)return r;const o=[];for(const n of r)o.length===0||this.clauseLooksLikeCommand(n)?o.push(n):o[o.length-1]=`${o[o.length-1]} ${n}`;return o}clauseLooksLikeCommand(t){return T(t).some(r=>R(r)!==null||L.COMMAND_VERBS.has(r))}async executeCandidate(t,r,o={}){const n=o.autoExecuteThreshold??kt,s=o.confirmGate??null;if(t.intent.destructive===!0&&s===null)return{executed:!1,candidate:t,alternatives:[],rejection:"destructive-no-gate"};if(t.intent.destructive===!0||t.confidence<n){if(s===null)return{executed:!1,candidate:t,alternatives:[],rejection:"below-threshold"};if(!await s(t))return{executed:!1,candidate:t,alternatives:[],rejection:"confirmation-declined"}}try{return await t.intent.execute(t.slots,r),{executed:!0,candidate:t,alternatives:[],rejection:null}}catch(a){const c=a instanceof Error?a:new Error(String(a));return typeof console<"u"&&console.error(`[svge.nlu] executeCandidate failed in intent "${t.intent.id}":`,c),{executed:!1,candidate:t,alternatives:[],rejection:"execute-error",error:c}}}static \u0275fac=v.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:L,deps:[],target:v.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=v.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:L,providedIn:"root"})}v.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:L,decorators:[{type:ce,args:[{providedIn:"root"}]}]});const _n=new Set(["delete","deletar","remove","remover","excluir","apagar","clear","limpar","reset","resetar"]);function xt(e){if(typeof e!="string"||e.length===0)return[];const t=e.replace(/\.{3}|…/g,"").trim(),r=qe(t,le).filter(n=>n.length>1),o=new Set(r);for(const n of r){const s=G(n);if(s!==null)for(const[i,a]of Object.entries(J))a===s&&o.add(i)}return[...o]}function $n(e){if(typeof e!="string"||e.length===0)return null;const t=e.replace(/\.{3}|…/g,"").trim(),r=qe(t,le).filter(n=>n.length>1);if(r.length<2)return null;const o=[];for(const n of r){const s=new Set([n]),i=G(n);if(i!==null)for(const[a,c]of Object.entries(J))c===i&&s.add(a);o.push([...s])}return o}function En(e){const t=new Set(xt(e));for(const r of _n)if(t.has(r))return!0;return!1}function jn(e){return`svge.nlu.menu.${e}`}function It(e){if(e.divider===!0||e.comingSoon===!0||typeof e.label!="string"||e.label.trim().length===0)return null;const t=xt(e.label);if(t.length===0)return null;const r=En(e.label),o=De(e.label),n=$n(e.label),s={id:jn(e.id),keywords:t,destructive:r,description:o,execute(i,a){const c={injector:a.injector};e.run(c)}};return n!==null?{...s,requiredAllGroups:n}:s}function Pe(e,t){const r=[],o=new Set(t.intents().map(s=>s.id));for(const s of e.contributions()){const i=It(s);if(i!==null&&!o.has(i.id))try{r.push(t.registerIntent(i))}catch{}}const n={dispose(){for(const s of r)try{s.dispose()}catch{}}};return{disposables:r,count:r.length,composedDispose:n}}function St(e,t,r){let o=e.contributions(),n=Pe(e,t),s=!1;const i=Pt(r,()=>Kt(()=>{const a=e.contributions();s||a!==o&&(n!==null&&n.composedDispose.dispose(),n=Pe(e,t),o=a)}));return{disposable:{dispose(){if(!s){s=!0;try{i.destroy()}catch{}if(n!==null){try{n.composedDispose.dispose()}catch{}n=null}}}}}}function b(e){return(Math.round(e*100)/100).toString()}const Ke=Object.freeze({"trending-up":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-9)} ${s(5)} L${n(-3)} ${s(-1)} L${n(1)} ${s(3)} L${n(9)} ${s(-6)} M${n(4)} ${s(-6)} L${n(9)} ${s(-6)} L${n(9)} ${s(-1)}`},"trending-down":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-9)} ${s(-5)} L${n(-3)} ${s(1)} L${n(1)} ${s(-3)} L${n(9)} ${s(6)} M${n(4)} ${s(6)} L${n(9)} ${s(6)} L${n(9)} ${s(1)}`},"bar-chart":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-9)} ${s(9)} H${n(9)} M${n(-6)} ${s(9)} V${s(1)} M${n(0)} ${s(9)} V${s(-5)} M${n(6)} ${s(9)} V${s(-2)}`},check:(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-7)} ${s(0)} L${n(-2)} ${s(5)} L${n(8)} ${s(-6)}`},close:(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-6)} ${s(-6)} L${n(6)} ${s(6)} M${n(6)} ${s(-6)} L${n(-6)} ${s(6)}`},plus:(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(0)} ${s(-7)} V${s(7)} M${n(-7)} ${s(0)} H${n(7)}`},minus:(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-7)} ${s(0)} H${n(7)}`},"arrow-up":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(0)} ${s(8)} V${s(-8)} M${n(-6)} ${s(-2)} L${n(0)} ${s(-8)} L${n(6)} ${s(-2)}`},"arrow-down":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(0)} ${s(-8)} V${s(8)} M${n(-6)} ${s(2)} L${n(0)} ${s(8)} L${n(6)} ${s(2)}`},"arrow-right":(e,t,r)=>{const o=r/24,n=i=>b(e+i*o),s=i=>b(t+i*o);return`M${n(-8)} ${s(0)} H${n(8)} M${n(2)} ${s(-6)} L${n(8)} ${s(0)} L${n(2)} ${s(6)}`},circle:(e,t,r)=>{const o=r/24,n=b(9*o);return`M${b(e)} ${b(t-9*o)} A${n} ${n} 0 1 0 ${b(e)} ${b(t+9*o)} A${n} ${n} 0 1 0 ${b(e)} ${b(t-9*o)} Z`},user:(e,t,r)=>{const o=r/24,n=l=>b(e+l*o),s=l=>b(t+l*o),i=b(4*o),a=`M${n(0)} ${s(-9)} A${i} ${i} 0 1 0 ${n(0)} ${s(-1)} A${i} ${i} 0 1 0 ${n(0)} ${s(-9)} Z`,c=`M${n(-8)} ${s(9)} A${b(9*o)} ${b(8*o)} 0 0 1 ${n(8)} ${s(9)}`;return`${a} ${c}`}}),Tn=Object.freeze({tendencia:"trending-up",alta:"trending-up",crescimento:"trending-up",subida:"trending-up",growth:"trending-up",up:"trending-up",queda:"trending-down",baixa:"trending-down",declinio:"trending-down",down:"trending-down",grafico:"bar-chart",graficos:"bar-chart",chart:"bar-chart",barras:"bar-chart",bars:"bar-chart",graph:"bar-chart",dashboard:"bar-chart",ok:"check",certo:"check",confirmar:"check",sucesso:"check",success:"check",done:"check",ativo:"check",x:"close",fechar:"close",erro:"close",error:"close",cancelar:"close",cancel:"close",mais:"plus",adicionar:"plus",add:"plus",menos:"minus",remover:"minus",remove:"minus","seta-cima":"arrow-up","seta-baixo":"arrow-down","seta-direita":"arrow-right",circulo:"circle",ponto:"circle",bolinha:"circle",dot:"circle",usuario:"user",pessoa:"user",perfil:"user",cliente:"user",person:"user",account:"user"}),bo=Object.freeze(Object.keys(Ke)),Nn=new RegExp("[\\u0300-\\u036f]","g");function An(e){return e.trim().toLowerCase().normalize("NFD").replace(Nn,"")}function Rn(e){if(typeof e!="string"||e.length===0)return null;const t=An(e);return Object.prototype.hasOwnProperty.call(Ke,t)?t:Tn[t]??null}function zt(e,t,r,o){const n=Rn(e);return n===null?null:Ke[n](t,r,o)}function q(e){typeof console<"u"&&console.warn(`[svge.nlu] ${e}`)}function B(e,t){const o=[...e.injector.get(j).selectedIds()];return o.length===0?(q(`${t}: nada selecionado`),null):o}function U(e,t,r,o){const n=B(e,o);if(n===null)return;e.injector.get(_).dispatch(new Ve(n,t,r))}function Mt(e,t){const r=B(e,`flip-${t}`);if(r===null)return;const o=e.injector.get(_),s=e.injector.get(K).document().viewBox,i={x:s.x+s.width/2,y:s.y+s.height/2},a=t==="horizontal"?-1:1,c=t==="vertical"?-1:1;for(const l of r)o.dispatch(new Be(l,i,a,c))}function be(e,t){const r=B(e,`reorder-${t}`);if(r===null)return;const o=e.injector.get(_);for(const n of r)o.dispatch(new Ut(n,t))}function ne(e,t){const o=[...e.injector.get(j).selectedIds()];if(o.length<2){q(`pathfinder-${t}: requer \u2265 2 n\xF3s selecionados`);return}const n=e.injector.get(_);switch(t){case"union":n.dispatch(new Vt(o));break;case"intersect":n.dispatch(new Gt(o));break;case"subtract":n.dispatch(new Yt(o));break;case"exclude":n.dispatch(new Ht(o));break;case"divide":n.dispatch(new Ft(o));break}}function Cn(e,t){if(t==="rect")return e.type==="rect";if(t==="ellipse"||t==="circle")return e.type==="ellipse";if(t==="line")return e.type==="line";if(t==="path")return e.type==="path";if(t==="polyline")return e.type==="polyline";if(t==="text")return e.type==="text";if(t==="image")return e.type==="image";if(t==="group")return e.type==="group";if(e.type!=="polygon")return!1;if(t==="polygon")return!0;if(t==="star")return e.points.length===10;const r=Qe[t];return r===void 0?!1:e.points.length===r}function Ln(e){const t=e.transform[4],r=e.transform[5];switch(e.type){case"rect":return{x:e.x+t,y:e.y+r};case"ellipse":return{x:e.cx-e.rx+t,y:e.cy-e.ry+r};case"line":return{x:Math.min(e.x1,e.x2)+t,y:Math.min(e.y1,e.y2)+r};case"polygon":case"polyline":{if(e.points.length===0)return null;let o=1/0,n=1/0;for(const s of e.points)s.x<o&&(o=s.x),s.y<n&&(n=s.y);return{x:o+t,y:n+r}}case"text":return{x:e.x+t,y:e.y+r};case"image":return{x:e.x+t,y:e.y+r};case"path":case"group":return null;default:return null}}function Ue(e,t,r){const o=B(e,"move-to-absolute");if(o===null)return;const n=e.injector.get(_),i=e.injector.get(K).document().root;let a=0,c=0;for(const l of o){const d=Bt(i,l);if(d===null){c++;continue}const f=Ln(d);if(f===null){q(`move-to-absolute: n\xF3 ${d.type} (id=${l}) sem origin comput\xE1vel headless \u2014 skip`),c++;continue}const h=t!==null?t-f.x:0,u=r!==null?r-f.y:0;h===0&&u===0||(n.dispatch(new We(l,h,u)),a++)}a===0&&c>0&&q(`move-to-absolute: ${c} n\xF3(s) skip; nada movido`)}function Dn(e,t){t.track(e.registerIntent({id:"svge.builtin.nlu.rotate-selected",keywords:["rotacionar","rotacione","girar","gire","rodar","rode","virar","vire","rotacao","rota\xE7\xE3o","rotate","spin","turn","twist","rotation"],actionKeywords:["rotate"],slots:{width:{kind:"number",optional:!1}},description:"Rotaciona os n\xF3s selecionados pelo \xE2ngulo dado (graus, sentido hor\xE1rio)",execute(r,o){const n=B(o,"rotate-selected");if(n===null)return;const s=o.injector.get(_),i=o.injector.get(K),c=(r.width??0)*Math.PI/180,l=i.document().viewBox,d={x:l.x+l.width/2,y:l.y+l.height/2};for(const f of n)s.dispatch(new Wt(f,c,d))}})),t.track(e.registerIntent({id:"svge.builtin.nlu.flip-horizontal",keywords:["espelhar","espelhe","espelhamento","inverter","inverta","refletir","reflita","horizontal","horizontalmente","flip","mirror","reflect","reverse"],actionKeywords:["flip"],slots:{axis:{kind:"enum",values:["horizontal","horiz","h","eixox","xaxis"],optional:!1}},description:"Espelha (flip) horizontalmente os n\xF3s selecionados em torno do centro do viewBox",execute(r,o){Mt(o,"horizontal")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.flip-vertical",keywords:["espelhar","espelhe","inverter","inverta","refletir","reflita","vertical","verticalmente","flip","mirror","reflect","reverse"],actionKeywords:["flip"],slots:{axis:{kind:"enum",values:["vertical","vert","v","eixoy","yaxis"],optional:!1}},description:"Espelha (flip) verticalmente os n\xF3s selecionados em torno do centro do viewBox",execute(r,o){Mt(o,"vertical")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.set-stroke",keywords:["borda","contorno","traco","tra\xE7o","linha","stroke","outline","border"],slots:{color:{kind:"color",optional:!1}},description:"Aplica a cor de borda (stroke) aos n\xF3s selecionados",execute(r,o){const n=r.color;n!==void 0&&U(o,"stroke",n,"set-stroke")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.set-stroke-width",keywords:["espessura","grossura","largura","tamanho","thickness","width","strokewidth"],slots:{width:{kind:"number",optional:!1}},description:"Define a espessura da borda (stroke width) dos n\xF3s selecionados",execute(r,o){const n=r.width;n===void 0||n<0||U(o,"strokeWidth",n,"set-stroke-width")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.set-opacity",keywords:["opacidade","transparencia","transpar\xEAncia","translucido","visibilidade","opacity","transparency","alpha","fade"],slots:{width:{kind:"number",optional:!1}},description:"Define a opacidade (0\u20131 ou 0\u2013100%) dos n\xF3s selecionados",execute(r,o){let n=r.width??1;n>1&&(n=n/100);const s=Math.max(0,Math.min(1,n));U(o,"opacity",s,"set-opacity")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.remove-fill",keywords:["preenchimento","fundo","fill","background","sempreenchimento","semfundo","nofill","nocolor"],actionKeywords:["delete"],description:"Remove o preenchimento (fill = none) dos n\xF3s selecionados",execute(r,o){U(o,"fill","none","remove-fill")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.remove-stroke",keywords:["borda","contorno","traco","stroke","outline","border","semborda","semcontorno","nostroke","noborder"],actionKeywords:["delete"],description:"Remove a borda (stroke = none) dos n\xF3s selecionados",execute(r,o){U(o,"stroke","none","remove-stroke")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.select-all",keywords:["tudo","todos","todas","all","everything","tudoselecionado","ambos","ambas"],actionKeywords:["select","select-all"],description:"Seleciona TODOS os n\xF3s top-level do documento (tudo, todos, todas, ambos, all)",execute(r,o){const n=o.injector.get(K),s=o.injector.get(j),i=n.document().root.children.map(a=>a.id);if(i.length===0){q("select-all: documento vazio");return}s.selectMany(i)}})),t.track(e.registerIntent({id:"svge.builtin.nlu.deselect",keywords:["desselecionar","desselecione","desmarcar","desmarque","limpar","limpe","deselect","unselect","clear"],actionKeywords:["deselect"],description:"Limpa a sele\xE7\xE3o (nenhum n\xF3 selecionado)",execute(r,o){o.injector.get(j).clear()}})),t.track(e.registerIntent({id:"svge.builtin.nlu.select-by-type",keywords:["retangulo","retangulos","quadrado","quadrados","circulo","circulos","elipse","elipses","linha","linhas","texto","textos","textos","grupo","grupos","caminho","caminhos","poligono","poligonos","triangulo","triangulos","losango","losangos","diamante","diamantes","pentagono","pentagonos","hexagono","hexagonos","octogono","octogonos","estrela","estrelas","polilinha","polilinhas","rectangle","rectangles","rect","rects","square","squares","circle","circles","ellipse","ellipses","line","lines","text","texts","group","groups","path","paths","polygon","polygons","triangle","triangles","rhombus","diamond","diamonds","pentagon","pentagons","hexagon","hexagons","octagon","octagons","star","stars","polyline","polylines"],actionKeywords:["select","select-all"],slots:{shape:{kind:"shape",optional:!1},count:{kind:"number",optional:!0},fill:{kind:"color",optional:!0}},description:'Seleciona n\xF3s por tipo (rect, circle, polygon, hexagon, star, text, etc) \u2014 filtra opcionalmente por cor e valida quantidade ("selecionar os 3 triangulos azuis")',execute(r,o){const n=r.shape;if(n===void 0)return;const s=r.count,i=r.fill,a=o.injector.get(K),c=o.injector.get(j),l=[];for(const d of Xt(a.document().root))Cn(d,n)&&(i!==void 0&&d.style?.fill!==i||l.push(d.id));if(l.length===0){const d=i!==void 0?`${n} com fill=${i}`:n;q(`select-by-type: nenhum ${d} encontrado`);return}s!==void 0&&l.length!==s&&q(`select-by-type: usu\xE1rio pediu ${s} ${n}${i!==void 0?" "+i:""} mas encontrei ${l.length} \u2014 selecionando todos os ${l.length} encontrados`),c.selectMany(l)}})),t.track(e.registerIntent({id:"svge.builtin.nlu.show-selected",keywords:["mostrar","mostre","exibir","exiba","visualizar","visualize","revelar","revele","show","display","reveal","unhide"],actionKeywords:["show"],description:"Torna vis\xEDveis os n\xF3s selecionados (visibility: visible)",execute(r,o){U(o,"visibility","visible","show")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.hide-selected",keywords:["esconder","esconda","ocultar","oculte","hide","conceal"],actionKeywords:["hide"],description:"Esconde os n\xF3s selecionados (visibility: hidden)",execute(r,o){U(o,"visibility","hidden","hide")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.bring-to-front",keywords:["frente","topo","front","top","acima","cima"],actionKeywords:["bring-forward"],description:"Traz os n\xF3s selecionados para o topo do z-order",execute(r,o){be(o,"toFront")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.send-to-back",keywords:["tras","fundo","back","bottom","abaixo","baixo"],actionKeywords:["send-backward"],description:"Envia os n\xF3s selecionados para o fundo do z-order",execute(r,o){be(o,"toBack")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.bring-forward",keywords:["avancar","avance","forward","subir","suba","umafrente"],actionKeywords:["bring-forward"],description:"Avan\xE7a os n\xF3s selecionados uma posi\xE7\xE3o no z-order",execute(r,o){be(o,"forward")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.send-backward",keywords:["recuar","recue","backward","descer","desca","umatras"],actionKeywords:["send-backward"],description:"Recua os n\xF3s selecionados uma posi\xE7\xE3o no z-order",execute(r,o){be(o,"backward")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.pathfinder-union",keywords:["unir","una","unificar","unifique","fundir","funda","mesclar","mescle","union","unify","weld","fuse","merge"],actionKeywords:["union"],description:"Combina (Union) os paths selecionados em uma \xFAnica forma",execute(r,o){ne(o,"union")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.pathfinder-intersect",keywords:["intersectar","intersecte","cruzar","cruze","intersecao","interseccao","intersect","intersection","cross"],actionKeywords:["intersect"],description:"Mant\xE9m apenas a \xE1rea de sobreposi\xE7\xE3o (Intersect) dos paths",execute(r,o){ne(o,"intersect")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.pathfinder-subtract",keywords:["subtrair","subtraia","menos","remover2","subtract","minus","difference","diferenca"],actionKeywords:["subtract"],description:"Subtrai o segundo path do primeiro (Subtract / Minus Front)",execute(r,o){ne(o,"subtract")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.pathfinder-exclude",keywords:["excluda","excluir2","xor","exclude","excluir","exclua"],actionKeywords:["exclude"],description:"Remove a sobreposi\xE7\xE3o m\xFAtua (XOR / Exclude)",execute(r,o){ne(o,"exclude")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.pathfinder-divide",keywords:["fatiar","fatie","divide","divida","recortar2","slice","split2"],actionKeywords:["divide"],description:"Divide os paths em regi\xF5es pelas intersec\xE7\xF5es (cada regi\xE3o vira shape)",execute(r,o){ne(o,"divide")}})),t.track(e.registerIntent({id:"svge.builtin.nlu.convert-to-path",keywords:["caminho","path","vetor","vector"],actionKeywords:["convert"],description:"Converte rect/ellipse/line/polygon/polyline selecionados em <path>",execute(r,o){const n=o.injector.get(_),i=[...o.injector.get(j).selectedIds()];if(i.length===0){q("convert-to-path: nada selecionado");return}for(const a of i)n.dispatch(new Jt(a))}})),t.track(e.registerIntent({id:"svge.builtin.nlu.move-to-position",keywords:["mover","mova","move","movem","movimentar","movimente","movimenta","deslocar","desloque","desloca","arrastar","arraste","arrasta","posicionar","posicione","posiciona","drag","shift","position","translate"],actionKeywords:["move"],slots:{position:{kind:"point",optional:!1,anchorKeywords:["posicao","position","coordenada","coordinate","para","to"]}},description:'Move os n\xF3s selecionados pra POSI\xC7\xC3O absoluta (x, y) \u2014 diferente do "move dx dy" que \xE9 relativo',execute(r,o){const n=r.position;n!==void 0&&Ue(o,n.x,n.y)}})),t.track(e.registerIntent({id:"svge.builtin.nlu.move-to-x",keywords:["mover","mova","move","movimenta","movimente","desloca","desloque","deslocar","posicionar","posicione","x","horizontal"],actionKeywords:["move"],slots:{targetX:{kind:"number",optional:!1,anchorKeywords:["x","horizontal"]}},description:"Move os n\xF3s selecionados pra coordenada X absoluta (eixo horizontal)",execute(r,o){const n=r.targetX;n!==void 0&&Ue(o,n,null)}})),t.track(e.registerIntent({id:"svge.builtin.nlu.move-to-y",keywords:["mover","mova","move","movimenta","movimente","desloca","desloque","deslocar","posicionar","posicione","y","vertical"],actionKeywords:["move"],slots:{targetY:{kind:"number",optional:!1,anchorKeywords:["y","vertical"]}},description:"Move os n\xF3s selecionados pra coordenada Y absoluta (eixo vertical)",execute(r,o){const n=r.targetY;n!==void 0&&Ue(o,null,n)}})),t.track(e.registerIntent({id:"svge.builtin.nlu.delete-selected",keywords:["deletar","delete2","deleta","apagar","apague","remover","remova","excluir3","eliminar","elimine","erase","destroy","discard"],actionKeywords:["delete"],destructive:!0,description:"DESTRUTIVO: remove permanentemente os n\xF3s selecionados",execute(r,o){const n=B(o,"delete-selected");if(n===null)return;const s=o.injector.get(_);for(const i of n)s.dispatch(new Zt(i))}}))}const qn=Object.freeze(["grade","grades","grid","matriz","malha","linha","linhas","fileira","fileiras","row","horizontal","coluna","colunas","column","columns","vertical","pilha","empilhado","empilhados","diagonal","cascata","cascade","espalhado","espalhados","espalhada","espalhadas","distribuido","distribuidos","distribuida","distribuidas","disperso","dispersos","scatter","spread"]);function Pn(e){switch(e){case"linha":case"linhas":case"fileira":case"fileiras":case"row":case"horizontal":return"row";case"coluna":case"colunas":case"column":case"columns":case"vertical":case"pilha":case"empilhado":case"empilhados":return"column";case"grade":case"grades":case"grid":case"matriz":case"malha":return"grid";case"espalhado":case"espalhados":case"espalhada":case"espalhadas":case"distribuido":case"distribuidos":case"distribuida":case"distribuidas":case"disperso":case"dispersos":case"scatter":case"spread":return"scatter";default:return"diagonal"}}function Kn(e,t,r,o,n,s,i){const a=[],c=Math.max(n,s)*.5+20,l=Math.max(n,s)+20;if(e==="scatter"){const d=Math.max(1,Math.ceil(Math.sqrt(t))),f=Math.max(1,Math.ceil(t/d)),h=i.width/d,u=i.height/f;for(let m=0;m<t;m++){const p=m%d,g=Math.floor(m/d);a.push({cx:i.x+(p+.5)*h,cy:i.y+(g+.5)*u})}return a}if(e==="grid"){const d=Math.max(1,Math.ceil(Math.sqrt(t)));for(let f=0;f<t;f++)a.push({cx:r+f%d*l,cy:o+Math.floor(f/d)*l});return a}if(e==="row"){for(let d=0;d<t;d++)a.push({cx:r+d*l,cy:o});return a}if(e==="column"){for(let d=0;d<t;d++)a.push({cx:r,cy:o+d*l});return a}for(let d=0;d<t;d++)a.push({cx:r+d*c,cy:o+d*c});return a}function Un(e){if(e.length===1){const r=e[0];return ee.test(r)?[{offset:0,color:V(r,.18)},{offset:1,color:V(r,-.18)}]:[{offset:0,color:r},{offset:1,color:r}]}const t=e.length;return e.map((r,o)=>({offset:o/(t-1),color:r}))}function Fn(e){return e.kind==="radial"?{cx:.5,cy:.5,r:.5}:e.direction==="vertical"?{x1:0,y1:0,x2:0,y2:1}:e.direction==="diagonal"?{x1:0,y1:0,x2:1,y2:1}:{x1:0,y1:0,x2:1,y2:0}}function Hn(e,t){const r=Qt(),o={id:r,name:"Gradiente (NLU)",kind:e.kind,stops:Un(e.colors),geometry:Fn(e),buildMarkup(){return an(this)}};return t.get(cn).register(o),`url(#${r})`}function Fe(e){if(!Array.isArray(e))return[];const t=[];for(const r of e)if(typeof r=="string"&&r.length>0)t.push(r);else if(r!==null&&typeof r=="object"){const o=r.color;typeof o=="string"&&o.length>0&&t.push(o)}return t}function Yn(e){const t=e.direction;if(t==="horizontal"||t==="vertical"||t==="diagonal")return t;const r=`${String(e.from??"")} ${String(e.to??"")}`.toLowerCase(),o=/left|right|esquerda|direita|leste|oeste/.test(r),n=/top|bottom|up|down|cima|baixo|topo|fundo/.test(r);return o&&n?"diagonal":n?"vertical":"horizontal"}function Gn(e){const t=e.gradient;if(t!==null&&typeof t=="object"&&Array.isArray(t.colors)){const s=t;return s.colors.length>0?s:void 0}let r=Fe(e.colorStops);return r.length===0&&(r=Fe(e.stops)),r.length===0&&(r=Fe(e.colors)),r.length===0?void 0:{kind:(typeof t=="string"?t:e.type)==="radial"?"radial":"linear",direction:Yn(e),colors:r}}const Vn={id:"svge.builtin.nlu",name:"Built-in NLU (rule-based, Fase 1)",version:"1.0.0",apiVersion:dn,description:"Natural-language commands (rule-based): create shapes, set fill, and more.",author:"SVGEngine",icon:"smart_toy",category:"nlu",install(e){const t=e.injector.get(L),r=e.injector.get(ln),o=St(r,t,e.injector);e.track(o.disposable),e.track(t.registerIntent({id:"svge.builtin.nlu.create-shape",keywords:Q,actionKeywords:["create","add","draw","insert","new"],slots:{shape:{kind:"shape",optional:!0,default:"rect"},fill:{kind:"color",optional:!0},width:{kind:"number",optional:!0,default:100},height:{kind:"number",optional:!0,default:100},stroke:{kind:"color",optional:!0,anchorKeywords:["borda","contorno","stroke","outline"]},strokeWidth:{kind:"number",optional:!0,anchorKeywords:["espessura","thickness","tamanho","strokewidth"]},position:{kind:"point",optional:!0,anchorKeywords:["posicao","position","coordenada","coordinate"]},count:{kind:"number",optional:!0,positional:!1,default:1},layout:{kind:"enum",values:qn,optional:!0,fuzzy:!1},gradient:{kind:"gradient",optional:!0},content:{kind:"string",optional:!0,anchorKeywords:["texto","conteudo","content","dizendo","escrito","label"]},fontSize:{kind:"number",optional:!0,anchorKeywords:["fonte","fontsize"]},fontWeight:{kind:"enum",values:["bold","negrito"],optional:!0,fuzzy:!1},icon:{kind:"string",optional:!0,anchorKeywords:["icone","icon","glifo","glyph"]}},description:"Criar forma (ret\xE2ngulo, c\xEDrculo, elipse, texto, etc.) \u2014 suporta fill/stroke/espessura/posi\xE7\xE3o; para texto: content (texto literal), fontSize e fontWeight (bold)",execute(n,s){const i=s.injector.get(_),a=s.injector.get(K),c=n.shape??"rect",l=n.width??100,d=n.height??100,f=Gn(n);let h=n.fill;f!==void 0&&f.colors.length>0&&(h=Hn(f,s.injector));const u=n.stroke,m=n.strokeWidth,p=n.position,g=n.content,x=typeof g=="string"&&g.trim().length>0?g:void 0,S=n.fontSize,H=typeof S=="number"&&Number.isFinite(S)&&S>0?S:void 0,W=n.fontWeight!==void 0,se=typeof n.icon=="string"?n.icon:void 0;let w;(h!==void 0||u!==void 0||m!==void 0)&&(w={},h!==void 0&&(w.fill=h),u!==void 0&&(w.stroke=u),m!==void 0&&(w.strokeWidth=m));const X=a.document(),ie=X.root.id,y=X.viewBox,I=p?p.x:y.x+y.width/2,z=p?p.y:y.y+y.height/2,Y=Math.max(1,Math.min(50,Math.round(n.count??1))),Dt=Pn(n.layout),qt=Kn(Dt,Y,I,z,l,d,y);for(let ve=0;ve<Y;ve++){const{cx:M,cy:O}=qt[ve];switch(c){case"rect":{const k=rn({x:M-l/2,y:O-d/2,width:l,height:d},w?{style:w}:{});i.dispatch(new N(A,k));break}case"ellipse":{const k=Je({cx:M,cy:O,rx:l/2,ry:d/2},w?{style:w}:{});i.dispatch(new N(A,k));break}case"circle":{const k=Math.min(l,d)/2,$=Je({cx:M,cy:O,rx:k,ry:k},w?{style:w}:{});i.dispatch(new N(A,$));break}case"triangle":case"rhombus":case"pentagon":case"hexagon":case"octagon":case"polygon":{const k=Qe[c]??6,$=Math.min(l,d)/2,ae=hn(M,O,$,k),ye=Xe(ae,w?{style:w}:{});i.dispatch(new N(A,ye));break}case"star":{const k=Math.min(l,d)/2,$=gn(M,O,k),ae=Xe($,w?{style:w}:{});i.dispatch(new N(A,ae));break}case"line":{const k=on({x1:M-l/2,y1:O,x2:M+l/2,y2:O},w?{style:w}:{});i.dispatch(new N(A,k));break}case"polyline":{const k=[{x:M-l/2,y:O+d/4},{x:M,y:O-d/4},{x:M+l/2,y:O+d/4}],$=nn(k,w?{style:w}:{});i.dispatch(new N(A,$));break}case"icon":{const k=Math.min(l,d),$=zt(se,M,O,k)??zt("circle",M,O,k)??"";if($.length===0)break;const ye=tn($,{style:{fill:"none",stroke:h??"#334155",strokeWidth:Math.max(1.5,k/12)}});i.dispatch(new N(A,ye));break}case"text":{const k=H??Math.max(12,Math.min(l,d)/3),$=en({x:M,y:O+k/3,content:x??"Texto",fontSize:k,fontWeight:W?"bold":void 0,textAnchor:"middle"},w?{style:w}:{});i.dispatch(new N(A,$));break}default:{typeof console<"u"&&console.warn("[svge.nlu] create-shape: kind",c,"requer dados espec\xEDficos (URL/d-string/children) que NLU n\xE3o infere. Registre intent customizado (e.g., create-image com slot `url`).");break}}}}})),e.track(t.registerIntent({id:"svge.builtin.nlu.set-fill",keywords:["cor","pintar","pinta","preenchimento","fill","color","paint"],slots:{color:{kind:"color",optional:!1}},description:"Aplica a cor de preenchimento aos n\xF3s selecionados",execute(n,s){const i=n.color;if(i===void 0)return;const a=s.injector.get(_),l=[...s.injector.get(j).selectedIds()];if(l.length===0){typeof console<"u"&&console.warn("[svge.nlu] set-fill: nada selecionado");return}a.dispatch(new Ve(l,"fill",i))}})),e.track(t.registerIntent({id:"svge.builtin.nlu.move-selected",keywords:["mover","mova","move","arrastar","arraste","drag","deslocar","desloque","shift","posicionar","posicione","position"],slots:{width:{kind:"number",optional:!1},height:{kind:"number",optional:!1}},description:"Move (desloca relativo) os n\xF3s selecionados por dx, dy",execute(n,s){const i=s.injector.get(_),c=[...s.injector.get(j).selectedIds()];if(c.length===0){typeof console<"u"&&console.warn("[svge.nlu] move-selected: nada selecionado");return}const l=n.width??0,d=n.height??0;for(const f of c)i.dispatch(new We(f,l,d))}})),e.track(t.registerIntent({id:"svge.builtin.nlu.resize-selected",keywords:["redimensionar","redimensione","escalar","escale","scale","rescale","resize","dimensionar","dimensione","ajustar","ajuste","adjust"],slots:{width:{kind:"number",optional:!1},height:{kind:"number",optional:!1}},description:"Escala os n\xF3s selecionados por sx, sy (200 = 2x; 100 = manter)",execute(n,s){const i=s.injector.get(_),a=s.injector.get(K),l=[...s.injector.get(j).selectedIds()];if(l.length===0){typeof console<"u"&&console.warn("[svge.nlu] resize-selected: nada selecionado");return}const d=n.width??1,f=n.height??1,h=d>=10?d/100:d,u=f>=10?f/100:f,m={x:a.document().viewBox.x,y:a.document().viewBox.y};for(const p of l)i.dispatch(new Be(p,m,h,u))}})),e.track(t.registerIntent({id:"svge.builtin.nlu.duplicate-selected",keywords:["duplicar","duplique","duplicate","clonar","clone"],description:"Duplica os n\xF3s selecionados (offset padr\xE3o 10,10)",execute(n,s){const i=s.injector.get(_),c=[...s.injector.get(j).selectedIds()];if(c.length===0){typeof console<"u"&&console.warn("[svge.nlu] duplicate-selected: nada selecionado");return}i.dispatch(new sn(c))}})),Dn(t,{track:n=>e.track(n)})}};function Bn(e){if(e.length===0)return{language:"unknown",hits:{pt:0,en:0}};let t=0,r=0;for(const o of e){const n=Ee.has(o)||o in xe||o in Se||o in Oe,s=$e.has(o)||o in ke||o in Ie||o in Me;n&&!s?t++:s&&!n&&r++}return t===0&&r===0?{language:"unknown",hits:{pt:0,en:0}}:t===r?{language:"unknown",hits:{pt:t,en:r}}:{language:t>r?"pt":"en",hits:{pt:t,en:r}}}class oe{_colors=P(new Map,...ngDevMode?[{debugName:"_colors"}]:[]);_shapes=P(new Map,...ngDevMode?[{debugName:"_shapes"}]:[]);_actions=P(new Map,...ngDevMode?[{debugName:"_actions"}]:[]);colors=this._colors.asReadonly();shapes=this._shapes.asReadonly();actions=this._actions.asReadonly();registerColor(t,r){return this.registerEntry(this._colors,t,r,"color")}registerShape(t,r){return this.registerEntry(this._shapes,t,r,"shape")}registerAction(t,r){return this.registerEntry(this._actions,t,r,"action")}resolveColor(t){return this._colors().get(t)??null}resolveShape(t){return this._shapes().get(t)??null}resolveAction(t){return this._actions().get(t)??null}registerEntry(t,r,o,n){if(typeof r!="string"||r.length===0)throw new Error(`NluDictionaryRegistry.register${n}: key must be non-empty string`);const s=t(),i=new Map(s);return i.set(r,o),t.set(i),{dispose:()=>{const a=t();if(!a.has(r))return;const c=new Map(a);c.delete(r),t.set(c)}}}static \u0275fac=v.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:oe,deps:[],target:v.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=v.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:oe,providedIn:"root"})}v.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:oe,decorators:[{type:ce,args:[{providedIn:"root"}]}]});const Wn=new Ge("VOICE_WHISPER_PROVIDER",{providedIn:"root",factory:()=>null}),He=new Ge("AI_CHAT_PROVIDER",{providedIn:"root",factory:()=>null}),Ot="http://localhost:11434",_t="qwen2.5:3b",$t=["qwen2.5:3b","qwen2.5:7b","qwen2.5-coder:3b","qwen2.5-coder:7b","qwen2.5-coder:14b"];function Et(e){return e.endsWith("/")?e.slice(0,-1):e}class F{_baseUrl=P(Ot,...ngDevMode?[{debugName:"_baseUrl"}]:[]);_model=P(_t,...ngDevMode?[{debugName:"_model"}]:[]);_suggestedModels=P($t,...ngDevMode?[{debugName:"_suggestedModels"}]:[]);baseUrl=this._baseUrl.asReadonly();defaultModel=this._model.asReadonly();suggestedModels=this._suggestedModels.asReadonly();isConfigured=Ye(()=>this._baseUrl().length>0,...ngDevMode?[{debugName:"isConfigured"}]:[]);configure(t){typeof t.baseUrl=="string"&&t.baseUrl.length>0&&this._baseUrl.set(Et(t.baseUrl)),typeof t.model=="string"&&t.model.length>0&&this._model.set(t.model),Array.isArray(t.models)&&t.models.length>0&&this._suggestedModels.set([...t.models])}setBaseUrl(t){typeof t=="string"&&t.length>0&&this._baseUrl.set(Et(t))}setModel(t){typeof t=="string"&&t.length>0&&this._model.set(t)}async chat(t,r={}){const o=r.model??this._model(),n={};typeof r.temperature=="number"&&(n.temperature=r.temperature),typeof r.maxTokens=="number"&&(n.num_predict=r.maxTokens);const s={model:o,messages:t.map(c=>({role:c.role,content:c.content})),stream:!1};r.format==="json"&&(s.format="json"),Object.keys(n).length>0&&(s.options=n);const i=await fetch(`${this._baseUrl()}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),signal:r.signal});if(!i.ok)throw new Error(`Ollama /api/chat returned HTTP ${i.status}`);const a=await i.json();if(typeof a.error=="string"&&a.error.length>0)throw new Error(`Ollama error: ${a.error}`);return a.message?.content??""}async listModels(){const t=await fetch(`${this._baseUrl()}/api/tags`,{method:"GET"});if(!t.ok)throw new Error(`Ollama /api/tags returned HTTP ${t.status}`);const o=((await t.json()).models??[]).map(n=>n.name??n.model).filter(n=>typeof n=="string"&&n.length>0);return[...new Set(o)].sort((n,s)=>n.localeCompare(s))}static \u0275fac=v.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:F,deps:[],target:v.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=v.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:F})}v.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:F,decorators:[{type:ce}]});function Xn(e){return[F,{provide:He,useFactory:()=>{const t=we(F);return e!==void 0&&t.configure(e),t}}]}const jt=24,Tt=["create-shape","create-text","set-fill"],Jn=["You translate a user design request (Portuguese or English) into a PLAN of editor commands.","Respond with ONLY a JSON object, no prose and no markdown fences, in this exact shape:",'{"steps":[{"intentId":"<id>","slots":{...}}],"confidence":<number 0..1>}',"Rules:",'- The top-level object MUST have exactly two keys: "steps" (array) and "confidence" (number).','- NEVER output any other top-level key. Do NOT return {"card":...}, {"title":...}, {"value":...} or similar \u2014 only the {"steps":[...]} shape above.',"- Use ONLY intentId values present in the CATALOG below. Never invent an id.","- Decompose complex requests (e.g. a KPI card) into several steps using the available primitives (create one shape/text node per step).","- Fill a slot only when the request implies it; omit unknown slots.","- Output valid JSON and nothing else.","","CATALOG:"].join(`
2
+ `);class re{nlu=we(L);provider=we(He,{optional:!0});get isAvailable(){return this.provider!==null&&this.provider!==void 0}get defaultModel(){return this.provider?.defaultModel()??null}async listModels(){return this.provider===null||this.provider===void 0?[]:typeof this.provider.listModels!="function"?[]:this.provider.listModels()}suggestedModels(){return this.provider?.suggestedModels?.()??[]}buildCatalog(t,r={}){const o=this.nlu.intents(),n=r.maxEntries??jt;return(typeof t=="string"&&t.length>0&&o.length>n?Qn(o,t,n):o).map(Zn)}async resolvePlan(t,r={}){if(this.provider===null||this.provider===void 0)throw new Error("LlmIntentResolverService: no AI_CHAT_PROVIDER registered");const o=[{role:"system",content:oo(this.buildCatalog(t))},{role:"user",content:t}],n=await this.provider.chat(o,{format:"json",model:r.model,maxTokens:r.maxTokens,signal:r.signal,temperature:0}),s=Nt(n),i=[],a=[];for(const c of s.steps){const l=this.nlu.getIntent(c.intentId);if(l===null){a.push(c.intentId);continue}i.push({intentId:c.intentId,intent:l,slots:c.slots})}return{steps:i,confidence:s.confidence,raw:n,dropped:a}}async resolveAndExecute(t,r,o={}){const n=await this.resolvePlan(t,o),s=[];for(const i of n.steps){const a={intent:i.intent,confidence:n.confidence,slots:i.slots,matches:[]};s.push(await this.nlu.executeCandidate(a,r,{autoExecuteThreshold:0,confirmGate:o.confirmGate??null}))}return s}async generateSvg(t,r={}){if(this.provider===null||this.provider===void 0)throw new Error("LlmIntentResolverService: no AI_CHAT_PROVIDER registered");const o=[{role:"system",content:io()},{role:"user",content:t}],n=await this.provider.chat(o,{model:r.model,maxTokens:r.maxTokens,signal:r.signal,temperature:0});return{svg:At(n),raw:n}}async generateAndInsertSvg(t,r,o={}){const{svg:n,raw:s}=await this.generateSvg(t,o);if(n.length===0)return{ok:!1,svg:n,raw:s,warnings:[],error:"A IA n\xE3o retornou um SVG v\xE1lido."};const i=fn.import(n);if(!i.ok)return{ok:!1,svg:n,raw:s,warnings:[],error:i.error};const a=r.injector.get(un).placeDocumentCentered(i.document);return a===null?{ok:!1,svg:n,raw:s,warnings:i.warnings,error:"O SVG retornado n\xE3o tinha conte\xFAdo desenh\xE1vel."}:{ok:!0,svg:n,raw:s,nodeId:a,warnings:i.warnings}}static \u0275fac=v.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:re,deps:[],target:v.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=v.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:re,providedIn:"root"})}v.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:v,type:re,decorators:[{type:ce,args:[{providedIn:"root"}]}]});function Zn(e){const t={};for(const[r,o]of Object.entries(e.slots??{}))t[r]=o.kind;return{id:e.id,description:e.description??e.keywords.join(", "),slots:t}}function Qn(e,t,r){const o=new Set(T(t).filter(c=>!E(c)&&c.length>=2)),n=e.filter(c=>Tt.some(l=>c.id.includes(l))),s=new Set(n.map(c=>c.id)),i=e.filter(c=>!s.has(c.id)).map(c=>({intent:c,score:eo(c,o)})).sort((c,l)=>l.score-c.score),a=Math.max(0,r-n.length);return[...n,...i.slice(0,a).map(c=>c.intent)]}function eo(e,t){const r=new Set;for(const n of e.keywords)for(const s of T(n))r.add(s);for(const n of T(e.id.replace(/[.\-_]/g," ")))r.add(n);if(typeof e.description=="string")for(const n of T(e.description))!E(n)&&n.length>=3&&r.add(n);let o=0;for(const n of t)r.has(n)&&o++;return o}function to(e){const t=e.find(n=>n.id.includes("create-shape"));if(t===void 0)return"";const r=t.id;return["","EXAMPLE \u2014 a request and the ONLY acceptable output shape:",'User: "crie um card de KPI com \xEDcone, t\xEDtulo, valor e status"',JSON.stringify({steps:[{intentId:r,slots:{shape:"rect",width:280,height:150,position:{x:400,y:300},fill:"#ffffff",stroke:"#d0d7de"}},{intentId:r,slots:{shape:"icon",icon:"trending-up",width:28,height:28,position:{x:295,y:252},fill:"#3b82f6"}},{intentId:r,slots:{shape:"text",content:"Receita",fontSize:14,fill:"#6b7280",position:{x:345,y:252}}},{intentId:r,slots:{shape:"text",content:"R$ 1,2M",fontSize:32,fontWeight:"bold",fill:"#111827",position:{x:305,y:315}}},{intentId:r,slots:{shape:"ellipse",width:80,height:26,position:{x:495,y:350},fill:"#dcfce7"}},{intentId:r,slots:{shape:"text",content:"Ativo",fontSize:12,fill:"#16a34a",position:{x:495,y:354}}}],confidence:.75})].join(`
3
+ `)}const no=["",'Output ONLY the JSON object {"steps":[...],"confidence":number}.',"Every intentId MUST appear in the CATALOG above. No prose, no markdown, no other top-level keys."].join(`
4
+ `);function oo(e){const t=e.map(r=>{const o=Object.entries(r.slots).map(([s,i])=>`${s}(${i})`).join(", "),n=o.length>0?` | slots: ${o}`:"";return`- ${r.id}: ${r.description}${n}`});return`${Jn}
5
+ ${t.join(`
6
+ `)}
7
+ ${to(e)}
8
+ ${no}`}const ro=["You convert a user design request (Portuguese or English) into ONE complete, standalone SVG image.","Rules:","- Output ONLY the SVG: a single <svg ...>...</svg> element. No prose, no explanation, no markdown fences.","- Always set an explicit viewBox plus numeric width and height on the root <svg>.","- Use inline presentation attributes (fill, stroke, stroke-width, font-size, font-weight, text-anchor).",'- For gradients/filters/patterns, declare them in <defs> and reference via fill="url(#id)".','- Use font-family="sans-serif" for text; center labels with text-anchor="middle" when appropriate.',"- Compose rich requests (e.g. a KPI card) from <rect>, <text>, <ellipse>, <circle>, <path>, gradients.","- NEVER include <script>, event handlers (on*), external URLs, or <image> referencing remote files."].join(`
9
+ `),so=["","EXAMPLE \u2014 a request and the ONLY acceptable kind of output (a complete SVG, nothing else):",'User: "crie um card de KPI com \xEDcone, t\xEDtulo, valor e status"',['<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 150" width="280" height="150">','<defs><linearGradient id="kpiIcon" x1="0" y1="0" x2="1" y2="1">','<stop offset="0" stop-color="#3b82f6"/><stop offset="1" stop-color="#1e40af"/>',"</linearGradient></defs>",'<rect x="1" y="1" width="278" height="148" rx="12" fill="#ffffff" stroke="#d0d7de"/>','<circle cx="34" cy="40" r="18" fill="url(#kpiIcon)"/>','<path d="M26 44 L32 38 L37 42 L43 34" fill="none" stroke="#ffffff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>','<text x="64" y="36" font-family="sans-serif" font-size="14" fill="#6b7280">Receita</text>','<text x="64" y="64" font-family="sans-serif" font-size="32" font-weight="bold" fill="#111827">R$ 1,2M</text>','<ellipse cx="222" cy="120" rx="44" ry="14" fill="#dcfce7"/>','<text x="222" y="124" font-family="sans-serif" font-size="12" fill="#16a34a" text-anchor="middle">Ativo</text>',"</svg>"].join("")].join(`
10
+ `);function io(){return`${ro}
11
+ ${so}`}function Nt(e){const t=co(e);let r;try{r=JSON.parse(t)}catch{throw new Error("LlmIntentResolverService: model did not return valid JSON")}const o=ao(r),n=[];for(const i of o){if(i===null||typeof i!="object")continue;const a=i,c=a.intentId??a.id??a.intent;if(typeof c!="string"||c.length===0)continue;const l=a.slots,d=l!==null&&typeof l=="object"?l:{};n.push({intentId:c,slots:d})}let s=1;if(r!==null&&typeof r=="object"){const i=r.confidence;typeof i=="number"&&Number.isFinite(i)&&(s=Math.max(0,Math.min(1,i)))}return{steps:n,confidence:s}}function ao(e){if(Array.isArray(e))return e;if(e!==null&&typeof e=="object"){const t=e;if(Array.isArray(t.steps))return t.steps;if(typeof t.intentId=="string"||typeof t.id=="string")return[t]}return[]}function At(e){const t=e.trim(),r=t.match(/```(?:svg|xml|html)?\s*([\s\S]*?)```/i),o=(r?r[1]:t).trim(),n=o.search(/<svg[\s>]/i);if(n===-1)return"";const s="</svg>",i=o.toLowerCase().lastIndexOf(s);return i===-1||i<n?"":o.slice(n,i+s.length)}function co(e){const t=e.trim(),r=t.match(/```(?:json)?\s*([\s\S]*?)```/i),o=(r?r[1]:t).trim(),n=o.indexOf("{"),s=o.indexOf("["),i=s!==-1&&(n===-1||s<n)?s:n;if(i===-1)return o;const a=o[i]==="["?o.lastIndexOf("]"):o.lastIndexOf("}");return a===-1||a<i?o:o.slice(i,a+1)}const Rt=3,Ct=.5,Lt=new Set(["card","kpi","dashboard","painel","organograma","fluxograma","diagrama","infografico","infografia","banner","formulario","timeline","cronograma","grafico","tabela","calendario","mockup","wireframe","cartaz","poster","folder","panfleto"]);function lo(e){return!!(R(e)!==null||Z(e)!==null||G(e)!==null||Te(e)!==null||/[0-9]/.test(e))}function uo(e){const t=T(e);if(t.some(n=>Lt.has(n)))return!0;const r=t.filter(n=>!E(n)&&n.length>=2);return r.length<Rt?!1:r.filter(lo).length/r.length<Ct}export{J as ACTION_DICTIONARY,ke as ACTION_DICTIONARY_EN,xe as ACTION_DICTIONARY_PT,pn as ACTION_KEYS,He as AI_CHAT_PROVIDER,ze as COLOR_DICTIONARY,Ie as COLOR_DICTIONARY_EN,Se as COLOR_DICTIONARY_PT,Ze as COLOR_KEYS,Lt as COMPOSITE_KEYWORDS,Tt as CORE_INTENT_ID_HINTS,jt as DEFAULT_CATALOG_MAX_ENTRIES,Ot as DEFAULT_OLLAMA_BASE_URL,_t as DEFAULT_OLLAMA_MODEL,$t as DEFAULT_OLLAMA_MODELS,ee as HEX_COLOR_RE,fe as LIGHTNESS_MODIFIERS,pe as LIGHTNESS_MULTIPLIERS,re as LlmIntentResolverService,et as NUMBER_WORDS,L as NaturalLanguageService,oe as NluDictionaryRegistry,F as OllamaChatProvider,_e as SHAPE_DICTIONARY,Me as SHAPE_DICTIONARY_EN,Oe as SHAPE_DICTIONARY_PT,Q as SHAPE_KEYS,le as STOPWORDS,$e as STOPWORDS_EN,Ee as STOPWORDS_PT,Rt as VAGUE_MIN_MEANINGFUL_TOKENS,Ct as VAGUE_RECOGNIZED_FRACTION,Wn as VOICE_WHISPER_PROVIDER,je as adaptiveMaxDistance,V as adjustHexLightness,mn as bestMatch,Vn as builtinNluPlugin,kn as darkenHex,ct as deaccent,Bn as detectLanguage,Pe as discoverMenuIntents,St as discoverMenuIntentsReactive,it as extractSlots,At as extractSvgBlob,bn as fuzzyMatchAll,ue as fuzzyMatchAny,C as fuzzyMatchToken,ot as hexToRgb,Re as hslToRgb,E as isStopword,uo as isVagueForRuleBased,de as levenshtein,wn as lightenHex,It as menuContributionToIntent,De as normalize,ge as parseColorPhrase,te as parseColorToken,Le as parseDimensionToken,nt as parseHslFunction,D as parseNumberToken,Nt as parsePlan,tt as parseRgbFunction,Xn as provideOllamaChat,G as resolveActionCanonical,Z as resolveColorName,Te as resolveNumberWord,R as resolveShapeKind,rt as rgbToHsl,T as tokenize,qe as tokenizeWithoutStopwords};
@@ -0,0 +1,3 @@
1
+ import*as O from"@angular/core";import{InjectionToken as Go,signal as ot,computed as Dt,Injectable as zt,inject as Yt}from"@angular/core";import q from"polygon-clipping";function Gt(n,t,e,o){if(e<0||o<0)throw new RangeError(`BoundingBox dimensions must be non-negative: ${e}x${o}`);return{x:n,y:t,width:e,height:o}}function $e(n,t){const e=Math.min(n.x,t.x),o=Math.min(n.y,t.y),s=Math.max(n.x+n.width,t.x+t.width),r=Math.max(n.y+n.height,t.y+t.height);return{x:e,y:o,width:s-e,height:r-o}}function Bo(n,t,e){return t>=n.x&&t<=n.x+n.width&&e>=n.y&&e<=n.y+n.height}function Uo(n,t){return n.x<=t.x+t.width&&n.x+n.width>=t.x&&n.y<=t.y+t.height&&n.y+n.height>=t.y}const W=Object.freeze({});function Xo(n){return n}function x(){return typeof globalThis.crypto?.randomUUID=="function"?globalThis.crypto.randomUUID():Ko()}let sn=0;function Ko(){return sn+=1,`node-${Date.now().toString(36)}-${sn.toString(36)}`}const Wo=Object.freeze({x:0,y:0}),rn=Object.freeze({}),H=Object.freeze({fill:"#cccccc",stroke:"#333333",strokeWidth:1}),A=[1,0,0,1,0,0];function F(n,t){return[1,0,0,1,n,t]}function dt(n,t=n){return[n,0,0,t,0,0]}function wt(n){const t=Math.cos(n),e=Math.sin(n);return[t,e,-e,t,0,0]}function an(n){return[1,0,Math.tan(n),1,0,0]}function un(n){return[1,Math.tan(n),0,1,0,0]}function S(n,t){const[e,o,s,r,i,a]=n,[u,l,h,f,d,p]=t;return[e*u+s*l,o*u+r*l,e*h+s*f,o*h+r*f,e*d+s*p+i,o*d+r*p+a]}function dn(n,t,e){const[o,s,r,i,a,u]=n;return{x:o*t+r*e+a,y:s*t+i*e+u}}function Bt(n){const[t,e,o,s,r,i]=n,a=t*s-e*o;if(Math.abs(a)<1e-12)throw new RangeError(`invert: matrix is non-invertible (det=${a}); cannot project into local frame.`);return[s/a,-e/a,-o/a,t/a,(o*i-s*r)/a,(e*r-t*i)/a]}function qo(n,t=1e-9){const[e,o,s,r,i,a]=n;return Math.abs(e-1)<t&&Math.abs(o)<t&&Math.abs(s)<t&&Math.abs(r-1)<t&&Math.abs(i)<t&&Math.abs(a)<t}function Ho(n){if(n===null||n.trim()==="")return A;const t=/([a-zA-Z]+)\s*\(([^)]*)\)/g;let e=A,o,s=!1;for(;(o=t.exec(n))!==null;){s=!0;const r=o[1]??"",i=o[2]??"",a=Zo(i),u=Qo(r,a);if(u===null)return A;e=S(e,u)}return s?e:A}function Zo(n){return n.trim()===""?[]:n.split(/[,\s]+/).filter(t=>t.length>0).map(Number)}function Qo(n,t){switch(n){case"matrix":return t.length!==6?null:[t[0],t[1],t[2],t[3],t[4],t[5]];case"translate":return t.length===1?F(t[0],0):t.length===2?F(t[0],t[1]):null;case"scale":return t.length===1?dt(t[0]):t.length===2?dt(t[0],t[1]):null;case"rotate":{if(t.length===1)return wt(Ut(t[0]));if(t.length===3){const[e,o,s]=t,r=wt(Ut(e));return S(S(F(o,s),r),F(-o,-s))}return null}case"skewX":return t.length!==1?null:[1,0,Math.tan(Ut(t[0])),1,0,0];case"skewY":return t.length!==1?null:[1,Math.tan(Ut(t[0])),0,1,0,0];default:return null}}function Ut(n){return n*Math.PI/180}const Jo=["rect","ellipse","line","polygon","polyline","path","text","image","group","symbol-use"];function B(n){return n.type==="group"}const X="svgeKind",ve="layer";function ft(n){if(n.type!=="group")return!1;const t=n.metadata.customData;return t===void 0?!1:t[X]===ve}function Ce(n){return{...n,metadata:{...n.metadata,customData:{...n.metadata.customData??{},[X]:ve}}}}function cn(n){const t=n.metadata.customData;if(t===void 0||t[X]===void 0)return n;const e={...t};delete e[X];const o=Object.keys(e).length>0?e:void 0;return{...n,metadata:{...n.metadata,customData:o}}}const Xt="smart-object";function Kt(n){if(n.type!=="group")return!1;const t=n.metadata.customData;return t===void 0?!1:t[X]===Xt}function ln(n){return{...n,metadata:{...n.metadata,customData:{...n.metadata.customData??{},[X]:Xt}}}}function ts(n){const t=n.metadata.customData;if(t===void 0||t[X]!==Xt)return n;const e={...t};delete e[X];const o=Object.keys(e).length>0?e:void 0;return{...n,metadata:{...n.metadata,customData:o}}}const Wt="page",Nt="svgePageViewBox",pt="svgePageName",Re="svgePageOptions",ct={background:{kind:"transparent"},margins:{top:0,right:0,bottom:0,left:0},orientation:"landscape",format:"custom"};function j(n){if(n.type!=="group")return!1;const t=n.metadata.customData;return t===void 0?!1:t[X]===Wt}function Mt(n){if(!j(n))return null;const t=n.metadata.customData?.[Nt];if(t===void 0||typeof t!="object"||t===null)return null;const e=t;return typeof e.x!="number"||typeof e.y!="number"||typeof e.width!="number"||typeof e.height!="number"?null:{x:e.x,y:e.y,width:e.width,height:e.height}}function hn(n){if(!j(n))return"";const t=n.metadata.customData?.[pt];return typeof t=="string"&&t.length>0?t:typeof n.metadata.name=="string"&&n.metadata.name.length>0?n.metadata.name:"Untitled Page"}function Se(n,t,e){const o={...n.metadata.customData??{},[X]:Wt,[Nt]:{...t}};return e!==void 0&&(o[pt]=e),{...n,metadata:{...n.metadata,customData:o}}}function es(n){const t=n.metadata.customData;if(t===void 0||t[X]!==Wt)return n;const e={...t};delete e[X],delete e[Nt],delete e[pt];const o=Object.keys(e).length>0?e:void 0;return{...n,metadata:{...n.metadata,customData:o}}}function qt(n,t){return j(n)?{...n,metadata:{...n.metadata,customData:{...n.metadata.customData??{},[Nt]:{...t}}}}:n}function fn(n,t){if(!j(n))return n;const e={...n.metadata.customData??{}};return t.length===0?delete e[pt]:e[pt]=t,{...n,metadata:{...n.metadata,customData:e}}}function Ht(n){if(!j(n))return ct;const t=n.metadata.customData?.[Re];if(typeof t!="object"||t===null)return ct;const e=t,o=ns(e.background)?e.background:ct.background,s=os(e.margins)?e.margins:ct.margins,r=e.orientation==="portrait"||e.orientation==="landscape"?e.orientation:ct.orientation,i=ss(e.format)?e.format:ct.format;return{background:o,margins:s,orientation:r,format:i}}function ke(n,t){if(!j(n))return n;const e=Ht(n),o={background:t.background??e.background,margins:t.margins??e.margins,orientation:t.orientation??e.orientation,format:t.format??e.format};return{...n,metadata:{...n.metadata,customData:{...n.metadata.customData??{},[Re]:o}}}}const Zt={a4:{width:595,height:842},a5:{width:420,height:595},a3:{width:842,height:1191},letter:{width:612,height:792},legal:{width:612,height:1008},tabloid:{width:792,height:1224},"square-1080":{width:1080,height:1080},"square-1200":{width:1200,height:1200},"square-2048":{width:2048,height:2048}};function De(n,t){if(n==="custom")return null;const e=Zt[n];return t==="landscape"?{width:e.height,height:e.width}:{width:e.width,height:e.height}}function we(n,t){return n>t?"landscape":"portrait"}function pn(n,t){const e=Math.min(n,t),o=Math.max(n,t);for(const s of Object.keys(Zt)){const r=Zt[s];if(Math.abs(r.width-e)<=.5&&Math.abs(r.height-o)<=.5)return s}return"custom"}function ns(n){if(typeof n!="object"||n===null)return!1;const t=n;switch(t.kind){case"transparent":return!0;case"solid":return typeof t.color=="string"&&t.color.length>0;case"image":return typeof t.href=="string"&&t.href.length>0;default:return!1}}function os(n){if(typeof n!="object"||n===null)return!1;const t=n;return Qt(t.top)&&Qt(t.right)&&Qt(t.bottom)&&Qt(t.left)}function ss(n){return n==="a4"||n==="a5"||n==="a3"||n==="letter"||n==="legal"||n==="tabloid"||n==="square-1080"||n==="square-1200"||n==="square-2048"||n==="custom"}function Qt(n){return typeof n=="number"&&Number.isFinite(n)&&n>=0}function mn(n,t={}){return{type:"rect",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,x:n.x,y:n.y,width:n.width,height:n.height,rx:n.rx,ry:n.ry}}function rs(n,t={}){return{type:"ellipse",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,cx:n.cx,cy:n.cy,rx:n.rx,ry:n.ry}}function is(n,t={}){return{type:"line",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2}}function as(n,t={}){return{type:"polygon",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,points:n}}function us(n,t={}){return{type:"polyline",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,points:n}}function tt(n,t={}){return{type:"path",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,d:n}}function ds(n,t={}){return{type:"text",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,x:n.x,y:n.y,content:n.content,fontSize:n.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,textAnchor:n.textAnchor,fontStyle:n.fontStyle,textDecoration:n.textDecoration,lineHeight:n.lineHeight,fontVariationSettings:n.fontVariationSettings,fontFeatureSettings:n.fontFeatureSettings,letterSpacing:n.letterSpacing,textPathRef:n.textPathRef,textPathStartOffset:n.textPathStartOffset,runs:n.runs}}function yn(n,t={}){return{type:"image",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,x:n.x,y:n.y,width:n.width,height:n.height,href:n.href,preserveAspectRatio:n.preserveAspectRatio}}function et(n=[],t={}){return{type:"group",id:t.id??x(),transform:t.transform??A,style:t.style??rn,metadata:t.metadata??W,children:n}}function cs(n,t={}){return{type:"symbol-use",id:t.id??x(),transform:t.transform??A,style:t.style??H,metadata:t.metadata??W,symbolId:n.symbolId,x:n.x,y:n.y,width:n.width,height:n.height}}const gn="xMidYMid slice";function ls(n){const t=Mt(n);if(t===null||t.width<=0||t.height<=0)return null;const e=Ht(n).background;return e.kind==="solid"?mn({x:t.x,y:t.y,width:t.width,height:t.height},{style:{fill:e.color}}):e.kind==="image"?yn({x:t.x,y:t.y,width:t.width,height:t.height,href:e.href,preserveAspectRatio:gn}):null}const Jt="svgeCustomAttrs",te="data-",In="svge",hs=/^[a-z][a-z0-9-]*$/;function st(n){return!(typeof n!="string"||!hs.test(n)||n===In||n.startsWith(`${In}-`))}function fs(n){return`${te}${n}`}function ps(n){if(!n.startsWith(te))return null;const t=n.slice(te.length);return st(t)?t:null}function Pt(n){const t=n.metadata.customData?.[Jt];if(t==null||typeof t!="object")return{};const e={};for(const[o,s]of Object.entries(t))typeof s=="string"&&st(o)&&(e[o]=s);return e}function ms(n){return Object.keys(Pt(n)).length>0}function ee(n,t){const e=Object.entries(t).filter(([r,i])=>st(r)&&typeof i=="string"),o={...n.metadata.customData??{}};e.length===0?delete o[Jt]:o[Jt]=Object.fromEntries(e);const s=Object.keys(o).length>0?o:void 0;return{...n,metadata:{...n.metadata,customData:s}}}function xn(n,t,e){return st(t)?ee(n,{...Pt(n),[t]:e}):n}function bn(n,t){const e=Pt(n);if(!(t in e))return n;const o={...e};return delete o[t],ee(n,o)}function $n(n,t,e){const o=Pt(n);if(!(t in o)||!st(e)||e in o)return n;const s={};for(const[r,i]of Object.entries(o))s[r===t?e:r]=i;return ee(n,s)}const ys=/[MmLlHhVvCcSsQqTtAaZz]|-?(?:\d+\.\d*|\d+|\.\d+)(?:[eE][+-]?\d+)?/g;function ne(n){const t=n.match(ys)??[],e=[];let o=null,s=[];const r=()=>{o!==null&&e.push({cmd:o,args:s})};for(const i of t)if(/^[A-Za-z]$/.test(i))r(),o=i,s=[];else{const a=Number(i);Number.isFinite(a)&&s.push(a)}return r(),e}function vn(n){const t=[];for(const e of n){t.push(e.cmd);for(const o of e.args)t.push(gs(o))}return t.join(" ").replace(/\s+/g," ").trim()}function gs(n){if(Object.is(n,-0))return"0";const t=Math.round(n*1e6)/1e6;return String(t)}function Cn(n,t,e,o){return Is(n).map(r=>xs(r,t,e,o))}function Is(n){if(n.length===0)return n;const t=n[0];if(t.cmd!=="m"||t.args.length<2)return n;const e={cmd:"M",args:[t.args[0],t.args[1]]},o=t.args.slice(2),s=[e];return o.length>0&&s.push({cmd:"l",args:o}),[...s,...n.slice(1)]}function xs(n,t,e,o){const s=n.args;switch(n.cmd){case"Z":case"z":return n;case"M":case"L":case"T":return{cmd:n.cmd,args:Ne(s,t,e,o)};case"m":case"l":case"t":return{cmd:n.cmd,args:Me(s,t,e)};case"H":return{cmd:n.cmd,args:s.map(r=>o.x+(r-o.x)*t)};case"h":return{cmd:n.cmd,args:s.map(r=>r*t)};case"V":return{cmd:n.cmd,args:s.map(r=>o.y+(r-o.y)*e)};case"v":return{cmd:n.cmd,args:s.map(r=>r*e)};case"C":return{cmd:n.cmd,args:Ne(s,t,e,o)};case"c":return{cmd:n.cmd,args:Me(s,t,e)};case"S":case"Q":return{cmd:n.cmd,args:Ne(s,t,e,o)};case"s":case"q":return{cmd:n.cmd,args:Me(s,t,e)};case"A":return{cmd:n.cmd,args:bs(s,t,e,o)};case"a":return{cmd:n.cmd,args:$s(s,t,e)}}}function Ne(n,t,e,o){const s=[];for(let r=0;r+1<n.length;r+=2)s.push(o.x+(n[r]-o.x)*t),s.push(o.y+(n[r+1]-o.y)*e);return s}function Me(n,t,e){const o=[];for(let s=0;s+1<n.length;s+=2)o.push(n[s]*t),o.push(n[s+1]*e);return o}function bs(n,t,e,o){const s=[],r=t<0!=e<0;for(let i=0;i+6<n.length;i+=7)s.push(Math.abs(n[i]*t)),s.push(Math.abs(n[i+1]*e)),s.push(n[i+2]),s.push(n[i+3]),s.push(r?1-Math.round(n[i+4]):Math.round(n[i+4])),s.push(o.x+(n[i+5]-o.x)*t),s.push(o.y+(n[i+6]-o.y)*e);return s}function $s(n,t,e){const o=[],s=t<0!=e<0;for(let r=0;r+6<n.length;r+=7)o.push(Math.abs(n[r]*t)),o.push(Math.abs(n[r+1]*e)),o.push(n[r+2]),o.push(n[r+3]),o.push(s?1-Math.round(n[r+4]):Math.round(n[r+4])),o.push(n[r+5]*t),o.push(n[r+6]*e);return o}function Rn(n,t,e,o){return n.trim()===""?n:vn(Cn(ne(n),t,e,o))}function Ot(n,t,e,o){const s=e+(n-e)*o,r=e+(n+t-e)*o;return{start:Math.min(s,r),length:Math.abs(r-s)}}function lt(n,t,e,o){return{x:t.x+(n.x-t.x)*e,y:t.y+(n.y-t.y)*o}}function Sn(n,t,e,o){const s=Ot(n.x,n.width,o.x,t),r=Ot(n.y,n.height,o.y,e);return{...n,x:s.start,y:r.start,width:s.length,height:r.length,rx:n.rx!==void 0?Math.abs(n.rx*t):n.rx,ry:n.ry!==void 0?Math.abs(n.ry*e):n.ry}}function kn(n,t,e,o){const s=lt({x:n.cx,y:n.cy},o,t,e);return{...n,cx:s.x,cy:s.y,rx:Math.abs(n.rx*t),ry:Math.abs(n.ry*e)}}function Dn(n,t,e,o){const s=lt({x:n.x1,y:n.y1},o,t,e),r=lt({x:n.x2,y:n.y2},o,t,e);return{...n,x1:s.x,y1:s.y,x2:r.x,y2:r.y}}function wn(n,t,e,o){return{...n,points:n.points.map(s=>lt(s,o,t,e))}}function Nn(n,t,e,o){return{...n,points:n.points.map(s=>lt(s,o,t,e))}}function Mn(n,t,e,o){const s=Ot(n.x,n.width,o.x,t),r=Ot(n.y,n.height,o.y,e);return{...n,x:s.start,y:r.start,width:s.length,height:r.length}}function Pn(n,t,e,o){const s=lt({x:n.x,y:n.y},o,t,e),r=Math.abs(Math.abs(t)-Math.abs(e))<1e-9,i=r&&n.fontSize!==void 0?Math.abs(n.fontSize*t):n.fontSize,a=r&&n.runs!==void 0?n.runs.map(u=>u.fontSize!==void 0?{...u,fontSize:Math.abs(u.fontSize*t)}:u):n.runs;return{...n,x:s.x,y:s.y,fontSize:i,runs:a}}function On(n,t,e,o,s){const r=n.children.map(i=>s(i)??i);return{...n,children:r}}function Pe(n){const[t,e,o,s]=n;return Math.abs(t-1)<1e-9&&Math.abs(e)<1e-9&&Math.abs(o)<1e-9&&Math.abs(s-1)<1e-9}function Tn(n,t,e,o){return{...n,d:Rn(n.d,t,e,o)}}function Oe(n,t,e,o,s=null){if(!Pe(n.transform))return null;let r=o;s!==null&&Pe(s)&&(r={x:o.x-s[4],y:o.y-s[5]});const i={x:r.x-n.transform[4],y:r.y-n.transform[5]};switch(n.type){case"rect":return Sn(n,t,e,i);case"ellipse":return kn(n,t,e,i);case"line":return Dn(n,t,e,i);case"polygon":return wn(n,t,e,i);case"polyline":return Nn(n,t,e,i);case"path":return Tn(n,t,e,i);case"text":return Pn(n,t,e,i);case"image":return Mn(n,t,e,i);case"group":return On(n,t,e,r,a=>Oe(a,t,e,i,null));case"symbol-use":return{...n,x:i.x+(n.x-i.x)*t,y:i.y+(n.y-i.y)*e,width:(n.width??100)*t,height:(n.height??100)*e}}}function oe(n){const[t,e,o,s,r,i]=n,a=r,u=i,l=Math.atan2(e,t),h=Math.hypot(t,e),f=t*s-e*o,d=Math.hypot(o,s),p=h===0?0:h,y=d===0?0:f<0?-d:d;return{tx:a,ty:u,rotationRad:l,scaleX:p,scaleY:y}}function An(n){let t=A;return(n.scaleX!==1||n.scaleY!==1)&&(t=S(t,dt(n.scaleX,n.scaleY))),n.rotationRad!==0&&(t=S(wt(n.rotationRad),t)),(n.tx!==0||n.ty!==0)&&(t=S(F(n.tx,n.ty),t)),t}function Te(n,t=A){const e=t===A?n.transform:S(t,n.transform);switch(n.type){case"rect":return vs(n,e);case"ellipse":return Cs(n,e);case"line":return Rs(n,e);case"polygon":return Ss(n,e);case"polyline":return ks(n,e);case"path":return Ds(n,e);case"text":return ws(n,e);case"image":return Ns(n,e);case"group":return Ms(n,e);case"symbol-use":return nt(e,[[n.x,n.y],[n.x+(n.width??100),n.y],[n.x+(n.width??100),n.y+(n.height??100)],[n.x,n.y+(n.height??100)]])}}function vs(n,t){return nt(t,[[n.x,n.y],[n.x+n.width,n.y],[n.x+n.width,n.y+n.height],[n.x,n.y+n.height]])}function Cs(n,t){return nt(t,[[n.cx-n.rx,n.cy-n.ry],[n.cx+n.rx,n.cy-n.ry],[n.cx+n.rx,n.cy+n.ry],[n.cx-n.rx,n.cy+n.ry]])}function Rs(n,t){return nt(t,[[n.x1,n.y1],[n.x2,n.y2]])}function Ss(n,t){return n.points.length===0?mt(t):nt(t,n.points.map(e=>[e.x,e.y]))}function ks(n,t){return n.points.length===0?mt(t):nt(t,n.points.map(e=>[e.x,e.y]))}function Ds(n,t){const e=ne(n.d),o=[];let s=0,r=0,i=0,a=0;for(const u of e){const l=u.cmd,h=l===l.toLowerCase()&&l!==l.toUpperCase(),f=u.args;switch(l.toUpperCase()){case"M":case"L":case"T":for(let d=0;d+1<f.length;d+=2){const p=h?s+(f[d]??0):f[d]??0,y=h?r+(f[d+1]??0):f[d+1]??0;o.push([p,y]),s=p,r=y,l.toUpperCase()==="M"&&d===0&&(i=p,a=y)}break;case"H":for(const d of f){const p=h?s+d:d;o.push([p,r]),s=p}break;case"V":for(const d of f){const p=h?r+d:d;o.push([s,p]),r=p}break;case"C":for(let d=0;d+5<f.length;d+=6){const p=h?s+(f[d]??0):f[d]??0,y=h?r+(f[d+1]??0):f[d+1]??0,g=h?s+(f[d+2]??0):f[d+2]??0,I=h?r+(f[d+3]??0):f[d+3]??0,v=h?s+(f[d+4]??0):f[d+4]??0,b=h?r+(f[d+5]??0):f[d+5]??0;o.push([p,y],[g,I],[v,b]),s=v,r=b}break;case"S":case"Q":for(let d=0;d+3<f.length;d+=4){const p=h?s+(f[d]??0):f[d]??0,y=h?r+(f[d+1]??0):f[d+1]??0,g=h?s+(f[d+2]??0):f[d+2]??0,I=h?r+(f[d+3]??0):f[d+3]??0;o.push([p,y],[g,I]),s=g,r=I}break;case"A":for(let d=0;d+6<f.length;d+=7){const p=h?s+(f[d+5]??0):f[d+5]??0,y=h?r+(f[d+6]??0):f[d+6]??0;o.push([p,y]),s=p,r=y}break;case"Z":s=i,r=a;break}}return o.length===0?mt(t):nt(t,o)}function ws(n,t){const e=n.fontSize??16,o=Math.max(1,n.content.length)*e*.6,s=e*1.2,r=n.textAnchor==="middle"?o/2:n.textAnchor==="end"?o:0,i=n.x-r,a=n.y-e;return nt(t,[[i,a],[i+o,a],[i+o,a+s],[i,a+s]])}function Ns(n,t){return nt(t,[[n.x,n.y],[n.x+n.width,n.y],[n.x+n.width,n.y+n.height],[n.x,n.y+n.height]])}function Ms(n,t){if(!B(n)||n.children.length===0)return mt(t);let e=null;for(const o of n.children){const s=Te(o,t);e=e===null?s:$e(e,s)}return e??mt(t)}function nt(n,t){if(t.length===0)return mt(n);let e=1/0,o=1/0,s=-1/0,r=-1/0;for(const[i,a]of t){const u=dn(n,i,a);u.x<e&&(e=u.x),u.x>s&&(s=u.x),u.y<o&&(o=u.y),u.y>r&&(r=u.y)}return Gt(e,o,s-e,r-o)}function mt(n){return Gt(n[4],n[5],0,0)}function Ps(n,t){if(t.size===0)return null;let e=null;const o=(s,r)=>{if(t.has(s.id)){const i=Te(s,r);e=e===null?i:$e(e,i);return}if(B(s)){const i=s.transform===A?r:S(r,s.transform);for(const a of s.children)o(a,i)}};return o(n,A),e}function K(n){const t=ne(n),e=[];let o=null,s=0,r=0,i=null,a=null,u=null;const l=(h,f)=>{if(o!==null){if(o.anchors.length>0&&u!==null){const d=o.anchors[o.anchors.length-1];o.anchors[o.anchors.length-1]={...d,handleOut:u}}o.anchors.push(h),u=f}};for(const h of t){const{cmd:f,args:d}=h;switch(f){case"M":case"m":{for(let p=0;p<d.length;p+=2){const y=d[p],g=d[p+1];if(p===0){const I=f==="M"||e.length===0,v=I?y:s+y,b=I?g:r+g;o={anchors:[],closed:!1},e.push(o),u=null;const P={point:{x:v,y:b},handleIn:{x:v,y:b},handleOut:{x:v,y:b},kind:"cusp"};o.anchors.push(P),s=v,r=b}else{const I=f==="M",v=I?y:s+y,b=I?g:r+g;l({point:{x:v,y:b},handleIn:{x:v,y:b},handleOut:{x:v,y:b},kind:"cusp"},null),s=v,r=b}}i=null,a=null;break}case"L":case"l":{for(let p=0;p<d.length;p+=2){const y=f==="L",g=y?d[p]:s+d[p],I=y?d[p+1]:r+d[p+1];l({point:{x:g,y:I},handleIn:{x:g,y:I},handleOut:{x:g,y:I},kind:"cusp"},null),s=g,r=I}i=null,a=null;break}case"H":case"h":{for(const p of d){const y=f==="H"?p:s+p;l({point:{x:y,y:r},handleIn:{x:y,y:r},handleOut:{x:y,y:r},kind:"cusp"},null),s=y}i=null,a=null;break}case"V":case"v":{for(const p of d){const y=f==="V"?p:r+p;l({point:{x:s,y},handleIn:{x:s,y},handleOut:{x:s,y},kind:"cusp"},null),r=y}i=null,a=null;break}case"C":case"c":{for(let p=0;p<d.length;p+=6){const y=f==="C",g=y?d[p]:s+d[p],I=y?d[p+1]:r+d[p+1],v=y?d[p+2]:s+d[p+2],b=y?d[p+3]:r+d[p+3],P=y?d[p+4]:s+d[p+4],M=y?d[p+5]:r+d[p+5];u={x:g,y:I},l({point:{x:P,y:M},handleIn:{x:v,y:b},handleOut:{x:P,y:M},kind:Ae({x:P,y:M},{x:v,y:b},null)},null),i={x:v,y:b},a=null,s=P,r=M}break}case"S":case"s":{for(let p=0;p<d.length;p+=4){const y=f==="S",g=y?d[p]:s+d[p],I=y?d[p+1]:r+d[p+1],v=y?d[p+2]:s+d[p+2],b=y?d[p+3]:r+d[p+3],P=i!==null?2*s-i.x:s,M=i!==null?2*r-i.y:r;u={x:P,y:M},l({point:{x:v,y:b},handleIn:{x:g,y:I},handleOut:{x:v,y:b},kind:"smooth"},null),i={x:g,y:I},a=null,s=v,r=b}break}case"Q":case"q":{for(let p=0;p<d.length;p+=4){const y=f==="Q",g=y?d[p]:s+d[p],I=y?d[p+1]:r+d[p+1],v=y?d[p+2]:s+d[p+2],b=y?d[p+3]:r+d[p+3],P=s+2/3*(g-s),M=r+2/3*(I-r),C=v+2/3*(g-v),N=b+2/3*(I-b);u={x:P,y:M},l({point:{x:v,y:b},handleIn:{x:C,y:N},handleOut:{x:v,y:b},kind:"smooth"},null),a={x:g,y:I},i=null,s=v,r=b}break}case"T":case"t":{for(let p=0;p<d.length;p+=2){const y=f==="T",g=y?d[p]:s+d[p],I=y?d[p+1]:r+d[p+1],v=a!==null?2*s-a.x:s,b=a!==null?2*r-a.y:r,P=s+2/3*(v-s),M=r+2/3*(b-r),C=g+2/3*(v-g),N=I+2/3*(b-I);u={x:P,y:M},l({point:{x:g,y:I},handleIn:{x:C,y:N},handleOut:{x:g,y:I},kind:"smooth"},null),a={x:v,y:b},i=null,s=g,r=I}break}case"A":case"a":{for(let p=0;p<d.length;p+=7){const y=f==="A",g=y?d[p+5]:s+d[p+5],I=y?d[p+6]:r+d[p+6];l({point:{x:g,y:I},handleIn:{x:g,y:I},handleOut:{x:g,y:I},kind:"cusp"},null),s=g,r=I}i=null,a=null;break}case"Z":case"z":{if(o!==null&&(o.closed=!0),o!==null&&o.anchors.length>0){const p=o.anchors[0];s=p.point.x,r=p.point.y}i=null,a=null;break}}}if(o!==null&&u!==null&&o.anchors.length>0){const h=o.anchors.length-1,f=o.anchors[h];o.anchors[h]={...f,handleOut:u}}for(const h of e)for(let f=0;f<h.anchors.length;f++){const d=h.anchors[f],p=Ae(d.point,d.handleIn,d.handleOut);p!==d.kind&&(h.anchors[f]={...d,kind:p})}return e}function Z(n){const t=[];for(const e of n){if(e.anchors.length===0)continue;const o=e.anchors[0];t.push(`M${Q(o.point.x)} ${Q(o.point.y)}`);for(let s=1;s<e.anchors.length;s++){const r=e.anchors[s-1],i=e.anchors[s];t.push(En(r,i))}if(e.closed){const s=e.anchors[0],r=e.anchors[e.anchors.length-1];se(r.handleOut,r.point)&&se(s.handleIn,s.point)||t.push(En(r,s)),t.push("Z")}}return t.join(" ")}function En(n,t){const e=se(n.handleOut,n.point),o=se(t.handleIn,t.point);return e&&o?`L${Q(t.point.x)} ${Q(t.point.y)}`:`C${Q(n.handleOut.x)} ${Q(n.handleOut.y)} ${Q(t.handleIn.x)} ${Q(t.handleIn.y)} ${Q(t.point.x)} ${Q(t.point.y)}`}function se(n,t,e=1e-6){return Math.abs(n.x-t.x)<e&&Math.abs(n.y-t.y)<e}function Q(n){return Number.isInteger(n)?`${n}`:Number(n.toFixed(4)).toString()}function Ae(n,t,e){if(e===null)return"cusp";const o=t.x-n.x,s=t.y-n.y,r=e.x-n.x,i=e.y-n.y,a=Math.hypot(o,s),u=Math.hypot(r,i);if(a<1e-6||u<1e-6)return"cusp";const l=o*i-s*r,h=o*r+s*i;return Math.abs(l)>1e-4*a*u||h>=0?"cusp":Math.abs(a-u)<1e-4*Math.max(a,u)?"symmetric":"smooth"}function Tt(n,t=.5){const e=K(n),o=[];for(const s of e){if(s.anchors.length===0)continue;const r=[];r.push(s.anchors[0].point);for(let i=1;i<s.anchors.length;i++){const a=s.anchors[i-1],u=s.anchors[i],l=re(a.point,a.handleOut,u.handleIn,u.point,t);for(let h=1;h<l.length;h++)r.push(l[h])}if(s.closed){const i=s.anchors[0],a=s.anchors[s.anchors.length-1];if(!(_n(a.handleOut,a.point)&&_n(i.handleIn,i.point))){const l=re(a.point,a.handleOut,i.handleIn,i.point,t);for(let h=1;h<l.length-1;h++)r.push(l[h])}r.push(i.point)}o.push(r)}return o}function re(n,t,e,o,s,r=[n],i=0){if(i>16||Os(n,t,e,o,s))return r[r.length-1]!==o&&r.push(o),r;const a=yt(n,t),u=yt(t,e),l=yt(e,o),h=yt(a,u),f=yt(u,l),d=yt(h,f);return re(n,a,h,d,s,r,i+1),re(d,f,l,o,s,r,i+1),r}function yt(n,t){return{x:(n.x+t.x)/2,y:(n.y+t.y)/2}}function Os(n,t,e,o,s){const r=o.x-n.x,i=o.y-n.y,a=Math.hypot(r,i);if(a<1e-9)return!0;const u=l=>{const h=(l.x-n.x)*i-(l.y-n.y)*r;return Math.abs(h)/a};return u(t)<s&&u(e)<s}function _n(n,t,e=1e-6){return Math.abs(n.x-t.x)<e&&Math.abs(n.y-t.y)<e}function Ee(n){const t=[];for(const e of n)if(!(e.length<2)){t.push(`M${ie(e[0].x)} ${ie(e[0].y)}`);for(let o=1;o<e.length;o++){const s=e[o];t.push(`L${ie(s.x)} ${ie(s.y)}`)}t.push("Z")}return t.join(" ")}function ie(n){return Number.isInteger(n)?`${n}`:Number(n.toFixed(4)).toString()}function Ts(n,t){if(t<=0||n.length===0)return n;let e;try{e=K(n)}catch{return n}if(e.length===0)return n;let o=!1;for(const r of e){for(let i=0;i<r.anchors.length;i++){const a=r.anchors[i],u=rt(a.handleIn,a.point),l=rt(a.handleOut,a.point);if(a.kind==="cusp"&&u&&l&&(i>0&&i<r.anchors.length-1||r.closed)){o=!0;break}}if(o)break}if(!o)return n;const s=[];for(const r of e)r.anchors.length!==0&&s.push(As(r,t));return s.join(" ")}function As(n,t){const e=n.anchors,o=e.length;if(o===0)return"";const s=e.map((h,f)=>!rt(h.handleIn,h.point)||!rt(h.handleOut,h.point)||h.kind!=="cusp"?!1:n.closed?!0:f>0&&f<o-1),r=[],i=[],a=[];for(let h=0;h<o;h++){const f=e[h];if(!s[h]){r.push(f.point),i.push(f.point),a.push(0);continue}const d=e[(h-1+o)%o],p=e[(h+1)%o],y=jn(d.point,f.point),g=jn(f.point,p.point),I=Fn(Ln(d.point,f.point)),v=Fn(Ln(p.point,f.point)),b=Math.max(-1,Math.min(1,I.x*v.x+I.y*v.y)),P=Math.acos(b);if(P<=1e-4||P>=Math.PI-1e-4||y<1e-9||g<1e-9){r.push(f.point),i.push(f.point),a.push(0);continue}const M=Math.tan(P/2),C=Math.min(t/M,y/2,g/2);if(C<1e-9){r.push(f.point),i.push(f.point),a.push(0);continue}const N=C*M;r.push({x:f.point.x+C*I.x,y:f.point.y+C*I.y}),i.push({x:f.point.x+C*v.x,y:f.point.y+C*v.y}),a.push(N)}const u=[],l=n.closed?i[0]:e[0].point;u.push(`M${E(l.x)} ${E(l.y)}`);for(let h=1;h<o;h++){const f=e[h],d=e[h-1],p=!rt(d.handleOut,d.point),y=!rt(f.handleIn,f.point);if(p||y?u.push(` C${E(d.handleOut.x)} ${E(d.handleOut.y)} ${E(f.handleIn.x)} ${E(f.handleIn.y)} ${E(r[h].x)} ${E(r[h].y)}`):u.push(` L${E(r[h].x)} ${E(r[h].y)}`),a[h]>0){const g=a[h],I=e[(h-1+o)%o].point,v=e[(h+1)%o].point,b=Vn(I,f.point,v);u.push(` A${E(g)} ${E(g)} 0 0 ${b} ${E(i[h].x)} ${E(i[h].y)}`)}}if(n.closed){const h=e[o-1],f=e[0],d=!rt(h.handleOut,h.point),p=!rt(f.handleIn,f.point);if(d||p?u.push(` C${E(h.handleOut.x)} ${E(h.handleOut.y)} ${E(f.handleIn.x)} ${E(f.handleIn.y)} ${E(r[0].x)} ${E(r[0].y)}`):u.push(` L${E(r[0].x)} ${E(r[0].y)}`),a[0]>0){const y=a[0],g=e[o-1].point,I=e[1%o].point,v=Vn(g,f.point,I);u.push(` A${E(y)} ${E(y)} 0 0 ${v} ${E(i[0].x)} ${E(i[0].y)}`)}u.push(" Z")}return u.join("")}function rt(n,t){return Math.abs(n.x-t.x)<1e-6&&Math.abs(n.y-t.y)<1e-6}function Ln(n,t){return{x:n.x-t.x,y:n.y-t.y}}function jn(n,t){const e=n.x-t.x,o=n.y-t.y;return Math.sqrt(e*e+o*o)}function Fn(n){const t=Math.sqrt(n.x*n.x+n.y*n.y);return t<1e-9?{x:0,y:0}:{x:n.x/t,y:n.y/t}}function Vn(n,t,e){const o=t.x-n.x,s=t.y-n.y,r=e.x-t.x,i=e.y-t.y;return o*i-s*r>0?1:0}function E(n){const t=Math.round(n*1e4)/1e4;return String(t)}const _e=1e-6;function ae(n,t){return Math.abs(n.x-t.x)<_e&&Math.abs(n.y-t.y)<_e}function zn(n){const t=K(n);if(t.length===0)return n;const e=t.map(o=>({closed:o.closed,anchors:[...o.anchors].reverse().map(s=>({point:s.point,handleIn:s.handleOut,handleOut:s.handleIn,kind:s.kind}))}));return Z(e)}function Yn(n){const t=K(n);if(t.length===0)return n;const e=[];for(const o of t){const s=[];for(const r of o.anchors){const i=s[s.length-1];i!==void 0&&ae(i.point,r.point)&&ae(i.handleOut,i.point)&&ae(r.handleIn,r.point)||s.push(r)}s.length>=2&&e.push({anchors:s,closed:o.closed})}return Z(e)}function Gn(n,t){const e=K(n);if(e.length===0)return n;const o=e.map(s=>Bn(s,t));return Z(o)}function Bn(n,t){const e=n.anchors;if(e.length<3)return n;const o=new Array(e.length).fill(!1);return o[0]=!0,o[e.length-1]=!0,Le(e,0,e.length-1,Math.max(0,t),o),{anchors:e.filter((r,i)=>o[i]),closed:n.closed}}function Le(n,t,e,o,s){if(e-t<2)return;const r=n[t].point,i=n[e].point;let a=0,u=t;for(let l=t+1;l<e;l++){const h=Es(n[l].point,r,i);h>a&&(a=h,u=l)}a>o&&(s[u]=!0,Le(n,t,u,o,s),Le(n,u,e,o,s))}function Es(n,t,e){const o=e.x-t.x,s=e.y-t.y,r=o*o+s*s;if(r<_e)return Math.hypot(n.x-t.x,n.y-t.y);let i=((n.x-t.x)*o+(n.y-t.y)*s)/r;i=Math.max(0,Math.min(1,i));const a=t.x+o*i,u=t.y+s*i;return Math.hypot(n.x-a,n.y-u)}function je(n){const t=[],e=[];for(const i of n)for(const a of K(i))a.anchors.length!==0&&(a.closed?e.push(a):t.push([...a.anchors]));if(t.length===0)return null;if(t.length===1){const i={anchors:t[0],closed:!0};return Z([...e,i])}const o=t.slice();let s=o.shift();for(;o.length>0;){const i=s[s.length-1].point;let a=0,u=1/0,l=!1;for(let f=0;f<o.length;f++){const d=o[f],p=Un(i,d[0].point),y=Un(i,d[d.length-1].point);p<u&&(u=p,a=f,l=!1),y<u&&(u=y,a=f,l=!0)}let h=o.splice(a,1)[0];l&&(h=[...h].reverse().map(f=>({point:f.point,handleIn:f.handleOut,handleOut:f.handleIn,kind:f.kind}))),ae(s[s.length-1].point,h[0].point)&&(h=h.slice(1)),s=s.concat(h)}const r={anchors:s,closed:!1};return Z([...e,r])}function Un(n,t){const e=n.x-t.x,o=n.y-t.y;return e*e+o*o}function Xn(n,t){const e=K(n);if(e.length===0)return null;const o=new Map;for(const i of t){if(i.subpathIndex<0||i.subpathIndex>=e.length)continue;const a=o.get(i.subpathIndex)??new Set;a.add(i.anchorIndex),o.set(i.subpathIndex,a)}const s=[];let r=!1;for(let i=0;i<e.length;i++){const a=e[i],u=o.get(i);if(u===void 0||u.size===0){s.push(Z([a]));continue}const l=_s(a.anchors,a.closed,u);(l.length>1||a.closed&&l.length===1)&&(r=!0);for(const h of l)h.length>=2&&s.push(Z([{anchors:h,closed:!1}]))}return r?s:null}function _s(n,t,e){const o=n.length;if(o<2)return[n.slice()];let s,r;if(t){const u=[...e].filter(h=>h>=0&&h<o).sort((h,f)=>h-f);if(u.length===0)return[n.slice()];const l=u[0];s=[...n.slice(l),...n.slice(0,l),n[l]],r=u.slice(1).map(h=>(h-l+o)%o)}else s=n,r=[...e].filter(u=>u>0&&u<o-1).sort((u,l)=>u-l);if(r.length===0)return[s.slice()];const i=[];let a=0;for(const u of r)i.push(s.slice(a,u+1)),a=u;return i.push(s.slice(a)),i.filter(u=>u.length>=2)}const Ls=4;function Kn(n,t){const e=Math.hypot(n,t);return e<1e-9?{x:0,y:0}:{x:n/e,y:t/e}}function ue(n,t){const e=Kn(t.x-n.x,t.y-n.y);return{x:-e.y,y:e.x}}function Wn(n){let t=0;for(let e=0;e<n.length;e++){const o=n[e],s=n[(e+1)%n.length];t+=o.x*s.y-s.x*o.y}return t/2}function qn(n,t,e,o){const s=t??e,r=e??t,i=Kn(s.x+r.x,s.y+r.y);if(i.x===0&&i.y===0)return{x:n.x+s.x*o,y:n.y+s.y*o};const a=i.x*s.x+i.y*s.y,u=Math.min(Ls,1/Math.max(1e-4,Math.abs(a)));return{x:n.x+i.x*o*u,y:n.y+i.y*o*u}}function de(n,t){const e=n.length;if(e<2)return n.slice();const o=[];for(let s=0;s<e;s++){const r=s>0?ue(n[s-1],n[s]):null,i=s<e-1?ue(n[s],n[s+1]):null;o.push(qn(n[s],r,i,t))}return o}function ce(n,t){const e=n.length>1&&Math.abs(n[0].x-n[n.length-1].x)<1e-6&&Math.abs(n[0].y-n[n.length-1].y)<1e-6?n.slice(0,-1):n.slice(),o=e.length;if(o<3)return e;const s=u=>{const l=[];for(let h=0;h<o;h++){const f=e[(h-1+o)%o],d=e[h],p=e[(h+1)%o];l.push(qn(d,ue(f,d),ue(d,p),u))}return l},r=Math.abs(Wn(e)),i=s(1),a=Math.abs(Wn(i))>=r?1:-1;return s(a*t)}function js(n){if(n.length<3)return"";const t=[`M${it(n[0].x)} ${it(n[0].y)}`];for(let e=1;e<n.length;e++)t.push(`L${it(n[e].x)} ${it(n[e].y)}`);return t.push("Z"),t.join(" ")}function Fs(n){if(n.length<2)return"";const t=[`M${it(n[0].x)} ${it(n[0].y)}`];for(let e=1;e<n.length;e++)t.push(`L${it(n[e].x)} ${it(n[e].y)}`);return t.join(" ")}function it(n){const t=Math.round(n*1e4)/1e4;return Number.isInteger(t),String(t)}function Hn(n,t){if(!Number.isFinite(t)||Math.abs(t)<1e-6)return n;const e=K(n),o=Tt(n);if(e.length===0||o.length===0)return n;const s=[];for(let r=0;r<o.length;r++){const i=o[r];if(e[r]?.closed??!1){const u=ce(i,t),l=js(u);l.length>0&&s.push(l)}else{const u=de(i,t),l=Fs(u);l.length>0&&s.push(l)}}return s.length>0?s.join(" "):n}function Zn(n,t){if(!Number.isFinite(t)||t<=0)return"";const e=t/2,o=K(n),s=Tt(n);if(o.length===0||s.length===0)return"";const r=[];for(let i=0;i<s.length;i++){const a=s[i];if(a.length<2)continue;if(o[i]?.closed??!1){const l=ce(a,e),h=ce(a,-e),f=Fe(l),d=Fe([...h].reverse());f.length>0&&r.push(f),d.length>0&&r.push(d)}else{const l=de(a,e),h=de(a,-e),f=[...l,...h.slice().reverse()],d=Fe(f);d.length>0&&r.push(d)}}return r.join(" ")}function Fe(n){if(n.length<3)return"";const t=[`M${le(n[0].x)} ${le(n[0].y)}`];for(let e=1;e<n.length;e++)t.push(`L${le(n[e].x)} ${le(n[e].y)}`);return t.push("Z"),t.join(" ")}function le(n){const t=Math.round(n*1e4)/1e4;return Number.isInteger(t),String(t)}const Qn={kind:"linear"},Vs={easeIn:[.42,0,1,1],easeOut:[0,0,.58,1],easeInOut:[.42,0,.58,1]};function Ve(n){switch(n.kind){case"linear":return null;case"cubicBezier":return[n.x1,n.y1,n.x2,n.y2];default:return Vs[n.kind]}}function ze(n,t,e,o){return((n*o+t)*o+e)*o}function zs(n,t,e,o){return(3*n*o+2*t)*o+e}function Ys(n,t,e,o){let s=n;for(let a=0;a<8;a++){const u=ze(t,e,o,s)-n;if(Math.abs(u)<1e-6)return s;const l=zs(t,e,o,s);if(Math.abs(l)<1e-6)break;s-=u/l}let r=0,i=1;for(s=n;r<i;){const a=ze(t,e,o,s);if(Math.abs(a-n)<1e-6)return s;n>a?r=s:i=s,s=(i-r)*.5+r}return s}function Jn(n,t){const e=t<=0?0:t>=1?1:t,o=Ve(n);if(o===null)return e;const[s,r,i,a]=o,u=3*s,l=3*(i-s)-u,h=1-u-l,f=3*r,d=3*(a-r)-f,p=1-f-d,y=Ys(e,h,l,u);return ze(p,d,f,y)}const Ye="svgeAnimation";function to(n=1e3){return{durationMs:n,tracks:[]}}function eo(n){const t=n?.metadata.customData?.[Ye];return no(t)?t:null}function no(n){return typeof n=="object"&&n!==null&&typeof n.durationMs=="number"&&Array.isArray(n.tracks)}function At(n,t,e){return n.tracks.find(o=>o.nodeId===t&&o.property===e)??null}const Et=1e-6;function Ge(n,t,e,o){const s={...o,easing:o.easing??Qn},r=At(n,t,e);if(r===null){const l={nodeId:t,property:e,keyframes:[s]};return{...n,tracks:[...n.tracks,l]}}const a=[...r.keyframes.filter(l=>Math.abs(l.time-s.time)>Et),s].sort((l,h)=>l.time-h.time),u=n.tracks.map(l=>l===r?{...l,keyframes:a}:l);return{...n,tracks:u}}function Be(n,t,e,o){const s=At(n,t,e);if(s===null)return n;const r=s.keyframes.filter(a=>Math.abs(a.time-o)>Et);if(r.length===s.keyframes.length)return n;const i=r.length===0?n.tracks.filter(a=>a!==s):n.tracks.map(a=>a===s?{...a,keyframes:r}:a);return{...n,tracks:i}}function oo(n,t,e){const o=n.tracks.filter(s=>!(s.nodeId===t&&s.property===e));return o.length===n.tracks.length?n:{...n,tracks:o}}function so(n,t,e,o,s,r){const i=At(n,t,e);if(i===null)return n;const a=i.keyframes.find(h=>Math.abs(h.time-o)<=Et);if(a===void 0)return n;const u=r??a.value;if(Math.abs(s-o)<=Et&&u===a.value)return n;const l=Be(n,t,e,o);return Ge(l,t,e,{time:s,value:u,easing:a.easing})}function ro(n,t,e,o,s){const r=At(n,t,e);if(r===null)return n;let i=!1;const a=r.keyframes.map(l=>Math.abs(l.time-o)<=Et?(i=!0,{...l,easing:s}):l);if(!i)return n;const u=n.tracks.map(l=>l===r?{...l,keyframes:a}:l);return{...n,tracks:u}}function io(n,t){const e=t<0?0:t;return e===n.durationMs?n:{...n,durationMs:e}}function ao(n,t,e){if(typeof n=="number"&&typeof t=="number")return n+(t-n)*e;if(typeof n=="string"&&typeof t=="string"){const o=uo(n,t,e);if(o!==null)return o}return e>=1?t:n}function Ue(n){const t=n.trim();if(t.startsWith("#"))return Gs(t);const e=/^rgba?\(\s*([^)]+)\)$/i.exec(t);if(e){const o=e[1].split(/[\s,/]+/).filter(u=>u.length>0);if(o.length<3)return null;const s=Xe(Number(o[0])),r=Xe(Number(o[1])),i=Xe(Number(o[2])),a=o[3]===void 0?1:Bs(Number(o[3]));return[s,r,i,a].some(u=>Number.isNaN(u))?null:{r:s,g:r,b:i,a}}return null}function Gs(n){let t=n.slice(1);if((t.length===3||t.length===4)&&(t=t.split("").map(i=>i+i).join("")),t.length!==6&&t.length!==8)return null;const e=parseInt(t.slice(0,2),16),o=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16),r=t.length===8?parseInt(t.slice(6,8),16)/255:1;return[e,o,s].some(i=>Number.isNaN(i))?null:{r:e,g:o,b:s,a:r}}function uo(n,t,e){const o=Ue(n),s=Ue(t);if(o===null||s===null)return null;const r=Math.round(o.r+(s.r-o.r)*e),i=Math.round(o.g+(s.g-o.g)*e),a=Math.round(o.b+(s.b-o.b)*e),u=o.a+(s.a-o.a)*e;return u>=1?`rgb(${r}, ${i}, ${a})`:`rgba(${r}, ${i}, ${a}, ${Math.round(u*1e3)/1e3})`}function Xe(n){return Math.max(0,Math.min(255,Math.round(n)))}function Bs(n){return Math.max(0,Math.min(1,n))}function he(n,t){const e=n.keyframes;if(e.length===0)return null;const o=e[0],s=e[e.length-1];if(t<=o.time)return o.value;if(t>=s.time)return s.value;for(let r=1;r<e.length;r++){const i=e[r];if(t<=i.time){const a=e[r-1],u=i.time-a.time,l=u<=0?0:(t-a.time)/u,h=Jn(a.easing,l);return ao(a.value,i.value,h)}}return s.value}function Us(n,t){const e=new Map;for(const o of n.tracks){const s=he(o,t);if(s===null)continue;let r=e.get(o.nodeId);r===void 0&&(r=new Map,e.set(o.nodeId,r)),r.set(o.property,s)}return e}const fe=new Set(["translateX","translateY","rotation","scaleX","scaleY"]),pe=new Set(["opacity","fillOpacity","strokeOpacity","strokeWidth","fill","stroke"]),Xs=[{property:"translateX",label:"Translate X",kind:"number",group:"transform",defaultValue:0},{property:"translateY",label:"Translate Y",kind:"number",group:"transform",defaultValue:0},{property:"rotation",label:"Rotation",kind:"angle",group:"transform",defaultValue:0},{property:"scaleX",label:"Scale X",kind:"scale",group:"transform",defaultValue:1},{property:"scaleY",label:"Scale Y",kind:"scale",group:"transform",defaultValue:1}],Ks=[{property:"opacity",label:"Opacity",kind:"number",group:"style",defaultValue:1},{property:"fill",label:"Fill",kind:"color",group:"style",defaultValue:"#000000"},{property:"stroke",label:"Stroke",kind:"color",group:"style",defaultValue:"#000000"},{property:"strokeWidth",label:"Stroke width",kind:"number",group:"style",defaultValue:1},{property:"fillOpacity",label:"Fill opacity",kind:"number",group:"style",defaultValue:1},{property:"strokeOpacity",label:"Stroke opacity",kind:"number",group:"style",defaultValue:1}];function U(n,t){return{property:n,label:t,kind:"number",group:"geometry",defaultValue:0}}const Ws=[U("x","X"),U("y","Y"),U("width","Width"),U("height","Height")],qs=[U("cx","Center X"),U("cy","Center Y"),U("rx","Radius X"),U("ry","Radius Y")],Hs=[U("x1","X1"),U("y1","Y1"),U("x2","X2"),U("y2","Y2")],Zs=[U("x","X"),U("y","Y")];function Qs(n){switch(n.type){case"rect":case"image":return Ws;case"ellipse":return qs;case"line":return Hs;case"text":case"symbol-use":return Zs;default:return[]}}function co(n){return[...Qs(n),...Xs,...Ks]}function Js(n,t){return co(n).find(e=>e.property===t)??null}function tr(n,t){if(fe.has(t)){const o=oe(n.transform);switch(t){case"translateX":return o.tx;case"translateY":return o.ty;case"rotation":return o.rotationRad*180/Math.PI;case"scaleX":return o.scaleX;case"scaleY":return o.scaleY;default:return null}}if(pe.has(t)){const o=n.style[t];return typeof o=="number"||typeof o=="string"?o:null}const e=n[t];return typeof e=="number"?e:null}function er(n,t){return t.size===0?n:lo(n,t)}function lo(n,t){let e=n;const o=t.get(n.id);if(o!==void 0&&o.size>0&&(e=nr(n,o)),B(e)){let s=!1;const r=e.children.map(i=>{const a=lo(i,t);return a!==i&&(s=!0),a});s&&(e={...e,children:r})}return e}function nr(n,t){const e={},o={},s=new Map;let r=!1,i=!1,a=!1;for(const[l,h]of t)fe.has(l)?(s.set(l,sr(h)),a=!0):pe.has(l)?(o[l]=h,i=!0):(e[l]=h,r=!0);let u=n;return r&&(u={...u,...e}),i&&(u={...u,style:{...u.style,...o}}),a&&(u=or(u,s)),u}function or(n,t){const e=oe(n.transform),o={tx:t.has("translateX")?t.get("translateX"):e.tx,ty:t.has("translateY")?t.get("translateY"):e.ty,rotationRad:t.has("rotation")?t.get("rotation")*Math.PI/180:e.rotationRad,scaleX:t.has("scaleX")?t.get("scaleX"):e.scaleX,scaleY:t.has("scaleY")?t.get("scaleY"):e.scaleY};return{...n,transform:An(o)}}function sr(n){const t=typeof n=="number"?n:Number(n);return Number.isFinite(t)?t:0}const rr={opacity:"opacity",fill:"fill",stroke:"stroke",fillOpacity:"fill-opacity",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width"};function ir(n){return pe.has(n)?rr[n]??n:n}function V(n){if(!Number.isFinite(n))return"0";const t=Math.round(n*1e6)/1e6;return String(Object.is(t,-0)?0:t)}function _t(n){const t=typeof n=="number"?n:Number(n);return Number.isFinite(t)?t:0}function ar(n){return typeof n=="number"?V(n):n}function ur(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function dr(n){const t=Ve(n);return t===null?"0 0 1 1":`${V(t[0])} ${V(t[1])} ${V(t[2])} ${V(t[3])}`}function ho(n,t,e){return n<t?t:n>e?e:n}const fo={kind:"linear"};function Ke(n,t){if(n.length===0)return[];const e=n.map(s=>({t:ho(s.time,0,t),value:s.value,easing:s.easing}));e[0].t>0&&e.unshift({t:0,value:e[0].value,easing:fo});const o=e[e.length-1];return o.t<t&&e.push({t,value:o.value,easing:fo}),e}function gt(n,t,e,o,s,r){const i=[...t,`dur="${V(e/1e3)}s"`,'repeatCount="indefinite"',...n==="animateTransform"?['additive="sum"']:[],`keyTimes="${o}"`,`values="${ur(s)}"`];return r!==null&&i.push('calcMode="spline"',`keySplines="${r.join(";")}"`),`<${n} ${i.join(" ")} />`}function We(n){const t=n.slice(0,n.length-1).map(e=>dr(e.easing));return t.every(e=>e==="0 0 1 1")?null:t}function cr(n,t,e){if(t.keyframes.length===0)return null;const o=Ke(t.keyframes,e);if(o.length<2)return null;const s=o.map(i=>V(i.t/e)).join(";"),r=o.map(i=>ar(i.value)).join(";");return gt("animate",[`attributeName="${n}"`],e,s,r,We(o))}function lr(n,t){const e=new Set([0,t]);for(const o of n)for(const s of o.keyframes)e.add(ho(s.time,0,t));return[...e].sort((o,s)=>o-s)}function hr(n,t,e){const o=['attributeName="transform"','type="rotate"'];if(n===null){if(t===0)return null;const a=V(t);return gt("animateTransform",o,e,"0;1",`${a};${a}`,null)}const s=Ke(n.keyframes,e);if(s.length<2)return null;const r=s.map(a=>V(a.t/e)).join(";"),i=s.map(a=>V(_t(a.value))).join(";");return gt("animateTransform",o,e,r,i,We(s))}function po(n,t,e,o,s,r,i){const a=['attributeName="transform"',`type="${n}"`];if(t===null&&e===null){if(o===r&&s===r)return null;const f=`${V(o)},${V(s)}`;return gt("animateTransform",a,i,"0;1",`${f};${f}`,null)}if(t===null||e===null){const f=t??e,d=t!==null,p=Ke(f.keyframes,i);if(p.length>=2){const y=p.map(I=>V(I.t/i)).join(";"),g=p.map(I=>{const v=d?_t(I.value):o,b=d?s:_t(I.value);return`${V(v)},${V(b)}`}).join(";");return gt("animateTransform",a,i,y,g,We(p))}}const u=lr([t,e].filter(f=>f!==null),i),l=u.map(f=>V(f/i)).join(";"),h=u.map(f=>{const d=t!==null?_t(he(t,f)??o):o,p=e!==null?_t(he(e,f)??s):s;return`${V(d)},${V(p)}`}).join(";");return gt("animateTransform",a,i,l,h,null)}function fr(n,t,e){if(n.size===0)return[];const o=e!==void 0?oe(e):{tx:0,ty:0,rotationRad:0,scaleX:1,scaleY:1},s=[],r=po("translate",n.get("translateX")??null,n.get("translateY")??null,o.tx,o.ty,0,t);r!==null&&s.push(r);const i=hr(n.get("rotation")??null,o.rotationRad*180/Math.PI,t);i!==null&&s.push(i);const a=po("scale",n.get("scaleX")??null,n.get("scaleY")??null,o.scaleX,o.scaleY,1,t);return a!==null&&s.push(a),s}function pr(n,t,e){if(n.durationMs<=0)return[];const o=n.durationMs,s=[],r=new Map;for(const a of n.tracks){if(a.nodeId!==t)continue;if(fe.has(a.property)){r.set(a.property,a);continue}const u=ir(a.property),l=cr(u,a,o);l!==null&&s.push({name:u,el:l})}return[...s.sort((a,u)=>a.name.localeCompare(u.name)).map(a=>a.el),...fr(r,o,e)]}function $(n,t){if(n.id===t)return n;for(const e of n.children){if(e.id===t)return e;if(B(e)){const o=$(e,t);if(o!==null)return o}}return null}function T(n,t){for(const e of n.children){if(e.id===t)return n;if(B(e)){const o=T(e,t);if(o!==null)return o}}return null}function w(n,t,e,o){if($(n,e.id)!==null)throw new Error(`insertNode: node id "${e.id}" already exists in tree`);return me(n,r=>{if(r.id!==t)return null;const i=mr(o??r.children.length,r.children.length),a=[...r.children.slice(0,i),e,...r.children.slice(i)];return{...r,children:a}})}function D(n,t){return n.id===t?n:me(n,e=>{const o=e.children.findIndex(r=>r.id===t);if(o<0)return null;const s=[...e.children.slice(0,o),...e.children.slice(o+1)];return{...e,children:s}})}function R(n,t,e){if(n.id===t){const o=e(n);return o===n?n:o}return me(n,o=>{const s=o.children.findIndex(u=>u.id===t);if(s<0)return null;const r=o.children[s];if(!r)return null;const i=e(r);if(i===r)return null;if(i.id!==r.id)throw new Error(`updateNode: updater changed id (${r.id} -> ${i.id})`);if(i.type!==r.type)throw new Error(`updateNode: updater changed type (${r.type} -> ${i.type}); use a remove+insert pair instead`);const a=[...o.children.slice(0,s),i,...o.children.slice(s+1)];return{...o,children:a}})}function me(n,t){let e=!1;const o=n.children.map(i=>{if(!B(i))return i;const a=me(i,t);return a!==i&&(e=!0),a}),s=e?{...n,children:o}:n;return t(s)??s}function mr(n,t){return Number.isFinite(n)?Math.max(0,Math.min(Math.trunc(n),t)):t}function qe(n,t){mo(n,t)}function mo(n,t){if(t(n)===!1)return!1;if(B(n)){for(const e of n.children)if(mo(e,t)===!1)return!1}return!0}function yo(n){const t=[];return qe(n,e=>{t.push(e)}),t}function go(n,t={}){let o=t.includeRoot??!0?0:-1;return qe(n,()=>{o+=1}),o}function He(n){return B(n)?{...n,id:x(),children:n.children.map(t=>He(t))}:{...n,id:x()}}const Io=Gt(0,0,800,600);function Ze(n={}){return{id:n.id??x(),viewBox:n.viewBox??Io,width:n.width,height:n.height,root:et([],{metadata:{name:"root"}})}}const m=()=>({ok:!0});function c(n){return{ok:!1,error:n}}const xo=new Go("svge.commands.InsertParentResolver");function ye(n,t,e){const o=n.state.document(),s=$(o.root,t);if(s===null||s.type!=="path")return null;const r=s,i=K(r.d).map(l=>({anchors:[...l.anchors],closed:l.closed}));if(!e(i))return null;const u=Z(i);return u===r.d?null:{prevD:r.d,nextD:u}}function at(n,t,e){const o=n.state.document(),s=R(o.root,t,r=>r.type!=="path"?r:{...r,d:e});return s===o.root?c(`anchor command: failed to update node "${t}"`):(n.state.setDocument({...o,root:s}),m())}class yr{ref;newPosition;which;id=x();label="Move anchor";previous=null;constructor(t,e,o="point"){this.ref=t,this.newPosition=e,this.which=o}execute(t){const e=ye(t,this.ref.nodeId,o=>{const s=o[this.ref.subpathIndex];if(s===void 0)return!1;const r=s.anchors[this.ref.anchorIndex];return r===void 0?!1:(s.anchors[this.ref.anchorIndex]=gr(r,this.newPosition,this.which),!0)});return e===null?c("MoveAnchorCommand: target not found or mutation rejected"):(this.previous={d:e.prevD},at(t,this.ref.nodeId,e.nextD))}undo(t){return this.previous===null?c("MoveAnchorCommand undo: nothing captured"):at(t,this.ref.nodeId,this.previous.d)}}function gr(n,t,e){if(e==="point"){const u=t.x-n.point.x,l=t.y-n.point.y;return{...n,point:t,handleIn:{x:n.handleIn.x+u,y:n.handleIn.y+l},handleOut:{x:n.handleOut.x+u,y:n.handleOut.y+l}}}if(e==="handleIn"){if(n.kind==="cusp")return{...n,handleIn:t};const u=t.x-n.point.x,l=t.y-n.point.y,h=Math.hypot(u,l);let f=-u,d=-l;if(n.kind==="smooth"&&h>1e-6){const y=Math.hypot(n.handleOut.x-n.point.x,n.handleOut.y-n.point.y)/h;f=-u*y,d=-l*y}return{...n,handleIn:t,handleOut:{x:n.point.x+f,y:n.point.y+d}}}if(n.kind==="cusp")return{...n,handleOut:t};const o=t.x-n.point.x,s=t.y-n.point.y,r=Math.hypot(o,s);let i=-o,a=-s;if(n.kind==="smooth"&&r>1e-6){const l=Math.hypot(n.handleIn.x-n.point.x,n.handleIn.y-n.point.y)/r;i=-o*l,a=-s*l}return{...n,handleOut:t,handleIn:{x:n.point.x+i,y:n.point.y+a}}}class Ir{ref;t;id=x();label="Insert anchor";previous=null;constructor(t,e){this.ref=t,this.t=e}execute(t){if(!Number.isFinite(this.t)||this.t<=0||this.t>=1)return c(`InsertAnchorCommand: t must be in (0, 1), got ${this.t}`);const e=ye(t,this.ref.nodeId,o=>{const s=o[this.ref.subpathIndex];if(s===void 0)return!1;const r=this.ref.anchorIndex,i=s.closed&&r===s.anchors.length-1?0:r+1,a=s.anchors[r],u=s.anchors[i];if(a===void 0||u===void 0)return!1;const[l,h,f]=xr(a,u,this.t);return s.anchors[r]=l,i===0?(s.anchors.push(h),s.anchors[0]=f):(s.anchors.splice(i,0,h),s.anchors[i+1]=f),!0});return e===null?c("InsertAnchorCommand: target not found"):(this.previous={d:e.prevD},at(t,this.ref.nodeId,e.nextD))}undo(t){return this.previous===null?c("InsertAnchorCommand undo: nothing captured"):at(t,this.ref.nodeId,this.previous.d)}}function xr(n,t,e){const o=n.point,s=n.handleOut,r=t.handleIn,i=t.point,a=(y,g)=>({x:y.x+(g.x-y.x)*e,y:y.y+(g.y-y.y)*e}),u=a(o,s),l=a(s,r),h=a(r,i),f=a(u,l),d=a(l,h),p=a(f,d);return[{...n,handleOut:u},{point:p,handleIn:f,handleOut:d,kind:"smooth"},{...t,handleIn:h}]}class br{ref;id=x();label="Remove anchor";previous=null;constructor(t){this.ref=t}execute(t){const e=ye(t,this.ref.nodeId,o=>{const s=o[this.ref.subpathIndex];return s===void 0||this.ref.anchorIndex<0||this.ref.anchorIndex>=s.anchors.length?!1:(s.anchors.splice(this.ref.anchorIndex,1),s.anchors.length<2&&o.splice(this.ref.subpathIndex,1),!0)});return e===null?c("RemoveAnchorCommand: target not found"):(this.previous={d:e.prevD},at(t,this.ref.nodeId,e.nextD))}undo(t){return this.previous===null?c("RemoveAnchorCommand undo: nothing captured"):at(t,this.ref.nodeId,this.previous.d)}}class $r{ref;nextKind;id=x();label="Convert anchor type";previous=null;constructor(t,e){this.ref=t,this.nextKind=e}execute(t){const e=this.nextKind,o=this.ref,s=ye(t,this.ref.nodeId,r=>{const i=r[o.subpathIndex];if(i===void 0)return!1;const a=i.anchors[o.anchorIndex];if(a===void 0)return!1;const u=i.anchors.length,l=o.anchorIndex>0?i.anchors[o.anchorIndex-1]:i.closed?i.anchors[u-1]:void 0,h=o.anchorIndex<u-1?i.anchors[o.anchorIndex+1]:i.closed?i.anchors[0]:void 0;return i.anchors[o.anchorIndex]=Rr(a,e,l,h),!0});return s===null?c("ConvertAnchorTypeCommand: target not found"):(this.previous={d:s.prevD},at(t,this.ref.nodeId,s.nextD))}undo(t){return this.previous===null?c("ConvertAnchorTypeCommand undo: nothing captured"):at(t,this.ref.nodeId,this.previous.d)}}const vr=.4,Cr=.3,Qe=1/3;function Rr(n,t,e,o){const s=n.handleIn.x-n.point.x,r=n.handleIn.y-n.point.y,i=n.handleOut.x-n.point.x,a=n.handleOut.y-n.point.y,u=Math.hypot(s,r),l=Math.hypot(i,a);if(t==="cusp")return{...n,kind:t,handleIn:n.point,handleOut:n.point};if(u<1e-6&&l<1e-6){const d=Sr(n,e,o,t);return d===null?{...n,kind:t}:{...n,kind:t,handleIn:d.handleIn,handleOut:d.handleOut}}if(u<1e-6){const p=(t==="symmetric"?l:Qe*ge(n,e))/l;return{...n,kind:t,handleIn:{x:n.point.x-i*p,y:n.point.y-a*p}}}const f=(t==="symmetric"?u:l>1e-6?l:Qe*ge(n,o))/u;return{...n,kind:t,handleOut:{x:n.point.x-s*f,y:n.point.y-r*f}}}function ge(n,t){return t===void 0?0:Math.hypot(t.point.x-n.point.x,t.point.y-n.point.y)}function Sr(n,t,e,o){if(t===void 0&&e===void 0)return null;let s,r;t!==void 0&&e!==void 0?(s=e.point.x-t.point.x,r=e.point.y-t.point.y):e!==void 0?(s=e.point.x-n.point.x,r=e.point.y-n.point.y):(s=n.point.x-t.point.x,r=n.point.y-t.point.y);const i=Math.hypot(s,r);if(i<1e-6)return null;const a=s/i,u=r/i,l=ge(n,t),h=ge(n,e);if(o==="symmetric"){const y=(l>0&&h>0?Math.min(l,h):Math.max(l,h))*Qe;return{handleIn:{x:n.point.x-a*y,y:n.point.y-u*y},handleOut:{x:n.point.x+a*y,y:n.point.y+u*y}}}const f=(l>0?l:h)*vr,d=(h>0?h:l)*Cr;return{handleIn:{x:n.point.x-a*f,y:n.point.y-u*f},handleOut:{x:n.point.x+a*d,y:n.point.y+u*d}}}class bo{nodeId;id=x();label="Convert to path";previousNode=null;previousParentId=null;previousIndex=-1;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`ConvertNodeToPathCommand: node "${this.nodeId}" not found`);if(o.type==="path"||o.type==="group"||o.type==="text"||o.type==="image")return c(`ConvertNodeToPathCommand: type "${o.type}" not convertible to path`);const s=T(e.root,this.nodeId);if(s===null)return c(`ConvertNodeToPathCommand: node "${this.nodeId}" has no parent (root?)`);const r=s.children.findIndex(f=>f.id===this.nodeId);if(r<0)return c(`ConvertNodeToPathCommand: index lookup failed for "${this.nodeId}"`);const i=It(o);if(i===null)return c(`ConvertNodeToPathCommand: failed to compute "d" for type "${o.type}"`);this.previousNode=o,this.previousParentId=s.id,this.previousIndex=r;const u={...tt(i),id:o.id,transform:o.transform,style:o.style,metadata:o.metadata},l=D(e.root,this.nodeId);if(l===e.root)return c(`ConvertNodeToPathCommand: remove failed for "${this.nodeId}"`);const h=w(l,s.id,u,r);return h===l?c(`ConvertNodeToPathCommand: insert failed for "${this.nodeId}"`):(t.state.setDocument({...e,root:h}),m())}undo(t){if(this.previousNode===null||this.previousParentId===null||this.previousIndex<0)return c("ConvertNodeToPathCommand undo: nothing captured");const e=t.state.document(),o=D(e.root,this.nodeId);if(o===e.root)return c(`ConvertNodeToPathCommand undo: remove failed for "${this.nodeId}"`);const s=w(o,this.previousParentId,this.previousNode,this.previousIndex);return s===o?c(`ConvertNodeToPathCommand undo: insert failed for "${this.nodeId}"`):(t.state.setDocument({...e,root:s}),m())}}function It(n){switch(n.type){case"rect":{const{x:t,y:e,width:o,height:s}=n,r=t+o,i=e+s;return`M${k(t)} ${k(e)} L${k(r)} ${k(e)} L${k(r)} ${k(i)} L${k(t)} ${k(i)} Z`}case"ellipse":{const{cx:t,cy:e,rx:o,ry:s}=n,r=.5522847498307933,i=o*r,a=s*r,u=t-o,l=t+o,h=e-s,f=e+s;return`M${k(u)} ${k(e)} C${k(u)} ${k(e-a)} ${k(t-i)} ${k(h)} ${k(t)} ${k(h)} C${k(t+i)} ${k(h)} ${k(l)} ${k(e-a)} ${k(l)} ${k(e)} C${k(l)} ${k(e+a)} ${k(t+i)} ${k(f)} ${k(t)} ${k(f)} C${k(t-i)} ${k(f)} ${k(u)} ${k(e+a)} ${k(u)} ${k(e)} Z`}case"line":{const{x1:t,y1:e,x2:o,y2:s}=n;return`M${k(t)} ${k(e)} L${k(o)} ${k(s)}`}case"polygon":case"polyline":{const t=n.points;if(t.length===0)return null;const e=[`M${k(t[0].x)} ${k(t[0].y)}`];for(let o=1;o<t.length;o++)e.push(`L${k(t[o].x)} ${k(t[o].y)}`);return n.type==="polygon"&&e.push("Z"),e.join(" ")}default:return null}}function k(n){return Number.isInteger(n)?`${n}`:Number(n.toFixed(4)).toString()}class kr{nodeIds;id=x();label;isDestructive=!0;subCommands;constructor(t){this.nodeIds=t,this.subCommands=t.map(e=>new bo(e)),this.label=t.length===1?"Convert to path":`Convert ${t.length} nodes to path`}execute(t){if(this.nodeIds.length===0)return m();const e=t.state.document();for(const o of this.nodeIds)if($(e.root,o)===null)return c(`BatchConvertToPathCommand: node "${o}" not found`);for(const o of this.subCommands){const s=o.execute(t);if(!s.ok)return s}return m()}undo(t){for(let e=this.subCommands.length-1;e>=0;e--){const o=this.subCommands[e].undo(t);if(!o.ok)return o}return m()}}class Dr{nodeId;image;id=x();label="Rasterize";isDestructive=!0;previousNode=null;previousParentId=null;previousIndex=-1;constructor(t,e){this.nodeId=t,this.image=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`RasterizeNodeCommand: node "${this.nodeId}" not found`);const s=T(e.root,this.nodeId);if(s===null)return c(`RasterizeNodeCommand: node "${this.nodeId}" has no parent (root?)`);const r=s.children.findIndex(l=>l.id===this.nodeId);if(r<0)return c(`RasterizeNodeCommand: index lookup failed for "${this.nodeId}"`);this.previousNode=o,this.previousParentId=s.id,this.previousIndex=r;const i={...this.image,id:o.id},a=D(e.root,this.nodeId);if(a===e.root)return c(`RasterizeNodeCommand: remove failed for "${this.nodeId}"`);const u=w(a,s.id,i,r);return u===a?c(`RasterizeNodeCommand: insert failed for "${this.nodeId}"`):(t.state.setDocument({...e,root:u}),m())}undo(t){if(this.previousNode===null||this.previousParentId===null||this.previousIndex<0)return c("RasterizeNodeCommand undo: nothing captured");const e=t.state.document(),o=D(e.root,this.nodeId);if(o===e.root)return c(`RasterizeNodeCommand undo: remove failed for "${this.nodeId}"`);const s=w(o,this.previousParentId,this.previousNode,this.previousIndex);return s===o?c(`RasterizeNodeCommand undo: insert failed for "${this.nodeId}"`):(t.state.setDocument({...e,root:s}),m())}}function $o(n,t){const e=n??"";return e.length===0?t:`${e}
2
+ ${t}`}function wr(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function vo(n){return new RegExp(`<(clipPath|mask)\\b[^>]*\\bid=(["'])${wr(n)}\\2[^>]*>[\\s\\S]*?</\\1>`,"i")}function Co(n,t){return n===void 0||n.length===0?"":n.replace(vo(t),"").replace(/\n{2,}/g,`
3
+ `).trim()}function Nr(n,t){if(n===void 0||n.length===0)return null;const e=vo(t).exec(n);return e===null?null:e[0]}function Ro(n){if(n===void 0)return null;const t=/^url\(\s*['"]?#([^'"\s)]+)['"]?\s*\)$/.exec(n.trim());return t===null?null:t[1]}function So(n,t,e){return{...n,style:{...n.style,[t]:e}}}class Mr{targetIds;clipperId;defId;defMarkup;kind;id;label;isDestructive=!0;before=null;constructor(t,e,o,s,r){this.targetIds=t,this.clipperId=e,this.defId=o,this.defMarkup=s,this.kind=r,this.id=o,this.label=r==="clipPath"?"Make clipping path":"Make opacity mask"}execute(t){const e=t.state.document();if(this.targetIds.length===0)return c("MakeClipMaskCommand: no target nodes");if($(e.root,this.clipperId)===null)return c(`MakeClipMaskCommand: clipper "${this.clipperId}" not found`);for(const r of this.targetIds)if($(e.root,r)===null)return c(`MakeClipMaskCommand: target "${r}" not found`);this.before=e;let o=D(e.root,this.clipperId);const s=`url(#${this.defId})`;for(const r of this.targetIds)o=R(o,r,i=>So(i,this.kind,s));return t.state.setDocument({...e,root:o,defs:$o(e.defs,this.defMarkup)}),m()}undo(t){return this.before===null?c("MakeClipMaskCommand: nothing to undo"):(t.state.setDocument(this.before),m())}}class Pr{nodeId;kind;restoredNode;id;label;isDestructive=!0;before=null;constructor(t,e,o){this.nodeId=t,this.kind=e,this.restoredNode=o,this.id=`release-${t}`,this.label=e==="clipPath"?"Release clipping path":"Release mask"}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`ReleaseClipMaskCommand: node "${this.nodeId}" not found`);const s=Ro(o.style[this.kind]);if(s===null)return c(`ReleaseClipMaskCommand: node has no ${this.kind} reference`);this.before=e;let r=R(e.root,this.nodeId,i=>So(i,this.kind,void 0));if(this.restoredNode!==null&&$(r,this.restoredNode.id)===null){const i=T(r,this.nodeId);r=w(r,i?.id??r.id,this.restoredNode)}return t.state.setDocument({...e,root:r,defs:Co(e.defs,s)}),m()}undo(t){return this.before===null?c("ReleaseClipMaskCommand: nothing to undo"):(t.state.setDocument(this.before),m())}}class Or{nodeIds;id=x();label="Make Compound Path";isDestructive=!0;previousRootSnapshot=null;constructor(t){this.nodeIds=t}execute(t){if(this.nodeIds.length<2)return c(`${this.label}: need at least 2 nodes (got ${this.nodeIds.length})`);const e=t.state.document();this.previousRootSnapshot=e.root;const o=[];for(const d of this.nodeIds){const p=$(e.root,d);if(p===null)return c(`${this.label}: node "${d}" not found`);if(p.type==="group"||p.type==="text"||p.type==="image")return c(`${this.label}: type "${p.type}" not supported`);o.push(p)}const s=[];for(const d of o){const p=d.type==="path"?d.d:It(d);if(p===null)return c(`${this.label}: cannot compute "d" for type "${d.type}"`);const y=Je(p,d.transform);s.push(y.trim())}const r=s.join(" "),i=o[0],a=T(e.root,i.id);if(a===null)return c(`${this.label}: operand A has no parent`);const u=a.children.findIndex(d=>d.id===i.id);if(u<0)return c(`${this.label}: operand A index lookup failed`);const h={...tt(r),id:i.id,transform:[1,0,0,1,0,0],style:i.style,metadata:i.metadata};let f=D(e.root,i.id);f=w(f,a.id,h,u);for(let d=1;d<o.length;d++)f=D(f,o[d].id);return t.state.setDocument({...e,root:f}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Tr{nodeId;id=x();label="Release Compound Path";previousRootSnapshot=null;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(o.type!=="path")return c(`${this.label}: only paths can be released`);const s=ko(o.d);if(s.length<2)return c(`${this.label}: path has only ${s.length} subpath(s) \u2014 nothing to release`);this.previousRootSnapshot=e.root;const r=T(e.root,this.nodeId);if(r===null)return c(`${this.label}: node has no parent`);const i=r.children.findIndex(l=>l.id===this.nodeId);if(i<0)return c(`${this.label}: index lookup failed`);const a=s.map((l,h)=>{const f=tt(l);return{...f,id:h===0?o.id:f.id,transform:o.transform,style:o.style,metadata:o.metadata}});let u=D(e.root,this.nodeId);for(let l=0;l<a.length;l++)u=w(u,r.id,a[l],i+l);return t.state.setDocument({...e,root:u}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}function ko(n){if(n.length===0)return[];const t=n.match(/[Mm][^Mm]*/g);return t===null?[]:t.map(e=>e.trim()).filter(e=>e.length>0)}function Je(n,t){const[e,o,s,r,i,a]=t;if(e===1&&o===0&&s===0&&r===1&&i===0&&a===0)return n;const u=(g,I)=>[e*g+s*I+i,o*g+r*I+a],l=n.match(/[a-df-zA-DF-Z][^a-df-zA-DF-Z]*/g)??[],h=[];let f=0,d=0,p=0,y=0;for(const g of l){const I=g[0],v=g.slice(1),b=Ar(v),P=I===I.toLowerCase()&&I!=="Z"&&I!=="z",M=I.toUpperCase();switch(M){case"M":{if(b.length<2)break;const C=[];for(let _=0;_<b.length;_+=2){let Y=b[_],G=b[_+1];P&&(Y+=f,G+=d),C.push([Y,G]),f=Y,d=G}const[N,z]=u(C[0][0],C[0][1]);h.push(`M${L(N)} ${L(z)}`),p=C[0][0],y=C[0][1];for(let _=1;_<C.length;_++){const[Y,G]=u(C[_][0],C[_][1]);h.push(` L${L(Y)} ${L(G)}`)}break}case"L":case"T":{for(let C=0;C<b.length;C+=2){let N=b[C],z=b[C+1];P&&(N+=f,z+=d);const[_,Y]=u(N,z);h.push(`${M}${L(_)} ${L(Y)}`),f=N,d=z}break}case"H":{for(const C of b){let N=C;P&&(N+=f);const[z,_]=u(N,d);h.push(`L${L(z)} ${L(_)}`),f=N}break}case"V":{for(const C of b){let N=C;P&&(N+=d);const[z,_]=u(f,N);h.push(`L${L(z)} ${L(_)}`),d=N}break}case"C":{for(let C=0;C<b.length;C+=6){let N=b[C],z=b[C+1],_=b[C+2],Y=b[C+3],G=b[C+4],J=b[C+5];P&&(N+=f,z+=d,_+=f,Y+=d,G+=f,J+=d);const[ut,St]=u(N,z),[kt,Vo]=u(_,Y),[zo,Yo]=u(G,J);h.push(`C${L(ut)} ${L(St)} ${L(kt)} ${L(Vo)} ${L(zo)} ${L(Yo)}`),f=G,d=J}break}case"S":case"Q":{for(let N=0;N<b.length;N+=4){let z=b[N],_=b[N+1],Y=b[N+2],G=b[N+3];P&&(z+=f,_+=d,Y+=f,G+=d);const[J,ut]=u(z,_),[St,kt]=u(Y,G);h.push(`${M}${L(J)} ${L(ut)} ${L(St)} ${L(kt)}`),f=Y,d=G}break}case"A":{for(let C=0;C<b.length;C+=7){const N=b[C],z=b[C+1],_=b[C+2],Y=b[C+3],G=b[C+4];let J=b[C+5],ut=b[C+6];P&&(J+=f,ut+=d);const[St,kt]=u(J,ut);h.push(`A${N} ${z} ${_} ${Y} ${G} ${L(St)} ${L(kt)}`),f=J,d=ut}break}case"Z":{h.push("Z"),f=p,d=y;break}default:h.push(g)}}return h.join(" ")}function Ar(n){const t=[],e=n.match(/-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g)??[];for(const o of e){const s=Number(o);Number.isNaN(s)||t.push(s)}return t}function L(n){const t=Math.round(n*1e4)/1e4;return Number.isInteger(t),String(t)}const Ie="svgeLiveBoolean",xt="svgeLiveBooleanRole";function xe(n){if(n.type!=="group")return!1;const t=n.metadata.customData;if(t===void 0)return!1;const e=t[Ie];return e==="union"||e==="intersect"||e==="subtract"||e==="exclude"}function Do(n){return xe(n)?n.metadata.customData[Ie]:null}class Er{nodeIds;op;id=x();label;previousRootSnapshot=null;constructor(t,e){this.nodeIds=t,this.op=e,this.label=`Make Live ${wo(e)}`}execute(t){if(this.nodeIds.length<2)return c(`${this.label}: need at least 2 nodes`);const e=t.state.document();this.previousRootSnapshot=e.root;const o=[];for(const I of this.nodeIds){const v=$(e.root,I);if(v===null)return c(`${this.label}: node "${I}" not found`);if(v.type==="group"||v.type==="text"||v.type==="image")return c(`${this.label}: type "${v.type}" not supported`);o.push(v)}const s=No(o,this.op);if(s===null)return c(`${this.label}: boolean op failed`);const r=o[0],i=T(e.root,r.id);if(i===null)return c(`${this.label}: operand A has no parent`);const a=i.children.findIndex(I=>I.id===r.id);if(a<0)return c(`${this.label}: operand A index lookup failed`);const l={...tt(s),transform:[1,0,0,1,0,0],style:r.style,metadata:{...r.metadata,visible:!0,customData:{...r.metadata.customData??{},[xt]:"result"}}},h=o.map(I=>({...I,metadata:{...I.metadata,visible:!1,customData:{...I.metadata.customData??{},[xt]:"input"}}})),f=et([l,...h],{metadata:{name:`Live ${wo(this.op)}`,customData:{[Ie]:this.op}}});let d=e.root;for(const I of o)d=D(d,I.id);const p=$(d,i.id),y=p!==null&&p.type==="group"?p.children:[],g=Math.min(a,y.length);return d=w(d,i.id,f,g),t.state.setDocument({...e,root:d}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class _r{groupId;id=x();label="Refresh Live Boolean";previousRootSnapshot=null;constructor(t){this.groupId=t}execute(t){const e=t.state.document(),o=$(e.root,this.groupId);if(o===null)return c(`${this.label}: group "${this.groupId}" not found`);if(!xe(o))return c(`${this.label}: not a live-boolean group`);const s=Do(o),r=[];let i=-1;for(let g=0;g<o.children.length;g++){const I=o.children[g],v=I.metadata.customData?.[xt];v==="input"?r.push(I):v==="result"&&(i=g)}if(r.length<2)return c(`${this.label}: not enough inputs`);if(i<0)return c(`${this.label}: no result child found`);const a=No(r,s);if(a===null)return c(`${this.label}: boolean op failed`);this.previousRootSnapshot=e.root;const l={...o.children[i],d:a},h=o.children.map((g,I)=>I===i?l:g),f={...o,children:h},d=T(e.root,o.id);if(d===null)return c(`${this.label}: group has no parent`);const p=d.children.findIndex(g=>g.id===o.id);if(p<0)return c(`${this.label}: group index lookup failed`);let y=D(e.root,o.id);return y=w(y,d.id,f,p),t.state.setDocument({...e,root:y}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Lr{groupId;id=x();label="Release Live Boolean";previousRootSnapshot=null;constructor(t){this.groupId=t}execute(t){const e=t.state.document(),o=$(e.root,this.groupId);if(o===null)return c(`${this.label}: group "${this.groupId}" not found`);if(!xe(o))return c(`${this.label}: not a live-boolean group`);this.previousRootSnapshot=e.root;const s=T(e.root,o.id);if(s===null)return c(`${this.label}: group has no parent`);const r=s.children.findIndex(u=>u.id===o.id);if(r<0)return c(`${this.label}: group index lookup failed`);const i=[];for(const u of o.children)if(u.metadata.customData?.[xt]==="input"){const h={...u.metadata.customData??{}};delete h[xt];const f=Object.keys(h).length>0?h:void 0;i.push({...u,metadata:{...u.metadata,visible:!0,customData:f}})}let a=D(e.root,o.id);for(let u=0;u<i.length;u++)a=w(a,s.id,i[u],r+u);return t.state.setDocument({...e,root:a}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}function wo(n){return n.length===0?n:n[0].toUpperCase()+n.slice(1)}function No(n,t){const e=[];for(const o of n){const s=o.type==="path"?o.d:It(o);if(s===null)return null;const r=Tt(s).map(i=>jr(i,o.transform));e.push(r)}try{let o;const s=e.map(Fr);switch(t){case"union":o=q.union(s[0],...s.slice(1));break;case"intersect":o=q.intersection(s[0],...s.slice(1));break;case"subtract":o=q.difference(s[0],...s.slice(1));break;case"exclude":o=q.xor(s[0],...s.slice(1));break}const r=[];for(const i of o)for(const a of i){const u=a.slice(0,-1).map(l=>({x:l[0],y:l[1]}));u.length>=3&&r.push(u)}return r.length===0?"":Ee(r)}catch{return null}}function jr(n,t){const[e,o,s,r,i,a]=t;return n.map(u=>({x:e*u.x+s*u.y+i,y:o*u.x+r*u.y+a}))}function Fr(n){return n.map(t=>{const e=t.map(o=>[o.x,o.y]);return e.length>0&&(e[0][0]!==e.at(-1)[0]||e[0][1]!==e.at(-1)[1])&&e.push([e[0][0],e[0][1]]),e})}const Vr={x:10,y:10};class zr{originalIds;offset;id=x();label;insertedIds=[];constructor(t,e=Vr){if(this.originalIds=t,this.offset=e,this.label=`Duplicate ${t.length} node(s)`,!Number.isFinite(e.x)||!Number.isFinite(e.y))throw new RangeError(`DuplicateNodeCommand: non-finite offset (got ${e.x}, ${e.y})`)}execute(t){if(this.originalIds.length===0)return this.insertedIds=[],m();const e=t.state.document(),o=e.root.id;for(const i of this.originalIds){if(i===o)return c("DuplicateNodeCommand: cannot duplicate document root");if($(e.root,i)===null)return c(`DuplicateNodeCommand: node "${i}" not found`);if(T(e.root,i)===null)return c(`DuplicateNodeCommand: parent of "${i}" not found`)}let s=e.root;const r=[];for(const i of this.originalIds){const a=$(s,i);if(a===null)return c(`DuplicateNodeCommand: "${i}" disappeared mid-execute`);const u=T(s,i);if(u===null)return c(`DuplicateNodeCommand: parent of "${i}" missing mid-execute`);const l=He(a),h={...l,transform:S(F(this.offset.x,this.offset.y),l.transform)},f=u.children.findIndex(p=>p.id===i)+1,d=w(s,u.id,h,f);if(d===s)return c(`DuplicateNodeCommand: insert of clone failed for "${i}"`);s=d,r.push(h.id)}return this.insertedIds=r,t.state.setDocument({...e,root:s}),m()}undo(t){if(this.insertedIds.length===0)return m();const e=t.state.document();let o=e.root;for(const s of this.insertedIds){const r=D(o,s);r!==o&&(o=r)}return t.state.setDocument({...e,root:o}),m()}getInsertedIds(){return this.insertedIds}}class Lt{nodeIds;id=x();isDestructive=!0;previousRootSnapshot=null;constructor(t){this.nodeIds=t}execute(t){if(this.nodeIds.length<2)return c(`${this.label}: need at least 2 nodes (got ${this.nodeIds.length})`);const e=t.state.document();this.previousRootSnapshot=e.root;const o=[];for(const f of this.nodeIds){const d=$(e.root,f);if(d===null)return c(`${this.label}: node "${f}" not found`);if(d.type==="group"||d.type==="text"||d.type==="image")return c(`${this.label}: type "${d.type}" not supported (skip groups/text/image)`);const p=d.type==="path"?d.d:It(d);if(p===null)return c(`${this.label}: cannot compute path "d" for "${d.type}" node`);const y=Tt(p).map(g=>Kr(g,d.transform));o.push({id:f,rings:y})}let s;try{s=this.runOp(o.map(f=>f.rings))}catch(f){return c(`${this.label}: polygon op failed \u2014 ${Wr(f)}`)}if(s.length===0){let f=e.root;for(const d of o)f=D(f,d.id);return t.state.setDocument({...e,root:f}),m()}const r=$(e.root,o[0].id);if(r===null)return c(`${this.label}: operand A vanished`);const i=[];for(const f of o){const d=$(e.root,f.id);d===null?i.push({style:r.style,metadata:r.metadata}):i.push({style:d.style,metadata:d.metadata})}const a=s.map((f,d)=>{const p=Ee(f.rings),y=tt(p),g=typeof f.styleSourceIdx=="number"&&f.styleSourceIdx>=0&&f.styleSourceIdx<i.length?f.styleSourceIdx:0,I=i[g];return{...y,id:d===0?r.id:y.id,transform:[1,0,0,1,0,0],style:I.style,metadata:d===0?r.metadata:I.metadata}}),u=T(e.root,r.id);if(u===null)return c(`${this.label}: operand A has no parent`);const l=u.children.findIndex(f=>f.id===r.id);if(l<0)return c(`${this.label}: operand A index lookup failed`);let h=D(e.root,r.id);h=w(h,u.id,a[0],l);for(let f=1;f<o.length;f++)h=D(h,o[f].id);if(a.length>1){const f=T(h,r.id);if(f!==null){const d=f.children.findIndex(p=>p.id===r.id);for(let p=a.length-1;p>=1;p--)h=w(h,f.id,a[p],d+p)}}return t.state.setDocument({...e,root:h}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Yr extends Lt{label="Union";runOp(t){const e=t.map(jt);return q.union(e[0],...e.slice(1)).map(s=>({rings:bt(s)}))}}class Gr extends Lt{label="Intersect";runOp(t){const e=t.map(jt);return q.intersection(e[0],...e.slice(1)).map(s=>({rings:bt(s)}))}}class Br extends Lt{label="Subtract";runOp(t){const e=t.map(jt);return q.difference(e[0],...e.slice(1)).map(s=>({rings:bt(s)}))}}class Ur extends Lt{label="Exclude";runOp(t){const e=t.map(jt);return q.xor(e[0],...e.slice(1)).map(s=>({rings:bt(s)}))}}class Xr extends Lt{label="Divide";runOp(t){const e=t.map(jt),o=[];for(let s=0;s<e.length;s++){const r=e.filter((a,u)=>u!==s),i=r.length===0?[e[s]]:q.difference(e[s],...r);for(const a of i)o.push({rings:bt(a),styleSourceIdx:s})}for(let s=0;s<e.length;s++)for(let r=s+1;r<e.length;r++){const i=q.intersection(e[s],e[r]);for(const a of i)o.push({rings:bt(a)})}return o}}function jt(n){return n.map(t=>t.map(e=>[e.x,e.y]))}function bt(n){return n.map(t=>t.map(([e,o])=>({x:e,y:o})))}function Kr(n,t){const[e,o,s,r,i,a]=t;return n.map(u=>({x:e*u.x+s*u.y+i,y:o*u.x+r*u.y+a}))}function Wr(n){return n instanceof Error?n.message:String(n)}class qr{selectedIds;groupId;id=x();label="Group selection";newGroupId=null;parentId=null;snapshot=[];wrappedNodes=[];constructor(t,e){this.selectedIds=t,this.groupId=e}execute(t){if(this.selectedIds.length===0)return c("GroupSelectionCommand: selection is empty");const e=t.state.document();let o=null;const s=[];for(const d of this.selectedIds){const p=$(e.root,d);if(p===null)return c(`GroupSelectionCommand: node "${d}" not found`);if(ft(p)||j(p))return c(`GroupSelectionCommand: cannot group a ${j(p)?"page":"layer"} ("${d}") \u2014 layers/pages are top-level only`);const y=T(e.root,d);if(y===null)return c(`GroupSelectionCommand: node "${d}" has no parent`);if(o===null)o=y;else if(o.id!==y.id)return c(`GroupSelectionCommand: nodes must share the same immediate parent (found "${o.id}" and "${y.id}")`);s.push(p)}if(o===null)return c("GroupSelectionCommand: could not resolve common parent");const r=new Set(this.selectedIds),i=[];o.children.forEach((d,p)=>{r.has(d.id)&&i.push({id:d.id,index:p})});const a=i.map(d=>s.find(p=>p.id===d.id)),u=i[0].index;this.snapshot=i,this.wrappedNodes=a,this.parentId=o.id;const l=et(a,{id:this.groupId});this.newGroupId=l.id;let h=e.root;for(const d of this.selectedIds){const p=D(h,d);if(p===h)return c(`GroupSelectionCommand: failed to detach child "${d}"`);h=p}let f;try{f=w(h,o.id,l,u)}catch(d){return c(d instanceof Error?d.message:String(d))}return f===h?c(`GroupSelectionCommand: failed to insert new group under "${o.id}"`):(t.state.setDocument({...e,root:f}),m())}undo(t){if(this.newGroupId===null||this.parentId===null)return c("GroupSelectionCommand undo: nothing captured (was execute called?)");const e=t.state.document();let o=D(e.root,this.newGroupId);if(o===e.root)return c(`GroupSelectionCommand undo: group "${this.newGroupId}" not found`);for(let r=0;r<this.snapshot.length;r++){const{index:i}=this.snapshot[r],a=this.wrappedNodes[r];try{o=w(o,this.parentId,a,i)}catch(u){return c(u instanceof Error?u.message:String(u))}}const s=$(o,this.parentId);return s===null||!B(s)?c(`GroupSelectionCommand undo: parent "${this.parentId}" lost`):(t.state.setDocument({...e,root:o}),m())}}const Mo="auto";class Hr{parentId;node;index;id=x();label;resolvedParentId=null;constructor(t,e,o){this.parentId=t,this.node=e,this.index=o,this.label=`Insert ${e.type}`}getResolvedParentId(){return this.resolvedParentId}execute(t){const e=t.state.document(),o=this.parentId===Mo?t.parentResolver?.resolveAutoParent()??e.root.id:this.parentId;this.resolvedParentId=o;let s;try{s=w(e.root,o,this.node,this.index)}catch(r){return c(r instanceof Error?r.message:String(r))}return s===e.root?c(`InsertNodeCommand: parent group "${o}" not found`):(t.state.setDocument({...e,root:s}),m())}undo(t){const e=t.state.document(),o=D(e.root,this.node.id);return o===e.root?c(`InsertNodeCommand undo: node "${this.node.id}" not found`):(t.state.setDocument({...e,root:o}),m())}}class Zr{nodeId;dx;dy;id=x();label="Move node";previousTransform=null;constructor(t,e,o){this.nodeId=t,this.dx=e,this.dy=o}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`MoveNodeCommand: node "${this.nodeId}" not found`);this.previousTransform=o.transform;const s=S(F(this.dx,this.dy),o.transform),r=R(e.root,this.nodeId,i=>({...i,transform:s}));return r===e.root?c(`MoveNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousTransform===null)return c("MoveNodeCommand undo: nothing captured (was execute called?)");const e=this.previousTransform,o=t.state.document(),s=R(o.root,this.nodeId,r=>({...r,transform:e}));return s===o.root?c(`MoveNodeCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...o,root:s}),m())}}class Qr{nodeId;newParentId;newIndex;id=x();label="Move in tree";originalParentId=null;originalIndex=-1;nodeRef=null;constructor(t,e,o){this.nodeId=t,this.newParentId=e,this.newIndex=o}execute(t){const e=t.state.document();if(this.nodeId===e.root.id)return c("MoveNodeInTreeCommand: cannot move the document root");const o=$(e.root,this.nodeId);if(o===null)return c(`MoveNodeInTreeCommand: node "${this.nodeId}" not found`);const s=$(e.root,this.newParentId);if(s===null)return c(`MoveNodeInTreeCommand: new parent "${this.newParentId}" not found`);if(!B(s))return c(`MoveNodeInTreeCommand: new parent "${this.newParentId}" is not a group`);if(j(o)&&this.newParentId!==e.root.id)return c("MoveNodeInTreeCommand: a page can only live at the document root");if(ft(o)&&!(this.newParentId===e.root.id||j(s)))return c(`MoveNodeInTreeCommand: a layer can only live at the document root or inside a page (not "${this.newParentId}")`);if(this.newParentId===this.nodeId)return c("MoveNodeInTreeCommand: cannot move a node into itself");if(B(o)&&Po(o,this.newParentId))return c(`MoveNodeInTreeCommand: cannot move "${this.nodeId}" into its own descendant "${this.newParentId}" (cycle)`);const r=T(e.root,this.nodeId);if(r===null)return c(`MoveNodeInTreeCommand: node "${this.nodeId}" has no parent`);const i=r.children.findIndex(d=>d.id===this.nodeId);if(i<0)return c("MoveNodeInTreeCommand: failed to locate node in current parent");const a=r.id===this.newParentId,u=s.children,l=a?u.length-1:u.length,h=Math.max(0,Math.min(l,this.newIndex));if(a&&h===i)return this.originalParentId=r.id,this.originalIndex=i,this.nodeRef=o,m();this.originalParentId=r.id,this.originalIndex=i,this.nodeRef=o;let f=D(e.root,this.nodeId);if(f===e.root)return c("MoveNodeInTreeCommand: failed to detach node");try{f=w(f,this.newParentId,o,h)}catch(d){return c(d instanceof Error?d.message:String(d))}return t.state.setDocument({...e,root:f}),m()}undo(t){if(this.originalParentId===null||this.nodeRef===null)return c("MoveNodeInTreeCommand undo: nothing captured");const e=t.state.document();let o=D(e.root,this.nodeId);if(o===e.root)return c(`MoveNodeInTreeCommand undo: node "${this.nodeId}" not found`);try{o=w(o,this.originalParentId,this.nodeRef,this.originalIndex)}catch(s){return c(s instanceof Error?s.message:String(s))}return t.state.setDocument({...e,root:o}),m()}}function Po(n,t){if(!B(n))return!1;for(const e of n.children)if(e.id===t||B(e)&&Po(e,t))return!0;return!1}class Jr{nodeId;id=x();label;capturedNode=null;capturedParentId=null;capturedIndex=null;constructor(t){this.nodeId=t,this.label="Remove node"}execute(t){const e=t.state.document();if(e.root.id===this.nodeId)return c("RemoveNodeCommand: cannot remove the root group");const o=$(e.root,this.nodeId);if(o===null)return c(`RemoveNodeCommand: node "${this.nodeId}" not found`);const s=T(e.root,this.nodeId);if(s===null)return c(`RemoveNodeCommand: parent of "${this.nodeId}" not found`);const r=s.children.findIndex(a=>a.id===this.nodeId);this.capturedNode=o,this.capturedParentId=s.id,this.capturedIndex=r;const i=D(e.root,this.nodeId);return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.capturedNode===null||this.capturedParentId===null||this.capturedIndex===null)return c("RemoveNodeCommand undo: nothing was captured (was execute called?)");const e=t.state.document();let o;try{o=w(e.root,this.capturedParentId,this.capturedNode,this.capturedIndex)}catch(s){return c(s instanceof Error?s.message:String(s))}return o===e.root?c(`RemoveNodeCommand undo: parent "${this.capturedParentId}" not found`):(t.state.setDocument({...e,root:o}),m())}}class ti{nodeId;direction;id=x();label;parentId=null;originalIndex=-1;nodeRef=null;constructor(t,e){this.nodeId=t,this.direction=e,this.label=`Reorder (${e})`}execute(t){const e=t.state.document(),o=T(e.root,this.nodeId);if(o===null)return c(`ReorderNodeCommand: node "${this.nodeId}" has no parent (root or missing)`);const s=o.children.findIndex(h=>h.id===this.nodeId);if(s<0)return c("ReorderNodeCommand: failed to locate node in its parent");const r=o.children[s],i=o.children.length-1,a=ei(s,i,this.direction);if(this.parentId=o.id,this.originalIndex=s,this.nodeRef=r,a===s)return m();const u=(a>s,a);let l=D(e.root,this.nodeId);if(l===e.root)return c("ReorderNodeCommand: failed to detach node");try{l=w(l,o.id,r,u)}catch(h){return c(h instanceof Error?h.message:String(h))}return t.state.setDocument({...e,root:l}),m()}undo(t){if(this.parentId===null||this.nodeRef===null)return c("ReorderNodeCommand undo: nothing captured");const e=t.state.document();let o=D(e.root,this.nodeId);if(o===e.root)return c(`ReorderNodeCommand undo: node "${this.nodeId}" not found`);try{o=w(o,this.parentId,this.nodeRef,this.originalIndex)}catch(s){return c(s instanceof Error?s.message:String(s))}return t.state.setDocument({...e,root:o}),m()}}function ei(n,t,e){switch(e){case"forward":return Math.min(t,n+1);case"backward":return Math.max(0,n-1);case"toFront":return t;case"toBack":return 0}}class ni{nodeId;anchor;sx;sy;parentMatrix;localFrame;id=x();label="Resize node";previousNode=null;constructor(t,e,o,s,r=null,i=!1){if(this.nodeId=t,this.anchor=e,this.sx=o,this.sy=s,this.parentMatrix=r,this.localFrame=i,!Number.isFinite(o)||!Number.isFinite(s))throw new RangeError(`ResizeNodeCommand: scale factors must be finite (got sx=${o}, sy=${s})`)}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`ResizeNodeCommand: node "${this.nodeId}" not found`);if(this.previousNode=o,this.localFrame){const i=R(e.root,this.nodeId,()=>({...o,transform:S(o.transform,be(F(0,0),this.sx,this.sy,this.anchor))}));return i===e.root?c(`ResizeNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:i}),m())}const s=Oe(o,this.sx,this.sy,this.anchor,this.parentMatrix),r=R(e.root,this.nodeId,()=>s!==null?s:{...o,transform:be(o.transform,this.sx,this.sy,this.anchor)});return r===e.root?c(`ResizeNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousNode===null)return c("ResizeNodeCommand undo: nothing captured (was execute called?)");const e=this.previousNode,o=t.state.document(),s=R(o.root,this.nodeId,()=>e);return s===o.root?c(`ResizeNodeCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...o,root:s}),m())}}function be(n,t,e,o){const s=F(-o.x,-o.y),r=dt(t,e),i=F(o.x,o.y);return S(S(S(i,r),s),n)}const oi=[1,0,0,1,0,0];class si{entries;anchor;sx;sy;id=x();label;previous=new Map;constructor(t,e,o,s){this.entries=t,this.anchor=e,this.sx=o,this.sy=s,this.label=`Resize ${this.entries.length} nodes`}execute(t){if(this.entries.length===0)return m();const e=t.state.document(),o=be(oi,this.sx,this.sy,this.anchor);let s=e.root;this.previous.clear();for(const r of this.entries){const i=$(s,r.id);if(i===null)continue;const a=i.transform;this.previous.set(r.id,a);const u=ri(o,a,r.parentMatrix);s=R(s,r.id,l=>({...l,transform:u}))}return t.state.setDocument({...e,root:s}),m()}undo(t){const e=t.state.document();let o=e.root;for(const[s,r]of this.previous)o=R(o,s,i=>({...i,transform:r}));return t.state.setDocument({...e,root:o}),m()}}function ri(n,t,e){if(e===null)return S(n,t);try{const o=Bt(e);return S(o,S(n,S(e,t)))}catch{return S(n,t)}}class ii{nodeId;angleRad;pivot;id=x();label="Rotate node";previousTransform=null;constructor(t,e,o){this.nodeId=t,this.angleRad=e,this.pivot=o}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`RotateNodeCommand: node "${this.nodeId}" not found`);this.previousTransform=o.transform;const s=tn(o.transform,this.angleRad,this.pivot),r=R(e.root,this.nodeId,i=>({...i,transform:s}));return r===e.root?c(`RotateNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousTransform===null)return c("RotateNodeCommand undo: nothing captured (was execute called?)");const e=this.previousTransform,o=t.state.document(),s=R(o.root,this.nodeId,r=>({...r,transform:e}));return s===o.root?c(`RotateNodeCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...o,root:s}),m())}}function tn(n,t,e){const o=F(-e.x,-e.y),s=wt(t),r=F(e.x,e.y);return S(S(S(r,s),o),n)}const ai=[1,0,0,1,0,0];class ui{entries;pivot;angleRad;id=x();label;previous=new Map;constructor(t,e,o){this.entries=t,this.pivot=e,this.angleRad=o,this.label=`Rotate ${this.entries.length} nodes`}execute(t){if(this.entries.length===0)return m();const e=t.state.document(),o=tn(ai,this.angleRad,this.pivot);let s=e.root;this.previous.clear();for(const r of this.entries){const i=$(s,r.id);if(i===null)continue;const a=i.transform;this.previous.set(r.id,a);const u=di(o,a,r.parentMatrix);s=R(s,r.id,l=>({...l,transform:u}))}return t.state.setDocument({...e,root:s}),m()}undo(t){const e=t.state.document();let o=e.root;for(const[s,r]of this.previous)o=R(o,s,i=>({...i,transform:r}));return t.state.setDocument({...e,root:o}),m()}}function di(n,t,e){if(e===null)return S(n,t);try{const o=Bt(e);return S(o,S(n,S(e,t)))}catch{return S(n,t)}}class ci{nodeId;skewXRad;skewYRad;pivot;id=x();label="Skew node";previousTransform=null;constructor(t,e,o,s){if(this.nodeId=t,this.skewXRad=e,this.skewYRad=o,this.pivot=s,!Number.isFinite(e)||!Number.isFinite(o))throw new RangeError(`SkewNodeCommand: skew angles must be finite (got x=${e}, y=${o})`)}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`SkewNodeCommand: node "${this.nodeId}" not found`);this.previousTransform=o.transform;const s=en(o.transform,this.skewXRad,this.skewYRad,this.pivot),r=R(e.root,this.nodeId,i=>({...i,transform:s}));return r===e.root?c(`SkewNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousTransform===null)return c("SkewNodeCommand undo: nothing captured (was execute called?)");const e=this.previousTransform,o=t.state.document(),s=R(o.root,this.nodeId,r=>({...r,transform:e}));return s===o.root?c(`SkewNodeCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...o,root:s}),m())}}function en(n,t,e,o){const s=F(-o.x,-o.y),r=S(an(t),un(e)),i=F(o.x,o.y);return S(S(S(i,r),s),n)}const li=[1,0,0,1,0,0];class hi{entries;pivot;skewXRad;skewYRad;id=x();label;previous=new Map;constructor(t,e,o,s){this.entries=t,this.pivot=e,this.skewXRad=o,this.skewYRad=s,this.label=`Skew ${this.entries.length} nodes`}execute(t){if(this.entries.length===0)return m();const e=t.state.document(),o=en(li,this.skewXRad,this.skewYRad,this.pivot);let s=e.root;this.previous.clear();for(const r of this.entries){const i=$(s,r.id);if(i===null)continue;const a=i.transform;this.previous.set(r.id,a);const u=fi(o,a,r.parentMatrix);s=R(s,r.id,l=>({...l,transform:u}))}return t.state.setDocument({...e,root:s}),m()}undo(t){const e=t.state.document();let o=e.root;for(const[s,r]of this.previous)o=R(o,s,i=>({...i,transform:r}));return t.state.setDocument({...e,root:o}),m()}}function fi(n,t,e){if(e===null)return S(n,t);try{const o=Bt(e);return S(o,S(n,S(e,t)))}catch{return S(n,t)}}class pi{nodeId;axis;pivot;id=x();label="Flip node";previousTransform=null;constructor(t,e,o){this.nodeId=t,this.axis=e,this.pivot=o}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`FlipNodeCommand: node "${this.nodeId}" not found`);this.previousTransform=o.transform;const s=Oo(o.transform,this.axis,this.pivot),r=R(e.root,this.nodeId,i=>({...i,transform:s}));return r===e.root?c(`FlipNodeCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousTransform===null)return c("FlipNodeCommand undo: nothing captured (was execute called?)");const e=this.previousTransform,o=t.state.document(),s=R(o.root,this.nodeId,r=>({...r,transform:e}));return s===o.root?c(`FlipNodeCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...o,root:s}),m())}}function Oo(n,t,e){const o=F(-e.x,-e.y),s=t==="horizontal"?dt(-1,1):dt(1,-1),r=F(e.x,e.y);return S(S(S(r,s),o),n)}class mi{nodeId;docPoint;tolerance;snapToNodes;id=x();label="Cut path";isDestructive=!0;previousNode=null;previousParentId=null;previousIndex=-1;insertedIds=[];get createdIds(){return this.insertedIds}constructor(t,e,o,s){this.nodeId=t,this.docPoint=e,this.tolerance=o,this.snapToNodes=s}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`KnifeCutPathCommand: node "${this.nodeId}" not found`);const s=o.type==="path"?o.d:It(o);if(s===null)return c(`KnifeCutPathCommand: type "${o.type}" not cuttable`);const r=K(s);if(r.length===0)return c("KnifeCutPathCommand: path has no subpaths");const i=T(e.root,this.nodeId);if(i===null)return c(`KnifeCutPathCommand: node "${this.nodeId}" has no parent (root?)`);const a=i.children.findIndex(M=>M.id===this.nodeId);if(a<0)return c("KnifeCutPathCommand: index lookup failed");const u=yi(r,this.docPoint);if(u===null||u.dist>this.tolerance)return c(`KnifeCutPathCommand: no segment within ${this.tolerance}px of click`);let l;const h=this.snapToNodes?gi(r,this.docPoint,this.tolerance/2):null;h!==null?l={sp:h.sp,segIdx:h.anchorIdx===0?0:h.anchorIdx-1,t:h.anchorIdx===0?0:1,anchor:r[h.sp].anchors[h.anchorIdx]}:l={sp:u.sp,segIdx:u.segIdx,t:u.t,anchor:{point:u.proj,handleIn:u.proj,handleOut:u.proj,kind:"cusp"}};const f=r[l.sp],d=r.filter((M,C)=>C!==l.sp),p=f.closed?[xi(f,l.segIdx,l.anchor,h!==null)]:Ii(f,l.segIdx,l.anchor,h!==null);if(p.length===0)return c("KnifeCutPathCommand: cut produced no pieces");const y=p.map((M,C)=>C===0?[M,...d]:[M]),g=o.style,I=o.transform,v=o.metadata,b=y.map(M=>{const C=Z(M);return{...tt(C),transform:I,style:g,metadata:v}});let P=D(e.root,this.nodeId);if(P===e.root)return c(`KnifeCutPathCommand: remove failed for "${this.nodeId}"`);for(let M=b.length-1;M>=0;M--){const C=w(P,i.id,b[M],a);if(C===P)return c("KnifeCutPathCommand: insert failed");P=C}return this.previousNode=o,this.previousParentId=i.id,this.previousIndex=a,this.insertedIds=b.map(M=>M.id),t.state.setDocument({...e,root:P}),m()}undo(t){if(this.previousNode===null||this.previousParentId===null||this.previousIndex<0)return c("KnifeCutPathCommand undo: nothing captured");const e=t.state.document();let o=e.root;for(const r of this.insertedIds){const i=D(o,r);if(i===o)return c(`KnifeCutPathCommand undo: remove failed for piece "${r}"`);o=i}const s=w(o,this.previousParentId,this.previousNode,this.previousIndex);return s===o?c("KnifeCutPathCommand undo: re-insert failed"):(t.state.setDocument({...e,root:s}),m())}}function yi(n,t){let e=null;for(let o=0;o<n.length;o++){const s=n[o].anchors,r=n[o].closed?s.length:s.length-1;for(let i=0;i<r;i++){const a=s[i].point,u=s[(i+1)%s.length].point,l=bi(t,a,u),h=To(t,l.point);(e===null||h<e.dist)&&(e={sp:o,segIdx:i,t:l.t,dist:h,proj:l.point})}}return e}function gi(n,t,e){let o=null;for(let s=0;s<n.length;s++){const r=n[s].anchors;for(let i=0;i<r.length;i++){const a=To(t,r[i].point);a<=e&&(o===null||a<o.dist)&&(o={sp:s,anchorIdx:i,dist:a})}}return o}function Ii(n,t,e,o){const s=n.anchors;if(o){const u=t,l=s.slice(0,u+1),h=s.slice(u+1);return l.length<2||h.length<2?[l,h].filter(f=>f.length>=2).map(f=>({anchors:f,closed:!1})):[{anchors:l,closed:!1},{anchors:h,closed:!1}]}const r=[...s.slice(0,t+1),e],a=[{point:e.point,handleIn:e.handleIn,handleOut:e.handleOut,kind:e.kind},...s.slice(t+1)];return[{anchors:r,closed:!1},{anchors:a,closed:!1}]}function xi(n,t,e,o){const s=n.anchors;if(o){const i=t===s.length-1?0:t+1;return{anchors:[...s.slice(i),...s.slice(0,i)],closed:!1}}const r={point:e.point,handleIn:e.handleIn,handleOut:e.handleOut,kind:e.kind};return{anchors:[e,...s.slice(t+1),...s.slice(0,t+1),r],closed:!1}}function bi(n,t,e){const o=e.x-t.x,s=e.y-t.y,r=o*o+s*s;if(r===0)return{point:t,t:0};let i=((n.x-t.x)*o+(n.y-t.y)*s)/r;return i<0?i=0:i>1&&(i=1),{point:{x:t.x+i*o,y:t.y+i*s},t:i}}function To(n,t){return Math.hypot(t.x-n.x,t.y-n.y)}const $i={x:0,y:0,width:794,height:1123};class vi{viewBox;name;id=x();label="New Page";createdPageId=null;constructor(t=$i,e){this.viewBox=t,this.name=e}execute(t){const e=t.state.document();let o=0;for(const a of e.root.children)j(a)&&(o+=1);const s=et([],{metadata:{name:this.name??`Page ${o+1}`}}),r=Se(s,this.viewBox,this.name);this.createdPageId=r.id;const i=w(e.root,e.root.id,r,e.root.children.length);return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.createdPageId===null)return c(`${this.label} undo: nothing to remove`);const e=t.state.document(),o=D(e.root,this.createdPageId);return o===e.root?c(`${this.label} undo: created page "${this.createdPageId}" already gone`):(t.state.setDocument({...e,root:o}),m())}getCreatedPageId(){return this.createdPageId}}class Ci{nodeId;id=x();label="Delete Page";isDestructive=!0;previousRootSnapshot=null;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!j(o))return c(`${this.label}: node "${this.nodeId}" is not a page`);const s=T(e.root,this.nodeId);if(s===null||s.id!==e.root.id)return c(`${this.label}: only top-level pages can be deleted via this command (node is nested)`);this.previousRootSnapshot=e.root;const r=D(e.root,this.nodeId);return r===e.root?c(`${this.label}: remove failed for "${this.nodeId}"`):(t.state.setDocument({...e,root:r}),m())}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Ri{nodeId;newName;id=x();label="Rename Page";previousRootSnapshot=null;constructor(t,e){this.nodeId=t,this.newName=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!j(o))return c(`${this.label}: node "${this.nodeId}" is not a page`);if(hn(o)===this.newName)return m();this.previousRootSnapshot=e.root;const r=R(e.root,this.nodeId,i=>fn(i,this.newName));return t.state.setDocument({...e,root:r}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Si{nodeId;newViewBox;id=x();label="Resize Page";previousRootSnapshot=null;constructor(t,e){this.nodeId=t,this.newViewBox=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!j(o))return c(`${this.label}: node "${this.nodeId}" is not a page`);const s=Mt(o);if(s!==null&&s.x===this.newViewBox.x&&s.y===this.newViewBox.y&&s.width===this.newViewBox.width&&s.height===this.newViewBox.height)return m();this.previousRootSnapshot=e.root;const r=pn(this.newViewBox.width,this.newViewBox.height),i=we(this.newViewBox.width,this.newViewBox.height),a=R(e.root,this.nodeId,u=>ke(qt(u,this.newViewBox),{format:r,orientation:i}));return t.state.setDocument({...e,root:a}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class ki{nodeId;newOrigin;id=x();label="Move Page";previousRootSnapshot=null;constructor(t,e){this.nodeId=t,this.newOrigin=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!j(o))return c(`${this.label}: node "${this.nodeId}" is not a page`);const s=Mt(o);if(s===null)return c(`${this.label}: node "${this.nodeId}" has no pageViewBox`);if(s.x===this.newOrigin.x&&s.y===this.newOrigin.y)return m();this.previousRootSnapshot=e.root;const r=R(e.root,this.nodeId,i=>qt(i,{x:this.newOrigin.x,y:this.newOrigin.y,width:s.width,height:s.height}));return t.state.setDocument({...e,root:r}),m()}undo(t){if(this.previousRootSnapshot===null)return m();const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Di{nodeId;patch;id=x();label;previousRootSnapshot=null;constructor(t,e){this.nodeId=t,this.patch=e,this.label="Set page options"}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!j(o))return c(`${this.label}: node "${this.nodeId}" is not a page`);const s=Ht(o),r=Mt(o),i={...this.patch};let a=null;const u=r?.x??0,l=r?.y??0;if(this.patch.format!==void 0&&this.patch.format!=="custom"){const y=this.patch.orientation??(r!==null?we(r.width,r.height):s.orientation);i.orientation=y;const g=De(this.patch.format,y);g!==null&&(a={x:u,y:l,width:g.width,height:g.height})}else if(this.patch.orientation!==void 0){const y=i.format??s.format,g=De(y,this.patch.orientation);if(g!==null)a={x:u,y:l,width:g.width,height:g.height};else if(r!==null&&r.width!==r.height){const I=this.patch.orientation==="landscape",v=r.width>r.height;I!==v&&(a={x:r.x,y:r.y,width:r.height,height:r.width})}}const h={background:i.background??s.background,margins:i.margins??s.margins,orientation:i.orientation??s.orientation,format:i.format??s.format},f=a!==null&&(r===null||a.width!==r.width||a.height!==r.height||a.x!==r.x||a.y!==r.y);if(wi(s,h)&&!f)return m();this.previousRootSnapshot=e.root;const d=a,p=R(e.root,this.nodeId,y=>{const g=ke(y,i);return d!==null?qt(g,d):g});return t.state.setDocument({...e,root:p}),m()}undo(t){if(this.previousRootSnapshot===null)return m();const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}function wi(n,t){return Ni(n.background,t.background)&&n.margins.top===t.margins.top&&n.margins.right===t.margins.right&&n.margins.bottom===t.margins.bottom&&n.margins.left===t.margins.left&&n.orientation===t.orientation&&n.format===t.format}function Ni(n,t){return n.kind!==t.kind?!1:n.kind==="solid"&&t.kind==="solid"?n.color===t.color:n.kind==="image"&&t.kind==="image"?n.href===t.href:!0}class Mi{id=x();label="Bootstrap Page 1";previousRoot=null;createdPageId=null;getCreatedPageId(){return this.createdPageId}execute(t){const e=t.state.document();for(const a of e.root.children)if(j(a))return m();this.previousRoot=e.root;const o=[...e.root.children],s=et(o,{metadata:{name:"Page 1"}}),r=Se(s,e.viewBox,"Page 1");this.createdPageId=r.id;const i={...e.root,children:[r]};return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.previousRoot===null)return m();const e=t.state.document();return t.state.setDocument({...e,root:this.previousRoot}),m()}}class Pi{nodeId;property;value;id=x();label;previousValue;valueWasPresent=!1;constructor(t,e,o){if(this.nodeId=t,this.property=e,this.value=o,e==="id"||e==="type")throw new Error(`SetPropertyCommand: cannot mutate reserved property "${String(e)}"`);this.label=`Set ${String(e)}`}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`SetPropertyCommand: node "${this.nodeId}" not found`);this.valueWasPresent=Object.prototype.hasOwnProperty.call(o,this.property),this.previousValue=o[this.property];const s=this.value,r=this.property,i=R(e.root,this.nodeId,a=>({...a,[r]:s}));return i===e.root?c(`SetPropertyCommand: failed to update node "${this.nodeId}"`):(t.state.setDocument({...e,root:i}),m())}undo(t){!this.valueWasPresent&&this.previousValue;const e=t.state.document(),o=this.previousValue,s=this.property,r=R(e.root,this.nodeId,i=>({...i,[s]:o}));return r===e.root?c(`SetPropertyCommand undo: node "${this.nodeId}" not found`):(t.state.setDocument({...e,root:r}),m())}}class Oi{nodeIds;property;value;id=x();label;previousValues=null;constructor(t,e,o,s){if(this.nodeIds=t,this.property=e,this.value=o,e==="id"||e==="type")throw new Error(`SetPropertyOnManyCommand: cannot mutate reserved property "${String(e)}"`);this.label=s??`Set ${String(e)} (${t.length} nodes)`}execute(t){if(this.nodeIds.length===0)return m();const e=t.state.document(),o=new Map;for(const a of this.nodeIds){const u=$(e.root,a);if(u===null)return c(`SetPropertyOnManyCommand: node "${a}" not found`);o.set(a,{value:u[this.property],wasPresent:Object.prototype.hasOwnProperty.call(u,this.property)})}this.previousValues=o;const s=this.value,r=this.property;let i=e.root;for(const a of this.nodeIds){const u=R(i,a,l=>({...l,[r]:s}));if(u===i)return c(`SetPropertyOnManyCommand: failed to update "${a}"`);i=u}return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.previousValues===null)return c("SetPropertyOnManyCommand undo: nothing captured");const e=t.state.document(),o=this.property;let s=e.root;for(const[r,i]of this.previousValues){const a=R(s,r,u=>{if(!i.wasPresent){const l={...u};return delete l[o],l}return{...u,[o]:i.value}});a!==s&&(s=a)}return t.state.setDocument({...e,root:s}),m()}}class Ti{nodeIds;id=x();label="Set corner radius";radius;previous=null;constructor(t,e){this.nodeIds=t,this.radius=Number.isFinite(e)&&e>0?e:0}execute(t){if(this.nodeIds.length===0)return m();const e=t.state.document(),o=new Map,s=[];for(const a of this.nodeIds){const u=$(e.root,a);if(u===null||u.type!=="path")continue;const l=u;o.set(a,{value:l.cornerRadius,wasPresent:Object.prototype.hasOwnProperty.call(l,"cornerRadius")}),s.push(a)}if(s.length===0)return m();this.previous=o;const r=this.radius;let i=e.root;for(const a of s){const u=R(i,a,l=>({...l,cornerRadius:r}));if(u===i)return c(`SetCornerRadiusCommand: failed to update "${a}"`);i=u}return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.previous===null)return m();const e=t.state.document();let o=e.root;for(const[s,r]of this.previous){const i=R(o,s,a=>{if(!r.wasPresent){const u={...a};return delete u.cornerRadius,u}return{...a,cornerRadius:r.value}});i!==o&&(o=i)}return t.state.setDocument({...e,root:o}),m()}}class $t{containerId;id=x();previousCustomData;hadCustomData=!1;constructor(t){this.containerId=t}execute(t){const e=t.state.document(),o=$(e.root,this.containerId);if(o===null)return c(`${this.label}: container "${this.containerId}" not found`);const s=eo(o)??to(),r=this.nextDoc(s);if(r===s)return c(`${this.label}: no change to apply`);this.previousCustomData=o.metadata.customData,this.hadCustomData=Object.prototype.hasOwnProperty.call(o.metadata,"customData");const i=R(e.root,this.containerId,a=>({...a,metadata:{...a.metadata,customData:{...a.metadata.customData??{},[Ye]:r}}}));return i===e.root?c(`${this.label}: failed to update "${this.containerId}"`):(t.state.setDocument({...e,root:i}),m())}undo(t){const e=t.state.document(),o=this.previousCustomData,s=this.hadCustomData,r=R(e.root,this.containerId,i=>{if(!s){const a={...i.metadata};return delete a.customData,{...i,metadata:a}}return{...i,metadata:{...i.metadata,customData:o}}});return r===e.root?c(`${this.label} undo: container "${this.containerId}" not found`):(t.state.setDocument({...e,root:r}),m())}}class Ai extends $t{nodeId;property;keyframe;label="Add keyframe";constructor(t,e,o,s){super(t),this.nodeId=e,this.property=o,this.keyframe=s}nextDoc(t){return Ge(t,this.nodeId,this.property,this.keyframe)}}class Ei extends $t{nodeId;property;fromTime;toTime;newValue;label="Move keyframe";constructor(t,e,o,s,r,i){super(t),this.nodeId=e,this.property=o,this.fromTime=s,this.toTime=r,this.newValue=i}nextDoc(t){return so(t,this.nodeId,this.property,this.fromTime,this.toTime,this.newValue)}}class _i extends $t{nodeId;property;time;label="Remove keyframe";constructor(t,e,o,s){super(t),this.nodeId=e,this.property=o,this.time=s}nextDoc(t){return Be(t,this.nodeId,this.property,this.time)}}class Li extends $t{nodeId;property;time;easing;label="Set keyframe easing";constructor(t,e,o,s,r){super(t),this.nodeId=e,this.property=o,this.time=s,this.easing=r}nextDoc(t){return ro(t,this.nodeId,this.property,this.time,this.easing)}}class ji extends $t{durationMs;label="Set animation duration";constructor(t,e){super(t),this.durationMs=e}nextDoc(t){return io(t,this.durationMs)}}class Fi extends $t{nodeId;property;label="Remove track";constructor(t,e,o){super(t),this.nodeId=e,this.property=o}nextDoc(t){return oo(t,this.nodeId,this.property)}}class Vi{nodeIds;key;value;id=x();label;previousStyles=null;constructor(t,e,o,s){this.nodeIds=t,this.key=e,this.value=o,this.label=s??`Set ${e} (${t.length} nodes)`}execute(t){if(this.nodeIds.length===0)return m();const e=t.state.document(),o=new Map;for(const r of this.nodeIds){const i=$(e.root,r);if(i===null)return c(`SetStylePropertyOnManyCommand: node "${r}" not found`);o.set(r,i.style)}this.previousStyles=o;let s=e.root;for(const r of this.nodeIds){const i=R(s,r,a=>({...a,style:{...a.style,[this.key]:this.value}}));if(i===s)return c(`SetStylePropertyOnManyCommand: failed to update "${r}"`);s=i}return t.state.setDocument({...e,root:s}),m()}undo(t){if(this.previousStyles===null)return c("SetStylePropertyOnManyCommand undo: nothing captured");const e=t.state.document();let o=e.root;for(const[s,r]of this.previousStyles){const i=R(o,s,a=>({...a,style:r}));i!==o&&(o=i)}return t.state.setDocument({...e,root:o}),m()}}class zi{translations;id=x();label;previousTransforms=null;constructor(t,e="Translate many"){this.translations=t;for(const[o,s]of t)if(!Number.isFinite(s.x)||!Number.isFinite(s.y))throw new RangeError(`TranslateManyCommand: non-finite delta for node "${o}" (got ${s.x}, ${s.y})`);this.label=e}execute(t){if(this.translations.size===0)return this.previousTransforms=new Map,m();const e=t.state.document();for(const r of this.translations.keys())if($(e.root,r)===null)return c(`TranslateManyCommand: node "${r}" not found`);const o=new Map;let s=e.root;for(const[r,i]of this.translations){const a=$(s,r);if(a===null)return c(`TranslateManyCommand: node "${r}" disappeared mid-execute`);o.set(r,a.transform);const u=S(F(i.x,i.y),a.transform),l=R(s,r,h=>({...h,transform:u}));if(l===s)return c(`TranslateManyCommand: failed to update node "${r}"`);s=l}return this.previousTransforms=o,t.state.setDocument({...e,root:s}),m()}undo(t){if(this.previousTransforms===null)return c("TranslateManyCommand undo: nothing captured (was execute called?)");const e=t.state.document();let o=e.root;for(const[s,r]of this.previousTransforms){const i=R(o,s,a=>({...a,transform:r}));i!==o&&(o=i)}return t.state.setDocument({...e,root:o}),m()}}class Yi{groupId;id=x();label="Ungroup";parentId=null;originalIndex=-1;originalGroup=null;constructor(t){this.groupId=t}execute(t){const e=t.state.document();if(this.groupId===e.root.id)return c("UngroupCommand: cannot ungroup the document root");const o=$(e.root,this.groupId);if(o===null)return c(`UngroupCommand: group "${this.groupId}" not found`);if(!B(o))return c(`UngroupCommand: node "${this.groupId}" is not a group`);const s=T(e.root,this.groupId);if(s===null)return c(`UngroupCommand: group "${this.groupId}" has no parent`);const r=s.children.findIndex(h=>h.id===this.groupId);if(r<0)return c("UngroupCommand: failed to locate group within parent");this.parentId=s.id,this.originalIndex=r,this.originalGroup=o;const i=o.transform,a=Gi(i);let u=D(e.root,this.groupId);if(u===e.root)return c(`UngroupCommand: failed to detach group "${this.groupId}"`);const l=o.children;for(let h=0;h<l.length;h++){const f=l[h],d=a?f:{...f,transform:S(i,f.transform)};try{u=w(u,s.id,d,r+h)}catch(p){return c(p instanceof Error?p.message:String(p))}}return t.state.setDocument({...e,root:u}),m()}undo(t){if(this.parentId===null||this.originalGroup===null)return c("UngroupCommand undo: nothing captured (was execute called?)");const e=t.state.document();let o=e.root;for(const r of this.originalGroup.children){const i=D(o,r.id);if(i===o)return c(`UngroupCommand undo: child "${r.id}" not found`);o=i}const s=et(this.originalGroup.children,{id:this.originalGroup.id,transform:this.originalGroup.transform,style:this.originalGroup.style,metadata:this.originalGroup.metadata});try{o=w(o,this.parentId,s,this.originalIndex)}catch(r){return c(r instanceof Error?r.message:String(r))}return t.state.setDocument({...e,root:o}),m()}}function Gi(n){return n[0]===A[0]&&n[1]===A[1]&&n[2]===A[2]&&n[3]===A[3]&&n[4]===A[4]&&n[5]===A[5]}class Bi{nodeId;id=x();label="Convert to Layer";previousRootSnapshot=null;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(o.type!=="group")return c(`${this.label}: node "${this.nodeId}" is "${o.type}", not a group`);if(ft(o))return m();if(j(o))return c(`${this.label}: node "${this.nodeId}" is a page, not a convertible group`);const s=T(e.root,this.nodeId);if(s===null||s.id!==e.root.id&&!j(s))return c(`${this.label}: only top-level groups can become layers (node "${this.nodeId}" is nested)`);this.previousRootSnapshot=e.root;const r=R(e.root,this.nodeId,i=>Ce(i));return t.state.setDocument({...e,root:r}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Ui{nodeId;id=x();label="Convert to Group";previousRootSnapshot=null;resultNodeId=null;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(o.type!=="group")return c(`${this.label}: node "${this.nodeId}" is "${o.type}", not a group`);if(!ft(o))return m();if(o.children.length===1){const r=T(e.root,this.nodeId);if(r===null)return c(`${this.label}: layer "${this.nodeId}" has no parent`);const i=r.children.findIndex(h=>h.id===this.nodeId);if(i<0)return c(`${this.label}: failed to locate layer within parent`);const a=o.children[0],u={...a,transform:S(o.transform,a.transform)};this.previousRootSnapshot=e.root;let l=D(e.root,this.nodeId);if(l===e.root)return c(`${this.label}: failed to detach layer "${this.nodeId}"`);try{l=w(l,r.id,u,i)}catch(h){return c(h instanceof Error?h.message:String(h))}return this.resultNodeId=a.id,t.state.setDocument({...e,root:l}),m()}this.previousRootSnapshot=e.root;const s=R(e.root,this.nodeId,r=>cn(r));return this.resultNodeId=this.nodeId,t.state.setDocument({...e,root:s}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}getResultNodeId(){return this.resultNodeId}}class Xi{parentId;id=x();label="New Layer";createdLayerId=null;constructor(t=null){this.parentId=t}execute(t){const e=t.state.document(),o=this.parentId??e.root.id,s=$(e.root,o);if(s===null||s.type!=="group")return c(`${this.label}: parent "${o}" not found or not a group`);let r=0;for(const l of s.children)ft(l)&&(r+=1);const i=et([],{metadata:{name:`Layer ${r+1}`}}),a=Ce(i);this.createdLayerId=a.id;const u=w(e.root,o,a,0);return t.state.setDocument({...e,root:u}),m()}undo(t){if(this.createdLayerId===null)return c(`${this.label} undo: nothing to remove`);const e=t.state.document(),o=D(e.root,this.createdLayerId);return o===e.root?c(`${this.label} undo: created layer "${this.createdLayerId}" already gone`):(t.state.setDocument({...e,root:o}),m())}getCreatedLayerId(){return this.createdLayerId}}class Ki{snapshotId;snapshots;id=x();label="Restore Snapshot";isDestructive=!1;previousDocument=null;constructor(t,e){this.snapshotId=t,this.snapshots=e}execute(t){const e=this.snapshots.getById(this.snapshotId);return e===null?c(`${this.label}: snapshot "${this.snapshotId}" not found`):(this.previousDocument=t.state.document(),t.state.setDocument(e.document),this.snapshots.setCurrent(e.id),m())}undo(t){return this.previousDocument===null?c(`${this.label} undo: nothing captured`):(t.state.setDocument(this.previousDocument),this.snapshots.setCurrent(null),m())}}class Wi{nodeIds;name;id=x();label="Convert to Smart Object";previousRootSnapshot=null;createdWrapperId=null;constructor(t,e){this.nodeIds=t,this.name=e}execute(t){if(this.nodeIds.length===0)return c(`${this.label}: no nodes selected`);const e=t.state.document(),o=[];for(const d of this.nodeIds){const p=$(e.root,d);if(p===null)return c(`${this.label}: node "${d}" not found`);o.push(p)}const s=T(e.root,o[0].id);if(s===null)return c(`${this.label}: first node has no parent`);for(let d=1;d<o.length;d++){const p=T(e.root,o[d].id);if(p===null||p.id!==s.id)return c(`${this.label}: all selected nodes must share the same parent`)}const r=s.children.findIndex(d=>d.id===o[0].id);if(r<0)return c(`${this.label}: first node index lookup failed`);const i=this.name??this.defaultName(e.root);this.previousRootSnapshot=e.root;const a=ln(et(o,{metadata:{name:i}}));this.createdWrapperId=a.id;let u=e.root;for(const d of o)u=D(u,d.id);const l=$(u,s.id),h=l!==null&&l.type==="group"?l.children:[],f=Math.min(r,h.length);return u=w(u,s.id,a,f),t.state.setDocument({...e,root:u}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}getCreatedWrapperId(){return this.createdWrapperId}defaultName(t){let e=0;const o=s=>{if(Kt(s)&&(e+=1),s.type==="group")for(const r of s.children)o(r)};return o(t),`Smart Object ${e+1}`}}class Ao{nodeId;id=x();label="Release Smart Object";previousRootSnapshot=null;constructor(t){this.nodeId=t}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!Kt(o))return m();const s=T(e.root,this.nodeId);if(s===null)return c(`${this.label}: target has no parent`);const r=s.children.findIndex(a=>a.id===this.nodeId);if(r<0)return c(`${this.label}: index lookup failed`);this.previousRootSnapshot=e.root;let i=D(e.root,this.nodeId);for(let a=0;a<o.children.length;a++)i=w(i,s.id,o.children[a],r+a);return t.state.setDocument({...e,root:i}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class Eo{nodeId;newChildren;id=x();label="Edit Smart Object Contents";previousRootSnapshot=null;constructor(t,e){this.nodeId=t,this.newChildren=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(!Kt(o))return c(`${this.label}: target "${this.nodeId}" is not a smart object`);this.previousRootSnapshot=e.root;const s=R(e.root,this.nodeId,r=>({...r,children:this.newChildren}));return t.state.setDocument({...e,root:s}),m()}undo(t){if(this.previousRootSnapshot===null)return c(`${this.label} undo: nothing captured`);const e=this.previousRootSnapshot;if(e.type!=="group")return c(`${this.label} undo: snapshot root not a group`);const o=t.state.document();return t.state.setDocument({...o,root:e}),m()}}class qi extends Eo{label="Replace Smart Object Contents"}function nn(n,t,e){if(e===null)return c(`${t} undo: nothing captured`);if(e.type!=="group")return c(`${t} undo: snapshot root not a group`);const o=n.state.document();return n.state.setDocument({...o,root:e}),m()}class Hi{nodeId;name;value;id=x();label="Set custom attribute";snapshot=null;constructor(t,e,o){this.nodeId=t,this.name=e,this.value=o}execute(t){if(!st(this.name))return c(`${this.label}: invalid attribute name "${this.name}"`);const e=t.state.document();if($(e.root,this.nodeId)===null)return c(`${this.label}: node "${this.nodeId}" not found`);this.snapshot=e.root;const s=R(e.root,this.nodeId,r=>xn(r,this.name,this.value));return t.state.setDocument({...e,root:s}),m()}undo(t){return nn(t,this.label,this.snapshot)}}class Zi{nodeId;name;id=x();label="Remove custom attribute";snapshot=null;constructor(t,e){this.nodeId=t,this.name=e}execute(t){const e=t.state.document();if($(e.root,this.nodeId)===null)return c(`${this.label}: node "${this.nodeId}" not found`);this.snapshot=e.root;const s=R(e.root,this.nodeId,r=>bn(r,this.name));return t.state.setDocument({...e,root:s}),m()}undo(t){return nn(t,this.label,this.snapshot)}}class Qi{nodeId;from;to;id=x();label="Rename custom attribute";snapshot=null;constructor(t,e,o){this.nodeId=t,this.from=e,this.to=o}execute(t){if(!st(this.to))return c(`${this.label}: invalid attribute name "${this.to}"`);const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);const s=$n(o,this.from,this.to);if(s===o)return c(`${this.label}: "${this.from}" \u2192 "${this.to}" not applicable`);this.snapshot=e.root;const r=R(e.root,this.nodeId,()=>s);return t.state.setDocument({...e,root:r}),m()}undo(t){return nn(t,this.label,this.snapshot)}}function ht(n,t,e){if(e===null)return c(`${t} undo: nothing captured`);if(e.type!=="group")return c(`${t} undo: snapshot root not a group`);const o=n.state.document();return n.state.setDocument({...o,root:e}),m()}function Ft(n,t,e){let o=n,s=!1;for(const r of t){const i=$(o,r);if(i===null||i.type!=="path")continue;const a=e(i);a===null||a===i||(o=R(o,r,()=>a),s=!0)}return{root:o,changed:s}}class Ji{nodeIds;id=x();label="Reverse Path Direction";snapshot=null;constructor(t){this.nodeIds=t}execute(t){const e=t.state.document(),{root:o,changed:s}=Ft(e.root,this.nodeIds,r=>{const i=zn(r.d);return i===r.d?null:{...r,d:i}});return s?(this.snapshot=e.root,t.state.setDocument({...e,root:o}),m()):c(`${this.label}: no path changed`)}undo(t){return ht(t,this.label,this.snapshot)}}class ta{nodeIds;id=x();label="Clean Up Path";snapshot=null;constructor(t){this.nodeIds=t}execute(t){const e=t.state.document(),{root:o,changed:s}=Ft(e.root,this.nodeIds,r=>{const i=Yn(r.d);return i===r.d?null:{...r,d:i}});return s?(this.snapshot=e.root,t.state.setDocument({...e,root:o}),m()):c(`${this.label}: nothing to clean`)}undo(t){return ht(t,this.label,this.snapshot)}}const _o=1.5;class ea{nodeIds;tolerance;id=x();label="Simplify Path";snapshot=null;constructor(t,e=_o){this.nodeIds=t,this.tolerance=e}execute(t){const e=t.state.document(),{root:o,changed:s}=Ft(e.root,this.nodeIds,r=>{const i=Gn(r.d,this.tolerance);return i===r.d?null:{...r,d:i}});return s?(this.snapshot=e.root,t.state.setDocument({...e,root:o}),m()):c(`${this.label}: nothing to simplify`)}undo(t){return ht(t,this.label,this.snapshot)}}const Lo=10;class na{nodeIds;distance;id=x();label="Offset Path";snapshot=null;constructor(t,e=Lo){this.nodeIds=t,this.distance=e}execute(t){const e=t.state.document(),{root:o,changed:s}=Ft(e.root,this.nodeIds,r=>{const i=Hn(r.d,this.distance);return i===r.d?null:{...r,d:i}});return s?(this.snapshot=e.root,t.state.setDocument({...e,root:o}),m()):c(`${this.label}: nothing to offset`)}undo(t){return ht(t,this.label,this.snapshot)}}class oa{nodeIds;id=x();label="Outline Stroke";snapshot=null;constructor(t){this.nodeIds=t}execute(t){const e=t.state.document(),{root:o,changed:s}=Ft(e.root,this.nodeIds,r=>{const i=r.style.stroke,a=r.style.strokeWidth??1;if(typeof i!="string"||i==="none"||i.trim()===""||a<=0)return null;const u=Zn(r.d,a);if(u.length===0)return null;const l={...r.style},h=l;return h.fill=i,r.style.strokeOpacity!==void 0&&(h.fillOpacity=r.style.strokeOpacity),delete h.stroke,delete h.strokeWidth,delete h.strokeOpacity,delete h.strokeDasharray,delete h.strokeLinecap,delete h.strokeLinejoin,{...r,d:u,style:l}});return s?(this.snapshot=e.root,t.state.setDocument({...e,root:o}),m()):c(`${this.label}: no strokable path in selection`)}undo(t){return ht(t,this.label,this.snapshot)}}class sa{nodeIds;id=x();label="Join Path";snapshot=null;constructor(t){this.nodeIds=t}execute(t){const e=t.state.document(),o=[];for(const d of this.nodeIds){const p=$(e.root,d);p!==null&&p.type==="path"&&o.push(p)}if(o.length===0)return c(`${this.label}: no path selected`);if(o.length===1){const d=o[0],p=je([d.d]);if(p===null||p===d.d)return c(`${this.label}: nothing to join`);this.snapshot=e.root;const y=R(e.root,d.id,g=>({...g,d:p}));return t.state.setDocument({...e,root:y}),m()}const s=o.map(d=>Je(d.d,d.transform)),r=je(s);if(r===null)return c(`${this.label}: nothing to join`);const i=o[0],a=T(e.root,i.id);if(a===null)return c(`${this.label}: operand A has no parent`);const u=a.children.findIndex(d=>d.id===i.id);if(u<0)return c(`${this.label}: operand A index lookup failed`);this.snapshot=e.root;const h={...tt(r),id:i.id,transform:[1,0,0,1,0,0],style:i.style,metadata:i.metadata};let f=D(e.root,i.id);f=w(f,a.id,h,u);for(let d=1;d<o.length;d++)f=D(f,o[d].id);return t.state.setDocument({...e,root:f}),m()}undo(t){return ht(t,this.label,this.snapshot)}}class ra{nodeId;cuts;id=x();label="Split Path";snapshot=null;constructor(t,e){this.nodeId=t,this.cuts=e}execute(t){const e=t.state.document(),o=$(e.root,this.nodeId);if(o===null)return c(`${this.label}: node "${this.nodeId}" not found`);if(o.type!=="path")return c(`${this.label}: only paths can be split`);if(this.cuts.length===0)return c(`${this.label}: no cut points`);const s=Xn(o.d,this.cuts);if(s===null||s.length<2)return c(`${this.label}: nothing to split`);const r=T(e.root,this.nodeId);if(r===null)return c(`${this.label}: node has no parent`);const i=r.children.findIndex(l=>l.id===this.nodeId);if(i<0)return c(`${this.label}: index lookup failed`);this.snapshot=e.root;const a=s.map((l,h)=>{const f=tt(l);return{...f,id:h===0?o.id:f.id,transform:o.transform,style:o.style,metadata:o.metadata}});let u=D(e.root,this.nodeId);for(let l=0;l<a.length;l++)u=w(u,r.id,a[l],i+l);return t.state.setDocument({...e,root:u}),m()}undo(t){return ht(t,this.label,this.snapshot)}}class vt{_document=ot(Ze(),...ngDevMode?[{debugName:"_document"}]:[]);_dirty=ot(!1,...ngDevMode?[{debugName:"_dirty"}]:[]);document=this._document.asReadonly();dirty=this._dirty.asReadonly();nodeCount=Dt(()=>go(this._document().root),...ngDevMode?[{debugName:"nodeCount"}]:[]);allNodes=Dt(()=>yo(this._document().root),...ngDevMode?[{debugName:"allNodes"}]:[]);setDocument(t){this._document.set(t),this._dirty.set(!0)}resetDocument(t=Ze()){this._document.set(t),this._dirty.set(!1)}markClean(){this._dirty.set(!1)}static \u0275fac=O.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:vt,deps:[],target:O.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=O.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:vt,providedIn:"root"})}O.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:vt,decorators:[{type:zt,args:[{providedIn:"root"}]}]});const ia=100,jo=1;class Ct{_undoStack=ot([],...ngDevMode?[{debugName:"_undoStack"}]:[]);_redoStack=ot([],...ngDevMode?[{debugName:"_redoStack"}]:[]);_maxSize=ot(ia,...ngDevMode?[{debugName:"_maxSize"}]:[]);undoStack=this._undoStack.asReadonly();redoStack=this._redoStack.asReadonly();maxSize=this._maxSize.asReadonly();canUndo=Dt(()=>this._undoStack().length>0,...ngDevMode?[{debugName:"canUndo"}]:[]);canRedo=Dt(()=>this._redoStack().length>0,...ngDevMode?[{debugName:"canRedo"}]:[]);push(t){this._undoStack.update(e=>on([...e,t],this._maxSize())),this._redoStack.set([])}peekUndo(){return this._undoStack().at(-1)??null}peekRedo(){return this._redoStack().at(-1)??null}commitUndo(){const t=this._undoStack(),e=t.at(-1);e&&(this._undoStack.set(t.slice(0,-1)),this._redoStack.update(o=>[...o,e]))}commitRedo(){const t=this._redoStack(),e=t.at(-1);e&&(this._redoStack.set(t.slice(0,-1)),this._undoStack.update(o=>on([...o,e],this._maxSize())))}clear(){this._undoStack.set([]),this._redoStack.set([])}setMaxSize(t){if(!Number.isFinite(t)||t<jo)throw new RangeError(`HistoryService.setMaxSize: size must be >= ${jo}`);const e=Math.trunc(t);this._maxSize.set(e),this._undoStack.update(o=>on(o,e))}static \u0275fac=O.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Ct,deps:[],target:O.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=O.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Ct,providedIn:"root"})}O.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Ct,decorators:[{type:zt,args:[{providedIn:"root"}]}]});function on(n,t){return n.length<=t?n:n.slice(n.length-t)}const Fo=Object.freeze({maxCount:50,autoOnOpen:!0,autoOnDestructive:!1});class Rt{_snapshots=ot([],...ngDevMode?[{debugName:"_snapshots"}]:[]);_limits=ot(Fo,...ngDevMode?[{debugName:"_limits"}]:[]);_currentId=ot(null,...ngDevMode?[{debugName:"_currentId"}]:[]);snapshots=this._snapshots.asReadonly();count=Dt(()=>this._snapshots().length,...ngDevMode?[{debugName:"count"}]:[]);limits=this._limits.asReadonly();currentSnapshotId=this._currentId.asReadonly();take(t,e={}){const o=e.source??"manual",s=e.name??this.defaultName(o),r={id:x(),name:s,createdAt:Date.now(),document:t,thumbnail:null,source:o},i=this._snapshots(),a=this._limits().maxCount;let u=[r,...i];if(u.length>a){for(let l=u.length-1;l>=0;l--)if(u[l].source!=="auto-open"){u=[...u.slice(0,l),...u.slice(l+1)];break}u.length>a&&(u=u.slice(0,a))}return this._snapshots.set(u),r}attachThumbnail(t,e){const o=this._snapshots(),s=o.findIndex(i=>i.id===t);if(s<0)return!1;const r={...o[s],thumbnail:e};return this._snapshots.set([...o.slice(0,s),r,...o.slice(s+1)]),!0}rename(t,e){const o=e.trim();if(o.length===0)return!1;const s=this._snapshots(),r=s.findIndex(a=>a.id===t);if(r<0)return!1;const i={...s[r],name:o};return this._snapshots.set([...s.slice(0,r),i,...s.slice(r+1)]),!0}delete(t){const e=this._snapshots(),o=e.filter(s=>s.id!==t);return o.length===e.length?!1:(this._snapshots.set(o),this._currentId()===t&&this._currentId.set(null),!0)}clear(){this._snapshots().length!==0&&(this._snapshots.set([]),this._currentId.set(null))}setCurrent(t){this._currentId.set(t)}getById(t){return this._snapshots().find(e=>e.id===t)??null}setLimits(t){const e=this._limits(),o={...e,...t};if(o.maxCount===e.maxCount&&o.autoOnOpen===e.autoOnOpen&&o.autoOnDestructive===e.autoOnDestructive)return;this._limits.set(o);const s=this._snapshots();if(s.length>o.maxCount){const r=s.filter(u=>u.source==="auto-open"),a=s.filter(u=>u.source!=="auto-open").slice(0,Math.max(0,o.maxCount-r.length));this._snapshots.set([...a,...r.slice(0,o.maxCount-a.length)])}}hydrate(t){this._snapshots.set(t),this._currentId.set(null)}bootstrap(t){this._limits().autoOnOpen&&(this._snapshots().some(e=>e.source==="auto-open")||this.take(t,{name:"Opened",source:"auto-open"}))}defaultName(t){switch(t){case"auto-open":return"Opened";case"auto-destructive":return"Before edit";case"auto-restore":return"Before restore";default:return`Snapshot ${this._snapshots().filter(o=>o.source==="manual").length+1}`}}static \u0275fac=O.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Rt,deps:[],target:O.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=O.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Rt})}O.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Rt,decorators:[{type:zt}]});class Vt{state=Yt(vt);history=Yt(Ct);snapshots=Yt(Rt,{optional:!0});parentResolver=Yt(xo,{optional:!0});dispatch(t,e){const o=e?.recordHistory??!0;o&&this.maybeAutoSnapshot(t);const s=t.execute(this.buildContext());return s.ok&&o&&this.history.push(t),s}buildContext(){return this.parentResolver===null?{state:this.state}:{state:this.state,parentResolver:this.parentResolver}}maybeAutoSnapshot(t){if(t.isDestructive!==!0)return;const e=this.snapshots;e!==null&&e.limits().autoOnDestructive&&e.take(this.state.document(),{name:`Before ${t.label}`,source:"auto-destructive"})}undo(){const t=this.history.peekUndo();if(t===null)return c("Nothing to undo");const e=t.undo(this.buildContext());return e.ok&&this.history.commitUndo(),e}redo(){const t=this.history.peekRedo();if(t===null)return c("Nothing to redo");const e=t.execute(this.buildContext());return e.ok&&this.history.commitRedo(),e}goto(t){const e=this.history.undoStack().length+this.history.redoStack().length,o=Math.max(0,Math.min(Math.trunc(t),e));let s=0;for(;this.history.undoStack().length>o&&this.undo().ok;)s+=1;for(;this.history.undoStack().length<o&&this.redo().ok;)s+=1;return s}static \u0275fac=O.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Vt,deps:[],target:O.\u0275\u0275FactoryTarget.Injectable});static \u0275prov=O.\u0275\u0275ngDeclareInjectable({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Vt,providedIn:"root"})}O.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.13",ngImport:O,type:Vt,decorators:[{type:zt,args:[{providedIn:"root"}]}]});export{Ye as ANIMATION_KEY,Mo as AUTO_PARENT,Ai as AddKeyframeCommand,kr as BatchConvertToPathCommand,te as CUSTOM_ATTR_DATA_PREFIX,ta as CleanUpPathCommand,Vt as CommandBus,$r as ConvertAnchorTypeCommand,bo as ConvertNodeToPathCommand,Xi as CreateLayerCommand,vi as CreatePageCommand,Qn as DEFAULT_EASING,Lo as DEFAULT_OFFSET_DISTANCE,ct as DEFAULT_PAGE_OPTIONS,_o as DEFAULT_SIMPLIFY_TOLERANCE,Fo as DEFAULT_SNAPSHOT_LIMITS,H as DEFAULT_STYLE,Io as DEFAULT_VIEW_BOX,Ci as DeletePageCommand,Xr as DivideCommand,zr as DuplicateNodeCommand,W as EMPTY_METADATA,rn as EMPTY_STYLE,Eo as EditSmartObjectContentsCommand,vt as EditorStateService,Mi as EnsureDefaultPageCommand,Ur as ExcludeCommand,pi as FlipNodeCommand,qr as GroupSelectionCommand,Ct as HistoryService,A as IDENTITY_TRANSFORM,xo as INSERT_PARENT_RESOLVER,Ir as InsertAnchorCommand,Hr as InsertNodeCommand,Gr as IntersectCommand,sa as JoinPathsCommand,mi as KnifeCutPathCommand,Ie as LIVE_BOOLEAN_KEY,xt as LIVE_BOOLEAN_ROLE_KEY,Mr as MakeClipMaskCommand,Or as MakeCompoundPathCommand,Bi as MakeLayerCommand,Er as MakeLiveBooleanCommand,Wi as MakeSmartObjectCommand,yr as MoveAnchorCommand,Ei as MoveKeyframeCommand,Zr as MoveNodeCommand,Qr as MoveNodeInTreeCommand,ki as MovePageCommand,Wo as ORIGIN,na as OffsetPathCommand,oa as OutlineStrokeCommand,gn as PAGE_BACKGROUND_IMAGE_PAR,Zt as PAGE_FORMAT_SIZES,Dr as RasterizeNodeCommand,Ao as RasterizeSmartObjectCommand,_r as RefreshLiveBooleanCommand,Pr as ReleaseClipMaskCommand,Tr as ReleaseCompoundPathCommand,Lr as ReleaseLiveBooleanCommand,Ao as ReleaseSmartObjectCommand,br as RemoveAnchorCommand,Zi as RemoveCustomAttrCommand,_i as RemoveKeyframeCommand,Jr as RemoveNodeCommand,Fi as RemoveTrackCommand,Qi as RenameCustomAttrCommand,Ri as RenamePageCommand,ti as ReorderNodeCommand,qi as ReplaceSmartObjectContentsCommand,ni as ResizeNodeCommand,si as ResizeNodesCommand,Si as ResizePageCommand,Ki as RestoreSnapshotCommand,Ji as ReversePathCommand,ii as RotateNodeCommand,ui as RotateNodesCommand,pe as STYLE_PROPERTY_NAMES,Jt as SVGE_CUSTOM_ATTRS_KEY,X as SVGE_KIND_KEY,ve as SVGE_KIND_LAYER,Wt as SVGE_KIND_PAGE,Xt as SVGE_KIND_SMART_OBJECT,pt as SVGE_PAGE_NAME_KEY,Re as SVGE_PAGE_OPTIONS_KEY,Nt as SVGE_PAGE_VIEWBOX_KEY,Jo as SVG_NODE_TYPES,ji as SetAnimationDurationCommand,Ti as SetCornerRadiusCommand,Hi as SetCustomAttrCommand,Li as SetKeyframeEasingCommand,Di as SetPageOptionsCommand,Pi as SetPropertyCommand,Oi as SetPropertyOnManyCommand,Vi as SetStylePropertyOnManyCommand,ea as SimplifyPathCommand,ci as SkewNodeCommand,hi as SkewNodesCommand,Rt as SnapshotsService,ra as SplitPathCommand,Br as SubtractCommand,fe as TRANSFORM_PROPERTY_NAMES,zi as TranslateManyCommand,Yi as UngroupCommand,Yr as UnionCommand,Ui as UnmakeLayerCommand,Z as anchorsToPathD,co as animatablePropertiesForNode,pr as animationToSmil,$o as appendDef,er as applyAnimationToTree,dn as applyTransform,kn as bakeEllipse,On as bakeGroup,Mn as bakeImage,Dn as bakeLine,Tn as bakePath,Rn as bakePathD,wn as bakePolygon,Nn as bakePolyline,Sn as bakeRect,Oe as bakeScaleIntoNode,Pn as bakeText,Je as bakeTransformIntoPathD,Gt as bbox,Ae as classifyAnchorKind,Yn as cleanUpPathD,He as cloneNodeWithNewIds,yo as collectNodes,be as composeAnchoredScale,Oo as composePivotFlip,tn as composePivotRotation,en as composePivotSkew,An as composeTransform,Bo as containsPoint,go as countNodes,rs as createEllipse,Ze as createEmptyDocument,et as createGroup,yn as createImage,is as createLine,tt as createPath,as as createPolygon,us as createPolyline,mn as createRect,cs as createSymbolUse,ds as createText,fs as customAttrToDataName,ps as dataNameToCustomAttr,oe as decomposeTransform,pn as detectPageFormat,Ve as easingControlPoints,to as emptyAnimationDoc,Jn as evalEasing,Nr as extractDefById,c as fail,Js as findAnimatableProperty,$ as findNodeById,T as findParent,At as findTrack,Tt as flattenPathD,x as generateNodeId,Do as getLiveBooleanOp,Te as getNodeBBox,Ps as getNodesWorldBBox,ls as getPageBackgroundNode,hn as getPageName,Ht as getPageOptions,Mt as getPageViewBox,ms as hasCustomAttrs,w as insertNode,ao as interpolateValue,Uo as intersectsBBox,Bt as invert,no as isAnimationDoc,B as isGroupNode,qo as isIdentity,Pe as isIdentityOrTranslate,ft as isLayer,xe as isLiveBooleanGroup,j as isPage,Kt as isSmartObject,st as isValidCustomAttrName,je as joinPathDs,uo as mixColor,so as moveKeyframe,S as multiply,It as nodeToPathD,ce as offsetClosedRing,Hn as offsetPathD,de as offsetPolyline,m as ok,Zn as outlineStrokeToPathD,De as pageFormatSize,we as pageOrientationFromSize,Ue as parseColor,ne as parsePathD,K as parsePathToAnchors,Ho as parseTransformAttr,tr as readAnimatableValue,eo as readAnimationDoc,Pt as readCustomAttrs,bn as removeCustomAttr,Co as removeDefById,Be as removeKeyframe,D as removeNode,oo as removeTrack,$n as renameCustomAttr,zn as reversePathD,Ee as ringsToPathD,wt as rotate,Ts as roundPathCorners,Us as sampleAnimation,he as sampleTrack,dt as scale,Ot as scaleAxisInterval,Cn as scalePathSegments,lt as scalePoint,vn as serializePathD,io as setAnimationDuration,xn as setCustomAttr,ro as setKeyframeEasing,Bn as simplifyAnchorSubpath,Gn as simplifyPathD,an as skewX,un as skewY,Xn as splitPathDAtAnchors,ko as splitPathDIntoSubpaths,Xo as toNodeId,F as translate,$e as unionBBox,Ro as unwrapUrlRef,R as updateNode,Ge as upsertKeyframe,qe as walk,ee as withCustomAttrs,Ce as withLayerFlag,Se as withPageFlag,fn as withPageName,ke as withPageOptions,qt as withPageViewBox,ln as withSmartObjectFlag,cn as withoutLayerFlag,es as withoutPageFlag,ts as withoutSmartObjectFlag};