@weapp-vite/web 1.3.20 → 1.3.22
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/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/dependency.mjs.map +1 -1
- package/dist/compiler/wxml/interpolation.mjs.map +1 -1
- package/dist/compiler/wxml/navigation.mjs.map +1 -1
- package/dist/compiler/wxml/parser.mjs.map +1 -1
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/compiler/wxs.mjs.map +1 -1
- package/dist/css/wxss.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/entry.mjs.map +1 -1
- package/dist/plugin/files.mjs.map +1 -1
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/navigation.mjs.map +1 -1
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/scanConfig.mjs.map +1 -1
- package/dist/plugin/state.mjs.map +1 -1
- package/dist/runtime/button/helpers.mjs.map +1 -1
- package/dist/runtime/button/index.mjs.map +1 -1
- package/dist/runtime/button/style.mjs.map +1 -1
- package/dist/runtime/component/behavior.mjs.map +1 -1
- package/dist/runtime/component/constants.mjs.map +1 -1
- package/dist/runtime/component/dom.mjs.map +1 -1
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/component/index.mjs.map +1 -1
- package/dist/runtime/component/state.mjs.map +1 -1
- package/dist/runtime/component/utils.mjs.map +1 -1
- package/dist/runtime/execution.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
- package/dist/runtime/navigationBar/index.mjs.map +1 -1
- package/dist/runtime/polyfill/ad.mjs.map +1 -1
- package/dist/runtime/polyfill/appState.mjs.map +1 -1
- package/dist/runtime/polyfill/async.mjs.map +1 -1
- package/dist/runtime/polyfill/auth.mjs.map +1 -1
- package/dist/runtime/polyfill/authApi.mjs.map +1 -1
- package/dist/runtime/polyfill/background.mjs.map +1 -1
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
- package/dist/runtime/polyfill/capability.mjs.map +1 -1
- package/dist/runtime/polyfill/cloud.mjs.map +1 -1
- package/dist/runtime/polyfill/device.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/filePicker.mjs.map +1 -1
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -1
- package/dist/runtime/polyfill/files.mjs.map +1 -1
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/interaction.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/location.mjs.map +1 -1
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/network/request.mjs.map +1 -1
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -1
- package/dist/runtime/polyfill/network/status.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
- package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.mjs.map +1 -1
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/subscribe.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
- package/dist/runtime/polyfill/ui.mjs.map +1 -1
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -1
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -1
- package/dist/runtime/polyfill/windowResize.mjs.map +1 -1
- package/dist/runtime/polyfill/worker.mjs.map +1 -1
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.mjs.map +1 -1
- package/dist/runtime/style.mjs.map +1 -1
- package/dist/runtime/utils/object.mjs.map +1 -1
- package/dist/runtime/warning.mjs.map +1 -1
- package/dist/shared/slugify.mjs.map +1 -1
- package/dist/shared/wxml.mjs.map +1 -1
- package/package.json +4 -4
package/dist/plugin/scan.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.mjs","names":[],"sources":["../../src/plugin/scan.ts"],"sourcesContent":["import type { ComponentEntry, PageEntry, ScanState, WarnFn } from './types'\nimport process from 'node:process'\n\nimport { dirname, extname, join, posix, relative, resolve } from 'pathe'\nimport { slugify } from '../shared/slugify'\nimport { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from './files'\nimport { mergeNavigationConfig, pickNavigationConfig } from './navigation'\nimport { normalizePath, toPosixId } from './path'\nimport { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from './scanConfig'\n\ninterface ScanProjectOptions {\n srcRoot: string\n warn?: WarnFn\n state: ScanState\n}\n\nexport async function scanProject({ srcRoot, warn, state }: ScanProjectOptions) {\n state.moduleMeta.clear()\n state.pageNavigationMap.clear()\n state.templateComponentMap.clear()\n state.templatePathSet.clear()\n state.componentTagMap.clear()\n state.componentIdMap.clear()\n\n let appNavigationDefaults = {}\n let appComponentTags: Record<string, string> = {}\n\n const pages = new Map<string, PageEntry>()\n const components = new Map<string, ComponentEntry>()\n\n const reportWarning = (message: string) => {\n if (warn) {\n warn(message)\n return\n }\n if (typeof process !== 'undefined' && typeof process.emitWarning === 'function') {\n process.emitWarning(message)\n }\n }\n\n const appScript = await resolveScriptFile(join(srcRoot, 'app'))\n if (appScript) {\n state.moduleMeta.set(normalizePath(appScript), {\n kind: 'app',\n id: 'app',\n scriptPath: appScript,\n stylePath: await resolveStyleFile(appScript),\n })\n }\n\n const resolveComponentScript = async (raw: string, importerDir: string) => {\n const base = resolveComponentBase(raw, importerDir, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveScriptFile(base)\n }\n\n const getComponentId = (script: string) => {\n const cached = state.componentIdMap.get(script)\n if (cached) {\n return cached\n }\n const idRelative = relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), '')\n const componentIdPosix = toPosixId(idRelative)\n state.componentIdMap.set(script, componentIdPosix)\n return componentIdPosix\n }\n\n const getComponentTag = (script: string) => {\n const cached = state.componentTagMap.get(script)\n if (cached) {\n return cached\n }\n const id = getComponentId(script)\n const tag = slugify(id, 'wv-component')\n state.componentTagMap.set(script, tag)\n return tag\n }\n\n const collectComponent = async (componentId: string, importerDir: string) => {\n const base = resolveComponentBase(componentId, importerDir, srcRoot)\n const script = base ? await resolveScriptFile(base) : undefined\n if (!script || components.has(script)) {\n return\n }\n\n const idRelative = relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), '')\n const componentIdPosix = toPosixId(idRelative)\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n state.moduleMeta.set(normalizePath(script), {\n kind: 'component',\n id: componentIdPosix,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n })\n\n components.set(script, { script, id: componentIdPosix })\n\n const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), '')}.json`\n const componentTags = await collectComponentTagsFromJson({\n jsonBasePath: componentJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir: nextImporterDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n\n if (!template) {\n return\n }\n\n const mergedTags = mergeComponentTags(appComponentTags, componentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n return\n }\n state.templateComponentMap.delete(normalizePath(template))\n }\n\n const appJsonBasePath = join(srcRoot, 'app.json')\n const appJsonPath = await resolveJsonPath(appJsonBasePath)\n if (appJsonPath) {\n const appJson = await readJsonFile(appJsonPath)\n\n if (appJson) {\n appComponentTags = await collectComponentTagsFromConfig({\n json: appJson,\n importerDir: srcRoot,\n jsonPath: appJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved: (tags) => {\n appComponentTags = tags\n },\n })\n }\n\n if (appJson?.pages && Array.isArray(appJson.pages)) {\n for (const page of appJson.pages) {\n if (typeof page === 'string') {\n await collectPage(page)\n }\n }\n }\n\n if (appJson?.subPackages && Array.isArray(appJson.subPackages)) {\n for (const pkg of appJson.subPackages) {\n if (!pkg || typeof pkg !== 'object' || !Array.isArray(pkg.pages)) {\n continue\n }\n const root = typeof pkg.root === 'string' ? pkg.root : ''\n for (const page of pkg.pages) {\n if (typeof page !== 'string') {\n continue\n }\n await collectPage(posix.join(root, page))\n }\n }\n }\n\n const windowConfig = isRecord(appJson?.window) ? appJson.window : undefined\n appNavigationDefaults = pickNavigationConfig(windowConfig)\n }\n\n state.appNavigationDefaults = appNavigationDefaults\n state.appComponentTags = appComponentTags\n state.scanResult = {\n app: appScript,\n pages: Array.from(pages.values()),\n components: Array.from(components.values()),\n }\n\n async function collectPage(pageId: string) {\n const base = join(srcRoot, pageId)\n const script = await resolveScriptFile(base)\n if (!script) {\n return\n }\n\n const template = await resolveTemplateFile(base)\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const style = await resolveStyleFile(base)\n const pageJsonBasePath = join(srcRoot, `${pageId}.json`)\n const pageJsonPath = await resolveJsonPath(pageJsonBasePath)\n const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : undefined\n\n state.moduleMeta.set(normalizePath(script), {\n kind: 'page',\n id: toPosixId(pageId),\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n })\n\n pages.set(script, {\n script,\n id: toPosixId(pageId),\n })\n\n const pageComponentTags = pageJson && pageJsonPath\n ? await collectComponentTagsFromConfig({\n json: pageJson,\n importerDir: dirname(script),\n jsonPath: pageJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : await collectComponentTagsFromJson({\n jsonBasePath: pageJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, importerDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n\n if (template) {\n const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n }\n else {\n state.templateComponentMap.delete(normalizePath(template))\n }\n }\n\n if (!template) {\n return\n }\n\n if (pageJson) {\n state.pageNavigationMap.set(\n normalizePath(template),\n mergeNavigationConfig(appNavigationDefaults, pickNavigationConfig(pageJson)),\n )\n return\n }\n\n state.pageNavigationMap.set(normalizePath(template), { ...appNavigationDefaults })\n }\n}\n\nfunction resolveComponentBase(raw: string, importerDir: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(importerDir, raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot, raw)\n}\n"],"mappings":";;;;;;;;;AAgBA,eAAsB,YAAY,EAAE,SAAS,MAAM,SAA6B;CAC9E,MAAM,WAAW,OAAO;CACxB,MAAM,kBAAkB,OAAO;CAC/B,MAAM,qBAAqB,OAAO;CAClC,MAAM,gBAAgB,OAAO;CAC7B,MAAM,gBAAgB,OAAO;CAC7B,MAAM,eAAe,OAAO;CAE5B,IAAI,wBAAwB,EAAE;CAC9B,IAAI,mBAA2C,EAAE;CAEjD,MAAM,wBAAQ,IAAI,KAAwB;CAC1C,MAAM,6BAAa,IAAI,KAA6B;CAEpD,MAAM,iBAAiB,YAAoB;EACzC,IAAI,MAAM;GACR,KAAK,QAAQ;GACb;;EAEF,IAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,gBAAgB,YACnE,QAAQ,YAAY,QAAQ;;CAIhC,MAAM,YAAY,MAAM,kBAAkB,KAAK,SAAS,MAAM,CAAC;CAC/D,IAAI,WACF,M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ACH,CAAC;EAEN,IAAI,UAAU;GACZ,MAAM,aAAa,mBAAmB,kBAAkB,kBAAkB;GAC1E,IAAI,OAAO,KAAK,WAAW,CAAC,SAAS,GACnC,MAAM,qBAAqB,IAAI,cAAc,SAAS,EAAE,WAAW;QAGnE,MAAM,qBAAqB,OAAO,cAAc,SAAS,CAAC;;EAI9D,IAAI,CAAC,UACH;EAGF,IAAI,UAAU;GACZ,MAAM,kBAAkB,IACtB,cAAc,SAAS,EACvB,sBAAsB,uBAAuB,qBAAqB,SAAS,CAAC,CAC7E;GACD;;EAGF,MAAM,kBAAkB,IAAI,cAAc,SAAS,EAAE,EAAE,GAAG,uBAAuB,CAAC;;;AAItF,SAAS,qBAAqB,KAAa,aAAqB,SAAiB;CAC/E,IAAI,CAAC,KACH;CAEF,IAAI,IAAI,WAAW,IAAI,EACrB,OAAO,QAAQ,aAAa,IAAI;CAElC,IAAI,IAAI,WAAW,IAAI,EACrB,OAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAC;CAEvC,OAAO,QAAQ,SAAS,IAAI"}
|
|
1
|
+
{"version":3,"file":"scan.mjs","names":[],"sources":["../../src/plugin/scan.ts"],"sourcesContent":["import type { ComponentEntry, PageEntry, ScanState, WarnFn } from './types'\nimport process from 'node:process'\n\nimport { dirname, extname, join, posix, relative, resolve } from 'pathe'\nimport { slugify } from '../shared/slugify'\nimport { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from './files'\nimport { mergeNavigationConfig, pickNavigationConfig } from './navigation'\nimport { normalizePath, toPosixId } from './path'\nimport { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from './scanConfig'\n\ninterface ScanProjectOptions {\n srcRoot: string\n warn?: WarnFn\n state: ScanState\n}\n\nexport async function scanProject({ srcRoot, warn, state }: ScanProjectOptions) {\n state.moduleMeta.clear()\n state.pageNavigationMap.clear()\n state.templateComponentMap.clear()\n state.templatePathSet.clear()\n state.componentTagMap.clear()\n state.componentIdMap.clear()\n\n let appNavigationDefaults = {}\n let appComponentTags: Record<string, string> = {}\n\n const pages = new Map<string, PageEntry>()\n const components = new Map<string, ComponentEntry>()\n\n const reportWarning = (message: string) => {\n if (warn) {\n warn(message)\n return\n }\n if (typeof process !== 'undefined' && typeof process.emitWarning === 'function') {\n process.emitWarning(message)\n }\n }\n\n const appScript = await resolveScriptFile(join(srcRoot, 'app'))\n if (appScript) {\n state.moduleMeta.set(normalizePath(appScript), {\n kind: 'app',\n id: 'app',\n scriptPath: appScript,\n stylePath: await resolveStyleFile(appScript),\n })\n }\n\n const resolveComponentScript = async (raw: string, importerDir: string) => {\n const base = resolveComponentBase(raw, importerDir, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveScriptFile(base)\n }\n\n const getComponentId = (script: string) => {\n const cached = state.componentIdMap.get(script)\n if (cached) {\n return cached\n }\n const idRelative = relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), '')\n const componentIdPosix = toPosixId(idRelative)\n state.componentIdMap.set(script, componentIdPosix)\n return componentIdPosix\n }\n\n const getComponentTag = (script: string) => {\n const cached = state.componentTagMap.get(script)\n if (cached) {\n return cached\n }\n const id = getComponentId(script)\n const tag = slugify(id, 'wv-component')\n state.componentTagMap.set(script, tag)\n return tag\n }\n\n const collectComponent = async (componentId: string, importerDir: string) => {\n const base = resolveComponentBase(componentId, importerDir, srcRoot)\n const script = base ? await resolveScriptFile(base) : undefined\n if (!script || components.has(script)) {\n return\n }\n\n const idRelative = relative(srcRoot, script).replace(new RegExp(`${extname(script)}$`), '')\n const componentIdPosix = toPosixId(idRelative)\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n state.moduleMeta.set(normalizePath(script), {\n kind: 'component',\n id: componentIdPosix,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n })\n\n components.set(script, { script, id: componentIdPosix })\n\n const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), '')}.json`\n const componentTags = await collectComponentTagsFromJson({\n jsonBasePath: componentJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir: nextImporterDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n\n if (!template) {\n return\n }\n\n const mergedTags = mergeComponentTags(appComponentTags, componentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n return\n }\n state.templateComponentMap.delete(normalizePath(template))\n }\n\n const appJsonBasePath = join(srcRoot, 'app.json')\n const appJsonPath = await resolveJsonPath(appJsonBasePath)\n if (appJsonPath) {\n const appJson = await readJsonFile(appJsonPath)\n\n if (appJson) {\n appComponentTags = await collectComponentTagsFromConfig({\n json: appJson,\n importerDir: srcRoot,\n jsonPath: appJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved: (tags) => {\n appComponentTags = tags\n },\n })\n }\n\n if (appJson?.pages && Array.isArray(appJson.pages)) {\n for (const page of appJson.pages) {\n if (typeof page === 'string') {\n await collectPage(page)\n }\n }\n }\n\n if (appJson?.subPackages && Array.isArray(appJson.subPackages)) {\n for (const pkg of appJson.subPackages) {\n if (!pkg || typeof pkg !== 'object' || !Array.isArray(pkg.pages)) {\n continue\n }\n const root = typeof pkg.root === 'string' ? pkg.root : ''\n for (const page of pkg.pages) {\n if (typeof page !== 'string') {\n continue\n }\n await collectPage(posix.join(root, page))\n }\n }\n }\n\n const windowConfig = isRecord(appJson?.window) ? appJson.window : undefined\n appNavigationDefaults = pickNavigationConfig(windowConfig)\n }\n\n state.appNavigationDefaults = appNavigationDefaults\n state.appComponentTags = appComponentTags\n state.scanResult = {\n app: appScript,\n pages: Array.from(pages.values()),\n components: Array.from(components.values()),\n }\n\n async function collectPage(pageId: string) {\n const base = join(srcRoot, pageId)\n const script = await resolveScriptFile(base)\n if (!script) {\n return\n }\n\n const template = await resolveTemplateFile(base)\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const style = await resolveStyleFile(base)\n const pageJsonBasePath = join(srcRoot, `${pageId}.json`)\n const pageJsonPath = await resolveJsonPath(pageJsonBasePath)\n const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : undefined\n\n state.moduleMeta.set(normalizePath(script), {\n kind: 'page',\n id: toPosixId(pageId),\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n })\n\n pages.set(script, {\n script,\n id: toPosixId(pageId),\n })\n\n const pageComponentTags = pageJson && pageJsonPath\n ? await collectComponentTagsFromConfig({\n json: pageJson,\n importerDir: dirname(script),\n jsonPath: pageJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : await collectComponentTagsFromJson({\n jsonBasePath: pageJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, importerDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n\n if (template) {\n const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n }\n else {\n state.templateComponentMap.delete(normalizePath(template))\n }\n }\n\n if (!template) {\n return\n }\n\n if (pageJson) {\n state.pageNavigationMap.set(\n normalizePath(template),\n mergeNavigationConfig(appNavigationDefaults, pickNavigationConfig(pageJson)),\n )\n return\n }\n\n state.pageNavigationMap.set(normalizePath(template), { ...appNavigationDefaults })\n }\n}\n\nfunction resolveComponentBase(raw: string, importerDir: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(importerDir, raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot,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O,QAAQ,SAAS,IAAI,MAAM,CAAC,CAAC;CAEtC,OAAO,QAAQ,SAAS,GAAG;AAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanConfig.mjs","names":[],"sources":["../../src/plugin/scanConfig.ts"],"sourcesContent":["import type { WarnFn } from './types'\nimport { readJsonFile, resolveJsonPath } from './files'\n\ninterface CollectComponentTagsFromConfigOptions {\n json: Record<string, unknown>\n importerDir: string\n jsonPath: string\n warn: WarnFn\n resolveComponentScript: (raw: string, importerDir: string) => Promise<string | undefined>\n getComponentTag: (script: string) => string\n collectComponent: (componentId: string, importerDir: string) => Promise<void>\n onResolved?: (tags: Record<string, string>) => void\n}\n\nexport async function collectComponentTagsFromConfig({\n json,\n importerDir,\n jsonPath,\n warn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved,\n}: CollectComponentTagsFromConfigOptions) {\n const usingComponents = json.usingComponents\n if (!usingComponents || typeof usingComponents !== 'object') {\n return {}\n }\n\n const tags: Record<string, string> = {}\n const resolved: Array<{ rawValue: string }> = []\n\n for (const [rawKey, rawValue] of Object.entries(usingComponents)) {\n if (typeof rawValue !== 'string') {\n continue\n }\n const key = normalizeComponentKey(rawKey)\n if (!key) {\n continue\n }\n const script = await resolveComponentScript(rawValue, importerDir)\n if (!script) {\n warn(`[@weapp-vite/web] usingComponents entry \"${rawKey}\" not found: ${rawValue} (${jsonPath})`)\n continue\n }\n const tag = getComponentTag(script)\n tags[key] = tag\n resolved.push({ rawValue })\n }\n\n onResolved?.(tags)\n for (const entry of resolved) {\n await collectComponent(entry.rawValue, importerDir)\n }\n\n return tags\n}\n\ninterface CollectComponentTagsFromJsonOptions {\n jsonBasePath: string\n importerDir: string\n warn: WarnFn\n collectFromConfig: (json: Record<string, unknown>, importerDir: string, jsonPath: string, warn: WarnFn) => Promise<Record<string, string>>\n}\n\nexport async function collectComponentTagsFromJson({\n jsonBasePath,\n importerDir,\n warn,\n collectFromConfig,\n}: CollectComponentTagsFromJsonOptions) {\n const resolvedPath = await resolveJsonPath(jsonBasePath)\n if (!resolvedPath) {\n return {}\n }\n const json = await readJsonFile(resolvedPath)\n if (!json) {\n return {}\n }\n return collectFromConfig(json, importerDir, resolvedPath, warn)\n}\n\nexport function mergeComponentTags(base: Record<string, string>, overrides: Record<string, string>) {\n if (!Object.keys(base).length && !Object.keys(overrides).length) {\n return {}\n }\n return {\n ...base,\n ...overrides,\n }\n}\n\nfunction normalizeComponentKey(raw: string) {\n return raw.trim().toLowerCase()\n}\n"],"mappings":";;;AAcA,eAAsB,+BAA+B,EACnD,MACA,aACA,UACA,MACA,wBACA,iBACA,kBACA,cACwC;CACxC,MAAM,kBAAkB,KAAK;CAC7B,IAAI,CAAC,mBAAmB,OAAO,oBAAoB,UACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"scanConfig.mjs","names":[],"sources":["../../src/plugin/scanConfig.ts"],"sourcesContent":["import type { WarnFn } from './types'\nimport { readJsonFile, resolveJsonPath } from './files'\n\ninterface CollectComponentTagsFromConfigOptions {\n json: Record<string, unknown>\n importerDir: string\n jsonPath: string\n warn: WarnFn\n resolveComponentScript: (raw: string, importerDir: string) => Promise<string | undefined>\n getComponentTag: (script: string) => string\n collectComponent: (componentId: string, importerDir: string) => Promise<void>\n onResolved?: (tags: Record<string, string>) => void\n}\n\nexport async function collectComponentTagsFromConfig({\n json,\n importerDir,\n jsonPath,\n warn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved,\n}: CollectComponentTagsFromConfigOptions) {\n const usingComponents = json.usingComponents\n if (!usingComponents || typeof usingComponents !== 'object') {\n return {}\n }\n\n const tags: Record<string, string> = {}\n const resolved: Array<{ rawValue: string }> = []\n\n for (const [rawKey, rawValue] of Object.entries(usingComponents)) {\n if (typeof rawValue !== 'string') {\n continue\n }\n const key = normalizeComponentKey(rawKey)\n if (!key) {\n continue\n }\n const script = await resolveComponentScript(rawValue, importerDir)\n if (!script) {\n warn(`[@weapp-vite/web] usingComponents entry \"${rawKey}\" not found: ${rawValue} (${jsonPath})`)\n continue\n }\n const tag = getComponentTag(script)\n tags[key] = tag\n resolved.push({ rawValue })\n }\n\n onResolved?.(tags)\n for (const entry of resolved) {\n await collectComponent(entry.rawValue, importerDir)\n }\n\n return tags\n}\n\ninterface CollectComponentTagsFromJsonOptions {\n jsonBasePath: string\n importerDir: string\n warn: WarnFn\n collectFromConfig: (json: Record<string, unknown>, importerDir: string, jsonPath: string, warn: WarnFn) => Promise<Record<string, string>>\n}\n\nexport async function collectComponentTagsFromJson({\n jsonBasePath,\n importerDir,\n warn,\n collectFromConfig,\n}: CollectComponentTagsFromJsonOptions) {\n const resolvedPath = await resolveJsonPath(jsonBasePath)\n if (!resolvedPath) {\n return {}\n }\n const json = await readJsonFile(resolvedPath)\n if (!json) {\n return {}\n }\n return collectFromConfig(json, importerDir, resolvedPath, warn)\n}\n\nexport function mergeComponentTags(base: Record<string, string>, overrides: Record<string, string>) {\n if (!Object.keys(base).length && !Object.keys(overrides).length) {\n return {}\n }\n return {\n ...base,\n ...overrides,\n }\n}\n\nfunction normalizeComponentKey(raw: string) {\n return raw.trim().toLowerCase()\n}\n"],"mappings":";;;AAcA,eAAsB,+BAA+B,EACnD,MACA,aACA,UACA,MACA,wBACA,iBACA,kBACA,cACwC;CACxC,MAAM,kBAAkB,KAAK;CAC7B,IAAI,CAAC,mBAAmB,OAAO,oBAAoB,UACjD,OAAO,CAAC;CAGV,MAAM,OAA+B,CAAC;CACtC,MAAM,WAAwC,CAAC;CAE/C,KAAK,MAAM,CAAC,QAAQ,aAAa,OAAO,QAAQ,eAAe,GAAG;EAChE,IAAI,OAAO,aAAa,UACtB;EAEF,MAAM,MAAM,sBAAsB,MAAM;EACxC,IAAI,CAAC,KACH;EAEF,MAAM,SAAS,MAAM,uBAAuB,UAAU,WAAW;EACjE,IAAI,CAAC,QAAQ;GACX,KAAK,4CAA4C,OAAO,eAAe,SAAS,IAAI,SAAS,EAAE;GAC/F;EACF;EAEA,KAAK,OADO,gBAAgB,MACd;EACd,SAAS,KAAK,EAAE,SAAS,CAAC;CAC5B;CAEA,aAAa,IAAI;CACjB,KAAK,MAAM,SAAS,UAClB,MAAM,iBAAiB,MAAM,UAAU,WAAW;CAGpD,OAAO;AACT;AASA,eAAsB,6BAA6B,EACjD,cACA,aACA,MACA,qBACsC;CACtC,MAAM,eAAe,MAAM,gBAAgB,YAAY;CACvD,IAAI,CAAC,cACH,OAAO,CAAC;CAEV,MAAM,OAAO,MAAM,aAAa,YAAY;CAC5C,IAAI,CAAC,MACH,OAAO,CAAC;CAEV,OAAO,kBAAkB,MAAM,aAAa,cAAc,IAAI;AAChE;AAEA,SAAgB,mBAAmB,MAA8B,WAAmC;CAClG,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,QACvD,OAAO,CAAC;CAEV,OAAO;EACL,GAAG;EACH,GAAG;CACL;AACF;AAEA,SAAS,sBAAsB,KAAa;CAC1C,OAAO,IAAI,KAAK,EAAE,YAAY;AAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../src/plugin/state.ts"],"sourcesContent":["import type { ScanState } from './types'\n\nexport function createEmptyScanState(): ScanState {\n return {\n moduleMeta: new Map(),\n pageNavigationMap: new Map(),\n templateComponentMap: new Map(),\n templatePathSet: new Set(),\n componentTagMap: new Map(),\n componentIdMap: new Map(),\n appNavigationDefaults: {},\n appComponentTags: {},\n scanResult: {\n app: undefined,\n pages: [],\n components: [],\n },\n }\n}\n"],"mappings":";AAEA,SAAgB,uBAAkC;CAChD,OAAO;EACL,4BAAY,IAAI,
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../src/plugin/state.ts"],"sourcesContent":["import type { ScanState } from './types'\n\nexport function createEmptyScanState(): ScanState {\n return {\n moduleMeta: new Map(),\n pageNavigationMap: new Map(),\n templateComponentMap: new Map(),\n templatePathSet: new Set(),\n componentTagMap: new Map(),\n componentIdMap: new Map(),\n appNavigationDefaults: {},\n appComponentTags: {},\n scanResult: {\n app: undefined,\n pages: [],\n components: [],\n },\n }\n}\n"],"mappings":";AAEA,SAAgB,uBAAkC;CAChD,OAAO;EACL,4BAAY,IAAI,IAAI;EACpB,mCAAmB,IAAI,IAAI;EAC3B,sCAAsB,IAAI,IAAI;EAC9B,iCAAiB,IAAI,IAAI;EACzB,iCAAiB,IAAI,IAAI;EACzB,gCAAgB,IAAI,IAAI;EACxB,uBAAuB,CAAC;EACxB,kBAAkB,CAAC;EACnB,YAAY;GACV,KAAK;GACL,OAAO,CAAC;GACR,YAAY,CAAC;EACf;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/runtime/button/helpers.ts"],"sourcesContent":["const DEFAULT_HOVER_CLASS = 'button-hover'\n\nexport const DEFAULT_HOVER_START = 20\nexport const DEFAULT_HOVER_STAY = 70\n\nexport function toBoolean(value: string | null) {\n if (value === null) {\n return false\n }\n const normalized = value.trim().toLowerCase()\n if (normalized === '' || normalized === 'true') {\n return true\n }\n return normalized !== 'false' && normalized !== '0'\n}\n\nexport function parseNumber(value: string | null, fallback: number) {\n if (value === null || value === '') {\n return fallback\n }\n const numeric = Number(value)\n return Number.isFinite(numeric) ? numeric : fallback\n}\n\nexport function isDisabled(element: HTMLElement) {\n return toBoolean(element.getAttribute('disabled')) || toBoolean(element.getAttribute('loading'))\n}\n\nexport function normalizeType(value: string | null) {\n if (!value) {\n return 'default'\n }\n const normalized = value.toLowerCase()\n if (normalized === 'primary' || normalized === 'warn') {\n return normalized\n }\n return 'default'\n}\n\nexport function getHoverClass(element: HTMLElement) {\n const hoverClass = element.getAttribute('hover-class')\n if (!hoverClass) {\n return DEFAULT_HOVER_CLASS\n }\n if (hoverClass === 'none') {\n return ''\n }\n return hoverClass\n}\n\nexport function isInternalNode(node: Node) {\n return node instanceof HTMLElement && node.dataset?.weappInternal === 'true'\n}\n\nexport function collectFormValues(form: HTMLFormElement) {\n const values: Record<string, any> = {}\n\n const appendValue = (name: string, value: any, multiple = false) => {\n if (multiple) {\n if (!Array.isArray(values[name])) {\n values[name] = values[name] === undefined ? [] : [values[name]]\n }\n values[name].push(value)\n return\n }\n values[name] = value\n }\n\n const formElements = Array.from(form.elements ?? [])\n for (const element of formElements) {\n if (!(element instanceof HTMLElement)) {\n continue\n }\n const name = element.getAttribute('name')?.trim()\n if (!name) {\n continue\n }\n const disabled = 'disabled' in element ? (element as any).disabled : toBoolean(element.getAttribute('disabled'))\n if (disabled) {\n continue\n }\n if (element instanceof HTMLInputElement) {\n const type = element.type?.toLowerCase()\n if (type === 'checkbox') {\n if (element.checked) {\n appendValue(name, element.value, true)\n }\n continue\n }\n if (type === 'radio') {\n if (element.checked) {\n appendValue(name, element.value)\n }\n continue\n }\n appendValue(name, element.value)\n continue\n }\n if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {\n appendValue(name, (element as HTMLTextAreaElement | HTMLSelectElement).value)\n continue\n }\n }\n\n const customControls = form.querySelectorAll('switch, checkbox, radio, picker, slider, weapp-switch, weapp-checkbox, weapp-radio, weapp-picker, weapp-slider')\n for (const element of Array.from(customControls)) {\n const name = element.getAttribute('name')?.trim()\n if (!name) {\n continue\n }\n const disabled = toBoolean(element.getAttribute('disabled'))\n if (disabled) {\n continue\n }\n const tag = element.tagName.toLowerCase()\n const rawValue = (element as any).value ?? element.getAttribute('value')\n if (tag.includes('checkbox')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n if (checked) {\n appendValue(name, rawValue ?? true, true)\n }\n continue\n }\n if (tag.includes('radio')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n if (checked) {\n appendValue(name, rawValue ?? true)\n }\n continue\n }\n if (tag.includes('switch')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n appendValue(name, checked)\n continue\n }\n appendValue(name, rawValue ?? '')\n }\n\n return values\n}\n"],"mappings":";AAAA,MAAM,sBAAsB;AAK5B,SAAgB,UAAU,OAAsB;CAC9C,IAAI,UAAU,MACZ,OAAO;CAET,MAAM,aAAa,MAAM,
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/runtime/button/helpers.ts"],"sourcesContent":["const DEFAULT_HOVER_CLASS = 'button-hover'\n\nexport const DEFAULT_HOVER_START = 20\nexport const DEFAULT_HOVER_STAY = 70\n\nexport function toBoolean(value: string | null) {\n if (value === null) {\n return false\n }\n const normalized = value.trim().toLowerCase()\n if (normalized === '' || normalized === 'true') {\n return true\n }\n return normalized !== 'false' && normalized !== '0'\n}\n\nexport function parseNumber(value: string | null, fallback: number) {\n if (value === null || value === '') {\n return fallback\n }\n const numeric = Number(value)\n return Number.isFinite(numeric) ? numeric : fallback\n}\n\nexport function isDisabled(element: HTMLElement) {\n return toBoolean(element.getAttribute('disabled')) || toBoolean(element.getAttribute('loading'))\n}\n\nexport function normalizeType(value: string | null) {\n if (!value) {\n return 'default'\n }\n const normalized = value.toLowerCase()\n if (normalized === 'primary' || normalized === 'warn') {\n return normalized\n }\n return 'default'\n}\n\nexport function getHoverClass(element: HTMLElement) {\n const hoverClass = element.getAttribute('hover-class')\n if (!hoverClass) {\n return DEFAULT_HOVER_CLASS\n }\n if (hoverClass === 'none') {\n return ''\n }\n return hoverClass\n}\n\nexport function isInternalNode(node: Node) {\n return node instanceof HTMLElement && node.dataset?.weappInternal === 'true'\n}\n\nexport function collectFormValues(form: HTMLFormElement) {\n const values: Record<string, any> = {}\n\n const appendValue = (name: string, value: any, multiple = false) => {\n if (multiple) {\n if (!Array.isArray(values[name])) {\n values[name] = values[name] === undefined ? [] : [values[name]]\n }\n values[name].push(value)\n return\n }\n values[name] = value\n }\n\n const formElements = Array.from(form.elements ?? [])\n for (const element of formElements) {\n if (!(element instanceof HTMLElement)) {\n continue\n }\n const name = element.getAttribute('name')?.trim()\n if (!name) {\n continue\n }\n const disabled = 'disabled' in element ? (element as any).disabled : toBoolean(element.getAttribute('disabled'))\n if (disabled) {\n continue\n }\n if (element instanceof HTMLInputElement) {\n const type = element.type?.toLowerCase()\n if (type === 'checkbox') {\n if (element.checked) {\n appendValue(name, element.value, true)\n }\n continue\n }\n if (type === 'radio') {\n if (element.checked) {\n appendValue(name, element.value)\n }\n continue\n }\n appendValue(name, element.value)\n continue\n }\n if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {\n appendValue(name, (element as HTMLTextAreaElement | HTMLSelectElement).value)\n continue\n }\n }\n\n const customControls = form.querySelectorAll('switch, checkbox, radio, picker, slider, weapp-switch, weapp-checkbox, weapp-radio, weapp-picker, weapp-slider')\n for (const element of Array.from(customControls)) {\n const name = element.getAttribute('name')?.trim()\n if (!name) {\n continue\n }\n const disabled = toBoolean(element.getAttribute('disabled'))\n if (disabled) {\n continue\n }\n const tag = element.tagName.toLowerCase()\n const rawValue = (element as any).value ?? element.getAttribute('value')\n if (tag.includes('checkbox')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n if (checked) {\n appendValue(name, rawValue ?? true, true)\n }\n continue\n }\n if (tag.includes('radio')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n if (checked) {\n appendValue(name, rawValue ?? true)\n }\n continue\n }\n if (tag.includes('switch')) {\n const checked = (element as any).checked ?? toBoolean(element.getAttribute('checked'))\n appendValue(name, checked)\n continue\n }\n appendValue(name, rawValue ?? '')\n }\n\n return values\n}\n"],"mappings":";AAAA,MAAM,sBAAsB;AAK5B,SAAgB,UAAU,OAAsB;CAC9C,IAAI,UAAU,MACZ,OAAO;CAET,MAAM,aAAa,MAAM,KAAK,EAAE,YAAY;CAC5C,IAAI,eAAe,MAAM,eAAe,QACtC,OAAO;CAET,OAAO,eAAe,WAAW,eAAe;AAClD;AAEA,SAAgB,YAAY,OAAsB,UAAkB;CAClE,IAAI,UAAU,QAAQ,UAAU,IAC9B,OAAO;CAET,MAAM,U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AAO,IAAI;IAEvC;GACF;GACA,IAAI,SAAS,SAAS;IACpB,IAAI,QAAQ,SACV,YAAY,MAAM,QAAQ,KAAK;IAEjC;GACF;GACA,YAAY,MAAM,QAAQ,KAAK;GAC/B;EACF;EACA,IAAI,mBAAmB,uBAAuB,mBAAmB,mBAAmB;GAClF,YAAY,MAAO,QAAoD,KAAK;GAC5E;EACF;CACF;CAEA,MAAM,iBAAiB,KAAK,iBAAiB,gHAAgH;CAC7J,KAAK,MAAM,WAAW,MAAM,KAAK,cAAc,GAAG;EAChD,MAAM,OAAO,QAAQ,aAAa,MAAM,GAAG,KAAK;EAChD,IAAI,CAAC,MACH;EAGF,IADiB,UAAU,QAAQ,aAAa,UAAU,CAC/C,GACT;EAEF,MAAM,MAAM,QAAQ,QAAQ,YAAY;EACxC,MAAM,WAAY,QAAgB,SAAS,QAAQ,aAAa,OAAO;EACvE,IAAI,IAAI,SAAS,UAAU,GAAG;GAE5B,IADiB,QAAgB,WAAW,UAAU,QAAQ,aAAa,SAAS,CAAC,GAEnF,YAAY,MAAM,YAAY,MAAM,IAAI;GAE1C;EACF;EACA,IAAI,IAAI,SAAS,OAAO,GAAG;GAEzB,IADiB,QAAgB,WAAW,UAAU,QAAQ,aAAa,SAAS,CAAC,GAEnF,YAAY,MAAM,YAAY,IAAI;GAEpC;EACF;EACA,IAAI,IAAI,SAAS,QAAQ,GAAG;GAE1B,YAAY,MADK,QAAgB,WAAW,UAAU,QAAQ,aAAa,SAAS,CAAC,CAC5D;GACzB;EACF;EACA,YAAY,MAAM,YAAY,EAAE;CAClC;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#ensureStructure","#applyState","#bindEvents","#clearHoverTimers","#observer","#button","#content","#text","#loading","#handleClickCapture","#handleClick","#handlePressStart","#handlePressEnd","#lastTouchTime","#hoverTimer","#hoverRemoveTimer"],"sources":["../../../src/runtime/button/index.ts"],"sourcesContent":["import {\n collectFormValues,\n DEFAULT_HOVER_START,\n DEFAULT_HOVER_STAY,\n getHoverClass,\n isDisabled,\n isInternalNode,\n normalizeType,\n parseNumber,\n toBoolean,\n} from './helpers'\nimport { ensureButtonStyle } from './style'\n\ninterface ButtonFormConfig {\n preventDefault?: boolean\n}\n\nconst DEFAULT_FORM_CONFIG: Required<ButtonFormConfig> = {\n preventDefault: true,\n}\n\nconst NAV_BUTTON_TAG = 'weapp-button'\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nlet formConfig: Required<ButtonFormConfig> = { ...DEFAULT_FORM_CONFIG }\n\nclass WeappButton extends BaseElement {\n static observedAttributes = [\n 'type',\n 'plain',\n 'size',\n 'loading',\n 'disabled',\n 'hover-class',\n 'hover-start-time',\n 'hover-stay-time',\n 'form-type',\n 'open-type',\n ]\n\n #button?: HTMLButtonElement\n #content?: HTMLSpanElement\n #text?: HTMLSpanElement\n #loading?: HTMLSpanElement\n #hoverTimer?: ReturnType<typeof globalThis.setTimeout>\n #hoverRemoveTimer?: ReturnType<typeof globalThis.setTimeout>\n #lastTouchTime = 0\n #observer?: MutationObserver\n\n connectedCallback() {\n const root = this.getRootNode()\n if (root instanceof ShadowRoot) {\n ensureButtonStyle(root)\n }\n else {\n ensureButtonStyle()\n }\n this.#ensureStructure()\n this.#applyState()\n this.#bindEvents()\n }\n\n disconnectedCallback() {\n this.#clearHoverTimers()\n this.#observer?.disconnect()\n this.#observer = undefined\n }\n\n attributeChangedCallback() {\n this.#applyState()\n }\n\n #ensureStructure() {\n if (this.#button) {\n return\n }\n const button = document.createElement('button')\n button.type = 'button'\n button.className = 'weapp-btn'\n button.dataset.weappInternal = 'true'\n const content = document.createElement('span')\n content.className = 'weapp-btn__content'\n content.dataset.weappInternal = 'true'\n const loading = document.createElement('span')\n loading.className = 'weapp-btn__loading'\n loading.dataset.weappInternal = 'true'\n loading.setAttribute('hidden', '')\n const text = document.createElement('span')\n text.className = 'weapp-btn__text'\n text.dataset.weappInternal = 'true'\n content.append(loading, text)\n button.append(content)\n\n const existing = [...this.childNodes].filter(node => !isInternalNode(node))\n for (const node of existing) {\n text.appendChild(node)\n }\n this.appendChild(button)\n\n this.#button = button\n this.#content = content\n this.#text = text\n this.#loading = loading\n\n if (typeof MutationObserver !== 'undefined') {\n this.#observer = new MutationObserver((records) => {\n if (!this.#text) {\n return\n }\n for (const record of records) {\n for (const node of [...record.addedNodes]) {\n if (isInternalNode(node)) {\n continue\n }\n if (node === this.#button) {\n continue\n }\n this.#text.appendChild(node)\n }\n }\n })\n this.#observer.observe(this, { childList: true })\n }\n }\n\n #applyState() {\n if (!this.#button || !this.#loading) {\n return\n }\n const type = normalizeType(this.getAttribute('type'))\n const plain = toBoolean(this.getAttribute('plain'))\n const size = (this.getAttribute('size') ?? 'default').toLowerCase()\n const loading = toBoolean(this.getAttribute('loading'))\n const disabled = toBoolean(this.getAttribute('disabled'))\n const openType = this.getAttribute('open-type')\n\n this.classList.toggle('weapp-btn--primary', type === 'primary')\n this.classList.toggle('weapp-btn--warn', type === 'warn')\n this.classList.toggle('weapp-btn--default', type === 'default')\n this.classList.toggle('weapp-btn--plain', plain)\n this.classList.toggle('weapp-btn--mini', size === 'mini')\n this.classList.toggle('weapp-btn--loading', loading)\n this.classList.toggle('weapp-btn--disabled', disabled)\n\n if (openType) {\n const openTypeClass = `weapp-btn--open-type-${openType}`\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-') && className !== openTypeClass) {\n this.classList.remove(className)\n }\n }\n this.classList.add(openTypeClass)\n }\n else {\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-')) {\n this.classList.remove(className)\n }\n }\n }\n\n const locked = disabled || loading\n this.#button.disabled = locked\n if (locked) {\n this.#button.setAttribute('aria-disabled', 'true')\n }\n else {\n this.#button.removeAttribute('aria-disabled')\n }\n this.#loading.toggleAttribute('hidden', !loading)\n }\n\n #bindEvents() {\n if ((this as any).__weappButtonBound) {\n return\n }\n ;(this as any).__weappButtonBound = true\n this.addEventListener('click', this.#handleClickCapture, true)\n this.addEventListener('click', this.#handleClick)\n this.addEventListener('touchstart', this.#handlePressStart, { passive: true })\n this.addEventListener('mousedown', this.#handlePressStart)\n this.addEventListener('touchend', this.#handlePressEnd)\n this.addEventListener('touchcancel', this.#handlePressEnd)\n this.addEventListener('mouseup', this.#handlePressEnd)\n this.addEventListener('mouseleave', this.#handlePressEnd)\n }\n\n #handleClickCapture = (event: Event) => {\n if (isDisabled(this)) {\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n }\n\n #handleClick = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const formType = this.getAttribute('form-type')\n if (!formType) {\n return\n }\n const form = this.closest('form') as HTMLFormElement | null\n if (!form) {\n return\n }\n if (formType === 'submit') {\n const detail = { value: collectFormValues(form) }\n const submitEvent = new CustomEvent('submit', {\n detail,\n bubbles: true,\n cancelable: true,\n })\n const shouldSubmit = form.dispatchEvent(submitEvent)\n if (shouldSubmit && !formConfig.preventDefault) {\n form.submit()\n }\n event.preventDefault()\n return\n }\n if (formType === 'reset') {\n form.reset()\n event.preventDefault()\n }\n }\n\n #handlePressStart = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'touchstart') {\n this.#lastTouchTime = Date.now()\n }\n if (event.type === 'mousedown' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const startTime = parseNumber(this.getAttribute('hover-start-time'), DEFAULT_HOVER_START)\n this.#clearHoverTimers()\n this.#hoverTimer = globalThis.setTimeout(() => {\n this.classList.add(hoverClass)\n }, startTime)\n }\n\n #handlePressEnd = (event: Event) => {\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'mouseup' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const stayTime = parseNumber(this.getAttribute('hover-stay-time'), DEFAULT_HOVER_STAY)\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.classList.contains(hoverClass)) {\n this.#hoverRemoveTimer = globalThis.setTimeout(() => {\n this.classList.remove(hoverClass)\n }, stayTime)\n }\n }\n\n #clearHoverTimers() {\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.#hoverRemoveTimer) {\n clearTimeout(this.#hoverRemoveTimer)\n this.#hoverRemoveTimer = undefined\n }\n }\n}\n\nexport function ensureButtonDefined(): void {\n if (typeof customElements === 'undefined') {\n return\n }\n if (!customElements.get(NAV_BUTTON_TAG)) {\n customElements.define(NAV_BUTTON_TAG, WeappButton)\n }\n}\n\nexport function setButtonFormConfig(next: ButtonFormConfig): void {\n formConfig = {\n ...formConfig,\n ...next,\n }\n}\n\nexport type { ButtonFormConfig }\n"],"mappings":";;;;AAiBA,MAAM,sBAAkD,EACtD,gBAAgB,MACjB;AAED,MAAM,iBAAiB;AACvB,MAAM,cAAe,WAAW,eAAe,MAAM;AAErD,IAAI,aAAyC,EAAE,GAAG,qBAAqB;AAEvE,IAAM,cAAN,cAA0B,YAAY;CACpC,OAAO,qBAAqB;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CAED;CACA;CACA;CACA;CACA;CACA;CACA,iBAAiB;CACjB;CAEA,oBAAoB;EAClB,MAAM,OAAO,KAAK,aAAa;EAC/B,IAAI,gBAAgB,YAClB,kBAAkB,KAAK;OAGvB,mBAAmB;EAErB,KAAKA,kBAAkB;EACvB,KAAKC,aAAa;EAClB,KAAKC,aAAa;;CAGpB,uBAAuB;EACrB,KAAKC,mBAAmB;EACxB,KAAKC,WAAW,YAAY;EAC5B,KAAKA,YAAY;;CAGnB,2BAA2B;EACzB,KAAKH,aAAa;;CAGpB,mBAAmB;EACjB,IAAI,KAAKI,SACP;EAEF,MAAM,SAAS,SAAS,cAAc,SAAS;EAC/C,OAAO,OAAO;EACd,OAAO,YAAY;EACnB,OAAO,QAA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EACtF,IAAI,KAAKC,aAAa;GACpB,aAAa,KAAKA,YAAY;GAC9B,KAAKA,cAAc;;EAErB,IAAI,KAAK,UAAU,SAAS,WAAW,EACrC,KAAKC,oBAAoB,WAAW,iBAAiB;GACnD,KAAK,UAAU,OAAO,WAAW;KAChC,SAAS;;CAIhB,oBAAoB;EAClB,IAAI,KAAKD,aAAa;GACpB,aAAa,KAAKA,YAAY;GAC9B,KAAKA,cAAc;;EAErB,IAAI,KAAKC,mBAAmB;GAC1B,aAAa,KAAKA,kBAAkB;GACpC,KAAKA,oBAAoB;;;;AAK/B,SAAgB,sBAA4B;CAC1C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,IAAI,CAAC,eAAe,IAAI,eAAe,EACrC,eAAe,OAAO,gBAAgB,YAAY;;AAItD,SAAgB,oBAAoB,MAA8B;CAChE,aAAa;EACX,GAAG;EACH,GAAG;EACJ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#ensureStructure","#applyState","#bindEvents","#clearHoverTimers","#observer","#button","#content","#text","#loading","#handleClickCapture","#handleClick","#handlePressStart","#handlePressEnd","#lastTouchTime","#hoverTimer","#hoverRemoveTimer"],"sources":["../../../src/runtime/button/index.ts"],"sourcesContent":["import {\n collectFormValues,\n DEFAULT_HOVER_START,\n DEFAULT_HOVER_STAY,\n getHoverClass,\n isDisabled,\n isInternalNode,\n normalizeType,\n parseNumber,\n toBoolean,\n} from './helpers'\nimport { ensureButtonStyle } from './style'\n\ninterface ButtonFormConfig {\n preventDefault?: boolean\n}\n\nconst DEFAULT_FORM_CONFIG: Required<ButtonFormConfig> = {\n preventDefault: true,\n}\n\nconst NAV_BUTTON_TAG = 'weapp-button'\nconst BaseElement = (globalThis.HTMLElement ?? class {}) as typeof HTMLElement\n\nlet formConfig: Required<ButtonFormConfig> = { ...DEFAULT_FORM_CONFIG }\n\nclass WeappButton extends BaseElement {\n static observedAttributes = [\n 'type',\n 'plain',\n 'size',\n 'loading',\n 'disabled',\n 'hover-class',\n 'hover-start-time',\n 'hover-stay-time',\n 'form-type',\n 'open-type',\n ]\n\n #button?: HTMLButtonElement\n #content?: HTMLSpanElement\n #text?: HTMLSpanElement\n #loading?: HTMLSpanElement\n #hoverTimer?: ReturnType<typeof globalThis.setTimeout>\n #hoverRemoveTimer?: ReturnType<typeof globalThis.setTimeout>\n #lastTouchTime = 0\n #observer?: MutationObserver\n\n connectedCallback() {\n const root = this.getRootNode()\n if (root instanceof ShadowRoot) {\n ensureButtonStyle(root)\n }\n else {\n ensureButtonStyle()\n }\n this.#ensureStructure()\n this.#applyState()\n this.#bindEvents()\n }\n\n disconnectedCallback() {\n this.#clearHoverTimers()\n this.#observer?.disconnect()\n this.#observer = undefined\n }\n\n attributeChangedCallback() {\n this.#applyState()\n }\n\n #ensureStructure() {\n if (this.#button) {\n return\n }\n const button = document.createElement('button')\n button.type = 'button'\n button.className = 'weapp-btn'\n button.dataset.weappInternal = 'true'\n const content = document.createElement('span')\n content.className = 'weapp-btn__content'\n content.dataset.weappInternal = 'true'\n const loading = document.createElement('span')\n loading.className = 'weapp-btn__loading'\n loading.dataset.weappInternal = 'true'\n loading.setAttribute('hidden', '')\n const text = document.createElement('span')\n text.className = 'weapp-btn__text'\n text.dataset.weappInternal = 'true'\n content.append(loading, text)\n button.append(content)\n\n const existing = [...this.childNodes].filter(node => !isInternalNode(node))\n for (const node of existing) {\n text.appendChild(node)\n }\n this.appendChild(button)\n\n this.#button = button\n this.#content = content\n this.#text = text\n this.#loading = loading\n\n if (typeof MutationObserver !== 'undefined') {\n this.#observer = new MutationObserver((records) => {\n if (!this.#text) {\n return\n }\n for (const record of records) {\n for (const node of [...record.addedNodes]) {\n if (isInternalNode(node)) {\n continue\n }\n if (node === this.#button) {\n continue\n }\n this.#text.appendChild(node)\n }\n }\n })\n this.#observer.observe(this, { childList: true })\n }\n }\n\n #applyState() {\n if (!this.#button || !this.#loading) {\n return\n }\n const type = normalizeType(this.getAttribute('type'))\n const plain = toBoolean(this.getAttribute('plain'))\n const size = (this.getAttribute('size') ?? 'default').toLowerCase()\n const loading = toBoolean(this.getAttribute('loading'))\n const disabled = toBoolean(this.getAttribute('disabled'))\n const openType = this.getAttribute('open-type')\n\n this.classList.toggle('weapp-btn--primary', type === 'primary')\n this.classList.toggle('weapp-btn--warn', type === 'warn')\n this.classList.toggle('weapp-btn--default', type === 'default')\n this.classList.toggle('weapp-btn--plain', plain)\n this.classList.toggle('weapp-btn--mini', size === 'mini')\n this.classList.toggle('weapp-btn--loading', loading)\n this.classList.toggle('weapp-btn--disabled', disabled)\n\n if (openType) {\n const openTypeClass = `weapp-btn--open-type-${openType}`\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-') && className !== openTypeClass) {\n this.classList.remove(className)\n }\n }\n this.classList.add(openTypeClass)\n }\n else {\n for (const className of [...this.classList]) {\n if (className.startsWith('weapp-btn--open-type-')) {\n this.classList.remove(className)\n }\n }\n }\n\n const locked = disabled || loading\n this.#button.disabled = locked\n if (locked) {\n this.#button.setAttribute('aria-disabled', 'true')\n }\n else {\n this.#button.removeAttribute('aria-disabled')\n }\n this.#loading.toggleAttribute('hidden', !loading)\n }\n\n #bindEvents() {\n if ((this as any).__weappButtonBound) {\n return\n }\n ;(this as any).__weappButtonBound = true\n this.addEventListener('click', this.#handleClickCapture, true)\n this.addEventListener('click', this.#handleClick)\n this.addEventListener('touchstart', this.#handlePressStart, { passive: true })\n this.addEventListener('mousedown', this.#handlePressStart)\n this.addEventListener('touchend', this.#handlePressEnd)\n this.addEventListener('touchcancel', this.#handlePressEnd)\n this.addEventListener('mouseup', this.#handlePressEnd)\n this.addEventListener('mouseleave', this.#handlePressEnd)\n }\n\n #handleClickCapture = (event: Event) => {\n if (isDisabled(this)) {\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n }\n\n #handleClick = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const formType = this.getAttribute('form-type')\n if (!formType) {\n return\n }\n const form = this.closest('form') as HTMLFormElement | null\n if (!form) {\n return\n }\n if (formType === 'submit') {\n const detail = { value: collectFormValues(form) }\n const submitEvent = new CustomEvent('submit', {\n detail,\n bubbles: true,\n cancelable: true,\n })\n const shouldSubmit = form.dispatchEvent(submitEvent)\n if (shouldSubmit && !formConfig.preventDefault) {\n form.submit()\n }\n event.preventDefault()\n return\n }\n if (formType === 'reset') {\n form.reset()\n event.preventDefault()\n }\n }\n\n #handlePressStart = (event: Event) => {\n if (isDisabled(this)) {\n return\n }\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'touchstart') {\n this.#lastTouchTime = Date.now()\n }\n if (event.type === 'mousedown' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const startTime = parseNumber(this.getAttribute('hover-start-time'), DEFAULT_HOVER_START)\n this.#clearHoverTimers()\n this.#hoverTimer = globalThis.setTimeout(() => {\n this.classList.add(hoverClass)\n }, startTime)\n }\n\n #handlePressEnd = (event: Event) => {\n const hoverClass = getHoverClass(this)\n if (!hoverClass) {\n return\n }\n if (event.type === 'mouseup' && Date.now() - this.#lastTouchTime < 400) {\n return\n }\n const stayTime = parseNumber(this.getAttribute('hover-stay-time'), DEFAULT_HOVER_STAY)\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.classList.contains(hoverClass)) {\n this.#hoverRemoveTimer = globalThis.setTimeout(() => {\n this.classList.remove(hoverClass)\n }, stayTime)\n }\n }\n\n #clearHoverTimers() {\n if (this.#hoverTimer) {\n clearTimeout(this.#hoverTimer)\n this.#hoverTimer = undefined\n }\n if (this.#hoverRemoveTimer) {\n clearTimeout(this.#hoverRemoveTimer)\n this.#hoverRemoveTimer = undefined\n }\n }\n}\n\nexport function ensureButtonDefined(): void {\n if (typeof customElements === 'undefined') {\n return\n }\n if (!customElements.get(NAV_BUTTON_TAG)) {\n customElements.define(NAV_BUTTON_TAG, WeappButton)\n }\n}\n\nexport function setButtonFormConfig(next: ButtonFormConfig): void {\n formConf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A4B;CAC1C,IAAI,OAAO,mBAAmB,aAC5B;CAEF,IAAI,CAAC,eAAe,IAAI,cAAc,GACpC,eAAe,OAAO,gBAAgB,WAAW;AAErD;AAEA,SAAgB,oBAAoB,MAA8B;CAChE,aAAa;EACX,GAAG;EACH,GAAG;CACL;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/button/style.ts"],"sourcesContent":["import { injectStyle } from '../style'\n\nconst BUTTON_STYLE_ID = 'weapp-web-button-style'\nconst styleTargets = new WeakSet<ParentNode>()\nlet sharedSheet: CSSStyleSheet | undefined\n\nconst BUTTON_STYLE = `\nweapp-button {\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\nweapp-button.weapp-btn--mini {\n display: inline-block;\n width: auto;\n}\n\nweapp-button .weapp-btn {\n appearance: none;\n -webkit-appearance: none;\n box-sizing: border-box;\n width: 100%;\n border-radius: 5px;\n border: 1px solid #d9d9d9;\n padding: 0 16px;\n height: 44px;\n line-height: 44px;\n font-size: 17px;\n font-weight: 400;\n background-color: #f8f8f8;\n color: #000000;\n cursor: pointer;\n outline: none;\n user-select: none;\n -webkit-tap-highlight-color: transparent;\n}\n\nweapp-button.weapp-btn--primary .weapp-btn {\n background-color: #07c160;\n border-color: #07c160;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--warn .weapp-btn {\n background-color: #e64340;\n border-color: #e64340;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--plain .weapp-btn {\n background-color: transparent;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {\n border-color: #b2b2b2;\n color: #353535;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {\n border-color: #07c160;\n color: #07c160;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {\n border-color: #e64340;\n color: #e64340;\n}\n\nweapp-button.weapp-btn--loading .weapp-btn,\nweapp-button.weapp-btn--disabled .weapp-btn {\n background-color: #f7f7f7;\n border-color: #d9d9d9;\n color: #9b9b9b;\n cursor: not-allowed;\n}\n\nweapp-button.button-hover .weapp-btn {\n background-color: #ededed;\n border-color: #d2d2d2;\n}\n\nweapp-button.button-hover.weapp-btn--primary .weapp-btn {\n background-color: #06ad56;\n border-color: #06ad56;\n}\n\nweapp-button.button-hover.weapp-btn--warn .weapp-btn {\n background-color: #d93c37;\n border-color: #d93c37;\n}\n\nweapp-button.button-hover.weapp-btn--plain .weapp-btn {\n background-color: rgba(0, 0, 0, 0.06);\n}\n\nweapp-button.weapp-btn--mini .weapp-btn {\n height: 32px;\n line-height: 32px;\n font-size: 13px;\n padding: 0 12px;\n border-radius: 4px;\n}\n\nweapp-button .weapp-btn__content {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n width: 100%;\n}\n\nweapp-button .weapp-btn__loading {\n width: 14px;\n height: 14px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-btn-spin 0.8s linear infinite;\n}\n\nweapp-button .weapp-btn__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-btn-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n\nfunction resolveAdoptedStyleSheets(root: ShadowRoot) {\n const doc = root.ownerDocument ?? document\n if (!doc || typeof doc.createElement !== 'function') {\n return undefined\n }\n if (!('adoptedStyleSheets' in doc)) {\n return undefined\n }\n if (!sharedSheet && 'replaceSync' in CSSStyleSheet.prototype) {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(BUTTON_STYLE)\n sharedSheet = sheet\n }\n return sharedSheet\n}\n\nexport function ensureButtonStyle(root?: ShadowRoot) {\n if (typeof document === 'undefined') {\n return\n }\n if (root && styleTargets.has(root)) {\n return\n }\n if (!root) {\n const target = document.head\n if (!target || styleTargets.has(target)) {\n return\n }\n injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID)\n styleTargets.add(target)\n return\n }\n const sheet = resolveAdoptedStyleSheets(root)\n if (sheet) {\n const existing = root.adoptedStyleSheets ?? []\n if (!existing.includes(sheet)) {\n root.adoptedStyleSheets = [...existing, sheet]\n }\n styleTargets.add(root)\n return\n }\n const style = document.createElement('style')\n style.id = BUTTON_STYLE_ID\n style.textContent = BUTTON_STYLE\n root.appendChild(style)\n styleTargets.add(root)\n}\n"],"mappings":";;;AAEA,MAAM,kBAAkB;AACxB,MAAM,+BAAe,IAAI,
|
|
1
|
+
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/runtime/button/style.ts"],"sourcesContent":["import { injectStyle } from '../style'\n\nconst BUTTON_STYLE_ID = 'weapp-web-button-style'\nconst styleTargets = new WeakSet<ParentNode>()\nlet sharedSheet: CSSStyleSheet | undefined\n\nconst BUTTON_STYLE = `\nweapp-button {\n display: block;\n width: 100%;\n box-sizing: border-box;\n}\n\nweapp-button.weapp-btn--mini {\n display: inline-block;\n width: auto;\n}\n\nweapp-button .weapp-btn {\n appearance: none;\n -webkit-appearance: none;\n box-sizing: border-box;\n width: 100%;\n border-radius: 5px;\n border: 1px solid #d9d9d9;\n padding: 0 16px;\n height: 44px;\n line-height: 44px;\n font-size: 17px;\n font-weight: 400;\n background-color: #f8f8f8;\n color: #000000;\n cursor: pointer;\n outline: none;\n user-select: none;\n -webkit-tap-highlight-color: transparent;\n}\n\nweapp-button.weapp-btn--primary .weapp-btn {\n background-color: #07c160;\n border-color: #07c160;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--warn .weapp-btn {\n background-color: #e64340;\n border-color: #e64340;\n color: #ffffff;\n}\n\nweapp-button.weapp-btn--plain .weapp-btn {\n background-color: transparent;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--default .weapp-btn {\n border-color: #b2b2b2;\n color: #353535;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--primary .weapp-btn {\n border-color: #07c160;\n color: #07c160;\n}\n\nweapp-button.weapp-btn--plain.weapp-btn--warn .weapp-btn {\n border-color: #e64340;\n color: #e64340;\n}\n\nweapp-button.weapp-btn--loading .weapp-btn,\nweapp-button.weapp-btn--disabled .weapp-btn {\n background-color: #f7f7f7;\n border-color: #d9d9d9;\n color: #9b9b9b;\n cursor: not-allowed;\n}\n\nweapp-button.button-hover .weapp-btn {\n background-color: #ededed;\n border-color: #d2d2d2;\n}\n\nweapp-button.button-hover.weapp-btn--primary .weapp-btn {\n background-color: #06ad56;\n border-color: #06ad56;\n}\n\nweapp-button.button-hover.weapp-btn--warn .weapp-btn {\n background-color: #d93c37;\n border-color: #d93c37;\n}\n\nweapp-button.button-hover.weapp-btn--plain .weapp-btn {\n background-color: rgba(0, 0, 0, 0.06);\n}\n\nweapp-button.weapp-btn--mini .weapp-btn {\n height: 32px;\n line-height: 32px;\n font-size: 13px;\n padding: 0 12px;\n border-radius: 4px;\n}\n\nweapp-button .weapp-btn__content {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n width: 100%;\n}\n\nweapp-button .weapp-btn__loading {\n width: 14px;\n height: 14px;\n border-radius: 50%;\n border: 2px solid currentColor;\n border-top-color: transparent;\n animation: weapp-btn-spin 0.8s linear infinite;\n}\n\nweapp-button .weapp-btn__loading[hidden] {\n display: none;\n}\n\n@keyframes weapp-btn-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n`\n\nfunction resolveAdoptedStyleSheets(root: ShadowRoot) {\n const doc = root.ownerDocument ?? document\n if (!doc || typeof doc.createElement !== 'function') {\n return undefined\n }\n if (!('adoptedStyleSheets' in doc)) {\n return undefined\n }\n if (!sharedSheet && 'replaceSync' in CSSStyleSheet.prototype) {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(BUTTON_STYLE)\n sharedSheet = sheet\n }\n return sharedSheet\n}\n\nexport function ensureButtonStyle(root?: ShadowRoot) {\n if (typeof document === 'undefined') {\n return\n }\n if (root && styleTargets.has(root)) {\n return\n }\n if (!root) {\n const target = document.head\n if (!target || styleTargets.has(target)) {\n return\n }\n injectStyle(BUTTON_STYLE, BUTTON_STYLE_ID)\n styleTargets.add(target)\n return\n }\n const sheet = resolveAdoptedStyleSheets(root)\n if (sheet) {\n const existing = root.adoptedStyleSheets ?? []\n if (!existing.includes(sheet)) {\n root.adoptedStyleSheets = [...existing, sheet]\n }\n styleTargets.add(root)\n return\n }\n const style = document.createElement('style')\n style.id = BUTTON_STYLE_ID\n style.textContent = BUTTON_STYLE\n root.appendChild(style)\n styleTargets.add(root)\n}\n"],"mappings":";;;AAEA,MAAM,kBAAkB;AACxB,MAAM,+BAAe,IAAI,QAAoB;AAC7C,IAAI;AAEJ,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HrB,SAAS,0BAA0B,MAAkB;CACnD,MAAM,MAAM,KAAK,iBAAiB;CAClC,IAAI,CAAC,OAAO,OAAO,IAAI,kBAAkB,YACvC;CAEF,IAAI,EAAE,wBAAwB,MAC5B;CAEF,IAAI,CAAC,eAAe,iBAAiB,cAAc,WAAW;EAC5D,MAAM,QAAQ,IAAI,cAAc;EAChC,MAAM,YAAY,YAAY;EAC9B,cAAc;CAChB;CACA,OAAO;AACT;AAEA,SAAgB,kBAAkB,MAAmB;CACnD,IAAI,OAAO,aAAa,aACtB;CAEF,IAAI,QAAQ,aAAa,IAAI,IAAI,GAC/B;CAEF,IAAI,CAAC,MAAM;EACT,MAAM,SAAS,SAAS;EACxB,IAAI,CAAC,UAAU,aAAa,IAAI,MAAM,GACpC;EAEF,YAAY,cAAc,eAAe;EACzC,aAAa,IAAI,MAAM;EACvB;CACF;CACA,MAAM,QAAQ,0BAA0B,IAAI;CAC5C,IAAI,OAAO;EACT,MAAM,WAAW,KAAK,sBAAsB,CAAC;EAC7C,IAAI,CAAC,SAAS,SAAS,KAAK,GAC1B,KAAK,qBAAqB,CAAC,GAAG,UAAU,KAAK;EAE/C,aAAa,IAAI,IAAI;EACrB;CACF;CACA,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,KAAK;CACX,MAAM,cAAc;CACpB,KAAK,YAAY,KAAK;CACtB,aAAa,IAAI,IAAI;AACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"behavior.mjs","names":[],"sources":["../../../src/runtime/component/behavior.ts"],"sourcesContent":["import type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n LifeTimeHooks,\n PageLifeTimeHooks,\n} from './types'\n\nfunction isPlainObject(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction mergeLifetimes(target: LifeTimeHooks, source?: LifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof LifeTimeHooks> = ['created', 'attached', 'ready', 'detached']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nfunction mergePageLifetimes(target: PageLifeTimeHooks, source?: PageLifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof PageLifeTimeHooks> = ['show', 'hide', 'resize']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nexport function normalizeBehaviors(component: ComponentOptions | undefined) {\n if (!component) {\n return { component: undefined, warnings: [] as string[] }\n }\n const warnings: string[] = []\n const visited = new Set<ComponentOptions>()\n const merged: ComponentOptions = {}\n\n const mergeComponent = (source: ComponentOptions) => {\n if (source.properties) {\n merged.properties = { ...(merged.properties ?? {}), ...source.properties }\n }\n if (source.data) {\n const nextData = typeof source.data === 'function'\n ? source.data()\n : source.data\n if (isPlainObject(nextData)) {\n merged.data = { ...((merged.data as DataRecord) ?? {}), ...nextData }\n }\n }\n if (source.methods) {\n merged.methods = { ...(merged.methods ?? {}), ...source.methods }\n }\n if (source.lifetimes) {\n merged.lifetimes = merged.lifetimes ?? {}\n mergeLifetimes(merged.lifetimes, source.lifetimes)\n }\n if (source.pageLifetimes) {\n merged.pageLifetimes = merged.pageLifetimes ?? {}\n mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes)\n }\n }\n\n const walk = (source: ComponentOptions) => {\n if (visited.has(source)) {\n warnings.push('[@weapp-vite/web] behaviors 存在循环引用,已跳过。')\n return\n }\n visited.add(source)\n const behaviors = source.behaviors ?? []\n if (Array.isArray(behaviors)) {\n for (const behavior of behaviors) {\n if (!behavior || !isPlainObject(behavior)) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。')\n continue\n }\n walk(behavior as ComponentOptions)\n mergeComponent(behavior as ComponentOptions)\n }\n }\n else if (behaviors) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持数组,已忽略。')\n }\n }\n\n walk(component)\n mergeComponent(component)\n\n return {\n component: merged,\n warnings,\n }\n}\n"],"mappings":";AAQA,SAAS,cAAc,OAA8C;CACnE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"behavior.mjs","names":[],"sources":["../../../src/runtime/component/behavior.ts"],"sourcesContent":["import type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n LifeTimeHooks,\n PageLifeTimeHooks,\n} from './types'\n\nfunction isPlainObject(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction mergeLifetimes(target: LifeTimeHooks, source?: LifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof LifeTimeHooks> = ['created', 'attached', 'ready', 'detached']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nfunction mergePageLifetimes(target: PageLifeTimeHooks, source?: PageLifeTimeHooks) {\n if (!source) {\n return\n }\n const keys: Array<keyof PageLifeTimeHooks> = ['show', 'hide', 'resize']\n for (const key of keys) {\n const next = source[key]\n if (!next) {\n continue\n }\n const current = target[key]\n target[key] = current\n ? function merged(this: ComponentPublicInstance) {\n current.call(this)\n next.call(this)\n }\n : next\n }\n}\n\nexport function normalizeBehaviors(component: ComponentOptions | undefined) {\n if (!component) {\n return { component: undefined, warnings: [] as string[] }\n }\n const warnings: string[] = []\n const visited = new Set<ComponentOptions>()\n const merged: ComponentOptions = {}\n\n const mergeComponent = (source: ComponentOptions) => {\n if (source.properties) {\n merged.properties = { ...(merged.properties ?? {}), ...source.properties }\n }\n if (source.data) {\n const nextData = typeof source.data === 'function'\n ? source.data()\n : source.data\n if (isPlainObject(nextData)) {\n merged.data = { ...((merged.data as DataRecord) ?? {}), ...nextData }\n }\n }\n if (source.methods) {\n merged.methods = { ...(merged.methods ?? {}), ...source.methods }\n }\n if (source.lifetimes) {\n merged.lifetimes = merged.lifetimes ?? {}\n mergeLifetimes(merged.lifetimes, source.lifetimes)\n }\n if (source.pageLifetimes) {\n merged.pageLifetimes = merged.pageLifetimes ?? {}\n mergePageLifetimes(merged.pageLifetimes, source.pageLifetimes)\n }\n }\n\n const walk = (source: ComponentOptions) => {\n if (visited.has(source)) {\n warnings.push('[@weapp-vite/web] behaviors 存在循环引用,已跳过。')\n return\n }\n visited.add(source)\n const behaviors = source.behaviors ?? []\n if (Array.isArray(behaviors)) {\n for (const behavior of behaviors) {\n if (!behavior || !isPlainObject(behavior)) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持对象,已忽略非对象条目。')\n continue\n }\n walk(behavior as ComponentOptions)\n mergeComponent(behavior as ComponentOptions)\n }\n }\n else if (behaviors) {\n warnings.push('[@weapp-vite/web] behaviors 仅支持数组,已忽略。')\n }\n }\n\n walk(component)\n mergeComponent(component)\n\n return {\n component: merged,\n war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AAE,GAAI,OAAO,WAAW,CAAC;GAAI,GAAG,OAAO;EAAQ;EAElE,IAAI,OAAO,WAAW;GACpB,OAAO,YAAY,OAAO,aAAa,CAAC;GACxC,eAAe,OAAO,WAAW,OAAO,SAAS;EACnD;EACA,IAAI,OAAO,eAAe;GACxB,OAAO,gBAAgB,OAAO,iBAAiB,CAAC;GAChD,mBAAmB,OAAO,eAAe,OAAO,aAAa;EAC/D;CACF;CAEA,MAAM,QAAQ,WAA6B;EACzC,IAAI,QAAQ,IAAI,MAAM,GAAG;GACvB,SAAS,KAAK,yCAAyC;GACvD;EACF;EACA,QAAQ,IAAI,MAAM;EAClB,MAAM,YAAY,OAAO,aAAa,CAAC;EACvC,IAAI,MAAM,QAAQ,SAAS,GACzB,KAAK,MAAM,YAAY,WAAW;GAChC,IAAI,CAAC,YAAY,CAAC,cAAc,QAAQ,GAAG;IACzC,SAAS,KAAK,6CAA6C;IAC3D;GACF;GACA,KAAK,QAA4B;GACjC,eAAe,QAA4B;EAC7C;OAEG,IAAI,WACP,SAAS,KAAK,wCAAwC;CAE1D;CAEA,KAAK,SAAS;CACd,eAAe,SAAS;CAExB,OAAO;EACL,WAAW;EACX;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/runtime/component/constants.ts"],"sourcesContent":["export const supportsLit = typeof document !== 'undefined'\n && typeof document.createComment === 'function'\n && typeof document.createTreeWalker === 'function'\n\nexport const FallbackElement = class {}\n\nexport const MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX = 'data-mp-on-'\nexport const MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-mp-on-flags-'\n\nexport const WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX = 'data-wx-on-'\nexport const WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-wx-on-flags-'\n\nexport const LEGACY_EVENT_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX\nexport const LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX\n\nexport const EVENT_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX,\n] as const\n\nexport const EVENT_FLAG_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX,\n] as const\n"],"mappings":";AAAA,MAAa,cAAc,OAAO,aAAa,eAC1C,OAAO,SAAS,kBAAkB,cAClC,OAAO,SAAS,qBAAqB;AAE1C,MAAa,kBAAkB,MAAM;
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/runtime/component/constants.ts"],"sourcesContent":["export const supportsLit = typeof document !== 'undefined'\n && typeof document.createComment === 'function'\n && typeof document.createTreeWalker === 'function'\n\nexport const FallbackElement = class {}\n\nexport const MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX = 'data-mp-on-'\nexport const MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-mp-on-flags-'\n\nexport const WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX = 'data-wx-on-'\nexport const WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = 'data-wx-on-flags-'\n\nexport const LEGACY_EVENT_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX\nexport const LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX = WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX\n\nexport const EVENT_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX,\n] as const\n\nexport const EVENT_FLAG_ATTRIBUTE_PREFIXES = [\n MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX,\n WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX,\n] as const\n"],"mappings":";AAAA,MAAa,cAAc,OAAO,aAAa,eAC1C,OAAO,SAAS,kBAAkB,cAClC,OAAO,SAAS,qBAAqB;AAE1C,MAAa,kBAAkB,MAAM,CAAC;AAEtC,MAAa,sCAAsC;AACnD,MAAa,2CAA2C;AAExD,MAAa,uCAAuC;AACpD,MAAa,4CAA4C;AAKzD,MAAa,2BAA2B,CACtC,qCACA,oCACF;AAEA,MAAa,gCAAgC,CAC3C,0CACA,yCACF"}
|
|
@@ -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":";;;AAcA,MAAM,mCAAmC,
|
|
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 +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,EAC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AO,WAAW,UAAU;IAC9B,KAAK,YAAY,GAAG,cAAc;IAClC,kBAAkB,MAAoB,KAAKV,UAAU,KAAK;UAEvD,IAAI,UAAU,MACjB,KAAK,YAAY;QAGjB,KAAK,YAAY,GAAG,cAAc,OAAO,OAAO;GAElD,IAAI,CAAC,KAAKQ,aAAa;IACrB,aAAa,UAAU,OAAO,KAAK,KAAK;IACxC,KAAKA,cAAc;;;;CAKzB,OAAO"}
|
|
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,KAAKC,SAAS;IAAE,GAAG,WAAW,KAAKD,WAAW;IAAG,GAAG,WAAW,UAAU;GAAE;GAC3E,KAAKE,WAAW,CAAC;GACjB,KAAKC,aAAa,aAAa,aAAa,WAAW,CAAC,CAAC;GACzD,OAAO,iBAAiB,MAAM;IAC5B,MAAM;KACJ,cAAc;KACd,YAAY;KACZ,WAAW,KAAKF;IAClB;IACA,YAAY;KACV,cAAc;KACd,YAAY;KACZ,WAAW,KAAKD;IAClB;GACF,CAAC;GACD,KAAK,MAAM,CAAC,aAAa,aAAa,iBACpC,OAAO,eAAe,MAAM,UAAU;IACpC,cAAc;IACd,YAAY;IACZ,WAAW,KAAKC,OAAO;IACvB,MAAK,UAAS,KAAKG,aAAa,UAAU,KAAK;GACjD,CAAC;GAEH,IAAI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,OAAO,OAAO,QAAQ,KAAK,GAC1C,KAAKA,SAAS,OAAO;GAEvB,KAAKU,iBAAiB,oBAAoB,MAAM,KAAKV,QAAQ;EAC/D;EAEA,YAAY,aAA0C;GACpD,KAAKC,aAAa,WAAW;GAC7B,KAAK,cAAc;EACrB;EAEA,0BAA0B,MAA+B;GACvD,MAAM,OAAO,aAAa,cAAc;GACxC,IAAI,OAAO,SAAS,YAClB,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 +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":";;;AAMA,SAAS,gBAAgB,OAAsB;CAC7C,IAAI,CAAC,OACH,OAAO;EAAE,OAAO;EAAO,SAAS;
|
|
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 +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":";;;;;;;AAQA,SAAS,qBAAqB,UAA0B;CACtD,KAAK,MAAM,WAAW,UACpB,mBAAmB,SAAS;EAC1B,KAAK,uBAAuB;EAC5B,SAAS;
|
|
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 +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":";;;;;AA0BA,SAAS,2BAA2B,WAAyC;CAC3E,MAAM,aAAa,mBAAmB,
|
|
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 +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":";AAEA,SAAgB,UAAU,MAAc;CACtC,OAAO,KAAK,QAAQ,aAAa,GAAG,SAAiB,IAAI,KAAK,
|
|
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 +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":";;;AAIA,IAAI,8BAAoD;AACxD,MAAM,iCAAiB,IAAI,
|
|
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"}
|
|
@@ -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":";;;;;AAcA,MAAM,kBAAkB;AACxB,MAAM,mBAA2C;CAC/C,KAAK;CACL,SAAS;CACT,WAAW;
|
|
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,CA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AM,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 +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":";;;AAGA,MAAM,kCAAkB,IAAI,
|
|
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":";;;AAGA,MAAM,kCAAkB,IAAI,IAAiD;AAE7E,SAAgB,YAAY,SAA+B;CACzD,OAAO,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,WAAW,CAAC,CAAC;AACzD;AAEA,SAAgB,iBAAiB,QAA6B;CAC5D,OAAO,OAAO,OAAO,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;AAChD;AAEA,SAAgB,cAAc,OAAmB;CAC/C,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;CAET,IAAI,SAAS,MACX,OAAO,CAAC;CAEV,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG;EACvD,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;EAC5C,OAAO,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,UAAU,KAAK;CACnD;CACA,IAAI,OAAO,UAAU,UACnB,OAAO,OAAO,OAAO,KAAK;CAE5B,OAAO,CAAC;AACV;AAEA,SAAgB,WAAW,OAAe;CACxC,OAAO,MAAM,QAAQ,aAAa,UAAU;EAC1C,QAAQ,OAAR;GACE,KAAK,KACH,OAAO;GACT,KAAK,KACH,OAAO;GACT,KAAK,KACH,OAAO;GACT,KAAK,MACH,OAAO;GACT,KAAK,KACH,OAAO;GACT,SACE,OAAO;EACX;CACF,CAAC;AACH;AAEA,SAAgB,gBAAgB,OAAe;CAC7C,OAAO,WAAW,KAAK;AACzB;AAEA,SAAS,gBAAgB,OAAY;CACnC,IAAI,SAAS,MACX,OAAO;CAET,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,iBAAiB,MACnB,OAAO,MAAM,YAAY;EAE3B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