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

simple-code-preview.mjs 1.3KB

3 лет назад
3 лет назад
123456789101112131415161718192021
  1. import {setupCodePreview} from 'https://cdn.jsdelivr.net/gh/repalash/example-code-previewer/dist/index.js';
  2. const exampleScript = document.getElementById('example-script')
  3. const scripts = exampleScript && exampleScript.dataset.scripts ? exampleScript.dataset.scripts.split(';') : []
  4. if(exampleScript.textContent) scripts.push(exampleScript)
  5. const exampleStyle = document.querySelector('#example-style')
  6. const css = exampleStyle ? exampleStyle.textContent : ''
  7. setupCodePreview(
  8. document.getElementById('canvas-container') || document.querySelector('.code-preview-container'),
  9. scripts,
  10. scripts.map(s=>s.textContent ? 'js' : s.split('.').pop()), // title
  11. scripts.map(s=>(typeof s === 'string' && s.endsWith('.js')) ? s : 'https://github.com/repalash/threepipe/tree/master/examples/'+ window.location.pathname.split('/examples/').pop().replace('index.html', '')+(s.textContent ? 'index.html' : s)), // todo: github link
  12. (c)=>c
  13. .replaceAll(" from 'threepipe'", " from 'https://threepipe.org/dist/index.mjs'")
  14. .replaceAll(" from 'uiconfig-tweakpane'", " from 'https://unpkg.com/uiconfig-tweakpane@latest/dist/index.mjs'")
  15. .replaceAll(" from '../", " from 'https://threepipe.org/examples/"),
  16. {
  17. title: 'ThreePipe: ' + document.title,
  18. css,
  19. },
  20. );