This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,19 @@
import type { HighShaderBit, HighShaderSource } from './types';
/** A high template consists of vertex and fragment source */
export interface HighShaderTemplate {
name?: string;
fragment: string;
vertex: string;
}
export interface CompileHighShaderOptions {
template: HighShaderTemplate;
bits: HighShaderBit[];
}
/**
* This function will take a HighShader template, some High fragments and then merge them in to a shader source.
* @param options
* @param options.template
* @param options.bits
*/
export declare function compileHighShader({ template, bits }: CompileHighShaderOptions): HighShaderSource;
export declare function compileHighShaderGl({ template, bits }: CompileHighShaderOptions): HighShaderSource;

View File

@@ -0,0 +1,68 @@
'use strict';
var addBits = require('./utils/addBits.js');
var compileHooks = require('./utils/compileHooks.js');
var compileInputs = require('./utils/compileInputs.js');
var compileOutputs = require('./utils/compileOutputs.js');
var injectBits = require('./utils/injectBits.js');
"use strict";
const cacheMap = /* @__PURE__ */ Object.create(null);
const bitCacheMap = /* @__PURE__ */ new Map();
let CACHE_UID = 0;
function compileHighShader({
template,
bits
}) {
const cacheId = generateCacheId(template, bits);
if (cacheMap[cacheId])
return cacheMap[cacheId];
const { vertex, fragment } = compileInputsAndOutputs(template, bits);
cacheMap[cacheId] = compileBits(vertex, fragment, bits);
return cacheMap[cacheId];
}
function compileHighShaderGl({
template,
bits
}) {
const cacheId = generateCacheId(template, bits);
if (cacheMap[cacheId])
return cacheMap[cacheId];
cacheMap[cacheId] = compileBits(template.vertex, template.fragment, bits);
return cacheMap[cacheId];
}
function compileInputsAndOutputs(template, bits) {
const vertexFragments = bits.map((shaderBit) => shaderBit.vertex).filter((v) => !!v);
const fragmentFragments = bits.map((shaderBit) => shaderBit.fragment).filter((v) => !!v);
let compiledVertex = compileInputs.compileInputs(vertexFragments, template.vertex, true);
compiledVertex = compileOutputs.compileOutputs(vertexFragments, compiledVertex);
const compiledFragment = compileInputs.compileInputs(fragmentFragments, template.fragment, true);
return {
vertex: compiledVertex,
fragment: compiledFragment
};
}
function generateCacheId(template, bits) {
return bits.map((highFragment) => {
if (!bitCacheMap.has(highFragment)) {
bitCacheMap.set(highFragment, CACHE_UID++);
}
return bitCacheMap.get(highFragment);
}).sort((a, b) => a - b).join("-") + template.vertex + template.fragment;
}
function compileBits(vertex, fragment, bits) {
const vertexParts = compileHooks.compileHooks(vertex);
const fragmentParts = compileHooks.compileHooks(fragment);
bits.forEach((shaderBit) => {
addBits.addBits(shaderBit.vertex, vertexParts, shaderBit.name);
addBits.addBits(shaderBit.fragment, fragmentParts, shaderBit.name);
});
return {
vertex: injectBits.injectBits(vertex, vertexParts),
fragment: injectBits.injectBits(fragment, fragmentParts)
};
}
exports.compileHighShader = compileHighShader;
exports.compileHighShaderGl = compileHighShaderGl;
//# sourceMappingURL=compileHighShader.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,65 @@
import { addBits } from './utils/addBits.mjs';
import { compileHooks } from './utils/compileHooks.mjs';
import { compileInputs } from './utils/compileInputs.mjs';
import { compileOutputs } from './utils/compileOutputs.mjs';
import { injectBits } from './utils/injectBits.mjs';
"use strict";
const cacheMap = /* @__PURE__ */ Object.create(null);
const bitCacheMap = /* @__PURE__ */ new Map();
let CACHE_UID = 0;
function compileHighShader({
template,
bits
}) {
const cacheId = generateCacheId(template, bits);
if (cacheMap[cacheId])
return cacheMap[cacheId];
const { vertex, fragment } = compileInputsAndOutputs(template, bits);
cacheMap[cacheId] = compileBits(vertex, fragment, bits);
return cacheMap[cacheId];
}
function compileHighShaderGl({
template,
bits
}) {
const cacheId = generateCacheId(template, bits);
if (cacheMap[cacheId])
return cacheMap[cacheId];
cacheMap[cacheId] = compileBits(template.vertex, template.fragment, bits);
return cacheMap[cacheId];
}
function compileInputsAndOutputs(template, bits) {
const vertexFragments = bits.map((shaderBit) => shaderBit.vertex).filter((v) => !!v);
const fragmentFragments = bits.map((shaderBit) => shaderBit.fragment).filter((v) => !!v);
let compiledVertex = compileInputs(vertexFragments, template.vertex, true);
compiledVertex = compileOutputs(vertexFragments, compiledVertex);
const compiledFragment = compileInputs(fragmentFragments, template.fragment, true);
return {
vertex: compiledVertex,
fragment: compiledFragment
};
}
function generateCacheId(template, bits) {
return bits.map((highFragment) => {
if (!bitCacheMap.has(highFragment)) {
bitCacheMap.set(highFragment, CACHE_UID++);
}
return bitCacheMap.get(highFragment);
}).sort((a, b) => a - b).join("-") + template.vertex + template.fragment;
}
function compileBits(vertex, fragment, bits) {
const vertexParts = compileHooks(vertex);
const fragmentParts = compileHooks(fragment);
bits.forEach((shaderBit) => {
addBits(shaderBit.vertex, vertexParts, shaderBit.name);
addBits(shaderBit.fragment, fragmentParts, shaderBit.name);
});
return {
vertex: injectBits(vertex, vertexParts),
fragment: injectBits(fragment, fragmentParts)
};
}
export { compileHighShader, compileHighShaderGl };
//# sourceMappingURL=compileHighShader.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,41 @@
/** the vertex source code, an obj */
export type Vertex = {
/** stick uniforms and functions in here all headers will be compiled at the top of the shader */
header?: string;
/** code will be added at the start of the shader */
start?: string;
/** code will be run here before lighting happens */
main?: string;
/** code here will to modify anything before it is passed to the fragment shader */
end?: string;
};
export type Fragment = {
/** stick uniforms and functions in here all headers will be compiled at the top of the shader */
header?: string;
/** code will be added at the start of the shader */
start?: string;
/** code will be run here before lighting happens */
main?: string;
/** code here will to modify anything before it is passed to the fragment shader */
end?: string;
};
/**
* HighShaderBit is a part of a shader.
* it is used to compile HighShaders.
*
* Internally shaders are made up of many of these.
* You can even write your own and compile them in.
*/
export interface HighShaderBit {
/** used to make the shader easier to understand! */
name?: string;
/** the snippets of vertex code */
vertex?: Vertex;
/** the snippets of fragment code */
fragment?: Fragment;
}
/** source code to compile a shader. this can be directly used by pixi and should be good to go! */
export interface HighShaderSource {
fragment: string;
vertex: string;
}

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=types.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,7 @@
/**
* takes the HighFragment source parts and adds them to the hook hash
* @param srcParts - the hash of hook arrays
* @param parts - the code to inject into the hooks
* @param name - optional the name of the part to add
*/
export declare function addBits(srcParts: Record<string, string>, parts: Record<string, string[]>, name?: string): void;

