@stencil/core 4.43.2 → 5.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/stencil.mjs +2 -0
- package/dist/chunk-ClPoSABd.mjs +21 -0
- package/dist/client-DR9zhmKG.mjs +4449 -0
- package/dist/compiler/index.d.mts +187 -0
- package/dist/compiler/index.mjs +9 -0
- package/dist/compiler/utils/index.d.mts +3 -0
- package/dist/compiler/utils/index.mjs +5 -0
- package/dist/declarations/stencil-public-compiler.d.ts +4401 -0
- package/dist/declarations/stencil-public-compiler.js +53 -0
- package/dist/declarations/stencil-public-runtime.d.ts +1857 -0
- package/dist/index-Bxo2jCf6.d.mts +77 -0
- package/dist/index-szczUd2l.d.mts +6851 -0
- package/{internal/stencil-core/index.d.ts → dist/index.d.mts} +7 -3
- package/dist/index.mjs +4 -0
- package/dist/mock-doc.d.mts +1 -0
- package/dist/mock-doc.mjs +3 -0
- package/dist/node-sys-BGURUNOZ.mjs +1954 -0
- package/{internal → dist/runtime}/app-data/index.d.ts +11 -7
- package/dist/runtime/app-data/index.js +100 -0
- package/dist/runtime/app-globals/index.d.ts +5 -0
- package/dist/runtime/app-globals/index.js +6 -0
- package/dist/runtime/client/index.d.ts +2286 -0
- package/dist/runtime/client/index.js +4839 -0
- package/dist/runtime/index.d.ts +221 -0
- package/dist/runtime/index.js +4819 -0
- package/dist/runtime/server/index.d.mts +1277 -0
- package/dist/runtime/server/index.mjs +5376 -0
- package/dist/runtime/server/runner.d.mts +298 -0
- package/dist/runtime/server/runner.mjs +1976 -0
- package/dist/serialize-BJvhE9aQ.mjs +775 -0
- package/dist/stencil-private-Cgcr414u.d.ts +1893 -0
- package/dist/sys/node/index.d.mts +33 -0
- package/dist/sys/node/index.mjs +7 -0
- package/dist/sys/node/worker.d.mts +1 -0
- package/dist/sys/node/worker.mjs +60 -0
- package/dist/testing/index.d.mts +207 -0
- package/dist/testing/index.mjs +1188 -0
- package/dist/transpile-CJQcQEVa.mjs +21854 -0
- package/dist/validation-BdcPruW_.mjs +1451 -0
- package/package.json +88 -232
- package/bin/stencil +0 -57
- package/cli/config-flags.d.ts +0 -132
- package/cli/index.cjs +0 -5816
- package/cli/index.d.ts +0 -19
- package/cli/index.js +0 -5809
- package/cli/package.json +0 -14
- package/compiler/lib.d.ts +0 -22
- package/compiler/lib.decorators.d.ts +0 -384
- package/compiler/lib.decorators.legacy.d.ts +0 -22
- package/compiler/lib.dom.asynciterable.d.ts +0 -41
- package/compiler/lib.dom.d.ts +0 -29610
- package/compiler/lib.dom.iterable.d.ts +0 -493
- package/compiler/lib.es2015.collection.d.ts +0 -147
- package/compiler/lib.es2015.core.d.ts +0 -597
- package/compiler/lib.es2015.d.ts +0 -28
- package/compiler/lib.es2015.generator.d.ts +0 -77
- package/compiler/lib.es2015.iterable.d.ts +0 -605
- package/compiler/lib.es2015.promise.d.ts +0 -81
- package/compiler/lib.es2015.proxy.d.ts +0 -128
- package/compiler/lib.es2015.reflect.d.ts +0 -144
- package/compiler/lib.es2015.symbol.d.ts +0 -46
- package/compiler/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/compiler/lib.es2016.array.include.d.ts +0 -116
- package/compiler/lib.es2016.d.ts +0 -21
- package/compiler/lib.es2016.full.d.ts +0 -23
- package/compiler/lib.es2016.intl.d.ts +0 -31
- package/compiler/lib.es2017.arraybuffer.d.ts +0 -21
- package/compiler/lib.es2017.d.ts +0 -26
- package/compiler/lib.es2017.date.d.ts +0 -31
- package/compiler/lib.es2017.full.d.ts +0 -23
- package/compiler/lib.es2017.intl.d.ts +0 -44
- package/compiler/lib.es2017.object.d.ts +0 -49
- package/compiler/lib.es2017.sharedmemory.d.ts +0 -135
- package/compiler/lib.es2017.string.d.ts +0 -45
- package/compiler/lib.es2017.typedarrays.d.ts +0 -53
- package/compiler/lib.es2018.asyncgenerator.d.ts +0 -77
- package/compiler/lib.es2018.asynciterable.d.ts +0 -53
- package/compiler/lib.es2018.d.ts +0 -24
- package/compiler/lib.es2018.full.d.ts +0 -24
- package/compiler/lib.es2018.intl.d.ts +0 -83
- package/compiler/lib.es2018.promise.d.ts +0 -30
- package/compiler/lib.es2018.regexp.d.ts +0 -37
- package/compiler/lib.es2019.array.d.ts +0 -79
- package/compiler/lib.es2019.d.ts +0 -24
- package/compiler/lib.es2019.full.d.ts +0 -24
- package/compiler/lib.es2019.intl.d.ts +0 -23
- package/compiler/lib.es2019.object.d.ts +0 -33
- package/compiler/lib.es2019.string.d.ts +0 -37
- package/compiler/lib.es2019.symbol.d.ts +0 -24
- package/compiler/lib.es2020.bigint.d.ts +0 -765
- package/compiler/lib.es2020.d.ts +0 -27
- package/compiler/lib.es2020.date.d.ts +0 -42
- package/compiler/lib.es2020.full.d.ts +0 -24
- package/compiler/lib.es2020.intl.d.ts +0 -474
- package/compiler/lib.es2020.number.d.ts +0 -28
- package/compiler/lib.es2020.promise.d.ts +0 -47
- package/compiler/lib.es2020.sharedmemory.d.ts +0 -99
- package/compiler/lib.es2020.string.d.ts +0 -44
- package/compiler/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/compiler/lib.es2021.d.ts +0 -23
- package/compiler/lib.es2021.full.d.ts +0 -24
- package/compiler/lib.es2021.intl.d.ts +0 -166
- package/compiler/lib.es2021.promise.d.ts +0 -48
- package/compiler/lib.es2021.string.d.ts +0 -33
- package/compiler/lib.es2021.weakref.d.ts +0 -78
- package/compiler/lib.es2022.array.d.ts +0 -121
- package/compiler/lib.es2022.d.ts +0 -25
- package/compiler/lib.es2022.error.d.ts +0 -75
- package/compiler/lib.es2022.full.d.ts +0 -24
- package/compiler/lib.es2022.intl.d.ts +0 -121
- package/compiler/lib.es2022.object.d.ts +0 -26
- package/compiler/lib.es2022.regexp.d.ts +0 -39
- package/compiler/lib.es2022.string.d.ts +0 -25
- package/compiler/lib.es2023.array.d.ts +0 -924
- package/compiler/lib.es2023.collection.d.ts +0 -21
- package/compiler/lib.es2023.d.ts +0 -22
- package/compiler/lib.es2023.full.d.ts +0 -24
- package/compiler/lib.es2023.intl.d.ts +0 -56
- package/compiler/lib.es2024.arraybuffer.d.ts +0 -65
- package/compiler/lib.es2024.collection.d.ts +0 -29
- package/compiler/lib.es2024.d.ts +0 -26
- package/compiler/lib.es2024.full.d.ts +0 -24
- package/compiler/lib.es2024.object.d.ts +0 -29
- package/compiler/lib.es2024.promise.d.ts +0 -35
- package/compiler/lib.es2024.regexp.d.ts +0 -25
- package/compiler/lib.es2024.sharedmemory.d.ts +0 -68
- package/compiler/lib.es2024.string.d.ts +0 -29
- package/compiler/lib.es5.d.ts +0 -4594
- package/compiler/lib.es6.d.ts +0 -23
- package/compiler/lib.esnext.array.d.ts +0 -35
- package/compiler/lib.esnext.collection.d.ts +0 -96
- package/compiler/lib.esnext.d.ts +0 -27
- package/compiler/lib.esnext.decorators.d.ts +0 -28
- package/compiler/lib.esnext.disposable.d.ts +0 -193
- package/compiler/lib.esnext.float16.d.ts +0 -443
- package/compiler/lib.esnext.full.d.ts +0 -24
- package/compiler/lib.esnext.intl.d.ts +0 -21
- package/compiler/lib.esnext.iterator.d.ts +0 -148
- package/compiler/lib.esnext.promise.d.ts +0 -34
- package/compiler/lib.scripthost.d.ts +0 -322
- package/compiler/lib.webworker.asynciterable.d.ts +0 -41
- package/compiler/lib.webworker.d.ts +0 -9894
- package/compiler/lib.webworker.importscripts.d.ts +0 -23
- package/compiler/lib.webworker.iterable.d.ts +0 -287
- package/compiler/package.json +0 -8
- package/compiler/stencil.d.ts +0 -73
- package/compiler/stencil.js +0 -287816
- package/compiler/sys/in-memory-fs.d.ts +0 -227
- package/compiler/transpile.d.ts +0 -32
- package/dev-server/client/app-error.d.ts +0 -20
- package/dev-server/client/events.d.ts +0 -6
- package/dev-server/client/hmr-components.d.ts +0 -12
- package/dev-server/client/hmr-external-styles.d.ts +0 -1
- package/dev-server/client/hmr-images.d.ts +0 -1
- package/dev-server/client/hmr-inline-styles.d.ts +0 -1
- package/dev-server/client/hmr-util.d.ts +0 -39
- package/dev-server/client/hmr-window.d.ts +0 -10
- package/dev-server/client/index.d.ts +0 -6
- package/dev-server/client/index.js +0 -793
- package/dev-server/client/logger.d.ts +0 -6
- package/dev-server/client/package.json +0 -8
- package/dev-server/client/progress.d.ts +0 -3
- package/dev-server/client/status.d.ts +0 -4
- package/dev-server/client/test/hmr-util.spec.d.ts +0 -1
- package/dev-server/client/test/status.spec.d.ts +0 -1
- package/dev-server/connector.html +0 -6
- package/dev-server/index.d.ts +0 -3
- package/dev-server/index.js +0 -247
- package/dev-server/package.json +0 -8
- package/dev-server/server-process.js +0 -12095
- package/dev-server/server-worker-thread.js +0 -39
- package/dev-server/static/favicon.ico +0 -0
- package/dev-server/templates/directory-index.html +0 -176
- package/dev-server/templates/initial-load.html +0 -168
- package/dev-server/visualstudio.vbs +0 -82
- package/dev-server/xdg-open +0 -1066
- package/internal/app-data/index.cjs +0 -119
- package/internal/app-data/index.js +0 -92
- package/internal/app-data/package.json +0 -15
- package/internal/app-globals/index.d.ts +0 -2
- package/internal/app-globals/index.js +0 -14
- package/internal/app-globals/package.json +0 -14
- package/internal/child_process.d.ts +0 -7
- package/internal/client/index.js +0 -4736
- package/internal/client/package.json +0 -10
- package/internal/client/patch-browser.js +0 -45
- package/internal/client/polyfills/core-js.js +0 -11
- package/internal/client/polyfills/dom.js +0 -79
- package/internal/client/polyfills/es5-html-element.js +0 -1
- package/internal/client/polyfills/index.js +0 -34
- package/internal/client/polyfills/system.js +0 -6
- package/internal/client/shadow-css.js +0 -414
- package/internal/hydrate/index.js +0 -6671
- package/internal/hydrate/package.json +0 -7
- package/internal/hydrate/runner.d.ts +0 -287
- package/internal/hydrate/runner.js +0 -17950
- package/internal/index.d.ts +0 -4
- package/internal/index.js +0 -2
- package/internal/package.json +0 -9
- package/internal/stencil-core/index.cjs +0 -1
- package/internal/stencil-core/index.js +0 -18
- package/internal/stencil-core/jsx-dev-runtime.cjs +0 -7
- package/internal/stencil-core/jsx-dev-runtime.d.ts +0 -41
- package/internal/stencil-core/jsx-dev-runtime.js +0 -2
- package/internal/stencil-core/jsx-runtime.cjs +0 -8
- package/internal/stencil-core/jsx-runtime.d.ts +0 -40
- package/internal/stencil-core/jsx-runtime.js +0 -2
- package/internal/stencil-private.d.ts +0 -2549
- package/internal/stencil-public-compiler.d.ts +0 -2867
- package/internal/stencil-public-runtime.d.ts +0 -1860
- package/internal/testing/index.js +0 -6528
- package/internal/testing/jsx-dev-runtime.d.ts +0 -2
- package/internal/testing/jsx-dev-runtime.js +0 -8
- package/internal/testing/jsx-runtime.d.ts +0 -2
- package/internal/testing/jsx-runtime.js +0 -9
- package/internal/testing/package.json +0 -7
- package/internal/utils/index.d.ts +0 -1
- package/internal/utils/result.d.ts +0 -112
- package/mock-doc/index.cjs +0 -10165
- package/mock-doc/index.d.ts +0 -1172
- package/mock-doc/index.js +0 -10144
- package/mock-doc/package.json +0 -15
- package/readme.md +0 -94
- package/screenshot/compare/assets/favicon.ico +0 -0
- package/screenshot/compare/assets/logo.png +0 -0
- package/screenshot/compare/build/app.css +0 -1
- package/screenshot/compare/build/app.esm.js +0 -1
- package/screenshot/compare/build/app.js +0 -33
- package/screenshot/compare/build/p-081b0641.js +0 -1
- package/screenshot/compare/build/p-227a1e18.entry.js +0 -1
- package/screenshot/compare/build/p-2c298727.entry.js +0 -1
- package/screenshot/compare/build/p-5479268c.entry.js +0 -1
- package/screenshot/compare/build/p-573ec8a4.entry.js +0 -1
- package/screenshot/compare/build/p-6ba08604.entry.js +0 -1
- package/screenshot/compare/build/p-6bc63295.entry.js +0 -1
- package/screenshot/compare/build/p-7a3759fd.entry.js +0 -1
- package/screenshot/compare/build/p-7b4e3ba7.js +0 -1
- package/screenshot/compare/build/p-988eb362.css +0 -1
- package/screenshot/compare/build/p-9b6a9315.js +0 -1
- package/screenshot/compare/build/p-b4cc611c.entry.js +0 -1
- package/screenshot/compare/build/p-d1bf53f5.entry.js +0 -1
- package/screenshot/compare/build/p-e2efe0df.js +0 -1
- package/screenshot/compare/build/p-e8ca6d97.entry.js +0 -1
- package/screenshot/compare/build/p-ec2f13e0.entry.js +0 -1
- package/screenshot/compare/build/p-f0b99977.entry.js +0 -1
- package/screenshot/compare/build/p-f4745c2f.entry.js +0 -1
- package/screenshot/compare/build/p-fbbae598.js +0 -1
- package/screenshot/compare/host.config.json +0 -15
- package/screenshot/compare/index.html +0 -1
- package/screenshot/compare/manifest.json +0 -13
- package/screenshot/connector-base.d.ts +0 -42
- package/screenshot/connector-local.d.ts +0 -7
- package/screenshot/connector.js +0 -2
- package/screenshot/index.d.ts +0 -3
- package/screenshot/index.js +0 -2433
- package/screenshot/local-connector.js +0 -2
- package/screenshot/package.json +0 -15
- package/screenshot/pixel-match.d.ts +0 -1
- package/screenshot/pixel-match.js +0 -2315
- package/screenshot/screenshot-compare.d.ts +0 -20
- package/screenshot/screenshot-fs.d.ts +0 -14
- package/sys/node/460.node-fetch.js +0 -451
- package/sys/node/autoprefixer.js +0 -9
- package/sys/node/glob.js +0 -1
- package/sys/node/graceful-fs.js +0 -1
- package/sys/node/index.d.ts +0 -39
- package/sys/node/index.js +0 -64
- package/sys/node/node-fetch.js +0 -12
- package/sys/node/package.json +0 -8
- package/sys/node/prompts.js +0 -1
- package/sys/node/worker.js +0 -4
- package/testing/index.d.ts +0 -9
- package/testing/index.js +0 -13064
- package/testing/jest/jest-27-and-under/jest-config.d.ts +0 -16
- package/testing/jest/jest-27-and-under/jest-environment.d.ts +0 -2
- package/testing/jest/jest-27-and-under/jest-facade.d.ts +0 -155
- package/testing/jest/jest-27-and-under/jest-preprocessor.d.ts +0 -59
- package/testing/jest/jest-27-and-under/jest-preset.d.ts +0 -3
- package/testing/jest/jest-27-and-under/jest-runner.d.ts +0 -11
- package/testing/jest/jest-27-and-under/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-27-and-under/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-27-and-under/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-27-and-under/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-27-and-under/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-27-and-under/matchers/events.d.ts +0 -25
- package/testing/jest/jest-27-and-under/matchers/html.d.ts +0 -13
- package/testing/jest/jest-27-and-under/matchers/index.d.ts +0 -24
- package/testing/jest/jest-27-and-under/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-27-and-under/matchers/text.d.ts +0 -4
- package/testing/jest/jest-27-and-under/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-28/jest-config.d.ts +0 -16
- package/testing/jest/jest-28/jest-environment.d.ts +0 -2
- package/testing/jest/jest-28/jest-facade.d.ts +0 -134
- package/testing/jest/jest-28/jest-preprocessor.d.ts +0 -35
- package/testing/jest/jest-28/jest-preset.d.ts +0 -3
- package/testing/jest/jest-28/jest-runner.d.ts +0 -11
- package/testing/jest/jest-28/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-28/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-28/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-28/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-28/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-28/matchers/events.d.ts +0 -25
- package/testing/jest/jest-28/matchers/html.d.ts +0 -13
- package/testing/jest/jest-28/matchers/index.d.ts +0 -24
- package/testing/jest/jest-28/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-28/matchers/text.d.ts +0 -4
- package/testing/jest/jest-28/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-29/jest-config.d.ts +0 -16
- package/testing/jest/jest-29/jest-environment.d.ts +0 -2
- package/testing/jest/jest-29/jest-facade.d.ts +0 -136
- package/testing/jest/jest-29/jest-preprocessor.d.ts +0 -35
- package/testing/jest/jest-29/jest-preset.d.ts +0 -3
- package/testing/jest/jest-29/jest-runner.d.ts +0 -11
- package/testing/jest/jest-29/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-29/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-29/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-29/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-29/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-29/matchers/events.d.ts +0 -25
- package/testing/jest/jest-29/matchers/html.d.ts +0 -13
- package/testing/jest/jest-29/matchers/index.d.ts +0 -24
- package/testing/jest/jest-29/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-29/matchers/text.d.ts +0 -4
- package/testing/jest/jest-29/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-apis.d.ts +0 -86
- package/testing/jest/jest-facade.d.ts +0 -74
- package/testing/jest/jest-stencil-connector.d.ts +0 -65
- package/testing/jest/test/jest-stencil-connector.spec.d.ts +0 -1
- package/testing/jest-environment.js +0 -3
- package/testing/jest-preprocessor.js +0 -3
- package/testing/jest-preset.js +0 -2
- package/testing/jest-runner.js +0 -3
- package/testing/jest-setuptestframework.js +0 -3
- package/testing/mock-fetch.d.ts +0 -11
- package/testing/mocks.d.ts +0 -56
- package/testing/package.json +0 -8
- package/testing/puppeteer/index.d.ts +0 -2
- package/testing/puppeteer/puppeteer-browser.d.ts +0 -6
- package/testing/puppeteer/puppeteer-declarations.d.ts +0 -414
- package/testing/puppeteer/puppeteer-element.d.ts +0 -67
- package/testing/puppeteer/puppeteer-emulate.d.ts +0 -2
- package/testing/puppeteer/puppeteer-events.d.ts +0 -21
- package/testing/puppeteer/puppeteer-page.d.ts +0 -2
- package/testing/puppeteer/puppeteer-screenshot.d.ts +0 -27
- package/testing/puppeteer/test/puppeteer-screenshot.spec.d.ts +0 -1
- package/testing/reset-build-conditionals.d.ts +0 -12
- package/testing/spec-page.d.ts +0 -7
- package/testing/test/testing-utils.spec.d.ts +0 -1
- package/testing/test-transpile.d.ts +0 -2
- package/testing/testing-logger.d.ts +0 -26
- package/testing/testing-sys.d.ts +0 -6
- package/testing/testing-utils.d.ts +0 -80
- package/testing/testing.d.ts +0 -2
- /package/{internal → dist/declarations}/stencil-ext-modules.d.ts +0 -0
- /package/{internal → dist/declarations}/stencil-public-docs.d.ts +0 -0
- /package/{screenshot/compare/build/index.esm.js → dist/declarations/stencil-public-runtime.js} +0 -0
|
@@ -0,0 +1,1976 @@
|
|
|
1
|
+
import { MockWindow, cloneWindow, constrainTimeouts, patchWindow, serializeNodeToHtml } from "@stencil/mock-doc";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import "minimatch";
|
|
4
|
+
|
|
5
|
+
//#region src/server/runner/create-window.ts
|
|
6
|
+
const templateWindows = /* @__PURE__ */ new Map();
|
|
7
|
+
function createWindowFromHtml(templateHtml, uniqueId) {
|
|
8
|
+
let templateWindow = templateWindows.get(uniqueId);
|
|
9
|
+
if (templateWindow == null) {
|
|
10
|
+
templateWindow = new MockWindow(templateHtml);
|
|
11
|
+
templateWindows.set(uniqueId, templateWindow);
|
|
12
|
+
}
|
|
13
|
+
return cloneWindow(templateWindow);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/server/runner/hydrate-factory.ts
|
|
18
|
+
function hydrateFactory(win, opts, results, afterHydrate, resolve) {}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/app-data/index.ts
|
|
22
|
+
/**
|
|
23
|
+
* A collection of default build flags for a Stencil project.
|
|
24
|
+
*
|
|
25
|
+
* This collection can be found throughout the Stencil codebase, often imported from the `virtual:app-data` module like so:
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { BUILD } from 'virtual:app-data';
|
|
28
|
+
* ```
|
|
29
|
+
* and is used to determine if a portion of the output of a Stencil _project_'s compilation step can be eliminated.
|
|
30
|
+
*
|
|
31
|
+
* e.g. When `BUILD.allRenderFn` evaluates to `false`, the compiler will eliminate conditional statements like:
|
|
32
|
+
* ```ts
|
|
33
|
+
* if (BUILD.allRenderFn) {
|
|
34
|
+
* // some code that will be eliminated if BUILD.allRenderFn is false
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* `virtual:app-data`, the module that `BUILD` is imported from, is an alias for the `@stencil/core/runtime/app-data`, and is
|
|
39
|
+
* partially referenced by {@link STENCIL_APP_DATA_ID}. The `src/compiler/bundle/app-data-plugin.ts` references
|
|
40
|
+
* `STENCIL_APP_DATA_ID` uses it to replace these defaults with {@link BuildConditionals} that are derived from a
|
|
41
|
+
* Stencil project's contents (i.e. metadata from the components). This replacement happens at a Stencil project's
|
|
42
|
+
* compile time. Such code can be found at `src/compiler/app-core/app-data.ts`.
|
|
43
|
+
*/
|
|
44
|
+
const BUILD = {
|
|
45
|
+
allRenderFn: false,
|
|
46
|
+
element: true,
|
|
47
|
+
event: true,
|
|
48
|
+
hasRenderFn: true,
|
|
49
|
+
hostListener: true,
|
|
50
|
+
hostListenerTargetWindow: true,
|
|
51
|
+
hostListenerTargetDocument: true,
|
|
52
|
+
hostListenerTargetBody: true,
|
|
53
|
+
hostListenerTargetParent: false,
|
|
54
|
+
hostListenerTarget: true,
|
|
55
|
+
member: true,
|
|
56
|
+
method: true,
|
|
57
|
+
mode: true,
|
|
58
|
+
observeAttribute: true,
|
|
59
|
+
prop: true,
|
|
60
|
+
propMutable: true,
|
|
61
|
+
reflect: true,
|
|
62
|
+
scoped: true,
|
|
63
|
+
shadowDom: true,
|
|
64
|
+
slot: true,
|
|
65
|
+
cssAnnotations: true,
|
|
66
|
+
state: true,
|
|
67
|
+
style: true,
|
|
68
|
+
formAssociated: false,
|
|
69
|
+
svg: true,
|
|
70
|
+
updatable: true,
|
|
71
|
+
vdomAttribute: true,
|
|
72
|
+
vdomXlink: true,
|
|
73
|
+
vdomClass: true,
|
|
74
|
+
vdomFunctional: true,
|
|
75
|
+
vdomKey: true,
|
|
76
|
+
vdomListener: true,
|
|
77
|
+
vdomRef: true,
|
|
78
|
+
vdomPropOrAttr: true,
|
|
79
|
+
vdomRender: true,
|
|
80
|
+
vdomStyle: true,
|
|
81
|
+
vdomText: true,
|
|
82
|
+
propChangeCallback: true,
|
|
83
|
+
taskQueue: true,
|
|
84
|
+
hotModuleReplacement: false,
|
|
85
|
+
isDebug: false,
|
|
86
|
+
isDev: false,
|
|
87
|
+
isTesting: false,
|
|
88
|
+
hydrateServerSide: false,
|
|
89
|
+
hydrateClientSide: false,
|
|
90
|
+
lifecycleDOMEvents: false,
|
|
91
|
+
lazyLoad: false,
|
|
92
|
+
profile: false,
|
|
93
|
+
slotRelocation: true,
|
|
94
|
+
appendChildSlotFix: false,
|
|
95
|
+
cloneNodeFix: false,
|
|
96
|
+
hydratedAttribute: false,
|
|
97
|
+
hydratedClass: true,
|
|
98
|
+
scopedSlotTextContentFix: false,
|
|
99
|
+
shadowDomShim: false,
|
|
100
|
+
slotChildNodesFix: false,
|
|
101
|
+
invisiblePrehydration: true,
|
|
102
|
+
propBoolean: true,
|
|
103
|
+
propNumber: true,
|
|
104
|
+
propString: true,
|
|
105
|
+
constructableCSS: true,
|
|
106
|
+
devTools: false,
|
|
107
|
+
shadowDelegatesFocus: true,
|
|
108
|
+
shadowSlotAssignmentManual: false,
|
|
109
|
+
initializeNextTick: false,
|
|
110
|
+
asyncLoading: true,
|
|
111
|
+
asyncQueue: false,
|
|
112
|
+
transformTagName: false,
|
|
113
|
+
attachStyles: true,
|
|
114
|
+
experimentalSlotFixes: false
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/client/client-build.ts
|
|
119
|
+
const Build = {
|
|
120
|
+
isDev: BUILD.isDev ? true : false,
|
|
121
|
+
isBrowser: true,
|
|
122
|
+
isServer: false,
|
|
123
|
+
isTesting: BUILD.isTesting ? true : false
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/utils/constants.ts
|
|
128
|
+
const CF_scopedCssEncapsulation = 2;
|
|
129
|
+
const CF_needsShadowDomShim = 8;
|
|
130
|
+
/**
|
|
131
|
+
* A set of flags used for bitwise calculations against {@link ComponentRuntimeMeta#$flags$}.
|
|
132
|
+
*
|
|
133
|
+
* These flags should only be used in conjunction with {@link ComponentRuntimeMeta#$flags$}.
|
|
134
|
+
* They should _not_ be used for calculations against other fields/numbers
|
|
135
|
+
*/
|
|
136
|
+
const CMP_FLAGS = {
|
|
137
|
+
shadowDomEncapsulation: 1,
|
|
138
|
+
scopedCssEncapsulation: CF_scopedCssEncapsulation,
|
|
139
|
+
hasSlotRelocation: 4,
|
|
140
|
+
needsShadowDomShim: CF_needsShadowDomShim,
|
|
141
|
+
shadowDelegatesFocus: 16,
|
|
142
|
+
hasMode: 32,
|
|
143
|
+
needsScopedEncapsulation: CF_scopedCssEncapsulation | CF_needsShadowDomShim,
|
|
144
|
+
formAssociated: 64,
|
|
145
|
+
shadowNeedsScopedCss: 128,
|
|
146
|
+
hasSlot: 256,
|
|
147
|
+
hasModernPropertyDecls: 512,
|
|
148
|
+
shadowSlotAssignmentManual: 1024
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Represents a primitive type.
|
|
152
|
+
* Described in https://w3c.github.io/webdriver-bidi/#type-script-PrimitiveProtocolValue.
|
|
153
|
+
*/
|
|
154
|
+
const PrimitiveType = {
|
|
155
|
+
Undefined: "undefined",
|
|
156
|
+
Null: "null",
|
|
157
|
+
String: "string",
|
|
158
|
+
Number: "number",
|
|
159
|
+
SpecialNumber: "number",
|
|
160
|
+
Boolean: "boolean",
|
|
161
|
+
BigInt: "bigint"
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Represents a non-primitive type.
|
|
165
|
+
* Described in https://w3c.github.io/webdriver-bidi/#type-script-RemoteValue.
|
|
166
|
+
* @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead.
|
|
167
|
+
*/
|
|
168
|
+
const NonPrimitiveType = {
|
|
169
|
+
Array: "array",
|
|
170
|
+
Date: "date",
|
|
171
|
+
Map: "map",
|
|
172
|
+
Object: "object",
|
|
173
|
+
RegularExpression: "regexp",
|
|
174
|
+
Set: "set",
|
|
175
|
+
Channel: "channel",
|
|
176
|
+
Symbol: "symbol"
|
|
177
|
+
};
|
|
178
|
+
/** @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead. */
|
|
179
|
+
const TYPE_CONSTANT = "type";
|
|
180
|
+
/** @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead. */
|
|
181
|
+
const VALUE_CONSTANT = "value";
|
|
182
|
+
/** @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead. */
|
|
183
|
+
const SERIALIZED_PREFIX = "serialized:";
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/client/client-log.ts
|
|
187
|
+
const STENCIL_DEV_MODE = BUILD.isTesting ? ["STENCIL:"] : ["%cstencil", "color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px"];
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/client/client-style.ts
|
|
191
|
+
const modeResolutionChain = [];
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/runtime/runtime-constants.ts
|
|
195
|
+
const PF_appLoaded = 2;
|
|
196
|
+
const PF_queueSync = 4;
|
|
197
|
+
const PLATFORM_FLAGS = {
|
|
198
|
+
isTmpDisconnected: 1,
|
|
199
|
+
appLoaded: PF_appLoaded,
|
|
200
|
+
queueSync: PF_queueSync,
|
|
201
|
+
queueMask: PF_appLoaded | PF_queueSync
|
|
202
|
+
};
|
|
203
|
+
const HYDRATED_STYLE_ID = "sty-id";
|
|
204
|
+
const STENCIL_DOC_DATA = "_stencilDocData";
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/client/client-window.ts
|
|
208
|
+
const win = typeof window !== "undefined" ? window : {};
|
|
209
|
+
const H = win.HTMLElement || class {};
|
|
210
|
+
const supportsShadow = BUILD.shadowDom;
|
|
211
|
+
const supportsConstructableStylesheets = BUILD.constructableCSS ? /* @__PURE__ */ (() => {
|
|
212
|
+
try {
|
|
213
|
+
if (!win.document.adoptedStyleSheets) return false;
|
|
214
|
+
new CSSStyleSheet();
|
|
215
|
+
return typeof new CSSStyleSheet().replaceSync === "function";
|
|
216
|
+
} catch (e) {}
|
|
217
|
+
return false;
|
|
218
|
+
})() : false;
|
|
219
|
+
const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable : false;
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/utils/helpers.ts
|
|
223
|
+
const isString = (v) => typeof v === "string";
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/utils/shadow-css.ts
|
|
227
|
+
const _polyfillHost = "-shadowcsshost";
|
|
228
|
+
const _polyfillSlotted = "-shadowcssslotted";
|
|
229
|
+
const _polyfillHostContext = "-shadowcsscontext";
|
|
230
|
+
const _parenSuffix = ")(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)";
|
|
231
|
+
const _cssColonHostRe = new RegExp("(" + _polyfillHost + _parenSuffix, "gim");
|
|
232
|
+
const _cssColonHostContextRe = new RegExp("(" + _polyfillHostContext + _parenSuffix, "gim");
|
|
233
|
+
const _cssColonSlottedRe = new RegExp("(" + _polyfillSlotted + _parenSuffix, "gim");
|
|
234
|
+
const _polyfillHostNoCombinator = _polyfillHost + "-no-combinator";
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/runtime/mode.ts
|
|
238
|
+
const setMode = (handler) => modeResolutionChain.push(handler);
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/utils/local-value.ts
|
|
242
|
+
/**
|
|
243
|
+
* Represents a local value with a specified type and optional value.
|
|
244
|
+
* Described in https://w3c.github.io/webdriver-bidi/#type-script-LocalValue
|
|
245
|
+
* @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead.
|
|
246
|
+
*/
|
|
247
|
+
var LocalValue = class LocalValue {
|
|
248
|
+
type;
|
|
249
|
+
value;
|
|
250
|
+
constructor(type, value) {
|
|
251
|
+
if (type === PrimitiveType.Undefined || type === PrimitiveType.Null) this.type = type;
|
|
252
|
+
else {
|
|
253
|
+
this.type = type;
|
|
254
|
+
this.value = value;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Creates a new LocalValue object with a string value.
|
|
259
|
+
*
|
|
260
|
+
* @param {string} value - The string value to be stored in the LocalValue object.
|
|
261
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
262
|
+
*/
|
|
263
|
+
static createStringValue(value) {
|
|
264
|
+
return new LocalValue(PrimitiveType.String, value);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Creates a new LocalValue object with a number value.
|
|
268
|
+
*
|
|
269
|
+
* @param {number} value - The number value.
|
|
270
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
271
|
+
*/
|
|
272
|
+
static createNumberValue(value) {
|
|
273
|
+
return new LocalValue(PrimitiveType.Number, value);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Creates a new LocalValue object with a special number value.
|
|
277
|
+
*
|
|
278
|
+
* @param {number} value - The value of the special number.
|
|
279
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
280
|
+
*/
|
|
281
|
+
static createSpecialNumberValue(value) {
|
|
282
|
+
if (Number.isNaN(value)) return new LocalValue(PrimitiveType.SpecialNumber, "NaN");
|
|
283
|
+
if (Object.is(value, -0)) return new LocalValue(PrimitiveType.SpecialNumber, "-0");
|
|
284
|
+
if (value === Infinity) return new LocalValue(PrimitiveType.SpecialNumber, "Infinity");
|
|
285
|
+
if (value === -Infinity) return new LocalValue(PrimitiveType.SpecialNumber, "-Infinity");
|
|
286
|
+
return new LocalValue(PrimitiveType.SpecialNumber, value);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Creates a new LocalValue object with an undefined value.
|
|
290
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
291
|
+
*/
|
|
292
|
+
static createUndefinedValue() {
|
|
293
|
+
return new LocalValue(PrimitiveType.Undefined);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Creates a new LocalValue object with a null value.
|
|
297
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
298
|
+
*/
|
|
299
|
+
static createNullValue() {
|
|
300
|
+
return new LocalValue(PrimitiveType.Null);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Creates a new LocalValue object with a boolean value.
|
|
304
|
+
*
|
|
305
|
+
* @param {boolean} value - The boolean value.
|
|
306
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
307
|
+
*/
|
|
308
|
+
static createBooleanValue(value) {
|
|
309
|
+
return new LocalValue(PrimitiveType.Boolean, value);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Creates a new LocalValue object with a BigInt value.
|
|
313
|
+
*
|
|
314
|
+
* @param {BigInt} value - The BigInt value.
|
|
315
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
316
|
+
*/
|
|
317
|
+
static createBigIntValue(value) {
|
|
318
|
+
return new LocalValue(PrimitiveType.BigInt, value.toString());
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Creates a new LocalValue object with an array.
|
|
322
|
+
*
|
|
323
|
+
* @param {Array} value - The array.
|
|
324
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
325
|
+
*/
|
|
326
|
+
static createArrayValue(value) {
|
|
327
|
+
return new LocalValue(NonPrimitiveType.Array, value);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Creates a new LocalValue object with date value.
|
|
331
|
+
*
|
|
332
|
+
* @param {string} value - The date.
|
|
333
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
334
|
+
*/
|
|
335
|
+
static createDateValue(value) {
|
|
336
|
+
return new LocalValue(NonPrimitiveType.Date, value);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Creates a new LocalValue object of map value.
|
|
340
|
+
* @param {Map} map - The map.
|
|
341
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
342
|
+
*/
|
|
343
|
+
static createMapValue(map) {
|
|
344
|
+
const value = [];
|
|
345
|
+
Array.from(map.entries()).forEach(([key, val]) => {
|
|
346
|
+
value.push([LocalValue.getArgument(key), LocalValue.getArgument(val)]);
|
|
347
|
+
});
|
|
348
|
+
return new LocalValue(NonPrimitiveType.Map, value);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Creates a new LocalValue object from the passed object.
|
|
352
|
+
*
|
|
353
|
+
* @param object the object to create a LocalValue from
|
|
354
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
355
|
+
*/
|
|
356
|
+
static createObjectValue(object) {
|
|
357
|
+
const value = [];
|
|
358
|
+
Object.entries(object).forEach(([key, val]) => {
|
|
359
|
+
value.push([key, LocalValue.getArgument(val)]);
|
|
360
|
+
});
|
|
361
|
+
return new LocalValue(NonPrimitiveType.Object, value);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Creates a new LocalValue object of regular expression value.
|
|
365
|
+
*
|
|
366
|
+
* @param {string} value - The value of the regular expression.
|
|
367
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
368
|
+
*/
|
|
369
|
+
static createRegularExpressionValue(value) {
|
|
370
|
+
return new LocalValue(NonPrimitiveType.RegularExpression, value);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Creates a new LocalValue object with the specified value.
|
|
374
|
+
* @param {Set} value - The value to be set.
|
|
375
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
376
|
+
*/
|
|
377
|
+
static createSetValue(value) {
|
|
378
|
+
return new LocalValue(NonPrimitiveType.Set, value);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Creates a new LocalValue object with the given channel value
|
|
382
|
+
*
|
|
383
|
+
* @param {ChannelValue} value - The channel value.
|
|
384
|
+
* @returns {LocalValue} - The created LocalValue object.
|
|
385
|
+
*/
|
|
386
|
+
static createChannelValue(value) {
|
|
387
|
+
return new LocalValue(NonPrimitiveType.Channel, value);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Creates a new LocalValue object with a Symbol value.
|
|
391
|
+
*
|
|
392
|
+
* @param {Symbol} symbol - The Symbol value
|
|
393
|
+
* @returns {LocalValue} - The created LocalValue object
|
|
394
|
+
*/
|
|
395
|
+
static createSymbolValue(symbol) {
|
|
396
|
+
const description = symbol.description || "Symbol()";
|
|
397
|
+
return new LocalValue(NonPrimitiveType.Symbol, description);
|
|
398
|
+
}
|
|
399
|
+
static getArgument(argument) {
|
|
400
|
+
const type = typeof argument;
|
|
401
|
+
switch (type) {
|
|
402
|
+
case PrimitiveType.String: return LocalValue.createStringValue(argument);
|
|
403
|
+
case PrimitiveType.Number:
|
|
404
|
+
if (Number.isNaN(argument) || Object.is(argument, -0) || !Number.isFinite(argument)) return LocalValue.createSpecialNumberValue(argument);
|
|
405
|
+
return LocalValue.createNumberValue(argument);
|
|
406
|
+
case PrimitiveType.Boolean: return LocalValue.createBooleanValue(argument);
|
|
407
|
+
case PrimitiveType.BigInt: return LocalValue.createBigIntValue(argument);
|
|
408
|
+
case PrimitiveType.Undefined: return LocalValue.createUndefinedValue();
|
|
409
|
+
case NonPrimitiveType.Symbol: return LocalValue.createSymbolValue(argument);
|
|
410
|
+
case NonPrimitiveType.Object:
|
|
411
|
+
if (argument === null) return LocalValue.createNullValue();
|
|
412
|
+
if (argument instanceof Date) return LocalValue.createDateValue(argument);
|
|
413
|
+
if (argument instanceof Map) {
|
|
414
|
+
const map = [];
|
|
415
|
+
argument.forEach((value, key) => {
|
|
416
|
+
const objectKey = typeof key === "string" ? key : LocalValue.getArgument(key);
|
|
417
|
+
const objectValue = LocalValue.getArgument(value);
|
|
418
|
+
map.push([objectKey, objectValue]);
|
|
419
|
+
});
|
|
420
|
+
return LocalValue.createMapValue(argument);
|
|
421
|
+
}
|
|
422
|
+
if (argument instanceof Set) {
|
|
423
|
+
const set = [];
|
|
424
|
+
argument.forEach((value) => {
|
|
425
|
+
set.push(LocalValue.getArgument(value));
|
|
426
|
+
});
|
|
427
|
+
return LocalValue.createSetValue(set);
|
|
428
|
+
}
|
|
429
|
+
if (argument instanceof Array) {
|
|
430
|
+
const arr = [];
|
|
431
|
+
argument.forEach((value) => {
|
|
432
|
+
arr.push(LocalValue.getArgument(value));
|
|
433
|
+
});
|
|
434
|
+
return LocalValue.createArrayValue(arr);
|
|
435
|
+
}
|
|
436
|
+
if (argument instanceof RegExp) return LocalValue.createRegularExpressionValue({
|
|
437
|
+
pattern: argument.source,
|
|
438
|
+
flags: argument.flags
|
|
439
|
+
});
|
|
440
|
+
return LocalValue.createObjectValue(argument);
|
|
441
|
+
}
|
|
442
|
+
throw new Error(`Unsupported type: ${type}`);
|
|
443
|
+
}
|
|
444
|
+
asMap() {
|
|
445
|
+
return {
|
|
446
|
+
[TYPE_CONSTANT]: this.type,
|
|
447
|
+
...!(this.type === PrimitiveType.Null || this.type === PrimitiveType.Undefined) ? { [VALUE_CONSTANT]: this.value } : {}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/utils/remote-value.ts
|
|
454
|
+
/**
|
|
455
|
+
* RemoteValue class for deserializing LocalValue serialized objects back into their original form
|
|
456
|
+
* @deprecated will be removed in v5. Use `@AttrDeserialize()` / `@PropDeserialize()` decorators instead.
|
|
457
|
+
*/
|
|
458
|
+
var RemoteValue = class RemoteValue {
|
|
459
|
+
/**
|
|
460
|
+
* Deserializes a LocalValue serialized object back to its original JavaScript representation
|
|
461
|
+
*
|
|
462
|
+
* @param serialized The serialized LocalValue object
|
|
463
|
+
* @returns The original JavaScript value/object
|
|
464
|
+
*/
|
|
465
|
+
static fromLocalValue(serialized) {
|
|
466
|
+
const type = serialized[TYPE_CONSTANT];
|
|
467
|
+
const value = VALUE_CONSTANT in serialized ? serialized[VALUE_CONSTANT] : void 0;
|
|
468
|
+
switch (type) {
|
|
469
|
+
case PrimitiveType.String: return value;
|
|
470
|
+
case PrimitiveType.Boolean: return value;
|
|
471
|
+
case PrimitiveType.BigInt: return BigInt(value);
|
|
472
|
+
case PrimitiveType.Undefined: return;
|
|
473
|
+
case PrimitiveType.Null: return null;
|
|
474
|
+
case PrimitiveType.Number:
|
|
475
|
+
if (value === "NaN") return NaN;
|
|
476
|
+
if (value === "-0") return -0;
|
|
477
|
+
if (value === "Infinity") return Infinity;
|
|
478
|
+
if (value === "-Infinity") return -Infinity;
|
|
479
|
+
return value;
|
|
480
|
+
case NonPrimitiveType.Array: return value.map((item) => RemoteValue.fromLocalValue(item));
|
|
481
|
+
case NonPrimitiveType.Date: return new Date(value);
|
|
482
|
+
case NonPrimitiveType.Map:
|
|
483
|
+
const map = /* @__PURE__ */ new Map();
|
|
484
|
+
for (const [key, val] of value) {
|
|
485
|
+
const deserializedKey = typeof key === "object" && key !== null ? RemoteValue.fromLocalValue(key) : key;
|
|
486
|
+
const deserializedValue = RemoteValue.fromLocalValue(val);
|
|
487
|
+
map.set(deserializedKey, deserializedValue);
|
|
488
|
+
}
|
|
489
|
+
return map;
|
|
490
|
+
case NonPrimitiveType.Object:
|
|
491
|
+
const obj = {};
|
|
492
|
+
for (const [key, val] of value) obj[key] = RemoteValue.fromLocalValue(val);
|
|
493
|
+
return obj;
|
|
494
|
+
case NonPrimitiveType.RegularExpression:
|
|
495
|
+
const { pattern, flags } = value;
|
|
496
|
+
return new RegExp(pattern, flags);
|
|
497
|
+
case NonPrimitiveType.Set:
|
|
498
|
+
const set = /* @__PURE__ */ new Set();
|
|
499
|
+
for (const item of value) set.add(RemoteValue.fromLocalValue(item));
|
|
500
|
+
return set;
|
|
501
|
+
case NonPrimitiveType.Symbol: return Symbol(value);
|
|
502
|
+
default: throw new Error(`Unsupported type: ${type}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Utility method to deserialize multiple LocalValues at once
|
|
507
|
+
*
|
|
508
|
+
* @param serializedValues Array of serialized LocalValue objects
|
|
509
|
+
* @returns Array of deserialized JavaScript values
|
|
510
|
+
*/
|
|
511
|
+
static fromLocalValueArray(serializedValues) {
|
|
512
|
+
return serializedValues.map((value) => RemoteValue.fromLocalValue(value));
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Verifies if the given object matches the structure of a serialized LocalValue
|
|
516
|
+
*
|
|
517
|
+
* @param obj Object to verify
|
|
518
|
+
* @returns boolean indicating if the object has LocalValue structure
|
|
519
|
+
*/
|
|
520
|
+
static isLocalValueObject(obj) {
|
|
521
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
522
|
+
if (!obj.hasOwnProperty(TYPE_CONSTANT)) return false;
|
|
523
|
+
const type = obj[TYPE_CONSTANT];
|
|
524
|
+
if (!Object.values({
|
|
525
|
+
...PrimitiveType,
|
|
526
|
+
...NonPrimitiveType
|
|
527
|
+
}).includes(type)) return false;
|
|
528
|
+
if (type !== PrimitiveType.Null && type !== PrimitiveType.Undefined) return obj.hasOwnProperty(VALUE_CONSTANT);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/utils/serialize.ts
|
|
535
|
+
/**
|
|
536
|
+
* Serialize a value to a string that can be deserialized later.
|
|
537
|
+
* @param {unknown} value - The value to serialize.
|
|
538
|
+
* @returns {string} A string that can be deserialized later.
|
|
539
|
+
* @deprecated will be removed in v5. Use `@PropSerialize()` decorator instead.
|
|
540
|
+
*/
|
|
541
|
+
function serializeProperty(value) {
|
|
542
|
+
/**
|
|
543
|
+
* If the value is a primitive type, return it as is.
|
|
544
|
+
*/
|
|
545
|
+
if ([
|
|
546
|
+
"string",
|
|
547
|
+
"boolean",
|
|
548
|
+
"undefined"
|
|
549
|
+
].includes(typeof value) || typeof value === "number" && value !== Infinity && value !== -Infinity && !isNaN(value)) return value;
|
|
550
|
+
const arg = LocalValue.getArgument(value);
|
|
551
|
+
return SERIALIZED_PREFIX + btoa(JSON.stringify(arg));
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Deserialize a value from a string that was serialized earlier.
|
|
555
|
+
* @param {string} value - The string to deserialize.
|
|
556
|
+
* @returns {unknown} The deserialized value.
|
|
557
|
+
* @deprecated will be removed in v5. Use `@AttrDeserialize()` decorator instead.
|
|
558
|
+
*/
|
|
559
|
+
function deserializeProperty(value) {
|
|
560
|
+
if (typeof value !== "string" || !value.startsWith(SERIALIZED_PREFIX)) return value;
|
|
561
|
+
return RemoteValue.fromLocalValue(JSON.parse(atob(value.slice(SERIALIZED_PREFIX.length))));
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/runtime/vdom/set-accessor.ts
|
|
566
|
+
const CAPTURE_EVENT_SUFFIX = "Capture";
|
|
567
|
+
const CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + "$");
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/runtime/mixin.ts
|
|
571
|
+
const baseClass = BUILD.lazyLoad ? class {} : globalThis.HTMLElement || class {};
|
|
572
|
+
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/runtime/tag-transform.ts
|
|
575
|
+
let tagTransformer = void 0;
|
|
576
|
+
/**
|
|
577
|
+
* Transforms a tag name using the current tag transformer
|
|
578
|
+
* @param tag - the tag to transform e.g. `my-tag`
|
|
579
|
+
* @returns the transformed tag e.g. `new-my-tag`
|
|
580
|
+
*/
|
|
581
|
+
function transformTag(tag) {
|
|
582
|
+
if (!tagTransformer) return tag;
|
|
583
|
+
return tagTransformer(tag);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Sets the tag transformer to be used when rendering custom elements
|
|
587
|
+
* @param transformer the transformer function to use. Must return a string
|
|
588
|
+
*/
|
|
589
|
+
function setTagTransformer(transformer) {
|
|
590
|
+
if (tagTransformer) console.warn(`
|
|
591
|
+
A tagTransformer has already been set.
|
|
592
|
+
Overwriting it may lead to error and unexpected results if your components have already been defined.
|
|
593
|
+
`);
|
|
594
|
+
tagTransformer = transformer;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/utils/message-utils.ts
|
|
599
|
+
/**
|
|
600
|
+
* Builds a diagnostic from an `Error`, appends it to the `diagnostics` parameter, and returns the created diagnostic
|
|
601
|
+
* @param diagnostics the series of diagnostics the newly created diagnostics should be added to
|
|
602
|
+
* @param err the error to derive information from in generating the diagnostic
|
|
603
|
+
* @param msg an optional message to use in place of `err` to generate the diagnostic
|
|
604
|
+
* @returns the generated diagnostic
|
|
605
|
+
*/
|
|
606
|
+
const catchError = (diagnostics, err, msg) => {
|
|
607
|
+
const diagnostic = {
|
|
608
|
+
level: "error",
|
|
609
|
+
type: "build",
|
|
610
|
+
header: "Build Error",
|
|
611
|
+
messageText: "build error",
|
|
612
|
+
lines: []
|
|
613
|
+
};
|
|
614
|
+
if (isString(msg)) diagnostic.messageText = msg.length ? msg : "UNKNOWN ERROR";
|
|
615
|
+
else if (err != null) if (err.stack != null) diagnostic.messageText = err.stack.toString();
|
|
616
|
+
else if (err.message != null) diagnostic.messageText = err.message.length ? err.message : "UNKNOWN ERROR";
|
|
617
|
+
else diagnostic.messageText = err.toString();
|
|
618
|
+
if (diagnostics != null && !shouldIgnoreError(diagnostic.messageText)) diagnostics.push(diagnostic);
|
|
619
|
+
return diagnostic;
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* Determine if the provided diagnostics have any build errors
|
|
623
|
+
* @param diagnostics the diagnostics to inspect
|
|
624
|
+
* @returns true if any of the diagnostics in the list provided are errors that did not occur at runtime. false
|
|
625
|
+
* otherwise.
|
|
626
|
+
*/
|
|
627
|
+
const hasError = (diagnostics) => {
|
|
628
|
+
if (diagnostics == null || diagnostics.length === 0) return false;
|
|
629
|
+
return diagnostics.some((d) => d.level === "error" && d.type !== "runtime");
|
|
630
|
+
};
|
|
631
|
+
const shouldIgnoreError = (msg) => {
|
|
632
|
+
return msg === TASK_CANCELED_MSG;
|
|
633
|
+
};
|
|
634
|
+
const TASK_CANCELED_MSG = `task canceled`;
|
|
635
|
+
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/utils/util.ts
|
|
638
|
+
/**
|
|
639
|
+
* Create a function that lowercases the first string parameter before passing it to the provided function
|
|
640
|
+
* @param fn the function to pass the lowercased path to
|
|
641
|
+
* @returns the result of the provided function
|
|
642
|
+
*/
|
|
643
|
+
const lowerPathParam = (fn) => (p) => fn(p.toLowerCase());
|
|
644
|
+
/**
|
|
645
|
+
* Determine if a stringified file path is a TypeScript declaration file based on the extension at the end of the path.
|
|
646
|
+
* @param p the path to evaluate
|
|
647
|
+
* @returns `true` if the path ends in `.d.ts` (case-sensitive), `false` otherwise.
|
|
648
|
+
*/
|
|
649
|
+
const isDtsFile = lowerPathParam((p) => p.endsWith(".d.ts") || p.endsWith(".d.mts") || p.endsWith(".d.cts"));
|
|
650
|
+
/**
|
|
651
|
+
* Determine if a stringified file path is a TypeScript file based on the extension at the end of the path. This
|
|
652
|
+
* function does _not_ consider type declaration files (`.d.ts` files) to be TypeScript files.
|
|
653
|
+
* @param p the path to evaluate
|
|
654
|
+
* @returns `true` if the path ends in `.ts` (case-sensitive) but does _not_ end in `.d.ts`, `false` otherwise.
|
|
655
|
+
*/
|
|
656
|
+
const isTsFile = lowerPathParam((p) => !isDtsFile(p) && (p.endsWith(".ts") || p.endsWith(".mts") || p.endsWith(".cts")));
|
|
657
|
+
/**
|
|
658
|
+
* Determine if a stringified file path is a TSX file based on the extension at the end of the path
|
|
659
|
+
* @param p the path to evaluate
|
|
660
|
+
* @returns `true` if the path ends in `.tsx` (case-sensitive), `false` otherwise.
|
|
661
|
+
*/
|
|
662
|
+
const isTsxFile = lowerPathParam((p) => p.endsWith(".tsx") || p.endsWith(".mtsx") || p.endsWith(".ctsx"));
|
|
663
|
+
/**
|
|
664
|
+
* Determine if a stringified file path is a JSX file based on the extension at the end of the path
|
|
665
|
+
* @param p the path to evaluate
|
|
666
|
+
* @returns `true` if the path ends in `.jsx` (case-sensitive), `false` otherwise.
|
|
667
|
+
*/
|
|
668
|
+
const isJsxFile = lowerPathParam((p) => p.endsWith(".jsx") || p.endsWith(".mjsx") || p.endsWith(".cjsx"));
|
|
669
|
+
/**
|
|
670
|
+
* Determine if a stringified file path is a JavaScript file based on the extension at the end of the path
|
|
671
|
+
* @param p the path to evaluate
|
|
672
|
+
* @returns `true` if the path ends in `.js` (case-sensitive), `false` otherwise.
|
|
673
|
+
*/
|
|
674
|
+
const isJsFile = lowerPathParam((p) => p.endsWith(".js") || p.endsWith(".mjs") || p.endsWith(".cjs"));
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region src/compiler/html/canonical-link.ts
|
|
678
|
+
const updateCanonicalLink = (doc, href) => {
|
|
679
|
+
let canonicalLinkElm = doc.head.querySelector("link[rel=\"canonical\"]");
|
|
680
|
+
if (typeof href === "string") {
|
|
681
|
+
if (canonicalLinkElm == null) {
|
|
682
|
+
canonicalLinkElm = doc.createElement("link");
|
|
683
|
+
canonicalLinkElm.setAttribute("rel", "canonical");
|
|
684
|
+
doc.head.appendChild(canonicalLinkElm);
|
|
685
|
+
}
|
|
686
|
+
canonicalLinkElm.setAttribute("href", href);
|
|
687
|
+
} else if (canonicalLinkElm != null) {
|
|
688
|
+
if (!canonicalLinkElm.getAttribute("href")) canonicalLinkElm.parentNode?.removeChild(canonicalLinkElm);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
//#endregion
|
|
693
|
+
//#region src/compiler/html/relocate-meta-charset.ts
|
|
694
|
+
const relocateMetaCharset = (doc) => {
|
|
695
|
+
const head = doc.head;
|
|
696
|
+
let charsetElm = head.querySelector("meta[charset]");
|
|
697
|
+
if (charsetElm == null) {
|
|
698
|
+
charsetElm = doc.createElement("meta");
|
|
699
|
+
charsetElm.setAttribute("charset", "utf-8");
|
|
700
|
+
} else charsetElm.remove();
|
|
701
|
+
head.insertBefore(charsetElm, head.firstChild);
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/compiler/style/css-parser/css-parse-declarations.ts
|
|
706
|
+
let CssNodeType = /* @__PURE__ */ function(CssNodeType) {
|
|
707
|
+
CssNodeType[CssNodeType["Charset"] = 0] = "Charset";
|
|
708
|
+
CssNodeType[CssNodeType["Comment"] = 1] = "Comment";
|
|
709
|
+
CssNodeType[CssNodeType["CustomMedia"] = 2] = "CustomMedia";
|
|
710
|
+
CssNodeType[CssNodeType["Document"] = 3] = "Document";
|
|
711
|
+
CssNodeType[CssNodeType["Declaration"] = 4] = "Declaration";
|
|
712
|
+
CssNodeType[CssNodeType["FontFace"] = 5] = "FontFace";
|
|
713
|
+
CssNodeType[CssNodeType["Host"] = 6] = "Host";
|
|
714
|
+
CssNodeType[CssNodeType["Import"] = 7] = "Import";
|
|
715
|
+
CssNodeType[CssNodeType["KeyFrames"] = 8] = "KeyFrames";
|
|
716
|
+
CssNodeType[CssNodeType["KeyFrame"] = 9] = "KeyFrame";
|
|
717
|
+
CssNodeType[CssNodeType["Media"] = 10] = "Media";
|
|
718
|
+
CssNodeType[CssNodeType["Container"] = 11] = "Container";
|
|
719
|
+
CssNodeType[CssNodeType["Namespace"] = 12] = "Namespace";
|
|
720
|
+
CssNodeType[CssNodeType["Page"] = 13] = "Page";
|
|
721
|
+
CssNodeType[CssNodeType["Rule"] = 14] = "Rule";
|
|
722
|
+
CssNodeType[CssNodeType["StyleSheet"] = 15] = "StyleSheet";
|
|
723
|
+
CssNodeType[CssNodeType["Supports"] = 16] = "Supports";
|
|
724
|
+
return CssNodeType;
|
|
725
|
+
}({});
|
|
726
|
+
|
|
727
|
+
//#endregion
|
|
728
|
+
//#region src/compiler/style/css-parser/parse-css.ts
|
|
729
|
+
/**
|
|
730
|
+
* Parses CSS string input into an AST representation.
|
|
731
|
+
* Used for minification, finding & resolving URLs and during SSR / prerendering, removing unused selectors.
|
|
732
|
+
*
|
|
733
|
+
* @param css The CSS string to parse
|
|
734
|
+
* @param filePath Optional file path for diagnostic reporting
|
|
735
|
+
* @returns The results of the CSS parsing, including the AST and any diagnostics
|
|
736
|
+
*/
|
|
737
|
+
const parseCss = (css, filePath) => {
|
|
738
|
+
let lineno = 1;
|
|
739
|
+
let column = 1;
|
|
740
|
+
const diagnostics = [];
|
|
741
|
+
const updatePosition = (str) => {
|
|
742
|
+
const lines = str.match(/\n/g);
|
|
743
|
+
if (lines) lineno += lines.length;
|
|
744
|
+
const i = str.lastIndexOf("\n");
|
|
745
|
+
column = ~i ? str.length - i : column + str.length;
|
|
746
|
+
};
|
|
747
|
+
const position = () => {
|
|
748
|
+
const start = {
|
|
749
|
+
line: lineno,
|
|
750
|
+
column
|
|
751
|
+
};
|
|
752
|
+
return (node) => {
|
|
753
|
+
node.position = new ParsePosition(start);
|
|
754
|
+
whitespace();
|
|
755
|
+
return node;
|
|
756
|
+
};
|
|
757
|
+
};
|
|
758
|
+
const error = (msg) => {
|
|
759
|
+
const srcLines = css.split("\n");
|
|
760
|
+
const d = {
|
|
761
|
+
level: "error",
|
|
762
|
+
type: "css",
|
|
763
|
+
language: "css",
|
|
764
|
+
header: "CSS Parse",
|
|
765
|
+
messageText: msg,
|
|
766
|
+
absFilePath: filePath,
|
|
767
|
+
lines: [{
|
|
768
|
+
lineIndex: lineno - 1,
|
|
769
|
+
lineNumber: lineno,
|
|
770
|
+
errorCharStart: column,
|
|
771
|
+
text: css[lineno - 1]
|
|
772
|
+
}]
|
|
773
|
+
};
|
|
774
|
+
if (lineno > 1) {
|
|
775
|
+
const previousLine = {
|
|
776
|
+
lineIndex: lineno - 1,
|
|
777
|
+
lineNumber: lineno - 1,
|
|
778
|
+
text: css[lineno - 2],
|
|
779
|
+
errorCharStart: -1,
|
|
780
|
+
errorLength: -1
|
|
781
|
+
};
|
|
782
|
+
d.lines.unshift(previousLine);
|
|
783
|
+
}
|
|
784
|
+
if (lineno + 2 < srcLines.length) {
|
|
785
|
+
const nextLine = {
|
|
786
|
+
lineIndex: lineno,
|
|
787
|
+
lineNumber: lineno + 1,
|
|
788
|
+
text: srcLines[lineno],
|
|
789
|
+
errorCharStart: -1,
|
|
790
|
+
errorLength: -1
|
|
791
|
+
};
|
|
792
|
+
d.lines.push(nextLine);
|
|
793
|
+
}
|
|
794
|
+
diagnostics.push(d);
|
|
795
|
+
return null;
|
|
796
|
+
};
|
|
797
|
+
const stylesheet = () => {
|
|
798
|
+
const rulesList = rules();
|
|
799
|
+
return {
|
|
800
|
+
type: CssNodeType.StyleSheet,
|
|
801
|
+
stylesheet: {
|
|
802
|
+
source: filePath,
|
|
803
|
+
rules: rulesList
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
};
|
|
807
|
+
const open = () => match(/^{\s*/);
|
|
808
|
+
const close = () => match(/^}/);
|
|
809
|
+
const match = (re) => {
|
|
810
|
+
const m = re.exec(css);
|
|
811
|
+
if (!m) return;
|
|
812
|
+
const str = m[0];
|
|
813
|
+
updatePosition(str);
|
|
814
|
+
css = css.slice(str.length);
|
|
815
|
+
return m;
|
|
816
|
+
};
|
|
817
|
+
const rules = () => {
|
|
818
|
+
let node;
|
|
819
|
+
const rules = [];
|
|
820
|
+
whitespace();
|
|
821
|
+
comments(rules);
|
|
822
|
+
while (css.length && css.charAt(0) !== "}" && (node = atrule() || rule())) {
|
|
823
|
+
rules.push(node);
|
|
824
|
+
comments(rules);
|
|
825
|
+
}
|
|
826
|
+
return rules;
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Parse whitespace.
|
|
830
|
+
*/
|
|
831
|
+
const whitespace = () => match(/^\s*/);
|
|
832
|
+
const comments = (rules) => {
|
|
833
|
+
let c;
|
|
834
|
+
rules = rules || [];
|
|
835
|
+
while (c = comment()) rules.push(c);
|
|
836
|
+
return rules;
|
|
837
|
+
};
|
|
838
|
+
const comment = () => {
|
|
839
|
+
const pos = position();
|
|
840
|
+
if ("/" !== css.charAt(0) || "*" !== css.charAt(1)) return null;
|
|
841
|
+
let i = 2;
|
|
842
|
+
while ("" !== css.charAt(i) && ("*" !== css.charAt(i) || "/" !== css.charAt(i + 1))) ++i;
|
|
843
|
+
i += 2;
|
|
844
|
+
if ("" === css.charAt(i - 1)) return error("End of comment missing");
|
|
845
|
+
const comment = css.slice(2, i - 2);
|
|
846
|
+
column += 2;
|
|
847
|
+
updatePosition(comment);
|
|
848
|
+
css = css.slice(i);
|
|
849
|
+
column += 2;
|
|
850
|
+
return pos({
|
|
851
|
+
type: CssNodeType.Comment,
|
|
852
|
+
comment
|
|
853
|
+
});
|
|
854
|
+
};
|
|
855
|
+
const selector = () => {
|
|
856
|
+
const m = match(/^([^{]+)/);
|
|
857
|
+
if (!m) return null;
|
|
858
|
+
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, "").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
|
|
859
|
+
return m.replace(/,/g, "");
|
|
860
|
+
}).split(/\s*(?![^(]*\)),\s*/).map(function(s) {
|
|
861
|
+
return s.replace(/\u200C/g, ",");
|
|
862
|
+
});
|
|
863
|
+
};
|
|
864
|
+
const declaration = () => {
|
|
865
|
+
const pos = position();
|
|
866
|
+
let prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
|
|
867
|
+
if (!prop) return null;
|
|
868
|
+
prop = trim(prop[0]);
|
|
869
|
+
if (!match(/^:\s*/)) return error(`property missing ':'`);
|
|
870
|
+
const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
|
|
871
|
+
const ret = pos({
|
|
872
|
+
type: CssNodeType.Declaration,
|
|
873
|
+
property: prop.replace(commentre, ""),
|
|
874
|
+
value: val ? trim(val[0]).replace(commentre, "") : ""
|
|
875
|
+
});
|
|
876
|
+
match(/^[;\s]*/);
|
|
877
|
+
return ret;
|
|
878
|
+
};
|
|
879
|
+
const declarations = () => {
|
|
880
|
+
const decls = [];
|
|
881
|
+
if (!open()) return error(`missing '{'`);
|
|
882
|
+
comments(decls);
|
|
883
|
+
let decl;
|
|
884
|
+
while (decl = declaration()) {
|
|
885
|
+
decls.push(decl);
|
|
886
|
+
comments(decls);
|
|
887
|
+
}
|
|
888
|
+
if (!close()) return error(`missing '}'`);
|
|
889
|
+
return decls;
|
|
890
|
+
};
|
|
891
|
+
const keyframe = () => {
|
|
892
|
+
let m;
|
|
893
|
+
const values = [];
|
|
894
|
+
const pos = position();
|
|
895
|
+
while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
|
|
896
|
+
values.push(m[1]);
|
|
897
|
+
match(/^,\s*/);
|
|
898
|
+
}
|
|
899
|
+
if (!values.length) return null;
|
|
900
|
+
return pos({
|
|
901
|
+
type: CssNodeType.KeyFrame,
|
|
902
|
+
values,
|
|
903
|
+
declarations: declarations()
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
const atkeyframes = () => {
|
|
907
|
+
const pos = position();
|
|
908
|
+
let m = match(/^@([-\w]+)?keyframes\s*/);
|
|
909
|
+
if (!m) return null;
|
|
910
|
+
const vendor = m[1];
|
|
911
|
+
m = match(/^([-\w]+)\s*/);
|
|
912
|
+
if (!m) return error(`@keyframes missing name`);
|
|
913
|
+
const name = m[1];
|
|
914
|
+
if (!open()) return error(`@keyframes missing '{'`);
|
|
915
|
+
let frame;
|
|
916
|
+
let frames = comments();
|
|
917
|
+
while (frame = keyframe()) {
|
|
918
|
+
frames.push(frame);
|
|
919
|
+
frames = frames.concat(comments());
|
|
920
|
+
}
|
|
921
|
+
if (!close()) return error(`@keyframes missing '}'`);
|
|
922
|
+
return pos({
|
|
923
|
+
type: CssNodeType.KeyFrames,
|
|
924
|
+
name,
|
|
925
|
+
vendor,
|
|
926
|
+
keyframes: frames
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
const atsupports = () => {
|
|
930
|
+
const pos = position();
|
|
931
|
+
const m = match(/^@supports *([^{]+)/);
|
|
932
|
+
if (!m) return null;
|
|
933
|
+
const supports = trim(m[1]);
|
|
934
|
+
if (!open()) return error(`@supports missing '{'`);
|
|
935
|
+
const style = comments().concat(rules());
|
|
936
|
+
if (!close()) return error(`@supports missing '}'`);
|
|
937
|
+
return pos({
|
|
938
|
+
type: CssNodeType.Supports,
|
|
939
|
+
supports,
|
|
940
|
+
rules: style
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
const athost = () => {
|
|
944
|
+
const pos = position();
|
|
945
|
+
if (!match(/^@host\s*/)) return null;
|
|
946
|
+
if (!open()) return error(`@host missing '{'`);
|
|
947
|
+
const style = comments().concat(rules());
|
|
948
|
+
if (!close()) return error(`@host missing '}'`);
|
|
949
|
+
return pos({
|
|
950
|
+
type: CssNodeType.Host,
|
|
951
|
+
rules: style
|
|
952
|
+
});
|
|
953
|
+
};
|
|
954
|
+
const atquery = (name) => {
|
|
955
|
+
const pos = position();
|
|
956
|
+
const m = match(new RegExp("^@" + name + " *([^{]+)"));
|
|
957
|
+
if (!m) return null;
|
|
958
|
+
const media = trim(m[1]);
|
|
959
|
+
if (!open()) return error(`@${name} missing '{'`);
|
|
960
|
+
const style = comments().concat(rules());
|
|
961
|
+
if (!close()) return error(`@${name} missing '}'`);
|
|
962
|
+
return pos({
|
|
963
|
+
type: name === "media" ? CssNodeType.Media : CssNodeType.Container,
|
|
964
|
+
media,
|
|
965
|
+
rules: style
|
|
966
|
+
});
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* Parse nested @ rule that contains declarations instead of rules
|
|
970
|
+
*/
|
|
971
|
+
const nestedAtQuery = (name) => {
|
|
972
|
+
const pos = position();
|
|
973
|
+
const m = match(new RegExp("^@" + name + " *([^{]+)"));
|
|
974
|
+
if (!m) return null;
|
|
975
|
+
const media = trim(m[1]);
|
|
976
|
+
const decls = declarations();
|
|
977
|
+
if (!decls) return null;
|
|
978
|
+
return pos({
|
|
979
|
+
type: name === "media" ? CssNodeType.Media : name === "container" ? CssNodeType.Container : CssNodeType.Supports,
|
|
980
|
+
media,
|
|
981
|
+
declarations: decls
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* Try to parse a nested at-rule (one that contains declarations, not rules)
|
|
986
|
+
*/
|
|
987
|
+
const nestedAtrule = () => {
|
|
988
|
+
if (css[0] !== "@") return null;
|
|
989
|
+
return nestedAtQuery("media") || nestedAtQuery("supports") || nestedAtQuery("container");
|
|
990
|
+
};
|
|
991
|
+
const atcustommedia = () => {
|
|
992
|
+
const pos = position();
|
|
993
|
+
const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
|
|
994
|
+
if (!m) return null;
|
|
995
|
+
return pos({
|
|
996
|
+
type: CssNodeType.CustomMedia,
|
|
997
|
+
name: trim(m[1]),
|
|
998
|
+
media: trim(m[2])
|
|
999
|
+
});
|
|
1000
|
+
};
|
|
1001
|
+
const atpage = () => {
|
|
1002
|
+
const pos = position();
|
|
1003
|
+
if (!match(/^@page */)) return null;
|
|
1004
|
+
const sel = selector() || [];
|
|
1005
|
+
if (!open()) return error(`@page missing '{'`);
|
|
1006
|
+
let decls = comments();
|
|
1007
|
+
let decl;
|
|
1008
|
+
while (decl = declaration()) {
|
|
1009
|
+
decls.push(decl);
|
|
1010
|
+
decls = decls.concat(comments());
|
|
1011
|
+
}
|
|
1012
|
+
if (!close()) return error(`@page missing '}'`);
|
|
1013
|
+
return pos({
|
|
1014
|
+
type: CssNodeType.Page,
|
|
1015
|
+
selectors: sel,
|
|
1016
|
+
declarations: decls
|
|
1017
|
+
});
|
|
1018
|
+
};
|
|
1019
|
+
const atdocument = () => {
|
|
1020
|
+
const pos = position();
|
|
1021
|
+
const m = match(/^@([-\w]+)?document *([^{]+)/);
|
|
1022
|
+
if (!m) return null;
|
|
1023
|
+
const vendor = trim(m[1]);
|
|
1024
|
+
const doc = trim(m[2]);
|
|
1025
|
+
if (!open()) return error(`@document missing '{'`);
|
|
1026
|
+
const style = comments().concat(rules());
|
|
1027
|
+
if (!close()) return error(`@document missing '}'`);
|
|
1028
|
+
return pos({
|
|
1029
|
+
type: CssNodeType.Document,
|
|
1030
|
+
document: doc,
|
|
1031
|
+
vendor,
|
|
1032
|
+
rules: style
|
|
1033
|
+
});
|
|
1034
|
+
};
|
|
1035
|
+
const atfontface = () => {
|
|
1036
|
+
const pos = position();
|
|
1037
|
+
if (!match(/^@font-face\s*/)) return null;
|
|
1038
|
+
if (!open()) return error(`@font-face missing '{'`);
|
|
1039
|
+
let decls = comments();
|
|
1040
|
+
let decl;
|
|
1041
|
+
while (decl = declaration()) {
|
|
1042
|
+
decls.push(decl);
|
|
1043
|
+
decls = decls.concat(comments());
|
|
1044
|
+
}
|
|
1045
|
+
if (!close()) return error(`@font-face missing '}'`);
|
|
1046
|
+
return pos({
|
|
1047
|
+
type: CssNodeType.FontFace,
|
|
1048
|
+
declarations: decls
|
|
1049
|
+
});
|
|
1050
|
+
};
|
|
1051
|
+
const compileAtrule = (nodeName, nodeType) => {
|
|
1052
|
+
const re = new RegExp("^@" + nodeName + "\\s*([^;]+);");
|
|
1053
|
+
return () => {
|
|
1054
|
+
const pos = position();
|
|
1055
|
+
const m = match(re);
|
|
1056
|
+
if (!m) return null;
|
|
1057
|
+
const node = { type: nodeType };
|
|
1058
|
+
node[nodeName] = m[1].trim();
|
|
1059
|
+
return pos(node);
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
const atimport = compileAtrule("import", CssNodeType.Import);
|
|
1063
|
+
const atcharset = compileAtrule("charset", CssNodeType.Charset);
|
|
1064
|
+
const atnamespace = compileAtrule("namespace", CssNodeType.Namespace);
|
|
1065
|
+
const atrule = () => {
|
|
1066
|
+
if (css[0] !== "@") return null;
|
|
1067
|
+
return atkeyframes() || atquery("media") || atquery("container") || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface();
|
|
1068
|
+
};
|
|
1069
|
+
const rule = () => {
|
|
1070
|
+
const pos = position();
|
|
1071
|
+
const sel = selector();
|
|
1072
|
+
if (!sel) return error("selector missing");
|
|
1073
|
+
comments();
|
|
1074
|
+
if (!open()) return error(`missing '{'`);
|
|
1075
|
+
const decls = [];
|
|
1076
|
+
const nestedRules = [];
|
|
1077
|
+
comments(decls);
|
|
1078
|
+
while (css.length && css.charAt(0) !== "}") {
|
|
1079
|
+
whitespace();
|
|
1080
|
+
if (!css.length || css.charAt(0) === "}") break;
|
|
1081
|
+
const nextChar = css.charAt(0);
|
|
1082
|
+
if (nextChar === "@") {
|
|
1083
|
+
const nestedAt = nestedAtrule();
|
|
1084
|
+
if (nestedAt) {
|
|
1085
|
+
nestedRules.push(nestedAt);
|
|
1086
|
+
comments(nestedRules);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (nextChar === "&" || nextChar === ":" || /[a-zA-Z\.\#\[]/.test(nextChar)) {
|
|
1091
|
+
let hasOpenBrace = false;
|
|
1092
|
+
if (nextChar === "&" || nextChar === ":") {
|
|
1093
|
+
const lookAhead = css.match(/^[^{}]+/);
|
|
1094
|
+
hasOpenBrace = lookAhead && css[lookAhead[0].length] === "{";
|
|
1095
|
+
} else {
|
|
1096
|
+
const lookAhead = css.match(/^[^{};]+/);
|
|
1097
|
+
if (lookAhead) hasOpenBrace = css[lookAhead[0].length] === "{";
|
|
1098
|
+
}
|
|
1099
|
+
if (hasOpenBrace) {
|
|
1100
|
+
const nestedRule = rule();
|
|
1101
|
+
if (nestedRule) {
|
|
1102
|
+
nestedRules.push(nestedRule);
|
|
1103
|
+
comments(nestedRules);
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
const decl = declaration();
|
|
1109
|
+
if (decl) {
|
|
1110
|
+
decls.push(decl);
|
|
1111
|
+
comments(decls);
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
if (!close()) return error(`missing '}'`);
|
|
1117
|
+
return pos({
|
|
1118
|
+
type: CssNodeType.Rule,
|
|
1119
|
+
selectors: sel,
|
|
1120
|
+
declarations: decls,
|
|
1121
|
+
rules: nestedRules.length > 0 ? nestedRules : null
|
|
1122
|
+
});
|
|
1123
|
+
};
|
|
1124
|
+
class ParsePosition {
|
|
1125
|
+
start;
|
|
1126
|
+
end;
|
|
1127
|
+
source;
|
|
1128
|
+
content;
|
|
1129
|
+
constructor(start) {
|
|
1130
|
+
this.start = start;
|
|
1131
|
+
this.end = {
|
|
1132
|
+
line: lineno,
|
|
1133
|
+
column
|
|
1134
|
+
};
|
|
1135
|
+
this.source = filePath;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
ParsePosition.prototype.content = css;
|
|
1139
|
+
return {
|
|
1140
|
+
diagnostics,
|
|
1141
|
+
...addParent(stylesheet())
|
|
1142
|
+
};
|
|
1143
|
+
};
|
|
1144
|
+
const trim = (str) => str ? str.trim() : "";
|
|
1145
|
+
/**
|
|
1146
|
+
* Adds non-enumerable parent node reference to each node.
|
|
1147
|
+
*/
|
|
1148
|
+
const addParent = (obj, parent) => {
|
|
1149
|
+
const isNode = obj && typeof obj.type === "string";
|
|
1150
|
+
const childParent = isNode ? obj : parent;
|
|
1151
|
+
for (const k in obj) {
|
|
1152
|
+
const value = obj[k];
|
|
1153
|
+
if (Array.isArray(value)) value.forEach(function(v) {
|
|
1154
|
+
addParent(v, childParent);
|
|
1155
|
+
});
|
|
1156
|
+
else if (value && typeof value === "object") addParent(value, childParent);
|
|
1157
|
+
}
|
|
1158
|
+
if (isNode) Object.defineProperty(obj, "parent", {
|
|
1159
|
+
configurable: true,
|
|
1160
|
+
writable: true,
|
|
1161
|
+
enumerable: false,
|
|
1162
|
+
value: parent || null
|
|
1163
|
+
});
|
|
1164
|
+
return obj;
|
|
1165
|
+
};
|
|
1166
|
+
const commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
1167
|
+
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region src/compiler/style/css-parser/get-css-selectors.ts
|
|
1170
|
+
const getCssSelectors = (sel) => {
|
|
1171
|
+
SELECTORS.all.length = SELECTORS.tags.length = SELECTORS.classNames.length = SELECTORS.ids.length = SELECTORS.attrs.length = 0;
|
|
1172
|
+
sel = sel.replace(/\./g, " .").replace(/\#/g, " #").replace(/\[/g, " [").replace(/\>/g, " > ").replace(/\+/g, " + ").replace(/\~/g, " ~ ").replace(/\*/g, " * ").replace(/\:not\((.*?)\)/g, " ");
|
|
1173
|
+
const items = sel.split(" ");
|
|
1174
|
+
for (let i = 0, l = items.length; i < l; i++) {
|
|
1175
|
+
items[i] = items[i].split(":")[0];
|
|
1176
|
+
if (items[i].length === 0) continue;
|
|
1177
|
+
if (items[i].charAt(0) === ".") SELECTORS.classNames.push(items[i].slice(1));
|
|
1178
|
+
else if (items[i].charAt(0) === "#") SELECTORS.ids.push(items[i].slice(1));
|
|
1179
|
+
else if (items[i].charAt(0) === "[") {
|
|
1180
|
+
items[i] = items[i].slice(1).split("=")[0].split("]")[0].trim();
|
|
1181
|
+
SELECTORS.attrs.push(items[i].toLowerCase());
|
|
1182
|
+
} else if (/[a-z]/g.test(items[i].charAt(0))) SELECTORS.tags.push(items[i].toLowerCase());
|
|
1183
|
+
}
|
|
1184
|
+
SELECTORS.classNames = SELECTORS.classNames.sort((a, b) => {
|
|
1185
|
+
if (a.length < b.length) return -1;
|
|
1186
|
+
if (a.length > b.length) return 1;
|
|
1187
|
+
return 0;
|
|
1188
|
+
});
|
|
1189
|
+
return SELECTORS;
|
|
1190
|
+
};
|
|
1191
|
+
const SELECTORS = {
|
|
1192
|
+
all: [],
|
|
1193
|
+
tags: [],
|
|
1194
|
+
classNames: [],
|
|
1195
|
+
ids: [],
|
|
1196
|
+
attrs: []
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region src/compiler/style/css-parser/serialize-css.ts
|
|
1201
|
+
/**
|
|
1202
|
+
* Serializes CSS AST back into a minified CSS string,
|
|
1203
|
+
* possibly filtering by used selectors (used during SSR / prerendering)
|
|
1204
|
+
*
|
|
1205
|
+
* @param stylesheet The CSS AST to serialize.
|
|
1206
|
+
* @param serializeOpts Options for serialization, including used selectors for filtering.
|
|
1207
|
+
* @returns The serialized CSS string.
|
|
1208
|
+
*/
|
|
1209
|
+
const serializeCss = (stylesheet, serializeOpts) => {
|
|
1210
|
+
const usedSelectors = serializeOpts.usedSelectors || null;
|
|
1211
|
+
const opts = {
|
|
1212
|
+
usedSelectors: usedSelectors || null,
|
|
1213
|
+
hasUsedAttrs: !!usedSelectors && usedSelectors.attrs.size > 0,
|
|
1214
|
+
hasUsedClassNames: !!usedSelectors && usedSelectors.classNames.size > 0,
|
|
1215
|
+
hasUsedIds: !!usedSelectors && usedSelectors.ids.size > 0,
|
|
1216
|
+
hasUsedTags: !!usedSelectors && usedSelectors.tags.size > 0
|
|
1217
|
+
};
|
|
1218
|
+
const rules = stylesheet.rules;
|
|
1219
|
+
if (!rules) return "";
|
|
1220
|
+
const rulesLen = rules.length;
|
|
1221
|
+
const out = [];
|
|
1222
|
+
for (let i = 0; i < rulesLen; i++) out.push(serializeCssVisitNode(opts, rules[i], i, rulesLen));
|
|
1223
|
+
return out.join("");
|
|
1224
|
+
};
|
|
1225
|
+
const serializeCssVisitNode = (opts, node, index, len) => {
|
|
1226
|
+
const nodeType = node.type;
|
|
1227
|
+
if (nodeType === CssNodeType.Declaration) return serializeCssDeclaration(node, index, len);
|
|
1228
|
+
if (nodeType === CssNodeType.Rule) return serializeCssRule(opts, node);
|
|
1229
|
+
if (nodeType === CssNodeType.Comment) if (node.comment?.[0] === "!") return `/*${node.comment}*/`;
|
|
1230
|
+
else return "";
|
|
1231
|
+
if (nodeType === CssNodeType.Media) return serializeCssMedia(opts, node);
|
|
1232
|
+
if (nodeType === CssNodeType.Container) return serializeCssContainer(opts, node);
|
|
1233
|
+
if (nodeType === CssNodeType.KeyFrames) return serializeCssKeyframes(opts, node);
|
|
1234
|
+
if (nodeType === CssNodeType.KeyFrame) return serializeCssKeyframe(opts, node);
|
|
1235
|
+
if (nodeType === CssNodeType.FontFace) return serializeCssFontFace(opts, node);
|
|
1236
|
+
if (nodeType === CssNodeType.Supports) return serializeCssSupports(opts, node);
|
|
1237
|
+
if (nodeType === CssNodeType.Import) return "@import " + node.import + ";";
|
|
1238
|
+
if (nodeType === CssNodeType.Charset) return "@charset " + node.charset + ";";
|
|
1239
|
+
if (nodeType === CssNodeType.Page) return serializeCssPage(opts, node);
|
|
1240
|
+
if (nodeType === CssNodeType.Host) return "@host{" + serializeCssMapVisit(opts, node.rules) + "}";
|
|
1241
|
+
if (nodeType === CssNodeType.CustomMedia) return "@custom-media " + node.name + " " + node.media + ";";
|
|
1242
|
+
if (nodeType === CssNodeType.Document) return serializeCssDocument(opts, node);
|
|
1243
|
+
if (nodeType === CssNodeType.Namespace) return "@namespace " + node.namespace + ";";
|
|
1244
|
+
return "";
|
|
1245
|
+
};
|
|
1246
|
+
const serializeCssRule = (opts, node) => {
|
|
1247
|
+
const decls = node.declarations;
|
|
1248
|
+
const usedSelectors = opts.usedSelectors;
|
|
1249
|
+
const selectors = node.selectors?.slice() ?? [];
|
|
1250
|
+
const hasDecls = decls != null && decls.length > 0;
|
|
1251
|
+
const hasNestedRules = node.rules != null && node.rules.length > 0;
|
|
1252
|
+
if (!hasDecls && !hasNestedRules) return "";
|
|
1253
|
+
if (usedSelectors) {
|
|
1254
|
+
let i;
|
|
1255
|
+
let j;
|
|
1256
|
+
let include = true;
|
|
1257
|
+
for (i = selectors.length - 1; i >= 0; i--) {
|
|
1258
|
+
const sel = getCssSelectors(selectors[i]);
|
|
1259
|
+
include = true;
|
|
1260
|
+
let jlen = sel.classNames.length;
|
|
1261
|
+
if (jlen > 0 && opts.hasUsedClassNames) {
|
|
1262
|
+
for (j = 0; j < jlen; j++) if (!usedSelectors.classNames.has(sel.classNames[j])) {
|
|
1263
|
+
include = false;
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (include && opts.hasUsedTags) {
|
|
1268
|
+
jlen = sel.tags.length;
|
|
1269
|
+
if (jlen > 0) {
|
|
1270
|
+
for (j = 0; j < jlen; j++) if (!usedSelectors.tags.has(sel.tags[j])) {
|
|
1271
|
+
include = false;
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (include && opts.hasUsedAttrs) {
|
|
1277
|
+
jlen = sel.attrs.length;
|
|
1278
|
+
if (jlen > 0) {
|
|
1279
|
+
for (j = 0; j < jlen; j++) if (!usedSelectors.attrs.has(sel.attrs[j])) {
|
|
1280
|
+
include = false;
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (include && opts.hasUsedIds) {
|
|
1286
|
+
jlen = sel.ids.length;
|
|
1287
|
+
if (jlen > 0) {
|
|
1288
|
+
for (j = 0; j < jlen; j++) if (!usedSelectors.ids.has(sel.ids[j])) {
|
|
1289
|
+
include = false;
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
if (!include) selectors.splice(i, 1);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
if (selectors.length === 0) return "";
|
|
1298
|
+
const cleanedSelectors = [];
|
|
1299
|
+
let cleanedSelector = "";
|
|
1300
|
+
if (node.selectors) for (const selector of node.selectors) {
|
|
1301
|
+
cleanedSelector = removeSelectorWhitespace(selector);
|
|
1302
|
+
if (!cleanedSelectors.includes(cleanedSelector)) cleanedSelectors.push(cleanedSelector);
|
|
1303
|
+
}
|
|
1304
|
+
let declsCss = decls && decls.length > 0 ? serializeCssMapVisit(opts, decls) : "";
|
|
1305
|
+
const nestedRulesCss = node.rules ? serializeCssMapVisit(opts, node.rules) : "";
|
|
1306
|
+
if (declsCss && nestedRulesCss && declsCss.length > 0) declsCss += ";";
|
|
1307
|
+
return `${cleanedSelectors}{${declsCss}${nestedRulesCss}}`;
|
|
1308
|
+
};
|
|
1309
|
+
const serializeCssDeclaration = (node, index, len) => {
|
|
1310
|
+
if (node.value === "") return "";
|
|
1311
|
+
if (len - 1 === index) return node.property + ":" + node.value;
|
|
1312
|
+
return node.property + ":" + node.value + ";";
|
|
1313
|
+
};
|
|
1314
|
+
const serializeCssMedia = (opts, node) => {
|
|
1315
|
+
const mediaCss = node.declarations ? serializeCssMapVisit(opts, node.declarations) : serializeCssMapVisit(opts, node.rules);
|
|
1316
|
+
if (mediaCss === "") return "";
|
|
1317
|
+
return "@media " + removeMediaWhitespace(node.media) + "{" + mediaCss + "}";
|
|
1318
|
+
};
|
|
1319
|
+
const serializeCssKeyframes = (opts, node) => {
|
|
1320
|
+
const keyframesCss = serializeCssMapVisit(opts, node.keyframes);
|
|
1321
|
+
if (keyframesCss === "") return "";
|
|
1322
|
+
return "@" + (node.vendor || "") + "keyframes " + node.name + "{" + keyframesCss + "}";
|
|
1323
|
+
};
|
|
1324
|
+
const serializeCssKeyframe = (opts, node) => {
|
|
1325
|
+
return (node.values?.join(",") ?? "") + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
|
|
1326
|
+
};
|
|
1327
|
+
const serializeCssFontFace = (opts, node) => {
|
|
1328
|
+
const fontCss = serializeCssMapVisit(opts, node.declarations);
|
|
1329
|
+
if (fontCss === "") return "";
|
|
1330
|
+
return "@font-face{" + fontCss + "}";
|
|
1331
|
+
};
|
|
1332
|
+
const serializeCssSupports = (opts, node) => {
|
|
1333
|
+
const supportsCss = node.declarations ? serializeCssMapVisit(opts, node.declarations) : serializeCssMapVisit(opts, node.rules);
|
|
1334
|
+
if (supportsCss === "") return "";
|
|
1335
|
+
return "@supports " + node.supports + "{" + supportsCss + "}";
|
|
1336
|
+
};
|
|
1337
|
+
const serializeCssContainer = (opts, node) => {
|
|
1338
|
+
const containerCss = node.declarations ? serializeCssMapVisit(opts, node.declarations) : serializeCssMapVisit(opts, node.rules);
|
|
1339
|
+
if (containerCss === "") return "";
|
|
1340
|
+
return "@container " + removeMediaWhitespace(node.media) + "{" + containerCss + "}";
|
|
1341
|
+
};
|
|
1342
|
+
const serializeCssPage = (opts, node) => {
|
|
1343
|
+
return "@page " + (node.selectors?.join(", ") ?? "") + "{" + serializeCssMapVisit(opts, node.declarations) + "}";
|
|
1344
|
+
};
|
|
1345
|
+
const serializeCssDocument = (opts, node) => {
|
|
1346
|
+
const documentCss = serializeCssMapVisit(opts, node.rules);
|
|
1347
|
+
const doc = "@" + (node.vendor || "") + "document " + node.document;
|
|
1348
|
+
if (documentCss === "") return "";
|
|
1349
|
+
return doc + "{" + documentCss + "}";
|
|
1350
|
+
};
|
|
1351
|
+
const serializeCssMapVisit = (opts, nodes) => {
|
|
1352
|
+
let rtn = "";
|
|
1353
|
+
if (nodes) for (let i = 0, len = nodes.length; i < len; i++) rtn += serializeCssVisitNode(opts, nodes[i], i, len);
|
|
1354
|
+
return rtn;
|
|
1355
|
+
};
|
|
1356
|
+
const removeSelectorWhitespace = (selector) => {
|
|
1357
|
+
let rtn = "";
|
|
1358
|
+
let char = "";
|
|
1359
|
+
let inAttr = false;
|
|
1360
|
+
selector = selector.trim();
|
|
1361
|
+
for (let i = 0, l = selector.length; i < l; i++) {
|
|
1362
|
+
char = selector[i];
|
|
1363
|
+
if (char === "[" && rtn[rtn.length - 1] !== "\\") inAttr = true;
|
|
1364
|
+
else if (char === "]" && rtn[rtn.length - 1] !== "\\") inAttr = false;
|
|
1365
|
+
if (!inAttr && CSS_WS_REG.test(char)) {
|
|
1366
|
+
if (CSS_NEXT_CHAR_REG.test(selector[i + 1])) continue;
|
|
1367
|
+
if (CSS_PREV_CHAR_REG.test(rtn[rtn.length - 1])) continue;
|
|
1368
|
+
rtn += " ";
|
|
1369
|
+
} else rtn += char;
|
|
1370
|
+
}
|
|
1371
|
+
return rtn;
|
|
1372
|
+
};
|
|
1373
|
+
const removeMediaWhitespace = (media) => {
|
|
1374
|
+
let rtn = "";
|
|
1375
|
+
let char = "";
|
|
1376
|
+
media = media?.trim() ?? "";
|
|
1377
|
+
for (let i = 0, l = media.length; i < l; i++) {
|
|
1378
|
+
char = media[i];
|
|
1379
|
+
if (CSS_WS_REG.test(char)) {
|
|
1380
|
+
if (CSS_WS_REG.test(rtn[rtn.length - 1])) continue;
|
|
1381
|
+
rtn += " ";
|
|
1382
|
+
} else rtn += char;
|
|
1383
|
+
}
|
|
1384
|
+
return rtn;
|
|
1385
|
+
};
|
|
1386
|
+
const CSS_WS_REG = /\s/;
|
|
1387
|
+
const CSS_NEXT_CHAR_REG = /[>\(\)\~\,\+\s]/;
|
|
1388
|
+
const CSS_PREV_CHAR_REG = /[>\(\~\,\+]/;
|
|
1389
|
+
|
|
1390
|
+
//#endregion
|
|
1391
|
+
//#region src/compiler/style/css-parser/used-selectors.ts
|
|
1392
|
+
/**
|
|
1393
|
+
* Collects all used selectors (tags, class names, ids, attributes) from a given DOM element and its children.
|
|
1394
|
+
* Mainly used during SSR / prerendering to determine which CSS rules are necessary.
|
|
1395
|
+
*
|
|
1396
|
+
* @param elm The root element from which to start collecting used selectors.
|
|
1397
|
+
* @returns The set of used selectors found within the element and its descendants.
|
|
1398
|
+
*/
|
|
1399
|
+
const getUsedSelectors = (elm) => {
|
|
1400
|
+
const usedSelectors = {
|
|
1401
|
+
attrs: /* @__PURE__ */ new Set(),
|
|
1402
|
+
classNames: /* @__PURE__ */ new Set(),
|
|
1403
|
+
ids: /* @__PURE__ */ new Set(),
|
|
1404
|
+
tags: /* @__PURE__ */ new Set()
|
|
1405
|
+
};
|
|
1406
|
+
collectUsedSelectors(usedSelectors, elm);
|
|
1407
|
+
return usedSelectors;
|
|
1408
|
+
};
|
|
1409
|
+
const collectUsedSelectors = (usedSelectors, elm) => {
|
|
1410
|
+
if (elm != null && elm.nodeType === 1) {
|
|
1411
|
+
const children = elm.children;
|
|
1412
|
+
const tagName = elm.nodeName.toLowerCase();
|
|
1413
|
+
usedSelectors.tags.add(tagName);
|
|
1414
|
+
const attributes = elm.attributes;
|
|
1415
|
+
for (let i = 0, l = attributes.length; i < l; i++) {
|
|
1416
|
+
const attr = attributes.item(i);
|
|
1417
|
+
const attrName = attr.name.toLowerCase();
|
|
1418
|
+
usedSelectors.attrs.add(attrName);
|
|
1419
|
+
if (attrName === "class") {
|
|
1420
|
+
const classList = elm.classList;
|
|
1421
|
+
for (let i = 0, l = classList.length; i < l; i++) usedSelectors.classNames.add(classList.item(i));
|
|
1422
|
+
} else if (attrName === "id") usedSelectors.ids.add(attr.value);
|
|
1423
|
+
}
|
|
1424
|
+
if (children) for (let i = 0, l = children.length; i < l; i++) collectUsedSelectors(usedSelectors, children[i]);
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
//#endregion
|
|
1429
|
+
//#region src/compiler/html/remove-unused-styles.ts
|
|
1430
|
+
/**
|
|
1431
|
+
* Removes unused CSS styles from the document's style elements based on the selectors used in the document.
|
|
1432
|
+
* Primarily used during SSR / prerendering to optimize CSS delivery.
|
|
1433
|
+
*
|
|
1434
|
+
* @param doc The HTML document to process.
|
|
1435
|
+
* @param diagnostics An array to collect diagnostic messages.
|
|
1436
|
+
*/
|
|
1437
|
+
const removeUnusedStyles = (doc, diagnostics) => {
|
|
1438
|
+
try {
|
|
1439
|
+
const styleElms = doc.head.querySelectorAll(`style[data-styles]`);
|
|
1440
|
+
const styleLen = styleElms.length;
|
|
1441
|
+
if (styleLen > 0) {
|
|
1442
|
+
const usedSelectors = getUsedSelectors(doc.documentElement);
|
|
1443
|
+
for (let i = 0; i < styleLen; i++) removeUnusedStyleText(usedSelectors, diagnostics, styleElms[i]);
|
|
1444
|
+
}
|
|
1445
|
+
} catch (e) {
|
|
1446
|
+
catchError(diagnostics, e);
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
const removeUnusedStyleText = (usedSelectors, diagnostics, styleElm) => {
|
|
1450
|
+
try {
|
|
1451
|
+
const parseResults = parseCss(styleElm.innerHTML);
|
|
1452
|
+
diagnostics.push(...parseResults.diagnostics);
|
|
1453
|
+
if (hasError(diagnostics)) return;
|
|
1454
|
+
try {
|
|
1455
|
+
styleElm.innerHTML = serializeCss(parseResults.stylesheet, { usedSelectors });
|
|
1456
|
+
} catch (e) {
|
|
1457
|
+
diagnostics.push({
|
|
1458
|
+
level: "warn",
|
|
1459
|
+
type: "css",
|
|
1460
|
+
header: "CSS Stringify",
|
|
1461
|
+
messageText: e,
|
|
1462
|
+
lines: []
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
} catch (e) {
|
|
1466
|
+
diagnostics.push({
|
|
1467
|
+
level: "warn",
|
|
1468
|
+
type: "css",
|
|
1469
|
+
header: "CSS Parse",
|
|
1470
|
+
messageText: e,
|
|
1471
|
+
lines: []
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
//#endregion
|
|
1477
|
+
//#region src/server/runner/inspect-element.ts
|
|
1478
|
+
function inspectElement(results, elm, depth) {
|
|
1479
|
+
const children = [...Array.from(elm.children), ...Array.from(elm.shadowRoot ? elm.shadowRoot.children : [])];
|
|
1480
|
+
for (let i = 0, ii = children.length; i < ii; i++) {
|
|
1481
|
+
const childElm = children[i];
|
|
1482
|
+
const tagName = childElm.nodeName.toLowerCase();
|
|
1483
|
+
if (tagName.includes("-")) {
|
|
1484
|
+
const cmp = results.components.find((c) => c.tag === tagName);
|
|
1485
|
+
if (cmp != null) {
|
|
1486
|
+
cmp.count++;
|
|
1487
|
+
if (depth > cmp.depth) cmp.depth = depth;
|
|
1488
|
+
}
|
|
1489
|
+
} else switch (tagName) {
|
|
1490
|
+
case "a":
|
|
1491
|
+
const anchor = collectAttributes(childElm);
|
|
1492
|
+
anchor.href = childElm.href;
|
|
1493
|
+
if (typeof anchor.href === "string") {
|
|
1494
|
+
if (!results.anchors.some((a) => a.href === anchor.href)) results.anchors.push(anchor);
|
|
1495
|
+
}
|
|
1496
|
+
break;
|
|
1497
|
+
case "img":
|
|
1498
|
+
const img = collectAttributes(childElm);
|
|
1499
|
+
img.src = childElm.src;
|
|
1500
|
+
if (typeof img.src === "string") {
|
|
1501
|
+
if (!results.imgs.some((a) => a.src === img.src)) results.imgs.push(img);
|
|
1502
|
+
}
|
|
1503
|
+
break;
|
|
1504
|
+
case "link":
|
|
1505
|
+
const link = collectAttributes(childElm);
|
|
1506
|
+
link.href = childElm.href;
|
|
1507
|
+
if (typeof link.rel === "string" && link.rel.toLowerCase() === "stylesheet") {
|
|
1508
|
+
if (typeof link.href === "string") {
|
|
1509
|
+
if (!results.styles.some((s) => s.link === link.href)) {
|
|
1510
|
+
delete link.rel;
|
|
1511
|
+
delete link.type;
|
|
1512
|
+
results.styles.push(link);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
break;
|
|
1517
|
+
case "script":
|
|
1518
|
+
const script = collectAttributes(childElm);
|
|
1519
|
+
if (childElm.hasAttribute("src")) {
|
|
1520
|
+
script.src = childElm.src;
|
|
1521
|
+
if (typeof script.src === "string") {
|
|
1522
|
+
if (!results.scripts.some((s) => s.src === script.src)) results.scripts.push(script);
|
|
1523
|
+
}
|
|
1524
|
+
} else {
|
|
1525
|
+
const staticDataKey = childElm.getAttribute("data-stencil-static");
|
|
1526
|
+
if (staticDataKey) results.staticData.push({
|
|
1527
|
+
id: staticDataKey,
|
|
1528
|
+
type: childElm.getAttribute("type"),
|
|
1529
|
+
content: childElm.textContent
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
break;
|
|
1533
|
+
}
|
|
1534
|
+
depth++;
|
|
1535
|
+
inspectElement(results, childElm, depth);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
function collectAttributes(node) {
|
|
1539
|
+
const parsedElm = {};
|
|
1540
|
+
const attrs = node.attributes;
|
|
1541
|
+
for (let i = 0, ii = attrs.length; i < ii; i++) {
|
|
1542
|
+
const attr = attrs.item(i);
|
|
1543
|
+
const attrName = attr.nodeName.toLowerCase();
|
|
1544
|
+
if (SKIP_ATTRS.has(attrName)) continue;
|
|
1545
|
+
const attrValue = attr.nodeValue;
|
|
1546
|
+
if (attrName === "class" && attrValue === "") continue;
|
|
1547
|
+
parsedElm[attrName] = attrValue;
|
|
1548
|
+
}
|
|
1549
|
+
return parsedElm;
|
|
1550
|
+
}
|
|
1551
|
+
const SKIP_ATTRS = new Set(["s-id", "c-id"]);
|
|
1552
|
+
|
|
1553
|
+
//#endregion
|
|
1554
|
+
//#region src/server/runner/patch-dom-implementation.ts
|
|
1555
|
+
function patchDomImplementation(doc, opts) {
|
|
1556
|
+
let win;
|
|
1557
|
+
if (doc.defaultView != null) {
|
|
1558
|
+
opts.destroyWindow = true;
|
|
1559
|
+
patchWindow(doc.defaultView);
|
|
1560
|
+
win = doc.defaultView;
|
|
1561
|
+
} else {
|
|
1562
|
+
opts.destroyWindow = true;
|
|
1563
|
+
opts.destroyDocument = false;
|
|
1564
|
+
win = new MockWindow(false);
|
|
1565
|
+
}
|
|
1566
|
+
if (win.document !== doc) win.document = doc;
|
|
1567
|
+
if (doc.defaultView !== win) doc.defaultView = win;
|
|
1568
|
+
if (typeof doc.documentElement.constructor.prototype.getRootNode !== "function") {
|
|
1569
|
+
const HTMLUnknownElement = doc.createElement("unknown-element").constructor.prototype;
|
|
1570
|
+
HTMLUnknownElement.getRootNode = getRootNode;
|
|
1571
|
+
}
|
|
1572
|
+
if (typeof doc.createEvent === "function") {
|
|
1573
|
+
const CustomEvent = doc.createEvent("CustomEvent").constructor;
|
|
1574
|
+
if (win.CustomEvent !== CustomEvent) win.CustomEvent = CustomEvent;
|
|
1575
|
+
}
|
|
1576
|
+
try {
|
|
1577
|
+
win.__stencil_baseURI = doc.baseURI;
|
|
1578
|
+
} catch (e) {
|
|
1579
|
+
Object.defineProperty(doc, "baseURI", { get() {
|
|
1580
|
+
const baseElm = doc.querySelector("base[href]");
|
|
1581
|
+
if (baseElm) return new URL(baseElm.getAttribute("href"), win.location.href).href;
|
|
1582
|
+
return win.location.href;
|
|
1583
|
+
} });
|
|
1584
|
+
}
|
|
1585
|
+
return win;
|
|
1586
|
+
}
|
|
1587
|
+
function getRootNode(opts) {
|
|
1588
|
+
const isComposed = opts != null && opts.composed === true;
|
|
1589
|
+
let node = this;
|
|
1590
|
+
while (node.parentNode != null) {
|
|
1591
|
+
node = node.parentNode;
|
|
1592
|
+
if (isComposed === true && node.parentNode == null && node.host != null) node = node.host;
|
|
1593
|
+
}
|
|
1594
|
+
return node;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
//#endregion
|
|
1598
|
+
//#region src/server/runner/render-utils.ts
|
|
1599
|
+
function normalizeHydrateOptions(inputOpts) {
|
|
1600
|
+
const outputOpts = Object.assign({
|
|
1601
|
+
serializeToHtml: false,
|
|
1602
|
+
destroyWindow: false,
|
|
1603
|
+
destroyDocument: false
|
|
1604
|
+
}, inputOpts || {});
|
|
1605
|
+
if (typeof outputOpts.clientHydrateAnnotations !== "boolean") outputOpts.clientHydrateAnnotations = true;
|
|
1606
|
+
if (typeof outputOpts.constrainTimeouts !== "boolean") outputOpts.constrainTimeouts = true;
|
|
1607
|
+
if (typeof outputOpts.maxHydrateCount !== "number") outputOpts.maxHydrateCount = 300;
|
|
1608
|
+
if (typeof outputOpts.runtimeLogging !== "boolean") outputOpts.runtimeLogging = false;
|
|
1609
|
+
if (typeof outputOpts.timeout !== "number") outputOpts.timeout = 15e3;
|
|
1610
|
+
if (Array.isArray(outputOpts.excludeComponents)) outputOpts.excludeComponents = outputOpts.excludeComponents.filter(filterValidTags).map(mapValidTags);
|
|
1611
|
+
else outputOpts.excludeComponents = [];
|
|
1612
|
+
if (Array.isArray(outputOpts.staticComponents)) outputOpts.staticComponents = outputOpts.staticComponents.filter(filterValidTags).map(mapValidTags);
|
|
1613
|
+
else outputOpts.staticComponents = [];
|
|
1614
|
+
return outputOpts;
|
|
1615
|
+
}
|
|
1616
|
+
function filterValidTags(tag) {
|
|
1617
|
+
return typeof tag === "string" && tag.includes("-");
|
|
1618
|
+
}
|
|
1619
|
+
function mapValidTags(tag) {
|
|
1620
|
+
return tag.trim().toLowerCase();
|
|
1621
|
+
}
|
|
1622
|
+
function generateHydrateResults(opts) {
|
|
1623
|
+
if (typeof opts.url !== "string") opts.url = `https://hydrate.stenciljs.com/`;
|
|
1624
|
+
if (typeof opts.buildId !== "string") opts.buildId = createHydrateBuildId();
|
|
1625
|
+
const results = {
|
|
1626
|
+
buildId: opts.buildId,
|
|
1627
|
+
diagnostics: [],
|
|
1628
|
+
url: opts.url,
|
|
1629
|
+
host: null,
|
|
1630
|
+
hostname: null,
|
|
1631
|
+
href: null,
|
|
1632
|
+
pathname: null,
|
|
1633
|
+
port: null,
|
|
1634
|
+
search: null,
|
|
1635
|
+
hash: null,
|
|
1636
|
+
html: null,
|
|
1637
|
+
httpStatus: null,
|
|
1638
|
+
hydratedCount: 0,
|
|
1639
|
+
anchors: [],
|
|
1640
|
+
components: [],
|
|
1641
|
+
imgs: [],
|
|
1642
|
+
scripts: [],
|
|
1643
|
+
staticData: [],
|
|
1644
|
+
styles: [],
|
|
1645
|
+
title: null
|
|
1646
|
+
};
|
|
1647
|
+
try {
|
|
1648
|
+
const url = new URL(opts.url, `https://hydrate.stenciljs.com/`);
|
|
1649
|
+
results.url = url.href;
|
|
1650
|
+
results.host = url.host;
|
|
1651
|
+
results.hostname = url.hostname;
|
|
1652
|
+
results.href = url.href;
|
|
1653
|
+
results.port = url.port;
|
|
1654
|
+
results.pathname = url.pathname;
|
|
1655
|
+
results.search = url.search;
|
|
1656
|
+
results.hash = url.hash;
|
|
1657
|
+
} catch (e) {
|
|
1658
|
+
renderCatchError(results, e);
|
|
1659
|
+
}
|
|
1660
|
+
return results;
|
|
1661
|
+
}
|
|
1662
|
+
const createHydrateBuildId = () => {
|
|
1663
|
+
let chars = "abcdefghijklmnopqrstuvwxyz";
|
|
1664
|
+
let buildId = "";
|
|
1665
|
+
while (buildId.length < 8) {
|
|
1666
|
+
const char = chars[Math.floor(Math.random() * chars.length)];
|
|
1667
|
+
buildId += char;
|
|
1668
|
+
if (buildId.length === 1) chars += "0123456789";
|
|
1669
|
+
}
|
|
1670
|
+
return buildId;
|
|
1671
|
+
};
|
|
1672
|
+
function renderBuildDiagnostic(results, level, header, msg) {
|
|
1673
|
+
const diagnostic = {
|
|
1674
|
+
level,
|
|
1675
|
+
type: "build",
|
|
1676
|
+
header,
|
|
1677
|
+
messageText: msg,
|
|
1678
|
+
relFilePath: void 0,
|
|
1679
|
+
absFilePath: void 0,
|
|
1680
|
+
lines: []
|
|
1681
|
+
};
|
|
1682
|
+
if (results.pathname) {
|
|
1683
|
+
if (results.pathname !== "/") diagnostic.header += ": " + results.pathname;
|
|
1684
|
+
} else if (results.url) diagnostic.header += ": " + results.url;
|
|
1685
|
+
results.diagnostics.push(diagnostic);
|
|
1686
|
+
return diagnostic;
|
|
1687
|
+
}
|
|
1688
|
+
function renderBuildError(results, msg) {
|
|
1689
|
+
return renderBuildDiagnostic(results, "error", "Hydrate Error", msg || "");
|
|
1690
|
+
}
|
|
1691
|
+
function renderCatchError(results, err) {
|
|
1692
|
+
const diagnostic = renderBuildError(results);
|
|
1693
|
+
if (err != null) if (err.stack != null) diagnostic.messageText = err.stack.toString();
|
|
1694
|
+
else if (err.message != null) diagnostic.messageText = err.message.toString();
|
|
1695
|
+
else diagnostic.messageText = err.toString();
|
|
1696
|
+
return diagnostic;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
//#endregion
|
|
1700
|
+
//#region src/server/runner/runtime-log.ts
|
|
1701
|
+
function runtimeLogging(win, opts, results) {
|
|
1702
|
+
try {
|
|
1703
|
+
const pathname = win.location.pathname;
|
|
1704
|
+
win.console.error = (...msgs) => {
|
|
1705
|
+
const errMsg = msgs.reduce((errMsg, m) => {
|
|
1706
|
+
if (m) {
|
|
1707
|
+
if (m.stack != null) return errMsg + " " + String(m.stack);
|
|
1708
|
+
else if (m.message != null) return errMsg + " " + String(m.message);
|
|
1709
|
+
}
|
|
1710
|
+
return String(m);
|
|
1711
|
+
}, "").trim();
|
|
1712
|
+
if (errMsg !== "") {
|
|
1713
|
+
renderCatchError(results, errMsg);
|
|
1714
|
+
if (opts.runtimeLogging) runtimeLog(pathname, "error", [errMsg]);
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
win.console.debug = (...msgs) => {
|
|
1718
|
+
renderBuildDiagnostic(results, "debug", "Hydrate Debug", [...msgs].join(", "));
|
|
1719
|
+
if (opts.runtimeLogging) runtimeLog(pathname, "debug", msgs);
|
|
1720
|
+
};
|
|
1721
|
+
if (opts.runtimeLogging) [
|
|
1722
|
+
"log",
|
|
1723
|
+
"warn",
|
|
1724
|
+
"assert",
|
|
1725
|
+
"info",
|
|
1726
|
+
"trace"
|
|
1727
|
+
].forEach((type) => {
|
|
1728
|
+
win.console[type] = (...msgs) => {
|
|
1729
|
+
runtimeLog(pathname, type, msgs);
|
|
1730
|
+
};
|
|
1731
|
+
});
|
|
1732
|
+
} catch (e) {
|
|
1733
|
+
renderCatchError(results, e);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
function runtimeLog(pathname, type, msgs) {
|
|
1737
|
+
global.console[type].apply(global.console, [`[ ${pathname} ${type} ] `, ...msgs]);
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
//#endregion
|
|
1741
|
+
//#region src/server/runner/window-initialize.ts
|
|
1742
|
+
/**
|
|
1743
|
+
* Maintain a unique `docData` object across multiple hydration runs
|
|
1744
|
+
* to ensure that host ids remain unique.
|
|
1745
|
+
*/
|
|
1746
|
+
const docData = {
|
|
1747
|
+
hostIds: 0,
|
|
1748
|
+
rootLevelIds: 0,
|
|
1749
|
+
staticComponents: /* @__PURE__ */ new Set()
|
|
1750
|
+
};
|
|
1751
|
+
function initializeWindow(win, doc, opts, results) {
|
|
1752
|
+
if (typeof opts.url === "string") try {
|
|
1753
|
+
win.location.href = opts.url;
|
|
1754
|
+
} catch (e) {}
|
|
1755
|
+
if (typeof opts.userAgent === "string") try {
|
|
1756
|
+
win.navigator.userAgent = opts.userAgent;
|
|
1757
|
+
} catch (e) {}
|
|
1758
|
+
if (typeof opts.cookie === "string") try {
|
|
1759
|
+
doc.cookie = opts.cookie;
|
|
1760
|
+
} catch (e) {}
|
|
1761
|
+
if (typeof opts.referrer === "string") try {
|
|
1762
|
+
doc.referrer = opts.referrer;
|
|
1763
|
+
} catch (e) {}
|
|
1764
|
+
if (typeof opts.direction === "string") try {
|
|
1765
|
+
doc.documentElement.setAttribute("dir", opts.direction);
|
|
1766
|
+
} catch (e) {}
|
|
1767
|
+
if (typeof opts.language === "string") try {
|
|
1768
|
+
doc.documentElement.setAttribute("lang", opts.language);
|
|
1769
|
+
} catch (e) {}
|
|
1770
|
+
if (typeof opts.buildId === "string") try {
|
|
1771
|
+
doc.documentElement.setAttribute("data-stencil-build", opts.buildId);
|
|
1772
|
+
} catch (e) {}
|
|
1773
|
+
try {
|
|
1774
|
+
win.customElements = null;
|
|
1775
|
+
} catch (e) {}
|
|
1776
|
+
if (opts.constrainTimeouts) constrainTimeouts(win);
|
|
1777
|
+
runtimeLogging(win, opts, results);
|
|
1778
|
+
doc[STENCIL_DOC_DATA] = docData;
|
|
1779
|
+
return win;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
//#endregion
|
|
1783
|
+
//#region src/server/runner/render.ts
|
|
1784
|
+
const NOOP = () => {};
|
|
1785
|
+
function streamToString(html, option) {
|
|
1786
|
+
return renderToString(html, option, true);
|
|
1787
|
+
}
|
|
1788
|
+
function renderToString(html, options, asStream) {
|
|
1789
|
+
const opts = normalizeHydrateOptions(options);
|
|
1790
|
+
/**
|
|
1791
|
+
* Makes the rendered DOM not being rendered to a string.
|
|
1792
|
+
*/
|
|
1793
|
+
opts.serializeToHtml = true;
|
|
1794
|
+
/**
|
|
1795
|
+
* Set the flag whether or not we like to render into a declarative shadow root.
|
|
1796
|
+
*/
|
|
1797
|
+
opts.fullDocument = typeof opts.fullDocument === "boolean" ? opts.fullDocument : true;
|
|
1798
|
+
/**
|
|
1799
|
+
* Defines whether we render the shadow root as a declarative shadow root or as scoped shadow root.
|
|
1800
|
+
*/
|
|
1801
|
+
opts.serializeShadowRoot = typeof opts.serializeShadowRoot === "undefined" ? "declarative-shadow-dom" : opts.serializeShadowRoot;
|
|
1802
|
+
/**
|
|
1803
|
+
* Make sure we wait for components to be hydrated.
|
|
1804
|
+
*/
|
|
1805
|
+
opts.constrainTimeouts = false;
|
|
1806
|
+
return hydrateDocument(html, opts, asStream);
|
|
1807
|
+
}
|
|
1808
|
+
function hydrateDocument(doc, options, asStream) {
|
|
1809
|
+
const opts = normalizeHydrateOptions(options);
|
|
1810
|
+
/**
|
|
1811
|
+
* Defines whether we render the shadow root as a declarative shadow root or as scoped shadow root.
|
|
1812
|
+
*/
|
|
1813
|
+
opts.serializeShadowRoot = typeof opts.serializeShadowRoot === "undefined" ? "declarative-shadow-dom" : opts.serializeShadowRoot;
|
|
1814
|
+
let win = null;
|
|
1815
|
+
const results = generateHydrateResults(opts);
|
|
1816
|
+
if (hasError(results.diagnostics)) return Promise.resolve(results);
|
|
1817
|
+
if (typeof doc === "string") try {
|
|
1818
|
+
opts.destroyWindow = true;
|
|
1819
|
+
opts.destroyDocument = true;
|
|
1820
|
+
win = new MockWindow(doc);
|
|
1821
|
+
if (!asStream) return render(win, opts, results).then(() => results);
|
|
1822
|
+
return renderStream(win, opts, results);
|
|
1823
|
+
} catch (e) {
|
|
1824
|
+
if (win && win.close) win.close();
|
|
1825
|
+
win = null;
|
|
1826
|
+
renderCatchError(results, e);
|
|
1827
|
+
return Promise.resolve(results);
|
|
1828
|
+
}
|
|
1829
|
+
if (isValidDocument(doc)) try {
|
|
1830
|
+
opts.destroyDocument = false;
|
|
1831
|
+
win = patchDomImplementation(doc, opts);
|
|
1832
|
+
if (!asStream) return render(win, opts, results).then(() => results);
|
|
1833
|
+
return renderStream(win, opts, results);
|
|
1834
|
+
} catch (e) {
|
|
1835
|
+
if (win && win.close) win.close();
|
|
1836
|
+
win = null;
|
|
1837
|
+
renderCatchError(results, e);
|
|
1838
|
+
return Promise.resolve(results);
|
|
1839
|
+
}
|
|
1840
|
+
renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
|
|
1841
|
+
return Promise.resolve(results);
|
|
1842
|
+
}
|
|
1843
|
+
async function render(win, opts, results) {
|
|
1844
|
+
if ("process" in globalThis && typeof process.on === "function" && !process.__stencilErrors) {
|
|
1845
|
+
process.__stencilErrors = true;
|
|
1846
|
+
process.on("unhandledRejection", (e) => {
|
|
1847
|
+
console.log("unhandledRejection", e);
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
initializeWindow(win, win.document, opts, results);
|
|
1851
|
+
const beforeHydrateFn = typeof opts.beforeHydrate === "function" ? opts.beforeHydrate : NOOP;
|
|
1852
|
+
try {
|
|
1853
|
+
await Promise.resolve(beforeHydrateFn(win.document));
|
|
1854
|
+
return new Promise((resolve) => {
|
|
1855
|
+
if (Array.isArray(opts.modes)) {
|
|
1856
|
+
/**
|
|
1857
|
+
* Reset the mode resolution chain as we expect every `renderToString` call to render
|
|
1858
|
+
* the components in new environment/document.
|
|
1859
|
+
*/
|
|
1860
|
+
modeResolutionChain.length = 0;
|
|
1861
|
+
opts.modes.forEach((mode) => setMode(mode));
|
|
1862
|
+
}
|
|
1863
|
+
return /* @__PURE__ */ hydrateFactory(win, opts, results, afterHydrate, resolve);
|
|
1864
|
+
});
|
|
1865
|
+
} catch (e) {
|
|
1866
|
+
renderCatchError(results, e);
|
|
1867
|
+
return finalizeHydrate(win, win.document, opts, results);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Wrapper around `render` method to enable streaming by returning a Readable instead of a promise.
|
|
1872
|
+
* @param win MockDoc window object
|
|
1873
|
+
* @param opts serialization options
|
|
1874
|
+
* @param results render result object
|
|
1875
|
+
* @returns a Readable that can be passed into a response
|
|
1876
|
+
*/
|
|
1877
|
+
function renderStream(win, opts, results) {
|
|
1878
|
+
async function* processRender() {
|
|
1879
|
+
yield (await render(win, opts, results)).html;
|
|
1880
|
+
}
|
|
1881
|
+
return Readable.from(processRender());
|
|
1882
|
+
}
|
|
1883
|
+
async function afterHydrate(win, opts, results, resolve) {
|
|
1884
|
+
const afterHydrateFn = typeof opts.afterHydrate === "function" ? opts.afterHydrate : NOOP;
|
|
1885
|
+
try {
|
|
1886
|
+
await Promise.resolve(afterHydrateFn(win.document));
|
|
1887
|
+
return resolve(finalizeHydrate(win, win.document, opts, results));
|
|
1888
|
+
} catch (e) {
|
|
1889
|
+
renderCatchError(results, e);
|
|
1890
|
+
return resolve(finalizeHydrate(win, win.document, opts, results));
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
function finalizeHydrate(win, doc, opts, results) {
|
|
1894
|
+
try {
|
|
1895
|
+
inspectElement(results, doc.documentElement, 0);
|
|
1896
|
+
if (opts.removeUnusedStyles !== false) try {
|
|
1897
|
+
removeUnusedStyles(doc, results.diagnostics);
|
|
1898
|
+
} catch (e) {
|
|
1899
|
+
renderCatchError(results, e);
|
|
1900
|
+
}
|
|
1901
|
+
if (typeof opts.title === "string") try {
|
|
1902
|
+
doc.title = opts.title;
|
|
1903
|
+
} catch (e) {
|
|
1904
|
+
renderCatchError(results, e);
|
|
1905
|
+
}
|
|
1906
|
+
results.title = doc.title;
|
|
1907
|
+
if (opts.removeScripts) removeScripts(doc.documentElement);
|
|
1908
|
+
const styles = doc.querySelectorAll("head style");
|
|
1909
|
+
if (styles.length > 0) results.styles.push(...Array.from(styles).map((style) => ({
|
|
1910
|
+
href: style.getAttribute("href"),
|
|
1911
|
+
id: style.getAttribute(HYDRATED_STYLE_ID),
|
|
1912
|
+
content: style.textContent
|
|
1913
|
+
})));
|
|
1914
|
+
try {
|
|
1915
|
+
updateCanonicalLink(doc, opts.canonicalUrl);
|
|
1916
|
+
} catch (e) {
|
|
1917
|
+
renderCatchError(results, e);
|
|
1918
|
+
}
|
|
1919
|
+
try {
|
|
1920
|
+
relocateMetaCharset(doc);
|
|
1921
|
+
} catch (e) {}
|
|
1922
|
+
if (!hasError(results.diagnostics)) results.httpStatus = 200;
|
|
1923
|
+
try {
|
|
1924
|
+
const metaStatus = doc.head.querySelector("meta[http-equiv=\"status\"]");
|
|
1925
|
+
if (metaStatus != null) {
|
|
1926
|
+
const metaStatusContent = metaStatus.getAttribute("content");
|
|
1927
|
+
if (metaStatusContent && metaStatusContent.length > 0) results.httpStatus = parseInt(metaStatusContent, 10);
|
|
1928
|
+
}
|
|
1929
|
+
} catch (e) {}
|
|
1930
|
+
if (opts.clientHydrateAnnotations) doc.documentElement.classList.add("hydrated");
|
|
1931
|
+
if (opts.serializeToHtml) results.html = serializeDocumentToString(doc, opts);
|
|
1932
|
+
} catch (e) {
|
|
1933
|
+
renderCatchError(results, e);
|
|
1934
|
+
}
|
|
1935
|
+
destroyWindow(win, doc, opts, results);
|
|
1936
|
+
return results;
|
|
1937
|
+
}
|
|
1938
|
+
function destroyWindow(win, doc, opts, results) {
|
|
1939
|
+
if (!opts.destroyWindow) return;
|
|
1940
|
+
try {
|
|
1941
|
+
if (!opts.destroyDocument) {
|
|
1942
|
+
win.document = null;
|
|
1943
|
+
doc.defaultView = null;
|
|
1944
|
+
}
|
|
1945
|
+
if (win.close) win.close();
|
|
1946
|
+
} catch (e) {
|
|
1947
|
+
renderCatchError(results, e);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
function serializeDocumentToString(doc, opts) {
|
|
1951
|
+
return serializeNodeToHtml(doc, {
|
|
1952
|
+
approximateLineWidth: opts.approximateLineWidth,
|
|
1953
|
+
outerHtml: false,
|
|
1954
|
+
prettyHtml: opts.prettyHtml,
|
|
1955
|
+
removeAttributeQuotes: opts.removeAttributeQuotes,
|
|
1956
|
+
removeBooleanAttributeQuotes: opts.removeBooleanAttributeQuotes,
|
|
1957
|
+
removeEmptyAttributes: opts.removeEmptyAttributes,
|
|
1958
|
+
removeHtmlComments: opts.removeHtmlComments,
|
|
1959
|
+
serializeShadowRoot: opts.serializeShadowRoot,
|
|
1960
|
+
fullDocument: opts.fullDocument
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
function isValidDocument(doc) {
|
|
1964
|
+
return doc != null && doc.nodeType === 9 && doc.documentElement != null && doc.documentElement.nodeType === 1 && doc.body != null && doc.body.nodeType === 1;
|
|
1965
|
+
}
|
|
1966
|
+
function removeScripts(elm) {
|
|
1967
|
+
const children = elm.children;
|
|
1968
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
1969
|
+
const child = children[i];
|
|
1970
|
+
removeScripts(child);
|
|
1971
|
+
if (child.nodeName === "SCRIPT" || child.nodeName === "LINK" && child.getAttribute("rel") === "modulepreload") child.remove();
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
//#endregion
|
|
1976
|
+
export { createWindowFromHtml, deserializeProperty, hydrateDocument, renderToString, serializeDocumentToString, serializeProperty, setTagTransformer, streamToString, transformTag };
|