pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
51 lines (49 loc) • 1.48 kB
JavaScript
;
function extractOutputs(fragmentSource, out) {
let match;
const regex = /@out\s+([^;]+);/g;
while ((match = regex.exec(fragmentSource)) !== null) {
out.push(match[1]);
}
}
function extractVariableName(value) {
const regex = /\b(\w+)\s*:/g;
const match = regex.exec(value);
return match ? match[1] : "";
}
function stripVariable(value) {
const regex = /@.*?\s+/g;
return value.replace(regex, "");
}
function compileOutputs(fragments, template) {
const results = [];
extractOutputs(template, results);
fragments.forEach((fragment) => {
if (fragment.header) {
extractOutputs(fragment.header, results);
}
});
let index = 0;
const mainStruct = results.sort().map((inValue) => {
if (inValue.indexOf("builtin") > -1) {
return inValue;
}
return `@location(${index++}) ${inValue}`;
}).join(",\n");
const mainStart = results.sort().map((inValue) => ` var ${stripVariable(inValue)};`).join("\n");
const mainEnd = `return VSOutput(
${results.sort().map((inValue) => ` ${extractVariableName(inValue)}`).join(",\n")});`;
let compiledCode = template.replace(/@out\s+[^;]+;\s*/g, "");
compiledCode = compiledCode.replace("{{struct}}", `
${mainStruct}
`);
compiledCode = compiledCode.replace("{{start}}", `
${mainStart}
`);
compiledCode = compiledCode.replace("{{return}}", `
${mainEnd}
`);
return compiledCode;
}
export { compileOutputs };
//# sourceMappingURL=compileOutputs.mjs.map