View File

@@ -0,0 +1,28 @@
'use strict';
var warn = require('../../../../utils/logging/warn.js');
"use strict";
function addBits(srcParts, parts, name) {
if (srcParts) {
for (const i in srcParts) {
const id = i.toLocaleLowerCase();
const part = parts[id];
if (part) {
let sanitisedPart = srcParts[i];
if (i === "header") {
sanitisedPart = sanitisedPart.replace(/@in\s+[^;]+;\s*/g, "").replace(/@out\s+[^;]+;\s*/g, "");
}
if (name) {
part.push(`//----${name}----//`);
}
part.push(sanitisedPart);
} else {
warn.warn(`${i} placement hook does not exist in shader`);
}
}
}
}
exports.addBits = addBits;
//# sourceMappingURL=addBits.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"addBits.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/addBits.ts"],"sourcesContent":["import { warn } from '../../../../utils/logging/warn';\n\n/**\n * takes the HighFragment source parts and adds them to the hook hash\n * @param srcParts - the hash of hook arrays\n * @param parts - the code to inject into the hooks\n * @param name - optional the name of the part to add\n */\nexport function addBits(srcParts: Record<string, string>, parts: Record<string, string[]>, name?: string)\n{\n if (srcParts)\n {\n for (const i in srcParts)\n {\n const id = i.toLocaleLowerCase();\n\n const part = parts[id];\n\n if (part)\n {\n let sanitisedPart = srcParts[i];\n\n if (i === 'header')\n {\n sanitisedPart = sanitisedPart\n .replace(/@in\\s+[^;]+;\\s*/g, '')\n .replace(/@out\\s+[^;]+;\\s*/g, '');\n }\n\n if (name)\n {\n part.push(`//----${name}----//`);\n }\n part.push(sanitisedPart);\n }\n\n else\n {\n // #if _DEBUG\n warn(`${i} placement hook does not exist in shader`);\n // #endif\n }\n }\n }\n}\n"],"names":["warn"],"mappings":";;;;;AAQgB,SAAA,OAAA,CAAQ,QAAkC,EAAA,KAAA,EAAiC,IAC3F,EAAA;AACI,EAAA,IAAI,QACJ,EAAA;AACI,IAAA,KAAA,MAAW,KAAK,QAChB,EAAA;AACI,MAAM,MAAA,EAAA,GAAK,EAAE,iBAAkB,EAAA,CAAA;AAE/B,MAAM,MAAA,IAAA,GAAO,MAAM,EAAE,CAAA,CAAA;AAErB,MAAA,IAAI,IACJ,EAAA;AACI,QAAI,IAAA,aAAA,GAAgB,SAAS,CAAC,CAAA,CAAA;AAE9B,QAAA,IAAI,MAAM,QACV,EAAA;AACI,UAAA,aAAA,GAAgB,cACX,OAAQ,CAAA,kBAAA,EAAoB,EAAE,CAC9B,CAAA,OAAA,CAAQ,qBAAqB,EAAE,CAAA,CAAA;AAAA,SACxC;AAEA,QAAA,IAAI,IACJ,EAAA;AACI,UAAK,IAAA,CAAA,IAAA,CAAK,CAAS,MAAA,EAAA,IAAI,CAAQ,MAAA,CAAA,CAAA,CAAA;AAAA,SACnC;AACA,QAAA,IAAA,CAAK,KAAK,aAAa,CAAA,CAAA;AAAA,OAI3B,MAAA;AAEI,QAAKA,SAAA,CAAA,CAAA,EAAG,CAAC,CAA0C,wCAAA,CAAA,CAAA,CAAA;AAAA,OAEvD;AAAA,KACJ;AAAA,GACJ;AACJ;;;;"}

View File

