@weapp-vite/web 1.3.26 → 1.3.28
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/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/compiler/wxml/attributes.mjs +8 -0
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs +8 -0
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/dependency.mjs +8 -0
- package/dist/compiler/wxml/dependency.mjs.map +1 -1
- package/dist/compiler/wxml/interpolation.mjs +8 -0
- package/dist/compiler/wxml/interpolation.mjs.map +1 -1
- package/dist/compiler/wxml/navigation.mjs +8 -0
- package/dist/compiler/wxml/navigation.mjs.map +1 -1
- package/dist/compiler/wxml/parser.mjs +8 -0
- package/dist/compiler/wxml/parser.mjs.map +1 -1
- package/dist/compiler/wxml/renderer.mjs +8 -0
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +8 -0
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/compiler/wxs.mjs +8 -0
- package/dist/compiler/wxs.mjs.map +1 -1
- package/dist/css/wxss.d.mts +2 -0
- package/dist/css/wxss.mjs +8 -0
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +8 -0
- package/dist/plugin/constants.mjs +8 -0
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/entry.mjs +8 -0
- package/dist/plugin/entry.mjs.map +1 -1
- package/dist/plugin/files.mjs +8 -0
- package/dist/plugin/files.mjs.map +1 -1
- package/dist/plugin/index.d.mts +2 -0
- package/dist/plugin/index.mjs +8 -0
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/navigation.mjs +8 -0
- package/dist/plugin/navigation.mjs.map +1 -1
- package/dist/plugin/path.mjs +8 -0
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/register.mjs +8 -0
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/scan.mjs +8 -0
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/scanConfig.mjs +8 -0
- package/dist/plugin/scanConfig.mjs.map +1 -1
- package/dist/plugin/state.mjs +8 -0
- package/dist/plugin/state.mjs.map +1 -1
- package/dist/plugin/types.d.mts +2 -0
- package/dist/plugin.d.mts +2 -0
- package/dist/plugin.mjs +8 -0
- package/dist/runtime/button/helpers.mjs +8 -0
- package/dist/runtime/button/helpers.mjs.map +1 -1
- package/dist/runtime/button/index.d.mts +2 -0
- package/dist/runtime/button/index.mjs +8 -0
- package/dist/runtime/button/index.mjs.map +1 -1
- package/dist/runtime/button/style.mjs +8 -0
- package/dist/runtime/button/style.mjs.map +1 -1
- package/dist/runtime/component/behavior.mjs +8 -0
- package/dist/runtime/component/behavior.mjs.map +1 -1
- package/dist/runtime/component/constants.mjs +8 -0
- package/dist/runtime/component/constants.mjs.map +1 -1
- package/dist/runtime/component/dom.mjs +8 -0
- package/dist/runtime/component/dom.mjs.map +1 -1
- package/dist/runtime/component/element.mjs +8 -0
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/events.mjs +8 -0
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/component/index.d.mts +2 -0
- package/dist/runtime/component/index.mjs +8 -0
- package/dist/runtime/component/index.mjs.map +1 -1
- package/dist/runtime/component/state.mjs +8 -0
- package/dist/runtime/component/state.mjs.map +1 -1
- package/dist/runtime/component/types.d.mts +2 -0
- package/dist/runtime/component/utils.mjs +8 -0
- package/dist/runtime/component/utils.mjs.map +1 -1
- package/dist/runtime/execution.d.mts +2 -0
- package/dist/runtime/execution.mjs +8 -0
- package/dist/runtime/execution.mjs.map +1 -1
- package/dist/runtime/index.d.mts +2 -0
- package/dist/runtime/index.mjs +8 -0
- package/dist/runtime/legacyTemplate/dom.mjs +8 -0
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/expression.mjs +8 -0
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.d.mts +2 -0
- package/dist/runtime/legacyTemplate/index.mjs +8 -0
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/types.d.mts +2 -0
- package/dist/runtime/navigationBar/index.d.mts +2 -0
- package/dist/runtime/navigationBar/index.mjs +8 -0
- package/dist/runtime/navigationBar/index.mjs.map +1 -1
- package/dist/runtime/navigationBar/style.mjs +8 -0
- package/dist/runtime/navigationBar/style.mjs.map +1 -1
- package/dist/runtime/polyfill/ad.mjs +8 -0
- package/dist/runtime/polyfill/ad.mjs.map +1 -1
- package/dist/runtime/polyfill/appState.mjs +8 -0
- package/dist/runtime/polyfill/appState.mjs.map +1 -1
- package/dist/runtime/polyfill/async.mjs +8 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -1
- package/dist/runtime/polyfill/auth.mjs +8 -0
- package/dist/runtime/polyfill/auth.mjs.map +1 -1
- package/dist/runtime/polyfill/authApi.mjs +8 -0
- package/dist/runtime/polyfill/authApi.mjs.map +1 -1
- package/dist/runtime/polyfill/background.mjs +8 -0
- package/dist/runtime/polyfill/background.mjs.map +1 -1
- package/dist/runtime/polyfill/canvasContext.mjs +8 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
- package/dist/runtime/polyfill/capability.mjs +8 -0
- package/dist/runtime/polyfill/capability.mjs.map +1 -1
- package/dist/runtime/polyfill/cloud.mjs +8 -0
- package/dist/runtime/polyfill/cloud.mjs.map +1 -1
- package/dist/runtime/polyfill/device.mjs +8 -0
- package/dist/runtime/polyfill/device.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.mjs +8 -0
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +2 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +8 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/filePicker.mjs +8 -0
- package/dist/runtime/polyfill/filePicker.mjs.map +1 -1
- package/dist/runtime/polyfill/fileSystemManager.mjs +8 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
- package/dist/runtime/polyfill/files.mjs +8 -0
- package/dist/runtime/polyfill/files.mjs.map +1 -1
- package/dist/runtime/polyfill/index.d.mts +2 -0
- package/dist/runtime/polyfill/index.mjs +8 -0
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interaction.mjs +8 -0
- package/dist/runtime/polyfill/interaction.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +8 -0
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/location.mjs +8 -0
- package/dist/runtime/polyfill/location.mjs.map +1 -1
- package/dist/runtime/polyfill/locationApi.mjs +8 -0
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaActions.mjs +8 -0
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +8 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/info.mjs +8 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/picker.mjs +8 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs +8 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs +8 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaInfo.mjs +8 -0
- package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaPicker.mjs +8 -0
- package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaProcess.mjs +8 -0
- package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +8 -0
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +8 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/network/request.mjs +8 -0
- package/dist/runtime/polyfill/network/request.mjs.map +1 -1
- package/dist/runtime/polyfill/network/requestBridge.mjs +8 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -1
- package/dist/runtime/polyfill/network/status.mjs +8 -0
- package/dist/runtime/polyfill/network/status.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +8 -0
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
- package/dist/runtime/polyfill/platformRuntime.mjs +8 -0
- package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +8 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +8 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +2 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs +8 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/url.mjs +8 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime.d.mts +2 -0
- package/dist/runtime/polyfill/routeRuntime.mjs +8 -0
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +8 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +2 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs +8 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeInfra.mjs +8 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeOps.mjs +8 -0
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/selectorQuery.mjs +8 -0
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.mjs +8 -0
- package/dist/runtime/polyfill/storage.mjs.map +1 -1
- package/dist/runtime/polyfill/storageAsync.mjs +8 -0
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/subscribe.mjs +8 -0
- package/dist/runtime/polyfill/subscribe.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +8 -0
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs +8 -0
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/types/base.d.mts +2 -0
- package/dist/runtime/polyfill/types/common.d.mts +2 -0
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +2 -0
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +2 -0
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +2 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +2 -0
- package/dist/runtime/polyfill/ui.mjs +8 -0
- package/dist/runtime/polyfill/ui.mjs.map +1 -1
- package/dist/runtime/polyfill/uiFeedback.mjs +8 -0
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.d.mts +2 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs +8 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/runtime/polyfill/videoContext.mjs +8 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
- package/dist/runtime/polyfill/vkSession.mjs +8 -0
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
- package/dist/runtime/polyfill/windowResize.mjs +8 -0
- package/dist/runtime/polyfill/windowResize.mjs.map +1 -1
- package/dist/runtime/polyfill/worker.mjs +8 -0
- package/dist/runtime/polyfill/worker.mjs.map +1 -1
- package/dist/runtime/polyfill.d.mts +2 -0
- package/dist/runtime/renderContext.d.mts +2 -0
- package/dist/runtime/renderContext.mjs +8 -0
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.d.mts +2 -0
- package/dist/runtime/rpx.mjs +8 -0
- package/dist/runtime/rpx.mjs.map +1 -1
- package/dist/runtime/style.d.mts +2 -0
- package/dist/runtime/style.mjs +8 -0
- package/dist/runtime/style.mjs.map +1 -1
- package/dist/runtime/template.d.mts +2 -0
- package/dist/runtime/utils/object.mjs +8 -0
- package/dist/runtime/utils/object.mjs.map +1 -1
- package/dist/runtime/warning.d.mts +2 -0
- package/dist/runtime/warning.mjs +8 -0
- package/dist/runtime/warning.mjs.map +1 -1
- package/dist/shared/slugify.mjs +8 -0
- package/dist/shared/slugify.mjs.map +1 -1
- package/dist/shared/wxml.mjs +8 -0
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/component/dom.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { getMiniProgramRuntimeGlobalKeys } from '@weapp-core/shared'\n\ntype QueryRoot = ParentNode & {\n querySelector?: ParentNode['querySelector']\n querySelectorAll?: ParentNode['querySelectorAll']\n}\n\ninterface MiniProgramRuntimeGlobal {\n createSelectorQuery?: () => {\n in?: (context: unknown) => unknown\n }\n}\n\nconst MINI_PROGRAM_RUNTIME_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys()\n\nexport function resolveQueryRoot(instance: ComponentPublicInstance & { renderRoot?: ParentNode }): QueryRoot {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as QueryRoot\n}\n\nexport function resolveRenderRoot(instance: ComponentPublicInstance & { renderRoot?: HTMLElement | ShadowRoot }) {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as HTMLElement | ShadowRoot\n}\n\nexport function createScopedSelectorQuery(instance: ComponentPublicInstance) {\n const runtime = globalThis as unknown as Partial<Record<string, MiniProgramRuntimeGlobal | undefined>>\n for (const globalKey of MINI_PROGRAM_RUNTIME_GLOBAL_KEYS) {\n const query = runtime[globalKey]?.createSelectorQuery?.()\n if (query && typeof query.in === 'function') {\n return query.in(instance)\n }\n if (query) {\n return query\n }\n }\n return undefined\n}\n\nexport function selectRuntimeComponent(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelector !== 'function') {\n return null\n }\n return root.querySelector(selector) as ComponentPublicInstance | null\n}\n\nexport function selectRuntimeComponents(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelectorAll !== 'function') {\n return []\n }\n return Array.from(root.querySelectorAll(selector)) as ComponentPublicInstance[]\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/component/dom.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { getMiniProgramRuntimeGlobalKeys } from '@weapp-core/shared'\n\ntype QueryRoot = ParentNode & {\n querySelector?: ParentNode['querySelector']\n querySelectorAll?: ParentNode['querySelectorAll']\n}\n\ninterface MiniProgramRuntimeGlobal {\n createSelectorQuery?: () => {\n in?: (context: unknown) => unknown\n }\n}\n\nconst MINI_PROGRAM_RUNTIME_GLOBAL_KEYS = getMiniProgramRuntimeGlobalKeys()\n\nexport function resolveQueryRoot(instance: ComponentPublicInstance & { renderRoot?: ParentNode }): QueryRoot {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as QueryRoot\n}\n\nexport function resolveRenderRoot(instance: ComponentPublicInstance & { renderRoot?: HTMLElement | ShadowRoot }) {\n return (instance.renderRoot ?? instance.shadowRoot ?? instance) as HTMLElement | ShadowRoot\n}\n\nexport function createScopedSelectorQuery(instance: ComponentPublicInstance) {\n const runtime = globalThis as unknown as Partial<Record<string, MiniProgramRuntimeGlobal | undefined>>\n for (const globalKey of MINI_PROGRAM_RUNTIME_GLOBAL_KEYS) {\n const query = runtime[globalKey]?.createSelectorQuery?.()\n if (query && typeof query.in === 'function') {\n return query.in(instance)\n }\n if (query) {\n return query\n }\n }\n return undefined\n}\n\nexport function selectRuntimeComponent(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelector !== 'function') {\n return null\n }\n return root.querySelector(selector) as ComponentPublicInstance | null\n}\n\nexport function selectRuntimeComponents(instance: ComponentPublicInstance & { renderRoot?: ParentNode }, selector: string) {\n const root = resolveQueryRoot(instance)\n if (!selector || typeof root.querySelectorAll !== 'function') {\n return []\n }\n return Array.from(root.querySelectorAll(selector)) as ComponentPublicInstance[]\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,mCAAmC,gCAAgC;AAEzE,SAAgB,iBAAiB,UAA4E;CAC3G,OAAQ,SAAS,cAAc,SAAS,cAAc;AACxD;AAEA,SAAgB,kBAAkB,UAA+E;CAC/G,OAAQ,SAAS,cAAc,SAAS,cAAc;AACxD;AAEA,SAAgB,0BAA0B,UAAmC;CAC3E,MAAM,UAAU;CAChB,KAAK,MAAM,aAAa,kCAAkC;EACxD,MAAM,QAAQ,QAAQ,YAAY,sBAAsB;EACxD,IAAI,SAAS,OAAO,MAAM,OAAO,YAC/B,OAAO,MAAM,GAAG,QAAQ;EAE1B,IAAI,OACF,OAAO;CAEX;AAEF;AAEA,SAAgB,uBAAuB,UAAiE,UAAkB;CACxH,MAAM,OAAO,iBAAiB,QAAQ;CACtC,IAAI,CAAC,YAAY,OAAO,KAAK,kBAAkB,YAC7C,OAAO;CAET,OAAO,KAAK,cAAc,QAAQ;AACpC;AAEA,SAAgB,wBAAwB,UAAiE,UAAkB;CACzH,MAAM,OAAO,iBAAiB,QAAQ;CACtC,IAAI,CAAC,YAAY,OAAO,KAAK,qBAAqB,YAChD,OAAO,CAAC;CAEV,OAAO,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AACnD"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { supportsLit } from "./constants.mjs";
|
|
2
10
|
import { createRenderContext } from "../renderContext.mjs";
|
|
3
11
|
import { hasOwn } from "../utils/object.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.mjs","names":["#properties","#state","#methods","#syncMethods","#setProperty","#applyDataPatch","#applyAttributes","#runInitialObservers","#isMounted","#renderLegacy","#readyFired","#usesLegacyTemplate","#renderContext","#observedKeys","#observerInitDone"],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n DataRecord,\n PageLifeTimeHooks,\n} from './types'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createRenderContext } from '../renderContext'\nimport { hasOwn } from '../utils/object'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { cloneValue, coerceValue, toCamelCase } from './utils'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n class WeappWebComponent extends BaseElement implements WeappComponentInstance {\n static observedAttributes = runtimeState.observedAttributes\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any>\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = typeof runtimeState.componentRef.data === 'function'\n ? (runtimeState.componentRef.data as () => DataRecord)()\n : (runtimeState.componentRef.data ?? {})\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n this.#methods = {}\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this)\n }\n\n setData(patch: DataRecord) {\n this.#applyDataPatch(patch)\n }\n\n triggerEvent(name: string, detail?: any) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n connectedCallback() {\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this)\n this.#isMounted = true\n if (!supportsLit) {\n this.#renderLegacy()\n }\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n\n updated() {\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const styleMarkup = runtimeState.styleRef\n ? html`<style>${runtimeState.styleRef}</style>`\n : null\n if (typeof result === 'string') {\n this.#usesLegacyTemplate = true\n return html`${styleMarkup}${unsafeHTML(result)}`\n }\n this.#usesLegacyTemplate = false\n if (styleMarkup) {\n return html`${styleMarkup}${result as any}`\n }\n return result\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return\n }\n let changed = false\n for (const [key, value] of Object.entries(patch)) {\n if (this.#state[key] === value) {\n continue\n }\n const oldValue = this.#state[key]\n this.#state[key] = value\n if (hasOwn(this.#properties, key)) {\n this.#properties[key] = value\n const propOption = runtimeState.componentRef.properties?.[key]\n if (propOption?.observer) {\n propOption.observer.call(this, value, oldValue)\n this.#observedKeys.add(key)\n }\n }\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n }\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n if (propOption?.observer) {\n propOption.observer.call(this, coerced, oldValue)\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this)\n }\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n this.#methods[key] = fn\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : ''\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,4BAA4B,EAC1C,aACA,cACA,aACiE;CACjE,MAAM,0BAA0B,YAA8C;EAC5E,OAAO,qBAAqB,aAAa;EAEzC;EACA;EACA;EACA,aAAa;EACb,iBAAiB,oBAAoB,MAAM,CAAC,CAAC;EAC7C,sBAAsB;EACtB,cAAc;EACd,oBAAoB;EACpB,gCAAgB,IAAI,IAAY;EAChC,AAAS;EACT,AAAS;EAET,cAAc;GACZ,MAAM;GACN,MAAM,aAAa,OAAO,aAAa,aAAa,SAAS,aACxD,aAAa,aAAa,KAA0B,IACpD,aAAa,aAAa,QAAQ,CAAC;GACxC,KAAKA,cAAc,EAAE,GAAG,aAAa,sBAAsB;GAC3D,KAAK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AACT"}
|
|
1
|
+
{"version":3,"file":"element.mjs","names":["#properties","#state","#methods","#syncMethods","#setProperty","#applyDataPatch","#applyAttributes","#runInitialObservers","#isMounted","#renderLegacy","#readyFired","#usesLegacyTemplate","#renderContext","#observedKeys","#observerInitDone"],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n DataRecord,\n PageLifeTimeHooks,\n} from './types'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createRenderContext } from '../renderContext'\nimport { hasOwn } from '../utils/object'\nimport { supportsLit } from './constants'\nimport {\n createScopedSelectorQuery,\n resolveRenderRoot,\n selectRuntimeComponent,\n selectRuntimeComponents,\n} from './dom'\nimport { bindRuntimeEvents } from './events'\nimport { cloneValue, coerceValue, toCamelCase } from './utils'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n class WeappWebComponent extends BaseElement implements WeappComponentInstance {\n static observedAttributes = runtimeState.observedAttributes\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any>\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = typeof runtimeState.componentRef.data === 'function'\n ? (runtimeState.componentRef.data as () => DataRecord)()\n : (runtimeState.componentRef.data ?? {})\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n this.#methods = {}\n this.#syncMethods(runtimeState.componentRef.methods ?? {})\n Object.defineProperties(this, {\n data: {\n configurable: true,\n enumerable: true,\n get: () => this.#state,\n },\n properties: {\n configurable: true,\n enumerable: true,\n get: () => this.#properties,\n },\n })\n for (const [propName] of runtimeState.propertyEntries) {\n Object.defineProperty(this, propName, {\n configurable: true,\n enumerable: true,\n get: () => this.#state[propName],\n set: value => this.#setProperty(propName, value),\n })\n }\n if (!supportsLit) {\n const host = this as unknown as HTMLElement\n if (!host.shadowRoot && typeof host.attachShadow === 'function') {\n host.attachShadow({ mode: 'open' })\n }\n ;(this as any).renderRoot = host.shadowRoot ?? host\n }\n instances.add(this)\n runtimeState.lifetimes.created?.call(this)\n }\n\n setData(patch: DataRecord) {\n this.#applyDataPatch(patch)\n }\n\n triggerEvent(name: string, detail?: any) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n selectComponent(selector: string) {\n return selectRuntimeComponent(this, selector)\n }\n\n selectAllComponents(selector: string) {\n return selectRuntimeComponents(this, selector)\n }\n\n connectedCallback() {\n const superConnected = (BaseElement.prototype as { connectedCallback?: () => void }).connectedCallback\n if (supportsLit && typeof superConnected === 'function') {\n superConnected.call(this)\n }\n this.#applyAttributes()\n if (runtimeState.observerInitEnabled) {\n this.#runInitialObservers()\n }\n runtimeState.lifetimes.attached?.call(this)\n this.#isMounted = true\n if (!supportsLit) {\n this.#renderLegacy()\n }\n }\n\n disconnectedCallback() {\n const superDisconnected = (BaseElement.prototype as { disconnectedCallback?: () => void }).disconnectedCallback\n if (supportsLit && typeof superDisconnected === 'function') {\n superDisconnected.call(this)\n }\n this.#isMounted = false\n instances.delete(this)\n runtimeState.lifetimes.detached?.call(this)\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n const superAttributeChanged = (BaseElement.prototype as {\n attributeChangedCallback?: (name: string, oldValue: string | null, newValue: string | null) => void\n }).attributeChangedCallback\n if (supportsLit && typeof superAttributeChanged === 'function') {\n superAttributeChanged.call(this, attrName, oldValue, newValue)\n }\n const propName = toCamelCase(attrName)\n if (!hasOwn(this.#properties, propName)) {\n return\n }\n const propOption = runtimeState.componentRef.properties?.[propName]\n this.#setProperty(propName, coerceValue(newValue, propOption?.type))\n }\n\n firstUpdated() {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n\n updated() {\n if (this.#usesLegacyTemplate) {\n bindRuntimeEvents(resolveRenderRoot(this), this.#methods, this)\n }\n }\n\n render() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const styleMarkup = runtimeState.styleRef\n ? html`<style>${runtimeState.styleRef}</style>`\n : null\n if (typeof result === 'string') {\n this.#usesLegacyTemplate = true\n return html`${styleMarkup}${unsafeHTML(result)}`\n }\n this.#usesLegacyTemplate = false\n if (styleMarkup) {\n return html`${styleMarkup}${result as any}`\n }\n return result\n }\n\n requestUpdate(name?: PropertyKey, oldValue?: unknown, options?: unknown) {\n const superRequestUpdate = (BaseElement.prototype as any).requestUpdate\n if (supportsLit && typeof superRequestUpdate === 'function') {\n return superRequestUpdate.call(this, name, oldValue, options)\n }\n if (this.#isMounted) {\n this.#renderLegacy()\n }\n return undefined\n }\n\n #applyAttributes() {\n if (!this.attributes || typeof this.attributes[Symbol.iterator] !== 'function') {\n return\n }\n for (const attr of this.attributes) {\n this.attributeChangedCallback(attr.name, null, attr.value)\n }\n }\n\n #applyDataPatch(patch: DataRecord) {\n if (!patch || typeof patch !== 'object') {\n return\n }\n let changed = false\n for (const [key, value] of Object.entries(patch)) {\n if (this.#state[key] === value) {\n continue\n }\n const oldValue = this.#state[key]\n this.#state[key] = value\n if (hasOwn(this.#properties, key)) {\n this.#properties[key] = value\n const propOption = runtimeState.componentRef.properties?.[key]\n if (propOption?.observer) {\n propOption.observer.call(this, value, oldValue)\n this.#observedKeys.add(key)\n }\n }\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n }\n }\n\n #setProperty(name: string, value: any) {\n const propOption = runtimeState.componentRef.properties?.[name]\n const coerced = coerceValue(value, propOption?.type)\n const oldValue = this.#properties[name]\n if (oldValue === coerced) {\n return\n }\n this.#properties[name] = coerced\n this.#state[name] = coerced\n if (this.#isMounted) {\n this.requestUpdate()\n }\n if (propOption?.observer) {\n propOption.observer.call(this, coerced, oldValue)\n this.#observedKeys.add(name)\n }\n }\n\n #runInitialObservers() {\n if (this.#observerInitDone) {\n return\n }\n this.#observerInitDone = true\n for (const [propName, propOption] of runtimeState.propertyEntries) {\n if (!propOption.observer || this.#observedKeys.has(propName)) {\n continue\n }\n const value = this.#state[propName]\n propOption.observer.call(this, value, undefined)\n this.#observedKeys.add(propName)\n }\n }\n\n #syncMethods(nextMethods: ComponentOptions['methods']) {\n const resolved = nextMethods ?? {}\n const bound: Record<string, (event: any) => any> = {}\n for (const [name, fn] of Object.entries(resolved)) {\n if (typeof fn === 'function') {\n bound[name] = fn.bind(this)\n }\n }\n for (const key of Object.keys(this.#methods)) {\n if (!(key in bound)) {\n delete this.#methods[key]\n }\n }\n for (const [key, fn] of Object.entries(bound)) {\n this.#methods[key] = fn\n }\n this.#renderContext = createRenderContext(this, this.#methods)\n }\n\n __weappSync(nextMethods: ComponentOptions['methods']) {\n this.#syncMethods(nextMethods)\n this.requestUpdate()\n }\n\n __weappInvokePageLifetime(type: keyof PageLifeTimeHooks) {\n const hook = runtimeState.pageLifetimes[type]\n if (typeof hook === 'function') {\n hook.call(this)\n }\n }\n\n #renderLegacy() {\n const result = runtimeState.templateRef(this.#state, this.#renderContext)\n const root = resolveRenderRoot(this)\n const styleMarkup = runtimeState.styleRef ? `<style>${runtimeState.styleRef}</style>` : ''\n if (typeof result === 'string') {\n root.innerHTML = `${styleMarkup}${result}`\n bindRuntimeEvents(root as ShadowRoot, this.#methods, this)\n }\n else if (result == null) {\n root.innerHTML = styleMarkup\n }\n else {\n root.innerHTML = `${styleMarkup}${String(result)}`\n }\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this)\n this.#readyFired = true\n }\n }\n }\n\n return WeappW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AClB,KAAK,KAAK,IAAI;EAElB;EAEA,gBAAgB;GACd,MAAM,SAAS,aAAa,YAAY,KAAKF,QAAQ,KAAKW,cAAc;GACxE,MAAM,OAAO,kBAAkB,IAAI;GACnC,MAAM,cAAc,aAAa,WAAW,UAAU,aAAa,SAAS,YAAY;GACxF,IAAI,OAAO,WAAW,UAAU;IAC9B,KAAK,YAAY,GAAG,cAAc;IAClC,kBAAkB,MAAoB,KAAKV,UAAU,IAAI;GAC3D,OACK,IAAI,UAAU,MACjB,KAAK,YAAY;QAGjB,KAAK,YAAY,GAAG,cAAc,OAAO,MAAM;GAEjD,IAAI,CAAC,KAAKQ,aAAa;IACrB,aAAa,UAAU,OAAO,KAAK,IAAI;IACvC,KAAKA,cAAc;GACrB;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES } from "./constants.mjs";
|
|
2
10
|
|
|
3
11
|
//#region src/runtime/component/events.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport {\n EVENT_ATTRIBUTE_PREFIXES,\n EVENT_FLAG_ATTRIBUTE_PREFIXES,\n} from './constants'\n\nfunction parseEventFlags(value: string | null) {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n for (const attribute of element.getAttributeNames()) {\n const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find(prefix => attribute.startsWith(prefix))\n if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some(prefix => attribute.startsWith(prefix))) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const eventName = attribute.slice(matchedPrefix.length)\n const flagAttributeValue = EVENT_FLAG_ATTRIBUTE_PREFIXES\n .map(prefix => element.getAttribute(`${prefix}${eventName}`))\n .find(value => value !== null) ?? null\n const flags = parseEventFlags(flagAttributeValue)\n element.addEventListener(eventName, (nativeEvent) => {\n if (flags.catch) {\n nativeEvent.stopPropagation()\n }\n const dataset = { ...element.dataset }\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }, flags.capture)\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport {\n EVENT_ATTRIBUTE_PREFIXES,\n EVENT_FLAG_ATTRIBUTE_PREFIXES,\n} from './constants'\n\nfunction parseEventFlags(value: string | null) {\n if (!value) {\n return { catch: false, capture: false }\n }\n const tokens = value.split(',').map(token => token.trim()).filter(Boolean)\n const tokenSet = new Set(tokens)\n return {\n catch: tokenSet.has('catch'),\n capture: tokenSet.has('capture'),\n }\n}\n\nexport function bindRuntimeEvents(\n root: HTMLElement | ShadowRoot,\n methods: Record<string, (event: any) => any>,\n instance: ComponentPublicInstance,\n) {\n if (typeof document === 'undefined') {\n return\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)\n while (walker.nextNode()) {\n const element = walker.currentNode as HTMLElement\n for (const attribute of element.getAttributeNames()) {\n const matchedPrefix = EVENT_ATTRIBUTE_PREFIXES.find(prefix => attribute.startsWith(prefix))\n if (!matchedPrefix || EVENT_FLAG_ATTRIBUTE_PREFIXES.some(prefix => attribute.startsWith(prefix))) {\n continue\n }\n const handlerName = element.getAttribute(attribute)\n if (!handlerName) {\n continue\n }\n const handler = methods[handlerName]\n if (!handler) {\n continue\n }\n const eventName = attribute.slice(matchedPrefix.length)\n const flagAttributeValue = EVENT_FLAG_ATTRIBUTE_PREFIXES\n .map(prefix => element.getAttribute(`${prefix}${eventName}`))\n .find(value => value !== null) ?? null\n const flags = parseEventFlags(flagAttributeValue)\n element.addEventListener(eventName, (nativeEvent) => {\n if (flags.catch) {\n nativeEvent.stopPropagation()\n }\n const dataset = { ...element.dataset }\n const syntheticEvent = {\n type: eventName,\n timeStamp: nativeEvent.timeStamp,\n detail: (nativeEvent as CustomEvent).detail ?? (nativeEvent as InputEvent).data ?? undefined,\n target: {\n dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }, flags.capture)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAS,gBAAgB,OAAsB;CAC7C,IAAI,CAAC,OACH,OAAO;EAAE,OAAO;EAAO,SAAS;CAAM;CAExC,MAAM,SAAS,MAAM,MAAM,GAAG,EAAE,KAAI,UAAS,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO;CACzE,MAAM,WAAW,IAAI,IAAI,MAAM;CAC/B,OAAO;EACL,OAAO,SAAS,IAAI,OAAO;EAC3B,SAAS,SAAS,IAAI,SAAS;CACjC;AACF;AAEA,SAAgB,kBACd,MACA,SACA,UACA;CACA,IAAI,OAAO,aAAa,aACtB;CAEF,MAAM,SAAS,SAAS,iBAAiB,MAAM,WAAW,YAAY;CACtE,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,KAAK,MAAM,aAAa,QAAQ,kBAAkB,GAAG;GACnD,MAAM,gBAAgB,yBAAyB,MAAK,WAAU,UAAU,WAAW,MAAM,CAAC;GAC1F,IAAI,CAAC,iBAAiB,8BAA8B,MAAK,WAAU,UAAU,WAAW,MAAM,CAAC,GAC7F;GAEF,MAAM,cAAc,QAAQ,aAAa,SAAS;GAClD,IAAI,CAAC,aACH;GAEF,MAAM,UAAU,QAAQ;GACxB,IAAI,CAAC,SACH;GAEF,MAAM,YAAY,UAAU,MAAM,cAAc,MAAM;GAItD,MAAM,QAAQ,gBAHa,8BACxB,KAAI,WAAU,QAAQ,aAAa,GAAG,SAAS,WAAW,CAAC,EAC3D,MAAK,UAAS,UAAU,IAAI,KAAK,IACY;GAChD,QAAQ,iBAAiB,YAAY,gBAAgB;IACnD,IAAI,MAAM,OACR,YAAY,gBAAgB;IAE9B,MAAM,UAAU,EAAE,GAAG,QAAQ,QAAQ;IACrC,MAAM,iBAAiB;KACrB,MAAM;KACN,WAAW,YAAY;KACvB,QAAS,YAA4B,UAAW,YAA2B,QAAQ;KACnF,QAAQ,EACN,QACF;KACA,eAAe,EACb,QACF;KACA,eAAe;IACjB;IACA,QAAQ,KAAK,UAAU,cAAc;GACvC,GAAG,MAAM,OAAO;EAClB;CACF;AACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
1
3
|
import { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DefineComponentOptions, PropertyOption } from "./types.mjs";
|
|
2
4
|
|
|
3
5
|
//#region src/runtime/component/index.d.ts
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { emitRuntimeWarning } from "../warning.mjs";
|
|
2
10
|
import { FallbackElement, supportsLit } from "./constants.mjs";
|
|
3
11
|
import { createComponentElementClass } from "./element.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/component/index.ts"],"sourcesContent":["import type { WeappComponentInstance } from './element'\nimport type { ComponentConstructor, DefineComponentOptions } from './types'\nimport { LitElement } from 'lit'\nimport { emitRuntimeWarning } from '../warning'\nimport { FallbackElement, supportsLit } from './constants'\nimport { createComponentElementClass } from './element'\nimport { createComponentRuntimeState, updateComponentRuntimeState } from './state'\n\nfunction emitBehaviorWarnings(warnings: string[]): void {\n for (const warning of warnings) {\n emitRuntimeWarning(warning, {\n key: `component-behaviors:${warning}`,\n context: 'runtime:component',\n })\n }\n}\n\nexport function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor {\n if (!options || typeof options !== 'object') {\n throw new TypeError('[@weapp-vite/web] defineComponent 需要提供配置对象。')\n }\n\n const existing = customElements.get(tagName) as ComponentConstructor | undefined\n if (existing) {\n existing.__weappUpdate?.(options)\n return existing\n }\n\n if (!options.template) {\n throw new Error('[@weapp-vite/web] defineComponent 需要提供模板渲染函数。')\n }\n\n const BaseElement = (supportsLit ? LitElement : (globalThis.HTMLElement ?? FallbackElement)) as typeof HTMLElement\n const { state: runtimeState, warnings } = createComponentRuntimeState(options)\n emitBehaviorWarnings(warnings)\n\n const instances = new Set<WeappComponentInstance>()\n const WeappWebComponent = createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n })\n\n const updateComponent = (nextOptions: DefineComponentOptions) => {\n if (!nextOptions?.template) {\n return\n }\n const { warnings: nextWarnings, nextMethods } = updateComponentRuntimeState(runtimeState, nextOptions)\n emitBehaviorWarnings(nextWarnings)\n for (const instance of instances) {\n instance.__weappSync(nextMethods)\n }\n }\n\n ;(WeappWebComponent as ComponentConstructor).__weappUpdate = updateComponent\n\n customElements.define(tagName, WeappWebComponent)\n return WeappWebComponent\n}\n\nexport type {\n ComponentOptions,\n ComponentPublicInstance,\n DefineComponentOptions,\n PropertyOption,\n} from './types'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/component/index.ts"],"sourcesContent":["import type { WeappComponentInstance } from './element'\nimport type { ComponentConstructor, DefineComponentOptions } from './types'\nimport { LitElement } from 'lit'\nimport { emitRuntimeWarning } from '../warning'\nimport { FallbackElement, supportsLit } from './constants'\nimport { createComponentElementClass } from './element'\nimport { createComponentRuntimeState, updateComponentRuntimeState } from './state'\n\nfunction emitBehaviorWarnings(warnings: string[]): void {\n for (const warning of warnings) {\n emitRuntimeWarning(warning, {\n key: `component-behaviors:${warning}`,\n context: 'runtime:component',\n })\n }\n}\n\nexport function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor {\n if (!options || typeof options !== 'object') {\n throw new TypeError('[@weapp-vite/web] defineComponent 需要提供配置对象。')\n }\n\n const existing = customElements.get(tagName) as ComponentConstructor | undefined\n if (existing) {\n existing.__weappUpdate?.(options)\n return existing\n }\n\n if (!options.template) {\n throw new Error('[@weapp-vite/web] defineComponent 需要提供模板渲染函数。')\n }\n\n const BaseElement = (supportsLit ? LitElement : (globalThis.HTMLElement ?? FallbackElement)) as typeof HTMLElement\n const { state: runtimeState, warnings } = createComponentRuntimeState(options)\n emitBehaviorWarnings(warnings)\n\n const instances = new Set<WeappComponentInstance>()\n const WeappWebComponent = createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n })\n\n const updateComponent = (nextOptions: DefineComponentOptions) => {\n if (!nextOptions?.template) {\n return\n }\n const { warnings: nextWarnings, nextMethods } = updateComponentRuntimeState(runtimeState, nextOptions)\n emitBehaviorWarnings(nextWarnings)\n for (const instance of instances) {\n instance.__weappSync(nextMethods)\n }\n }\n\n ;(WeappWebComponent as ComponentConstructor).__weappUpdate = updateComponent\n\n customElements.define(tagName, WeappWebComponent)\n return WeappWebComponent\n}\n\nexport type {\n ComponentOptions,\n ComponentPublicInstance,\n DefineComponentOptions,\n PropertyOption,\n} from './types'\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAS,qBAAqB,UAA0B;CACtD,KAAK,MAAM,WAAW,UACpB,mBAAmB,SAAS;EAC1B,KAAK,uBAAuB;EAC5B,SAAS;CACX,CAAC;AAEL;AAEA,SAAgB,gBAAgB,SAAiB,SAAuD;CACtG,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,MAAM,IAAI,UAAU,6CAA6C;CAGnE,MAAM,WAAW,eAAe,IAAI,OAAO;CAC3C,IAAI,UAAU;EACZ,SAAS,gBAAgB,OAAO;EAChC,OAAO;CACT;CAEA,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,MAAM,+CAA+C;CAGjE,MAAM,cAAe,cAAc,aAAc,WAAW,eAAe;CAC3E,MAAM,EAAE,OAAO,cAAc,aAAa,4BAA4B,OAAO;CAC7E,qBAAqB,QAAQ;CAE7B,MAAM,4BAAY,IAAI,IAA4B;CAClD,MAAM,oBAAoB,4BAA4B;EACpD;EACA;EACA;CACF,CAAC;CAED,MAAM,mBAAmB,gBAAwC;EAC/D,IAAI,CAAC,aAAa,UAChB;EAEF,MAAM,EAAE,UAAU,cAAc,gBAAgB,4BAA4B,cAAc,WAAW;EACrG,qBAAqB,YAAY;EACjC,KAAK,MAAM,YAAY,WACrB,SAAS,YAAY,WAAW;CAEpC;CAEC,AAAC,kBAA2C,gBAAgB;CAE7D,eAAe,OAAO,SAAS,iBAAiB;CAChD,OAAO;AACT"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { hasOwn } from "../utils/object.mjs";
|
|
2
10
|
import { cloneValue, hyphenate } from "./utils.mjs";
|
|
3
11
|
import { normalizeBehaviors } from "./behavior.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n PageLifeTimeHooks,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef: ComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions | undefined) {\n const normalized = normalizeBehaviors(component)\n return {\n warnings: normalized.warnings,\n component: normalized.component ?? component ?? {},\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (hasOwn(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: ComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties ?? {})\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n templateRef: options.template,\n styleRef: options.style ?? '',\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.styleRef = options.style ?? ''\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/runtime/component/state.ts"],"sourcesContent":["import type {\n ComponentOptions,\n DataRecord,\n DefineComponentOptions,\n LifeTimeHooks,\n PageLifeTimeHooks,\n PropertyOption,\n} from './types'\nimport { hasOwn } from '../utils/object'\nimport { normalizeBehaviors } from './behavior'\nimport { cloneValue, hyphenate } from './utils'\n\ntype PropertyEntry = [string, PropertyOption]\n\nexport interface ComponentRuntimeState {\n templateRef: DefineComponentOptions['template']\n styleRef: string\n componentRef: ComponentOptions\n observerInitEnabled: boolean\n propertyEntries: PropertyEntry[]\n observedAttributes: string[]\n defaultPropertyValues: DataRecord\n lifetimes: LifeTimeHooks\n pageLifetimes: PageLifeTimeHooks\n}\n\nfunction resolveNormalizedComponent(component: ComponentOptions | undefined) {\n const normalized = normalizeBehaviors(component)\n return {\n warnings: normalized.warnings,\n component: normalized.component ?? component ?? {},\n }\n}\n\nfunction createDefaultPropertyValues(propertyEntries: PropertyEntry[]) {\n return propertyEntries.reduce<DataRecord>((acc, [name, prop]) => {\n if (hasOwn(prop, 'value')) {\n acc[name] = cloneValue(prop.value)\n }\n else {\n acc[name] = undefined\n }\n return acc\n }, {})\n}\n\nfunction createPropertyEntries(component: ComponentOptions): PropertyEntry[] {\n return Object.entries(component.properties ?? {})\n}\n\nfunction createObservedAttributes(propertyEntries: PropertyEntry[]) {\n return propertyEntries.map(([name]) => hyphenate(name))\n}\n\nexport function createComponentRuntimeState(options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n const state: ComponentRuntimeState = {\n templateRef: options.template,\n styleRef: options.style ?? '',\n componentRef: component,\n observerInitEnabled: Boolean(options.observerInit),\n propertyEntries,\n observedAttributes: createObservedAttributes(propertyEntries),\n defaultPropertyValues: createDefaultPropertyValues(propertyEntries),\n lifetimes: component.lifetimes ?? {},\n pageLifetimes: component.pageLifetimes ?? {},\n }\n return {\n state,\n warnings,\n }\n}\n\nexport function updateComponentRuntimeState(state: ComponentRuntimeState, options: DefineComponentOptions) {\n const { component, warnings } = resolveNormalizedComponent(options.component ?? {})\n const propertyEntries = createPropertyEntries(component)\n state.templateRef = options.template\n state.styleRef = options.style ?? ''\n state.componentRef = component\n state.observerInitEnabled = Boolean(options.observerInit)\n state.lifetimes = component.lifetimes ?? {}\n state.pageLifetimes = component.pageLifetimes ?? {}\n state.propertyEntries = propertyEntries\n state.observedAttributes = createObservedAttributes(propertyEntries)\n state.defaultPropertyValues = createDefaultPropertyValues(propertyEntries)\n return {\n warnings,\n nextMethods: component.methods ?? {},\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAS,2BAA2B,WAAyC;CAC3E,MAAM,aAAa,mBAAmB,SAAS;CAC/C,OAAO;EACL,UAAU,WAAW;EACrB,WAAW,WAAW,aAAa,aAAa,CAAC;CACnD;AACF;AAEA,SAAS,4BAA4B,iBAAkC;CACrE,OAAO,gBAAgB,QAAoB,KAAK,CAAC,MAAM,UAAU;EAC/D,IAAI,OAAO,MAAM,OAAO,GACtB,IAAI,QAAQ,WAAW,KAAK,KAAK;OAGjC,IAAI,QAAQ;EAEd,OAAO;CACT,GAAG,CAAC,CAAC;AACP;AAEA,SAAS,sBAAsB,WAA8C;CAC3E,OAAO,OAAO,QAAQ,UAAU,cAAc,CAAC,CAAC;AAClD;AAEA,SAAS,yBAAyB,iBAAkC;CAClE,OAAO,gBAAgB,KAAK,CAAC,UAAU,UAAU,IAAI,CAAC;AACxD;AAEA,SAAgB,4BAA4B,SAAiC;CAC3E,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,CAAC,CAAC;CAClF,MAAM,kBAAkB,sBAAsB,SAAS;CAYvD,OAAO;EACL;GAXA,aAAa,QAAQ;GACrB,UAAU,QAAQ,SAAS;GAC3B,cAAc;GACd,qBAAqB,QAAQ,QAAQ,YAAY;GACjD;GACA,oBAAoB,yBAAyB,eAAe;GAC5D,uBAAuB,4BAA4B,eAAe;GAClE,WAAW,UAAU,aAAa,CAAC;GACnC,eAAe,UAAU,iBAAiB,CAAC;EAGvC;EACJ;CACF;AACF;AAEA,SAAgB,4BAA4B,OAA8B,SAAiC;CACzG,MAAM,EAAE,WAAW,aAAa,2BAA2B,QAAQ,aAAa,CAAC,CAAC;CAClF,MAAM,kBAAkB,sBAAsB,SAAS;CACvD,MAAM,cAAc,QAAQ;CAC5B,MAAM,WAAW,QAAQ,SAAS;CAClC,MAAM,eAAe;CACrB,MAAM,sBAAsB,QAAQ,QAAQ,YAAY;CACxD,MAAM,YAAY,UAAU,aAAa,CAAC;CAC1C,MAAM,gBAAgB,UAAU,iBAAiB,CAAC;CAClD,MAAM,kBAAkB;CACxB,MAAM,qBAAqB,yBAAyB,eAAe;CACnE,MAAM,wBAAwB,4BAA4B,eAAe;CACzE,OAAO;EACL;EACA,aAAa,UAAU,WAAW,CAAC;CACrC;AACF"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
//#region src/runtime/component/utils.ts
|
|
2
10
|
function hyphenate(name) {
|
|
3
11
|
return name.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/runtime/component/utils.ts"],"sourcesContent":["import type { PropertyOption } from './types'\n\nexport function hyphenate(name: string) {\n return name.replace(/([A-Z])/g, (_, char: string) => `-${char.toLowerCase()}`)\n}\n\nexport function toCamelCase(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function cloneValue(value: any) {\n if (Array.isArray(value)) {\n return value.slice()\n }\n if (value && typeof value === 'object') {\n return { ...value }\n }\n return value\n}\n\nexport function coerceValue(value: any, type?: PropertyOption['type']) {\n if (type === Boolean) {\n if (value === '' || value === true) {\n return true\n }\n if (value === undefined || value === null || value === false) {\n return false\n }\n if (typeof value === 'string') {\n return value !== 'false'\n }\n return Boolean(value)\n }\n\n if (type === Number) {\n if (value === undefined || value === null) {\n return value\n }\n const numeric = Number(value)\n return Number.isNaN(numeric) ? value : numeric\n }\n\n if (type === Object || type === Array) {\n if (value === undefined || value === null) {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n }\n return value\n }\n\n return value\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/runtime/component/utils.ts"],"sourcesContent":["import type { PropertyOption } from './types'\n\nexport function hyphenate(name: string) {\n return name.replace(/([A-Z])/g, (_, char: string) => `-${char.toLowerCase()}`)\n}\n\nexport function toCamelCase(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function cloneValue(value: any) {\n if (Array.isArray(value)) {\n return value.slice()\n }\n if (value && typeof value === 'object') {\n return { ...value }\n }\n return value\n}\n\nexport function coerceValue(value: any, type?: PropertyOption['type']) {\n if (type === Boolean) {\n if (value === '' || value === true) {\n return true\n }\n if (value === undefined || value === null || value === false) {\n return false\n }\n if (typeof value === 'string') {\n return value !== 'false'\n }\n return Boolean(value)\n }\n\n if (type === Number) {\n if (value === undefined || value === null) {\n return value\n }\n const numeric = Number(value)\n return Number.isNaN(numeric) ? value : numeric\n }\n\n if (type === Object || type === Array) {\n if (value === undefined || value === null) {\n return value\n }\n if (typeof value === 'string') {\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n }\n return value\n }\n\n return value\n}\n"],"mappings":";;;;;;;;;AAEA,SAAgB,UAAU,MAAc;CACtC,OAAO,KAAK,QAAQ,aAAa,GAAG,SAAiB,IAAI,KAAK,YAAY,GAAG;AAC/E;AAEA,SAAgB,YAAY,MAAc;CACxC,OAAO,KAAK,QAAQ,cAAc,GAAG,SAAiB,KAAK,YAAY,CAAC;AAC1E;AAEA,SAAgB,WAAW,OAAY;CACrC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,MAAM;CAErB,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,EAAE,GAAG,MAAM;CAEpB,OAAO;AACT;AAEA,SAAgB,YAAY,OAAY,MAA+B;CACrE,IAAI,SAAS,SAAS;EACpB,IAAI,UAAU,MAAM,UAAU,MAC5B,OAAO;EAET,IAAI,UAAU,UAAa,UAAU,QAAQ,UAAU,OACrD,OAAO;EAET,IAAI,OAAO,UAAU,UACnB,OAAO,UAAU;EAEnB,OAAO,QAAQ,KAAK;CACtB;CAEA,IAAI,SAAS,QAAQ;EACnB,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO;EAET,MAAM,UAAU,OAAO,KAAK;EAC5B,OAAO,OAAO,MAAM,OAAO,IAAI,QAAQ;CACzC;CAEA,IAAI,SAAS,UAAU,SAAS,OAAO;EACrC,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO;EAET,IAAI,OAAO,UAAU,UACnB,IAAI;GACF,OAAO,KAAK,MAAM,KAAK;EACzB,QACM;GACJ,OAAO;EACT;EAEF,OAAO;CACT;CAEA,OAAO;AACT"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { emitRuntimeWarning } from "./warning.mjs";
|
|
2
10
|
|
|
3
11
|
//#region src/runtime/execution.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.mjs","names":[],"sources":["../../src/runtime/execution.ts"],"sourcesContent":["import { emitRuntimeWarning } from './warning'\n\nexport type RuntimeExecutionMode = 'compat' | 'safe' | 'strict'\n\nlet currentRuntimeExecutionMode: RuntimeExecutionMode = 'compat'\nconst warnedMessages = new Set<string>()\n\nfunction isRuntimeExecutionMode(value: unknown): value is RuntimeExecutionMode {\n return value === 'compat' || value === 'safe' || value === 'strict'\n}\n\nexport function getRuntimeExecutionMode(): RuntimeExecutionMode {\n return currentRuntimeExecutionMode\n}\n\nexport function warnRuntimeExecutionOnce(key: string, message: string): void {\n if (warnedMessages.has(key)) {\n return\n }\n warnedMessages.add(key)\n emitRuntimeWarning(message, {\n key: `execution:${key}`,\n context: 'runtime:execution',\n })\n}\n\nexport function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void {\n if (mode === undefined) {\n currentRuntimeExecutionMode = 'compat'\n warnedMessages.clear()\n return\n }\n if (isRuntimeExecutionMode(mode)) {\n currentRuntimeExecutionMode = mode\n warnedMessages.clear()\n return\n }\n warnRuntimeExecutionOnce(\n `invalid-runtime-mode:${String(mode)}`,\n `[@weapp-vite/web] 未知 executionMode \"${String(mode)}\",已回退到 compat。`,\n )\n currentRuntimeExecutionMode = 'compat'\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"execution.mjs","names":[],"sources":["../../src/runtime/execution.ts"],"sourcesContent":["import { emitRuntimeWarning } from './warning'\n\nexport type RuntimeExecutionMode = 'compat' | 'safe' | 'strict'\n\nlet currentRuntimeExecutionMode: RuntimeExecutionMode = 'compat'\nconst warnedMessages = new Set<string>()\n\nfunction isRuntimeExecutionMode(value: unknown): value is RuntimeExecutionMode {\n return value === 'compat' || value === 'safe' || value === 'strict'\n}\n\nexport function getRuntimeExecutionMode(): RuntimeExecutionMode {\n return currentRuntimeExecutionMode\n}\n\nexport function warnRuntimeExecutionOnce(key: string, message: string): void {\n if (warnedMessages.has(key)) {\n return\n }\n warnedMessages.add(key)\n emitRuntimeWarning(message, {\n key: `execution:${key}`,\n context: 'runtime:execution',\n })\n}\n\nexport function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void {\n if (mode === undefined) {\n currentRuntimeExecutionMode = 'compat'\n warnedMessages.clear()\n return\n }\n if (isRuntimeExecutionMode(mode)) {\n currentRuntimeExecutionMode = mode\n warnedMessages.clear()\n return\n }\n warnRuntimeExecutionOnce(\n `invalid-runtime-mode:${String(mode)}`,\n `[@weapp-vite/web] 未知 executionMode \"${String(mode)}\",已回退到 compat。`,\n )\n currentRuntimeExecutionMode = 'compat'\n}\n"],"mappings":";;;;;;;;;;;AAIA,IAAI,8BAAoD;AACxD,MAAM,iCAAiB,IAAI,IAAY;AAEvC,SAAS,uBAAuB,OAA+C;CAC7E,OAAO,UAAU,YAAY,UAAU,UAAU,UAAU;AAC7D;AAEA,SAAgB,0BAAgD;CAC9D,OAAO;AACT;AAEA,SAAgB,yBAAyB,KAAa,SAAuB;CAC3E,IAAI,eAAe,IAAI,GAAG,GACxB;CAEF,eAAe,IAAI,GAAG;CACtB,mBAAmB,SAAS;EAC1B,KAAK,aAAa;EAClB,SAAS;CACX,CAAC;AACH;AAEA,SAAgB,wBAAwB,MAA4C;CAClF,IAAI,SAAS,QAAW;EACtB,8BAA8B;EAC9B,eAAe,MAAM;EACrB;CACF;CACA,IAAI,uBAAuB,IAAI,GAAG;EAChC,8BAA8B;EAC9B,eAAe,MAAM;EACrB;CACF;CACA,yBACE,wBAAwB,OAAO,IAAI,KACnC,uCAAuC,OAAO,IAAI,EAAE,eACtD;CACA,8BAA8B;AAChC"}
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
1
3
|
import { ButtonFormConfig, ensureButtonDefined, setButtonFormConfig } from "./button/index.mjs";
|
|
2
4
|
import { RenderContext, createRenderContext } from "./renderContext.mjs";
|
|
3
5
|
import { createTemplate, renderTemplate } from "./legacyTemplate/index.mjs";
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { injectStyle, removeStyle } from "./style.mjs";
|
|
2
10
|
import { ensureButtonDefined, setButtonFormConfig } from "./button/index.mjs";
|
|
3
11
|
import { setRuntimeWarningOptions } from "./warning.mjs";
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { CONTROL_ATTRS, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
10
|
import { MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX } from "../component/constants.mjs";
|
|
3
11
|
import { escapeAttribute, resolveAttributeValue } from "./expression.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_KIND_ALIAS: Record<string, string> = {\n tap: 'click',\n longtap: 'contextmenu',\n longpress: 'contextmenu',\n}\n\nconst EVENT_PREFIX_FLAGS: Record<string, { catch?: boolean, capture?: boolean }> = {\n 'bind': {},\n 'catch': { catch: true },\n 'mut-bind': {},\n 'capture-bind': { capture: true },\n 'capture-catch': { capture: true, catch: true },\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const restAttribs: Record<string, string> = {}\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(key)) {\n continue\n }\n restAttribs[key] = val\n }\n\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n\n return {\n expr,\n itemName,\n indexName,\n restAttribs,\n }\n}\n\nexport function buildAttributeString(\n attribs: Record<string, string>,\n scope: LegacyTemplateScope,\n) {\n let result = ''\n for (const [name, rawValue] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n\n const eventMatch = EVENT_PREFIX_RE.exec(name)\n if (eventMatch) {\n const [, prefix, rawEvent] = eventMatch\n const event = rawEvent.toLowerCase()\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const runtimeEvent = EVENT_KIND_ALIAS[event] ?? event\n const flags = EVENT_PREFIX_FLAGS[prefix] ?? {}\n result += ` ${MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX}${runtimeEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${runtimeEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const value = resolveAttributeValue(rawValue, scope)\n if (value === '') {\n continue\n }\n const normalizedName = normalizeAttributeName(name)\n result += ` ${normalizedName}=\"${escapeAttribute(value)}\"`\n }\n return result\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nexport function isConditionalElement(node: Node): node is Element {\n if (node.type !== 'tag') {\n return false\n }\n const attribs = (node as Element).attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dom.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/dom.ts"],"sourcesContent":["import type { Element, Node } from 'domhandler'\nimport type { ExtractForResult, LegacyTemplateScope } from './types'\nimport {\n CONTROL_ATTRS,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport {\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n} from '../component/constants'\nimport { escapeAttribute, resolveAttributeValue } from './expression'\n\nconst EVENT_PREFIX_RE = /^(bind|catch|mut-bind|capture-bind|capture-catch)([\\w-]+)$/\nconst EVENT_KIND_ALIAS: Record<string, string> = {\n tap: 'click',\n longtap: 'contextmenu',\n longpress: 'contextmenu',\n}\n\nconst EVENT_PREFIX_FLAGS: Record<string, { catch?: boolean, capture?: boolean }> = {\n 'bind': {},\n 'catch': { catch: true },\n 'mut-bind': {},\n 'capture-bind': { capture: true },\n 'capture-catch': { capture: true, catch: true },\n}\n\nexport function extractFor(attribs: Record<string, string>): ExtractForResult {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const restAttribs: Record<string, string> = {}\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n\n for (const [key, val] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(key)) {\n continue\n }\n restAttribs[key] = val\n }\n\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n\n return {\n expr,\n itemName,\n indexName,\n restAttribs,\n }\n}\n\nexport function buildAttributeString(\n attribs: Record<string, string>,\n scope: LegacyTemplateScope,\n) {\n let result = ''\n for (const [name, rawValue] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n\n const eventMatch = EVENT_PREFIX_RE.exec(name)\n if (eventMatch) {\n const [, prefix, rawEvent] = eventMatch\n const event = rawEvent.toLowerCase()\n const handlerName = resolveAttributeValue(rawValue, scope).trim()\n if (!handlerName) {\n continue\n }\n const runtimeEvent = EVENT_KIND_ALIAS[event] ?? event\n const flags = EVENT_PREFIX_FLAGS[prefix] ?? {}\n result += ` ${MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX}${runtimeEvent}=\"${escapeAttribute(handlerName)}\"`\n const flagTokens = [\n flags.capture ? 'capture' : '',\n flags.catch ? 'catch' : '',\n ].filter(Boolean)\n if (flagTokens.length) {\n result += ` ${MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX}${runtimeEvent}=\"${flagTokens.join(',')}\"`\n }\n continue\n }\n\n const value = resolveAttributeValue(rawValue, scope)\n if (value === '') {\n continue\n }\n const normalizedName = normalizeAttributeName(name)\n result += ` ${normalizedName}=\"${escapeAttribute(value)}\"`\n }\n return result\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nexport function isConditionalElement(node: Node): node is Element {\n if (node.type !== 'tag') {\n return false\n }\n const attribs = (node as Element).attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,kBAAkB;AACxB,MAAM,mBAA2C;CAC/C,KAAK;CACL,SAAS;CACT,WAAW;AACb;AAEA,MAAM,qBAA6E;CACjF,QAAQ,CAAC;CACT,SAAS,EAAE,OAAO,KAAK;CACvB,YAAY,CAAC;CACb,gBAAgB,EAAE,SAAS,KAAK;CAChC,iBAAiB;EAAE,SAAS;EAAM,OAAO;CAAK;AAChD;AAEA,SAAgB,WAAW,SAAmD;CAC5E,MAAM,OAAO,6BAA6B,SAAS,KAAK;CACxD,MAAM,cAAsC,CAAC;CAC7C,MAAM,WAAW,6BAA6B,SAAS,UAAU,GAAG,KAAK,KAAK;CAC9E,IAAI,YAAY,6BAA6B,SAAS,WAAW,GAAG,KAAK,KAAK;CAE9E,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,OAAO,GAAG;EAChD,IAAI,cAAc,IAAI,GAAG,GACvB;EAEF,YAAY,OAAO;CACrB;CAEA,IAAI,aAAa,WACf,YAAY,GAAG,UAAU;CAG3B,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAEA,SAAgB,qBACd,SACA,OACA;CACA,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,OAAO,GAAG;EACtD,IAAI,cAAc,IAAI,IAAI,GACxB;EAGF,MAAM,aAAa,gBAAgB,KAAK,IAAI;EAC5C,IAAI,YAAY;GACd,MAAM,GAAG,QAAQ,YAAY;GAC7B,MAAM,QAAQ,SAAS,YAAY;GACnC,MAAM,cAAc,sBAAsB,UAAU,KAAK,EAAE,KAAK;GAChE,IAAI,CAAC,aACH;GAEF,MAAM,eAAe,iBAAiB,UAAU;GAChD,MAAM,QAAQ,mBAAmB,WAAW,CAAC;GAC7C,UAAU,IAAI,sCAAsC,aAAa,IAAI,gBAAgB,WAAW,EAAE;GAClG,MAAM,aAAa,CACjB,MAAM,UAAU,YAAY,IAC5B,MAAM,QAAQ,UAAU,EAC1B,EAAE,OAAO,OAAO;GAChB,IAAI,WAAW,QACb,UAAU,IAAI,2CAA2C,aAAa,IAAI,WAAW,KAAK,GAAG,EAAE;GAEjG;EACF;EAEA,MAAM,QAAQ,sBAAsB,UAAU,KAAK;EACnD,IAAI,UAAU,IACZ;EAEF,MAAM,iBAAiB,uBAAuB,IAAI;EAClD,UAAU,IAAI,eAAe,IAAI,gBAAgB,KAAK,EAAE;CAC1D;CACA,OAAO;AACT;AAEA,SAAgB,uBAAuB,SAAiC;CACtE,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,CAAC,cAAc,IAAI,IAAI,GACzB,OAAO,QAAQ;CAGnB,OAAO;AACT;AAEA,SAAgB,qBAAqB,MAA6B;CAChE,IAAI,KAAK,SAAS,OAChB,OAAO;CAET,MAAM,UAAW,KAAiB,WAAW,CAAC;CAC9C,OAAO,oBAAoB,SAAS,IAAI,KACnC,oBAAoB,SAAS,MAAM,KACnC,oBAAoB,SAAS,MAAM;AAC1C"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from "../execution.mjs";
|
|
2
10
|
|
|
3
11
|
//#region src/runtime/legacyTemplate/expression.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/expression.ts"],"sourcesContent":["import type { LegacyTemplateScope } from './types'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from '../execution'\n\nconst expressionCache = new Map<string, (scope: LegacyTemplateScope) => any>()\n\nexport function createScope(initial?: LegacyTemplateScope) {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nexport function createChildScope(parent: LegacyTemplateScope) {\n return Object.assign(Object.create(parent), {})\n}\n\nexport function normalizeList(value: any): any[] {\n if (Array.isArray(value)) {\n return value\n }\n if (value == null) {\n return []\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n const length = Math.max(0, Math.floor(value))\n return Array.from({ length }, (_, index) => index)\n }\n if (typeof value === 'object') {\n return Object.values(value)\n }\n return []\n}\n\nexport function escapeHtml(value: string) {\n return value.replace(/[&<>\"']/g, (match) => {\n switch (match) {\n case '&':\n return '&'\n case '<':\n return '<'\n case '>':\n return '>'\n case '\"':\n return '"'\n case '\\'':\n return '''\n default:\n return match\n }\n })\n}\n\nexport function escapeAttribute(value: string) {\n return escapeHtml(value)\n}\n\nfunction toDisplayString(value: any) {\n if (value == null) {\n return ''\n }\n if (typeof value === 'object') {\n if (value instanceof Date) {\n return value.toISOString()\n }\n try {\n return JSON.stringify(value)\n }\n catch {\n return String(value)\n }\n }\n return String(value)\n}\n\nfunction unwrapExpression(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{{') && trimmed.endsWith('}}')) {\n return trimmed.slice(2, -2).trim()\n }\n return trimmed\n}\n\nexport function evaluateExpression(expression: string, scope: LegacyTemplateScope) {\n if (!expression) {\n return undefined\n }\n const trimmed = unwrapExpression(expression)\n if (!trimmed) {\n return undefined\n }\n let evaluator = expressionCache.get(trimmed)\n if (!evaluator) {\n try {\n // eslint-disable-next-line no-new-func -- dynamic expressions are required for template evaluation\n evaluator = new Function('scope', `with(scope){ return (${trimmed}); }`) as (scope: LegacyTemplateScope) => any\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-parse:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式解析错误 \"${trimmed}\": ${reason}`,\n )\n evaluator = () => undefined\n }\n else {\n throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 \"${trimmed}\": ${reason}`)\n }\n }\n if (evaluator) {\n expressionCache.set(trimmed, evaluator)\n }\n }\n try {\n return evaluator?.(scope)\n }\n catch (error) {\n const mode = getRuntimeExecutionMode()\n if (mode === 'strict') {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 \"${trimmed}\": ${reason}`)\n }\n if (mode === 'safe') {\n const reason = error instanceof Error ? error.message : String(error)\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nexport function interpolateText(source: string, scope: LegacyTemplateScope, escapeResult: boolean) {\n if (!source.includes('{{')) {\n return escapeResult ? escapeHtml(source) : source\n }\n\n let cursor = 0\n let buffer = ''\n\n while (cursor < source.length) {\n const start = source.indexOf('{{', cursor)\n if (start === -1) {\n buffer += source.slice(cursor)\n break\n }\n\n buffer += source.slice(cursor, start)\n\n const end = source.indexOf('}}', start + 2)\n if (end === -1) {\n buffer += source.slice(start)\n break\n }\n\n const expression = source.slice(start + 2, end).trim()\n const evaluated = toDisplayString(evaluateExpression(expression, scope))\n buffer += evaluated\n cursor = end + 2\n }\n\n return escapeResult ? escapeHtml(buffer) : buffer\n}\n\nexport function resolveAttributeValue(value: string, scope: LegacyTemplateScope) {\n return interpolateText(value ?? '', scope, false)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"expression.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/expression.ts"],"sourcesContent":["import type { LegacyTemplateScope } from './types'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from '../execution'\n\nconst expressionCache = new Map<string, (scope: LegacyTemplateScope) => any>()\n\nexport function createScope(initial?: LegacyTemplateScope) {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nexport function createChildScope(parent: LegacyTemplateScope) {\n return Object.assign(Object.create(parent), {})\n}\n\nexport function normalizeList(value: any): any[] {\n if (Array.isArray(value)) {\n return value\n }\n if (value == null) {\n return []\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n const length = Math.max(0, Math.floor(value))\n return Array.from({ length }, (_, index) => index)\n }\n if (typeof value === 'object') {\n return Object.values(value)\n }\n return []\n}\n\nexport function escapeHtml(value: string) {\n return value.replace(/[&<>\"']/g, (match) => {\n switch (match) {\n case '&':\n return '&'\n case '<':\n return '<'\n case '>':\n return '>'\n case '\"':\n return '"'\n case '\\'':\n return '''\n default:\n return match\n }\n })\n}\n\nexport function escapeAttribute(value: string) {\n return escapeHtml(value)\n}\n\nfunction toDisplayString(value: any) {\n if (value == null) {\n return ''\n }\n if (typeof value === 'object') {\n if (value instanceof Date) {\n return value.toISOString()\n }\n try {\n return JSON.stringify(value)\n }\n catch {\n return String(value)\n }\n }\n return String(value)\n}\n\nfunction unwrapExpression(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{{') && trimmed.endsWith('}}')) {\n return trimmed.slice(2, -2).trim()\n }\n return trimmed\n}\n\nexport function evaluateExpression(expression: string, scope: LegacyTemplateScope) {\n if (!expression) {\n return undefined\n }\n const trimmed = unwrapExpression(expression)\n if (!trimmed) {\n return undefined\n }\n let evaluator = expressionCache.get(trimmed)\n if (!evaluator) {\n try {\n // eslint-disable-next-line no-new-func -- dynamic expressions are required for template evaluation\n evaluator = new Function('scope', `with(scope){ return (${trimmed}); }`) as (scope: LegacyTemplateScope) => any\n }\n catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n const mode = getRuntimeExecutionMode()\n if (mode === 'safe') {\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-parse:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式解析错误 \"${trimmed}\": ${reason}`,\n )\n evaluator = () => undefined\n }\n else {\n throw new SyntaxError(`[@weapp-vite/web] 无法解析表达式 \"${trimmed}\": ${reason}`)\n }\n }\n if (evaluator) {\n expressionCache.set(trimmed, evaluator)\n }\n }\n try {\n return evaluator?.(scope)\n }\n catch (error) {\n const mode = getRuntimeExecutionMode()\n if (mode === 'strict') {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`[@weapp-vite/web] strict 模式下表达式执行失败 \"${trimmed}\": ${reason}`)\n }\n if (mode === 'safe') {\n const reason = error instanceof Error ? error.message : String(error)\n warnRuntimeExecutionOnce(\n `safe-legacy-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nexport function interpolateText(source: string, scope: LegacyTemplateScope, escapeResult: boolean) {\n if (!source.includes('{{')) {\n return escapeResult ? escapeHtml(source) : source\n }\n\n let cursor = 0\n let buffer = ''\n\n while (cursor < source.length) {\n const start = source.indexOf('{{', cursor)\n if (start === -1) {\n buffer += source.slice(cursor)\n break\n }\n\n buffer += source.slice(cursor, start)\n\n const end = source.indexOf('}}', start + 2)\n if (end === -1) {\n buffer += source.slice(start)\n break\n }\n\n const expression = source.slice(start + 2, end).trim()\n const evaluated = toDisplayString(evaluateExpression(expression, scope))\n buffer += evaluated\n cursor = end + 2\n }\n\n return escapeResult ? escapeHtml(buffer) : buffer\n}\n\nexport function resolveAttributeValue(value: string, scope: LegacyTemplateScope) {\n return interpolateText(value ?? '', scope, false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AM,MAAM;EACzC,IAAI,UAAU,IAAI;GAChB,UAAU,OAAO,MAAM,MAAM;GAC7B;EACF;EAEA,UAAU,OAAO,MAAM,QAAQ,KAAK;EAEpC,MAAM,MAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;EAC1C,IAAI,QAAQ,IAAI;GACd,UAAU,OAAO,MAAM,KAAK;GAC5B;EACF;EAGA,MAAM,YAAY,gBAAgB,mBADf,OAAO,MAAM,QAAQ,GAAG,GAAG,EAAE,KACc,GAAG,KAAK,CAAC;EACvE,UAAU;EACV,SAAS,MAAM;CACjB;CAEA,OAAO,eAAe,WAAW,MAAM,IAAI;AAC7C;AAEA,SAAgB,sBAAsB,OAAe,OAA4B;CAC/E,OAAO,gBAAgB,SAAS,IAAI,OAAO,KAAK;AAClD"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { SELF_CLOSING_TAGS, hasControlAttribute, normalizeTagName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
|
|
2
10
|
import { createChildScope, createScope, evaluateExpression, interpolateText, normalizeList } from "./expression.mjs";
|
|
3
11
|
import { buildAttributeString, extractFor, isConditionalElement, stripControlAttributes } from "./dom.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n buildAttributeString,\n extractFor,\n isConditionalElement,\n stripControlAttributes,\n} from './dom'\nimport {\n createChildScope,\n createScope,\n evaluateExpression,\n interpolateText,\n normalizeList,\n} from './expression'\n\nconst templateCache = new Map<string, ChildNode[]>()\n\nfunction filterRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return data.trim().length > 0\n }\n return true\n}\n\nfunction getOrParseTemplate(source: string) {\n let cached = templateCache.get(source)\n if (!cached) {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n cached = (document.children ?? []).filter(filterRenderableNode)\n templateCache.set(source, cached)\n }\n return cached\n}\n\nfunction renderConditionalSequence(\n nodes: ChildNode[],\n startIndex: number,\n scope: LegacyTemplateScope,\n renderChildren: (input: ChildNode[] | ChildNode | undefined, scope: LegacyTemplateScope) => string,\n) {\n const branches: Array<{ node: Element, attribs: Record<string, string> }> = []\n let cursor = startIndex\n\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const element = candidate as Element\n const attribs = element.attribs ?? {}\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: element, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n\n if (!branches.length) {\n const node = nodes[startIndex]\n return {\n rendered: renderChildren(node, scope),\n endIndex: startIndex,\n }\n }\n\n for (const { node, attribs } of branches) {\n if (hasControlAttribute(attribs, 'else')) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n if (!conditionExpr) {\n continue\n }\n const condition = evaluateExpression(conditionExpr, scope)\n if (condition) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n }\n\n return {\n rendered: '',\n endIndex: startIndex + branches.length - 1,\n }\n}\n\nfunction renderElement(\n node: Element,\n scope: LegacyTemplateScope,\n renderChildren: (nodes: ChildNode[] | undefined, scope: LegacyTemplateScope) => string,\n options: RenderOptions = {},\n) {\n const attribs = node.attribs ?? {}\n if (!options.skipFor) {\n const forExtract = extractFor(attribs)\n if (forExtract.expr) {\n const list = normalizeList(evaluateExpression(forExtract.expr, scope))\n if (!list.length) {\n return ''\n }\n let buffer = ''\n for (let idx = 0; idx < list.length; idx++) {\n const item = list[idx]\n const childScope = createChildScope(scope)\n childScope[forExtract.itemName] = item\n childScope[forExtract.indexName] = idx\n buffer += renderElement(node, childScope, renderChildren, {\n skipFor: true,\n overrideAttribs: forExtract.restAttribs,\n })\n }\n return buffer\n }\n }\n\n const effectiveAttribs = options.overrideAttribs ?? attribs\n const normalizedTag = normalizeTagName(node.name)\n if (normalizedTag === '#fragment') {\n return renderChildren(node.children, scope)\n }\n\n const attrs = buildAttributeString(effectiveAttribs, scope)\n const children = renderChildren(node.children, scope)\n\n if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) {\n return `<${normalizedTag}${attrs} />`\n }\n\n return `<${normalizedTag}${attrs}>${children}</${normalizedTag}>`\n}\n\nfunction renderTextNode(node: DataNode, scope: LegacyTemplateScope) {\n const value = node.data ?? ''\n if (!value.trim()) {\n return ''\n }\n return interpolateText(value, scope, true)\n}\n\nfunction renderTree(\n input: ChildNode[] | ChildNode | undefined,\n scope: LegacyTemplateScope,\n): string {\n if (!input) {\n return ''\n }\n\n if (Array.isArray(input)) {\n let buffer = ''\n for (let index = 0; index < input.length; index++) {\n const node = input[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = renderConditionalSequence(input, index, scope, renderTree)\n buffer += rendered\n index = endIndex\n continue\n }\n buffer += renderTree(node, scope)\n }\n return buffer\n }\n\n const node = input\n if (node.type === 'text') {\n return renderTextNode(node as DataNode, scope)\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n return renderElement(node as Element, scope, renderTree)\n }\n if ('children' in node && node.children?.length) {\n return renderTree(node.children, scope)\n }\n return ''\n}\n\nexport function renderTemplate(nodes: ChildNode[], scope?: LegacyTemplateScope) {\n const renderScope = createScope(scope)\n return renderTree(nodes, renderScope)\n}\n\nexport function createTemplate(source: string): LegacyTemplateRenderer {\n const nodes = getOrParseTemplate(source)\n return (scope?: LegacyTemplateScope) => renderTemplate(nodes, scope)\n}\n\nexport type { LegacyTemplateRenderer, LegacyTemplateScope } from './types'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/runtime/legacyTemplate/index.ts"],"sourcesContent":["import type { ChildNode, DataNode, Element, Node } from 'domhandler'\nimport type {\n LegacyTemplateRenderer,\n LegacyTemplateScope,\n RenderOptions,\n} from './types'\nimport { parseDocument } from 'htmlparser2'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n buildAttributeString,\n extractFor,\n isConditionalElement,\n stripControlAttributes,\n} from './dom'\nimport {\n createChildScope,\n createScope,\n evaluateExpression,\n interpolateText,\n normalizeList,\n} from './expression'\n\nconst templateCache = new Map<string, ChildNode[]>()\n\nfunction filterRenderableNode(node: Node) {\n if (node.type === 'directive' || node.type === 'comment') {\n return false\n }\n if (node.type === 'text') {\n const data = (node as DataNode).data ?? ''\n return data.trim().length > 0\n }\n return true\n}\n\nfunction getOrParseTemplate(source: string) {\n let cached = templateCache.get(source)\n if (!cached) {\n const document = parseDocument(source, {\n xmlMode: true,\n decodeEntities: true,\n recognizeSelfClosing: true,\n })\n cached = (document.children ?? []).filter(filterRenderableNode)\n templateCache.set(source, cached)\n }\n return cached\n}\n\nfunction renderConditionalSequence(\n nodes: ChildNode[],\n startIndex: number,\n scope: LegacyTemplateScope,\n renderChildren: (input: ChildNode[] | ChildNode | undefined, scope: LegacyTemplateScope) => string,\n) {\n const branches: Array<{ node: Element, attribs: Record<string, string> }> = []\n let cursor = startIndex\n\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const element = candidate as Element\n const attribs = element.attribs ?? {}\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: element, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n\n if (!branches.length) {\n const node = nodes[startIndex]\n return {\n rendered: renderChildren(node, scope),\n endIndex: startIndex,\n }\n }\n\n for (const { node, attribs } of branches) {\n if (hasControlAttribute(attribs, 'else')) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')\n if (!conditionExpr) {\n continue\n }\n const condition = evaluateExpression(conditionExpr, scope)\n if (condition) {\n return {\n // eslint-disable-next-line ts/no-use-before-define -- 条件分支与普通节点复用同一元素渲染逻辑。\n rendered: renderElement(\n node,\n scope,\n renderChildren,\n { overrideAttribs: stripControlAttributes(attribs) },\n ),\n endIndex: startIndex + branches.length - 1,\n }\n }\n }\n\n return {\n rendered: '',\n endIndex: startIndex + branches.length - 1,\n }\n}\n\nfunction renderElement(\n node: Element,\n scope: LegacyTemplateScope,\n renderChildren: (nodes: ChildNode[] | undefined, scope: LegacyTemplateScope) => string,\n options: RenderOptions = {},\n) {\n const attribs = node.attribs ?? {}\n if (!options.skipFor) {\n const forExtract = extractFor(attribs)\n if (forExtract.expr) {\n const list = normalizeList(evaluateExpression(forExtract.expr, scope))\n if (!list.length) {\n return ''\n }\n let buffer = ''\n for (let idx = 0; idx < list.length; idx++) {\n const item = list[idx]\n const childScope = createChildScope(scope)\n childScope[forExtract.itemName] = item\n childScope[forExtract.indexName] = idx\n buffer += renderElement(node, childScope, renderChildren, {\n skipFor: true,\n overrideAttribs: forExtract.restAttribs,\n })\n }\n return buffer\n }\n }\n\n const effectiveAttribs = options.overrideAttribs ?? attribs\n const normalizedTag = normalizeTagName(node.name)\n if (normalizedTag === '#fragment') {\n return renderChildren(node.children, scope)\n }\n\n const attrs = buildAttributeString(effectiveAttribs, scope)\n const children = renderChildren(node.children, scope)\n\n if (SELF_CLOSING_TAGS.has(normalizedTag) && !children) {\n return `<${normalizedTag}${attrs} />`\n }\n\n return `<${normalizedTag}${attrs}>${children}</${normalizedTag}>`\n}\n\nfunction renderTextNode(node: DataNode, scope: LegacyTemplateScope) {\n const value = node.data ?? ''\n if (!value.trim()) {\n return ''\n }\n return interpolateText(value, scope, true)\n}\n\nfunction renderTree(\n input: ChildNode[] | ChildNode | undefined,\n scope: LegacyTemplateScope,\n): string {\n if (!input) {\n return ''\n }\n\n if (Array.isArray(input)) {\n let buffer = ''\n for (let index = 0; index < input.length; index++) {\n const node = input[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = renderConditionalSequence(input, index, scope, renderTree)\n buffer += rendered\n index = endIndex\n continue\n }\n buffer += renderTree(node, scope)\n }\n return buffer\n }\n\n const node = input\n if (node.type === 'text') {\n return renderTextNode(node as DataNode, scope)\n }\n if (node.type === 'tag' || node.type === 'script' || node.type === 'style') {\n return renderElement(node as Element, scope, renderTree)\n }\n if ('children' in node && node.children?.length) {\n return renderTree(node.children, scope)\n }\n return ''\n}\n\nexport function renderTemplate(nodes: ChildNode[], scope?: LegacyTemplateScope) {\n const renderScope = createScope(scope)\n return renderTree(nodes, renderScope)\n}\n\nexport function createTemplate(source: string): LegacyTemplateRenderer {\n const nodes = getOrParseTemplate(source)\n return (scope?: LegacyTemplateScope) => renderTemplate(nodes, scope)\n}\n\nexport type { LegacyTemplateRenderer, LegacyTemplateScope } from './types'\n"],"mappings":";;;;;;;;;;;;;;AA2BA,MAAM,gCAAgB,IAAI,IAAyB;AAEnD,SAAS,qBAAqB,MAAY;CACxC,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,WAC7C,OAAO;CAET,IAAI,KAAK,SAAS,QAEhB,QADc,KAAkB,QAAQ,IAC5B,KAAK,EAAE,SAAS;CAE9B,OAAO;AACT;AAEA,SAAS,mBAAmB,QAAgB;CAC1C,IAAI,SAAS,cAAc,IAAI,MAAM;CACrC,IAAI,CAAC,QAAQ;EAMX,UALiB,cAAc,QAAQ;GACrC,SAAS;GACT,gBAAgB;GAChB,sBAAsB;EACxB,CACiB,EAAE,YAAY,CAAC,GAAG,OAAO,oBAAoB;EAC9D,cAAc,IAAI,QAAQ,MAAM;CAClC;CACA,OAAO;AACT;AAEA,SAAS,0BACP,OACA,YACA,OACA,gBACA;CACA,MAAM,WAAsE,CAAC;CAC7E,IAAI,SAAS;CAEb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,YAAY,MAAM;EACxB,IAAI,CAAC,qBAAqB,SAAS,GACjC;EAEF,MAAM,UAAU;EAChB,MAAM,UAAU,QAAQ,WAAW,CAAC;EACpC,IAAI,SAAS,WAAW,KAAK,CAAC,oBAAoB,SAAS,IAAI,GAC7D;EAEF,IAAI,SAAS,SAAS,KAAK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W,KAAK,UAAU,KAAK;CAExC,OAAO;AACT;AAEA,SAAgB,eAAe,OAAoB,OAA6B;CAE9E,OAAO,WAAW,OADE,YAAY,KACG,CAAC;AACtC;AAEA,SAAgB,eAAe,QAAwC;CACrE,MAAM,QAAQ,mBAAmB,MAAM;CACvC,QAAQ,UAAgC,eAAe,OAAO,KAAK;AACrE"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { NAVBAR_STYLE } from "./style.mjs";
|
|
2
10
|
|
|
3
11
|
//#region src/runtime/navigationBar/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#renderShell","#bindResize","#resizeHandler","#nav","#title","#loading"],"sources":["../../../src/runtime/navigationBar/index.ts"],"sourcesContent":["import { NAVBAR_STYLE } from './style'\n\ninterface NavigationBarMetrics {\n statusBarHeight?: number\n navContentHeight?: number\n safeAreaTop?: number\n}\n\nconst NAVIGATION_BAR_TAG = 'weapp-navigation-bar'\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\nconst navigationBarInstances = new Set<WeappNavigationBar>()\nlet navigationBarMetrics: NavigationBarMetrics = {}\nconst IOS_DEVICE_RE = /iphone|ipad|ipod/i\n\nfunction isIOS() {\n if (typeof navigator === 'undefined') {\n return false\n }\n return IOS_DEVICE_RE.test(navigator.userAgent)\n}\n\nfunction getDefaultHeights() {\n if (isIOS()) {\n return { statusBarHeight: 20, navContentHeight: 44 }\n }\n return { statusBarHeight: 24, navContentHeight: 48 }\n}\n\nfunction readSafeAreaTop() {\n if (typeof document === 'undefined' || !document.body) {\n return 0\n }\n const probe = document.createElement('div')\n probe.style.cssText = [\n 'position: absolute',\n 'top: 0',\n 'height: env(safe-area-inset-top)',\n 'height: constant(safe-area-inset-top)',\n 'pointer-events: none',\n 'visibility: hidden',\n ].join(';')\n document.body.appendChild(probe)\n const height = Math.max(0, probe.getBoundingClientRect().height)\n probe.remove()\n return height\n}\n\nfunction resolveNavigationBarMetrics(): Required<NavigationBarMetrics> & { navHeight: number } {\n const defaults = getDefaultHeights()\n const safeAreaTop = navigationBarMetrics.safeAreaTop !== undefined\n ? navigationBarMetrics.safeAreaTop\n : readSafeAreaTop()\n const statusBarHeight = navigationBarMetrics.statusBarHeight !== undefined\n ? navigationBarMetrics.statusBarHeight\n : (safeAreaTop > 0 ? safeAreaTop : defaults.statusBarHeight)\n const navContentHeight = navigationBarMetrics.navContentHeight !== undefined\n ? navigationBarMetrics.navContentHeight\n : defaults.navContentHeight\n return {\n safeAreaTop,\n statusBarHeight,\n navContentHeight,\n navHeight: statusBarHeight + navContentHeight,\n }\n}\n\nfunction isTransparentColor(value: string | null) {\n if (!value) {\n return false\n }\n const normalized = value.trim().toLowerCase()\n return normalized === 'transparent'\n || normalized === 'rgba(0,0,0,0)'\n || normalized === 'rgba(0, 0, 0, 0)'\n || normalized === 'hsla(0,0%,0%,0)'\n}\n\nexport function setNavigationBarMetrics(next: NavigationBarMetrics) {\n navigationBarMetrics = { ...navigationBarMetrics, ...next }\n for (const instance of navigationBarInstances) {\n instance.applyMetrics()\n }\n}\n\nclass WeappNavigationBar extends BaseElement {\n static observedAttributes = ['title', 'background-color', 'text-style', 'front-color', 'loading']\n\n #nav?: HTMLDivElement\n #title?: HTMLSpanElement\n #loading?: HTMLSpanElement\n #resizeHandler?: () => void\n\n connectedCallback() {\n if (!this.shadowRoot) {\n this.attachShadow({ mode: 'open' })\n }\n if (this.shadowRoot && !this.shadowRoot.hasChildNodes()) {\n this.#renderShell()\n }\n navigationBarInstances.add(this)\n this.applyMetrics()\n this.applyAppearance()\n this.#bindResize()\n }\n\n disconnectedCallback() {\n navigationBarInstances.delete(this)\n if (this.#resizeHandler) {\n const target = typeof window !== 'undefined' ? (window.visualViewport ?? window) : undefined\n target?.removeEventListener('resize', this.#resizeHandler)\n this.#resizeHandler = undefined\n }\n }\n\n attributeChangedCallback() {\n this.applyAppearance()\n }\n\n applyMetrics() {\n const metrics = resolveNavigationBarMetrics()\n this.style.setProperty('--weapp-status-bar-height', `${metrics.statusBarHeight}px`)\n this.style.setProperty('--weapp-nav-content-height', `${metrics.navContentHeight}px`)\n this.style.setProperty('--weapp-nav-height', `${metrics.navHeight}px`)\n }\n\n applyAppearance() {\n if (!this.#nav || !this.#title || !this.#loading) {\n return\n }\n const title = this.getAttribute('title') ?? ''\n this.#title.textContent = title\n const background = this.getAttribute('background-color') ?? '#ffffff'\n const frontColor = this.getAttribute('front-color')\n const textStyle = (this.getAttribute('text-style') ?? '').toLowerCase()\n const color = frontColor || (textStyle === 'white' ? '#ffffff' : '#000000')\n const loadingAttr = this.getAttribute('loading')\n const loading = loadingAttr !== null && loadingAttr !== 'false' && loadingAttr !== '0'\n this.style.setProperty('--weapp-nav-bg', background)\n this.style.setProperty('--weapp-nav-color', color)\n this.#loading.toggleAttribute('hidden', !loading)\n this.#nav.classList.toggle('weapp-nav--transparent', isTransparentColor(background))\n }\n\n #bindResize() {\n if (this.#resizeHandler || typeof window === 'undefined') {\n return\n }\n const target = window.visualViewport ?? window\n this.#resizeHandler = () => {\n this.applyMetrics()\n }\n target.addEventListener('resize', this.#resizeHandler)\n }\n\n #renderShell() {\n const root = this.shadowRoot!\n root.innerHTML = ''\n const style = document.createElement('style')\n style.textContent = NAVBAR_STYLE\n const spacer = document.createElement('div')\n spacer.className = 'weapp-nav__spacer'\n const nav = document.createElement('div')\n nav.className = 'weapp-nav'\n const status = document.createElement('div')\n status.className = 'weapp-nav__status'\n const content = document.createElement('div')\n content.className = 'weapp-nav__content'\n const left = document.createElement('div')\n left.className = 'weapp-nav__left'\n const right = document.createElement('div')\n right.className = 'weapp-nav__right'\n const title = document.createElement('span')\n title.className = 'weapp-nav__title'\n const loading = document.createElement('span')\n loading.className = 'weapp-nav__loading'\n loading.setAttribute('hidden', '')\n const titleText = document.createElement('span')\n titleText.className = 'weapp-nav__title-text'\n title.append(loading, titleText)\n content.append(left, title, right)\n nav.append(status, content)\n root.append(style, spacer, nav)\n this.#nav = nav\n this.#title = titleText\n this.#loading = loading\n }\n}\n\nexport function ensureNavigationBarDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n if (!customElements.get(NAVIGATION_BAR_TAG)) {\n customElements.define(NAVIGATION_BAR_TAG, WeappNavigationBar)\n }\n}\n\nexport type { NavigationBarMetrics }\n"],"mappings":";;;AAQA,MAAM,qBAAqB;AAC3B,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AACtD,MAAM,yCAAyB,IAAI,IAAwB;AAC3D,IAAI,uBAA6C,CAAC;AAClD,MAAM,gBAAgB;AAEtB,SAAS,QAAQ;CACf,IAAI,OAAO,cAAc,aACvB,OAAO;CAET,OAAO,cAAc,KAAK,UAAU,SAAS;AAC/C;AAEA,SAAS,oBAAoB;CAC3B,IAAI,MAAM,GACR,OAAO;EAAE,iBAAiB;EAAI,kBAAkB;CAAG;CAErD,OAAO;EAAE,iBAAiB;EAAI,kBAAkB;CAAG;AACrD;AAEA,SAAS,kBAAkB;CACzB,IAAI,OAAO,aAAa,eAAe,CAAC,SAAS,MAC/C,OAAO;CAET,MAAM,QAAQ,SAAS,cAAc,KAAK;CAC1C,MAAM,MAAM,UAAU;EACpB;EACA;EACA;EACA;EACA;EACA;CACF,EAAE,KAAK,GAAG;CACV,SAAS,KAAK,YAAY,KAAK;CAC/B,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,sBAAsB,EAAE,MAAM;CAC/D,MAAM,OAAO;CACb,OAAO;AACT;AAEA,SAAS,8BAAsF;CAC7F,MA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AM,UAAU,SAAS,cAAc,KAAK;EAC5C,QAAQ,YAAY;EACpB,MAAM,OAAO,SAAS,cAAc,KAAK;EACzC,KAAK,YAAY;EACjB,MAAM,QAAQ,SAAS,cAAc,KAAK;EAC1C,MAAM,YAAY;EAClB,MAAM,QAAQ,SAAS,cAAc,MAAM;EAC3C,MAAM,YAAY;EAClB,MAAM,UAAU,SAAS,cAAc,MAAM;EAC7C,QAAQ,YAAY;EACpB,QAAQ,aAAa,UAAU,EAAE;EACjC,MAAM,YAAY,SAAS,cAAc,MAAM;EAC/C,UAAU,YAAY;EACtB,MAAM,OAAO,SAAS,SAAS;EAC/B,QAAQ,OAAO,MAAM,OAAO,KAAK;EACjC,IAAI,OAAO,QAAQ,OAAO;EAC1B,KAAK,OAAO,OAAO,QAAQ,GAAG;EAC9B,KAAKC,OAAO;EACZ,KAAKC,SAAS;EACd,KAAKC,WAAW;CAClB;AACF;AAEA,SAAgB,6BAA6B;CAC3C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,IAAI,CAAC,eAAe,IAAI,kBAAkB,GACxC,eAAe,OAAO,oBAAoB,kBAAkB;AAEhE"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#renderShell","#bindResize","#resizeHandler","#nav","#title","#loading"],"sources":["../../../src/runtime/navigationBar/index.ts"],"sourcesContent":["import { NAVBAR_STYLE } from './style'\n\ninterface NavigationBarMetrics {\n statusBarHeight?: number\n navContentHeight?: number\n safeAreaTop?: number\n}\n\nconst NAVIGATION_BAR_TAG = 'weapp-navigation-bar'\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\nconst navigationBarInstances = new Set<WeappNavigationBar>()\nlet navigationBarMetrics: NavigationBarMetrics = {}\nconst IOS_DEVICE_RE = /iphone|ipad|ipod/i\n\nfunction isIOS() {\n if (typeof navigator === 'undefined') {\n return false\n }\n return IOS_DEVICE_RE.test(navigator.userAgent)\n}\n\nfunction getDefaultHeights() {\n if (isIOS()) {\n return { statusBarHeight: 20, navContentHeight: 44 }\n }\n return { statusBarHeight: 24, navContentHeight: 48 }\n}\n\nfunction readSafeAreaTop() {\n if (typeof document === 'undefined' || !document.body) {\n return 0\n }\n const probe = document.createElement('div')\n probe.style.cssText = [\n 'position: absolute',\n 'top: 0',\n 'height: env(safe-area-inset-top)',\n 'height: constant(safe-area-inset-top)',\n 'pointer-events: none',\n 'visibility: hidden',\n ].join(';')\n document.body.appendChild(probe)\n const height = Math.max(0, probe.getBoundingClientRect().height)\n probe.remove()\n return height\n}\n\nfunction resolveNavigationBarMetrics(): Required<NavigationBarMetrics> & { navHeight: number } {\n const defaults = getDefaultHeights()\n const safeAreaTop = navigationBarMetrics.safeAreaTop !== undefined\n ? navigationBarMetrics.safeAreaTop\n : readSafeAreaTop()\n const statusBarHeight = navigationBarMetrics.statusBarHeight !== undefined\n ? navigationBarMetrics.statusBarHeight\n : (safeAreaTop > 0 ? safeAreaTop : defaults.statusBarHeight)\n const navContentHeight = navigationBarMetrics.navContentHeight !== undefined\n ? navigationBarMetrics.navContentHeight\n : defaults.navContentHeight\n return {\n safeAreaTop,\n statusBarHeight,\n navContentHeight,\n navHeight: statusBarHeight + navContentHeight,\n }\n}\n\nfunction isTransparentColor(value: string | null) {\n if (!value) {\n return false\n }\n const normalized = value.trim().toLowerCase()\n return normalized === 'transparent'\n || normalized === 'rgba(0,0,0,0)'\n || normalized === 'rgba(0, 0, 0, 0)'\n || normalized === 'hsla(0,0%,0%,0)'\n}\n\nexport function setNavigationBarMetrics(next: NavigationBarMetrics) {\n navigationBarMetrics = { ...navigationBarMetrics, ...next }\n for (const instance of navigationBarInstances) {\n instance.applyMetrics()\n }\n}\n\nclass WeappNavigationBar extends BaseElement {\n static observedAttributes = ['title', 'background-color', 'text-style', 'front-color', 'loading']\n\n #nav?: HTMLDivElement\n #title?: HTMLSpanElement\n #loading?: HTMLSpanElement\n #resizeHandler?: () => void\n\n connectedCallback() {\n if (!this.shadowRoot) {\n this.attachShadow({ mode: 'open' })\n }\n if (this.shadowRoot && !this.shadowRoot.hasChildNodes()) {\n this.#renderShell()\n }\n navigationBarInstances.add(this)\n this.applyMetrics()\n this.applyAppearance()\n this.#bindResize()\n }\n\n disconnectedCallback() {\n navigationBarInstances.delete(this)\n if (this.#resizeHandler) {\n const target = typeof window !== 'undefined' ? (window.visualViewport ?? window) : undefined\n target?.removeEventListener('resize', this.#resizeHandler)\n this.#resizeHandler = undefined\n }\n }\n\n attributeChangedCallback() {\n this.applyAppearance()\n }\n\n applyMetrics() {\n const metrics = resolveNavigationBarMetrics()\n this.style.setProperty('--weapp-status-bar-height', `${metrics.statusBarHeight}px`)\n this.style.setProperty('--weapp-nav-content-height', `${metrics.navContentHeight}px`)\n this.style.setProperty('--weapp-nav-height', `${metrics.navHeight}px`)\n }\n\n applyAppearance() {\n if (!this.#nav || !this.#title || !this.#loading) {\n return\n }\n const title = this.getAttribute('title') ?? ''\n this.#title.textContent = title\n const background = this.getAttribute('background-color') ?? '#ffffff'\n const frontColor = this.getAttribute('front-color')\n const textStyle = (this.getAttribute('text-style') ?? '').toLowerCase()\n const color = frontColor || (textStyle === 'white' ? '#ffffff' : '#000000')\n const loadingAttr = this.getAttribute('loading')\n const loading = loadingAttr !== null && loadingAttr !== 'false' && loadingAttr !== '0'\n this.style.setProperty('--weapp-nav-bg', background)\n this.style.setProperty('--weapp-nav-color', color)\n this.#loading.toggleAttribute('hidden', !loading)\n this.#nav.classList.toggle('weapp-nav--transparent', isTransparentColor(background))\n }\n\n #bindResize() {\n if (this.#resizeHandler || typeof window === 'undefined') {\n return\n }\n const target = window.visualViewport ?? window\n this.#resizeHandler = () => {\n this.applyMetrics()\n }\n target.addEventListener('resize', this.#resizeHandler)\n }\n\n #renderShell() {\n const root = this.shadowRoot!\n root.innerHTML = ''\n const style = document.createElement('style')\n style.textContent = NAVBAR_STYLE\n const spacer = document.createElement('div')\n spacer.className = 'weapp-nav__spacer'\n const nav = document.createElement('div')\n nav.className = 'weapp-nav'\n const status = document.createElement('div')\n status.className = 'weapp-nav__status'\n const content = document.createElement('div')\n content.className = 'weapp-nav__content'\n const left = document.createElement('div')\n left.className = 'weapp-nav__left'\n const right = document.createElement('div')\n right.className = 'weapp-nav__right'\n const title = document.createElement('span')\n title.className = 'weapp-nav__title'\n const loading = document.createElement('span')\n loading.className = 'weapp-nav__loading'\n loading.setAttribute('hidden', '')\n const titleText = document.createElement('span')\n titleText.className = 'weapp-nav__title-text'\n title.append(loading, titleText)\n content.append(left, title, right)\n nav.append(status, content)\n root.append(style, spacer, nav)\n this.#nav = nav\n this.#title = titleText\n this.#loading = loading\n }\n}\n\nexport function ensureNavigationBarDefined() {\n if (typeof customElements === 'undefined') {\n return\n }\n if (!customElements.get(NAVIGATION_BAR_TAG)) {\n customElements.define(NAVIGATION_BAR_TAG, WeappNavigationBar)\n }\n}\n\nexport type { NavigationBarMetrics }\n"],"mappings":";;;;;;;;;;;AAQA,MAAM,qBAAqB;AAC3B,MAAM,cAAe,WAAW,eAAe,MAAM,CAAC;AACtD,MAAM,yCAAyB,IAAI,IAAwB;AAC3D,IAAI,uBAA6C,CAAC;AAClD,MAAM,gBAAgB;AAEtB,SAAS,QAAQ;CACf,IAAI,OAAO,cAAc,aACvB,OAAO;CAET,OAAO,cAAc,KAAK,UAAU,SAAS;AAC/C;AAEA,SAAS,oBAAoB;CAC3B,IAAI,MAAM,GACR,OAAO;EAAE,iBAAiB;EAAI,kBAAkB;CAAG;CAErD,OAAO;EAAE,iBAAiB;EAAI,kBAAkB;CAAG;AACrD;AAEA,SAAS,kBAAkB;CACzB,IAAI,OAAO,aAAa,eAAe,CAAC,SAAS,MAC/C,OAAO;CAET,MAAM,QAAQ,SAAS,cAAc,KAAK;CAC1C,MAAM,MAAM,UAAU;EACpB;EACA;EACA;EACA;EACA;EACA;CACF,EAAE,KAAK,GAAG;CACV,SAAS,KAAK,YAAY,KAAK;CAC/B,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,sBAAsB,EAAE,MAAM;CAC/D,MAA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M,SAAS,SAAS,cAAc,KAAK;EAC3C,OAAO,YAAY;EACnB,MAAM,UAAU,SAAS,cAAc,KAAK;EAC5C,QAAQ,YAAY;EACpB,MAAM,OAAO,SAAS,cAAc,KAAK;EACzC,KAAK,YAAY;EACjB,MAAM,QAAQ,SAAS,cAAc,KAAK;EAC1C,MAAM,YAAY;EAClB,MAAM,QAAQ,SAAS,cAAc,MAAM;EAC3C,MAAM,YAAY;EAClB,MAAM,UAAU,SAAS,cAAc,MAAM;EAC7C,QAAQ,YAAY;EACpB,QAAQ,aAAa,UAAU,EAAE;EACjC,MAAM,YAAY,SAAS,cAAc,MAAM;EAC/C,UAAU,YAAY;EACtB,MAAM,OAAO,SAAS,SAAS;EAC/B,QAAQ,OAAO,MAAM,OAAO,KAAK;EACjC,IAAI,OAAO,QAAQ,OAAO;EAC1B,KAAK,OAAO,OAAO,QAAQ,GAAG;EAC9B,KAAKC,OAAO;EACZ,KAAKC,SAAS;EACd,KAAKC,WAAW;CAClB;AACF;AAEA,SAAgB,6BAA6B;CAC3C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,IAAI,CAAC,eAAe,IAAI,kBAAkB,GACxC,eAAe,OAAO,oBAAoB,kBAAkB;AAEhE"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
//#region src/runtime/navigationBar/style.ts
|
|
2
10
|
const NAVBAR_STYLE = `
|
|
3
11
|
:host {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/navigationBar/style.ts"],"sourcesContent":["export const NAVBAR_STYLE = `\n:host {\n --weapp-status-bar-height: 20px;\n --weapp-nav-content-height: 44px;\n --weapp-nav-height: calc(var(--weapp-status-bar-height) + var(--weapp-nav-content-height));\n --weapp-nav-bg: #ffffff;\n --weapp-nav-color: #000000;\n --weapp-nav-transition-duration: 0ms;\n --weapp-nav-transition-easing: ease;\n display: block;\n position: relative;\n z-index: 999;\n font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;\n}\n\n.weapp-nav__spacer {\n height: var(--weapp-nav-height);\n}\n\n.weapp-nav {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: var(--weapp-nav-height);\n display: flex;\n flex-direction: column;\n background: var(--weapp-nav-bg);\n color: var(--weapp-nav-color);\n box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.1);\n transition:\n background-color var(--weapp-nav-transition-duration) var(--weapp-nav-transition-easing),\n color var(--weapp-nav-transition-duration) var(--weapp-nav-transition-easing);\n}\n\n.weapp-nav--transparent {\n box-shadow: none;\n}\n\n.weapp-nav__status {\n height: var(--weapp-status-bar-height);\n}\n\n.weapp-nav__content {\n height: var(--weapp-nav-content-height);\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n padding: 0 12px;\n box-sizing: border-box;\n font-size: 17px;\n font-weight: 500;\n line-height: 1;\n}\n\n.weapp-nav__left,\n.weapp-nav__right {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 88px;\n display: flex;\n align-items: center;\n}\n\n.weapp-nav__left {\n left: 12px;\n}\n\n.weapp-nav__right {\n right: 12px;\n justify-content: flex-end;\n}\n\n.weapp-nav__title {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n max-width: 70%;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.weapp-nav__loading {\n width: 12px;\n height: 12px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-nav-spin 0.8s linear infinite;\n}\n\n.weapp-nav__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-nav-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/navigationBar/style.ts"],"sourcesContent":["export const NAVBAR_STYLE = `\n:host {\n --weapp-status-bar-height: 20px;\n --weapp-nav-content-height: 44px;\n --weapp-nav-height: calc(var(--weapp-status-bar-height) + var(--weapp-nav-content-height));\n --weapp-nav-bg: #ffffff;\n --weapp-nav-color: #000000;\n --weapp-nav-transition-duration: 0ms;\n --weapp-nav-transition-easing: ease;\n display: block;\n position: relative;\n z-index: 999;\n font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;\n}\n\n.weapp-nav__spacer {\n height: var(--weapp-nav-height);\n}\n\n.weapp-nav {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n height: var(--weapp-nav-height);\n display: flex;\n flex-direction: column;\n background: var(--weapp-nav-bg);\n color: var(--weapp-nav-color);\n box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.1);\n transition:\n background-color var(--weapp-nav-transition-duration) var(--weapp-nav-transition-easing),\n color var(--weapp-nav-transition-duration) var(--weapp-nav-transition-easing);\n}\n\n.weapp-nav--transparent {\n box-shadow: none;\n}\n\n.weapp-nav__status {\n height: var(--weapp-status-bar-height);\n}\n\n.weapp-nav__content {\n height: var(--weapp-nav-content-height);\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n padding: 0 12px;\n box-sizing: border-box;\n font-size: 17px;\n font-weight: 500;\n line-height: 1;\n}\n\n.weapp-nav__left,\n.weapp-nav__right {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 88px;\n display: flex;\n align-items: center;\n}\n\n.weapp-nav__left {\n left: 12px;\n}\n\n.weapp-nav__right {\n right: 12px;\n justify-content: flex-end;\n}\n\n.weapp-nav__title {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n max-width: 70%;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.weapp-nav__loading {\n width: 12px;\n height: 12px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-nav-spin 0.8s linear infinite;\n}\n\n.weapp-nav__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-nav-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n"],"mappings":";;;;;;;;;AAAA,MAAa,eAAe"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
//#region src/runtime/polyfill/ad.ts
|
|
2
10
|
function createAdError(errMsg) {
|
|
3
11
|
return {
|