| const css = exampleStyle ? exampleStyle.textContent : '' | const css = exampleStyle ? exampleStyle.textContent : '' | ||||
| const importMap = document.querySelector('script[type="importmap"]') | const importMap = document.querySelector('script[type="importmap"]') | ||||
| const imports = importMap ? JSON.parse(importMap.textContent||'{}').imports||{} : {} | const imports = importMap ? JSON.parse(importMap.textContent||'{}').imports||{} : {} | ||||
| Object.keys(imports).forEach((k)=>(k === 'threepipe' || k.startsWith('@threepipe/')) ? (imports[k] = 'https://esm.sh/'+k) : '') // required for codepen to work. this is done because plugins refer to threepipe as esm | |||||
| Object.entries(imports).forEach(([k,v])=>imports[k] = v.replace(/^\.\/\.\.\/\.\.\//, rootPath)) // ./../../ -> rootPath | Object.entries(imports).forEach(([k,v])=>imports[k] = v.replace(/^\.\/\.\.\/\.\.\//, rootPath)) // ./../../ -> rootPath | ||||
| function replaceImports(code) { | function replaceImports(code) { | ||||
| for (const [name, link] of Object.entries(imports)) code = code.replaceAll(` from '${name}'`, ` from '${link}'`) | for (const [name, link] of Object.entries(imports)) code = code.replaceAll(` from '${name}'`, ` from '${link}'`) | ||||
| return code | return code |