@@ -0,0 +1,26 @@
import { warn } from '../../../../utils/logging/warn.mjs';
"use strict";
function addBits(srcParts, parts, name) {
if (srcParts) {
for (const i in srcParts) {
const id = i.toLocaleLowerCase();
const part = parts[id];
if (part) {
let sanitisedPart = srcParts[i];
if (i === "header") {
sanitisedPart = sanitisedPart.replace(/@in\s+[^;]+;\s*/g, "").replace(/@out\s+[^;]+;\s*/g, "");
}
if (name) {
part.push(`//----${name}----//`);
}
part.push(sanitisedPart);
} else {
warn(`${i} placement hook does not exist in shader`);
}
}
}
}
export { addBits };
//# sourceMappingURL=addBits.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"addBits.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/addBits.ts"],"sourcesContent":["import { warn } from '../../../../utils/logging/warn';\n\n/**\n * takes the HighFragment source parts and adds them to the hook hash\n * @param srcParts - the hash of hook arrays\n * @param parts - the code to inject into the hooks\n * @param name - optional the name of the part to add\n */\nexport function addBits(srcParts: Record<string, string>, parts: Record<string, string[]>, name?: string)\n{\n if (srcParts)\n {\n for (const i in srcParts)\n {\n const id = i.toLocaleLowerCase();\n\n const part = parts[id];\n\n if (part)\n {\n let sanitisedPart = srcParts[i];\n\n if (i === 'header')\n {\n sanitisedPart = sanitisedPart\n .replace(/@in\\s+[^;]+;\\s*/g, '')\n .replace(/@out\\s+[^;]+;\\s*/g, '');\n }\n\n if (name)\n {\n part.push(`//----${name}----//`);\n }\n part.push(sanitisedPart);\n }\n\n else\n {\n // #if _DEBUG\n warn(`${i} placement hook does not exist in shader`);\n // #endif\n }\n }\n }\n}\n"],"names":[],"mappings":";;;AAQgB,SAAA,OAAA,CAAQ,QAAkC,EAAA,KAAA,EAAiC,IAC3F,EAAA;AACI,EAAA,IAAI,QACJ,EAAA;AACI,IAAA,KAAA,MAAW,KAAK,QAChB,EAAA;AACI,MAAM,MAAA,EAAA,GAAK,EAAE,iBAAkB,EAAA,CAAA;AAE/B,MAAM,MAAA,IAAA,GAAO,MAAM,EAAE,CAAA,CAAA;AAErB,MAAA,IAAI,IACJ,EAAA;AACI,QAAI,IAAA,aAAA,GAAgB,SAAS,CAAC,CAAA,CAAA;AAE9B,QAAA,IAAI,MAAM,QACV,EAAA;AACI,UAAA,aAAA,GAAgB,cACX,OAAQ,CAAA,kBAAA,EAAoB,EAAE,CAC9B,CAAA,OAAA,CAAQ,qBAAqB,EAAE,CAAA,CAAA;AAAA,SACxC;AAEA,QAAA,IAAI,IACJ,EAAA;AACI,UAAK,IAAA,CAAA,IAAA,CAAK,CAAS,MAAA,EAAA,IAAI,CAAQ,MAAA,CAAA,CAAA,CAAA;AAAA,SACnC;AACA,QAAA,IAAA,CAAK,KAAK,aAAa,CAAA,CAAA;AAAA,OAI3B,MAAA;AAEI,QAAK,IAAA,CAAA,CAAA,EAAG,CAAC,CAA0C,wCAAA,CAAA,CAAA,CAAA;AAAA,OAEvD;AAAA,KACJ;AAAA,GACJ;AACJ;;;;"}

View File

@@ -0,0 +1,6 @@
export declare const findHooksRx: RegExp;
/**
* takes a program string and returns an hash mapping the hooks to empty arrays
* @param programSrc - the program containing hooks
*/
export declare function compileHooks(programSrc: string): Record<string, string[]>;

View File

@@ -0,0 +1,16 @@
'use strict';
"use strict";
const findHooksRx = /\{\{(.*?)\}\}/g;
function compileHooks(programSrc) {
const parts = {};
const partMatches = programSrc.match(findHooksRx)?.map((hook) => hook.replace(/[{()}]/g, "")) ?? [];
partMatches.forEach((hook) => {
parts[hook] = [];
});
return parts;
}
exports.compileHooks = compileHooks;
exports.findHooksRx = findHooksRx;
//# sourceMappingURL=compileHooks.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileHooks.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileHooks.ts"],"sourcesContent":["export const findHooksRx = /\\{\\{(.*?)\\}\\}/g;\n\n/**\n * takes a program string and returns an hash mapping the hooks to empty arrays\n * @param programSrc - the program containing hooks\n */\nexport function compileHooks(programSrc: string): Record<string, string[]>\n{\n const parts: Record<string, string[]> = {};\n\n const partMatches = programSrc\n .match(findHooksRx)\n ?.map((hook) => hook.replace(/[{()}]/g, '')) ?? [];\n\n partMatches.forEach((hook) =>\n {\n parts[hook] = [];\n });\n\n return parts;\n}\n"],"names":[],"mappings":";;;AAAO,MAAM,WAAc,GAAA,iBAAA;AAMpB,SAAS,aAAa,UAC7B,EAAA;AACI,EAAA,MAAM,QAAkC,EAAC,CAAA;AAEzC,EAAA,MAAM,WAAc,GAAA,UAAA,CACf,KAAM,CAAA,WAAW,GAChB,GAAI,CAAA,CAAC,IAAS,KAAA,IAAA,CAAK,OAAQ,CAAA,SAAA,EAAW,EAAE,CAAC,KAAK,EAAC,CAAA;AAErD,EAAY,WAAA,CAAA,OAAA,CAAQ,CAAC,IACrB,KAAA;AACI,IAAM,KAAA,CAAA,IAAI,IAAI,EAAC,CAAA;AAAA,GAClB,CAAA,CAAA;AAED,EAAO,OAAA,KAAA,CAAA;AACX;;;;;"}

