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AAe,KAAK,KAAK,GAG3B,MAAM,EAAO,GAAG,aAAa,GAEvB,EAAU,YAAY,GAEtB,EAAI,QAAQ,KAAK,EAAQ,QAAS,CAAE,qBAAqB,IAC/D,EAAE,gBAAgB,YAAY,EAAI,MAClC,IAAI,EAAU,EAAE,QAAQ,OAExB,GAAI,EAAK,OAAQ,CACf,MAAM,EAAmB,SAAS,OAAO,EAAS,CAAE,MAAM,EAAO,OAAQ,UACzE,EAAU,YAAY,UAAU,EAAkB,EAAQ,KAC5D,CACA,GAAG,cAAc,EAAc,EAAS,QACxC,EAAI,KAAK,KACX,CAAE,MAAO,GACP,QAAQ,MAAM,EAChB,KAGF,EAAI,OAAO,GAAM,IAAM,QAAQ,IAAI,kDAAkD,OAAS","file":"/npm/model-viewer-studio@0.0.16/server.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/model-viewer-studio@0.0.16/server.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const cheerio = require(\"cheerio\");\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst express = require(\"express\");\nconst bodyParser = require(\"body-parser\");\nconst prettier = require(\"prettier\");\nconst cors = require(\"cors\");\nconst frontmatter = require('@github-docs/frontmatter');\n\nmodule.exports = ({ target, opts = {}, port = 3000 }) => {\n  const TARGET = target;\n  const TARGET_DIR = path.dirname(TARGET);\n  const app = express();\n  // get a list of all the files it should convert to static\n  const sourceFiles = fs.readdirSync(TARGET_DIR);\n\n  app.use(cors());\n  app.use(bodyParser.text({ type: \"*/*\" }));\n\n  if (opts.headless) {\n    // setup nothing\n  }\n  else {\n    // set up static for all files\n    let staticAssetsIdentified = [];\n    for (const file of sourceFiles) {\n      if (file !== path.basename(TARGET)) {\n        staticAssetsIdentified = [...staticAssetsIdentified, file];\n        app.use(`/${file}`, express.static(path.join(TARGET_DIR, file)));\n      }\n    }\n    console.log(\"Setting the following as static assets: \", staticAssetsIdentified);\n\n    app.use(\"/src\", express.static(path.join(__dirname, \"../frontend/src\")));\n    app.use(\"/web_modules\", express.static(path.join(__dirname, \"../frontend/web_modules\")));\n    \n    app.get(\"/\", (req, res) => {\n      const file = fs.readFileSync(path.join(TARGET), \"utf8\");\n      const $ = cheerio.load(file, { normalizeWhitespace: false });\n      $(\"body\").append(`\n    <x-toolbar></x-toolbar>\n    <x-panel></x-panel>\n    <x-preview style=\"height:100vh;\"></x-preview>\n    <script src=\"src/index.js\" type=\"module\"></script>\n    <script\n      nomodule\n      src=\"https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js\"\n    ></script>\n      `);\n      $(\"model-viewer\").appendTo(\"mvs-preview\");\n      res.send($.html());\n    });\n  }\n\n  app.get(\"/ping\", (req, res) => {\n    res.send(\"ok\");\n  });\n\n  app.post(\"/save\", (req, res) => {\n    try {\n      let fileLocation = null;\n      // if we are running in headless mode then we need to expect\n      // an on demand location variable.\n      if (opts.headless) {\n        let { location } = req.query;\n        fileLocation = path.join(TARGET, location);\n      }\n      else {\n        fileLocation = path.join(TARGET);\n      }\n      // load the existing file.\n      const file = fs.readFileSync(fileLocation);\n      // pull off the front matter\n      const fMatter = frontmatter(file);\n      // load the content portion of the file\n      const $ = cheerio.load(fMatter.content, { normalizeWhitespace: false });\n      $(\"model-viewer\").replaceWith(req.body);\n      let newFile = $('body').html();\n      // if prettier is turned on then format it.\n      if (opts.format) {\n        const formattedContent = prettier.format(newFile, { semi: false, parser: \"babel\" })\n        newFile = frontmatter.stringify(formattedContent, fMatter.data);\n      }\n      fs.writeFileSync(fileLocation, newFile, \"utf8\");\n      res.send(\"ok\");\n    } catch (error) {\n      console.error(error);\n    }\n  });\n\n  app.listen(port, () => console.log(`Example app listening on port http://localhost:${port}!`));\n}\n\n"]}