@three-blocks/devtools 1.0.0-alpha.208.g664cb7c258f9 → 1.0.1-alpha.214.gf051bb7d43f2
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/CHANGELOG.md +81 -66
- package/dist/{browser-smoke-FPR2OZ37.js → browser-smoke-GPOH7Z4F.js} +1 -1
- package/dist/{chunk-RQEPJ6GC.js → chunk-2JE5VZXK.js} +1 -1
- package/dist/{chunk-KLGY4Q2M.js → chunk-D6DGT5CE.js} +1 -1
- package/dist/{chunk-5RSAQ74G.js → chunk-LVY4EXVQ.js} +3 -3
- package/dist/{chunk-P56VQRTH.js → chunk-QGCA3ERA.js} +1 -1
- package/dist/{chunk-HLYATKSG.js → chunk-TGOUAHMD.js} +1 -1
- package/dist/{chunk-E6JYGHBW.js → chunk-WKUP6PVY.js} +1 -1
- package/dist/cli.js +8 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/{shader-browser-ZCKOOMQ3.js → shader-browser-5EYFT5IQ.js} +1 -1
- package/dist/{shader-browser-SZJLKYYT.js → shader-browser-IGGE5DDE.js} +1 -1
- package/dist/shader-capture-server.d.ts +1 -1
- package/dist/shader-capture-server.js +1 -1
- package/dist/{shader-watch-VWJGRJ23.js → shader-watch-TLLBKLCE.js} +1 -1
- package/dist/{shader-workflow-I2RA75GO.js → shader-workflow-TVW3WMIP.js} +1 -1
- package/dist/{status-GATTL2MS.js → status-J53T3G3P.js} +1 -1
- package/dist/transform.js +1 -1
- package/dist/webpack-loader.js +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {realpath,readFile,mkdir,readdir,unlink,lstat,open,rename,rm}from'fs/promises';import w from'path';import {parsePrecompiledManifest,SHADER_HYDRATION_SCHEMA_VERSION,SHADER_RECIPE_SCHEMA_VERSION,SHADER_ADDRESS_SCHEMA_VERSION,PRECOMPILED_MANIFEST_VERSION,THREE_WEBGPU_R185_COMPATIBILITY,THREE_R186DEV_VERSION,THREE_WEBGPU_R186DEV_COMPATIBILITY}from'three-blocks/shaders';import {createHash,randomUUID}from'crypto';import {createRequire}from'module';var mt=Object.defineProperty;var a=(e,t)=>mt(e,"name",{value:t,configurable:true});var x=Object.freeze({metadata:1024*1024,receipt:2*1024*1024,manifest:32*1024*1024,semanticInput:8*1024*1024,semanticTotal:64*1024*1024,metrics:8*1024*1024,texture:128*1024*1024,packageJson:1024*1024});function Ie(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"?e.code:void 0}a(Ie,"errorCode");function $(e){return createHash("sha256").update(e).digest("hex")}a($,"sha256");async function A(e){try{return await lstat(e),!0}catch(t){if(Ie(t)==="ENOENT")return false;throw t}}a(A,"pathExists");function N(e,t){let r=w.relative(e,t);return r===""||!w.isAbsolute(r)&&r!==".."&&!r.startsWith(`..${w.sep}`)}a(N,"isWithin");function V(e){return JSON.stringify(e)}a(V,"displayPath");async function _e(e,t,r){let n=await open(e,"r");try{let[i,s,o]=await Promise.all([lstat(e),n.stat(),realpath(e)]);if(i.isSymbolicLink())throw new Error(`${r} must not be a symbolic link: ${V(e)}.`);if(!s.isFile())throw new Error(`${r} must be a regular file: ${V(e)}.`);if(s.size>t)throw new Error(`${r} exceeds the ${t}-byte inspection limit: ${V(e)}.`);let c=await n.readFile();if(c.byteLength>t)throw new Error(`${r} grew beyond the ${t}-byte inspection limit while being read.`);return {path:o,data:c}}finally{await n.close();}}a(_e,"readBoundedRegularFile");async function ee(e,t){let r=w.dirname(e);await mkdir(r,{recursive:true});try{if((await lstat(e)).isSymbolicLink())throw new Error(`Atomic write target must not be a symbolic link: ${V(e)}.`)}catch(s){if(Ie(s)!=="ENOENT")throw s}let n=w.join(r,`.${w.basename(e)}.${process.pid}.${randomUUID()}.tmp`),i;try{i=await open(n,"wx",384),await i.writeFile(t),await i.sync(),await i.close(),i=void 0,await rename(n,e);}finally{await i?.close().catch(()=>{}),await rm(n,{force:true});}}a(ee,"writeAtomicRegularFile");async function le(e,t,r){return _e(e,t,r)}a(le,"readExternalRegularFile");async function H(e,t,r){let n=w.resolve(e),i=w.resolve(t);if(!N(n,i))throw new Error(`${r} escapes its allowed directory.`);let s=await lstat(i);if(s.isSymbolicLink())throw new Error(`${r} must not be a symbolic link.`);if(!s.isDirectory())throw new Error(`${r} must be a directory.`);let[o,c]=await Promise.all([realpath(n),realpath(i)]);if(!N(o,c))throw new Error(`${r} resolves outside its allowed directory.`);return c}a(H,"canonicalDirectoryWithin");async function C(e,t,r,n){let i=w.resolve(e),s=w.resolve(t);if(!N(i,s)||i===s)throw new Error(`${n} escapes its allowed directory.`);let o=await _e(s,r,n),c=await realpath(i);if(!N(c,o.path)||c===o.path)throw new Error(`${n} resolves outside its allowed directory.`);return o}a(C,"readRegularFileWithin");async function Pe(e,t,r,n=8192){let s=[await H(e,t,"Inspected directory")],o=[],c=0;for(;s.length>0;){let l=s.shift();if(l===void 0)break;let m=(await readdir(l,{withFileTypes:true})).sort((g,u)=>g.name.localeCompare(u.name));for(let g of m){if(c+=1,c>n)throw new Error(`Inspected directory exceeds the ${n}-entry limit.`);let u=w.join(l,g.name);if(g.isSymbolicLink())throw new Error(`Inspected directory contains a symbolic link: ${V(w.relative(e,u))}.`);if(g.isDirectory()){s.push(await H(e,u,"Nested inspected directory"));continue}if(g.isFile()&&r(g.name))o.push(u);else if(r(g.name))throw new Error(`Semantic input is not a regular file: ${V(u)}.`)}}return o.sort()}a(Pe,"listRegularFilesRecursively");var te=/^[a-f0-9]{64}$/,Et=/^[0-9A-Za-z][0-9A-Za-z.+_-]{0,127}$/,Oe=/^[a-z0-9][a-z0-9_-]{0,63}$/,Be=/^[0-9A-Za-z][0-9A-Za-z._/-]{0,127}$/;function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(f,"isRecord");function z(e){return typeof e=="string"&&Et.test(e)}a(z,"isSafeVersion");function fe(e){if(e.length===0||e.length>512||e.includes("\\")||/[\u0000-\u001f\u007f]/.test(e))return false;let t=e.split("/");return !e.startsWith("/")&&t.every(r=>r.length>0&&r!=="."&&r!=="..")}a(fe,"isSafeRelativePath");function Ne(e){if(!f(e)||e.schemaVersion!==2)throw new Error("three-blocks.json must use schemaVersion 2.");if(typeof e.template!="string"||!Oe.test(e.template))throw new Error("three-blocks.json has an invalid default shader scene key.");if(!Array.isArray(e.layers)||!e.layers.every(t=>typeof t=="string"&&Be.test(t))||new Set(e.layers).size!==e.layers.length)throw new Error("three-blocks.json has invalid layers.");if(e.generator!==void 0&&(!f(e.generator)||typeof e.generator.name!="string"||!Be.test(e.generator.name)||!z(e.generator.version)))throw new Error("three-blocks.json has invalid generator metadata.");if(!f(e.runtime)||!z(e.runtime.three)||!z(e.runtime.threeBlocks))throw new Error("three-blocks.json has invalid runtime versions.");if(!f(e.features)||typeof e.features.text!="boolean")throw new Error("three-blocks.json has invalid feature metadata.");if(!f(e.protocol)||e.protocol.resultFile!==1)throw new Error("three-blocks.json has an unsupported protocol schema.");if(e.artifacts!==void 0){if(!f(e.artifacts)||typeof e.artifacts.shaders!="string"||!["fresh","pending"].includes(e.artifacts.shaders)||typeof e.artifacts.text!="string"||!["fresh","pending","not-applicable"].includes(e.artifacts.text))throw new Error("three-blocks.json has invalid artifact metadata.");if(e.features.text?e.artifacts.text==="not-applicable":e.artifacts.text!=="not-applicable")throw new Error("three-blocks.json text artifact state does not match the text capability.")}return {schemaVersion:2,template:e.template,layers:e.layers,...e.generator===void 0?{}:{generator:{name:e.generator.name,version:e.generator.version}},runtime:{three:e.runtime.three,threeBlocks:e.runtime.threeBlocks},features:{text:e.features.text},...e.artifacts===void 0?{}:{artifacts:{shaders:e.artifacts.shaders,text:e.artifacts.text}},protocol:{resultFile:1}}}a(Ne,"parseProjectMetadata");function Rt(e){if(!f(e))throw new Error("Shader coverage is missing.");for(let t of ["render","vertex","fragment","compute"])if(typeof e[t]!="number"||!Number.isSafeInteger(e[t])||e[t]<0)throw new Error(`Shader coverage.${t} must be a non-negative integer.`);return e}a(Rt,"parseCoverage");function kt(e,t){if(!f(e))throw new Error(`Shader receipt inputs for "${t}" are invalid.`);let r=Object.entries(e);if(r.length===0||r.length>4096)throw new Error(`Shader receipt inputs for "${t}" must contain between 1 and 4096 files.`);for(let[n,i]of r)if(!fe(n)||typeof i!="string"||!te.test(i))throw new Error(`Shader receipt input for "${t}" is invalid.`)}a(kt,"parseInputs");function re(e){if(!f(e)||e.schemaVersion!==2||!f(e.runtime)||!z(e.runtime.three)||!z(e.runtime.threeBlocks)||typeof e.runtime.threeBlocksShaderClosure!="string"||!te.test(e.runtime.threeBlocksShaderClosure)||!f(e.scenes))throw new Error("Shader meta.json does not match receipt schema 2.");if(e.runtime.capture!==void 0&&(!f(e.runtime.capture)||typeof e.runtime.capture.userAgent!="string"||e.runtime.capture.userAgent.length>1024||typeof e.runtime.capture.adapter!="string"||e.runtime.capture.adapter.length>1024||!Array.isArray(e.runtime.capture.features)||e.runtime.capture.features.length>256||!e.runtime.capture.features.every(r=>typeof r=="string"&&r.length>0&&r.length<=128)))throw new Error("Shader meta.json has invalid browser capture provenance.");let t=Object.entries(e.scenes);if(t.length===0)throw new Error("Shader meta.json contains no scenes.");for(let[r,n]of t){if(!Oe.test(r)||!f(n)||typeof n.artifact!="string"||!fe(n.artifact)||!n.artifact.endsWith(".webgpu.ts")||typeof n.artifactHash!="string"||!te.test(n.artifactHash))throw new Error(`Shader receipt for "${r}" is invalid.`);if(n.asset===void 0!=(n.assetHash===void 0)||n.asset!==void 0&&(typeof n.asset!="string"||!fe(n.asset)||!n.asset.endsWith(".json")||typeof n.assetHash!="string"||!te.test(n.assetHash)))throw new Error(`Shader static asset receipt for "${r}" is invalid.`);if(kt(n.inputs,r),Rt(n.coverage),n.bytes!==void 0&&(!Number.isSafeInteger(n.bytes)||Number(n.bytes)<0))throw new Error(`Shader receipt byte count for "${r}" is invalid.`);if(n.skipped!==void 0&&(!f(n.skipped)||!Number.isSafeInteger(n.skipped.render)||Number(n.skipped.render)<0||!Number.isSafeInteger(n.skipped.compute)||Number(n.skipped.compute)<0))throw new Error(`Shader receipt skipped-build counts for "${r}" are invalid.`)}if(e.tool!==void 0&&(!f(e.tool)||e.tool.name!=="@three-blocks/devtools"||!z(e.tool.version)||typeof e.tool.compatibility!="string"||!Number.isSafeInteger(e.tool.transform)||!Number.isSafeInteger(e.tool.address)||!Number.isSafeInteger(e.tool.recipe)||!Number.isSafeInteger(e.tool.hydration)))throw new Error("Shader meta.json has invalid tool compatibility metadata.");return e}a(re,"parseShaderReceipt");var ve="three-blocks.shaders.json",he=".three-blocks/shaders";var Tt=/^[a-z0-9][a-z0-9_-]{0,63}$/u,jt=/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/u,De=64,Le=64,At={schemaVersion:1,scenes:[{key:"default",url:"/"}]};function Fe(e,t,r){if(e===void 0)return r;if(typeof e!="string"||e.length===0||e.length>512||w.isAbsolute(e)||/[\u0000-\u001f\u007f]/u.test(e))throw new Error(`${t} must be a bounded project-relative directory.`);let n=w.posix.normalize(e.replaceAll("\\","/")).replace(/\/+$/u,"");if(n==="."||n===".."||n.startsWith("../"))throw new Error(`${t} must stay inside the project.`);return n}a(Fe,"safeProjectDirectory");function $t(e,t){let r=Fe(e,t,"");if(typeof e!="string"||e.endsWith("/"))throw new Error(`${t} must be a project-relative file.`);return r}a($t,"safeProjectFile");function D(e,t,r,n,i){if(e===void 0)return i;if(!Number.isSafeInteger(e)||Number(e)<r||Number(e)>n)throw new Error(`${t} must be an integer in ${r}...${n}.`);return Number(e)}a(D,"boundedInteger");function Ve(e,t,r){if(e===void 0)return r;if(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)throw new Error(`${t} must be a finite ratio in 0...1.`);return e}a(Ve,"finiteRatio");function He(e,t){if(typeof e!="string"||e.length===0||e.length>2048||/[\u0000-\u001f\u007f]/u.test(e))throw new Error(`${t} must be a bounded project-relative URL.`);let r;try{r=new URL(e,"http://three-blocks.invalid/");}catch{throw new Error(`${t} is not a valid URL.`)}if(r.origin!=="http://three-blocks.invalid"||r.hash.length>0)throw new Error(`${t} must stay within the project and must not contain a fragment.`);return `${r.pathname}${r.search}`}a(He,"safeBrowserUrl");function Ct(e){if(!Array.isArray(e)||e.length===0||e.length>De)throw new Error(`Shader config scenes must contain 1...${De} entries.`);let t=new Set;return e.map((r,n)=>{if(!f(r)||typeof r.key!="string"||!Tt.test(r.key))throw new Error(`Shader config scene ${n} has an invalid key.`);if(t.has(r.key))throw new Error(`Shader config scene key "${r.key}" is duplicated.`);t.add(r.key);let i=r.parityFrames,s=r.maxDiffRatio;if(r.inputs!==void 0&&(!Array.isArray(r.inputs)||r.inputs.length===0||r.inputs.length>Le))throw new Error(`Shader config scene "${r.key}" inputs must contain 1...${Le} files.`);let o=r.inputs===void 0?void 0:r.inputs.map((c,l)=>$t(c,`Shader config scene "${r.key}" input ${l}`));if(o!==void 0&&new Set(o).size!==o.length)throw new Error(`Shader config scene "${r.key}" inputs must be unique.`);if(r.runtimeMotion!==void 0&&typeof r.runtimeMotion!="boolean")throw new Error(`Shader config scene "${r.key}" runtimeMotion must be a boolean.`);return {key:r.key,url:He(r.url,`Shader config scene "${r.key}" URL`),requiresText:r.requiresText===true,...o===void 0?{}:{inputs:o},...i===void 0?{}:{parityFrames:D(i,`Shader config scene "${r.key}" parityFrames`,0,1e4,0)},...s===void 0?{}:{maxDiffRatio:Ve(s,`Shader config scene "${r.key}" maxDiffRatio`,.01)},...r.runtimeMotion===true?{runtimeMotion:true}:{}}})}a(Ct,"parseScenes");function pe(e){if(!f(e)||e.schemaVersion!==void 0&&e.schemaVersion!==1)throw new Error("Shader config must use schemaVersion 1.");let t=e.viewport;if(t!==void 0&&!f(t))throw new Error("Shader config viewport must be an object.");let r=e.parity;if(r!==void 0&&!f(r))throw new Error("Shader config parity must be an object.");let n=e.bridge;if(n!==void 0&&!f(n))throw new Error("Shader config bridge must be an object.");let i=f(n)?n.deterministicModule:void 0;i!==void 0&&He(i,"Shader deterministic module");let s=e.readiness;if(s!==void 0&&!f(s))throw new Error("Shader config readiness must be an object.");let o=f(s)?s.selector:void 0;if(o!==void 0&&(typeof o!="string"||o.length===0||o.length>512||/[\u0000-\u001f\u007f]/u.test(o)))throw new Error("Shader readiness selector must be a bounded, non-empty CSS selector.");let c=f(s)?s.global:void 0;if(c!==void 0&&(typeof c!="string"||!jt.test(c)))throw new Error("Shader readiness global must be a dot-separated JavaScript property path.");return {schemaVersion:1,scenes:Ct(e.scenes),settleFrames:D(e.settleFrames,"Shader settleFrames",0,1e4,60),settleTimeoutMs:D(e.settleTimeoutMs,"Shader settleTimeoutMs",1e3,15*6e4,3e4),browserRelaunchScenes:D(e.browserRelaunchScenes,"Shader browserRelaunchScenes",1,64,8),timeoutMs:D(e.timeoutMs,"Shader timeoutMs",1e3,15*6e4,24e4),viewport:{width:D(f(t)?t.width:void 0,"Shader viewport width",64,8192,1024),height:D(f(t)?t.height:void 0,"Shader viewport height",64,8192,640)},parity:{frames:D(f(r)?r.frames:void 0,"Shader parity frames",0,1e4,90),channelTolerance:D(f(r)?r.channelTolerance:void 0,"Shader parity channelTolerance",0,255,8),maxDiffRatio:Ve(f(r)?r.maxDiffRatio:void 0,"Shader parity maxDiffRatio",.01)},bridge:{legacyLab:f(n)&&n.legacyLab===true,...typeof i=="string"?{deterministicModule:i}:{}},readiness:{...typeof o=="string"?{selector:o}:{},...typeof c=="string"?{global:c}:{}},publicDir:Fe(e.publicDir,"Shader publicDir","public"),allowLiveBuilds:e.allowLiveBuilds!==false}}a(pe,"parseShaderToolConfig");async function ze(e=process.cwd()){let t=w.resolve(e);for(;;){if(await A(w.join(t,ve))||await A(w.join(t,"three-blocks.json")))return realpath(t);let r=w.join(t,"package.json");if(await A(r)){let i=await C(t,r,x.packageJson,"Project package.json"),s;try{s=JSON.parse(i.data.toString("utf8"));}catch{throw new Error(`Project package.json is not valid JSON: ${r}.`)}if(f(s)&&[s.dependencies,s.devDependencies,s.peerDependencies,s.optionalDependencies].filter(f).some(l=>typeof l.three=="string"||typeof l["three-blocks"]=="string"||typeof l["@three-blocks/devtools"]=="string"))return realpath(t)}let n=w.dirname(t);if(n===t)throw new Error(`No Three Blocks shader project found from ${JSON.stringify(w.resolve(e))}; add Three.js to package.json or pass --root.`);t=n;}}a(ze,"findShaderProjectRoot");async function ge(e){let t=await realpath(e),r=w.join(t,ve);if(await A(r)){let i=await C(t,r,x.metadata,"Shader configuration");return pe(JSON.parse(i.data.toString("utf8")))}let n=w.join(t,"three-blocks.json");if(await A(n)){let i=Ne(JSON.parse(await readFile(n,"utf8")));return pe({schemaVersion:1,scenes:[{key:i.template,url:"/",requiresText:i.features.text}]})}return pe(At)}a(ge,"loadShaderToolConfig");function J(e){if(/^0\.185\./u.test(e))return THREE_WEBGPU_R185_COMPATIBILITY;if(e===THREE_R186DEV_VERSION)return THREE_WEBGPU_R186DEV_COMPATIBILITY;throw new Error(`Three.js ${e} is outside the supported shader compatibility contracts.`)}a(J,"shaderCompatibilityForThree");var q="0.1.0";var se=52,Ot="timing.local.json",Nt="timing.json";var ie=4096,Dt=4096;function ye(e,t,r=8192){if(typeof e!="string"||e.length===0||e.length>r||/[\u0000\u007f]/u.test(e))throw new Error(`${t} must be a bounded non-empty string.`);return e}a(ye,"boundedString");function y(e,t,r=true){if(typeof e!="number"||!Number.isFinite(e)||e<0||r&&!Number.isSafeInteger(e))throw new Error(`${t} must be a non-negative ${r?"integer":"finite number"}.`);return e}a(y,"nonNegativeNumber");function Lt(e){if(!f(e))throw new Error("Shader capture stats are missing.");let t={buildCalls:y(e.buildCalls,"capture stats.buildCalls"),renderBuilds:y(e.renderBuilds,"capture stats.renderBuilds"),computeBuilds:y(e.computeBuilds,"capture stats.computeBuilds"),registeredBuilds:y(e.registeredBuilds,"capture stats.registeredBuilds"),registeredRenderBuilds:y(e.registeredRenderBuilds,"capture stats.registeredRenderBuilds"),registeredComputeBuilds:y(e.registeredComputeBuilds,"capture stats.registeredComputeBuilds"),buildMs:y(e.buildMs,"capture stats.buildMs",false),syncBuildMs:y(e.syncBuildMs,"capture stats.syncBuildMs",false),asyncBuildElapsedMs:y(e.asyncBuildElapsedMs,"capture stats.asyncBuildElapsedMs",false),precompiledSetupMs:y(e.precompiledSetupMs,"capture stats.precompiledSetupMs",false),maxSyncBuildMs:y(e.maxSyncBuildMs??e.syncBuildMs,"capture stats.maxSyncBuildMs",false),maxPrecompiledSetupMs:y(e.maxPrecompiledSetupMs??e.precompiledSetupMs,"capture stats.maxPrecompiledSetupMs",false),hydrationMs:y(e.hydrationMs??0,"capture stats.hydrationMs",false),maxHydrationMs:y(e.maxHydrationMs??e.hydrationMs??0,"capture stats.maxHydrationMs",false),injected:y(e.injected,"capture stats.injected"),injectedRender:y(e.injectedRender,"capture stats.injectedRender"),injectedCompute:y(e.injectedCompute,"capture stats.injectedCompute"),missed:y(e.missed,"capture stats.missed"),missedRender:y(e.missedRender,"capture stats.missedRender"),missedCompute:y(e.missedCompute,"capture stats.missedCompute"),...Array.isArray(e.missedKeys)&&e.missedKeys.every(r=>typeof r=="string")?{missedKeys:e.missedKeys.slice(0,ie)}:{}};if(t.renderBuilds+t.computeBuilds!==t.buildCalls||t.registeredRenderBuilds+t.registeredComputeBuilds!==t.registeredBuilds||t.injectedRender+t.injectedCompute!==t.injected||t.missedRender+t.missedCompute!==t.missed||t.registeredBuilds>t.buildCalls||Math.abs(t.syncBuildMs+t.asyncBuildElapsedMs-t.buildMs)>.001||t.maxSyncBuildMs>t.syncBuildMs+.001||t.maxPrecompiledSetupMs>t.precompiledSetupMs+.001||t.maxHydrationMs>t.hydrationMs+.001)throw new Error("Shader capture stats totals are inconsistent.");return t}a(Lt,"captureStats");function vt(e){if(!Array.isArray(e)||e.length>ie)throw new Error("Shader capture skipped builds are invalid.");return e.map((t,r)=>{if(!f(t)||t.kind!=="render"&&t.kind!=="compute")throw new Error(`Shader capture skipped build ${r} is invalid.`);return {kind:t.kind,name:ye(t.name,`skipped build ${r} name`,512),reason:ye(t.reason,`skipped build ${r} reason`)}})}a(vt,"skippedBuilds");function Ft(e){let t=0,r=0,n=0,i=0;for(let s of Object.values(e.entries)){let o=e.states[s];o!==void 0&&((o.vertex!==null||o.fragment!==null)&&t++,o.vertex!==null&&r++,o.fragment!==null&&n++,o.compute!==null&&i++);}return {render:t,vertex:r,fragment:n,compute:i}}a(Ft,"shaderCoverage");function Vt(e,t){if(!f(e))throw new Error("Shader capture payload must be an object.");if(e.scene!==t.scene)throw new Error(`Shader capture scene does not match "${t.scene}".`);if(e.protocolVersion!==2)throw new Error("Shader capture protocolVersion must be 2.");let r=J(t.runtime.three);if(e.compatibility!==r)throw new Error(`Shader capture compatibility must be "${r}".`);if(!f(e.entries))throw new Error("Shader capture entries must be an object.");if(typeof e.requiresSetup!="boolean")throw new Error("Shader capture requiresSetup must be boolean.");let n=Object.keys(e.entries).length;if(n===0||n>ie)throw new Error(`Shader capture must contain 1...${ie} entries.`);if(!Array.isArray(e.errors)||e.errors.length>Dt)throw new Error("Shader capture errors are invalid.");let i=e.errors.map((p,d)=>ye(p,`capture error ${d}`,64*1024));if(i.length>0)throw new Error(`Shader capture failed:
|
|
1
|
+
import {realpath,readFile,mkdir,readdir,unlink,lstat,open,rename,rm}from'fs/promises';import w from'path';import {parsePrecompiledManifest,SHADER_HYDRATION_SCHEMA_VERSION,SHADER_RECIPE_SCHEMA_VERSION,SHADER_ADDRESS_SCHEMA_VERSION,PRECOMPILED_MANIFEST_VERSION,THREE_WEBGPU_R185_COMPATIBILITY,THREE_R186DEV_VERSION,THREE_WEBGPU_R186DEV_COMPATIBILITY}from'three-blocks/shaders';import {createHash,randomUUID}from'crypto';import {createRequire}from'module';var mt=Object.defineProperty;var a=(e,t)=>mt(e,"name",{value:t,configurable:true});var x=Object.freeze({metadata:1024*1024,receipt:2*1024*1024,manifest:32*1024*1024,semanticInput:8*1024*1024,semanticTotal:64*1024*1024,metrics:8*1024*1024,texture:128*1024*1024,packageJson:1024*1024});function Ie(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"?e.code:void 0}a(Ie,"errorCode");function $(e){return createHash("sha256").update(e).digest("hex")}a($,"sha256");async function A(e){try{return await lstat(e),!0}catch(t){if(Ie(t)==="ENOENT")return false;throw t}}a(A,"pathExists");function N(e,t){let r=w.relative(e,t);return r===""||!w.isAbsolute(r)&&r!==".."&&!r.startsWith(`..${w.sep}`)}a(N,"isWithin");function V(e){return JSON.stringify(e)}a(V,"displayPath");async function _e(e,t,r){let n=await open(e,"r");try{let[i,s,o]=await Promise.all([lstat(e),n.stat(),realpath(e)]);if(i.isSymbolicLink())throw new Error(`${r} must not be a symbolic link: ${V(e)}.`);if(!s.isFile())throw new Error(`${r} must be a regular file: ${V(e)}.`);if(s.size>t)throw new Error(`${r} exceeds the ${t}-byte inspection limit: ${V(e)}.`);let c=await n.readFile();if(c.byteLength>t)throw new Error(`${r} grew beyond the ${t}-byte inspection limit while being read.`);return {path:o,data:c}}finally{await n.close();}}a(_e,"readBoundedRegularFile");async function ee(e,t){let r=w.dirname(e);await mkdir(r,{recursive:true});try{if((await lstat(e)).isSymbolicLink())throw new Error(`Atomic write target must not be a symbolic link: ${V(e)}.`)}catch(s){if(Ie(s)!=="ENOENT")throw s}let n=w.join(r,`.${w.basename(e)}.${process.pid}.${randomUUID()}.tmp`),i;try{i=await open(n,"wx",384),await i.writeFile(t),await i.sync(),await i.close(),i=void 0,await rename(n,e);}finally{await i?.close().catch(()=>{}),await rm(n,{force:true});}}a(ee,"writeAtomicRegularFile");async function le(e,t,r){return _e(e,t,r)}a(le,"readExternalRegularFile");async function H(e,t,r){let n=w.resolve(e),i=w.resolve(t);if(!N(n,i))throw new Error(`${r} escapes its allowed directory.`);let s=await lstat(i);if(s.isSymbolicLink())throw new Error(`${r} must not be a symbolic link.`);if(!s.isDirectory())throw new Error(`${r} must be a directory.`);let[o,c]=await Promise.all([realpath(n),realpath(i)]);if(!N(o,c))throw new Error(`${r} resolves outside its allowed directory.`);return c}a(H,"canonicalDirectoryWithin");async function C(e,t,r,n){let i=w.resolve(e),s=w.resolve(t);if(!N(i,s)||i===s)throw new Error(`${n} escapes its allowed directory.`);let o=await _e(s,r,n),c=await realpath(i);if(!N(c,o.path)||c===o.path)throw new Error(`${n} resolves outside its allowed directory.`);return o}a(C,"readRegularFileWithin");async function Pe(e,t,r,n=8192){let s=[await H(e,t,"Inspected directory")],o=[],c=0;for(;s.length>0;){let l=s.shift();if(l===void 0)break;let m=(await readdir(l,{withFileTypes:true})).sort((g,u)=>g.name.localeCompare(u.name));for(let g of m){if(c+=1,c>n)throw new Error(`Inspected directory exceeds the ${n}-entry limit.`);let u=w.join(l,g.name);if(g.isSymbolicLink())throw new Error(`Inspected directory contains a symbolic link: ${V(w.relative(e,u))}.`);if(g.isDirectory()){s.push(await H(e,u,"Nested inspected directory"));continue}if(g.isFile()&&r(g.name))o.push(u);else if(r(g.name))throw new Error(`Semantic input is not a regular file: ${V(u)}.`)}}return o.sort()}a(Pe,"listRegularFilesRecursively");var te=/^[a-f0-9]{64}$/,Et=/^[0-9A-Za-z][0-9A-Za-z.+_-]{0,127}$/,Oe=/^[a-z0-9][a-z0-9_-]{0,63}$/,Be=/^[0-9A-Za-z][0-9A-Za-z._/-]{0,127}$/;function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(f,"isRecord");function z(e){return typeof e=="string"&&Et.test(e)}a(z,"isSafeVersion");function fe(e){if(e.length===0||e.length>512||e.includes("\\")||/[\u0000-\u001f\u007f]/.test(e))return false;let t=e.split("/");return !e.startsWith("/")&&t.every(r=>r.length>0&&r!=="."&&r!=="..")}a(fe,"isSafeRelativePath");function Ne(e){if(!f(e)||e.schemaVersion!==2)throw new Error("three-blocks.json must use schemaVersion 2.");if(typeof e.template!="string"||!Oe.test(e.template))throw new Error("three-blocks.json has an invalid default shader scene key.");if(!Array.isArray(e.layers)||!e.layers.every(t=>typeof t=="string"&&Be.test(t))||new Set(e.layers).size!==e.layers.length)throw new Error("three-blocks.json has invalid layers.");if(e.generator!==void 0&&(!f(e.generator)||typeof e.generator.name!="string"||!Be.test(e.generator.name)||!z(e.generator.version)))throw new Error("three-blocks.json has invalid generator metadata.");if(!f(e.runtime)||!z(e.runtime.three)||!z(e.runtime.threeBlocks))throw new Error("three-blocks.json has invalid runtime versions.");if(!f(e.features)||typeof e.features.text!="boolean")throw new Error("three-blocks.json has invalid feature metadata.");if(!f(e.protocol)||e.protocol.resultFile!==1)throw new Error("three-blocks.json has an unsupported protocol schema.");if(e.artifacts!==void 0){if(!f(e.artifacts)||typeof e.artifacts.shaders!="string"||!["fresh","pending"].includes(e.artifacts.shaders)||typeof e.artifacts.text!="string"||!["fresh","pending","not-applicable"].includes(e.artifacts.text))throw new Error("three-blocks.json has invalid artifact metadata.");if(e.features.text?e.artifacts.text==="not-applicable":e.artifacts.text!=="not-applicable")throw new Error("three-blocks.json text artifact state does not match the text capability.")}return {schemaVersion:2,template:e.template,layers:e.layers,...e.generator===void 0?{}:{generator:{name:e.generator.name,version:e.generator.version}},runtime:{three:e.runtime.three,threeBlocks:e.runtime.threeBlocks},features:{text:e.features.text},...e.artifacts===void 0?{}:{artifacts:{shaders:e.artifacts.shaders,text:e.artifacts.text}},protocol:{resultFile:1}}}a(Ne,"parseProjectMetadata");function Rt(e){if(!f(e))throw new Error("Shader coverage is missing.");for(let t of ["render","vertex","fragment","compute"])if(typeof e[t]!="number"||!Number.isSafeInteger(e[t])||e[t]<0)throw new Error(`Shader coverage.${t} must be a non-negative integer.`);return e}a(Rt,"parseCoverage");function kt(e,t){if(!f(e))throw new Error(`Shader receipt inputs for "${t}" are invalid.`);let r=Object.entries(e);if(r.length===0||r.length>4096)throw new Error(`Shader receipt inputs for "${t}" must contain between 1 and 4096 files.`);for(let[n,i]of r)if(!fe(n)||typeof i!="string"||!te.test(i))throw new Error(`Shader receipt input for "${t}" is invalid.`)}a(kt,"parseInputs");function re(e){if(!f(e)||e.schemaVersion!==2||!f(e.runtime)||!z(e.runtime.three)||!z(e.runtime.threeBlocks)||typeof e.runtime.threeBlocksShaderClosure!="string"||!te.test(e.runtime.threeBlocksShaderClosure)||!f(e.scenes))throw new Error("Shader meta.json does not match receipt schema 2.");if(e.runtime.capture!==void 0&&(!f(e.runtime.capture)||typeof e.runtime.capture.userAgent!="string"||e.runtime.capture.userAgent.length>1024||typeof e.runtime.capture.adapter!="string"||e.runtime.capture.adapter.length>1024||!Array.isArray(e.runtime.capture.features)||e.runtime.capture.features.length>256||!e.runtime.capture.features.every(r=>typeof r=="string"&&r.length>0&&r.length<=128)))throw new Error("Shader meta.json has invalid browser capture provenance.");let t=Object.entries(e.scenes);if(t.length===0)throw new Error("Shader meta.json contains no scenes.");for(let[r,n]of t){if(!Oe.test(r)||!f(n)||typeof n.artifact!="string"||!fe(n.artifact)||!n.artifact.endsWith(".webgpu.ts")||typeof n.artifactHash!="string"||!te.test(n.artifactHash))throw new Error(`Shader receipt for "${r}" is invalid.`);if(n.asset===void 0!=(n.assetHash===void 0)||n.asset!==void 0&&(typeof n.asset!="string"||!fe(n.asset)||!n.asset.endsWith(".json")||typeof n.assetHash!="string"||!te.test(n.assetHash)))throw new Error(`Shader static asset receipt for "${r}" is invalid.`);if(kt(n.inputs,r),Rt(n.coverage),n.bytes!==void 0&&(!Number.isSafeInteger(n.bytes)||Number(n.bytes)<0))throw new Error(`Shader receipt byte count for "${r}" is invalid.`);if(n.skipped!==void 0&&(!f(n.skipped)||!Number.isSafeInteger(n.skipped.render)||Number(n.skipped.render)<0||!Number.isSafeInteger(n.skipped.compute)||Number(n.skipped.compute)<0))throw new Error(`Shader receipt skipped-build counts for "${r}" are invalid.`)}if(e.tool!==void 0&&(!f(e.tool)||e.tool.name!=="@three-blocks/devtools"||!z(e.tool.version)||typeof e.tool.compatibility!="string"||!Number.isSafeInteger(e.tool.transform)||!Number.isSafeInteger(e.tool.address)||!Number.isSafeInteger(e.tool.recipe)||!Number.isSafeInteger(e.tool.hydration)))throw new Error("Shader meta.json has invalid tool compatibility metadata.");return e}a(re,"parseShaderReceipt");var ve="three-blocks.shaders.json",he=".three-blocks/shaders";var Tt=/^[a-z0-9][a-z0-9_-]{0,63}$/u,jt=/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/u,De=64,Le=64,At={schemaVersion:1,scenes:[{key:"default",url:"/"}]};function Fe(e,t,r){if(e===void 0)return r;if(typeof e!="string"||e.length===0||e.length>512||w.isAbsolute(e)||/[\u0000-\u001f\u007f]/u.test(e))throw new Error(`${t} must be a bounded project-relative directory.`);let n=w.posix.normalize(e.replaceAll("\\","/")).replace(/\/+$/u,"");if(n==="."||n===".."||n.startsWith("../"))throw new Error(`${t} must stay inside the project.`);return n}a(Fe,"safeProjectDirectory");function $t(e,t){let r=Fe(e,t,"");if(typeof e!="string"||e.endsWith("/"))throw new Error(`${t} must be a project-relative file.`);return r}a($t,"safeProjectFile");function D(e,t,r,n,i){if(e===void 0)return i;if(!Number.isSafeInteger(e)||Number(e)<r||Number(e)>n)throw new Error(`${t} must be an integer in ${r}...${n}.`);return Number(e)}a(D,"boundedInteger");function Ve(e,t,r){if(e===void 0)return r;if(typeof e!="number"||!Number.isFinite(e)||e<0||e>1)throw new Error(`${t} must be a finite ratio in 0...1.`);return e}a(Ve,"finiteRatio");function He(e,t){if(typeof e!="string"||e.length===0||e.length>2048||/[\u0000-\u001f\u007f]/u.test(e))throw new Error(`${t} must be a bounded project-relative URL.`);let r;try{r=new URL(e,"http://three-blocks.invalid/");}catch{throw new Error(`${t} is not a valid URL.`)}if(r.origin!=="http://three-blocks.invalid"||r.hash.length>0)throw new Error(`${t} must stay within the project and must not contain a fragment.`);return `${r.pathname}${r.search}`}a(He,"safeBrowserUrl");function Ct(e){if(!Array.isArray(e)||e.length===0||e.length>De)throw new Error(`Shader config scenes must contain 1...${De} entries.`);let t=new Set;return e.map((r,n)=>{if(!f(r)||typeof r.key!="string"||!Tt.test(r.key))throw new Error(`Shader config scene ${n} has an invalid key.`);if(t.has(r.key))throw new Error(`Shader config scene key "${r.key}" is duplicated.`);t.add(r.key);let i=r.parityFrames,s=r.maxDiffRatio;if(r.inputs!==void 0&&(!Array.isArray(r.inputs)||r.inputs.length===0||r.inputs.length>Le))throw new Error(`Shader config scene "${r.key}" inputs must contain 1...${Le} files.`);let o=r.inputs===void 0?void 0:r.inputs.map((c,l)=>$t(c,`Shader config scene "${r.key}" input ${l}`));if(o!==void 0&&new Set(o).size!==o.length)throw new Error(`Shader config scene "${r.key}" inputs must be unique.`);if(r.runtimeMotion!==void 0&&typeof r.runtimeMotion!="boolean")throw new Error(`Shader config scene "${r.key}" runtimeMotion must be a boolean.`);return {key:r.key,url:He(r.url,`Shader config scene "${r.key}" URL`),requiresText:r.requiresText===true,...o===void 0?{}:{inputs:o},...i===void 0?{}:{parityFrames:D(i,`Shader config scene "${r.key}" parityFrames`,0,1e4,0)},...s===void 0?{}:{maxDiffRatio:Ve(s,`Shader config scene "${r.key}" maxDiffRatio`,.01)},...r.runtimeMotion===true?{runtimeMotion:true}:{}}})}a(Ct,"parseScenes");function pe(e){if(!f(e)||e.schemaVersion!==void 0&&e.schemaVersion!==1)throw new Error("Shader config must use schemaVersion 1.");let t=e.viewport;if(t!==void 0&&!f(t))throw new Error("Shader config viewport must be an object.");let r=e.parity;if(r!==void 0&&!f(r))throw new Error("Shader config parity must be an object.");let n=e.bridge;if(n!==void 0&&!f(n))throw new Error("Shader config bridge must be an object.");let i=f(n)?n.deterministicModule:void 0;i!==void 0&&He(i,"Shader deterministic module");let s=e.readiness;if(s!==void 0&&!f(s))throw new Error("Shader config readiness must be an object.");let o=f(s)?s.selector:void 0;if(o!==void 0&&(typeof o!="string"||o.length===0||o.length>512||/[\u0000-\u001f\u007f]/u.test(o)))throw new Error("Shader readiness selector must be a bounded, non-empty CSS selector.");let c=f(s)?s.global:void 0;if(c!==void 0&&(typeof c!="string"||!jt.test(c)))throw new Error("Shader readiness global must be a dot-separated JavaScript property path.");return {schemaVersion:1,scenes:Ct(e.scenes),settleFrames:D(e.settleFrames,"Shader settleFrames",0,1e4,60),settleTimeoutMs:D(e.settleTimeoutMs,"Shader settleTimeoutMs",1e3,15*6e4,3e4),browserRelaunchScenes:D(e.browserRelaunchScenes,"Shader browserRelaunchScenes",1,64,8),timeoutMs:D(e.timeoutMs,"Shader timeoutMs",1e3,15*6e4,24e4),viewport:{width:D(f(t)?t.width:void 0,"Shader viewport width",64,8192,1024),height:D(f(t)?t.height:void 0,"Shader viewport height",64,8192,640)},parity:{frames:D(f(r)?r.frames:void 0,"Shader parity frames",0,1e4,90),channelTolerance:D(f(r)?r.channelTolerance:void 0,"Shader parity channelTolerance",0,255,8),maxDiffRatio:Ve(f(r)?r.maxDiffRatio:void 0,"Shader parity maxDiffRatio",.01)},bridge:{legacyLab:f(n)&&n.legacyLab===true,...typeof i=="string"?{deterministicModule:i}:{}},readiness:{...typeof o=="string"?{selector:o}:{},...typeof c=="string"?{global:c}:{}},publicDir:Fe(e.publicDir,"Shader publicDir","public"),allowLiveBuilds:e.allowLiveBuilds!==false}}a(pe,"parseShaderToolConfig");async function ze(e=process.cwd()){let t=w.resolve(e);for(;;){if(await A(w.join(t,ve))||await A(w.join(t,"three-blocks.json")))return realpath(t);let r=w.join(t,"package.json");if(await A(r)){let i=await C(t,r,x.packageJson,"Project package.json"),s;try{s=JSON.parse(i.data.toString("utf8"));}catch{throw new Error(`Project package.json is not valid JSON: ${r}.`)}if(f(s)&&[s.dependencies,s.devDependencies,s.peerDependencies,s.optionalDependencies].filter(f).some(l=>typeof l.three=="string"||typeof l["three-blocks"]=="string"||typeof l["@three-blocks/devtools"]=="string"))return realpath(t)}let n=w.dirname(t);if(n===t)throw new Error(`No Three Blocks shader project found from ${JSON.stringify(w.resolve(e))}; add Three.js to package.json or pass --root.`);t=n;}}a(ze,"findShaderProjectRoot");async function ge(e){let t=await realpath(e),r=w.join(t,ve);if(await A(r)){let i=await C(t,r,x.metadata,"Shader configuration");return pe(JSON.parse(i.data.toString("utf8")))}let n=w.join(t,"three-blocks.json");if(await A(n)){let i=Ne(JSON.parse(await readFile(n,"utf8")));return pe({schemaVersion:1,scenes:[{key:i.template,url:"/",requiresText:i.features.text}]})}return pe(At)}a(ge,"loadShaderToolConfig");function J(e){if(/^0\.185\./u.test(e))return THREE_WEBGPU_R185_COMPATIBILITY;if(e===THREE_R186DEV_VERSION)return THREE_WEBGPU_R186DEV_COMPATIBILITY;throw new Error(`Three.js ${e} is outside the supported shader compatibility contracts.`)}a(J,"shaderCompatibilityForThree");var q="0.1.0";var se=53,Ot="timing.local.json",Nt="timing.json";var ie=4096,Dt=4096;function ye(e,t,r=8192){if(typeof e!="string"||e.length===0||e.length>r||/[\u0000\u007f]/u.test(e))throw new Error(`${t} must be a bounded non-empty string.`);return e}a(ye,"boundedString");function y(e,t,r=true){if(typeof e!="number"||!Number.isFinite(e)||e<0||r&&!Number.isSafeInteger(e))throw new Error(`${t} must be a non-negative ${r?"integer":"finite number"}.`);return e}a(y,"nonNegativeNumber");function Lt(e){if(!f(e))throw new Error("Shader capture stats are missing.");let t={buildCalls:y(e.buildCalls,"capture stats.buildCalls"),renderBuilds:y(e.renderBuilds,"capture stats.renderBuilds"),computeBuilds:y(e.computeBuilds,"capture stats.computeBuilds"),registeredBuilds:y(e.registeredBuilds,"capture stats.registeredBuilds"),registeredRenderBuilds:y(e.registeredRenderBuilds,"capture stats.registeredRenderBuilds"),registeredComputeBuilds:y(e.registeredComputeBuilds,"capture stats.registeredComputeBuilds"),buildMs:y(e.buildMs,"capture stats.buildMs",false),syncBuildMs:y(e.syncBuildMs,"capture stats.syncBuildMs",false),asyncBuildElapsedMs:y(e.asyncBuildElapsedMs,"capture stats.asyncBuildElapsedMs",false),precompiledSetupMs:y(e.precompiledSetupMs,"capture stats.precompiledSetupMs",false),maxSyncBuildMs:y(e.maxSyncBuildMs??e.syncBuildMs,"capture stats.maxSyncBuildMs",false),maxPrecompiledSetupMs:y(e.maxPrecompiledSetupMs??e.precompiledSetupMs,"capture stats.maxPrecompiledSetupMs",false),hydrationMs:y(e.hydrationMs??0,"capture stats.hydrationMs",false),maxHydrationMs:y(e.maxHydrationMs??e.hydrationMs??0,"capture stats.maxHydrationMs",false),injected:y(e.injected,"capture stats.injected"),injectedRender:y(e.injectedRender,"capture stats.injectedRender"),injectedCompute:y(e.injectedCompute,"capture stats.injectedCompute"),missed:y(e.missed,"capture stats.missed"),missedRender:y(e.missedRender,"capture stats.missedRender"),missedCompute:y(e.missedCompute,"capture stats.missedCompute"),...Array.isArray(e.missedKeys)&&e.missedKeys.every(r=>typeof r=="string")?{missedKeys:e.missedKeys.slice(0,ie)}:{}};if(t.renderBuilds+t.computeBuilds!==t.buildCalls||t.registeredRenderBuilds+t.registeredComputeBuilds!==t.registeredBuilds||t.injectedRender+t.injectedCompute!==t.injected||t.missedRender+t.missedCompute!==t.missed||t.registeredBuilds>t.buildCalls||Math.abs(t.syncBuildMs+t.asyncBuildElapsedMs-t.buildMs)>.001||t.maxSyncBuildMs>t.syncBuildMs+.001||t.maxPrecompiledSetupMs>t.precompiledSetupMs+.001||t.maxHydrationMs>t.hydrationMs+.001)throw new Error("Shader capture stats totals are inconsistent.");return t}a(Lt,"captureStats");function vt(e){if(!Array.isArray(e)||e.length>ie)throw new Error("Shader capture skipped builds are invalid.");return e.map((t,r)=>{if(!f(t)||t.kind!=="render"&&t.kind!=="compute")throw new Error(`Shader capture skipped build ${r} is invalid.`);return {kind:t.kind,name:ye(t.name,`skipped build ${r} name`,512),reason:ye(t.reason,`skipped build ${r} reason`)}})}a(vt,"skippedBuilds");function Ft(e){let t=0,r=0,n=0,i=0;for(let s of Object.values(e.entries)){let o=e.states[s];o!==void 0&&((o.vertex!==null||o.fragment!==null)&&t++,o.vertex!==null&&r++,o.fragment!==null&&n++,o.compute!==null&&i++);}return {render:t,vertex:r,fragment:n,compute:i}}a(Ft,"shaderCoverage");function Vt(e,t){if(!f(e))throw new Error("Shader capture payload must be an object.");if(e.scene!==t.scene)throw new Error(`Shader capture scene does not match "${t.scene}".`);if(e.protocolVersion!==2)throw new Error("Shader capture protocolVersion must be 2.");let r=J(t.runtime.three);if(e.compatibility!==r)throw new Error(`Shader capture compatibility must be "${r}".`);if(!f(e.entries))throw new Error("Shader capture entries must be an object.");if(typeof e.requiresSetup!="boolean")throw new Error("Shader capture requiresSetup must be boolean.");let n=Object.keys(e.entries).length;if(n===0||n>ie)throw new Error(`Shader capture must contain 1...${ie} entries.`);if(!Array.isArray(e.errors)||e.errors.length>Dt)throw new Error("Shader capture errors are invalid.");let i=e.errors.map((p,d)=>ye(p,`capture error ${d}`,64*1024));if(i.length>0)throw new Error(`Shader capture failed:
|
|
2
2
|
- ${i.join(`
|
|
3
3
|
- `)}`);let s=vt(e.skipped),o=Lt(e.stats),c=f(e.timing)?e.timing:void 0,l=c===void 0?void 0:Object.fromEntries(["launch","firstRequest","readiness","lastBuild","settled","posted"].flatMap(p=>{let d=c[p];if(d===void 0)return [];if(typeof d!="number"||!Number.isFinite(d)||d<0)throw new Error(`Shader capture timing.${p} is invalid.`);return [[p,d]]})),m;if(e.provenance!==void 0){if(!f(e.provenance)||typeof e.provenance.userAgent!="string"||e.provenance.userAgent.length>1024||typeof e.provenance.adapter!="string"||e.provenance.adapter.length>1024||!Array.isArray(e.provenance.features)||e.provenance.features.length>256||!e.provenance.features.every(p=>typeof p=="string"&&p.length<=128))throw new Error("Shader capture provenance is invalid.");m={userAgent:e.provenance.userAgent,adapter:e.provenance.adapter,features:[...new Set(e.provenance.features)].sort()};}let g=parsePrecompiledManifest({version:PRECOMPILED_MANIFEST_VERSION,scene:t.scene,three:t.runtime.three,threeBlocks:t.runtime.threeBlocks,runtime:{id:r,address:SHADER_ADDRESS_SCHEMA_VERSION,recipe:SHADER_RECIPE_SCHEMA_VERSION,hydration:SHADER_HYDRATION_SCHEMA_VERSION},...e.automatic===void 0?{}:{automatic:e.automatic},requiresSetup:e.requiresSetup,modules:e.modules,nodes:e.nodes,layouts:e.layouts,attributePlans:e.attributePlans,updatePlans:e.updatePlans,requirementPlans:e.requirementPlans,states:e.states,entries:e.entries}),u=Ft(g);if(o.registeredRenderBuilds<u.render||o.registeredComputeBuilds<u.compute)throw new Error("Shader capture did not live-build every distinct registered render/compute entry.");return {scene:t.scene,manifest:g,skipped:s,stats:o,coverage:u,...l===void 0?{}:{timing:l},...m===void 0?{}:{provenance:m}}}a(Vt,"validateShaderCapture");function U(e,t=0){let r=" ".repeat(t),n=" ".repeat(t+1);if(Array.isArray(e))return e.length===0?"[]":e.every(s=>s===null||["number","string","boolean"].includes(typeof s))?JSON.stringify(e):`[
|
|
4
4
|
${e.map(s=>`${n}${U(s,t+1)}`).join(`,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {e as e$1}from'./chunk-
|
|
2
|
+
import {e as e$1}from'./chunk-LVY4EXVQ.js';import'./chunk-TGOUAHMD.js';import'./chunk-NE7SC2BX.js';import'./chunk-ZT6T2W4B.js';import {e}from'./chunk-NEWSG5RX.js';import'./chunk-ZDNZCQUQ.js';import'./chunk-5L2VS3BN.js';import {a}from'./chunk-HOZDD6PW.js';import {watch}from'fs';import v from'path';var o=class{static{a(this,"ShaderWatchQueue");}#s;#r;#a;#e;#t;#i=false;#n=false;constructor(r){if(this.#s=r.capture,this.#r=r.debounceMs??200,this.#a=r.onError??(()=>{}),!Number.isSafeInteger(this.#r)||this.#r<0||this.#r>6e4)throw new Error("Shader watch debounce must be an integer in 0...60000ms.")}notify(){this.#n||(this.#i=true,!this.#t&&(this.#e&&clearTimeout(this.#e),this.#e=setTimeout(()=>{this.#e=void 0,this.#o();},this.#r)));}#o(){this.#n||this.#t||!this.#i||(this.#i=false,this.#t=this.#s().catch(r=>{this.#a(r instanceof Error?r:new Error(String(r)));}).finally(()=>{this.#t=void 0,this.#i&&!this.#n&&this.notify();}));}async close(){this.#n=true,this.#i=false,this.#e&&clearTimeout(this.#e),this.#e=void 0,await this.#t;}};function y(e){let r=e.split(v.sep).join("/");return r===""||r.startsWith("node_modules/")||r.startsWith(".git/")||r.startsWith("dist/")||r===".three-blocks"||r.startsWith(".three-blocks/")}a(y,"ignored");async function W(e$2={}){let r=e$2.root??await e(e$2.start),d,l=new Promise(t=>{d=t;}),n=new o({...e$2.debounceMs!==void 0?{debounceMs:e$2.debounceMs}:{},...e$2.onError?{onError:e$2.onError}:{},capture:a(async()=>{let t=await e$1({root:r,...e$2.config?{config:e$2.config}:{},...e$2.driver?{driver:e$2.driver}:{},...e$2.driverKind?{driverKind:e$2.driverKind}:{},...e$2.serve?{serve:e$2.serve}:{},...e$2.url?{url:e$2.url}:{},...e$2.headed!==void 0?{headed:e$2.headed}:{},...e$2.attempts!==void 0?{attempts:e$2.attempts}:{}});e$2.onResult?.(t);},"capture")}),s,u=false,a$1=a(async()=>{u||(u=true,s?.close(),await n.close(),d?.());},"close");return s=watch(r,{recursive:true},(t,f)=>{y(f??"")||n.notify();}),s.on("error",t=>e$2.onError?.(t)),e$2.signal&&(e$2.signal.aborted?await a$1():e$2.signal.addEventListener("abort",()=>{a$1();},{once:true})),e$2.initial!==false&&n.notify(),{root:r,done:l,close:a$1}}a(W,"watchShaders");export{o as ShaderWatchQueue,W as watchShaders};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export{e as captureShaders,d as inspectShaderMatrix,f as testShaders}from'./chunk-
|
|
2
|
+
export{e as captureShaders,d as inspectShaderMatrix,f as testShaders}from'./chunk-LVY4EXVQ.js';import'./chunk-TGOUAHMD.js';import'./chunk-NE7SC2BX.js';import'./chunk-ZT6T2W4B.js';import'./chunk-NEWSG5RX.js';import'./chunk-ZDNZCQUQ.js';import'./chunk-5L2VS3BN.js';import'./chunk-HOZDD6PW.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export{b as RUNTIME_STATUS_RECEIPT_MAX_BYTES,a as RUNTIME_STATUS_RECEIPT_PATH,c as RUNTIME_STATUS_RECOVERY,e as findProjectRoot,i as formatShaderMatrixStatus,j as formatStatus,k as formatThreeBlocksStatus,f as inspectProject,g as inspectThreeBlocksStatus,d as parseRuntimeStatusReceipt,h as threeBlocksStatusIsFresh}from'./chunk-
|
|
2
|
+
export{b as RUNTIME_STATUS_RECEIPT_MAX_BYTES,a as RUNTIME_STATUS_RECEIPT_PATH,c as RUNTIME_STATUS_RECOVERY,e as findProjectRoot,i as formatShaderMatrixStatus,j as formatStatus,k as formatThreeBlocksStatus,f as inspectProject,g as inspectThreeBlocksStatus,d as parseRuntimeStatusReceipt,h as threeBlocksStatusIsFresh}from'./chunk-D6DGT5CE.js';import'./chunk-76WRV5MZ.js';import'./chunk-JMS5NTP7.js';export{c as readInstalledShaderRuntime,b as snapshotShaderInputs}from'./chunk-LVY4EXVQ.js';import'./chunk-TGOUAHMD.js';import'./chunk-NE7SC2BX.js';import'./chunk-ZT6T2W4B.js';import'./chunk-NEWSG5RX.js';import'./chunk-ZDNZCQUQ.js';import'./chunk-5L2VS3BN.js';import'./chunk-HOZDD6PW.js';
|
package/dist/transform.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as THREE_BLOCKS_WEBPACK_LOADER,f as createEsbuildShaderPlugin,g as createRollupShaderPlugin,d as resolveShaderAdapterThreeVersion,e as transformThreeWebGPUModule,c as withThreeBlocksNext,b as withThreeBlocksWebpack}from'./chunk-
|
|
1
|
+
export{a as THREE_BLOCKS_WEBPACK_LOADER,f as createEsbuildShaderPlugin,g as createRollupShaderPlugin,d as resolveShaderAdapterThreeVersion,e as transformThreeWebGPUModule,c as withThreeBlocksNext,b as withThreeBlocksWebpack}from'./chunk-QGCA3ERA.js';import'./chunk-2JE5VZXK.js';import'./chunk-EI7MMDWY.js';
|
package/dist/webpack-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {e}from'./chunk-
|
|
1
|
+
import {e}from'./chunk-QGCA3ERA.js';import'./chunk-2JE5VZXK.js';import {a}from'./chunk-EI7MMDWY.js';function o(e$1){return e(e$1,this.resourcePath,this.getOptions?.()??{})?.code??e$1}a(o,"threeBlocksShaderLoader");export{o as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@three-blocks/devtools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.214.gf051bb7d43f2",
|
|
4
4
|
"description": "Three Blocks devtools command engine for npx three-blocks; the runtime lives in three-blocks/devtools and the Vite plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@types/three": "0.185.0",
|
|
80
80
|
"create-vite": "9.1.1",
|
|
81
81
|
"playwright": "^1.61.1",
|
|
82
|
-
"three-blocks": "0.2.
|
|
82
|
+
"three-blocks": "0.2.1-alpha.214.gf051bb7d43f2",
|
|
83
83
|
"tsup": "^8.0.0",
|
|
84
84
|
"typescript": "^5.9.3",
|
|
85
85
|
"vite": "^7.2.2",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"playwright": "^1.61.1",
|
|
93
93
|
"three": ">=0.185.0 <0.186.0",
|
|
94
|
-
"three-blocks": "0.2.
|
|
94
|
+
"three-blocks": "0.2.1-alpha.214.gf051bb7d43f2",
|
|
95
95
|
"typescript": ">=5.9.3 <7.0.0",
|
|
96
96
|
"vite": ">=7.2.2 <9.0.0"
|
|
97
97
|
},
|