View File

@@ -0,0 +1,13 @@
"use strict";
const findHooksRx = /\{\{(.*?)\}\}/g;
function compileHooks(programSrc) {
const parts = {};
const partMatches = programSrc.match(findHooksRx)?.map((hook) => hook.replace(/[{()}]/g, "")) ?? [];
partMatches.forEach((hook) => {
parts[hook] = [];
});
return parts;
}
export { compileHooks, findHooksRx };
//# sourceMappingURL=compileHooks.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileHooks.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileHooks.ts"],"sourcesContent":["export const findHooksRx = /\\{\\{(.*?)\\}\\}/g;\n\n/**\n * takes a program string and returns an hash mapping the hooks to empty arrays\n * @param programSrc - the program containing hooks\n */\nexport function compileHooks(programSrc: string): Record<string, string[]>\n{\n const parts: Record<string, string[]> = {};\n\n const partMatches = programSrc\n .match(findHooksRx)\n ?.map((hook) => hook.replace(/[{()}]/g, '')) ?? [];\n\n partMatches.forEach((hook) =>\n {\n parts[hook] = [];\n });\n\n return parts;\n}\n"],"names":[],"mappings":";AAAO,MAAM,WAAc,GAAA,iBAAA;AAMpB,SAAS,aAAa,UAC7B,EAAA;AACI,EAAA,MAAM,QAAkC,EAAC,CAAA;AAEzC,EAAA,MAAM,WAAc,GAAA,UAAA,CACf,KAAM,CAAA,WAAW,GAChB,GAAI,CAAA,CAAC,IAAS,KAAA,IAAA,CAAK,OAAQ,CAAA,SAAA,EAAW,EAAE,CAAC,KAAK,EAAC,CAAA;AAErD,EAAY,WAAA,CAAA,OAAA,CAAQ,CAAC,IACrB,KAAA;AACI,IAAM,KAAA,CAAA,IAAI,IAAI,EAAC,CAAA;AAAA,GAClB,CAAA,CAAA;AAED,EAAO,OAAA,KAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1 @@
export declare function compileInputs(fragments: any[], template: string, sort?: boolean): string;

View File

