@jutge.org/toolkit 4.2.27 → 4.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3835,7 +3835,7 @@ main = do
|
|
|
3835
3835
|
\\SampleTwoColInputOutput[${H}]{${K}}{${v}}
|
|
3836
3836
|
`),v++}return[w.join(`
|
|
3837
3837
|
`),q.join(`
|
|
3838
|
-
`)]}async makePdfStatement(f,$){let Z=c3(f,$);await Mc(Z);let w=new Date().toISOString(),q=new Date().getFullYear(),v=this.problem.problemLangYmls[this.problem.originalLanguage].author||"Unknown",K=this.problem.problemLangYmls[this.problem.originalLanguage].author_email||"unknown email",H=this.problem.problemLangYmls[$].translator||"",[Y,P]=await this.makeSamples(Z,$),M=await V5(c3(bV2,"root-pdf.tpl.tex"));Wc.default.registerHelper("curly",function(O){return"{"+O+"}"});let W=Wc.default.compile(M)({language:$,jutgeLanguage:`jutge.${$}`,id:`${this.problem_nm}\\_${$}`,samples1c:Y,samples2c:P,author:v,translator:H,date:w,year:q});for await(let O of bY1("*",{cwd:this.problem.directory})){if(O.startsWith(D0())||O.endsWith(".exe")||O.endsWith(".html")||O.endsWith(".md")||O.endsWith(".txt")||await O81(this.problem.directory,O))continue;await Iq(c3(this.problem.directory,O),c3(Z,O))}if(await Sr(c3(Z,`original.${$}.pdf`))){L.warning(`Found original.${$}.pdf`),await Iq(c3(Z,`original.${$}.pdf`),c3(this.problem.directory,`problem.${$}.pdf`));return}await m7(c3(Z,"root.tex"),W);let X=(await V5(c3(Z,`problem.${$}.tex`))).replace(/\\begin{htmlonly}[\s\S]*?\\end{htmlonly}/g,"").replace(/\\begin{latexonly}/g,"").replace(/\\end{latexonly}/g,"").replace(/\.eps}/g,"}");if(await m7(c3(Z,`problem.${$}.tex`),X),await this.copyStyleFiles(Z,$),!await wV2()){L.error("xelatex not found");return}try{L.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error root.tex"),await K3({stderr:"inherit",cwd:Z})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error root.tex`,await Iq(c3(Z,"root.pdf"),c3(this.problem.directory,`problem.${$}.pdf`)),L.success(`Generated ${L.hyperlink(this.problem.directory,`problem.${$}.pdf`)} see ${L.hyperlink(Z,"root.log")}`)}catch(O){L.error(`Error in LaTeX: ${L.hyperlink(Z,"root.log")}`)}}async copyStyleFiles(f,$){let Z=async(w)=>{let q=c3(R7(),"assets","sty",w);await Iq(q,c3(f,w))};if(await Z("picins.sty"),await Z("jutge.sty"),$==="ca")await Z("jutge.ca.sty");if($==="es")await Z("jutge.es.sty");if($==="en")await Z("jutge.en.sty");if($==="fr")await Z("jutge.fr.sty");if($==="de")await Z("jutge.de.sty")}async makeFullTextualStatements(f=["txt","html","md"]){await this.makeTextualStatements(f,"full")}async makeShortTextualStatements(f=["txt","html","md"]){await this.makeTextualStatements(f,"short")}async makeTextualStatements(f=["txt","html","md"],$){await L.section(`Making textual statements (${$})`,async()=>{let Z=c3(this.problem.directory,D0()+"-text",A_());await Mc(Z,{recursive:!0}),await L.section("Creating working directory",async()=>{await J5(),L.directory(Z)});try{for(let w of this.problem.languages)if(this.problem.structure==="multi"||this.problem.structure==="single"&&w===this.problem.language)await L.section(`Making ${$} textual statements for ${B0[w]}`,async()=>{await this.makeTextualStatement(Z,w,f,$)})}finally{}})}async makeTextualStatement(f,$,Z,w){let q=c3(f,$);await Mc(q);let v=new Date().toISOString(),K=new Date().getFullYear(),H=this.problem.problemLangYmls[$].author||"Unknown",Y=this.problem.problemLangYmls[$].author_email||"unknown email",P=this.problem.problemLangYmls[$].translator||"",M=await V5(c3(bV2,`root-text-${w}.tpl.tex`));Wc.default.registerHelper("curly",function(V){return"{"+V+"}"});let W=Wc.default.compile(M)({language:$,jutgeLanguage:`jutge.${$}`,id:`${this.problem_nm}\\_${$}`,year:K,author:H,translator:P,date:v});for await(let V of bY1("*",{cwd:this.problem.directory})){if(V.startsWith(D0())||V.endsWith(".exe")||V.endsWith(".html")||V.endsWith(".md")||V.endsWith(".txt")||await O81(this.problem.directory,V))continue;await Iq(c3(this.problem.directory,V),c3(q,V))}if(await Sr(c3(q,`original.${$}.pdf`))){L.warning(`Found original.${$}.pdf`);return}let J=w==="full"?`problem.${$}`:`problem.${$}.short`;await m7(c3(q,"root.tex"),W);let O=(await V5(c3(q,`problem.${$}.tex`))).replace(/\\begin{latexonly}[\s\S]*?\\end{latexonly}/g,"").replace(/\\begin{htmlonly}/g,"").replace(/\\end{htmlonly}/g,"").replace(/\\begin{minipage}/g,"").replace(/\\end{minipage}/g,"");if(await m7(c3(q,`problem.${$}.tex`),O),await this.copyStyleFiles(q,$),!await vV2()){L.error("pandoc with lua support not found");return}let G=c3(R7(),"assets","lua","fixCodeBlocks.lua");if(await Iq(G,c3(q,"fixCodeBlocks.lua")),Z.includes("txt"))try{L.command("pandoc --sandbox --quiet root.tex --to plain --output root.txt"),await K3({cwd:q})`pandoc --sandbox --quiet root.tex --to plain --output root.txt`,await Iq(c3(q,"root.txt"),c3(this.problem.directory,`${J}.txt`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.txt`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}if(Z.includes("md"))try{L.command("pandoc --sandbox --quiet root.tex --to markdown --to markdown-header_attributes --lua-filter=fixCodeBlocks.lua --output root.md"),await K3({cwd:q})`pandoc --sandbox --quiet root.tex --to markdown --to markdown-header_attributes --lua-filter=fixCodeBlocks.lua --output root.md`,await Iq(c3(q,"root.md"),c3(this.problem.directory,`${J}.md`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.md`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}if(Z.includes("html"))try{L.command("pandoc --sandbox --quiet root.tex --to html --mathml --embed-resources --output root.html"),await K3({cwd:q})`pandoc --sandbox --quiet root.tex --to html --mathml --embed-resources --output root.html`,await Iq(c3(q,"root.html"),c3(this.problem.directory,`${J}.html`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.html`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}}async verifyCandidate(f){await L.section(`Verifying ${f}`,async()=>{let $=f.split(".").pop(),Z=jY1[$];if(!Z)throw Error(`No compiler found for .${$} files`);if(!await Z()){L.warning(`Compiler for .${$} files is not available, skipping verification of ${f}`);return}let w=lY1($),q=`${D0()}-${f}`;await L.section(`Copying ${L.hyperlink(this.problem.directory,f)} to ${L.hyperlink(this.problem.directory,q)}`,async()=>{await Iq(c3(this.problem.directory,f),c3(this.problem.directory,q))}),await L.section(`Using compiler ${w.name()} to compile ${L.hyperlink(this.problem.directory,q)}`,async()=>{try{let K;if(this.problem.handler.source_modifier==="none")K=await w.compileNormal(this.problem.handler,this.problem.directory,q);else if(this.problem.handler.source_modifier==="no_main")K=await w.compileWithMain(this.problem.handler,this.problem.directory,q);else throw Error(`Unknown source modifier: ${this.problem.handler.source_modifier}`);if(!await Sr(c3(this.problem.directory,K)))throw Error(`Compilation failed for ${q}`);L.success(`Compiled ${q} to ${K}`)}catch(K){throw Error(`Compilation failed: ${K}`)}});let v=[];await L.section("Executing testcases",async()=>{for(let H of this.problem.testcases)v.push(await this.runTestcase(H,`${H}.inp`,`${D0()}-${H}.${$}.out`,w,q));L.print(),L.print("testcase time status");let K=0;for(let H of v){let Y=H.error?"EE":await fI1(c3(this.problem.directory,`${H.testcase}.cor`),c3(this.problem.directory,`${D0()}-${H.testcase}.${$}.out`))?"OK":"WA",P=LG(H.time);if(L.print((Y!=="OK"?P0.red:P0.green)(`${H.testcase.padEnd(12)} ${P.padStart(10)} ${Y.padStart(10)}`)),Y!=="OK")K++}if(L.print(),K)L.error(`${K} errors found for ${f}`);else L.success(`All testcases passed successfully for ${f}`)})})}async makeTarFiles(){let{handler:f,directory:$}=this.problem,{compilers:Z}=f;if(Z==="PRO2"||Z==="MakePRO2")await L.section("Making `.tar` files",async()=>{for(let w of["public","private","solution"])if(await BZ($,w)){let{exitCode:q}=await K3({reject:!1,stderr:"inherit",stdout:"inherit",cwd:c3($,w)})`tar cf ../${w}.tar .`;if(q!==0)throw console.log(q),Error(`Error making ${w}.tar`);L.success(`Created ${L.hyperlink($,`${w}.tar`)}`)}})}}var yV2=new g6("verify").description("Verify programs against golden solution").argument("<programs...>","source programs to verify").option("-d, --directory <path>","problem directory",".").action(async(f,{directory:$})=>{let Z=await gr($);for(let w of f)await Z.verifyCandidate(w)});import yi4 from"path";var Jc=(f,$=[])=>f.name==="up"||$.includes("vim")&&f.name==="k"||$.includes("emacs")&&f.ctrl&&f.name==="p",cr=(f,$=[])=>f.name==="down"||$.includes("vim")&&f.name==="j"||$.includes("emacs")&&f.ctrl&&f.name==="n",uY1=(f)=>f.name==="space";var yY1=(f)=>"1234567890".includes(f.name),kY1=(f)=>f.name==="enter"||f.name==="return";class mY1 extends Error{name="AbortPromptError";message="Prompt was aborted";constructor(f){super();this.cause=f?.cause}}class xY1 extends Error{name="CancelPromptError";message="Prompt was canceled"}class br extends Error{name="ExitPromptError"}class BY1 extends Error{name="HookError"}class hc extends Error{name="ValidationError"}import{AsyncResource as MF4}from"async_hooks";import{AsyncLocalStorage as HF4,AsyncResource as YF4}from"async_hooks";var kV2=new HF4;function PF4(f){return{rl:f,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function mV2(f,$){let Z=PF4(f);return kV2.run(Z,()=>{function w(q){Z.handleChange=()=>{Z.index=0,q()},Z.handleChange()}return $(w)})}function Tz(){let f=kV2.getStore();if(!f)throw new BY1("[Inquirer] Hook functions can only be called from within a prompt");return f}function dY1(){return Tz().rl}function FY1(f){let $=(...Z)=>{let w=Tz(),q=!1,v=w.handleChange;w.handleChange=()=>{q=!0};let K=f(...Z);if(q)v();return w.handleChange=v,K};return YF4.bind($)}function LN(f){let $=Tz(),{index:Z}=$,w={get(){return $.hooks[Z]},set(v){$.hooks[Z]=v},initialized:Z in $.hooks},q=f(w);return $.index++,q}function xV2(){Tz().handleChange()}var Vz={queue(f){let $=Tz(),{index:Z}=$;$.hooksEffect.push(()=>{$.hooksCleanup[Z]?.();let w=f(dY1());if(w!=null&&typeof w!=="function")throw new hc("useEffect return value must be a cleanup function or nothing.");$.hooksCleanup[Z]=w})},run(){let f=Tz();FY1(()=>{f.hooksEffect.forEach(($)=>{$()}),f.hooksEffect.length=0})()},clearAll(){let f=Tz();f.hooksCleanup.forEach(($)=>{$?.()}),f.hooksEffect.length=0,f.hooksCleanup.length=0}};function WK(f){return LN(($)=>{let Z=MF4.bind(function(v){if($.get()!==v)$.set(v),xV2()});if($.initialized)return[$.get(),Z];let w=typeof f==="function"?f():f;return $.set(w),[w,Z]})}function ur(f,$){LN((Z)=>{let w=Z.get();if(!Array.isArray(w)||$.some((v,K)=>!Object.is(v,w[K])))Vz.queue(f);Z.set($)})}import{styleText as JK}from"util";import dH from"process";function WF4(){if(dH.platform!=="win32")return dH.env.TERM!=="linux";return Boolean(dH.env.WT_SESSION)||Boolean(dH.env.TERMINUS_SUBLIME)||dH.env.ConEmuTask==="{cmd::Cmder}"||dH.env.TERM_PROGRAM==="Terminus-Sublime"||dH.env.TERM_PROGRAM==="vscode"||dH.env.TERM==="xterm-256color"||dH.env.TERM==="alacritty"||dH.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var BV2={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"\u2588",squareDarkShade:"\u2593",squareMediumShade:"\u2592",squareLightShade:"\u2591",squareTop:"\u2580",squareBottom:"\u2584",squareLeft:"\u258C",squareRight:"\u2590",squareCenter:"\u25A0",bullet:"\u25CF",dot:"\u2024",ellipsis:"\u2026",pointerSmall:"\u203A",triangleUp:"\u25B2",triangleUpSmall:"\u25B4",triangleDown:"\u25BC",triangleDownSmall:"\u25BE",triangleLeftSmall:"\u25C2",triangleRightSmall:"\u25B8",home:"\u2302",heart:"\u2665",musicNote:"\u266A",musicNoteBeamed:"\u266B",arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",arrowLeftRight:"\u2194",arrowUpDown:"\u2195",almostEqual:"\u2248",notEqual:"\u2260",lessOrEqual:"\u2264",greaterOrEqual:"\u2265",identical:"\u2261",infinity:"\u221E",subscriptZero:"\u2080",subscriptOne:"\u2081",subscriptTwo:"\u2082",subscriptThree:"\u2083",subscriptFour:"\u2084",subscriptFive:"\u2085",subscriptSix:"\u2086",subscriptSeven:"\u2087",subscriptEight:"\u2088",subscriptNine:"\u2089",oneHalf:"\xBD",oneThird:"\u2153",oneQuarter:"\xBC",oneFifth:"\u2155",oneSixth:"\u2159",oneEighth:"\u215B",twoThirds:"\u2154",twoFifths:"\u2156",threeQuarters:"\xBE",threeFifths:"\u2157",threeEighths:"\u215C",fourFifths:"\u2158",fiveSixths:"\u215A",fiveEighths:"\u215D",sevenEighths:"\u215E",line:"\u2500",lineBold:"\u2501",lineDouble:"\u2550",lineDashed0:"\u2504",lineDashed1:"\u2505",lineDashed2:"\u2508",lineDashed3:"\u2509",lineDashed4:"\u254C",lineDashed5:"\u254D",lineDashed6:"\u2574",lineDashed7:"\u2576",lineDashed8:"\u2578",lineDashed9:"\u257A",lineDashed10:"\u257C",lineDashed11:"\u257E",lineDashed12:"\u2212",lineDashed13:"\u2013",lineDashed14:"\u2010",lineDashed15:"\u2043",lineVertical:"\u2502",lineVerticalBold:"\u2503",lineVerticalDouble:"\u2551",lineVerticalDashed0:"\u2506",lineVerticalDashed1:"\u2507",lineVerticalDashed2:"\u250A",lineVerticalDashed3:"\u250B",lineVerticalDashed4:"\u254E",lineVerticalDashed5:"\u254F",lineVerticalDashed6:"\u2575",lineVerticalDashed7:"\u2577",lineVerticalDashed8:"\u2579",lineVerticalDashed9:"\u257B",lineVerticalDashed10:"\u257D",lineVerticalDashed11:"\u257F",lineDownLeft:"\u2510",lineDownLeftArc:"\u256E",lineDownBoldLeftBold:"\u2513",lineDownBoldLeft:"\u2512",lineDownLeftBold:"\u2511",lineDownDoubleLeftDouble:"\u2557",lineDownDoubleLeft:"\u2556",lineDownLeftDouble:"\u2555",lineDownRight:"\u250C",lineDownRightArc:"\u256D",lineDownBoldRightBold:"\u250F",lineDownBoldRight:"\u250E",lineDownRightBold:"\u250D",lineDownDoubleRightDouble:"\u2554",lineDownDoubleRight:"\u2553",lineDownRightDouble:"\u2552",lineUpLeft:"\u2518",lineUpLeftArc:"\u256F",lineUpBoldLeftBold:"\u251B",lineUpBoldLeft:"\u251A",lineUpLeftBold:"\u2519",lineUpDoubleLeftDouble:"\u255D",lineUpDoubleLeft:"\u255C",lineUpLeftDouble:"\u255B",lineUpRight:"\u2514",lineUpRightArc:"\u2570",lineUpBoldRightBold:"\u2517",lineUpBoldRight:"\u2516",lineUpRightBold:"\u2515",lineUpDoubleRightDouble:"\u255A",lineUpDoubleRight:"\u2559",lineUpRightDouble:"\u2558",lineUpDownLeft:"\u2524",lineUpBoldDownBoldLeftBold:"\u252B",lineUpBoldDownBoldLeft:"\u2528",lineUpDownLeftBold:"\u2525",lineUpBoldDownLeftBold:"\u2529",lineUpDownBoldLeftBold:"\u252A",lineUpDownBoldLeft:"\u2527",lineUpBoldDownLeft:"\u2526",lineUpDoubleDownDoubleLeftDouble:"\u2563",lineUpDoubleDownDoubleLeft:"\u2562",lineUpDownLeftDouble:"\u2561",lineUpDownRight:"\u251C",lineUpBoldDownBoldRightBold:"\u2523",lineUpBoldDownBoldRight:"\u2520",lineUpDownRightBold:"\u251D",lineUpBoldDownRightBold:"\u2521",lineUpDownBoldRightBold:"\u2522",lineUpDownBoldRight:"\u251F",lineUpBoldDownRight:"\u251E",lineUpDoubleDownDoubleRightDouble:"\u2560",lineUpDoubleDownDoubleRight:"\u255F",lineUpDownRightDouble:"\u255E",lineDownLeftRight:"\u252C",lineDownBoldLeftBoldRightBold:"\u2533",lineDownLeftBoldRightBold:"\u252F",lineDownBoldLeftRight:"\u2530",lineDownBoldLeftBoldRight:"\u2531",lineDownBoldLeftRightBold:"\u2532",lineDownLeftRightBold:"\u252E",lineDownLeftBoldRight:"\u252D",lineDownDoubleLeftDoubleRightDouble:"\u2566",lineDownDoubleLeftRight:"\u2565",lineDownLeftDoubleRightDouble:"\u2564",lineUpLeftRight:"\u2534",lineUpBoldLeftBoldRightBold:"\u253B",lineUpLeftBoldRightBold:"\u2537",lineUpBoldLeftRight:"\u2538",lineUpBoldLeftBoldRight:"\u2539",lineUpBoldLeftRightBold:"\u253A",lineUpLeftRightBold:"\u2536",lineUpLeftBoldRight:"\u2535",lineUpDoubleLeftDoubleRightDouble:"\u2569",lineUpDoubleLeftRight:"\u2568",lineUpLeftDoubleRightDouble:"\u2567",lineUpDownLeftRight:"\u253C",lineUpBoldDownBoldLeftBoldRightBold:"\u254B",lineUpDownBoldLeftBoldRightBold:"\u2548",lineUpBoldDownLeftBoldRightBold:"\u2547",lineUpBoldDownBoldLeftRightBold:"\u254A",lineUpBoldDownBoldLeftBoldRight:"\u2549",lineUpBoldDownLeftRight:"\u2540",lineUpDownBoldLeftRight:"\u2541",lineUpDownLeftBoldRight:"\u253D",lineUpDownLeftRightBold:"\u253E",lineUpBoldDownBoldLeftRight:"\u2542",lineUpDownLeftBoldRightBold:"\u253F",lineUpBoldDownLeftBoldRight:"\u2543",lineUpBoldDownLeftRightBold:"\u2544",lineUpDownBoldLeftBoldRight:"\u2545",lineUpDownBoldLeftRightBold:"\u2546",lineUpDoubleDownDoubleLeftDoubleRightDouble:"\u256C",lineUpDoubleDownDoubleLeftRight:"\u256B",lineUpDownLeftDoubleRightDouble:"\u256A",lineCross:"\u2573",lineBackslash:"\u2572",lineSlash:"\u2571"},dV2={tick:"\u2714",info:"\u2139",warning:"\u26A0",cross:"\u2718",squareSmall:"\u25FB",squareSmallFilled:"\u25FC",circle:"\u25EF",circleFilled:"\u25C9",circleDotted:"\u25CC",circleDouble:"\u25CE",circleCircle:"\u24DE",circleCross:"\u24E7",circlePipe:"\u24BE",radioOn:"\u25C9",radioOff:"\u25EF",checkboxOn:"\u2612",checkboxOff:"\u2610",checkboxCircleOn:"\u24E7",checkboxCircleOff:"\u24BE",pointer:"\u276F",triangleUpOutline:"\u25B3",triangleLeft:"\u25C0",triangleRight:"\u25B6",lozenge:"\u25C6",lozengeOutline:"\u25C7",hamburger:"\u2630",smiley:"\u32E1",mustache:"\u0DF4",star:"\u2605",play:"\u25B6",nodejs:"\u2B22",oneSeventh:"\u2150",oneNinth:"\u2151",oneTenth:"\u2152"},JF4={tick:"\u221A",info:"i",warning:"\u203C",cross:"\xD7",squareSmall:"\u25A1",squareSmallFilled:"\u25A0",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(\u25CB)",circleCross:"(\xD7)",circlePipe:"(\u2502)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[\xD7]",checkboxOff:"[ ]",checkboxCircleOn:"(\xD7)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"\u2206",triangleLeft:"\u25C4",triangleRight:"\u25BA",lozenge:"\u2666",lozengeOutline:"\u25CA",hamburger:"\u2261",smiley:"\u263A",mustache:"\u250C\u2500\u2510",star:"\u2736",play:"\u25BA",nodejs:"\u2666",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},hF4={...BV2,...dV2},XF4={...BV2,...JF4},DF4=WF4(),OF4=DF4?hF4:XF4,ZX=OF4,W86=Object.entries(dV2);var FV2={prefix:{idle:JK("blue","?"),done:JK("green",ZX.tick)},spinner:{interval:80,frames:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"].map((f)=>JK("yellow",f))},style:{answer:(f)=>JK("cyan",f),message:(f)=>JK("bold",f),error:(f)=>JK("red",`> ${f}`),defaultAnswer:(f)=>JK("dim",`(${f})`),help:(f)=>JK("dim",f),highlight:(f)=>JK("cyan",f),key:(f)=>JK("cyan",JK("bold",`<${f}>`))}};function UV2(f){if(typeof f!=="object"||f===null)return!1;let $=f;while(Object.getPrototypeOf($)!==null)$=Object.getPrototypeOf($);return Object.getPrototypeOf(f)===$}function aV2(...f){let $={};for(let Z of f)for(let[w,q]of Object.entries(Z)){let v=$[w];$[w]=UV2(v)&&UV2(q)?aV2(v,q):q}return $}function Xc(...f){let $=[FV2,...f.filter((Z)=>Z!=null)];return aV2(...$)}function UY1({status:f="idle",theme:$}){let[Z,w]=WK(!1),[q,v]=WK(0),{prefix:K,spinner:H}=Xc($);if(ur(()=>{if(f==="loading"){let P,M=-1,W=setTimeout(()=>{w(!0),P=setInterval(()=>{M=M+1,v(M%H.frames.length)},H.interval)},300);return()=>{clearTimeout(W),clearInterval(P)}}else w(!1)},[f]),Z)return H.frames[q];return typeof K==="string"?K:K[f==="loading"?"idle":f]??K.idle}function aY1(f,$){return LN((Z)=>{let w=Z.get();if(!w||w.dependencies.length!==$.length||w.dependencies.some((q,v)=>q!==$[v])){let q=f();return Z.set({value:q,dependencies:$}),q}return w.value})}function yr(f){return WK({current:f})[0]}function iY1(f){let $=yr(f);$.current=f,ur((Z)=>{let w=!1,q=FY1((v,K)=>{if(w)return;$.current(K,Z)});return Z.input.on("keypress",q),()=>{w=!0,Z.input.removeListener("keypress",q)}},[])}var QV2=H4(wX(),1);function Dc(f,$){return f.split(`
|
|
3838
|
+
`)]}async makePdfStatement(f,$){let Z=c3(f,$);await Mc(Z);let w=new Date().toISOString(),q=new Date().getFullYear(),v=this.problem.problemLangYmls[this.problem.originalLanguage].author||"Unknown",K=this.problem.problemLangYmls[this.problem.originalLanguage].author_email||"unknown email",H=this.problem.problemLangYmls[$].translator||"",[Y,P]=await this.makeSamples(Z,$),M=await V5(c3(bV2,"root-pdf.tpl.tex"));Wc.default.registerHelper("curly",function(O){return"{"+O+"}"});let W=Wc.default.compile(M)({language:$,jutgeLanguage:`jutge.${$}`,id:`${this.problem_nm}\\_${$}`,samples1c:Y,samples2c:P,author:v,translator:H,date:w,year:q});for await(let O of bY1("*",{cwd:this.problem.directory})){if(O.startsWith(D0())||O.endsWith(".exe")||O.endsWith(".html")||O.endsWith(".md")||O.endsWith(".txt")||await O81(this.problem.directory,O))continue;await Iq(c3(this.problem.directory,O),c3(Z,O))}if(await Sr(c3(Z,`original.${$}.pdf`))){L.warning(`Found original.${$}.pdf`),await Iq(c3(Z,`original.${$}.pdf`),c3(this.problem.directory,`problem.${$}.pdf`));return}await m7(c3(Z,"root.tex"),W);let X=(await V5(c3(Z,`problem.${$}.tex`))).replace(/\\begin{htmlonly}[\s\S]*?\\end{htmlonly}/g,"").replace(/\\begin{latexonly}/g,"").replace(/\\end{latexonly}/g,"").replace(/\.eps}/g,"}");if(await m7(c3(Z,`problem.${$}.tex`),X),await this.copyStyleFiles(Z,$),!await wV2()){L.error("xelatex not found");return}try{L.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error root.tex"),await K3({stderr:"inherit",cwd:Z})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error root.tex`,await Iq(c3(Z,"root.pdf"),c3(this.problem.directory,`problem.${$}.pdf`)),L.success(`Generated ${L.hyperlink(this.problem.directory,`problem.${$}.pdf`)} see ${L.hyperlink(Z,"root.log")}`)}catch(O){L.error(`Error in LaTeX: ${L.hyperlink(Z,"root.log")}`)}}async copyStyleFiles(f,$){let Z=async(w)=>{let q=c3(R7(),"assets","sty",w);await Iq(q,c3(f,w))};if(await Z("picins.sty"),await Z("jutge.sty"),$==="ca")await Z("jutge.ca.sty");if($==="es")await Z("jutge.es.sty");if($==="en")await Z("jutge.en.sty");if($==="fr")await Z("jutge.fr.sty");if($==="de")await Z("jutge.de.sty")}async makeFullTextualStatements(f=["txt","html","md"]){await this.makeTextualStatements(f,"full")}async makeShortTextualStatements(f=["txt","html","md"]){await this.makeTextualStatements(f,"short")}async makeTextualStatements(f=["txt","html","md"],$){await L.section(`Making textual statements (${$})`,async()=>{let Z=c3(this.problem.directory,D0()+"-text",A_());await Mc(Z,{recursive:!0}),await L.section("Creating working directory",async()=>{await J5(),L.directory(Z)});try{for(let w of this.problem.languages)if(this.problem.structure==="multi"||this.problem.structure==="single"&&w===this.problem.language)await L.section(`Making ${$} textual statements for ${B0[w]}`,async()=>{await this.makeTextualStatement(Z,w,f,$)})}finally{}})}async makeTextualStatement(f,$,Z,w){let q=c3(f,$);await Mc(q);let v=new Date().toISOString(),K=new Date().getFullYear(),H=this.problem.problemLangYmls[$].author||"Unknown",Y=this.problem.problemLangYmls[$].author_email||"unknown email",P=this.problem.problemLangYmls[$].translator||"",M=await V5(c3(bV2,`root-text-${w}.tpl.tex`));Wc.default.registerHelper("curly",function(V){return"{"+V+"}"});let W=Wc.default.compile(M)({language:$,jutgeLanguage:`jutge.${$}`,id:`${this.problem_nm}\\_${$}`,year:K,author:H,translator:P,date:v});for await(let V of bY1("*",{cwd:this.problem.directory})){if(V.startsWith(D0())||V.endsWith(".exe")||V.endsWith(".html")||V.endsWith(".md")||V.endsWith(".txt")||await O81(this.problem.directory,V))continue;await Iq(c3(this.problem.directory,V),c3(q,V))}if(await Sr(c3(q,`original.${$}.pdf`))){L.warning(`Found original.${$}.pdf`);return}let J=w==="full"?`problem.${$}`:`problem.${$}.short`;await m7(c3(q,"root.tex"),W);let O=(await V5(c3(q,`problem.${$}.tex`))).replace(/\\begin{latexonly}[\s\S]*?\\end{latexonly}/g,"").replace(/\\begin{htmlonly}/g,"").replace(/\\end{htmlonly}/g,"").replace(/\\begin{minipage}/g,"").replace(/\\end{minipage}/g,"");if(await m7(c3(q,`problem.${$}.tex`),O),await this.copyStyleFiles(q,$),!await vV2()){L.error("pandoc with lua support not found");return}let G=c3(R7(),"assets","lua","fixCodeBlocks.lua");if(await Iq(G,c3(q,"fixCodeBlocks.lua")),Z.includes("txt"))try{L.command("pandoc --quiet root.tex --to plain --output root.txt"),await K3({cwd:q})`pandoc --quiet root.tex --to plain --output root.txt`,await Iq(c3(q,"root.txt"),c3(this.problem.directory,`${J}.txt`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.txt`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}if(Z.includes("md"))try{L.command("pandoc --quiet root.tex --to markdown --to markdown-header_attributes --lua-filter=fixCodeBlocks.lua --output root.md"),await K3({cwd:q})`pandoc --quiet root.tex --to markdown --to markdown-header_attributes --lua-filter=fixCodeBlocks.lua --output root.md`,await Iq(c3(q,"root.md"),c3(this.problem.directory,`${J}.md`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.md`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}if(Z.includes("html"))try{L.command("pandoc --quiet root.tex --to html --mathml --embed-resources --output root.html"),await K3({cwd:q})`pandoc --quiet root.tex --to html --mathml --embed-resources --output root.html`,await Iq(c3(q,"root.html"),c3(this.problem.directory,`${J}.html`)),L.success("Generated "+L.hyperlink(this.problem.directory,`${J}.html`))}catch(V){L.error(`pandoc error: ${V instanceof Error?V.message:"unknown error"}`)}}async verifyCandidate(f){await L.section(`Verifying ${f}`,async()=>{let $=f.split(".").pop(),Z=jY1[$];if(!Z)throw Error(`No compiler found for .${$} files`);if(!await Z()){L.warning(`Compiler for .${$} files is not available, skipping verification of ${f}`);return}let w=lY1($),q=`${D0()}-${f}`;await L.section(`Copying ${L.hyperlink(this.problem.directory,f)} to ${L.hyperlink(this.problem.directory,q)}`,async()=>{await Iq(c3(this.problem.directory,f),c3(this.problem.directory,q))}),await L.section(`Using compiler ${w.name()} to compile ${L.hyperlink(this.problem.directory,q)}`,async()=>{try{let K;if(this.problem.handler.source_modifier==="none")K=await w.compileNormal(this.problem.handler,this.problem.directory,q);else if(this.problem.handler.source_modifier==="no_main")K=await w.compileWithMain(this.problem.handler,this.problem.directory,q);else throw Error(`Unknown source modifier: ${this.problem.handler.source_modifier}`);if(!await Sr(c3(this.problem.directory,K)))throw Error(`Compilation failed for ${q}`);L.success(`Compiled ${q} to ${K}`)}catch(K){throw Error(`Compilation failed: ${K}`)}});let v=[];await L.section("Executing testcases",async()=>{for(let H of this.problem.testcases)v.push(await this.runTestcase(H,`${H}.inp`,`${D0()}-${H}.${$}.out`,w,q));L.print(),L.print("testcase time status");let K=0;for(let H of v){let Y=H.error?"EE":await fI1(c3(this.problem.directory,`${H.testcase}.cor`),c3(this.problem.directory,`${D0()}-${H.testcase}.${$}.out`))?"OK":"WA",P=LG(H.time);if(L.print((Y!=="OK"?P0.red:P0.green)(`${H.testcase.padEnd(12)} ${P.padStart(10)} ${Y.padStart(10)}`)),Y!=="OK")K++}if(L.print(),K)L.error(`${K} errors found for ${f}`);else L.success(`All testcases passed successfully for ${f}`)})})}async makeTarFiles(){let{handler:f,directory:$}=this.problem,{compilers:Z}=f;if(Z==="PRO2"||Z==="MakePRO2")await L.section("Making `.tar` files",async()=>{for(let w of["public","private","solution"])if(await BZ($,w)){let{exitCode:q}=await K3({reject:!1,stderr:"inherit",stdout:"inherit",cwd:c3($,w)})`tar cf ../${w}.tar .`;if(q!==0)throw console.log(q),Error(`Error making ${w}.tar`);L.success(`Created ${L.hyperlink($,`${w}.tar`)}`)}})}}var yV2=new g6("verify").description("Verify programs against golden solution").argument("<programs...>","source programs to verify").option("-d, --directory <path>","problem directory",".").action(async(f,{directory:$})=>{let Z=await gr($);for(let w of f)await Z.verifyCandidate(w)});import yi4 from"path";var Jc=(f,$=[])=>f.name==="up"||$.includes("vim")&&f.name==="k"||$.includes("emacs")&&f.ctrl&&f.name==="p",cr=(f,$=[])=>f.name==="down"||$.includes("vim")&&f.name==="j"||$.includes("emacs")&&f.ctrl&&f.name==="n",uY1=(f)=>f.name==="space";var yY1=(f)=>"1234567890".includes(f.name),kY1=(f)=>f.name==="enter"||f.name==="return";class mY1 extends Error{name="AbortPromptError";message="Prompt was aborted";constructor(f){super();this.cause=f?.cause}}class xY1 extends Error{name="CancelPromptError";message="Prompt was canceled"}class br extends Error{name="ExitPromptError"}class BY1 extends Error{name="HookError"}class hc extends Error{name="ValidationError"}import{AsyncResource as MF4}from"async_hooks";import{AsyncLocalStorage as HF4,AsyncResource as YF4}from"async_hooks";var kV2=new HF4;function PF4(f){return{rl:f,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function mV2(f,$){let Z=PF4(f);return kV2.run(Z,()=>{function w(q){Z.handleChange=()=>{Z.index=0,q()},Z.handleChange()}return $(w)})}function Tz(){let f=kV2.getStore();if(!f)throw new BY1("[Inquirer] Hook functions can only be called from within a prompt");return f}function dY1(){return Tz().rl}function FY1(f){let $=(...Z)=>{let w=Tz(),q=!1,v=w.handleChange;w.handleChange=()=>{q=!0};let K=f(...Z);if(q)v();return w.handleChange=v,K};return YF4.bind($)}function LN(f){let $=Tz(),{index:Z}=$,w={get(){return $.hooks[Z]},set(v){$.hooks[Z]=v},initialized:Z in $.hooks},q=f(w);return $.index++,q}function xV2(){Tz().handleChange()}var Vz={queue(f){let $=Tz(),{index:Z}=$;$.hooksEffect.push(()=>{$.hooksCleanup[Z]?.();let w=f(dY1());if(w!=null&&typeof w!=="function")throw new hc("useEffect return value must be a cleanup function or nothing.");$.hooksCleanup[Z]=w})},run(){let f=Tz();FY1(()=>{f.hooksEffect.forEach(($)=>{$()}),f.hooksEffect.length=0})()},clearAll(){let f=Tz();f.hooksCleanup.forEach(($)=>{$?.()}),f.hooksEffect.length=0,f.hooksCleanup.length=0}};function WK(f){return LN(($)=>{let Z=MF4.bind(function(v){if($.get()!==v)$.set(v),xV2()});if($.initialized)return[$.get(),Z];let w=typeof f==="function"?f():f;return $.set(w),[w,Z]})}function ur(f,$){LN((Z)=>{let w=Z.get();if(!Array.isArray(w)||$.some((v,K)=>!Object.is(v,w[K])))Vz.queue(f);Z.set($)})}import{styleText as JK}from"util";import dH from"process";function WF4(){if(dH.platform!=="win32")return dH.env.TERM!=="linux";return Boolean(dH.env.WT_SESSION)||Boolean(dH.env.TERMINUS_SUBLIME)||dH.env.ConEmuTask==="{cmd::Cmder}"||dH.env.TERM_PROGRAM==="Terminus-Sublime"||dH.env.TERM_PROGRAM==="vscode"||dH.env.TERM==="xterm-256color"||dH.env.TERM==="alacritty"||dH.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var BV2={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"\u2588",squareDarkShade:"\u2593",squareMediumShade:"\u2592",squareLightShade:"\u2591",squareTop:"\u2580",squareBottom:"\u2584",squareLeft:"\u258C",squareRight:"\u2590",squareCenter:"\u25A0",bullet:"\u25CF",dot:"\u2024",ellipsis:"\u2026",pointerSmall:"\u203A",triangleUp:"\u25B2",triangleUpSmall:"\u25B4",triangleDown:"\u25BC",triangleDownSmall:"\u25BE",triangleLeftSmall:"\u25C2",triangleRightSmall:"\u25B8",home:"\u2302",heart:"\u2665",musicNote:"\u266A",musicNoteBeamed:"\u266B",arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",arrowLeftRight:"\u2194",arrowUpDown:"\u2195",almostEqual:"\u2248",notEqual:"\u2260",lessOrEqual:"\u2264",greaterOrEqual:"\u2265",identical:"\u2261",infinity:"\u221E",subscriptZero:"\u2080",subscriptOne:"\u2081",subscriptTwo:"\u2082",subscriptThree:"\u2083",subscriptFour:"\u2084",subscriptFive:"\u2085",subscriptSix:"\u2086",subscriptSeven:"\u2087",subscriptEight:"\u2088",subscriptNine:"\u2089",oneHalf:"\xBD",oneThird:"\u2153",oneQuarter:"\xBC",oneFifth:"\u2155",oneSixth:"\u2159",oneEighth:"\u215B",twoThirds:"\u2154",twoFifths:"\u2156",threeQuarters:"\xBE",threeFifths:"\u2157",threeEighths:"\u215C",fourFifths:"\u2158",fiveSixths:"\u215A",fiveEighths:"\u215D",sevenEighths:"\u215E",line:"\u2500",lineBold:"\u2501",lineDouble:"\u2550",lineDashed0:"\u2504",lineDashed1:"\u2505",lineDashed2:"\u2508",lineDashed3:"\u2509",lineDashed4:"\u254C",lineDashed5:"\u254D",lineDashed6:"\u2574",lineDashed7:"\u2576",lineDashed8:"\u2578",lineDashed9:"\u257A",lineDashed10:"\u257C",lineDashed11:"\u257E",lineDashed12:"\u2212",lineDashed13:"\u2013",lineDashed14:"\u2010",lineDashed15:"\u2043",lineVertical:"\u2502",lineVerticalBold:"\u2503",lineVerticalDouble:"\u2551",lineVerticalDashed0:"\u2506",lineVerticalDashed1:"\u2507",lineVerticalDashed2:"\u250A",lineVerticalDashed3:"\u250B",lineVerticalDashed4:"\u254E",lineVerticalDashed5:"\u254F",lineVerticalDashed6:"\u2575",lineVerticalDashed7:"\u2577",lineVerticalDashed8:"\u2579",lineVerticalDashed9:"\u257B",lineVerticalDashed10:"\u257D",lineVerticalDashed11:"\u257F",lineDownLeft:"\u2510",lineDownLeftArc:"\u256E",lineDownBoldLeftBold:"\u2513",lineDownBoldLeft:"\u2512",lineDownLeftBold:"\u2511",lineDownDoubleLeftDouble:"\u2557",lineDownDoubleLeft:"\u2556",lineDownLeftDouble:"\u2555",lineDownRight:"\u250C",lineDownRightArc:"\u256D",lineDownBoldRightBold:"\u250F",lineDownBoldRight:"\u250E",lineDownRightBold:"\u250D",lineDownDoubleRightDouble:"\u2554",lineDownDoubleRight:"\u2553",lineDownRightDouble:"\u2552",lineUpLeft:"\u2518",lineUpLeftArc:"\u256F",lineUpBoldLeftBold:"\u251B",lineUpBoldLeft:"\u251A",lineUpLeftBold:"\u2519",lineUpDoubleLeftDouble:"\u255D",lineUpDoubleLeft:"\u255C",lineUpLeftDouble:"\u255B",lineUpRight:"\u2514",lineUpRightArc:"\u2570",lineUpBoldRightBold:"\u2517",lineUpBoldRight:"\u2516",lineUpRightBold:"\u2515",lineUpDoubleRightDouble:"\u255A",lineUpDoubleRight:"\u2559",lineUpRightDouble:"\u2558",lineUpDownLeft:"\u2524",lineUpBoldDownBoldLeftBold:"\u252B",lineUpBoldDownBoldLeft:"\u2528",lineUpDownLeftBold:"\u2525",lineUpBoldDownLeftBold:"\u2529",lineUpDownBoldLeftBold:"\u252A",lineUpDownBoldLeft:"\u2527",lineUpBoldDownLeft:"\u2526",lineUpDoubleDownDoubleLeftDouble:"\u2563",lineUpDoubleDownDoubleLeft:"\u2562",lineUpDownLeftDouble:"\u2561",lineUpDownRight:"\u251C",lineUpBoldDownBoldRightBold:"\u2523",lineUpBoldDownBoldRight:"\u2520",lineUpDownRightBold:"\u251D",lineUpBoldDownRightBold:"\u2521",lineUpDownBoldRightBold:"\u2522",lineUpDownBoldRight:"\u251F",lineUpBoldDownRight:"\u251E",lineUpDoubleDownDoubleRightDouble:"\u2560",lineUpDoubleDownDoubleRight:"\u255F",lineUpDownRightDouble:"\u255E",lineDownLeftRight:"\u252C",lineDownBoldLeftBoldRightBold:"\u2533",lineDownLeftBoldRightBold:"\u252F",lineDownBoldLeftRight:"\u2530",lineDownBoldLeftBoldRight:"\u2531",lineDownBoldLeftRightBold:"\u2532",lineDownLeftRightBold:"\u252E",lineDownLeftBoldRight:"\u252D",lineDownDoubleLeftDoubleRightDouble:"\u2566",lineDownDoubleLeftRight:"\u2565",lineDownLeftDoubleRightDouble:"\u2564",lineUpLeftRight:"\u2534",lineUpBoldLeftBoldRightBold:"\u253B",lineUpLeftBoldRightBold:"\u2537",lineUpBoldLeftRight:"\u2538",lineUpBoldLeftBoldRight:"\u2539",lineUpBoldLeftRightBold:"\u253A",lineUpLeftRightBold:"\u2536",lineUpLeftBoldRight:"\u2535",lineUpDoubleLeftDoubleRightDouble:"\u2569",lineUpDoubleLeftRight:"\u2568",lineUpLeftDoubleRightDouble:"\u2567",lineUpDownLeftRight:"\u253C",lineUpBoldDownBoldLeftBoldRightBold:"\u254B",lineUpDownBoldLeftBoldRightBold:"\u2548",lineUpBoldDownLeftBoldRightBold:"\u2547",lineUpBoldDownBoldLeftRightBold:"\u254A",lineUpBoldDownBoldLeftBoldRight:"\u2549",lineUpBoldDownLeftRight:"\u2540",lineUpDownBoldLeftRight:"\u2541",lineUpDownLeftBoldRight:"\u253D",lineUpDownLeftRightBold:"\u253E",lineUpBoldDownBoldLeftRight:"\u2542",lineUpDownLeftBoldRightBold:"\u253F",lineUpBoldDownLeftBoldRight:"\u2543",lineUpBoldDownLeftRightBold:"\u2544",lineUpDownBoldLeftBoldRight:"\u2545",lineUpDownBoldLeftRightBold:"\u2546",lineUpDoubleDownDoubleLeftDoubleRightDouble:"\u256C",lineUpDoubleDownDoubleLeftRight:"\u256B",lineUpDownLeftDoubleRightDouble:"\u256A",lineCross:"\u2573",lineBackslash:"\u2572",lineSlash:"\u2571"},dV2={tick:"\u2714",info:"\u2139",warning:"\u26A0",cross:"\u2718",squareSmall:"\u25FB",squareSmallFilled:"\u25FC",circle:"\u25EF",circleFilled:"\u25C9",circleDotted:"\u25CC",circleDouble:"\u25CE",circleCircle:"\u24DE",circleCross:"\u24E7",circlePipe:"\u24BE",radioOn:"\u25C9",radioOff:"\u25EF",checkboxOn:"\u2612",checkboxOff:"\u2610",checkboxCircleOn:"\u24E7",checkboxCircleOff:"\u24BE",pointer:"\u276F",triangleUpOutline:"\u25B3",triangleLeft:"\u25C0",triangleRight:"\u25B6",lozenge:"\u25C6",lozengeOutline:"\u25C7",hamburger:"\u2630",smiley:"\u32E1",mustache:"\u0DF4",star:"\u2605",play:"\u25B6",nodejs:"\u2B22",oneSeventh:"\u2150",oneNinth:"\u2151",oneTenth:"\u2152"},JF4={tick:"\u221A",info:"i",warning:"\u203C",cross:"\xD7",squareSmall:"\u25A1",squareSmallFilled:"\u25A0",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(\u25CB)",circleCross:"(\xD7)",circlePipe:"(\u2502)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[\xD7]",checkboxOff:"[ ]",checkboxCircleOn:"(\xD7)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"\u2206",triangleLeft:"\u25C4",triangleRight:"\u25BA",lozenge:"\u2666",lozengeOutline:"\u25CA",hamburger:"\u2261",smiley:"\u263A",mustache:"\u250C\u2500\u2510",star:"\u2736",play:"\u25BA",nodejs:"\u2666",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},hF4={...BV2,...dV2},XF4={...BV2,...JF4},DF4=WF4(),OF4=DF4?hF4:XF4,ZX=OF4,W86=Object.entries(dV2);var FV2={prefix:{idle:JK("blue","?"),done:JK("green",ZX.tick)},spinner:{interval:80,frames:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"].map((f)=>JK("yellow",f))},style:{answer:(f)=>JK("cyan",f),message:(f)=>JK("bold",f),error:(f)=>JK("red",`> ${f}`),defaultAnswer:(f)=>JK("dim",`(${f})`),help:(f)=>JK("dim",f),highlight:(f)=>JK("cyan",f),key:(f)=>JK("cyan",JK("bold",`<${f}>`))}};function UV2(f){if(typeof f!=="object"||f===null)return!1;let $=f;while(Object.getPrototypeOf($)!==null)$=Object.getPrototypeOf($);return Object.getPrototypeOf(f)===$}function aV2(...f){let $={};for(let Z of f)for(let[w,q]of Object.entries(Z)){let v=$[w];$[w]=UV2(v)&&UV2(q)?aV2(v,q):q}return $}function Xc(...f){let $=[FV2,...f.filter((Z)=>Z!=null)];return aV2(...$)}function UY1({status:f="idle",theme:$}){let[Z,w]=WK(!1),[q,v]=WK(0),{prefix:K,spinner:H}=Xc($);if(ur(()=>{if(f==="loading"){let P,M=-1,W=setTimeout(()=>{w(!0),P=setInterval(()=>{M=M+1,v(M%H.frames.length)},H.interval)},300);return()=>{clearTimeout(W),clearInterval(P)}}else w(!1)},[f]),Z)return H.frames[q];return typeof K==="string"?K:K[f==="loading"?"idle":f]??K.idle}function aY1(f,$){return LN((Z)=>{let w=Z.get();if(!w||w.dependencies.length!==$.length||w.dependencies.some((q,v)=>q!==$[v])){let q=f();return Z.set({value:q,dependencies:$}),q}return w.value})}function yr(f){return WK({current:f})[0]}function iY1(f){let $=yr(f);$.current=f,ur((Z)=>{let w=!1,q=FY1((v,K)=>{if(w)return;$.current(K,Z)});return Z.input.on("keypress",q),()=>{w=!0,Z.input.removeListener("keypress",q)}},[])}var QV2=H4(wX(),1);function Dc(f,$){return f.split(`
|
|
3839
3839
|
`).flatMap((Z)=>hZ(Z,$,{trim:!1,hard:!0}).split(`
|
|
3840
3840
|
`).map((w)=>w.trimEnd())).join(`
|
|
3841
3841
|
`)}function kr(){return QV2.default({defaultWidth:80,output:dY1().output})}function GF4({active:f,renderedItems:$,pageSize:Z,loop:w}){let q=yr({lastPointer:f,lastActive:void 0}),{lastPointer:v,lastActive:K}=q.current,H=Math.floor(Z/2),Y=$.reduce((W,J)=>W+J.length,0),P=$.slice(0,f).reduce((W,J)=>W+J.length,0),M=P;if(Y>Z)if(w){if(M=v,K!=null&&K<f&&f-K<Z)M=Math.min(H,Math.abs(f-K)===1?Math.min(v+($[K]?.length??0),Math.max(P,v)):v+f-K)}else{let W=$.slice(f).reduce((J,X)=>J+X.length,0);M=W<Z-H?Z-W:Math.min(P,H)}return q.current.lastPointer=M,q.current.lastActive=f,M}function QY1({items:f,active:$,renderItem:Z,pageSize:w,loop:q=!0}){let v=kr(),K=(N)=>(N%f.length+f.length)%f.length,H=f.map((N,E)=>{if(N==null)return[];return Dc(Z({item:N,index:E,isActive:E===$}),v).split(`
|
|
@@ -4069,7 +4069,7 @@ tell application "System Events" to get value of property list item "CFBundleNam
|
|
|
4069
4069
|
*
|
|
4070
4070
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
4071
4071
|
* Copyright (c) 2024 Florian Körner
|
|
4072
|
-
*/var Vs={};YZ(Vs,{schema:()=>eB2,meta:()=>dZ5,create:()=>FZ5});var PD1={};YZ(PD1,{ringTwo:()=>QB2,ringThree:()=>nB2,ringOne:()=>iB2,ringFour:()=>pB2,ringFive:()=>rB2,ring:()=>aB2});var aB2={container:(f,$)=>{var Z,w,q,v,K,H,Y,P,M,W,J,X,O,G,V,N,E,j,g,k;return`${(w=(Z=f.ringOne)===null||Z===void 0?void 0:Z.value(f,$))!==null&&w!==void 0?w:""}${(v=(q=f.ringTwo)===null||q===void 0?void 0:q.value(f,$))!==null&&v!==void 0?v:""}${(H=(K=f.ringThree)===null||K===void 0?void 0:K.value(f,$))!==null&&H!==void 0?H:""}${(P=(Y=f.ringFour)===null||Y===void 0?void 0:Y.value(f,$))!==null&&P!==void 0?P:""}${(W=(M=f.ringFive)===null||M===void 0?void 0:M.value(f,$))!==null&&W!==void 0?W:""}<g transform="matrix(1 0 0 -1 0 100)">${(X=(J=f.ringOne)===null||J===void 0?void 0:J.value(f,$))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(G=(O=f.ringTwo)===null||O===void 0?void 0:O.value(f,$))!==null&&G!==void 0?G:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(N=(V=f.ringThree)===null||V===void 0?void 0:V.value(f,$))!==null&&N!==void 0?N:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(j=(E=f.ringFour)===null||E===void 0?void 0:E.value(f,$))!==null&&j!==void 0?j:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(g=f.ringFive)===null||g===void 0?void 0:g.value(f,$))!==null&&k!==void 0?k:""}</g><circle cx="50" cy="50" r="45" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="25" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="10" fill="#fff" fill-opacity=".25" style="mix-blend-mode:lighten"/>`}};var iB2={half:(f,$)=>`<path d="M90 50h10c0-27.614-22.386-50-50-50S0 22.386 0 50h10c0-22.091 17.909-40 40-40s40 17.909 40 40Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${B1.xml(`${$.ring}`)}"/>`,eighth:(f,$)=>`<path d="M21.716 21.716C14.477 28.954 10 38.954 10 50H0c0-13.807 5.596-26.307 14.645-35.355l7.07 7.07Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="45" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var QB2={eighth:(f,$)=>`<path d="M20 50c0-8.284 3.358-15.784 8.787-21.213l-7.071-7.071C14.477 28.954 10 38.954 10 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M90 50c0-22.091-17.909-40-40-40S10 27.909 10 50h10c0-16.569 13.431-30 30-30 16.569 0 30 13.431 30 30h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="35" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var nB2={eighth:(f,$)=>`<path d="M30 50a19.937 19.937 0 0 1 5.858-14.142l-7.071-7.071C23.357 34.216 20 41.716 20 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M80 50c0-16.569-13.431-30-30-30-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20s20 8.954 20 20h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="25" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var pB2={eighth:(f,$)=>`<path d="M40 50a9.97 9.97 0 0 1 2.929-7.071l-7.071-7.071A19.937 19.937 0 0 0 30 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M70 50c0-11.046-8.954-20-20-20s-20 8.954-20 20h10c0-5.523 4.477-10 10-10s10 4.477 10 10h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="15" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var rB2={eighth:(f,$)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="10" fill="${B1.xml(`${$.ring}`)}"/>`};function hA({prng:f,group:$,width:Z,height:w,values:q=[],rotation:v,offsetX:K,offsetY:H}){let Y=PD1,P=f.pick(q),M=f.integer(Math.min(...v),Math.max(...v)),W=f.integer(Math.min(...K),Math.max(...K)),J=f.integer(Math.min(...H),Math.max(...H));if(P&&Y[$][P])return{name:P,value(X,O){var G,V,N;let E=Y[$][P](X,O);if(this.rotation||this.offsetX||this.offsetY)E=`<g transform="translate(${(G=this.offsetX)!==null&&G!==void 0?G:0}, ${(V=this.offsetY)!==null&&V!==void 0?V:0}) rotate(${(N=this.rotation)!==null&&N!==void 0?N:0} ${Z/2} ${w/2})">${E}</g>`;return E},rotation:M,offsetX:W,offsetY:J};else return}function oB2({prng:f,options:$}){var Z,w,q,v,K,H;let Y=hA({prng:f,group:"ring",values:$.ring,width:100,height:100,rotation:((Z=$.ringRotation)===null||Z===void 0?void 0:Z.length)?$.ringRotation:[0],offsetX:[0],offsetY:[0]}),P=hA({prng:f,group:"ringOne",values:$.ringOne,width:100,height:100,rotation:((w=$.ringOneRotation)===null||w===void 0?void 0:w.length)?$.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),M=hA({prng:f,group:"ringTwo",values:$.ringTwo,width:100,height:100,rotation:((q=$.ringTwoRotation)===null||q===void 0?void 0:q.length)?$.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),W=hA({prng:f,group:"ringThree",values:$.ringThree,width:100,height:100,rotation:((v=$.ringThreeRotation)===null||v===void 0?void 0:v.length)?$.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),J=hA({prng:f,group:"ringFour",values:$.ringFour,width:100,height:100,rotation:((K=$.ringFourRotation)===null||K===void 0?void 0:K.length)?$.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),X=hA({prng:f,group:"ringFive",values:$.ringFive,width:100,height:100,rotation:((H=$.ringFiveRotation)===null||H===void 0?void 0:H.length)?$.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:Y,ringOne:P,ringTwo:M,ringThree:W,ringFour:J,ringFive:X}}function tB2(f){return f==="transparent"?f:`#${f}`}function sB2({prng:f,options:$}){var Z;return{ring:tB2(f.pick((Z=$.ringColor)!==null&&Z!==void 0?Z:[],"transparent"))}}var eB2={$schema:"http://json-schema.org/draft-07/schema#",properties:{ring:{type:"array",items:{type:"string",enum:["container"]},default:["container"]},ringColor:{type:"array",items:{type:"string",pattern:"^(transparent|[a-fA-F0-9]{6})$"},default:["ffd54f","64b5f6","4dd0e1","ff8a65","9575cd","81c784","7986cb","4fc3f7","aed581","dce775","ffb74d","f06292","ba68c8","e57373","4db6ac","fff176"]},ringFive:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["full"]},ringFiveRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringFour:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringFourRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringOne:{type:"array",items:{type:"string",enum:["half","quarter","eighth","full"]},default:["half","quarter"]},ringOneRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringThree:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringThreeRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringTwo:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringTwoRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]}}};var dZ5={title:"Rings",creator:"DiceBear",source:"https://www.dicebear.com",homepage:"https://www.dicebear.com",license:{name:"CC0 1.0",url:"https://creativecommons.org/publicdomain/zero/1.0/"}},FZ5=({prng:f,options:$})=>{var Z,w;let q=oB2({prng:f,options:$}),v=sB2({prng:f,options:$});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(w=(Z=q.ring)===null||Z===void 0?void 0:Z.value(q,v))!==null&&w!==void 0?w:""}`,extra:()=>({...Object.entries(q).reduce((K,[H,Y])=>{return K[H]=Y===null||Y===void 0?void 0:Y.name,K},{}),...Object.entries(v).reduce((K,[H,Y])=>{return K[`${H}Color`]=Y,K},{})})}};var JD1=H4(fd2(),1);Gz();var wd2=H4(Go(),1);import{cp as ef,exists as Cs,glob as uq,mkdir as NW,rm as $d2,writeFile as rZ5}from"fs/promises";import bE from"os";import{join as j2,resolve as oZ5}from"path";class hD1{directory;problem_nm;workspace;workDir;stagingDir;stagingDirLang="to-be-set";workDirLang="to-be-set";problem_id="to-be-set";languages=[];original_language="";problem_ymls={};handlers={};author="";author_email="";problem_type="std";constructor(f,$){if(this.directory=oZ5(f),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=$,this.workspace=j2(f,D0()+"-stage",A_()),this.workDir=j2(this.workspace,"work.pbm"),this.stagingDir=j2(this.workspace,"stage",this.problem_nm)}async stage(){await L.section(`Staging problem at ${L.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await L.section(`Staging language ${f}`,async()=>{if(await this.setLanguage(f),this.problem_type==="std")await this.stageLanguage_Std(f);else if(this.problem_type==="game")await this.stageLanguage_Game(f);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(f)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await L.section("Summary",async()=>{let f=j2(this.stagingDir,"README.md");L.success("README.md content:"),await L.markdown(await V5(f)),L.success("Staging tree:"),L.print(wd2.default(this.stagingDir))}),L.success(`Problem successfully staged at directory ${L.hyperlink(this.stagingDir)}`),await jB2(this.stagingDir)}async stageLanguage_Std(f){await this.prepareStatements_Std(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Std(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Std(f)}async stageLanguage_Game(f){await this.prepareStatements_Game(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Game(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Game(f),await this.stageViewer(f)}async stageLanguage_Quizz(f){await this.stageQuiz(f)}async setLanguage(f){this.workDirLang=j2(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=j2(this.stagingDir,f),await NW(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await L.section(`Creating workspace ${this.workspace}`,async()=>{if(await Cs(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await NW(this.workspace,{recursive:!0}),await NW(this.workDir,{recursive:!0}),await NW(this.stagingDir,{recursive:!0}),L.directory(this.workspace)})}doNotCopy(f,$){if(f==="problem.yml")return!0;if(f.startsWith(D0()))return!0;let Z=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(Z&&Z[1]!==$)return!0;if(f===`problem.${$}.pdf`)return!0;return!1}async separateByLanguages(){await L.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(uq("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await L.section("Separating problem by languages without folders",async()=>{let $=(await Array.fromAsync(uq("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((Z)=>{let w=Z.match(/^problem\.([a-z][a-z])\.yml$/);if(!w)throw Error(`Unexpected yml file name: ${Z}`);return w[1]});this.languages=$;for(let Z of $){let w=j2(this.workDir,Z);await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:this.directory}));for(let v of q){if(this.doNotCopy(v,Z))continue;await ef(j2(this.directory,v),j2(w,v),{recursive:!0})}}L.success(`Found languages: ${$.join(", ")}`)})}async separateByLanguagesWithFolders(){await L.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(uq("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let $ of f){let Z=j2(this.directory,$),w=j2(this.workDir,$);await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:Z}));for(let v of q){if(this.doNotCopy(v,$))continue;await ef(j2(Z,v),j2(w,v),{recursive:!0})}}L.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await L.section("Reading problem metadata",async()=>{for(let $ of this.languages){let Z=j2(this.workDir,$,`problem.${$}.yml`);this.problem_ymls[$]=await O_(Z),Tx.parse(this.problem_ymls[$])}for(let $ of this.languages){let Z=j2(this.workDir,$,"handler.yml");this.handlers[$]=await O_(Z)}for(let $ of this.languages){let Z=this.problem_ymls[$];if(Z.author)this.author=Z.author;if(Z.author)this.original_language=$;if(Z.email)this.author_email=Z.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:f}=this.handlers[this.original_language];if(f==="game")this.problem_type="game";else if(f==="quiz")this.problem_type="quiz";else this.problem_type="std";L.success(`Problem type: ${this.problem_type}`),L.success(`Original language: ${this.original_language}`),L.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await L.section("Finding golden solution",async()=>{let $=this.handlers[f].handler,Z=this.handlers[f].compilers||"",w=this.handlers[f].solution,q;if($==="circuits")q="solution.v";else if(Z==="RunPython")q="solution.py";else if(Z==="RunHaskell"||Z==="GHC"||w==="Haskell")q="solution.hs";else if(Z==="RunClojure"||Z==="Clojure")q="solution.clj";else if(Z==="PRO2"||Z==="MakePRO2"){let v=await Array.fromAsync(uq("solution.{cc,hh,tar}",{cwd:this.directory}));if(v.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${v.join(", ")}`);q=v[0]}else{let v=this.handlers[f].solution||"C++";if(v==="C++"){let P=await Array.fromAsync(uq("solution.*",{cwd:this.directory}));if(L.print(P.join(", ")),P.length===1){let M=P[0].split(".").pop();v=XD1[M]}}let K=tZ5[v];if(!K)throw Error(`Unknown programming language ${v} for solution`);let H=j2(this.workDir,f,`solution.${K}`);if(!await Cs(H))throw Error(`Golden solution file ${H} not found`);q=`solution.${K}`}return L.success(`Golden solution: ${q}`),q})}async prepareStatements_Std(f){await L.section("Preparing statements",async()=>{let $=j2(this.workDir,f);L.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await K3({cwd:$,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:L.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await $d2(j2($,"jtk-pdf"),{recursive:!0,force:!0}),await $d2(j2($,"jtk-text"),{recursive:!0,force:!0}),L.success("Generated statements")})}async prepareStatements_Game(f){await L.section("Preparing game statements",async()=>{let $=j2(this.workDirLang,"Doc");await L.section("Generating PDF with xelatex",async()=>{L.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await K3({cwd:$})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await K3({cwd:$})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await ef(j2($,"main.pdf"),j2(this.workDirLang,`problem.${f}.pdf`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await L.section("Generating TXT with pandoc",async()=>{L.command("pandoc --sandbox --quiet main.tex --to plain --output main.txt"),await K3({cwd:$})`pandoc --sandbox --quiet main.tex --to plain --output main.txt`,await ef(j2($,"main.txt"),j2(this.workDirLang,`problem.${f}.txt`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await ef(j2($,"main.txt"),j2(this.workDirLang,`problem.${f}.short.txt`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await L.section("Generating Markdown with pandoc",async()=>{L.command("pandoc --sandbox --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await K3({cwd:$})`pandoc --sandbox --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await ef(j2($,"main.md"),j2(this.workDirLang,`problem.${f}.md`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await ef(j2($,"main.md"),j2(this.workDirLang,`problem.${f}.short.md`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await L.section("Generating HTML with pandoc",async()=>{L.command("pandoc --sandbox --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await K3({cwd:$})`pandoc --sandbox --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await ef(j2($,"main.html"),j2(this.workDirLang,`problem.${f}.html`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await ef(j2($,"main.html"),j2(this.workDirLang,`problem.${f}.short.html`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(!await $V2()){L.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await L.section("Skipping code metrics",async()=>{await J5(),L.warning("Code metrics not applicable for this problem type")});return}await L.section("Computing code metrics",async()=>{let $=await this.findGoldenSolution(f);L.command(`jutge-code-metrics ${$}`);try{let{stdout:Z}=await K3({cwd:this.workDirLang})`jutge-code-metrics ${$}`;await m7(j2(this.stagingDirLang,"code-metrics.json"),Z),L.success(`Generated ${L.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(Z){L.warning("Failed to compute code metrics")}})}async stageProblemFiles_Std(f){let $=(q)=>{if(q==="handler.yml")return!0;for(let v of["inp","cor","ops"])if(q.endsWith(`.${v}`))return!0;for(let v of Zd2){if(q===`solution.${v}`)return!0;if(q===`main.${v}`)return!0}if(q==="scores.yml")return!0;if(q==="checker.py")return!0;if(q==="checker.cc")return!0;if(q==="private.tar")return!0;if(q==="public.tar")return!0;if(q==="solution.tar")return!0;if(q==="solution.cc")return!0;if(q==="solution.hh")return!0;return!1},Z=j2(this.stagingDirLang,"problem.pbm");await NW(Z,{recursive:!0});let w=await Array.fromAsync(uq("*",{cwd:this.workDirLang}));for(let q of w)if($(q))await ef(j2(this.workDirLang,q),j2(Z,q));await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"problem.yml")),L.success(`Problem staged to ${L.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let $=(v)=>{if(v==="handler.yml")return!0;if(v==="Makefile")return!0;if(v==="README.txt")return!0;if(v==="README.md")return!0;if(v.endsWith(".cc"))return!0;if(v.endsWith(".hh"))return!0;if(v.endsWith(".cnf"))return!0;return!1},Z=j2(this.workDirLang,"Runner"),w=j2(this.stagingDirLang,"problem.pbm");await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:Z}));for(let v of q)if($(v))await ef(j2(Z,v),j2(w,v));await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(w,"problem.yml")),L.success(`Problem staged to ${L.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await L.section("Staging awards",async()=>{let $=0;for(let Z of["award.png","award.txt"])if(await BZ(this.workDirLang,Z))await ef(j2(this.workDirLang,Z),j2(this.stagingDir,Z)),$++;if($>0)L.success(`Staged ${$} award file(s)`);else L.warning("No award files found")})}async stageStatements(f){await L.section("Staging statements",async()=>{let $=0;for(let Z of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let w=`problem.${f}.${Z}`,q=`problem.${Z}`;if(await BZ(this.workDirLang,w))await ef(j2(this.workDirLang,w),j2(this.stagingDirLang,q)),$++}L.success(`Staged ${$} statement file(s)`)})}async stageFirstToSolve(){await L.section("Staging first-to-solve avatar",async()=>{let f=j2(this.stagingDir,"first-to-solve.svg"),Z=UB2(Vs,{seed:this.problem_nm}).toString();await m7(f,Z),L.success(`Generated ${L.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let $=(q)=>{for(let v of["pdf","html","md","txt"])if(q===`problem.${f}.${v}`)return!0;for(let v of Zd2){if(q===`main.${v}`)return!0;if(q===`code.${v}`)return!0}if((q.includes("sample")||q.startsWith("public")||q.startsWith("hint")||q.startsWith("distilled"))&&(q.endsWith(".inp")||q.endsWith(".cor")))return!0;return!1},Z=[],w=await Array.fromAsync(uq("*",{cwd:this.workDirLang}));for(let q of w)if($(q))Z.push({sourcePath:j2(this.workDirLang,q),archivePath:j2(`${this.problem_id}`,q)});await ab(Z,j2(this.stagingDirLang,"problem.zip")),L.success(`Created ${L.hyperlink(this.stagingDirLang,"problem.zip")} with ${Z.length} files`)}async stageZip_Game(f){let $=this.handlers[this.original_language].game.hide||["AIDummy.cc"],Z=(q)=>{if(q.endsWith(".cc")||q.endsWith(".hh"))return!$.includes(q);if(q.endsWith(".cnf"))return!0;if(q=="Makefile")return!0;if(q=="README.txt")return!0;if(q=="README.md")return!0;return!1},w=[];for(let q of["pdf","html","md","txt","short.html","short.md","short.txt"]){let v=`problem.${f}.${q}`;if(await BZ(this.workDirLang,v))w.push({sourcePath:j2(this.workDirLang,v),archivePath:j2(`${this.problem_id}`,v)})}{let q=j2(this.workDirLang,"Runner"),v=await Array.fromAsync(uq("*",{cwd:q}));for(let K of v)if(Z(K))w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src",K)})}{let q=j2(this.workDirLang,"Obj"),v=await Array.fromAsync(uq("*.o.*",{cwd:q}));for(let K of v)w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src",K)})}{let q=j2(this.workDirLang,"Viewer"),v=await Array.fromAsync(uq("**/*",{cwd:q}));for(let K of v)w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src","Viewer",K)})}await ab(w,j2(this.stagingDirLang,"problem.zip")),L.success(`Created ${L.hyperlink(this.stagingDirLang,"problem.zip")} with ${w.length} files`)}async stageViewer(f){await L.section("Staging viewer",async()=>{await ef(j2(this.workDirLang,"Viewer"),j2(this.stagingDirLang,"viewer"),{recursive:!0}),L.success(`Staged ${L.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await L.section("Staging quiz",async()=>{let $=yl.parse(await O_(j2(this.workDirLang,"quiz.yml"))),Z=j2(this.stagingDirLang,"quiz.pbm");await NW(Z,{recursive:!0}),await AJ(j2(Z,"quiz.yml"),$),await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"problem.yml")),await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"..","problem.yml"));for(let w of $.questions){{let q=j2(this.workDirLang,`${w.file}.yml`),v=j2(Z,`${w.file}.yml`);if(await Cs(q))await ef(q,v);else throw Error(`Quiz question file ${w.file}.yml not found`)}{let q=j2(this.workDirLang,`${w.file}.py`),v=j2(Z,`${w.file}.py`);if(await Cs(q))await ef(q,v)}}L.success(`Staged ${L.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await L.section("Staging information.yml",async()=>{let f={problem_nm:this.problem_nm,languages:this.languages,original_language:this.original_language,author:this.author,author_email:this.author_email,problems:this.problem_ymls,handlers:this.handlers},$=j2(this.stagingDir,"information.yml");await AJ($,f),L.success(`Generated ${L.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await L.section("Staging README.md",async()=>{let f=XZ.version,$=this.languages.map((v)=>{let H=this.problem_ymls[v].title,Y=`- *${v}*: ${H}
|
|
4072
|
+
*/var Vs={};YZ(Vs,{schema:()=>eB2,meta:()=>dZ5,create:()=>FZ5});var PD1={};YZ(PD1,{ringTwo:()=>QB2,ringThree:()=>nB2,ringOne:()=>iB2,ringFour:()=>pB2,ringFive:()=>rB2,ring:()=>aB2});var aB2={container:(f,$)=>{var Z,w,q,v,K,H,Y,P,M,W,J,X,O,G,V,N,E,j,g,k;return`${(w=(Z=f.ringOne)===null||Z===void 0?void 0:Z.value(f,$))!==null&&w!==void 0?w:""}${(v=(q=f.ringTwo)===null||q===void 0?void 0:q.value(f,$))!==null&&v!==void 0?v:""}${(H=(K=f.ringThree)===null||K===void 0?void 0:K.value(f,$))!==null&&H!==void 0?H:""}${(P=(Y=f.ringFour)===null||Y===void 0?void 0:Y.value(f,$))!==null&&P!==void 0?P:""}${(W=(M=f.ringFive)===null||M===void 0?void 0:M.value(f,$))!==null&&W!==void 0?W:""}<g transform="matrix(1 0 0 -1 0 100)">${(X=(J=f.ringOne)===null||J===void 0?void 0:J.value(f,$))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(G=(O=f.ringTwo)===null||O===void 0?void 0:O.value(f,$))!==null&&G!==void 0?G:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(N=(V=f.ringThree)===null||V===void 0?void 0:V.value(f,$))!==null&&N!==void 0?N:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(j=(E=f.ringFour)===null||E===void 0?void 0:E.value(f,$))!==null&&j!==void 0?j:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(g=f.ringFive)===null||g===void 0?void 0:g.value(f,$))!==null&&k!==void 0?k:""}</g><circle cx="50" cy="50" r="45" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="25" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="10" fill="#fff" fill-opacity=".25" style="mix-blend-mode:lighten"/>`}};var iB2={half:(f,$)=>`<path d="M90 50h10c0-27.614-22.386-50-50-50S0 22.386 0 50h10c0-22.091 17.909-40 40-40s40 17.909 40 40Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${B1.xml(`${$.ring}`)}"/>`,eighth:(f,$)=>`<path d="M21.716 21.716C14.477 28.954 10 38.954 10 50H0c0-13.807 5.596-26.307 14.645-35.355l7.07 7.07Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="45" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var QB2={eighth:(f,$)=>`<path d="M20 50c0-8.284 3.358-15.784 8.787-21.213l-7.071-7.071C14.477 28.954 10 38.954 10 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M90 50c0-22.091-17.909-40-40-40S10 27.909 10 50h10c0-16.569 13.431-30 30-30 16.569 0 30 13.431 30 30h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="35" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var nB2={eighth:(f,$)=>`<path d="M30 50a19.937 19.937 0 0 1 5.858-14.142l-7.071-7.071C23.357 34.216 20 41.716 20 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M80 50c0-16.569-13.431-30-30-30-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20s20 8.954 20 20h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="25" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var pB2={eighth:(f,$)=>`<path d="M40 50a9.97 9.97 0 0 1 2.929-7.071l-7.071-7.071A19.937 19.937 0 0 0 30 50h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M70 50c0-11.046-8.954-20-20-20s-20 8.954-20 20h10c0-5.523 4.477-10 10-10s10 4.477 10 10h10Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="15" stroke="${B1.xml(`${$.ring}`)}" stroke-width="10"/>`};var rB2={eighth:(f,$)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${B1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${B1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${B1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="10" fill="${B1.xml(`${$.ring}`)}"/>`};function hA({prng:f,group:$,width:Z,height:w,values:q=[],rotation:v,offsetX:K,offsetY:H}){let Y=PD1,P=f.pick(q),M=f.integer(Math.min(...v),Math.max(...v)),W=f.integer(Math.min(...K),Math.max(...K)),J=f.integer(Math.min(...H),Math.max(...H));if(P&&Y[$][P])return{name:P,value(X,O){var G,V,N;let E=Y[$][P](X,O);if(this.rotation||this.offsetX||this.offsetY)E=`<g transform="translate(${(G=this.offsetX)!==null&&G!==void 0?G:0}, ${(V=this.offsetY)!==null&&V!==void 0?V:0}) rotate(${(N=this.rotation)!==null&&N!==void 0?N:0} ${Z/2} ${w/2})">${E}</g>`;return E},rotation:M,offsetX:W,offsetY:J};else return}function oB2({prng:f,options:$}){var Z,w,q,v,K,H;let Y=hA({prng:f,group:"ring",values:$.ring,width:100,height:100,rotation:((Z=$.ringRotation)===null||Z===void 0?void 0:Z.length)?$.ringRotation:[0],offsetX:[0],offsetY:[0]}),P=hA({prng:f,group:"ringOne",values:$.ringOne,width:100,height:100,rotation:((w=$.ringOneRotation)===null||w===void 0?void 0:w.length)?$.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),M=hA({prng:f,group:"ringTwo",values:$.ringTwo,width:100,height:100,rotation:((q=$.ringTwoRotation)===null||q===void 0?void 0:q.length)?$.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),W=hA({prng:f,group:"ringThree",values:$.ringThree,width:100,height:100,rotation:((v=$.ringThreeRotation)===null||v===void 0?void 0:v.length)?$.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),J=hA({prng:f,group:"ringFour",values:$.ringFour,width:100,height:100,rotation:((K=$.ringFourRotation)===null||K===void 0?void 0:K.length)?$.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),X=hA({prng:f,group:"ringFive",values:$.ringFive,width:100,height:100,rotation:((H=$.ringFiveRotation)===null||H===void 0?void 0:H.length)?$.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:Y,ringOne:P,ringTwo:M,ringThree:W,ringFour:J,ringFive:X}}function tB2(f){return f==="transparent"?f:`#${f}`}function sB2({prng:f,options:$}){var Z;return{ring:tB2(f.pick((Z=$.ringColor)!==null&&Z!==void 0?Z:[],"transparent"))}}var eB2={$schema:"http://json-schema.org/draft-07/schema#",properties:{ring:{type:"array",items:{type:"string",enum:["container"]},default:["container"]},ringColor:{type:"array",items:{type:"string",pattern:"^(transparent|[a-fA-F0-9]{6})$"},default:["ffd54f","64b5f6","4dd0e1","ff8a65","9575cd","81c784","7986cb","4fc3f7","aed581","dce775","ffb74d","f06292","ba68c8","e57373","4db6ac","fff176"]},ringFive:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["full"]},ringFiveRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringFour:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringFourRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringOne:{type:"array",items:{type:"string",enum:["half","quarter","eighth","full"]},default:["half","quarter"]},ringOneRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringThree:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringThreeRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringTwo:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringTwoRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]}}};var dZ5={title:"Rings",creator:"DiceBear",source:"https://www.dicebear.com",homepage:"https://www.dicebear.com",license:{name:"CC0 1.0",url:"https://creativecommons.org/publicdomain/zero/1.0/"}},FZ5=({prng:f,options:$})=>{var Z,w;let q=oB2({prng:f,options:$}),v=sB2({prng:f,options:$});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(w=(Z=q.ring)===null||Z===void 0?void 0:Z.value(q,v))!==null&&w!==void 0?w:""}`,extra:()=>({...Object.entries(q).reduce((K,[H,Y])=>{return K[H]=Y===null||Y===void 0?void 0:Y.name,K},{}),...Object.entries(v).reduce((K,[H,Y])=>{return K[`${H}Color`]=Y,K},{})})}};var JD1=H4(fd2(),1);Gz();var wd2=H4(Go(),1);import{cp as ef,exists as Cs,glob as uq,mkdir as NW,rm as $d2,writeFile as rZ5}from"fs/promises";import bE from"os";import{join as j2,resolve as oZ5}from"path";class hD1{directory;problem_nm;workspace;workDir;stagingDir;stagingDirLang="to-be-set";workDirLang="to-be-set";problem_id="to-be-set";languages=[];original_language="";problem_ymls={};handlers={};author="";author_email="";problem_type="std";constructor(f,$){if(this.directory=oZ5(f),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=$,this.workspace=j2(f,D0()+"-stage",A_()),this.workDir=j2(this.workspace,"work.pbm"),this.stagingDir=j2(this.workspace,"stage",this.problem_nm)}async stage(){await L.section(`Staging problem at ${L.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await L.section(`Staging language ${f}`,async()=>{if(await this.setLanguage(f),this.problem_type==="std")await this.stageLanguage_Std(f);else if(this.problem_type==="game")await this.stageLanguage_Game(f);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(f)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await L.section("Summary",async()=>{let f=j2(this.stagingDir,"README.md");L.success("README.md content:"),await L.markdown(await V5(f)),L.success("Staging tree:"),L.print(wd2.default(this.stagingDir))}),L.success(`Problem successfully staged at directory ${L.hyperlink(this.stagingDir)}`),await jB2(this.stagingDir)}async stageLanguage_Std(f){await this.prepareStatements_Std(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Std(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Std(f)}async stageLanguage_Game(f){await this.prepareStatements_Game(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Game(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Game(f),await this.stageViewer(f)}async stageLanguage_Quizz(f){await this.stageQuiz(f)}async setLanguage(f){this.workDirLang=j2(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=j2(this.stagingDir,f),await NW(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await L.section(`Creating workspace ${this.workspace}`,async()=>{if(await Cs(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await NW(this.workspace,{recursive:!0}),await NW(this.workDir,{recursive:!0}),await NW(this.stagingDir,{recursive:!0}),L.directory(this.workspace)})}doNotCopy(f,$){if(f==="problem.yml")return!0;if(f.startsWith(D0()))return!0;let Z=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(Z&&Z[1]!==$)return!0;if(f===`problem.${$}.pdf`)return!0;return!1}async separateByLanguages(){await L.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(uq("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await L.section("Separating problem by languages without folders",async()=>{let $=(await Array.fromAsync(uq("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((Z)=>{let w=Z.match(/^problem\.([a-z][a-z])\.yml$/);if(!w)throw Error(`Unexpected yml file name: ${Z}`);return w[1]});this.languages=$;for(let Z of $){let w=j2(this.workDir,Z);await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:this.directory}));for(let v of q){if(this.doNotCopy(v,Z))continue;await ef(j2(this.directory,v),j2(w,v),{recursive:!0})}}L.success(`Found languages: ${$.join(", ")}`)})}async separateByLanguagesWithFolders(){await L.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(uq("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let $ of f){let Z=j2(this.directory,$),w=j2(this.workDir,$);await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:Z}));for(let v of q){if(this.doNotCopy(v,$))continue;await ef(j2(Z,v),j2(w,v),{recursive:!0})}}L.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await L.section("Reading problem metadata",async()=>{for(let $ of this.languages){let Z=j2(this.workDir,$,`problem.${$}.yml`);this.problem_ymls[$]=await O_(Z),Tx.parse(this.problem_ymls[$])}for(let $ of this.languages){let Z=j2(this.workDir,$,"handler.yml");this.handlers[$]=await O_(Z)}for(let $ of this.languages){let Z=this.problem_ymls[$];if(Z.author)this.author=Z.author;if(Z.author)this.original_language=$;if(Z.email)this.author_email=Z.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:f}=this.handlers[this.original_language];if(f==="game")this.problem_type="game";else if(f==="quiz")this.problem_type="quiz";else this.problem_type="std";L.success(`Problem type: ${this.problem_type}`),L.success(`Original language: ${this.original_language}`),L.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await L.section("Finding golden solution",async()=>{let $=this.handlers[f].handler,Z=this.handlers[f].compilers||"",w=this.handlers[f].solution,q;if($==="circuits")q="solution.v";else if(Z==="RunPython")q="solution.py";else if(Z==="RunHaskell"||Z==="GHC"||w==="Haskell")q="solution.hs";else if(Z==="RunClojure"||Z==="Clojure")q="solution.clj";else if(Z==="PRO2"||Z==="MakePRO2"){let v=await Array.fromAsync(uq("solution.{cc,hh,tar}",{cwd:this.directory}));if(v.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${v.join(", ")}`);q=v[0]}else{let v=this.handlers[f].solution||"C++";if(v==="C++"){let P=await Array.fromAsync(uq("solution.*",{cwd:this.directory}));if(L.print(P.join(", ")),P.length===1){let M=P[0].split(".").pop();v=XD1[M]}}let K=tZ5[v];if(!K)throw Error(`Unknown programming language ${v} for solution`);let H=j2(this.workDir,f,`solution.${K}`);if(!await Cs(H))throw Error(`Golden solution file ${H} not found`);q=`solution.${K}`}return L.success(`Golden solution: ${q}`),q})}async prepareStatements_Std(f){await L.section("Preparing statements",async()=>{let $=j2(this.workDir,f);L.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await K3({cwd:$,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:L.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await $d2(j2($,"jtk-pdf"),{recursive:!0,force:!0}),await $d2(j2($,"jtk-text"),{recursive:!0,force:!0}),L.success("Generated statements")})}async prepareStatements_Game(f){await L.section("Preparing game statements",async()=>{let $=j2(this.workDirLang,"Doc");await L.section("Generating PDF with xelatex",async()=>{L.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await K3({cwd:$})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await K3({cwd:$})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await ef(j2($,"main.pdf"),j2(this.workDirLang,`problem.${f}.pdf`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await L.section("Generating TXT with pandoc",async()=>{L.command("pandoc --quiet main.tex --to plain --output main.txt"),await K3({cwd:$})`pandoc --quiet main.tex --to plain --output main.txt`,await ef(j2($,"main.txt"),j2(this.workDirLang,`problem.${f}.txt`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await ef(j2($,"main.txt"),j2(this.workDirLang,`problem.${f}.short.txt`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await L.section("Generating Markdown with pandoc",async()=>{L.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await K3({cwd:$})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await ef(j2($,"main.md"),j2(this.workDirLang,`problem.${f}.md`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await ef(j2($,"main.md"),j2(this.workDirLang,`problem.${f}.short.md`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await L.section("Generating HTML with pandoc",async()=>{L.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await K3({cwd:$})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await ef(j2($,"main.html"),j2(this.workDirLang,`problem.${f}.html`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await ef(j2($,"main.html"),j2(this.workDirLang,`problem.${f}.short.html`)),L.success(`Generated ${L.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(!await $V2()){L.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await L.section("Skipping code metrics",async()=>{await J5(),L.warning("Code metrics not applicable for this problem type")});return}await L.section("Computing code metrics",async()=>{let $=await this.findGoldenSolution(f);L.command(`jutge-code-metrics ${$}`);try{let{stdout:Z}=await K3({cwd:this.workDirLang})`jutge-code-metrics ${$}`;await m7(j2(this.stagingDirLang,"code-metrics.json"),Z),L.success(`Generated ${L.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(Z){L.warning("Failed to compute code metrics")}})}async stageProblemFiles_Std(f){let $=(q)=>{if(q==="handler.yml")return!0;for(let v of["inp","cor","ops"])if(q.endsWith(`.${v}`))return!0;for(let v of Zd2){if(q===`solution.${v}`)return!0;if(q===`main.${v}`)return!0}if(q==="scores.yml")return!0;if(q==="checker.py")return!0;if(q==="checker.cc")return!0;if(q==="private.tar")return!0;if(q==="public.tar")return!0;if(q==="solution.tar")return!0;if(q==="solution.cc")return!0;if(q==="solution.hh")return!0;return!1},Z=j2(this.stagingDirLang,"problem.pbm");await NW(Z,{recursive:!0});let w=await Array.fromAsync(uq("*",{cwd:this.workDirLang}));for(let q of w)if($(q))await ef(j2(this.workDirLang,q),j2(Z,q));await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"problem.yml")),L.success(`Problem staged to ${L.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let $=(v)=>{if(v==="handler.yml")return!0;if(v==="Makefile")return!0;if(v==="README.txt")return!0;if(v==="README.md")return!0;if(v.endsWith(".cc"))return!0;if(v.endsWith(".hh"))return!0;if(v.endsWith(".cnf"))return!0;return!1},Z=j2(this.workDirLang,"Runner"),w=j2(this.stagingDirLang,"problem.pbm");await NW(w,{recursive:!0});let q=await Array.fromAsync(uq("*",{cwd:Z}));for(let v of q)if($(v))await ef(j2(Z,v),j2(w,v));await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(w,"problem.yml")),L.success(`Problem staged to ${L.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await L.section("Staging awards",async()=>{let $=0;for(let Z of["award.png","award.txt"])if(await BZ(this.workDirLang,Z))await ef(j2(this.workDirLang,Z),j2(this.stagingDir,Z)),$++;if($>0)L.success(`Staged ${$} award file(s)`);else L.warning("No award files found")})}async stageStatements(f){await L.section("Staging statements",async()=>{let $=0;for(let Z of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let w=`problem.${f}.${Z}`,q=`problem.${Z}`;if(await BZ(this.workDirLang,w))await ef(j2(this.workDirLang,w),j2(this.stagingDirLang,q)),$++}L.success(`Staged ${$} statement file(s)`)})}async stageFirstToSolve(){await L.section("Staging first-to-solve avatar",async()=>{let f=j2(this.stagingDir,"first-to-solve.svg"),Z=UB2(Vs,{seed:this.problem_nm}).toString();await m7(f,Z),L.success(`Generated ${L.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let $=(q)=>{for(let v of["pdf","html","md","txt"])if(q===`problem.${f}.${v}`)return!0;for(let v of Zd2){if(q===`main.${v}`)return!0;if(q===`code.${v}`)return!0}if((q.includes("sample")||q.startsWith("public")||q.startsWith("hint")||q.startsWith("distilled"))&&(q.endsWith(".inp")||q.endsWith(".cor")))return!0;if(q==="sample.dt")return!0;return!1},Z=[],w=await Array.fromAsync(uq("*",{cwd:this.workDirLang}));for(let q of w)if($(q))Z.push({sourcePath:j2(this.workDirLang,q),archivePath:j2(`${this.problem_id}`,q)});await ab(Z,j2(this.stagingDirLang,"problem.zip")),L.success(`Created ${L.hyperlink(this.stagingDirLang,"problem.zip")} with ${Z.length} files`)}async stageZip_Game(f){let $=this.handlers[this.original_language].game.hide||["AIDummy.cc"],Z=(q)=>{if(q.endsWith(".cc")||q.endsWith(".hh"))return!$.includes(q);if(q.endsWith(".cnf"))return!0;if(q=="Makefile")return!0;if(q=="README.txt")return!0;if(q=="README.md")return!0;return!1},w=[];for(let q of["pdf","html","md","txt","short.html","short.md","short.txt"]){let v=`problem.${f}.${q}`;if(await BZ(this.workDirLang,v))w.push({sourcePath:j2(this.workDirLang,v),archivePath:j2(`${this.problem_id}`,v)})}{let q=j2(this.workDirLang,"Runner"),v=await Array.fromAsync(uq("*",{cwd:q}));for(let K of v)if(Z(K))w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src",K)})}{let q=j2(this.workDirLang,"Obj"),v=await Array.fromAsync(uq("*.o.*",{cwd:q}));for(let K of v)w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src",K)})}{let q=j2(this.workDirLang,"Viewer"),v=await Array.fromAsync(uq("**/*",{cwd:q}));for(let K of v)w.push({sourcePath:j2(q,K),archivePath:j2(`${this.problem_id}`,"src","Viewer",K)})}await ab(w,j2(this.stagingDirLang,"problem.zip")),L.success(`Created ${L.hyperlink(this.stagingDirLang,"problem.zip")} with ${w.length} files`)}async stageViewer(f){await L.section("Staging viewer",async()=>{await ef(j2(this.workDirLang,"Viewer"),j2(this.stagingDirLang,"viewer"),{recursive:!0}),L.success(`Staged ${L.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await L.section("Staging quiz",async()=>{let $=yl.parse(await O_(j2(this.workDirLang,"quiz.yml"))),Z=j2(this.stagingDirLang,"quiz.pbm");await NW(Z,{recursive:!0}),await AJ(j2(Z,"quiz.yml"),$),await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"problem.yml")),await ef(j2(this.workDirLang,`problem.${f}.yml`),j2(Z,"..","problem.yml"));for(let w of $.questions){{let q=j2(this.workDirLang,`${w.file}.yml`),v=j2(Z,`${w.file}.yml`);if(await Cs(q))await ef(q,v);else throw Error(`Quiz question file ${w.file}.yml not found`)}{let q=j2(this.workDirLang,`${w.file}.py`),v=j2(Z,`${w.file}.py`);if(await Cs(q))await ef(q,v)}}L.success(`Staged ${L.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await L.section("Staging information.yml",async()=>{let f={problem_nm:this.problem_nm,languages:this.languages,original_language:this.original_language,author:this.author,author_email:this.author_email,problems:this.problem_ymls,handlers:this.handlers},$=j2(this.stagingDir,"information.yml");await AJ($,f),L.success(`Generated ${L.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await L.section("Staging README.md",async()=>{let f=XZ.version,$=this.languages.map((v)=>{let H=this.problem_ymls[v].title,Y=`- *${v}*: ${H}
|
|
4073
4073
|
`;if(v!==this.original_language)Y+=` ${this.problem_ymls[v].translator} <${this.problem_ymls[v].translator_email}>`;else Y="";return Y}).join(`
|
|
4074
4074
|
`);if($.trim())$=`## Translations
|
|
4075
4075
|
|