threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
3 лет назад
1 год назад
1 год назад
3 лет назад
3 лет назад
1 год назад
3 лет назад
1 год назад
3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839
  1. import {setupCodePreview} from 'https://cdn.jsdelivr.net/gh/repalash/example-code-previewer/dist/index.js';
  2. const rootPath = 'https://threepipe.org/'
  3. const examplePath = 'examples/'
  4. const codePath = 'https://github.com/repalash/threepipe/tree/master/'
  5. const exampleScript = document.getElementById('example-script')
  6. const scripts = exampleScript && exampleScript.dataset.scripts ? exampleScript.dataset.scripts.split(';') : []
  7. if(exampleScript.textContent) scripts.push(exampleScript)
  8. const exampleStyle = document.querySelector('#example-style')
  9. const css = exampleStyle ? exampleStyle.textContent : ''
  10. const importMap = document.querySelector('script[type="importmap"]')
  11. const imports = importMap ? JSON.parse(importMap.textContent||'{}').imports||{} : {}
  12. Object.keys(imports).forEach((k)=>(k === 'threepipe' || k.startsWith('@threepipe/')) ? (imports[k] = 'https://unpkg.com/'+k+'/dist/index.mjs') : '') // required for codepen to work. this is done because plugins refer to threepipe as esm
  13. Object.entries(imports).forEach(([k,v])=>imports[k] = v.replace(/^\.\/\.\.\/\.\.\//, rootPath)) // ./../../ -> rootPath
  14. // function replaceImports(code) {
  15. // for (const [name, link] of Object.entries(imports)) code = code.replaceAll(` from '${name}'`, ` from '${link}'`)
  16. // return code
  17. // .replaceAll(` from '../../`, ` from '${rootPath}`)
  18. // .replaceAll(` from '../`, ` from '${rootPath+examplePath}`)
  19. // }
  20. setupCodePreview(
  21. document.querySelector('.code-preview-container') || document.getElementById('canvas-container') || document.body,
  22. scripts,
  23. scripts.map(s=>s.textContent ? 'js' : s.split('.').pop()), // title
  24. scripts.map(s=>(typeof s === 'string' && s.endsWith('.js')) ? s : (codePath+examplePath+window.location.pathname.split('/examples/').pop().replace('index.html', '')+(s.textContent ? 'index.html' : s))), // todo: github link
  25. (c) => '// Threepipe example: ' + window.location.href + '\n' + (c),
  26. {
  27. title: 'ThreePipe: ' + document.title,
  28. css,
  29. },
  30. `
  31. <!-- Import maps polyfill -->
  32. <!-- Remove this when import maps will be widely supported -->
  33. <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
  34. <script type="importmap">${JSON.stringify({imports}, null, 2)}</script>
  35. `
  36. );