@@ -0,0 +1,32 @@
'use strict';
"use strict";
function extractInputs(fragmentSource, out) {
let match;
const regex = /@in\s+([^;]+);/g;
while ((match = regex.exec(fragmentSource)) !== null) {
out.push(match[1]);
}
}
function compileInputs(fragments, template, sort = false) {
const results = [];
extractInputs(template, results);
fragments.forEach((fragment) => {
if (fragment.header) {
extractInputs(fragment.header, results);
}
});
const mainInput = results;
if (sort) {
mainInput.sort();
}
const finalString = mainInput.map((inValue, i) => ` @location(${i}) ${inValue},`).join("\n");
let cleanedString = template.replace(/@in\s+[^;]+;\s*/g, "");
cleanedString = cleanedString.replace("{{in}}", `
${finalString}
`);
return cleanedString;
}
exports.compileInputs = compileInputs;
//# sourceMappingURL=compileInputs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileInputs.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileInputs.ts"],"sourcesContent":["function extractInputs(fragmentSource: string, out: string[])\n{\n let match;\n const regex = /@in\\s+([^;]+);/g;\n\n while ((match = regex.exec(fragmentSource)) !== null)\n {\n out.push(match[1]);\n }\n}\n\nexport function compileInputs(fragments: any[], template: string, sort = false)\n{\n // get all the inputs from the fragments..\n const results: string[] = [];\n\n extractInputs(template, results);\n\n fragments.forEach((fragment) =>\n {\n if (fragment.header)\n {\n extractInputs(fragment.header, results);\n }\n });\n\n // build the input:\n const mainInput = results;\n\n if (sort)\n {\n mainInput.sort();\n }\n\n const finalString = mainInput\n .map((inValue, i) => ` @location(${i}) ${inValue},`)\n .join('\\n');\n\n // Remove lines from original string\n let cleanedString = template.replace(/@in\\s+[^;]+;\\s*/g, '');\n\n cleanedString = cleanedString.replace('{{in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,OAAA,aAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,30 @@
"use strict";
function extractInputs(fragmentSource, out) {
let match;
const regex = /@in\s+([^;]+);/g;
while ((match = regex.exec(fragmentSource)) !== null) {
out.push(match[1]);
}
}
function compileInputs(fragments, template, sort = false) {
const results = [];
extractInputs(template, results);
fragments.forEach((fragment) => {
if (fragment.header) {
extractInputs(fragment.header, results);
}
});
const mainInput = results;
if (sort) {
mainInput.sort();
}
const finalString = mainInput.map((inValue, i) => ` @location(${i}) ${inValue},`).join("\n");
let cleanedString = template.replace(/@in\s+[^;]+;\s*/g, "");
cleanedString = cleanedString.replace("{{in}}", `
${finalString}
`);
return cleanedString;
}
export { compileInputs };
//# sourceMappingURL=compileInputs.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileInputs.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileInputs.ts"],"sourcesContent":["function extractInputs(fragmentSource: string, out: string[])\n{\n let match;\n const regex = /@in\\s+([^;]+);/g;\n\n while ((match = regex.exec(fragmentSource)) !== null)\n {\n out.push(match[1]);\n }\n}\n\nexport function compileInputs(fragments: any[], template: string, sort = false)\n{\n // get all the inputs from the fragments..\n const results: string[] = [];\n\n extractInputs(template, results);\n\n fragments.forEach((fragment) =>\n {\n if (fragment.header)\n {\n extractInputs(fragment.header, results);\n }\n });\n\n // build the input:\n const mainInput = results;\n\n if (sort)\n {\n mainInput.sort();\n }\n\n const finalString = mainInput\n .map((inValue, i) => ` @location(${i}) ${inValue},`)\n .join('\\n');\n\n // Remove lines from original string\n let cleanedString = template.replace(/@in\\s+[^;]+;\\s*/g, '');\n\n cleanedString = cleanedString.replace('{{in}}', `\\n${finalString}\\n`);\n\n return cleanedString;\n}\n"],"names":[],"mappings":";AAAA,SAAS,aAAA,CAAc,gBAAwB,GAC/C,EAAA;AACI,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,MAAM,KAAQ,GAAA,iBAAA,CAAA;AAEd,EAAA,OAAA,CAAQ,KAAQ,GAAA,KAAA,CAAM,IAAK,CAAA,cAAc,OAAO,IAChD,EAAA;AACI,IAAI,GAAA,CAAA,IAAA,CAAK,KAAM,CAAA,CAAC,CAAC,CAAA,CAAA;AAAA,GACrB;AACJ,CAAA;AAEO,SAAS,aAAc,CAAA,SAAA,EAAkB,QAAkB,EAAA,IAAA,GAAO,KACzE,EAAA;AAEI,EAAA,MAAM,UAAoB,EAAC,CAAA;AAE3B,EAAA,aAAA,CAAc,UAAU,OAAO,CAAA,CAAA;AAE/B,EAAU,SAAA,CAAA,OAAA,CAAQ,CAAC,QACnB,KAAA;AACI,IAAA,IAAI,SAAS,MACb,EAAA;AACI,MAAc,aAAA,CAAA,QAAA,CAAS,QAAQ,OAAO,CAAA,CAAA;AAAA,KAC1C;AAAA,GACH,CAAA,CAAA;AAGD,EAAA,MAAM,SAAY,GAAA,OAAA,CAAA;AAElB,EAAA,IAAI,IACJ,EAAA;AACI,IAAA,SAAA,CAAU,IAAK,EAAA,CAAA;AAAA,GACnB;AAEA,EAAA,MAAM,WAAc,GAAA,SAAA,CACf,GAAI,CAAA,CAAC,OAAS,EAAA,CAAA,KAAM,CAAoB,iBAAA,EAAA,CAAC,CAAK,EAAA,EAAA,OAAO,CAAG,CAAA,CAAA,CAAA,CACxD,KAAK,IAAI,CAAA,CAAA;AAGd,EAAA,IAAI,aAAgB,GAAA,QAAA,CAAS,OAAQ,CAAA,kBAAA,EAAoB,EAAE,CAAA,CAAA;AAE3D,EAAgB,aAAA,GAAA,aAAA,CAAc,QAAQ,QAAU,EAAA,CAAA;AAAA,EAAK,WAAW,CAAA;AAAA,CAAI,CAAA,CAAA;AAEpE,EAAO,OAAA,aAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1 @@
export declare function compileOutputs(fragments: any[], template: string): string;

View File

@@ -0,0 +1,52 @@
'use strict';
"use strict";
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;
}
exports.compileOutputs = compileOutputs;
//# sourceMappingURL=compileOutputs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileOutputs.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileOutputs.ts"],"sourcesContent":["function extractOutputs(fragmentSource: string, out: string[])\n{\n let match;\n const regex = /@out\\s+([^;]+);/g;\n\n while ((match = regex.exec(fragmentSource)) !== null)\n {\n out.push(match[1]);\n }\n}\n\nfunction extractVariableName(value: string)\n{\n const regex = /\\b(\\w+)\\s*:/g;\n\n const match = regex.exec(value);\n\n return match ? match[1] : '';\n}\n\nfunction stripVariable(value: string)\n{\n const regex = /@.*?\\s+/g;\n\n return value.replace(regex, '');\n}\n\nexport function compileOutputs(fragments: any[], template: string)\n{\n // get all the inputs from the fragments..\n const results: string[] = [];\n\n extractOutputs(template, results);\n\n fragments.forEach((fragment) =>\n {\n if (fragment.header)\n {\n extractOutputs(fragment.header, results);\n }\n });\n\n let index = 0;\n\n // generate the output struct\n const mainStruct = results\n .sort()\n .map((inValue) =>\n {\n if (inValue.indexOf('builtin') > -1)\n {\n return inValue;\n }\n\n return `@location(${index++}) ${inValue}`;\n })\n .join(',\\n');\n\n // generate the variables we will set:\n const mainStart = results\n .sort()\n .map((inValue) => ` var ${stripVariable(inValue)};`)\n .join('\\n');\n\n // generate the return object\n const mainEnd = `return VSOutput(\n ${results\n .sort()\n .map((inValue) => ` ${extractVariableName(inValue)}`)\n .join(',\\n')});`;\n\n // Remove lines from original string\n let compiledCode = template.replace(/@out\\s+[^;]+;\\s*/g, '');\n\n compiledCode = compiledCode.replace('{{struct}}', `\\n${mainStruct}\\n`);\n compiledCode = compiledCode.replace('{{start}}', `\\n${mainStart}\\n`);\n compiledCode = compiledCode.replace('{{return}}', `\\n${mainEnd}\\n`);\n\n return compiledCode;\n}\n"],"names":[],"mappings":";;;AAAA,SAAS,cAAA,CAAe,gBAAwB,GAChD,EAAA;AACI,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,MAAM,KAAQ,GAAA,kBAAA,CAAA;AAEd,EAAA,OAAA,CAAQ,KAAQ,GAAA,KAAA,CAAM,IAAK,CAAA,cAAc,OAAO,IAChD,EAAA;AACI,IAAI,GAAA,CAAA,IAAA,CAAK,KAAM,CAAA,CAAC,CAAC,CAAA,CAAA;AAAA,GACrB;AACJ,CAAA;AAEA,SAAS,oBAAoB,KAC7B,EAAA;AACI,EAAA,MAAM,KAAQ,GAAA,cAAA,CAAA;AAEd,EAAM,MAAA,KAAA,GAAQ,KAAM,CAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAE9B,EAAO,OAAA,KAAA,GAAQ,KAAM,CAAA,CAAC,CAAI,GAAA,EAAA,CAAA;AAC9B,CAAA;AAEA,SAAS,cAAc,KACvB,EAAA;AACI,EAAA,MAAM,KAAQ,GAAA,UAAA,CAAA;AAEd,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,KAAA,EAAO,EAAE,CAAA,CAAA;AAClC,CAAA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,CAAa,QAAQ,YAAc,EAAA,CAAA;AAAA,EAAK,UAAU,CAAA;AAAA,CAAI,CAAA,CAAA;AACrE,EAAe,YAAA,GAAA,YAAA,CAAa,QAAQ,WAAa,EAAA,CAAA;AAAA,EAAK,SAAS,CAAA;AAAA,CAAI,CAAA,CAAA;AACnE,EAAe,YAAA,GAAA,YAAA,CAAa,QAAQ,YAAc,EAAA,CAAA;AAAA,EAAK,OAAO,CAAA;AAAA,CAAI,CAAA,CAAA;AAElE,EAAO,OAAA,YAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,50 @@
"use strict";
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

