function fixSourceLinks(url, source) {
  const srcRE = /(src=)(")(.*?)(")/g;
  const linkRE = /(href=)(")(.*?)(")/g;
  const imageSrcRE = /((?:image|img)\.src = )(")(.*?)(")/g;
  const loadImageRE = /(loadImageAndCreateTextureInfo)\(('|")(.*?)('|")/g;
  const loadImagesRE = /loadImages(\s*)\((\s*)\[([^]*?)\](\s*),/g;
  const loadGLTFRE = /(loadGLTF\(')(.*?)(')/g;
  const webgpufundamentalsUrlRE = /(.*?)('|")([^"']*?)('|")([^'"]*?)(\/\*\s+webgpufundamentals:\s+url\s+\*\/)/ig;
  const urlPropRE = /(url:\s*)('|")(.*?)('|")/g;
  const quoteRE = /"(.*?)"/g;
  const workerRE = /(new\s+Worker\s*\(\s*)('|")(.*?)('|")/g;
  const importScriptsRE = /(importScripts\s*\(\s*)('|")(.*?)('|")/g;
  const moduleRE = /(import.*?)('|")(.*?)('|")/g;
  const prefix = getPrefix(url);
  const rootPrefix = getRootPrefix(url);

  function addCorrectPrefix(url) {
    return (url.startsWith('/'))
       ? `${rootPrefix}${url}`
       : removeDotDotSlash((prefix + url).replace(/\/.\//g, '/'));
  }

  function addPrefix(url) {
    return url.indexOf('://') < 0 && !url.startsWith('data:') && url[0] !== '?'
        ? removeDotDotSlash(addCorrectPrefix(url))
        : url;
  }
  function makeLinkFQedQuote(match, p1, url, p2) {
    return `${p1}${addPrefix(url)}${p2}`;
  }
  function makeLinkFDedQuotes(match, fn, q1, url, q2) {
    return fn + q1 + addPrefix(url) + q2;
  }
  function makeTaggedFDedQuotes(match, start, q1, url, q2, suffix) {
    return start + q1 + addPrefix(url) + q2 + suffix;
  }
  function makeFDedQuotes(match, start, q1, url, q2) {
    return start + q1 + addPrefix(url) + q2;
  }
  function makeLinkFDedQuotesModule(match, start, q1, url, q2) {
    // modules require relative paths or fully qualified, otherwise they are module names
    return `${start}${q1}${url.startsWith('.') ? addPrefix(url) : url}${q2}`;
  }
  source = source.replace(srcRE, makeLinkFDedQuotes);
  source = source.replace(linkRE, makeLinkFDedQuotes);
  source = source.replace(imageSrcRE, makeLinkFDedQuotes);
  source = source.replace(urlPropRE, makeLinkFDedQuotes);
  source = source.replace(workerRE, makeLinkFDedQuotes);
  source = source.replace(importScriptsRE, makeLinkFDedQuotesModule);
  source = source.replace(loadImageRE, function(match, fn, q1, url, q2) {
    return fn + '(' + q1 + addPrefix(url) + q2;
  });
  source = source.replace(loadImagesRE, function(match, p1, p2, p3, p4) {
      p3 = p3.replace(quoteRE, function(match, p1) {
          return '"' + addPrefix(p1) + '"';
      });
      return `loadImages${p1}(${p2}[${p3}]${p4},`;
  });
  source = source.replace(loadGLTFRE, makeLinkFQedQuote);
  source = source.replace(webgpufundamentalsUrlRE, makeTaggedFDedQuotes);
  source = source.replace(moduleRE, makeFDedQuotes);
  return source;
}
/**
 * Fix any local URLs into fully qualified urls.
 *
 * Examples:
 *    resources/image.jpg ->  https://domain.org/webgl/resouces/image.jpg
 *    /3rdparty/lib.js    ->  https://domain.org/3rdparty/lib.js
 *
 * The reason is (a) we're running the code as via blobUrl and nothing is relative to a blob.
 * (b) we can upload to jsfiddle/codepen and so need to link back to the files.
 *
 * This is all kind of hacky in that it's just a bunch of regular expressions looking
 * for matches.
 *
 * @param {string} url The URL of the file source.
 * @param {string} source An HTML file or JavaScript file
 * @returns {string} the source after having urls fixed.
 */
Fix any local URLs into fully qualified urls.

The reason is (a) we're running the code as via blobUrl and nothing is relative to a blob.
(b) we can upload to jsfiddle/codepen and so need to link back to the files.

This is all kind of hacky in that it's just a bunch of regular expressions looking
for matches.

@param {string} url The URL of the file source.
@param {string} source An HTML file or JavaScript file
@returns {string} the source after having urls fixed.
Fix any local URLs into fully qualified urls . The reason is ( a ) we ' re running the code as via blobUrl and nothing is relative to a blob . ( b ) we can upload to jsfiddle / codepen and so need to link back to the files . This is all kind of hacky in that it ' s just a bunch of regular expressions looking for matches . @param { string } url The URL of the file source . @param { string } source An HTML file or JavaScript file @returns { string } the source after having urls fixed .
function fixSourceLinks(url, source) {
  const srcRE = /(src=)(")(.*?)(")/g;
  const linkRE = /(href=)(")(.*?)(")/g;
  const imageSrcRE = /((?:image|img)\.src = )(")(.*?)(")/g;
  const loadImageRE = /(loadImageAndCreateTextureInfo)\(('|")(.*?)('|")/g;
  const loadImagesRE = /loadImages(\s*)\((\s*)\[([^]*?)\](\s*),/g;
  const loadGLTFRE = /(loadGLTF\(')(.*?)(')/g;
  const webgpufundamentalsUrlRE = /(.*?)('|")([^"']*?)('|")([^'"]*?)(\/\*\s+webgpufundamentals:\s+url\s+\*\/)/ig;
  const urlPropRE = /(url:\s*)('|")(.*?)('|")/g;
  const quoteRE = /"(.*?)"/g;
  const workerRE = /(new\s+Worker\s*\(\s*)('|")(.*?)('|")/g;
  const importScriptsRE = /(importScripts\s*\(\s*)('|")(.*?)('|")/g;
  const moduleRE = /(import.*?)('|")(.*?)('|")/g;
  const prefix = getPrefix(url);
  const rootPrefix = getRootPrefix(url);
  function addCorrectPrefix(url) {
    return (url.startsWith('/'))
       ? `${rootPrefix}${url}`
       : removeDotDotSlash((prefix + url).replace(/\/.\//g, '/'));
  }
  function addPrefix(url) {
    return url.indexOf('://') < 0 && !url.startsWith('data:') && url[0] !== '?'
        ? removeDotDotSlash(addCorrectPrefix(url))
        : url;
  }
  function makeLinkFQedQuote(match, p1, url, p2) {
    return `${p1}${addPrefix(url)}${p2}`;
  }
  function makeLinkFDedQuotes(match, fn, q1, url, q2) {
    return fn + q1 + addPrefix(url) + q2;
  }
  function makeTaggedFDedQuotes(match, start, q1, url, q2, suffix) {
    return start + q1 + addPrefix(url) + q2 + suffix;
  }
  function makeFDedQuotes(match, start, q1, url, q2) {
    return start + q1 + addPrefix(url) + q2;
  }
  function makeLinkFDedQuotesModule(match, start, q1, url, q2) {
    return `${start}${q1}${url.startsWith('.') ? addPrefix(url) : url}${q2}`;
  }
  source = source.replace(srcRE, makeLinkFDedQuotes);
  source = source.replace(linkRE, makeLinkFDedQuotes);
  source = source.replace(imageSrcRE, makeLinkFDedQuotes);
  source = source.replace(urlPropRE, makeLinkFDedQuotes);
  source = source.replace(workerRE, makeLinkFDedQuotes);
  source = source.replace(importScriptsRE, makeLinkFDedQuotesModule);
  source = source.replace(loadImageRE, function(match, fn, q1, url, q2) {
    return fn + '(' + q1 + addPrefix(url) + q2;
  });
  source = source.replace(loadImagesRE, function(match, p1, p2, p3, p4) {
      p3 = p3.replace(quoteRE, function(match, p1) {
          return '"' + addPrefix(p1) + '"';
      });
      return `loadImages${p1}(${p2}[${p3}]${p4},`;
  });
  source = source.replace(loadGLTFRE, makeLinkFQedQuote);
  source = source.replace(webgpufundamentalsUrlRE, makeTaggedFDedQuotes);
  source = source.replace(moduleRE, makeFDedQuotes);
  return source;
}
function fixSourceLinks ( url , source ) { const srcRE = / (src=)(")(.*?)(") / g ; const linkRE = / (href=)(")(.*?)(") / g ; const imageSrcRE = / ((?:image|img)\.src = )(")(.*?)(") / g ; const loadImageRE = / (loadImageAndCreateTextureInfo)\(('|")(.*?)('|") / g ; const loadImagesRE = / loadImages(\s*)\((\s*)\[([^]*?)\](\s*), / g ; const loadGLTFRE = / (loadGLTF\(')(.*?)(') / g ; const webgpufundamentalsUrlRE = / (.*?)('|")([^"']*?)('|")([^'"]*?)(\/\*\s+webgpufundamentals:\s+url\s+\*\/) / ig ; const urlPropRE = / (url:\s*)('|")(.*?)('|") / g ; const quoteRE = / "(.*?)" / g ; const workerRE = / (new\s+Worker\s*\(\s*)('|")(.*?)('|") / g ; const importScriptsRE = / (importScripts\s*\(\s*)('|")(.*?)('|") / g ; const moduleRE = / (import.*?)('|")(.*?)('|") / g ; const prefix = getPrefix ( url ) ; const rootPrefix = getRootPrefix ( url ) ; function addCorrectPrefix ( url ) { return ( url . startsWith ( '/' ) ) ? ` ${ rootPrefix } ${ url } ` : removeDotDotSlash ( ( prefix + url ) . replace ( / \/.\/ / g , '/' ) ) ; } function addPrefix ( url ) { return url . indexOf ( '://' ) < 0 && ! url . startsWith ( 'data:' ) && url [ 0 ] !== '?' ? removeDotDotSlash ( addCorrectPrefix ( url ) ) : url ; } function makeLinkFQedQuote ( match , p1 , url , p2 ) { return ` ${ p1 } ${ addPrefix ( url ) } ${ p2 } ` ; } function makeLinkFDedQuotes ( match , fn , q1 , url , q2 ) { return fn + q1 + addPrefix ( url ) + q2 ; } function makeTaggedFDedQuotes ( match , start , q1 , url , q2 , suffix ) { return start + q1 + addPrefix ( url ) + q2 + suffix ; } function makeFDedQuotes ( match , start , q1 , url , q2 ) { return start + q1 + addPrefix ( url ) + q2 ; } function makeLinkFDedQuotesModule ( match , start , q1 , url , q2 ) { return ` ${ start } ${ q1 } ${ url . startsWith ( '.' ) ? addPrefix ( url ) : url } ${ q2 } ` ; } source = source . replace ( srcRE , makeLinkFDedQuotes ) ; source = source . replace ( linkRE , makeLinkFDedQuotes ) ; source = source . replace ( imageSrcRE , makeLinkFDedQuotes ) ; source = source . replace ( urlPropRE , makeLinkFDedQuotes ) ; source = source . replace ( workerRE , makeLinkFDedQuotes ) ; source = source . replace ( importScriptsRE , makeLinkFDedQuotesModule ) ; source = source . replace ( loadImageRE , function ( match , fn , q1 , url , q2 ) { return fn + '(' + q1 + addPrefix ( url ) + q2 ; } ) ; source = source . replace ( loadImagesRE , function ( match , p1 , p2 , p3 , p4 ) { p3 = p3 . replace ( quoteRE , function ( match , p1 ) { return '"' + addPrefix ( p1 ) + '"' ; } ) ; return ` ${ p1 } ${ p2 } ${ p3 } ${ p4 } ` ; } ) ; source = source . replace ( loadGLTFRE , makeLinkFQedQuote ) ; source = source . replace ( webgpufundamentalsUrlRE , makeTaggedFDedQuotes ) ; source = source . replace ( moduleRE , makeFDedQuotes ) ; return source ; }
Fix any local URLs into fully qualified urls.
Fix any local URLs into fully qualified urls .
// modules require relative paths or fully qualified, otherwise they are module names