diff --git a/.vscode/settings.json b/.vscode/settings.json index eb29a0a..997a078 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,15 @@ { - // "editor.formatOnSave": false, - "js/ts.implicitProjectConfig.checkJs": true, - "cSpell.words": [ - "citty", - "consola", - "estree", - "giget", - "mcfly", - "mcflyjs", - "nitropack", - "ultrahtml", - "unstorage" - ] -} \ No newline at end of file + // "editor.formatOnSave": false, + "js/ts.implicitProjectConfig.checkJs": true, + "cSpell.words": [ + "citty", + "consola", + "estree", + "giget", + "mcfly", + "mcflyjs", + "nitropack", + "ultrahtml", + "unstorage" + ] +} diff --git a/eslint.config.js b/eslint.config.js index 0581434..11c03f0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,5 +1,5 @@ -import globals from "globals"; -import pluginJs from "@eslint/js"; +import globals from 'globals' +import pluginJs from '@eslint/js' /** @type {import('eslint').Linter.Config[]} */ export default [ @@ -7,12 +7,12 @@ export default [ pluginJs.configs.recommended, { ignores: [ - "dist/*", - ".output/*", - ".nitro/*", - "node-modules*", - "site/*", - "templates/*", + 'dist/*', + '.output/*', + '.nitro/*', + 'node-modules*', + 'site/*', + 'templates/*', ], }, -]; +] diff --git a/packages/cli/commands/build.mjs b/packages/cli/commands/build.mjs index 330360a..2b128db 100644 --- a/packages/cli/commands/build.mjs +++ b/packages/cli/commands/build.mjs @@ -1,29 +1,29 @@ #!/usr/bin/env node -import { consola } from "consola"; -import { defineCommand } from "citty"; -import { execSync } from "node:child_process"; +import { consola } from 'consola' +import { defineCommand } from 'citty' +import { execSync } from 'node:child_process' function build() { - consola.start("Building project..."); - try { - execSync(`npx nitropack build`, { stdio: "inherit" }); - } catch (err) { - consola.error(err); - } + consola.start('Building project...') + try { + execSync(`npx nitropack build`, { stdio: 'inherit' }) + } catch (err) { + consola.error(err) + } } export default defineCommand({ meta: { - name: "prepare", - description: "Builds the McFly project for production.", + name: 'prepare', + description: 'Builds the McFly project for production.', }, async run() { build() }, -}); +}) export const exportedForTest = { build, -} \ No newline at end of file +} diff --git a/packages/cli/commands/generate.mjs b/packages/cli/commands/generate.mjs index a600d25..7a33c65 100644 --- a/packages/cli/commands/generate.mjs +++ b/packages/cli/commands/generate.mjs @@ -1,22 +1,22 @@ #!/usr/bin/env node -import { consola } from "consola"; -import { defineCommand } from "citty"; +import { consola } from 'consola' +import { defineCommand } from 'citty' function generate() { - consola.box("Generate a McFly building block (In-progress)"); + consola.box('Generate a McFly building block (In-progress)') } export default defineCommand({ meta: { - name: "prepare", - description: "Generates building blocks for a McFly app.", + name: 'prepare', + description: 'Generates building blocks for a McFly app.', }, run() { - generate(); + generate() }, -}); +}) export const exportedForTest = { generate, -}; +} diff --git a/packages/cli/commands/new.mjs b/packages/cli/commands/new.mjs index dec2e95..1da156c 100644 --- a/packages/cli/commands/new.mjs +++ b/packages/cli/commands/new.mjs @@ -1,43 +1,43 @@ #!/usr/bin/env node -import { execSync } from "node:child_process"; -import { consola } from "consola"; -import { defineCommand } from "citty"; +import { execSync } from 'node:child_process' +import { consola } from 'consola' +import { defineCommand } from 'citty' function createNew(args) { - const directory = args.dir || args._dir; - const command = directory - ? `npm create mcfly@latest ${directory}` - : "npm create mcfly@latest"; - try { - execSync(command, { stdio: "inherit" }); - } catch (e) { - consola.error(e); - } + const directory = args.dir || args._dir + const command = directory + ? `npm create mcfly@latest ${directory}` + : 'npm create mcfly@latest' + try { + execSync(command, { stdio: 'inherit' }) + } catch (e) { + consola.error(e) + } } export default defineCommand({ meta: { - name: "prepare", - description: "Creates a new McFly project.", + name: 'prepare', + description: 'Creates a new McFly project.', }, args: { dir: { - type: "string", - description: "project root directory", + type: 'string', + description: 'project root directory', required: false, }, _dir: { - type: "positional", - description: "project root directory (prefer using `--dir`)", + type: 'positional', + description: 'project root directory (prefer using `--dir`)', required: false, }, }, async run({ args }) { createNew(args) }, -}); +}) export const exportedForTest = { - createNew -} \ No newline at end of file + createNew, +} diff --git a/packages/cli/commands/prepare.mjs b/packages/cli/commands/prepare.mjs index bfec23c..7e76180 100755 --- a/packages/cli/commands/prepare.mjs +++ b/packages/cli/commands/prepare.mjs @@ -1,38 +1,38 @@ #!/usr/bin/env node -import { consola } from "consola"; -import { defineCommand } from "citty"; -import { execSync } from "node:child_process"; +import { consola } from 'consola' +import { defineCommand } from 'citty' +import { execSync } from 'node:child_process' function prepare() { - consola.start("Preparing McFly workspace..."); + consola.start('Preparing McFly workspace...') - let err; + let err - try { - execSync("npx nitropack prepare", { stdio: "inherit" }); - } catch (e) { - consola.error(e); - err = e; - } + try { + execSync('npx nitropack prepare', { stdio: 'inherit' }) + } catch (e) { + consola.error(e) + err = e + } - if (err) { - consola.fail( - "McFly workspace preparation failed. Please make sure dependencies are installed.\n" - ); - } else consola.success("Done\n"); + if (err) { + consola.fail( + 'McFly workspace preparation failed. Please make sure dependencies are installed.\n' + ) + } else consola.success('Done\n') } export default defineCommand({ meta: { - name: "prepare", - description: "Prepares the McFly workspace.", + name: 'prepare', + description: 'Prepares the McFly workspace.', }, run() { - prepare(); + prepare() }, -}); +}) export const exportedForTest = { - prepare -} \ No newline at end of file + prepare, +} diff --git a/packages/cli/commands/serve.mjs b/packages/cli/commands/serve.mjs index 53ae310..843e472 100644 --- a/packages/cli/commands/serve.mjs +++ b/packages/cli/commands/serve.mjs @@ -1,46 +1,46 @@ #!/usr/bin/env node -import { consola } from "consola"; -import { colorize } from "consola/utils"; -import { defineCommand } from "citty"; -import { execSync } from "node:child_process"; -import { createRequire } from "node:module"; +import { consola } from 'consola' +import { colorize } from 'consola/utils' +import { defineCommand } from 'citty' +import { execSync } from 'node:child_process' +import { createRequire } from 'node:module' async function printInfo() { try { - const _require = createRequire(import.meta.url); - const mcflyPkg = await _require("@mcflyjs/core/package.json"); - const mcflyPkgVersion = `McFly ${colorize("bold", mcflyPkg.version)}`; - const nitroPkg = await _require("nitropack/package.json"); - const nitroPkgVersion = `Nitro ${nitroPkg.version}`; + const _require = createRequire(import.meta.url) + const mcflyPkg = await _require('@mcflyjs/core/package.json') + const mcflyPkgVersion = `McFly ${colorize('bold', mcflyPkg.version)}` + const nitroPkg = await _require('nitropack/package.json') + const nitroPkgVersion = `Nitro ${nitroPkg.version}` consola.log( - `${colorize("blue", mcflyPkgVersion)} ${colorize("dim", nitroPkgVersion)}` - ); + `${colorize('blue', mcflyPkgVersion)} ${colorize('dim', nitroPkgVersion)}` + ) } catch (e) { - consola.error(e); + consola.error(e) } } function serve() { try { - execSync(`npx nitropack dev`, { stdio: "inherit" }); + execSync(`npx nitropack dev`, { stdio: 'inherit' }) } catch (e) { - consola.error(e); + consola.error(e) } } export default defineCommand({ meta: { - name: "prepare", - description: "Runs the dev server.", + name: 'prepare', + description: 'Runs the dev server.', }, async run() { - await printInfo(); - serve(); + await printInfo() + serve() }, -}); +}) export const exportedForTest = { serve, printInfo, -}; +} diff --git a/packages/cli/index.js b/packages/cli/index.js index fb6b24e..5de7a97 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -1,23 +1,23 @@ #!/usr/bin/env node -import { defineCommand, runMain } from "citty"; +import { defineCommand, runMain } from 'citty' const main = defineCommand({ meta: { - name: "mcfly", - description: "McFly CLI", + name: 'mcfly', + description: 'McFly CLI', }, subCommands: { - new: () => import("./commands/new.mjs").then((r) => r.default), - serve: () => import("./commands/serve.mjs").then((r) => r.default), - build: () => import("./commands/build.mjs").then((r) => r.default), - prepare: () => import("./commands/prepare.mjs").then((r) => r.default), - generate: () => import("./commands/generate.mjs").then((r) => r.default), - g: () => import("./commands/generate.mjs").then((r) => r.default), + new: () => import('./commands/new.mjs').then((r) => r.default), + serve: () => import('./commands/serve.mjs').then((r) => r.default), + build: () => import('./commands/build.mjs').then((r) => r.default), + prepare: () => import('./commands/prepare.mjs').then((r) => r.default), + generate: () => import('./commands/generate.mjs').then((r) => r.default), + g: () => import('./commands/generate.mjs').then((r) => r.default), }, -}); +}) -runMain(main); +runMain(main) export const exportedForTest = { main, -}; +} diff --git a/packages/cli/test/build.test.js b/packages/cli/test/build.test.js index 865ccf7..1357fb7 100644 --- a/packages/cli/test/build.test.js +++ b/packages/cli/test/build.test.js @@ -1,46 +1,46 @@ -import consola from "consola"; -import { vi, expect, test } from "vitest"; -import { exportedForTest } from "../commands/build.mjs"; +import consola from 'consola' +import { vi, expect, test } from 'vitest' +import { exportedForTest } from '../commands/build.mjs' -const testFn = exportedForTest.build; +const testFn = exportedForTest.build const mocks = vi.hoisted(() => { return { execSync: vi.fn(), - }; -}); + } +}) -vi.mock("node:child_process", () => { +vi.mock('node:child_process', () => { return { execSync: mocks.execSync, - }; -}); + } +}) -test("start build with message", () => { - const message = "Building project..."; - const spy = vi.spyOn(consola, "start"); +test('start build with message', () => { + const message = 'Building project...' + const spy = vi.spyOn(consola, 'start') - testFn(); + testFn() - expect(spy).toHaveBeenCalledWith(message); -}); + expect(spy).toHaveBeenCalledWith(message) +}) -test("execute nitropack build", () => { - const command = "npx nitropack build"; - const param = { stdio: "inherit" }; +test('execute nitropack build', () => { + const command = 'npx nitropack build' + const param = { stdio: 'inherit' } - testFn(); + testFn() - expect(mocks.execSync).toHaveBeenCalledWith(command, param); -}); + expect(mocks.execSync).toHaveBeenCalledWith(command, param) +}) -test("catch error", () => { - const spy = vi.spyOn(consola, "error"); +test('catch error', () => { + const spy = vi.spyOn(consola, 'error') mocks.execSync.mockImplementationOnce(() => { - throw new Error("hey"); - }); + throw new Error('hey') + }) - testFn(); + testFn() - expect(spy).toHaveBeenCalledWith(new Error("hey")); -}); + expect(spy).toHaveBeenCalledWith(new Error('hey')) +}) diff --git a/packages/cli/test/generate.test.js b/packages/cli/test/generate.test.js index 501405a..c59455d 100644 --- a/packages/cli/test/generate.test.js +++ b/packages/cli/test/generate.test.js @@ -1,15 +1,15 @@ -import { expect, test, vi } from "vitest"; -import { exportedForTest } from "../commands/generate.mjs"; -import consola from "consola"; +import { expect, test, vi } from 'vitest' +import { exportedForTest } from '../commands/generate.mjs' +import consola from 'consola' -const testFn = exportedForTest.generate; +const testFn = exportedForTest.generate -test("show box message in-progress", () => { - const spy = vi.spyOn(consola, "box"); +test('show box message in-progress', () => { + const spy = vi.spyOn(consola, 'box') - testFn(); - const arg = spy.mock.calls[0][0]; + testFn() + const arg = spy.mock.calls[0][0] - expect(spy).toHaveBeenCalled(); - expect(arg).toContain("In-progress"); -}); + expect(spy).toHaveBeenCalled() + expect(arg).toContain('In-progress') +}) diff --git a/packages/cli/test/index.test.js b/packages/cli/test/index.test.js index 01f84c5..88b3e4c 100644 --- a/packages/cli/test/index.test.js +++ b/packages/cli/test/index.test.js @@ -1,12 +1,12 @@ -import { test } from "vitest"; -import { exportedForTest } from ".."; -import { expect } from "vitest"; +import { test } from 'vitest' +import { exportedForTest } from '..' +import { expect } from 'vitest' -const testObj = exportedForTest.main; +const testObj = exportedForTest.main -test("should have correct subcommands", () => { +test('should have correct subcommands', () => { Object.keys(testObj.subCommands).forEach((key) => { - expect(testObj.subCommands[key]).toBeTypeOf("function"); - expect(testObj.subCommands[key].name).toBe(key); - }); -}); + expect(testObj.subCommands[key]).toBeTypeOf('function') + expect(testObj.subCommands[key].name).toBe(key) + }) +}) diff --git a/packages/cli/test/new.test.js b/packages/cli/test/new.test.js index 3af3f32..97c08e4 100644 --- a/packages/cli/test/new.test.js +++ b/packages/cli/test/new.test.js @@ -1,79 +1,79 @@ -import { expect, test, vi } from "vitest"; -import { exportedForTest } from "../commands/new.mjs"; -import { execSync } from "node:child_process"; -import consola from "consola"; +import { expect, test, vi } from 'vitest' +import { exportedForTest } from '../commands/new.mjs' +import { execSync } from 'node:child_process' +import consola from 'consola' -const testFn = exportedForTest.createNew; -const baseCommand = `npm create mcfly@latest`; +const testFn = exportedForTest.createNew +const baseCommand = `npm create mcfly@latest` const mocks = vi.hoisted(() => { return { execSync: vi.fn(), - }; -}); + } +}) -vi.mock("node:child_process", () => { +vi.mock('node:child_process', () => { return { execSync: mocks.execSync, - }; -}); + } +}) -test("execute create mcfly", () => { - const param = { stdio: "inherit" }; +test('execute create mcfly', () => { + const param = { stdio: 'inherit' } - testFn({ dir: undefined }); + testFn({ dir: undefined }) - expect(execSync).toHaveBeenCalledWith(baseCommand, param); -}); + expect(execSync).toHaveBeenCalledWith(baseCommand, param) +}) -test("execute create mcfly with no dir", () => { - const dir = "fake-dir"; - const command = `${baseCommand} ${dir}`; - const param = { stdio: "inherit" }; +test('execute create mcfly with no dir', () => { + const dir = 'fake-dir' + const command = `${baseCommand} ${dir}` + const param = { stdio: 'inherit' } - testFn({ dir: undefined }); + testFn({ dir: undefined }) - expect(execSync).not.toHaveBeenCalledWith(command, param); -}); + expect(execSync).not.toHaveBeenCalledWith(command, param) +}) -test("execute create mcfly with dir", () => { - const dir = "fake-dir"; - const command = `${baseCommand} ${dir}`; - const param = { stdio: "inherit" }; +test('execute create mcfly with dir', () => { + const dir = 'fake-dir' + const command = `${baseCommand} ${dir}` + const param = { stdio: 'inherit' } - testFn({ dir }); + testFn({ dir }) - expect(execSync).toHaveBeenCalledWith(command, param); -}); + expect(execSync).toHaveBeenCalledWith(command, param) +}) -test("execute create mcfly with _dir", () => { - const dir = "fake-dir"; - const command = `${baseCommand} ${dir}`; - const param = { stdio: "inherit" }; +test('execute create mcfly with _dir', () => { + const dir = 'fake-dir' + const command = `${baseCommand} ${dir}` + const param = { stdio: 'inherit' } - testFn({ _dir: dir }); + testFn({ _dir: dir }) - expect(execSync).toHaveBeenCalledWith(command, param); -}); + expect(execSync).toHaveBeenCalledWith(command, param) +}) -test("execute create mcfly with dir preferred over _dir", () => { - const dir = "preferred-dir"; - const command = `${baseCommand} ${dir}`; - const param = { stdio: "inherit" }; +test('execute create mcfly with dir preferred over _dir', () => { + const dir = 'preferred-dir' + const command = `${baseCommand} ${dir}` + const param = { stdio: 'inherit' } - testFn({ dir: dir, _dir: "not-preferred" }); + testFn({ dir: dir, _dir: 'not-preferred' }) - expect(execSync).toHaveBeenCalledWith(command, param); -}); + expect(execSync).toHaveBeenCalledWith(command, param) +}) -test("catch error", () => { - const dir = "fake-dir"; - const spy = vi.spyOn(consola, "error"); +test('catch error', () => { + const dir = 'fake-dir' + const spy = vi.spyOn(consola, 'error') mocks.execSync.mockImplementationOnce(() => { - throw new Error("hey"); - }); + throw new Error('hey') + }) - testFn({ dir }); + testFn({ dir }) - expect(spy).toHaveBeenCalledWith(new Error("hey")); -}); + expect(spy).toHaveBeenCalledWith(new Error('hey')) +}) diff --git a/packages/cli/test/prepare.test.js b/packages/cli/test/prepare.test.js index 1f95e5f..5fba0a9 100644 --- a/packages/cli/test/prepare.test.js +++ b/packages/cli/test/prepare.test.js @@ -1,50 +1,50 @@ -import { test, expect, vi } from "vitest"; -import { exportedForTest } from "../commands/prepare.mjs"; -import consola from "consola"; -import { execSync } from "node:child_process"; +import { test, expect, vi } from 'vitest' +import { exportedForTest } from '../commands/prepare.mjs' +import consola from 'consola' +import { execSync } from 'node:child_process' -const testFn = exportedForTest.prepare; +const testFn = exportedForTest.prepare const mocks = vi.hoisted(() => { return { execSync: vi.fn(), - }; -}); + } +}) -vi.mock("node:child_process", () => { +vi.mock('node:child_process', () => { return { execSync: mocks.execSync, - }; -}); + } +}) -test("start prepare script", () => { - const spy = vi.spyOn(consola, "start"); +test('start prepare script', () => { + const spy = vi.spyOn(consola, 'start') - testFn(); + testFn() - expect(spy).toHaveBeenCalled(); -}); + expect(spy).toHaveBeenCalled() +}) -test("execute nitropack prepare", () => { - const successSpy = vi.spyOn(consola, "success"); - const command = "npx nitropack prepare"; - const param = { stdio: "inherit" }; +test('execute nitropack prepare', () => { + const successSpy = vi.spyOn(consola, 'success') + const command = 'npx nitropack prepare' + const param = { stdio: 'inherit' } - testFn(); + testFn() - expect(execSync).toHaveBeenCalledWith(command, param); - expect(successSpy).toHaveBeenCalled(); -}); + expect(execSync).toHaveBeenCalledWith(command, param) + expect(successSpy).toHaveBeenCalled() +}) -test("catch error", () => { - const errSpy = vi.spyOn(consola, "error"); - const failSpy = vi.spyOn(consola, "fail"); +test('catch error', () => { + const errSpy = vi.spyOn(consola, 'error') + const failSpy = vi.spyOn(consola, 'fail') mocks.execSync.mockImplementationOnce(() => { - throw new Error(); - }); + throw new Error() + }) - testFn(); + testFn() - expect(errSpy).toHaveBeenCalled(); - expect(failSpy).toHaveBeenCalled(); -}); + expect(errSpy).toHaveBeenCalled() + expect(failSpy).toHaveBeenCalled() +}) diff --git a/packages/cli/test/serve.test.js b/packages/cli/test/serve.test.js index 85ea2ab..8243d20 100644 --- a/packages/cli/test/serve.test.js +++ b/packages/cli/test/serve.test.js @@ -1,83 +1,83 @@ -import { describe, expect, test, vi } from "vitest"; -import { exportedForTest } from "../commands/serve.mjs"; -import consola from "consola"; +import { describe, expect, test, vi } from 'vitest' +import { exportedForTest } from '../commands/serve.mjs' +import consola from 'consola' -describe("FUNCTION: serve()", () => { - const testFn = exportedForTest.serve; +describe('FUNCTION: serve()', () => { + const testFn = exportedForTest.serve const mocks = vi.hoisted(() => { return { execSync: vi.fn(), - }; - }); + } + }) - vi.mock("node:child_process", () => { + vi.mock('node:child_process', () => { return { execSync: mocks.execSync, - }; - }); + } + }) - test("execute nitropack serve", async () => { - const command = `npx nitropack dev`; - const param = { stdio: "inherit" }; + test('execute nitropack serve', async () => { + const command = `npx nitropack dev` + const param = { stdio: 'inherit' } - testFn(); + testFn() - expect(mocks.execSync).toHaveBeenCalledWith(command, param); - }); + expect(mocks.execSync).toHaveBeenCalledWith(command, param) + }) - test("catch error", () => { - const spy = vi.spyOn(consola, "error"); + test('catch error', () => { + const spy = vi.spyOn(consola, 'error') mocks.execSync.mockImplementationOnce(() => { - throw new Error("hey"); - }); + throw new Error('hey') + }) - testFn(); + testFn() - expect(spy).toHaveBeenCalledWith(new Error("hey")); - }); -}); + expect(spy).toHaveBeenCalledWith(new Error('hey')) + }) +}) -describe("FUNCTION: printInfo()", () => { - const testFn = exportedForTest.printInfo; +describe('FUNCTION: printInfo()', () => { + const testFn = exportedForTest.printInfo const createRequireMocks = vi.hoisted(() => { return { createRequire: vi.fn(), - }; - }); + } + }) - vi.mock("node:module", () => { + vi.mock('node:module', () => { return { createRequire: createRequireMocks.createRequire, - }; - }); + } + }) - test("log mcfly and nitro versions", async () => { - const spy = vi.spyOn(consola, "log"); - const fakeMessage = "McFly -1.0.0 Nitro -1.0.0"; + test('log mcfly and nitro versions', async () => { + const spy = vi.spyOn(consola, 'log') + const fakeMessage = 'McFly -1.0.0 Nitro -1.0.0' createRequireMocks.createRequire.mockImplementationOnce(() => { return () => { return { - version: "-1.0.0", - }; - }; - }); + version: '-1.0.0', + } + } + }) - await testFn(); + await testFn() - expect(spy.mock.calls[0][0]).toContain("McFly"); - expect(spy.mock.calls[0][0]).toContain("Nitro"); - expect(spy).toHaveBeenCalledWith(fakeMessage); - }); + expect(spy.mock.calls[0][0]).toContain('McFly') + expect(spy.mock.calls[0][0]).toContain('Nitro') + expect(spy).toHaveBeenCalledWith(fakeMessage) + }) - test("catch error", async () => { + test('catch error', async () => { createRequireMocks.createRequire.mockImplementationOnce(() => { - throw new Error("error"); - }); - const spy = vi.spyOn(consola, "error"); + throw new Error('error') + }) + const spy = vi.spyOn(consola, 'error') - await testFn(); + await testFn() - expect(spy).toHaveBeenCalledWith(new Error("error")); - }); -}); + expect(spy).toHaveBeenCalledWith(new Error('error')) + }) +}) diff --git a/packages/cli/vitest.config.mjs b/packages/cli/vitest.config.mjs index 70a5c45..c9102ec 100644 --- a/packages/cli/vitest.config.mjs +++ b/packages/cli/vitest.config.mjs @@ -1,12 +1,12 @@ -import { coverageConfigDefaults, defineConfig } from "vitest/config"; +import { coverageConfigDefaults, defineConfig } from 'vitest/config' export default defineConfig({ test: { coverage: { enabled: true, - provider: "v8", - reporter: ["html", "text"], - exclude: ["html/**", ...coverageConfigDefaults.exclude], + provider: 'v8', + reporter: ['html', 'text'], + exclude: ['html/**', ...coverageConfigDefaults.exclude], }, }, -}); +}) diff --git a/packages/config/index.js b/packages/config/index.js index 7866d7e..f57c614 100644 --- a/packages/config/index.js +++ b/packages/config/index.js @@ -9,33 +9,33 @@ export default function () { return { framework: { - name: "McFly", + name: 'McFly', }, - compatibilityDate: "2024-12-08", + compatibilityDate: '2024-12-08', devServer: { - watch: ["./src/pages", "./src/components"], + watch: ['./src/pages', './src/components'], }, serverAssets: [ { - baseName: "pages", - dir: "./src/pages", + baseName: 'pages', + dir: './src/pages', }, { - baseName: "components", - dir: "./src/components", + baseName: 'components', + dir: './src/components', }, ], imports: { presets: [ { - from: "web-component-base", - imports: ["WebComponent", "html", "attachEffect"], + from: 'web-component-base', + imports: ['WebComponent', 'html', 'attachEffect'], }, { - from: "@mcflyjs/core", - imports: ["useMcFlyRoute", "defineMcFlyConfig"], + from: '@mcflyjs/core', + imports: ['useMcFlyRoute', 'defineMcFlyConfig'], }, ], }, - }; + } } diff --git a/packages/core/define-config.js b/packages/core/define-config.js index 739d48b..67366dc 100644 --- a/packages/core/define-config.js +++ b/packages/core/define-config.js @@ -10,5 +10,5 @@ * @returns {function(): McFlyConfig} */ export function defineMcFlyConfig(config) { - return () => config; + return () => config } diff --git a/packages/core/event-handler.js b/packages/core/event-handler.js index 5b25bc5..132d54c 100644 --- a/packages/core/event-handler.js +++ b/packages/core/event-handler.js @@ -1,6 +1,6 @@ -import { eventHandler } from "h3"; -import { ELEMENT_NODE, parse, render, renderSync, walkSync } from "ultrahtml"; -import { parseScript } from "esprima"; +import { eventHandler } from 'h3' +import { ELEMENT_NODE, parse, render, renderSync, walkSync } from 'ultrahtml' +import { parseScript } from 'esprima' /** * @typedef {import('./define-config.js').McFlyConfig} Config @@ -21,36 +21,36 @@ import { parseScript } from "esprima"; */ export function useMcFlyRoute({ config, storage }) { return eventHandler(async (event) => { - const { path } = event; - const { components: componentType } = config(); - let html = await getHtml(path, storage); + const { path } = event + const { components: componentType } = config() + let html = await getHtml(path, storage) if (html) { - const transforms = [doSetUp, deleteServerScripts]; + const transforms = [doSetUp, deleteServerScripts] for (const transform of transforms) { - html = transform(html.toString()); + html = transform(html.toString()) } - html = await useFragments(html.toString(), storage); + html = await useFragments(html.toString(), storage) if (!!componentType && !!html) { - html = await insertRegistry(html.toString(), componentType, storage); + html = await insertRegistry(html.toString(), componentType, storage) } } return ( html ?? new Response( - "😱 ERROR 404: Not found. You can put a 404.html on the ./src/pages directory to customize this error page.", + '😱 ERROR 404: Not found. You can put a 404.html on the ./src/pages directory to customize this error page.', { status: 404 } ) - ); - }); + ) + }) } function getPurePath(path) { - return path.split("?")[0]; + return path.split('?')[0] } /** @@ -60,17 +60,17 @@ function getPurePath(path) { * @returns {Promise} */ async function getHtml(path, storage) { - const purePath = getPurePath(path); + const purePath = getPurePath(path) const rawPath = - purePath[purePath.length - 1] === "/" ? purePath.slice(0, -1) : purePath; - const filename = rawPath === "" ? "/index.html" : `${rawPath}.html`; - const fallback = getPath(rawPath + "/index.html"); - const filePath = getPath(filename); - let html = await storage.getItem(filePath); - if (!html) html = await storage.getItem(fallback); - if (!html) html = await storage.getItem(getPath("/404.html")); + purePath[purePath.length - 1] === '/' ? purePath.slice(0, -1) : purePath + const filename = rawPath === '' ? '/index.html' : `${rawPath}.html` + const fallback = getPath(rawPath + '/index.html') + const filePath = getPath(filename) + let html = await storage.getItem(filePath) + if (!html) html = await storage.getItem(fallback) + if (!html) html = await storage.getItem(getPath('/404.html')) - return html; + return html } /** @@ -79,7 +79,7 @@ async function getHtml(path, storage) { * @returns {string} */ function getPath(filename) { - return `assets:pages${filename}`; + return `assets:pages${filename}` } /** @@ -90,21 +90,21 @@ function getPath(filename) { * @returns {Promise} */ async function insertRegistry(html, type, storage) { - const ast = parse(html); - const componentFiles = await getFiles(type, storage); + const ast = parse(html) + const componentFiles = await getFiles(type, storage) const availableComponents = componentFiles.map((key) => - key.replace(`.${type}`, "") - ); + key.replace(`.${type}`, '') + ) - const usedCustomElements = []; + const usedCustomElements = [] walkSync(ast, (node) => { - const usedElement = availableComponents.find((name) => name === node.name); + const usedElement = availableComponents.find((name) => name === node.name) if (node.type === ELEMENT_NODE && !!usedElement) { - usedCustomElements.push(usedElement); + usedCustomElements.push(usedElement) } - }); + }) // insert registry script to head if (usedCustomElements.length > 0) { @@ -112,15 +112,15 @@ async function insertRegistry(html, type, storage) { usedCustomElements, type, storage - ); + ) walkSync(ast, (node) => { - if (node.type === ELEMENT_NODE && node.name === "head") { - node.children.push(parse(registryScript)); + if (node.type === ELEMENT_NODE && node.name === 'head') { + node.children.push(parse(registryScript)) } - }); + }) } - return render(ast); + return render(ast) } /** @@ -131,41 +131,41 @@ async function insertRegistry(html, type, storage) { * @returns {Promise} */ async function buildRegistry(usedCustomElements, type, storage) { - let registryScript = `"; + registryScript += '' - return registryScript; + return registryScript } /** @@ -175,13 +175,13 @@ async function buildRegistry(usedCustomElements, type, storage) { */ function isConstructor(f) { try { - new f(); + new f() // eslint-disable-next-line no-unused-vars } catch (err) { // TODO: verify err is the expected error and then - return false; + return false } - return true; + return true } /** @@ -190,56 +190,56 @@ function isConstructor(f) { * @returns {string} */ function doSetUp(html) { - const ast = parse(html); - const serverScripts = []; + const ast = parse(html) + const serverScripts = [] walkSync(ast, (node) => { - const { attributes } = node; - const attributeKeys = Object.keys(attributes ?? {}); - const isServerScript = attributeKeys.some((key) => key.includes("server:")); + const { attributes } = node + const attributeKeys = Object.keys(attributes ?? {}) + const isServerScript = attributeKeys.some((key) => key.includes('server:')) if ( node.type === ELEMENT_NODE && - node.name === "script" && + node.name === 'script' && isServerScript ) { - const scripts = node.children.map((child) => child.value); - const script = cleanScript(scripts); - serverScripts.push(script); + const scripts = node.children.map((child) => child.value) + const script = cleanScript(scripts) + serverScripts.push(script) } - }); + }) - const setupMap = {}; + const setupMap = {} serverScripts.forEach((script) => { - const { body } = parseScript(script); + const { body } = parseScript(script) const keys = body - .filter((n) => n.type === "VariableDeclaration") - .map((n) => n["declarations"][0].id.name); + .filter((n) => n.type === 'VariableDeclaration') + .map((n) => n['declarations'][0].id.name) const constructor = `(function(){}.constructor)(\`${script}; return {${keys.join( - "," - )}}\`);`; - const evalStore = eval(constructor); - Object.assign(setupMap, new evalStore()); - }); + ',' + )}}\`);` + const evalStore = eval(constructor) + Object.assign(setupMap, new evalStore()) + }) - const regex = /{{(.*?)}}/g; - let match; + const regex = /{{(.*?)}}/g + let match while ((match = regex.exec(html))) { - let [key, value] = match; - value = value.replace(/\s/g, ""); + let [key, value] = match + value = value.replace(/\s/g, '') // nested objects - const keys = value.split("."); - let finalValue = ""; - let setupCopy = setupMap; + const keys = value.split('.') + let finalValue = '' + let setupCopy = setupMap keys.forEach((i) => { - finalValue = setupCopy[i]; - setupCopy = finalValue; - }); + finalValue = setupCopy[i] + setupCopy = finalValue + }) - html = html.replace(key, finalValue); + html = html.replace(key, finalValue) } - return html; + return html } /** @@ -248,17 +248,17 @@ function doSetUp(html) { * @returns {string} */ function deleteServerScripts(html) { - const ast = parse(html); + const ast = parse(html) walkSync(ast, (node) => { - const { attributes } = node; - const attributeKeys = Object.keys(attributes ?? {}); - const isServerScript = attributeKeys.some((key) => key.includes("server:")); + const { attributes } = node + const attributeKeys = Object.keys(attributes ?? {}) + const isServerScript = attributeKeys.some((key) => key.includes('server:')) if (isServerScript && !!node.parent) { - node.parent.children.splice(node.parent.children.indexOf(node), 1); + node.parent.children.splice(node.parent.children.indexOf(node), 1) } - }); + }) - return renderSync(ast); + return renderSync(ast) } /** @@ -267,11 +267,11 @@ function deleteServerScripts(html) { * @returns {string} */ function cleanScript(scripts) { - let script = scripts.map((s) => s.trim()).join(" "); + let script = scripts.map((s) => s.trim()).join(' ') - script = removeComments(script); + script = removeComments(script) - return script.replace(/\n/g, "").replace(/\s+/g, " "); + return script.replace(/\n/g, '').replace(/\s+/g, ' ') } /** @@ -281,11 +281,11 @@ function cleanScript(scripts) { */ function isComment(node) { return ( - node.type === "Line" || - node.type === "Block" || - node.type === "BlockComment" || - node.type === "LineComment" - ); + node.type === 'Line' || + node.type === 'Block' || + node.type === 'BlockComment' || + node.type === 'LineComment' + ) } /** @@ -294,25 +294,25 @@ function isComment(node) { * @returns {string} */ function removeComments(script) { - const entries = []; + const entries = [] parseScript(script, { comment: true }, function (node, meta) { if (isComment(node)) { entries.push({ start: meta.start.offset, end: meta.end.offset, - }); + }) } - }); + }) entries .sort((a, b) => { - return b.end - a.end; + return b.end - a.end }) .forEach((n) => { - script = script.slice(0, n.start) + script.slice(n.end); - }); + script = script.slice(0, n.start) + script.slice(n.end) + }) - return script; + return script } /** @@ -322,44 +322,44 @@ function removeComments(script) { * @returns {Promise} */ async function useFragments(html, storage) { - const fragmentFiles = await getFiles("html", storage); + const fragmentFiles = await getFiles('html', storage) const availableFragments = fragmentFiles.reduce((acc, key) => { return { ...acc, - [key.replace(".html", "")]: "", - }; - }, {}); - const ast = parse(html); + [key.replace('.html', '')]: '', + } + }, {}) + const ast = parse(html) for (const key in availableFragments) { /** * @type string | null */ - let text = await storage.getItem("assets:components:" + key + ".html"); - if (!text) continue; - availableFragments[key] = text.replace(/\n/g, "").replace(/\s+/g, " "); + let text = await storage.getItem('assets:components:' + key + '.html') + if (!text) continue + availableFragments[key] = text.replace(/\n/g, '').replace(/\s+/g, ' ') } walkSync(ast, (node) => { const selector = Object.keys(availableFragments).find( (name) => name === node.name - ); + ) if (node.type === ELEMENT_NODE && !!selector) { - const index = node.parent.children.indexOf(node); + const index = node.parent.children.indexOf(node) /** * @type {HtmlNode} */ - const fragmentNode = parse(availableFragments[selector]); + const fragmentNode = parse(availableFragments[selector]) - replaceSlots(fragmentNode, node); + replaceSlots(fragmentNode, node) - node.parent.children[index] = fragmentNode; + node.parent.children[index] = fragmentNode } - }); + }) - return render(ast); + return render(ast) } /** @@ -369,32 +369,32 @@ async function useFragments(html, storage) { * @returns {void} */ function replaceSlots(fragmentNode, node) { - let slotted = []; - const containsAll = (arr, target) => target.every((v) => arr.includes(v)); + let slotted = [] + const containsAll = (arr, target) => target.every((v) => arr.includes(v)) walkSync(fragmentNode, (n) => { - if (n.type === ELEMENT_NODE && n.name === "slot") { + if (n.type === ELEMENT_NODE && n.name === 'slot') { // find node child with same name attribute - const currentSlotName = n.attributes?.["name"] ?? null; - let nodeChildren = []; + const currentSlotName = n.attributes?.['name'] ?? null + let nodeChildren = [] if (currentSlotName === null) { nodeChildren = node.children.filter( - (child) => !child.attributes?.["slot"] - ); + (child) => !child.attributes?.['slot'] + ) } else { nodeChildren = node.children.filter((child) => { - const childSlotName = child.attributes?.["slot"]; - return childSlotName === currentSlotName; - }); + const childSlotName = child.attributes?.['slot'] + return childSlotName === currentSlotName + }) } if (nodeChildren.length > 0 && !containsAll(slotted, nodeChildren)) { - slotted = [...slotted, ...nodeChildren]; - const index = n.parent.children.indexOf(n); - n.parent.children.splice(index, 1, ...nodeChildren); + slotted = [...slotted, ...nodeChildren] + const index = n.parent.children.indexOf(n) + n.parent.children.splice(index, 1, ...nodeChildren) } } - }); + }) } /** @@ -404,7 +404,7 @@ function replaceSlots(fragmentNode, node) { * @returns {Promise} */ async function getFiles(type, storage) { - return (await storage.getKeys("assets:components")) - .map((key) => key.replace("assets:components:", "")) - .filter((key) => key.includes(type)); + return (await storage.getKeys('assets:components')) + .map((key) => key.replace('assets:components:', '')) + .filter((key) => key.includes(type)) } diff --git a/packages/core/index.js b/packages/core/index.js index b35b024..ba16c8a 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -1,2 +1,2 @@ -export { defineMcFlyConfig } from "./define-config.js"; -export { useMcFlyRoute } from "./event-handler.js"; +export { defineMcFlyConfig } from './define-config.js' +export { useMcFlyRoute } from './event-handler.js' diff --git a/packages/create-mcfly/index.js b/packages/create-mcfly/index.js index 2767a03..3fc4e24 100755 --- a/packages/create-mcfly/index.js +++ b/packages/create-mcfly/index.js @@ -1,12 +1,12 @@ #!/usr/bin/env node -import { consola } from "consola"; -import { colorize } from "consola/utils"; -import { downloadTemplate } from "giget"; -import { spawnSync } from "node:child_process"; -import path from "node:path"; +import { consola } from 'consola' +import { colorize } from 'consola/utils' +import { downloadTemplate } from 'giget' +import { spawnSync } from 'node:child_process' +import path from 'node:path' -const [, , directoryArg] = process.argv; +const [, , directoryArg] = process.argv /** * @typedef {{ @@ -23,25 +23,25 @@ const [, , directoryArg] = process.argv; * Create McFly App */ async function create() { - const defaultDirectory = "mcfly-app"; - consola.box(`Hello! Welcome to ${colorize("bold", "McFly")}!`); - let directory = directoryArg; + const defaultDirectory = 'mcfly-app' + consola.box(`Hello! Welcome to ${colorize('bold', 'McFly')}!`) + let directory = directoryArg if (!directory) { directory = - (await consola.prompt("Give your new project a name:", { + (await consola.prompt('Give your new project a name:', { placeholder: defaultDirectory, - })) ?? defaultDirectory; + })) ?? defaultDirectory } else { - consola.success(`Using ${directory} as name.`); + consola.success(`Using ${directory} as name.`) } - if (typeof directory !== "string") { - return; + if (typeof directory !== 'string') { + return } - directory = getSafeDirectory(directory); - const hasErrors = await downloadTemplateToDirectory(directory); + directory = getSafeDirectory(directory) + const hasErrors = await downloadTemplateToDirectory(directory) if (!hasErrors) { /** @@ -50,33 +50,33 @@ async function create() { const prompts = [ { prompt: `Would you like to install the dependencies to ${colorize( - "bold", + 'bold', directory )}?`, - info: "This might take some time depending on your connectivity.", - startMessage: "Installing dependencies using npm...", + info: 'This might take some time depending on your connectivity.', + startMessage: 'Installing dependencies using npm...', command: `npm`, - subCommand: "install", + subCommand: 'install', error: `Install dependencies later with ${colorize( - "yellow", - "npm install" + 'yellow', + 'npm install' )}`, }, { - prompt: "Would you like to initialize your git repository?", - startMessage: "Initializing git repository...", + prompt: 'Would you like to initialize your git repository?', + startMessage: 'Initializing git repository...', command: `git`, - subCommand: "init", + subCommand: 'init', error: `Initialize git repository later with ${colorize( - "yellow", - "git init" + 'yellow', + 'git init' )}`, }, - ]; + ] - const intentions = await askPrompts(prompts, directory); + const intentions = await askPrompts(prompts, directory) if (!!intentions && intentions.length > 0) - showResults(directory, intentions[0]); + showResults(directory, intentions[0]) } } @@ -86,10 +86,10 @@ async function create() { * @returns string | undefined */ function getSafeDirectory(directory) { - const { platform } = process; - const locale = path[platform === `win32` ? `win32` : `posix`]; - const localePath = directory.split(path.sep).join(locale.sep); - return path.normalize(localePath); + const { platform } = process + const locale = path[platform === `win32` ? `win32` : `posix`] + const localePath = directory.split(path.sep).join(locale.sep) + return path.normalize(localePath) } /** @@ -98,22 +98,22 @@ function getSafeDirectory(directory) { * @returns Promise hasErrors */ async function downloadTemplateToDirectory(directory) { - let hasErrors = false; + let hasErrors = false try { consola.start( - `Copying template to ${colorize("bold", getSafeDirectory(directory))}...` - ); - await downloadTemplate("github:ayoayco/mcfly/templates/basic", { + `Copying template to ${colorize('bold', getSafeDirectory(directory))}...` + ) + await downloadTemplate('github:ayoayco/mcfly/templates/basic', { dir: directory, - }); + }) } catch (ㆆ_ㆆ) { - consola.error(ㆆ_ㆆ.message); - consola.info("Try a different name.\n"); - hasErrors = true; + consola.error(ㆆ_ㆆ.message) + consola.info('Try a different name.\n') + hasErrors = true } - return hasErrors; + return hasErrors } /** @@ -123,37 +123,37 @@ async function downloadTemplateToDirectory(directory) { * @returns Array | undefined */ async function askPrompts(prompts, cwd) { - const results = []; + const results = [] for (const p of prompts) { const userIntends = await consola.prompt(p.prompt, { - type: "confirm", - }); + type: 'confirm', + }) - if (typeof userIntends !== "boolean") { - return; + if (typeof userIntends !== 'boolean') { + return } if (userIntends) { - p.info && consola.info(p.info); - consola.start(p.startMessage); + p.info && consola.info(p.info) + consola.start(p.startMessage) try { spawnSync(p.command, [p.subCommand], { cwd, shell: true, timeout: 100_000, - stdio: "inherit", - }); - consola.success("Done!"); + stdio: 'inherit', + }) + consola.success('Done!') } catch (ㆆ_ㆆ) { - consola.error(ㆆ_ㆆ.message); - consola.info(p.error + "\n"); + consola.error(ㆆ_ㆆ.message) + consola.info(p.error + '\n') } } - results.push(userIntends); + results.push(userIntends) } - return results; + return results } /** @@ -163,28 +163,28 @@ async function askPrompts(prompts, cwd) { */ function showResults(directory, installDeps) { let nextActions = [ - `Go to your project by running ${colorize("yellow", `cd ${directory}`)}`, - ]; + `Go to your project by running ${colorize('yellow', `cd ${directory}`)}`, + ] if (!installDeps) { nextActions.push( - `Install the dependencies with ${colorize("yellow", "npm install")}` - ); + `Install the dependencies with ${colorize('yellow', 'npm install')}` + ) } nextActions = nextActions.concat([ - `Start the dev server with ${colorize("yellow", "npm start")}`, - `Join us at ${colorize("blue", "https://ayco.io/gh/McFly")}`, - ]); + `Start the dev server with ${colorize('yellow', 'npm start')}`, + `Join us at ${colorize('blue', 'https://ayco.io/gh/McFly')}`, + ]) const result = `🎉 Your new ${colorize( - "bold", - "McFly" + 'bold', + 'McFly' )} app is ready: ${directory}\n\nNext actions: ${nextActions .map((action, index) => `\n${++index}. ${action}`) - .join("")}`; + .join('')}` - consola.box(result); + consola.box(result) } -create(); +create() diff --git a/prettier.config.js b/prettier.config.js index bcf2340..dd04dd7 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -5,10 +5,10 @@ * @type {import("prettier").Config} */ const config = { - trailingComma: "es5", + trailingComma: 'es5', tabWidth: 2, semi: false, singleQuote: true, -}; +} -export default config; +export default config diff --git a/site/mcfly.config.mjs b/site/mcfly.config.mjs index 2642ce3..db26040 100644 --- a/site/mcfly.config.mjs +++ b/site/mcfly.config.mjs @@ -1,4 +1,4 @@ -import { defineMcFlyConfig } from "#imports"; +import { defineMcFlyConfig } from '#imports' export default defineMcFlyConfig({ - components: "js", -}); + components: 'js', +}) diff --git a/site/nitro.config.mjs b/site/nitro.config.mjs index 3740aef..dccc0a2 100644 --- a/site/nitro.config.mjs +++ b/site/nitro.config.mjs @@ -1,14 +1,14 @@ export default defineNitroConfig({ - extends: "@mcflyjs/config", + extends: '@mcflyjs/config', devServer: { - watch: ["../packages"], + watch: ['../packages'], }, routeRules: { - "/chat": { + '/chat': { redirect: { - to: "https://matrix.to/#/#mcfly:matrix.org", + to: 'https://matrix.to/#/#mcfly:matrix.org', statusCode: 302, }, }, @@ -19,5 +19,5 @@ export default defineNitroConfig({ brotli: true, }, - compatibilityDate: "2024-12-08", -}); \ No newline at end of file + compatibilityDate: '2024-12-08', +}) diff --git a/site/public/prism.js b/site/public/prism.js index 6adbc13..bc77578 100644 --- a/site/public/prism.js +++ b/site/public/prism.js @@ -1,7 +1,753 @@ /* PrismJS 1.29.0 https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript */ -var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(e){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,t=0,r={},a={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof i?new i(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&").replace(/=g.reach);A+=w.value.length,w=w.next){var E=w.value;if(n.length>e.length)return;if(!(E instanceof i)){var P,L=1;if(y){if(!(P=l(b,A,e,m))||P.index>=e.length)break;var S=P.index,O=P.index+P[0].length,j=A;for(j+=w.value.length;S>=j;)j+=(w=w.next).value.length;if(A=j-=w.value.length,w.value instanceof i)continue;for(var C=w;C!==n.tail&&(jg.reach&&(g.reach=W);var z=w.prev;if(_&&(z=u(n,z,_),A+=_.length),c(n,z,L),w=u(n,z,new i(f,p?a.tokenize(N,p):N,k,N)),M&&u(n,w,M),L>1){var I={cause:f+","+d,reach:W};o(e,n,t,w.prev,A,I),g&&I.reach>g.reach&&(g.reach=I.reach)}}}}}}function s(){var e={value:null,prev:null,next:null},n={value:null,prev:e,next:null};e.next=n,this.head=e,this.tail=n,this.length=0}function u(e,n,t){var r=n.next,a={value:t,prev:n,next:r};return n.next=a,r.prev=a,e.length++,a}function c(e,n,t){for(var r=n.next,a=0;a"+i.content+""},!e.document)return e.addEventListener?(a.disableWorkerMessageHandler||e.addEventListener("message",(function(n){var t=JSON.parse(n.data),r=t.language,i=t.code,l=t.immediateClose;e.postMessage(a.highlight(i,a.languages[r],r)),l&&e.close()}),!1),a):a;var g=a.util.currentScript();function f(){a.manual||a.highlightAll()}if(g&&(a.filename=g.src,g.hasAttribute("data-manual")&&(a.manual=!0)),!a.manual){var h=document.readyState;"loading"===h||"interactive"===h&&g&&g.defer?document.addEventListener("DOMContentLoaded",f):window.requestAnimationFrame?window.requestAnimationFrame(f):window.setTimeout(f,16)}return a}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); -Prism.languages.markup={comment:{pattern://,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern://i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity,Prism.languages.markup.doctype.inside["internal-subset"].inside=Prism.languages.markup,Prism.hooks.add("wrap",(function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))})),Object.defineProperty(Prism.languages.markup.tag,"addInlined",{value:function(a,e){var s={};s["language-"+e]={pattern:/(^$)/i,lookbehind:!0,inside:Prism.languages[e]},s.cdata=/^$/i;var t={"included-cdata":{pattern://i,inside:s}};t["language-"+e]={pattern:/[\s\S]+/,inside:Prism.languages[e]};var n={};n[a]={pattern:RegExp("(<__[^>]*>)(?:))*\\]\\]>|(?!)".replace(/__/g,(function(){return a})),"i"),lookbehind:!0,greedy:!0,inside:t},Prism.languages.insertBefore("markup","cdata",n)}}),Object.defineProperty(Prism.languages.markup.tag,"addAttribute",{value:function(a,e){Prism.languages.markup.tag.inside["special-attr"].push({pattern:RegExp("(^|[\"'\\s])(?:"+a+")\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+(?=[\\s>]))","i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[e,"language-"+e],inside:Prism.languages[e]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup,Prism.languages.xml=Prism.languages.extend("markup",{}),Prism.languages.ssml=Prism.languages.xml,Prism.languages.atom=Prism.languages.xml,Prism.languages.rss=Prism.languages.xml; -!function(s){var e=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;s.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp("@[\\w-](?:[^;{\\s\"']|\\s+(?!\\s)|"+e.source+")*?(?:;|(?=\\s*\\{))"),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+e.source+"|(?:[^\\\\\r\n()\"']|\\\\[^])*)\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+e.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+e.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:e,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},s.languages.css.atrule.inside.rest=s.languages.css;var t=s.languages.markup;t&&(t.tag.addInlined("style","css"),t.tag.addAttribute("style","css"))}(Prism); -Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; -Prism.languages.javascript=Prism.languages.extend("clike",{"class-name":[Prism.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp("(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])"),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:RegExp("((?:^|[^$\\w\\xA0-\\uFFFF.\"'\\])\\s]|\\b(?:return|yield))\\s*)/(?:(?:\\[(?:[^\\]\\\\\r\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|/\\*(?:[^*]|\\*(?!/))*\\*/)*(?:$|[\r\n,.;:})\\]]|//))"),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:Prism.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),Prism.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined("script","javascript"),Prism.languages.markup.tag.addAttribute("on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)","javascript")),Prism.languages.js=Prism.languages.javascript; +var _self = + 'undefined' != typeof window + ? window + : 'undefined' != typeof WorkerGlobalScope && + self instanceof WorkerGlobalScope + ? self + : {}, + Prism = (function (e) { + var n = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i, + t = 0, + r = {}, + a = { + manual: e.Prism && e.Prism.manual, + disableWorkerMessageHandler: + e.Prism && e.Prism.disableWorkerMessageHandler, + util: { + encode: function e(n) { + return n instanceof i + ? new i(n.type, e(n.content), n.alias) + : Array.isArray(n) + ? n.map(e) + : n + .replace(/&/g, '&') + .replace(/= g.reach); + A += w.value.length, w = w.next + ) { + var E = w.value + if (n.length > e.length) return + if (!(E instanceof i)) { + var P, + L = 1 + if (y) { + if (!(P = l(b, A, e, m)) || P.index >= e.length) break + var S = P.index, + O = P.index + P[0].length, + j = A + for (j += w.value.length; S >= j; ) + j += (w = w.next).value.length + if (((A = j -= w.value.length), w.value instanceof i)) + continue + for ( + var C = w; + C !== n.tail && (j < O || 'string' == typeof C.value); + C = C.next + ) + L++, (j += C.value.length) + L--, (E = e.slice(A, j)), (P.index -= A) + } else if (!(P = l(b, 0, E, m))) continue + S = P.index + var N = P[0], + _ = E.slice(0, S), + M = E.slice(S + N.length), + W = A + E.length + g && W > g.reach && (g.reach = W) + var z = w.prev + if ( + (_ && ((z = u(n, z, _)), (A += _.length)), + c(n, z, L), + (w = u(n, z, new i(f, p ? a.tokenize(N, p) : N, k, N))), + M && u(n, w, M), + L > 1) + ) { + var I = { cause: f + ',' + d, reach: W } + o(e, n, t, w.prev, A, I), + g && I.reach > g.reach && (g.reach = I.reach) + } + } + } + } + } + } + function s() { + var e = { value: null, prev: null, next: null }, + n = { value: null, prev: e, next: null } + ;(e.next = n), (this.head = e), (this.tail = n), (this.length = 0) + } + function u(e, n, t) { + var r = n.next, + a = { value: t, prev: n, next: r } + return (n.next = a), (r.prev = a), e.length++, a + } + function c(e, n, t) { + for (var r = n.next, a = 0; a < t && r !== e.tail; a++) r = r.next + ;(n.next = r), (r.prev = n), (e.length -= a) + } + if ( + ((e.Prism = a), + (i.stringify = function e(n, t) { + if ('string' == typeof n) return n + if (Array.isArray(n)) { + var r = '' + return ( + n.forEach(function (n) { + r += e(n, t) + }), + r + ) + } + var i = { + type: n.type, + content: e(n.content, t), + tag: 'span', + classes: ['token', n.type], + attributes: {}, + language: t, + }, + l = n.alias + l && + (Array.isArray(l) + ? Array.prototype.push.apply(i.classes, l) + : i.classes.push(l)), + a.hooks.run('wrap', i) + var o = '' + for (var s in i.attributes) + o += + ' ' + + s + + '="' + + (i.attributes[s] || '').replace(/"/g, '"') + + '"' + return ( + '<' + + i.tag + + ' class="' + + i.classes.join(' ') + + '"' + + o + + '>' + + i.content + + '' + ) + }), + !e.document) + ) + return e.addEventListener + ? (a.disableWorkerMessageHandler || + e.addEventListener( + 'message', + function (n) { + var t = JSON.parse(n.data), + r = t.language, + i = t.code, + l = t.immediateClose + e.postMessage(a.highlight(i, a.languages[r], r)), l && e.close() + }, + !1 + ), + a) + : a + var g = a.util.currentScript() + function f() { + a.manual || a.highlightAll() + } + if ( + (g && + ((a.filename = g.src), + g.hasAttribute('data-manual') && (a.manual = !0)), + !a.manual) + ) { + var h = document.readyState + 'loading' === h || ('interactive' === h && g && g.defer) + ? document.addEventListener('DOMContentLoaded', f) + : window.requestAnimationFrame + ? window.requestAnimationFrame(f) + : window.setTimeout(f, 16) + } + return a + })(_self) +'undefined' != typeof module && module.exports && (module.exports = Prism), + 'undefined' != typeof global && (global.Prism = Prism) +;(Prism.languages.markup = { + comment: { pattern: //, greedy: !0 }, + prolog: { pattern: /<\?[\s\S]+?\?>/, greedy: !0 }, + doctype: { + pattern: + /"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|)*\]\s*)?>/i, + greedy: !0, + inside: { + 'internal-subset': { + pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/, + lookbehind: !0, + greedy: !0, + inside: null, + }, + string: { pattern: /"[^"]*"|'[^']*'/, greedy: !0 }, + punctuation: /^$|[[\]]/, + 'doctype-tag': /^DOCTYPE/i, + name: /[^\s<>'"]+/, + }, + }, + cdata: { pattern: //i, greedy: !0 }, + tag: { + pattern: + /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/, + greedy: !0, + inside: { + tag: { + pattern: /^<\/?[^\s>\/]+/, + inside: { punctuation: /^<\/?/, namespace: /^[^\s>\/:]+:/ }, + }, + 'special-attr': [], + 'attr-value': { + pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/, + inside: { + punctuation: [ + { pattern: /^=/, alias: 'attr-equals' }, + { pattern: /^(\s*)["']|["']$/, lookbehind: !0 }, + ], + }, + }, + punctuation: /\/?>/, + 'attr-name': { + pattern: /[^\s>\/]+/, + inside: { namespace: /^[^\s>\/:]+:/ }, + }, + }, + }, + entity: [ + { pattern: /&[\da-z]{1,8};/i, alias: 'named-entity' }, + /&#x?[\da-f]{1,8};/i, + ], +}), + (Prism.languages.markup.tag.inside['attr-value'].inside.entity = + Prism.languages.markup.entity), + (Prism.languages.markup.doctype.inside['internal-subset'].inside = + Prism.languages.markup), + Prism.hooks.add('wrap', function (a) { + 'entity' === a.type && + (a.attributes.title = a.content.replace(/&/, '&')) + }), + Object.defineProperty(Prism.languages.markup.tag, 'addInlined', { + value: function (a, e) { + var s = {} + ;(s['language-' + e] = { + pattern: /(^$)/i, + lookbehind: !0, + inside: Prism.languages[e], + }), + (s.cdata = /^$/i) + var t = { + 'included-cdata': { pattern: //i, inside: s }, + } + t['language-' + e] = { pattern: /[\s\S]+/, inside: Prism.languages[e] } + var n = {} + ;(n[a] = { + pattern: RegExp( + '(<__[^>]*>)(?:))*\\]\\]>|(?!)'.replace( + /__/g, + function () { + return a + } + ), + 'i' + ), + lookbehind: !0, + greedy: !0, + inside: t, + }), + Prism.languages.insertBefore('markup', 'cdata', n) + }, + }), + Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', { + value: function (a, e) { + Prism.languages.markup.tag.inside['special-attr'].push({ + pattern: RegExp( + '(^|["\'\\s])(?:' + + a + + ')\\s*=\\s*(?:"[^"]*"|\'[^\']*\'|[^\\s\'">=]+(?=[\\s>]))', + 'i' + ), + lookbehind: !0, + inside: { + 'attr-name': /^[^\s=]+/, + 'attr-value': { + pattern: /=[\s\S]+/, + inside: { + value: { + pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/, + lookbehind: !0, + alias: [e, 'language-' + e], + inside: Prism.languages[e], + }, + punctuation: [{ pattern: /^=/, alias: 'attr-equals' }, /"|'/], + }, + }, + }, + }) + }, + }), + (Prism.languages.html = Prism.languages.markup), + (Prism.languages.mathml = Prism.languages.markup), + (Prism.languages.svg = Prism.languages.markup), + (Prism.languages.xml = Prism.languages.extend('markup', {})), + (Prism.languages.ssml = Prism.languages.xml), + (Prism.languages.atom = Prism.languages.xml), + (Prism.languages.rss = Prism.languages.xml) +!(function (s) { + var e = + /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/ + ;(s.languages.css = { + comment: /\/\*[\s\S]*?\*\//, + atrule: { + pattern: RegExp( + '@[\\w-](?:[^;{\\s"\']|\\s+(?!\\s)|' + e.source + ')*?(?:;|(?=\\s*\\{))' + ), + inside: { + rule: /^@[\w-]+/, + 'selector-function-argument': { + pattern: + /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/, + lookbehind: !0, + alias: 'selector', + }, + keyword: { + pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/, + lookbehind: !0, + }, + }, + }, + url: { + pattern: RegExp( + '\\burl\\((?:' + e.source + '|(?:[^\\\\\r\n()"\']|\\\\[^])*)\\)', + 'i' + ), + greedy: !0, + inside: { + function: /^url/i, + punctuation: /^\(|\)$/, + string: { pattern: RegExp('^' + e.source + '$'), alias: 'url' }, + }, + }, + selector: { + pattern: RegExp( + '(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + + e.source + + ')*(?=\\s*\\{)' + ), + lookbehind: !0, + }, + string: { pattern: e, greedy: !0 }, + property: { + pattern: + /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i, + lookbehind: !0, + }, + important: /!important\b/i, + function: { pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i, lookbehind: !0 }, + punctuation: /[(){};:,]/, + }), + (s.languages.css.atrule.inside.rest = s.languages.css) + var t = s.languages.markup + t && (t.tag.addInlined('style', 'css'), t.tag.addAttribute('style', 'css')) +})(Prism) +Prism.languages.clike = { + comment: [ + { pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, lookbehind: !0, greedy: !0 }, + { pattern: /(^|[^\\:])\/\/.*/, lookbehind: !0, greedy: !0 }, + ], + string: { + pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, + greedy: !0, + }, + 'class-name': { + pattern: + /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i, + lookbehind: !0, + inside: { punctuation: /[.\\]/ }, + }, + keyword: + /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/, + boolean: /\b(?:false|true)\b/, + function: /\b\w+(?=\()/, + number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, + operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/, + punctuation: /[{}[\];(),.:]/, +} +;(Prism.languages.javascript = Prism.languages.extend('clike', { + 'class-name': [ + Prism.languages.clike['class-name'], + { + pattern: + /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/, + lookbehind: !0, + }, + ], + keyword: [ + { pattern: /((?:^|\})\s*)catch\b/, lookbehind: !0 }, + { + pattern: + /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/, + lookbehind: !0, + }, + ], + function: + /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/, + number: { + pattern: RegExp( + '(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])' + ), + lookbehind: !0, + }, + operator: + /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/, +})), + (Prism.languages.javascript['class-name'][0].pattern = + /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/), + Prism.languages.insertBefore('javascript', 'keyword', { + regex: { + pattern: RegExp( + '((?:^|[^$\\w\\xA0-\\uFFFF."\'\\])\\s]|\\b(?:return|yield))\\s*)/(?:(?:\\[(?:[^\\]\\\\\r\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|/\\*(?:[^*]|\\*(?!/))*\\*/)*(?:$|[\r\n,.;:})\\]]|//))' + ), + lookbehind: !0, + greedy: !0, + inside: { + 'regex-source': { + pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/, + lookbehind: !0, + alias: 'language-regex', + inside: Prism.languages.regex, + }, + 'regex-delimiter': /^\/|\/$/, + 'regex-flags': /^[a-z]+$/, + }, + }, + 'function-variable': { + pattern: + /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/, + alias: 'function', + }, + parameter: [ + { + pattern: + /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/, + lookbehind: !0, + inside: Prism.languages.javascript, + }, + { + pattern: + /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i, + lookbehind: !0, + inside: Prism.languages.javascript, + }, + { + pattern: + /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/, + lookbehind: !0, + inside: Prism.languages.javascript, + }, + { + pattern: + /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/, + lookbehind: !0, + inside: Prism.languages.javascript, + }, + ], + constant: /\b[A-Z](?:[A-Z_]|\dx?)*\b/, + }), + Prism.languages.insertBefore('javascript', 'string', { + hashbang: { pattern: /^#!.*/, greedy: !0, alias: 'comment' }, + 'template-string': { + pattern: + /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, + greedy: !0, + inside: { + 'template-punctuation': { pattern: /^`|`$/, alias: 'string' }, + interpolation: { + pattern: + /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, + lookbehind: !0, + inside: { + 'interpolation-punctuation': { + pattern: /^\$\{|\}$/, + alias: 'punctuation', + }, + rest: Prism.languages.javascript, + }, + }, + string: /[\s\S]+/, + }, + }, + 'string-property': { + pattern: + /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m, + lookbehind: !0, + greedy: !0, + alias: 'property', + }, + }), + Prism.languages.insertBefore('javascript', 'operator', { + 'literal-property': { + pattern: + /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m, + lookbehind: !0, + alias: 'property', + }, + }), + Prism.languages.markup && + (Prism.languages.markup.tag.addInlined('script', 'javascript'), + Prism.languages.markup.tag.addAttribute( + 'on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)', + 'javascript' + )), + (Prism.languages.js = Prism.languages.javascript) diff --git a/site/routes/[...index].js b/site/routes/[...index].js index 12bc8c6..95042b5 100644 --- a/site/routes/[...index].js +++ b/site/routes/[...index].js @@ -5,5 +5,5 @@ * ...reusable code are in ./src/components * @see https://ayco.io/gh/McFly#special-directories */ -import config from "../mcfly.config.mjs"; -export default useMcFlyRoute({ config, storage: useStorage() }); +import config from '../mcfly.config.mjs' +export default useMcFlyRoute({ config, storage: useStorage() }) diff --git a/site/src/components/clickable-text.js b/site/src/components/clickable-text.js index 566d5c1..5356bd8 100644 --- a/site/src/components/clickable-text.js +++ b/site/src/components/clickable-text.js @@ -4,9 +4,9 @@ */ class ClickableText extends WebComponent { onInit() { - this.onclick = () => alert("Thank you for clicking the text!"); + this.onclick = () => alert('Thank you for clicking the text!') } get template() { - return `Click me too!`; + return `Click me too!` } } diff --git a/site/src/components/code-block.js b/site/src/components/code-block.js index 5c50387..c1a156d 100644 --- a/site/src/components/code-block.js +++ b/site/src/components/code-block.js @@ -1,41 +1,41 @@ class CodeBlockComponent extends HTMLElement { connectedCallback() { - const trimmed = this.innerHTML.trim(); - const lang = this.getAttribute("language"); - const inline = this.getAttribute("inline") !== null; + const trimmed = this.innerHTML.trim() + const lang = this.getAttribute('language') + const inline = this.getAttribute('inline') !== null this.innerHTML = `
${trimmed}
- `; + ` /** * @type {HTMLPreElement} */ - const pre = this.querySelector("#pre"); + const pre = this.querySelector('#pre') if (lang) { - pre.className = `language-${lang}`; + pre.className = `language-${lang}` } /** * @type {Partial} */ const style = { - background: "#f5f2f0", - padding: "1em", - margin: "1em 0", - fontSize: "large", - overflow: "auto", - borderRadius: '5px' - }; + background: '#f5f2f0', + padding: '1em', + margin: '1em 0', + fontSize: 'large', + overflow: 'auto', + borderRadius: '5px', + } if (inline) { - style.display = 'inline'; - style.padding = '0.3em'; + style.display = 'inline' + style.padding = '0.3em' } Object.keys(style).forEach((rule) => { - pre.style[rule] = style[rule]; - }); + pre.style[rule] = style[rule] + }) } } diff --git a/site/src/components/my-hello-world.js b/site/src/components/my-hello-world.js index 5190ca9..d5ec388 100644 --- a/site/src/components/my-hello-world.js +++ b/site/src/components/my-hello-world.js @@ -8,14 +8,16 @@ class HelloWorld extends WebComponent { count: 0, } - updateLabel(){ - this.props.myName = `Clicked ${++this.props.count}x`; + updateLabel() { + this.props.myName = `Clicked ${++this.props.count}x` } - + get template() { - return html` - `; + return html` ` } } diff --git a/site/src/components/vanilla-hello-world.js b/site/src/components/vanilla-hello-world.js index 69f69c3..33d52e1 100644 --- a/site/src/components/vanilla-hello-world.js +++ b/site/src/components/vanilla-hello-world.js @@ -1,22 +1,22 @@ class HelloWorld extends HTMLElement { static get observedAttributes() { - return ["my-name"]; + return ['my-name'] } connectedCallback() { - let count = 0; - const currentName = this.getAttribute('my-name'); + let count = 0 + const currentName = this.getAttribute('my-name') if (!currentName) { this.setAttribute('my-name', 'World') } - this.onclick = () => this.setAttribute("my-name", `Clicked ${++count}x`); + this.onclick = () => this.setAttribute('my-name', `Clicked ${++count}x`) } attributeChangedCallback(property, previousValue, currentValue) { - if (property === "my-name" && previousValue !== currentValue) { - this.innerHTML = ``; + if (property === 'my-name' && previousValue !== currentValue) { + this.innerHTML = `` } } } diff --git a/templates/basic/mcfly.config.mjs b/templates/basic/mcfly.config.mjs index 2642ce3..db26040 100644 --- a/templates/basic/mcfly.config.mjs +++ b/templates/basic/mcfly.config.mjs @@ -1,4 +1,4 @@ -import { defineMcFlyConfig } from "#imports"; +import { defineMcFlyConfig } from '#imports' export default defineMcFlyConfig({ - components: "js", -}); + components: 'js', +}) diff --git a/templates/basic/nitro.config.mjs b/templates/basic/nitro.config.mjs index 82a71b7..2b7028e 100644 --- a/templates/basic/nitro.config.mjs +++ b/templates/basic/nitro.config.mjs @@ -1 +1 @@ -export default defineNitroConfig({ extends: '@mcflyjs/config' }); +export default defineNitroConfig({ extends: '@mcflyjs/config' }) diff --git a/templates/basic/routes/[...index].js b/templates/basic/routes/[...index].js index 12bc8c6..95042b5 100644 --- a/templates/basic/routes/[...index].js +++ b/templates/basic/routes/[...index].js @@ -5,5 +5,5 @@ * ...reusable code are in ./src/components * @see https://ayco.io/gh/McFly#special-directories */ -import config from "../mcfly.config.mjs"; -export default useMcFlyRoute({ config, storage: useStorage() }); +import config from '../mcfly.config.mjs' +export default useMcFlyRoute({ config, storage: useStorage() }) diff --git a/templates/basic/routes/api/user.js b/templates/basic/routes/api/user.js index 73d2695..5063377 100644 --- a/templates/basic/routes/api/user.js +++ b/templates/basic/routes/api/user.js @@ -5,7 +5,7 @@ */ export default eventHandler(() => { return { - user: "AYO", + user: 'AYO', date: new Date(), - }; -}); + } +}) diff --git a/templates/basic/src/components/code-block.js b/templates/basic/src/components/code-block.js index 5c50387..c1a156d 100644 --- a/templates/basic/src/components/code-block.js +++ b/templates/basic/src/components/code-block.js @@ -1,41 +1,41 @@ class CodeBlockComponent extends HTMLElement { connectedCallback() { - const trimmed = this.innerHTML.trim(); - const lang = this.getAttribute("language"); - const inline = this.getAttribute("inline") !== null; + const trimmed = this.innerHTML.trim() + const lang = this.getAttribute('language') + const inline = this.getAttribute('inline') !== null this.innerHTML = `
${trimmed}
- `; + ` /** * @type {HTMLPreElement} */ - const pre = this.querySelector("#pre"); + const pre = this.querySelector('#pre') if (lang) { - pre.className = `language-${lang}`; + pre.className = `language-${lang}` } /** * @type {Partial} */ const style = { - background: "#f5f2f0", - padding: "1em", - margin: "1em 0", - fontSize: "large", - overflow: "auto", - borderRadius: '5px' - }; + background: '#f5f2f0', + padding: '1em', + margin: '1em 0', + fontSize: 'large', + overflow: 'auto', + borderRadius: '5px', + } if (inline) { - style.display = 'inline'; - style.padding = '0.3em'; + style.display = 'inline' + style.padding = '0.3em' } Object.keys(style).forEach((rule) => { - pre.style[rule] = style[rule]; - }); + pre.style[rule] = style[rule] + }) } } diff --git a/templates/basic/src/components/my-hello-world.js b/templates/basic/src/components/my-hello-world.js index c25d168..ac61bca 100644 --- a/templates/basic/src/components/my-hello-world.js +++ b/templates/basic/src/components/my-hello-world.js @@ -5,7 +5,7 @@ class MyHelloWorld extends WebComponent { static props = { myName: 'World', - count: 0 + count: 0, } updateLabel() { @@ -13,9 +13,11 @@ class MyHelloWorld extends WebComponent { } get template() { - return html` - `; + return html` ` } }