View File

@@ -0,0 +1 @@
{"version":3,"file":"compileOutputs.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/compileOutputs.ts"],"sourcesContent":["function extractOutputs(fragmentSource: string, out: string[])\n{\n let match;\n const regex = /@out\\s+([^;]+);/g;\n\n while ((match = regex.exec(fragmentSource)) !== null)\n {\n out.push(match[1]);\n }\n}\n\nfunction extractVariableName(value: string)\n{\n const regex = /\\b(\\w+)\\s*:/g;\n\n const match = regex.exec(value);\n\n return match ? match[1] : '';\n}\n\nfunction stripVariable(value: string)\n{\n const regex = /@.*?\\s+/g;\n\n return value.replace(regex, '');\n}\n\nexport function compileOutputs(fragments: any[], template: string)\n{\n // get all the inputs from the fragments..\n const results: string[] = [];\n\n extractOutputs(template, results);\n\n fragments.forEach((fragment) =>\n {\n if (fragment.header)\n {\n extractOutputs(fragment.header, results);\n }\n });\n\n let index = 0;\n\n // generate the output struct\n const mainStruct = results\n .sort()\n .map((inValue) =>\n {\n if (inValue.indexOf('builtin') > -1)\n {\n return inValue;\n }\n\n return `@location(${index++}) ${inValue}`;\n })\n .join(',\\n');\n\n // generate the variables we will set:\n const mainStart = results\n .sort()\n .map((inValue) => ` var ${stripVariable(inValue)};`)\n .join('\\n');\n\n // generate the return object\n const mainEnd = `return VSOutput(\n ${results\n .sort()\n .map((inValue) => ` ${extractVariableName(inValue)}`)\n .join(',\\n')});`;\n\n // Remove lines from original string\n let compiledCode = template.replace(/@out\\s+[^;]+;\\s*/g, '');\n\n compiledCode = compiledCode.replace('{{struct}}', `\\n${mainStruct}\\n`);\n compiledCode = compiledCode.replace('{{start}}', `\\n${mainStart}\\n`);\n compiledCode = compiledCode.replace('{{return}}', `\\n${mainEnd}\\n`);\n\n return compiledCode;\n}\n"],"names":[],"mappings":";AAAA,SAAS,cAAA,CAAe,gBAAwB,GAChD,EAAA;AACI,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,MAAM,KAAQ,GAAA,kBAAA,CAAA;AAEd,EAAA,OAAA,CAAQ,KAAQ,GAAA,KAAA,CAAM,IAAK,CAAA,cAAc,OAAO,IAChD,EAAA;AACI,IAAI,GAAA,CAAA,IAAA,CAAK,KAAM,CAAA,C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c,WAAA,EAAA,aAAA,CAAc,OAAO,CAAC,CAAG,CAAA,CAAA,CAAA,CACxD,KAAK,IAAI,CAAA,CAAA;AAGd,EAAA,MAAM,OAAU,GAAA,CAAA;AAAA,gBAAA,EACF,OACT,CAAA,IAAA,EACA,CAAA,GAAA,CAAI,CAAC,OAAY,KAAA,CAAA,CAAA,EAAI,mBAAoB,CAAA,OAAO,CAAC,CAAA,CAAE,CACnD,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA,EAAA,CAAA,CAAA;AAGhB,EAAA,IAAI,YAAe,GAAA,QAAA,CAAS,OAAQ,CAAA,mBAAA,EAAqB,EAAE,CAAA,CAAA;AAE3D,EAAe,YAAA,GAAA,YAAA,CAAa,QAAQ,YAAc,EAAA,CAAA;AAAA,EAAK,UAAU,CAAA;AAAA,CAAI,CAAA,CAAA;AACrE,EAAe,YAAA,GAAA,YAAA,CAAa,QAAQ,WAAa,EAAA,CAAA;AAAA,EAAK,SAAS,CAAA;AAAA,CAAI,CAAA,CAAA;AACnE,EAAe,YAAA,GAAA,YAAA,CAAa,QAAQ,YAAc,EAAA,CAAA;AAAA,EAAK,OAAO,CAAA;AAAA,CAAI,CAAA,CAAA;AAElE,EAAO,OAAA,YAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,5 @@
/**
* formats a shader so its more pleasant to read!
* @param shader - a glsl shader program source
*/
export declare function formatShader(shader: string): string;

View File

@@ -0,0 +1,21 @@
'use strict';
"use strict";
function formatShader(shader) {
const spl = shader.split(/([\n{}])/g).map((a) => a.trim()).filter((a) => a.length);
let indent = "";
const formatted = spl.map((a) => {
let indentedLine = indent + a;
if (a === "{") {
indent += " ";
} else if (a === "}") {
indent = indent.substr(0, indent.length - 4);
indentedLine = indent + a;
}
return indentedLine;
}).join("\n");
return formatted;
}
exports.formatShader = formatShader;
//# sourceMappingURL=formatShader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"formatShader.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/formatShader.ts"],"sourcesContent":["/**\n * formats a shader so its more pleasant to read!\n * @param shader - a glsl shader program source\n */\nexport function formatShader(shader: string): string\n{\n const spl = shader.split(/([\\n{}])/g)\n .map((a) => a.trim())\n .filter((a) => a.length);\n\n let indent = '';\n\n const formatted = spl.map((a) =>\n {\n let indentedLine = indent + a;\n\n if (a === '{')\n {\n indent += ' ';\n }\n else if (a === '}')\n {\n indent = indent.substr(0, indent.length - 4);\n\n indentedLine = indent + a;\n }\n\n return indentedLine;\n }).join('\\n');\n\n return formatted;\n}\n\n"],"names":[],"mappings":";;;AAIO,SAAS,aAAa,MAC7B,EAAA;AACI,EAAA,MAAM,MAAM,MAAO,CAAA,KAAA,CAAM,WAAW,CAAA,CAC/B,IAAI,CAAC,CAAA,KAAM,CAAE,CAAA,IAAA,EAAM,CACnB,CAAA,MAAA,CAAO,CAAC,CAAA,KAAM,EAAE,MAAM,CAAA,CAAA;AAE3B,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AAEb,EAAA,MAAM,SAAY,GAAA,GAAA,CAAI,GAAI,CAAA,CAAC,CAC3B,KAAA;AACI,IAAA,IAAI,eAAe,MAAS,GAAA,CAAA,CAAA;AAE5B,IAAA,IAAI,MAAM,GACV,EAAA;AACI,MAAU,MAAA,IAAA,MAAA,CAAA;AAAA,KACd,MAAA,IACS,MAAM,GACf,EAAA;AACI,MAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAO,CAAG,EAAA,MAAA,CAAO,SAAS,CAAC,CAAA,CAAA;AAE3C,MAAA,YAAA,GAAe,MAAS,GAAA,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAO,OAAA,YAAA,CAAA;AAAA,GACV,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAEZ,EAAO,OAAA,SAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,19 @@
"use strict";
function formatShader(shader) {
const spl = shader.split(/([\n{}])/g).map((a) => a.trim()).filter((a) => a.length);
let indent = "";
const formatted = spl.map((a) => {
let indentedLine = indent + a;
if (a === "{") {
indent += " ";
} else if (a === "}") {
indent = indent.substr(0, indent.length - 4);
indentedLine = indent + a;
}
return indentedLine;
}).join("\n");
return formatted;
}
export { formatShader };
//# sourceMappingURL=formatShader.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"formatShader.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/formatShader.ts"],"sourcesContent":["/**\n * formats a shader so its more pleasant to read!\n * @param shader - a glsl shader program source\n */\nexport function formatShader(shader: string): string\n{\n const spl = shader.split(/([\\n{}])/g)\n .map((a) => a.trim())\n .filter((a) => a.length);\n\n let indent = '';\n\n const formatted = spl.map((a) =>\n {\n let indentedLine = indent + a;\n\n if (a === '{')\n {\n indent += ' ';\n }\n else if (a === '}')\n {\n indent = indent.substr(0, indent.length - 4);\n\n indentedLine = indent + a;\n }\n\n return indentedLine;\n }).join('\\n');\n\n return formatted;\n}\n\n"],"names":[],"mappings":";AAIO,SAAS,aAAa,MAC7B,EAAA;AACI,EAAA,MAAM,MAAM,MAAO,CAAA,KAAA,CAAM,WAAW,CAAA,CAC/B,IAAI,CAAC,CAAA,KAAM,CAAE,CAAA,IAAA,EAAM,CACnB,CAAA,MAAA,CAAO,CAAC,CAAA,KAAM,EAAE,MAAM,CAAA,CAAA;AAE3B,EAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AAEb,EAAA,MAAM,SAAY,GAAA,GAAA,CAAI,GAAI,CAAA,CAAC,CAC3B,KAAA;AACI,IAAA,IAAI,eAAe,MAAS,GAAA,CAAA,CAAA;AAE5B,IAAA,IAAI,MAAM,GACV,EAAA;AACI,MAAU,MAAA,IAAA,MAAA,CAAA;AAAA,KACd,MAAA,IACS,MAAM,GACf,EAAA;AACI,MAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAO,CAAG,EAAA,MAAA,CAAO,SAAS,CAAC,CAAA,CAAA;AAE3C,MAAA,YAAA,GAAe,MAAS,GAAA,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAO,OAAA,YAAA,CAAA;AAAA,GACV,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAEZ,EAAO,OAAA,SAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,6 @@
/**
* takes a shader src and replaces any hooks with the HighFragment code.
* @param templateSrc - the program src template
* @param fragmentParts - the fragments to inject
*/
export declare function injectBits(templateSrc: string, fragmentParts: Record<string, string[]>): string;

View File

@@ -0,0 +1,21 @@
'use strict';
"use strict";
function injectBits(templateSrc, fragmentParts) {
let out = templateSrc;
for (const i in fragmentParts) {
const parts = fragmentParts[i];
const toInject = parts.join("\n");
if (toInject.length) {
out = out.replace(`{{${i}}}`, `//-----${i} START-----//
${parts.join("\n")}
//----${i} FINISH----//`);
} else {
out = out.replace(`{{${i}}}`, "");
}
}
return out;
}
exports.injectBits = injectBits;
//# sourceMappingURL=injectBits.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"injectBits.js","sources":["../../../../../src/rendering/high-shader/compiler/utils/injectBits.ts"],"sourcesContent":["/**\n * takes a shader src and replaces any hooks with the HighFragment code.\n * @param templateSrc - the program src template\n * @param fragmentParts - the fragments to inject\n */\nexport function injectBits(templateSrc: string, fragmentParts: Record<string, string[]>): string\n{\n let out = templateSrc;\n\n for (const i in fragmentParts)\n {\n const parts = fragmentParts[i];\n\n const toInject = parts.join('\\n');\n\n if (toInject.length)\n {\n out = out.replace(`{{${i}}}`, `//-----${i} START-----//\\n${parts.join('\\n')}\\n//----${i} FINISH----//`);\n }\n\n else\n {\n out = out.replace(`{{${i}}}`, '');\n }\n }\n\n return out;\n}\n"],"names":[],"mappings":";;;AAKgB,SAAA,UAAA,CAAW,aAAqB,aAChD,EAAA;AACI,EAAA,IAAI,GAAM,GAAA,WAAA,CAAA;AAEV,EAAA,KAAA,MAAW,KAAK,aAChB,EAAA;AACI,IAAM,MAAA,KAAA,GAAQ,cAAc,CAAC,CAAA,CAAA;AAE7B,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAEhC,IAAA,IAAI,SAAS,MACb,EAAA;AACI,MAAA,GAAA,GAAM,IAAI,OAAQ,CAAA,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,CAAA,EAAM,UAAU,CAAC,CAAA;AAAA,EAAkB,KAAA,CAAM,IAAK,CAAA,IAAI,CAAC,CAAA;AAAA,MAAA,EAAW,CAAC,CAAe,aAAA,CAAA,CAAA,CAAA;AAAA,KAI1G,MAAA;AACI,MAAA,GAAA,GAAM,GAAI,CAAA,OAAA,CAAQ,CAAK,EAAA,EAAA,CAAC,MAAM,EAAE,CAAA,CAAA;AAAA,KACpC;AAAA,GACJ;AAEA,EAAO,OAAA,GAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,19 @@
"use strict";
function injectBits(templateSrc, fragmentParts) {
let out = templateSrc;
for (const i in fragmentParts) {
const parts = fragmentParts[i];
const toInject = parts.join("\n");
if (toInject.length) {
out = out.replace(`{{${i}}}`, `//-----${i} START-----//
${parts.join("\n")}
//----${i} FINISH----//`);
} else {
out = out.replace(`{{${i}}}`, "");
}
}
return out;
}
export { injectBits };
//# sourceMappingURL=injectBits.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"injectBits.mjs","sources":["../../../../../src/rendering/high-shader/compiler/utils/injectBits.ts"],"sourcesContent":["/**\n * takes a shader src and replaces any hooks with the HighFragment code.\n * @param templateSrc - the program src template\n * @param fragmentParts - the fragments to inject\n */\nexport function injectBits(templateSrc: string, fragmentParts: Record<string, string[]>): string\n{\n let out = templateSrc;\n\n for (const i in fragmentParts)\n {\n const parts = fragmentParts[i];\n\n const toInject = parts.join('\\n');\n\n if (toInject.length)\n {\n out = out.replace(`{{${i}}}`, `//-----${i} START-----//\\n${parts.join('\\n')}\\n//----${i} FINISH----//`);\n }\n\n else\n {\n out = out.replace(`{{${i}}}`, '');\n }\n }\n\n return out;\n}\n"],"names":[],"mappings":";AAKgB,SAAA,UAAA,CAAW,aAAqB,aAChD,EAAA;AACI,EAAA,IAAI,GAAM,GAAA,WAAA,CAAA;AAEV,EAAA,KAAA,MAAW,KAAK,aAChB,EAAA;AACI,IAAM,MAAA,KAAA,GAAQ,cAAc,CAAC,CAAA,CAAA;AAE7B,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAEhC,IAAA,IAAI,SAAS,MACb,EAAA;AACI,MAAA,GAAA,GAAM,IAAI,OAAQ,CAAA,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,CAAA,EAAM,UAAU,CAAC,CAAA;AAAA,EAAkB,KAAA,CAAM,IAAK,CAAA,IAAI,CAAC,CAAA;AAAA,MAAA,EAAW,CAAC,CAAe,aAAA,CAAA,CAAA,CAAA;AAAA,KAI1G,MAAA;AACI,MAAA,GAAA,GAAM,GAAI,CAAA,OAAA,CAAQ,CAAK,EAAA,EAAA,CAAC,MAAM,EAAE,CAAA,CAAA;AAAA,KACpC;AAAA,GACJ;AAEA,EAAO,OAAA,GAAA,CAAA;AACX;;;;"}