@weapp-vite/web 1.4.20 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/compiler/wxml/attributes.mjs +5 -3
- package/dist/compiler/wxml/attributes.mjs.map +1 -1
- package/dist/compiler/wxml/compile.mjs +6 -1
- package/dist/compiler/wxml/compile.mjs.map +1 -1
- package/dist/compiler/wxml/types.d.mts +1 -2
- package/dist/css/wxss.d.mts +3 -4
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +4 -3
- package/dist/plugin/assets.d.mts +1 -2
- package/dist/plugin/constants.mjs +2 -1
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/index.d.mts +2 -2
- package/dist/plugin/index.mjs +7 -2
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/register.mjs +20 -5
- package/dist/plugin/register.mjs.map +1 -1
- package/dist/plugin/types.d.mts +5 -6
- package/dist/runtime/button/index.d.mts +3 -4
- package/dist/runtime/component/constants.mjs +9 -1
- package/dist/runtime/component/constants.mjs.map +1 -1
- package/dist/runtime/component/element.mjs +24 -4
- package/dist/runtime/component/element.mjs.map +1 -1
- package/dist/runtime/component/events.mjs +6 -4
- package/dist/runtime/component/events.mjs.map +1 -1
- package/dist/runtime/component/index.d.mts +2 -2
- package/dist/runtime/component/types.d.mts +13 -14
- package/dist/runtime/eventBinding.d.mts +16 -0
- package/dist/runtime/eventBinding.mjs +51 -0
- package/dist/runtime/eventBinding.mjs.map +1 -0
- package/dist/runtime/execution.d.mts +3 -4
- package/dist/runtime/host/index.d.mts +9 -9
- package/dist/runtime/host/types.d.mts +4 -5
- package/dist/runtime/hostGlobals.d.mts +1 -2
- package/dist/runtime/index.d.mts +5 -3
- package/dist/runtime/index.mjs +4 -3
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/runtime/inputHandlerResult.mjs +22 -0
- package/dist/runtime/inputHandlerResult.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/dom.mjs +27 -9
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
- package/dist/runtime/legacyTemplate/index.d.mts +2 -3
- package/dist/runtime/legacyTemplate/types.d.mts +2 -3
- package/dist/runtime/nativeComponents/form.d.mts +1 -2
- package/dist/runtime/nativeComponents/image.d.mts +1 -2
- package/dist/runtime/nativeComponents/index.d.mts +2 -2
- package/dist/runtime/nativeComponents/input.d.mts +1 -2
- package/dist/runtime/nativeComponents/input.mjs +3 -1
- package/dist/runtime/nativeComponents/input.mjs.map +1 -1
- package/dist/runtime/nativeComponents/scrollView.d.mts +1 -2
- package/dist/runtime/nativeComponents/scrollView.mjs +21 -12
- package/dist/runtime/nativeComponents/scrollView.mjs.map +1 -1
- package/dist/runtime/nativeComponents/switch.d.mts +1 -2
- package/dist/runtime/nativeComponents/textarea.d.mts +1 -2
- package/dist/runtime/nativeComponents/video/helpers.d.mts +3 -4
- package/dist/runtime/navigationBar/index.d.mts +2 -2
- package/dist/runtime/pageLayout.d.mts +2 -3
- package/dist/runtime/polyfill/async.d.mts +1 -2
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +27 -28
- package/dist/runtime/polyfill/index.d.mts +17 -16
- package/dist/runtime/polyfill/index.mjs +6 -2
- package/dist/runtime/polyfill/index.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +53 -7
- package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime/history.d.mts +8 -9
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +14 -10
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -1
- package/dist/runtime/polyfill/routeRuntime.d.mts +17 -13
- package/dist/runtime/polyfill/routeRuntime.mjs +13 -1
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +28 -29
- package/dist/runtime/polyfill/types/base.d.mts +2 -3
- package/dist/runtime/polyfill/types/common.d.mts +26 -27
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +34 -35
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +34 -35
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +25 -26
- package/dist/runtime/polyfill/types/systemAuth.d.mts +22 -23
- package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +5 -6
- package/dist/runtime/polyfill/uiMediaApi.d.mts +42 -43
- package/dist/runtime/polyfill.d.mts +3 -2
- package/dist/runtime/renderContext.d.mts +2 -3
- package/dist/runtime/renderContext.mjs +2 -1
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/runtime/rpx.d.mts +2 -3
- package/dist/runtime/seo/index.d.mts +11 -11
- package/dist/runtime/style.d.mts +2 -3
- package/dist/runtime/template.d.mts +3 -3
- package/dist/runtime/viewport/index.d.mts +4 -4
- package/dist/runtime/viewport/types.d.mts +2 -3
- package/dist/runtime/warning.d.mts +3 -4
- package/dist/runtime/wevu.d.mts +7 -4
- package/dist/runtime/wevu.mjs +13 -2
- package/dist/runtime/wevu.mjs.map +1 -1
- package/dist/shared/tabBar.d.mts +2 -3
- package/package.json +20 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { STYLE_QUERY, TEMPLATE_QUERY } from './constants'\nimport { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nexport function resolveBabelTraverse(mod: any): TraverseFunction {\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse = resolveBabelTraverse(_babelTraverse)\n\nfunction getRegisterName(kind: ModuleMeta['kind'], callee: string) {\n if (kind === 'page' && (callee === 'Page' || callee === 'Component')) {\n return 'registerPage'\n }\n if (kind === 'component' && callee === 'Component') {\n return 'registerComponent'\n }\n if (kind === 'app' && callee === 'App') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction createRegisterMetaCode(\n meta: ModuleMeta,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n includeKind = false,\n) {\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (includeKind) {\n metaParts.push(`kind: ${JSON.stringify(meta.kind)}`)\n }\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${metaParts.join(', ')} }`\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n includeKind = false,\n) {\n const node = path.node\n const callee = node.callee\n const identifier = callee as t.Identifier\n const end = node.end!\n const insertPosition = end - 1\n const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind)\n s.overwrite(identifier.start!, identifier.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n runtimeModuleId?: string\n hmrAcceptCode?: string\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n runtimeModuleId,\n hmrAcceptCode,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n const wevuDefineComponentNames = new Set<string>()\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement) || statement.source.value !== 'wevu') {\n continue\n }\n for (const specifier of statement.specifiers) {\n if (t.isImportSpecifier(specifier)\n && t.isIdentifier(specifier.imported, { name: 'defineComponent' })) {\n wevuDefineComponentNames.add(specifier.local.name)\n }\n }\n }\n\n const imports: string[] = []\n const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n const styleQuery = meta.stylePath.endsWith('.wxss') ? STYLE_QUERY : 'inline'\n imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n if (wevuDefineComponentNames.has(name) && meta.kind !== 'app') {\n registerImports.add('registerWebWevuComponent')\n overwriteCall(path, meta, 'registerWebWevuComponent', templateIdent, styleIdent, s, true)\n return\n }\n const registerName = getRegisterName(meta.kind, name)\n if (registerName) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n }\n },\n })\n\n registerImports.add('installWebModuleRegistration')\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n\n const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true)\n const restoreIdent = '__weapp_web_restore_registration__'\n const prefix = `${imports.join('\\n')}\\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\\n`\n s.prepend(prefix)\n\n s.append(`\\n${restoreIdent}()\\n`)\n\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,qBAAqB,KAA4B;CAC/D,IAAI,OAAO,QAAQ,YACjB,OAAO;CAET,IAAI,KAAK,WAAW,OAAO,IAAI,YAAY,YACzC,OAAO,IAAI;CAEb,IAAI,KAAK,YAAY,OAAO,IAAI,aAAa,YAC3C,OAAO,IAAI;CAEb,MAAM,IAAI,UAAU,6DAA6D;AACnF;AAEA,MAAM,WAAW,qBAAqB,cAAc;AAEpD,SAAS,gBAAgB,MAA0B,QAAgB;CACjE,IAAI,SAAS,WAAW,WAAW,UAAU,WAAW,cACtD,OAAO;CAET,IAAI,SAAS,eAAe,WAAW,aACrC,OAAO;CAET,IAAI,SAAS,SAAS,WAAW,OAC/B,OAAO;AAGX;AAEA,SAAS,uBACP,MACA,eACA,YACA,cAAc,OACd;CACA,MAAM,YAAsB,CAAC,OAAO,KAAK,UAAU,KAAK,EAAE,GAAG;CAC7D,IAAI,aACF,UAAU,KAAK,SAAS,KAAK,UAAU,KAAK,IAAI,GAAG;CAErD,IAAI,eACF,UAAU,KAAK,aAAa,eAAe;CAE7C,IAAI,YACF,UAAU,KAAK,UAAU,YAAY;CAEvC,IAAI,KAAK,eACP,UAAU,KAAK,kBAAkB,KAAK,UAAU,KAAK,aAAa,GAAG;CAEvE,OAAO,KAAK,UAAU,KAAK,IAAI,EAAE;AACnC;AAEA,SAAS,cACP,MACA,MACA,cACA,eACA,YACA,GACA,cAAc,OACd;CACA,MAAM,OAAO,KAAK;CAElB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AkB,IAAI,IAAY;CAExC,SAAS,KAAK,EACZ,eAAe,MAAgC;EAC7C,IAAI,CAAC,EAAE,aAAa,KAAK,KAAK,MAAM,GAClC;EAEF,MAAM,OAAO,KAAK,KAAK,OAAO;EAC9B,IAAI,yBAAyB,IAAI,IAAI,KAAK,KAAK,SAAS,OAAO;GAC7D,gBAAgB,IAAI,0BAA0B;GAC9C,cAAc,MAAM,MAAM,4BAA4B,eAAe,YAAY,GAAG,IAAI;GACxF;EACF;EACA,MAAM,eAAe,gBAAgB,KAAK,MAAM,IAAI;EACpD,IAAI,cAAc;GAChB,gBAAgB,IAAI,YAAY;GAChC,cAAc,MAAM,MAAM,cAAc,eAAe,YAAY,CAAC;EACtE;CACF,EACF,CAAC;CAED,gBAAgB,IAAI,8BAA8B;CAClD,QAAQ,QAAQ,YAAY,MAAM,KAAK,eAAe,CAAC,CAAC,KAAK,IAAI,EAAE,WAAW,kBAAkB,EAAE;CAElG,MAAM,iBAAiB,uBAAuB,MAAM,eAAe,YAAY,IAAI;CACnF,MAAM,eAAe;CACrB,MAAM,SAAS,GAAG,QAAQ,KAAK,IAAI,EAAE,UAAU,aAAa,kCAAkC,eAAe;CAC7G,EAAE,QAAQ,MAAM;CAEhB,EAAE,OAAO,KAAK,aAAa,KAAK;CAEhC,IAAI,aAAa,eACf,EAAE,OAAO,KAAK,cAAc,GAAG;CAGjC,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY,EACjB,OAAO,KACT,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"register.mjs","names":[],"sources":["../../src/plugin/register.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { SourceMap } from 'magic-string'\n\nimport type { ModuleMeta } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport MagicString from 'magic-string'\nimport { STYLE_QUERY, TEMPLATE_QUERY } from './constants'\nimport { appendQuery, resolveRuntimePolyfillPath, toRelativeImport, toViteFsImport } from './path'\n\ntype TraverseFunction = typeof _babelTraverse extends (...args: any[]) => any\n ? typeof _babelTraverse\n : typeof _babelTraverse extends { default: infer D }\n ? D\n : typeof _babelTraverse\n\nexport function resolveBabelTraverse(mod: any): TraverseFunction {\n if (typeof mod === 'function') {\n return mod\n }\n if (mod?.default && typeof mod.default === 'function') {\n return mod.default\n }\n if (mod?.traverse && typeof mod.traverse === 'function') {\n return mod.traverse\n }\n throw new TypeError('[@weapp-vite/web] Failed to resolve @babel/traverse export.')\n}\n\nconst traverse = resolveBabelTraverse(_babelTraverse)\n\nfunction getRegisterName(kind: ModuleMeta['kind'], callee: string) {\n if (kind === 'page' && (callee === 'Page' || callee === 'Component')) {\n return 'registerPage'\n }\n if (kind === 'component' && callee === 'Component') {\n return 'registerComponent'\n }\n if (kind === 'app' && callee === 'App') {\n return 'registerApp'\n }\n return undefined\n}\n\nfunction createRegisterMetaCode(\n meta: ModuleMeta,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n includeKind = false,\n) {\n const metaParts: string[] = [`id: ${JSON.stringify(meta.id)}`]\n if (includeKind) {\n metaParts.push(`kind: ${JSON.stringify(meta.kind)}`)\n }\n if (templateIdent) {\n metaParts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n metaParts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n metaParts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${metaParts.join(', ')} }`\n}\n\nfunction overwriteCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n registerName: string,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n includeKind = false,\n) {\n const node = path.node\n const callee = node.callee\n const identifier = callee as t.Identifier\n const end = node.end!\n const insertPosition = end - 1\n const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, includeKind)\n s.overwrite(identifier.start!, identifier.end!, registerName)\n s.appendLeft(insertPosition, `, ${metaCode}`)\n}\n\nfunction overwriteWevuFactoryCall(\n path: NodePath<CallExpression>,\n meta: ModuleMeta,\n templateIdent: string | undefined,\n styleIdent: string | undefined,\n s: MagicString,\n) {\n const node = path.node\n const identifier = node.callee as t.Identifier\n const factoryName = identifier.name\n const metaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true)\n const firstArgument = node.arguments[0]\n s.overwrite(identifier.start!, identifier.end!, 'registerWebWevuComponentFactory')\n if (firstArgument) {\n s.prependLeft(firstArgument.start!, `${factoryName}, ${metaCode}, `)\n return\n }\n s.appendLeft(node.end! - 1, `${factoryName}, ${metaCode}`)\n}\n\ninterface TransformScriptModuleOptions {\n code: string\n cleanId: string\n meta: ModuleMeta\n enableHmr: boolean\n runtimeModuleId?: string\n hmrAcceptCode?: string\n}\n\nexport function transformScriptModule({\n code,\n cleanId,\n meta,\n enableHmr,\n runtimeModuleId,\n hmrAcceptCode,\n}: TransformScriptModuleOptions): null | { code: string, map: SourceMap } {\n let ast: ReturnType<typeof parse> | undefined\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n ranges: true,\n })\n }\n catch {\n return null\n }\n\n const s = new MagicString(code)\n const wevuDefineComponentSpecifiers = new Map<string, t.ImportSpecifier>()\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement) || statement.source.value !== 'wevu') {\n continue\n }\n for (const specifier of statement.specifiers) {\n if (\n t.isImportSpecifier(specifier)\n && t.isIdentifier(specifier.imported, { name: 'defineComponent' })\n ) {\n wevuDefineComponentSpecifiers.set(specifier.local.name, specifier)\n }\n }\n }\n\n const imports: string[] = []\n const runtimePolyfillId = runtimeModuleId ?? toViteFsImport(resolveRuntimePolyfillPath())\n const templateIdent = meta.templatePath ? '__weapp_template__' : undefined\n const styleIdent = meta.stylePath ? '__weapp_style__' : undefined\n\n if (meta.templatePath && templateIdent) {\n imports.push(`import ${templateIdent} from '${appendQuery(toRelativeImport(cleanId, meta.templatePath), TEMPLATE_QUERY)}'`)\n }\n\n if (meta.stylePath && styleIdent) {\n const styleQuery = meta.stylePath.endsWith('.wxss') ? STYLE_QUERY : 'inline'\n imports.push(`import ${styleIdent} from '${appendQuery(toRelativeImport(cleanId, meta.stylePath), styleQuery)}'`)\n }\n\n const registerImports = new Set<string>()\n\n traverse(ast, {\n CallExpression(path: NodePath<CallExpression>) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n const name = path.node.callee.name\n const wevuFactorySpecifier = wevuDefineComponentSpecifiers.get(name)\n const binding = path.scope.getBinding(name)\n if (\n wevuFactorySpecifier\n && binding?.path.node === wevuFactorySpecifier\n && meta.kind !== 'app'\n ) {\n registerImports.add('registerWebWevuComponentFactory')\n overwriteWevuFactoryCall(path, meta, templateIdent, styleIdent, s)\n return\n }\n const registerName = getRegisterName(meta.kind, name)\n if (registerName) {\n registerImports.add(registerName)\n overwriteCall(path, meta, registerName, templateIdent, styleIdent, s)\n }\n },\n })\n\n registerImports.add('installWebModuleRegistration')\n imports.unshift(`import { ${Array.from(registerImports).join(', ')} } from '${runtimePolyfillId}'`)\n\n const moduleMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent, true)\n const restoreIdent = '__weapp_web_restore_registration__'\n const prefix = `${imports.join('\\n')}\\nconst ${restoreIdent} = installWebModuleRegistration(${moduleMetaCode})\\n`\n s.prepend(prefix)\n\n s.append(`\\n${restoreIdent}()\\n`)\n\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({\n hires: true,\n }),\n }\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,qBAAqB,KAA4B;CAC/D,IAAI,OAAO,QAAQ,YACjB,OAAO;CAET,IAAI,KAAK,WAAW,OAAO,IAAI,YAAY,YACzC,OAAO,IAAI;CAEb,IAAI,KAAK,YAAY,OAAO,IAAI,aAAa,YAC3C,OAAO,IAAI;CAEb,MAAM,IA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OAAO,KAAK,KAAK,OAAO;EAC9B,MAAM,uBAAuB,8BAA8B,IAAI,IAAI;EACnE,MAAM,UAAU,KAAK,MAAM,WAAW,IAAI;EAC1C,IACE,wBACG,SAAS,KAAK,SAAS,wBACvB,KAAK,SAAS,OACjB;GACA,gBAAgB,IAAI,iCAAiC;GACrD,yBAAyB,MAAM,MAAM,eAAe,YAAY,CAAC;GACjE;EACF;EACA,MAAM,eAAe,gBAAgB,KAAK,MAAM,IAAI;EACpD,IAAI,cAAc;GAChB,gBAAgB,IAAI,YAAY;GAChC,cAAc,MAAM,MAAM,cAAc,eAAe,YAAY,CAAC;EACtE;CACF,EACF,CAAC;CAED,gBAAgB,IAAI,8BAA8B;CAClD,QAAQ,QAAQ,YAAY,MAAM,KAAK,eAAe,CAAC,CAAC,KAAK,IAAI,EAAE,WAAW,kBAAkB,EAAE;CAElG,MAAM,iBAAiB,uBAAuB,MAAM,eAAe,YAAY,IAAI;CACnF,MAAM,eAAe;CACrB,MAAM,SAAS,GAAG,QAAQ,KAAK,IAAI,EAAE,UAAU,aAAa,kCAAkC,eAAe;CAC7G,EAAE,QAAQ,MAAM;CAEhB,EAAE,OAAO,KAAK,aAAa,KAAK;CAEhC,IAAI,aAAa,eACf,EAAE,OAAO,KAAK,cAAc,GAAG;CAGjC,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY,EACjB,OAAO,KACT,CAAC;CACH;AACF"}
|
package/dist/plugin/types.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { WebRoutingConfig } from "../runtime/polyfill/routeRuntime/history.mjs";
|
|
|
3
3
|
import { WebResourceHintsConfig, WebRuntimeSeoConfig as WebSeoConfig } from "../runtime/seo/index.mjs";
|
|
4
4
|
import "wevu/compiler";
|
|
5
5
|
//#region src/plugin/types.d.ts
|
|
6
|
-
interface WeappWebPluginOptions {
|
|
6
|
+
export interface WeappWebPluginOptions {
|
|
7
7
|
wxss?: WxssTransformOptions;
|
|
8
8
|
/**
|
|
9
9
|
* 小程序项目的源代码根目录,默认 `<root>/src`。
|
|
@@ -74,18 +74,17 @@ interface WeappWebPluginOptions {
|
|
|
74
74
|
/** @internal */
|
|
75
75
|
__resolveAppConfig?: (appConfigPath: string) => Promise<Record<string, unknown> | undefined>;
|
|
76
76
|
}
|
|
77
|
-
type WebStylePreprocessOptions = Record<string, Record<string, unknown>>;
|
|
78
|
-
interface WebResolvedComponent {
|
|
77
|
+
export type WebStylePreprocessOptions = Record<string, Record<string, unknown>>;
|
|
78
|
+
export interface WebResolvedComponent {
|
|
79
79
|
name: string;
|
|
80
80
|
from: string;
|
|
81
81
|
resolvedId?: string;
|
|
82
82
|
sourceType?: 'wevu-sfc' | 'native';
|
|
83
83
|
}
|
|
84
|
-
type WebComponentResolver = {
|
|
84
|
+
export type WebComponentResolver = {
|
|
85
85
|
components?: Record<string, string>;
|
|
86
86
|
resolve?: (componentName: string, baseName: string) => WebResolvedComponent | void;
|
|
87
87
|
} | ((componentName: string, baseName: string) => WebResolvedComponent | void);
|
|
88
|
-
type ResolveWebModuleId = (source: string, importer?: string) => Promise<string | undefined>;
|
|
88
|
+
export type ResolveWebModuleId = (source: string, importer?: string) => Promise<string | undefined>;
|
|
89
89
|
//#endregion
|
|
90
|
-
export { ResolveWebModuleId, WeappWebPluginOptions, WebComponentResolver, WebResolvedComponent, WebStylePreprocessOptions };
|
|
91
90
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { FormConfig } from "../nativeComponents/form.mjs";
|
|
2
2
|
//#region src/runtime/button/index.d.ts
|
|
3
|
-
declare function ensureButtonDefined(): void;
|
|
4
|
-
declare function setButtonFormConfig(next: FormConfig): void;
|
|
5
|
-
type ButtonFormConfig = FormConfig;
|
|
3
|
+
export declare function ensureButtonDefined(): void;
|
|
4
|
+
export declare function setButtonFormConfig(next: FormConfig): void;
|
|
5
|
+
export type ButtonFormConfig = FormConfig;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { ButtonFormConfig, ensureButtonDefined, setButtonFormConfig };
|
|
8
7
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
//#region src/runtime/component/constants.ts
|
|
2
2
|
const supportsLit = typeof document !== "undefined" && typeof document.createComment === "function" && typeof document.createTreeWalker === "function";
|
|
3
3
|
const FallbackElement = class {};
|
|
4
|
+
const EVENT_ATTRIBUTE_NAME_ESCAPE_RE = /[A-Z_]/g;
|
|
5
|
+
const EVENT_ATTRIBUTE_NAME_UNESCAPE_RE = /_([a-z_])/g;
|
|
6
|
+
function encodeEventAttributeName(eventName) {
|
|
7
|
+
return eventName.replace(EVENT_ATTRIBUTE_NAME_ESCAPE_RE, (character) => character === "_" ? "__" : `_${character.toLowerCase()}`);
|
|
8
|
+
}
|
|
9
|
+
function decodeEventAttributeName(attributeName) {
|
|
10
|
+
return attributeName.replace(EVENT_ATTRIBUTE_NAME_UNESCAPE_RE, (_match, character) => character === "_" ? "_" : character.toUpperCase());
|
|
11
|
+
}
|
|
4
12
|
const MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX = "data-mp-on-";
|
|
5
13
|
const MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX = "data-mp-on-flags-";
|
|
6
14
|
const WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX = "data-wx-on-";
|
|
@@ -9,5 +17,5 @@ const EVENT_ATTRIBUTE_PREFIXES = [MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, WECHAT_LE
|
|
|
9
17
|
const EVENT_FLAG_ATTRIBUTE_PREFIXES = [MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX];
|
|
10
18
|
|
|
11
19
|
//#endregion
|
|
12
|
-
export { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES, FallbackElement, MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX, supportsLit };
|
|
20
|
+
export { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES, FallbackElement, MINI_PROGRAM_EVENT_ATTRIBUTE_PREFIX, MINI_PROGRAM_EVENT_FLAG_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_ATTRIBUTE_PREFIX, WECHAT_LEGACY_EVENT_FLAG_ATTRIBUTE_PREFIX, decodeEventAttributeName, encodeEventAttributeName, supportsLit };
|
|
13
21
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -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,CAAC;
|
|
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\n// HTML 会折叠属性名大小写,因此用小写安全后缀保存自定义事件名。\nconst EVENT_ATTRIBUTE_NAME_ESCAPE_RE = /[A-Z_]/g\nconst EVENT_ATTRIBUTE_NAME_UNESCAPE_RE = /_([a-z_])/g\n\nexport function encodeEventAttributeName(eventName: string) {\n return eventName.replace(\n EVENT_ATTRIBUTE_NAME_ESCAPE_RE,\n character => character === '_' ? '__' : `_${character.toLowerCase()}`,\n )\n}\n\nexport function decodeEventAttributeName(attributeName: string) {\n return attributeName.replace(\n EVENT_ATTRIBUTE_NAME_UNESCAPE_RE,\n (_match, character: string) => character === '_' ? '_' : character.toUpperCase(),\n )\n}\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;AAGtC,MAAM,iCAAiC;AACvC,MAAM,mCAAmC;AAEzC,SAAgB,yBAAyB,WAAmB;CAC1D,OAAO,UAAU,QACf,iCACA,cAAa,cAAc,MAAM,OAAO,IAAI,UAAU,YAAY,GACpE;AACF;AAEA,SAAgB,yBAAyB,eAAuB;CAC9D,OAAO,cAAc,QACnB,mCACC,QAAQ,cAAsB,cAAc,MAAM,MAAM,UAAU,YAAY,CACjF;AACF;AAEA,MAAa,sCAAsC;AACnD,MAAa,2CAA2C;AAExD,MAAa,uCAAuC;AACpD,MAAa,4CAA4C;AAKzD,MAAa,2BAA2B,CACtC,qCACA,oCACF;AAEA,MAAa,gCAAgC,CAC3C,0CACA,yCACF"}
|
|
@@ -11,6 +11,7 @@ import { createWebSlotsProxy } from "./slots.mjs";
|
|
|
11
11
|
import { assignDataPath, cloneValue, coerceValue, parseDataPath, resolveDataPath, toCamelCase } from "./utils.mjs";
|
|
12
12
|
import { clearVirtualHostClasses, clearVirtualHostParts, syncVirtualHostClasses, syncVirtualHostParts } from "./virtualHost.mjs";
|
|
13
13
|
import { html } from "lit";
|
|
14
|
+
import { WEVU_HOST_COMMIT_PROMISE_KEY } from "@weapp-core/constants";
|
|
14
15
|
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
15
16
|
|
|
16
17
|
//#region src/runtime/component/element.ts
|
|
@@ -45,6 +46,9 @@ function createComponentElementClass({ BaseElement, runtimeState, instances }) {
|
|
|
45
46
|
#virtualHostClassTokens = /* @__PURE__ */ new Set();
|
|
46
47
|
#virtualHostPartTokens = /* @__PURE__ */ new Set();
|
|
47
48
|
#virtualHostRootElement;
|
|
49
|
+
#needsSetDataRecovery = false;
|
|
50
|
+
#hostCommitPromise;
|
|
51
|
+
#hostCommitUpdate;
|
|
48
52
|
data;
|
|
49
53
|
properties;
|
|
50
54
|
constructor() {
|
|
@@ -88,11 +92,27 @@ function createComponentElementClass({ BaseElement, runtimeState, instances }) {
|
|
|
88
92
|
instances.add(this);
|
|
89
93
|
runtimeState.lifetimes.created?.call(this.#publicInstance);
|
|
90
94
|
}
|
|
95
|
+
get [WEVU_HOST_COMMIT_PROMISE_KEY]() {
|
|
96
|
+
if (!supportsLit) return;
|
|
97
|
+
const update = this.updateComplete;
|
|
98
|
+
return this.#hostCommitUpdate === update ? this.#hostCommitPromise : update;
|
|
99
|
+
}
|
|
91
100
|
setData(patch, callback) {
|
|
92
101
|
const changed = this.#applyDataPatch(patch);
|
|
93
|
-
if (supportsLit && changed
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
if (supportsLit && (changed || this.#needsSetDataRecovery)) {
|
|
103
|
+
if (!changed) this.requestUpdate();
|
|
104
|
+
const update = this.updateComplete;
|
|
105
|
+
const commitPromise = update.then(() => {
|
|
106
|
+
this.#needsSetDataRecovery = false;
|
|
107
|
+
callback?.();
|
|
108
|
+
}, (cause) => {
|
|
109
|
+
this.#needsSetDataRecovery = true;
|
|
110
|
+
throw cause;
|
|
111
|
+
});
|
|
112
|
+
this.#hostCommitPromise = commitPromise;
|
|
113
|
+
this.#hostCommitUpdate = update;
|
|
114
|
+
return commitPromise;
|
|
115
|
+
}
|
|
96
116
|
callback?.();
|
|
97
117
|
}
|
|
98
118
|
triggerEvent(name, detail, options = {}) {
|
|
@@ -185,7 +205,7 @@ function createComponentElementClass({ BaseElement, runtimeState, instances }) {
|
|
|
185
205
|
for (const [path, value] of Object.entries(patch)) {
|
|
186
206
|
const segments = parseDataPath(path);
|
|
187
207
|
const topKey = segments[0];
|
|
188
|
-
if (!topKey || Object.is(resolveDataPath(this.#state, segments), value)) continue;
|
|
208
|
+
if (!topKey || topKey === "$slots" || Object.is(resolveDataPath(this.#state, segments), value)) continue;
|
|
189
209
|
if (hasOwn(this.#properties, topKey) && !hasOwn(previousProperties, topKey)) previousProperties[topKey] = this.#properties[topKey];
|
|
190
210
|
assignDataPath(this.#state, segments, value);
|
|
191
211
|
if (hasOwn(this.#properties, topKey)) this.#properties[topKey] = this.#state[topKey];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.mjs","names":[],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n PageLifeTimeHooks,\n TriggerEventOptions,\n} from './types'\nimport type { ClassAttributeElement } from './virtualHost'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createIntersectionObserverBridge } from '../polyfill/intersectionObserver'\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 { runComponentObservers } from './observers'\nimport { createComponentPublicInstance } from './publicInstance'\nimport { resolveRelationNodes } from './relations'\nimport { createWebSlotsProxy } from './slots'\nimport { assignDataPath, cloneValue, coerceValue, parseDataPath, resolveDataPath, toCamelCase } from './utils'\nimport {\n clearVirtualHostClasses,\n clearVirtualHostParts,\n syncVirtualHostClasses,\n syncVirtualHostParts,\n} from './virtualHost'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nfunction resolveComposedParent(node: Node): Node | undefined {\n const assignedSlot = (node as Element).assignedSlot\n if (assignedSlot) {\n return assignedSlot\n }\n if (node.parentNode) {\n return node.parentNode\n }\n const root = node.getRootNode?.()\n return root instanceof ShadowRoot ? root.host : undefined\n}\n\nfunction isWeappComponentInstance(value: unknown): value is WeappComponentInstance {\n return Boolean(\n value\n && typeof value === 'object'\n && typeof (value as WeappComponentInstance).__weappSync === 'function',\n )\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n const RuntimeBaseElement = BaseElement as typeof HTMLElement & {\n readonly observedAttributes?: string[]\n }\n class WeappWebComponent extends RuntimeBaseElement implements WeappComponentInstance {\n static get observedAttributes() {\n const inherited = super.observedAttributes ?? []\n return Array.from(new Set([...inherited, ...runtimeState.observedAttributes]))\n }\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any> = {}\n #publicInstance: ComponentPublicInstance\n #exposedMethodNames = new Set<string>()\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n #virtualHostClassTokens = new Set<string>()\n #virtualHostPartTokens = new Set<string>()\n #virtualHostRootElement: ClassAttributeElement | undefined\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = runtimeState.componentRef.data ?? {}\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n Object.defineProperty(this.#state, '$slots', {\n configurable: true,\n enumerable: true,\n value: createWebSlotsProxy(() => this.#state.vueSlots),\n })\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 this.#publicInstance = createComponentPublicInstance(\n this,\n WeappWebComponent.prototype,\n key => typeof key === 'string' ? this.#methods[key] : undefined,\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 this.#syncMethods(runtimeState.componentRef.methods ?? {})\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.#publicInstance)\n }\n\n setData(patch: DataRecord, callback?: () => void) {\n const changed = this.#applyDataPatch(patch)\n if (supportsLit && changed) {\n const updateComplete = (this as unknown as { updateComplete: Promise<boolean> }).updateComplete\n return updateComplete.then(() => {\n callback?.()\n })\n }\n callback?.()\n }\n\n triggerEvent(name: string, detail?: any, options: TriggerEventOptions = {}) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: options.bubbles ?? false,\n composed: options.composed ?? false,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n createIntersectionObserver(options?: {\n initialRatio?: number\n observeAll?: boolean\n thresholds?: number[]\n }) {\n return createIntersectionObserverBridge(this, options)\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 getRelationNodes(relationPath: string) {\n const relation = runtimeState.componentRef.relations?.[relationPath]\n return relation\n ? resolveRelationNodes(this, runtimeState.id, relationPath, relation.type)\n : []\n }\n\n selectOwnerComponent() {\n let current = resolveComposedParent(this)\n while (current) {\n if (isWeappComponentInstance(current)) {\n return current\n }\n current = resolveComposedParent(current)\n }\n return undefined\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.#publicInstance)\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.#publicInstance)\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.#publicInstance)\n this.#readyFired = true\n }\n\n updated() {\n this.#syncVirtualHostClasses()\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 false\n }\n let changed = false\n const changedKeys: string[] = []\n const previousProperties: DataRecord = {}\n for (const [path, value] of Object.entries(patch)) {\n const segments = parseDataPath(path)\n const topKey = segments[0]\n if (!topKey || Object.is(resolveDataPath(this.#state, segments), value)) {\n continue\n }\n if (hasOwn(this.#properties, topKey) && !hasOwn(previousProperties, topKey)) {\n previousProperties[topKey] = this.#properties[topKey]\n }\n assignDataPath(this.#state, segments, value)\n if (hasOwn(this.#properties, topKey)) {\n this.#properties[topKey] = this.#state[topKey]\n }\n changedKeys.push(path)\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, changedKeys, previousProperties)\n for (const key of changedKeys) {\n if (runtimeState.componentRef.properties?.[key]?.observer) {\n this.#observedKeys.add(key)\n }\n }\n }\n return changed\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 runComponentObservers(runtimeState.componentRef, this.#publicInstance, [name], { [name]: oldValue })\n if (propOption?.observer) {\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.#publicInstance, 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.#publicInstance)\n }\n }\n for (const name of this.#exposedMethodNames) {\n if (name in bound) {\n continue\n }\n const descriptor = Object.getOwnPropertyDescriptor(this, name)\n if (descriptor?.configurable && descriptor.value === this.#methods[name]) {\n delete (this as unknown as Record<string, unknown>)[name]\n }\n this.#exposedMethodNames.delete(name)\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 if (!this.#exposedMethodNames.has(key) && key in this) {\n continue\n }\n Object.defineProperty(this, key, {\n configurable: true,\n enumerable: false,\n writable: true,\n value: fn,\n })\n this.#exposedMethodNames.add(key)\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.#publicInstance)\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 this.#syncVirtualHostClasses()\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n }\n\n #syncVirtualHostClasses() {\n const host = this as unknown as ClassAttributeElement\n if (!runtimeState.componentRef.options?.virtualHost) {\n clearVirtualHostClasses(host, this.#virtualHostClassTokens)\n clearVirtualHostParts(this.#virtualHostRootElement, this.#virtualHostPartTokens)\n this.#virtualHostRootElement = undefined\n return\n }\n const root = resolveRenderRoot(this)\n syncVirtualHostClasses(host, root, this.#virtualHostClassTokens)\n this.#virtualHostRootElement = syncVirtualHostParts(\n root,\n this.#virtualHostRootElement,\n this.#virtualHostPartTokens,\n )\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,SAAS,sBAAsB,MAA8B;CAC3D,MAAM,eAAgB,KAAiB;CACvC,IAAI,cACF,OAAO;CAET,IAAI,KAAK,YACP,OAAO,KAAK;CAEd,MAAM,OAAO,KAAK,cAAc;CAChC,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;AAEA,SAAS,yBAAyB,OAAiD;CACjF,OAAO,QACL,SACG,OAAO,UAAU,YACjB,OAAQ,MAAiC,gBAAgB,UAC9D;AACF;AAEA,SAAgB,4BAA4B,EAC1C,aACA,cACA,aACiE;CACjE,MAAM,qBAAqB;CAG3B,MAAM,0BAA0B,mBAAqD;EACnF,WAAW,qBAAqB;GAC9B,MAAM,YAAY,MAAM,sBAAsB,CAAC;GAC/C,OAAO,MAAM,qBAAK,IAAI,IAAI,CAAC,GAAG,WAAW,GAAG,aAAa,kBAAkB,CAAC,CAAC;EAC/E;EAEA;EACA;EACA,WAAgD,CAAC;EACjD;EACA,sCAAsB,IAAI,IAAY;EACtC,aAAa;EACb,iBAAiB,oBAAoB,MAAM,CAAC,CAAC;EAC7C,sBAAsB;EACtB,cAAc;EACd,oBAAoB;EACpB,gCAAgB,IAAI,IAAY;EAChC,0CAA0B,IAAI,IAAY;EAC1C,yCAAyB,IAAI,IAAY;EACzC;EACA,AAAS;EACT,AAAS;EAET,cAAc;GACZ,MAAM;GACN,MAAM,aAAa,aAAa,aAAa,QAAQ,CAAC;GACtD,KAAK,cAAc,EAAE,GAAG,aAAa,sBAAsB;GAC3D,KAAK,SAAS;IAAE,GAAG,WAAW,KAAK,WA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B,KAAK,YAAY,GAAG,cAAc,OAAO,MAAM;GAEjD,KAAK,wBAAwB;GAC7B,IAAI,CAAC,KAAK,aAAa;IACrB,aAAa,UAAU,OAAO,KAAK,KAAK,eAAe;IACvD,KAAK,cAAc;GACrB;EACF;EAEA,0BAA0B;GACxB,MAAM,OAAO;GACb,IAAI,CAAC,aAAa,aAAa,SAAS,aAAa;IACnD,wBAAwB,MAAM,KAAK,uBAAuB;IAC1D,sBAAsB,KAAK,yBAAyB,KAAK,sBAAsB;IAC/E,KAAK,0BAA0B;IAC/B;GACF;GACA,MAAM,OAAO,kBAAkB,IAAI;GACnC,uBAAuB,MAAM,MAAM,KAAK,uBAAuB;GAC/D,KAAK,0BAA0B,qBAC7B,MACA,KAAK,yBACL,KAAK,sBACP;EACF;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"element.mjs","names":[],"sources":["../../../src/runtime/component/element.ts"],"sourcesContent":["import type {\n CreateComponentElementClassOptions,\n WeappComponentInstance,\n} from './elementTypes'\nimport type {\n ComponentOptions,\n ComponentPublicInstance,\n DataRecord,\n PageLifeTimeHooks,\n TriggerEventOptions,\n} from './types'\nimport type { ClassAttributeElement } from './virtualHost'\nimport { WEVU_HOST_COMMIT_PROMISE_KEY } from '@weapp-core/constants'\nimport { html } from 'lit'\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js'\nimport { createIntersectionObserverBridge } from '../polyfill/intersectionObserver'\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 { runComponentObservers } from './observers'\nimport { createComponentPublicInstance } from './publicInstance'\nimport { resolveRelationNodes } from './relations'\nimport { createWebSlotsProxy } from './slots'\nimport { assignDataPath, cloneValue, coerceValue, parseDataPath, resolveDataPath, toCamelCase } from './utils'\nimport {\n clearVirtualHostClasses,\n clearVirtualHostParts,\n syncVirtualHostClasses,\n syncVirtualHostParts,\n} from './virtualHost'\n\nexport type { WeappComponentInstance } from './elementTypes'\nexport type WeappComponentElementClass = typeof HTMLElement & {\n new (): WeappComponentInstance\n}\n\nfunction resolveComposedParent(node: Node): Node | undefined {\n const assignedSlot = (node as Element).assignedSlot\n if (assignedSlot) {\n return assignedSlot\n }\n if (node.parentNode) {\n return node.parentNode\n }\n const root = node.getRootNode?.()\n return root instanceof ShadowRoot ? root.host : undefined\n}\n\nfunction isWeappComponentInstance(value: unknown): value is WeappComponentInstance {\n return Boolean(\n value\n && typeof value === 'object'\n && typeof (value as WeappComponentInstance).__weappSync === 'function',\n )\n}\n\nexport function createComponentElementClass({\n BaseElement,\n runtimeState,\n instances,\n}: CreateComponentElementClassOptions): WeappComponentElementClass {\n const RuntimeBaseElement = BaseElement as typeof HTMLElement & {\n readonly observedAttributes?: string[]\n }\n class WeappWebComponent extends RuntimeBaseElement implements WeappComponentInstance {\n static get observedAttributes() {\n const inherited = super.observedAttributes ?? []\n return Array.from(new Set([...inherited, ...runtimeState.observedAttributes]))\n }\n\n #state: DataRecord\n #properties: DataRecord\n #methods: Record<string, (event: any) => any> = {}\n #publicInstance: ComponentPublicInstance\n #exposedMethodNames = new Set<string>()\n #isMounted = false\n #renderContext = createRenderContext(this, {})\n #usesLegacyTemplate = false\n #readyFired = false\n #observerInitDone = false\n #observedKeys = new Set<string>()\n #virtualHostClassTokens = new Set<string>()\n #virtualHostPartTokens = new Set<string>()\n #virtualHostRootElement: ClassAttributeElement | undefined\n #needsSetDataRecovery = false\n #hostCommitPromise: Promise<void> | undefined\n #hostCommitUpdate: Promise<boolean> | undefined\n readonly data!: DataRecord\n readonly properties!: DataRecord\n\n constructor() {\n super()\n const dataOption = runtimeState.componentRef.data ?? {}\n this.#properties = { ...runtimeState.defaultPropertyValues }\n this.#state = { ...cloneValue(this.#properties), ...cloneValue(dataOption) }\n Object.defineProperty(this.#state, '$slots', {\n configurable: true,\n enumerable: true,\n value: createWebSlotsProxy(() => this.#state.vueSlots),\n })\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 this.#publicInstance = createComponentPublicInstance(\n this,\n WeappWebComponent.prototype,\n key => typeof key === 'string' ? this.#methods[key] : undefined,\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 this.#syncMethods(runtimeState.componentRef.methods ?? {})\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.#publicInstance)\n }\n\n get [WEVU_HOST_COMMIT_PROMISE_KEY]() {\n // 回调异常属于当前提交;后续属性更新或 HMR 必须等待自己的 Lit 提交。\n if (!supportsLit) {\n return undefined\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n return this.#hostCommitUpdate === update ? this.#hostCommitPromise : update\n }\n\n setData(patch: DataRecord, callback?: () => void) {\n const changed = this.#applyDataPatch(patch)\n if (supportsLit && (changed || this.#needsSetDataRecovery)) {\n if (!changed) {\n this.requestUpdate()\n }\n // 动态 Lit 基类不会在静态声明中暴露 updateComplete。\n const litElement = this as unknown as { updateComplete: Promise<boolean> }\n const update = litElement.updateComplete\n const commitPromise = update.then(\n () => {\n this.#needsSetDataRecovery = false\n callback?.()\n },\n (cause) => {\n this.#needsSetDataRecovery = true\n throw cause\n },\n )\n this.#hostCommitPromise = commitPromise\n this.#hostCommitUpdate = update\n return commitPromise\n }\n callback?.()\n }\n\n triggerEvent(name: string, detail?: any, options: TriggerEventOptions = {}) {\n this.dispatchEvent(new CustomEvent(name, {\n detail,\n bubbles: options.bubbles ?? false,\n composed: options.composed ?? false,\n }))\n }\n\n createSelectorQuery() {\n return createScopedSelectorQuery(this)\n }\n\n createIntersectionObserver(options?: {\n initialRatio?: number\n observeAll?: boolean\n thresholds?: number[]\n }) {\n return createIntersectionObserverBridge(this, options)\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 getRelationNodes(relationPath: string) {\n const relation = runtimeState.componentRef.relations?.[relationPath]\n return relation\n ? resolveRelationNodes(this, runtimeState.id, relationPath, relation.type)\n : []\n }\n\n selectOwnerComponent() {\n let current = resolveComposedParent(this)\n while (current) {\n if (isWeappComponentInstance(current)) {\n return current\n }\n current = resolveComposedParent(current)\n }\n return undefined\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.#publicInstance)\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.#publicInstance)\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.#publicInstance)\n this.#readyFired = true\n }\n\n updated() {\n this.#syncVirtualHostClasses()\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 false\n }\n let changed = false\n const changedKeys: string[] = []\n const previousProperties: DataRecord = {}\n for (const [path, value] of Object.entries(patch)) {\n const segments = parseDataPath(path)\n const topKey = segments[0]\n if (!topKey || topKey === '$slots' || Object.is(resolveDataPath(this.#state, segments), value)) {\n continue\n }\n if (hasOwn(this.#properties, topKey) && !hasOwn(previousProperties, topKey)) {\n previousProperties[topKey] = this.#properties[topKey]\n }\n assignDataPath(this.#state, segments, value)\n if (hasOwn(this.#properties, topKey)) {\n this.#properties[topKey] = this.#state[topKey]\n }\n changedKeys.push(path)\n changed = true\n }\n if (changed) {\n this.requestUpdate()\n runComponentObservers(runtimeState.componentRef, this.#publicInstance, changedKeys, previousProperties)\n for (const key of changedKeys) {\n if (runtimeState.componentRef.properties?.[key]?.observer) {\n this.#observedKeys.add(key)\n }\n }\n }\n return changed\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 runComponentObservers(runtimeState.componentRef, this.#publicInstance, [name], { [name]: oldValue })\n if (propOption?.observer) {\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.#publicInstance, 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.#publicInstance)\n }\n }\n for (const name of this.#exposedMethodNames) {\n if (name in bound) {\n continue\n }\n const descriptor = Object.getOwnPropertyDescriptor(this, name)\n if (descriptor?.configurable && descriptor.value === this.#methods[name]) {\n delete (this as unknown as Record<string, unknown>)[name]\n }\n this.#exposedMethodNames.delete(name)\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 if (!this.#exposedMethodNames.has(key) && key in this) {\n continue\n }\n Object.defineProperty(this, key, {\n configurable: true,\n enumerable: false,\n writable: true,\n value: fn,\n })\n this.#exposedMethodNames.add(key)\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.#publicInstance)\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 this.#syncVirtualHostClasses()\n if (!this.#readyFired) {\n runtimeState.lifetimes.ready?.call(this.#publicInstance)\n this.#readyFired = true\n }\n }\n\n #syncVirtualHostClasses() {\n const host = this as unknown as ClassAttributeElement\n if (!runtimeState.componentRef.options?.virtualHost) {\n clearVirtualHostClasses(host, this.#virtualHostClassTokens)\n clearVirtualHostParts(this.#virtualHostRootElement, this.#virtualHostPartTokens)\n this.#virtualHostRootElement = undefined\n return\n }\n const root = resolveRenderRoot(this)\n syncVirtualHostClasses(host, root, this.#virtualHostClassTokens)\n this.#virtualHostRootElement = syncVirtualHostParts(\n root,\n this.#virtualHostRootElement,\n this.#virtualHostPartTokens,\n )\n }\n }\n\n return WeappWebComponent as WeappComponentElementClass\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2CA,SAAS,sBAAsB,MAA8B;CAC3D,MAAM,eAAgB,KAAiB;CACvC,IAAI,cACF,OAAO;CAET,IAAI,KAAK,YACP,OAAO,KAAK;CAEd,MAAM,OAAO,KAAK,cAAc;CAChC,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;AAEA,SAAS,yBAAyB,OAAiD;CACjF,OAAO,QACL,SACG,OAAO,UAAU,YACjB,OAAQ,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0BAA0B;GACxB,MAAM,OAAO;GACb,IAAI,CAAC,aAAa,aAAa,SAAS,aAAa;IACnD,wBAAwB,MAAM,KAAK,uBAAuB;IAC1D,sBAAsB,KAAK,yBAAyB,KAAK,sBAAsB;IAC/E,KAAK,0BAA0B;IAC/B;GACF;GACA,MAAM,OAAO,kBAAkB,IAAI;GACnC,uBAAuB,MAAM,MAAM,KAAK,uBAAuB;GAC/D,KAAK,0BAA0B,qBAC7B,MACA,KAAK,yBACL,KAAK,sBACP;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES } from "./constants.mjs";
|
|
1
|
+
import { EVENT_ATTRIBUTE_PREFIXES, EVENT_FLAG_ATTRIBUTE_PREFIXES, decodeEventAttributeName } from "./constants.mjs";
|
|
2
|
+
import { invokeMiniProgramEventHandler } from "../inputHandlerResult.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/runtime/component/events.ts
|
|
4
5
|
function parseEventFlags(value) {
|
|
@@ -25,8 +26,9 @@ function bindRuntimeEvents(root, methods, instance) {
|
|
|
25
26
|
if (!handlerName) continue;
|
|
26
27
|
const handler = methods[handlerName];
|
|
27
28
|
if (!handler) continue;
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
const encodedEventName = attribute.slice(matchedPrefix.length);
|
|
30
|
+
const eventName = decodeEventAttributeName(encodedEventName);
|
|
31
|
+
const flags = parseEventFlags(EVENT_FLAG_ATTRIBUTE_PREFIXES.map((prefix) => element.getAttribute(`${prefix}${encodedEventName}`)).find((value) => value !== null) ?? null);
|
|
30
32
|
element.addEventListener(eventName, (nativeEvent) => {
|
|
31
33
|
if (flags.catch) nativeEvent.stopPropagation();
|
|
32
34
|
const dataset = { ...element.dataset };
|
|
@@ -38,7 +40,7 @@ function bindRuntimeEvents(root, methods, instance) {
|
|
|
38
40
|
currentTarget: { dataset },
|
|
39
41
|
originalEvent: nativeEvent
|
|
40
42
|
};
|
|
41
|
-
handler
|
|
43
|
+
invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent);
|
|
42
44
|
}, flags.capture);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/runtime/component/events.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './types'\nimport { invokeMiniProgramEventHandler } from '../inputHandlerResult'\nimport {\n decodeEventAttributeName,\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 encodedEventName = attribute.slice(matchedPrefix.length)\n const eventName = decodeEventAttributeName(encodedEventName)\n const flagAttributeValue = EVENT_FLAG_ATTRIBUTE_PREFIXES\n .map(prefix => element.getAttribute(`${prefix}${encodedEventName}`))\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 invokeMiniProgramEventHandler(handler, instance, syntheticEvent, nativeEvent)\n }, flags.capture)\n }\n }\n}\n"],"mappings":";;;;AAQA,SAAS,gBAAgB,OAAsB;CAC7C,IAAI,CAAC,OACH,OAAO;EAAE,OAAO;EAAO,SAAS;CAAM;CAExC,MAAM,SA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AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentConstructor, ComponentOptions, ComponentPublicInstance, DefineComponentOptions, PropertyOption } from "./types.mjs";
|
|
2
2
|
//#region src/runtime/component/index.d.ts
|
|
3
|
-
declare function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor;
|
|
3
|
+
export declare function defineComponent(tagName: string, options: DefineComponentOptions): ComponentConstructor;
|
|
4
4
|
//#endregion
|
|
5
|
-
export {
|
|
5
|
+
export type { ComponentOptions, ComponentPublicInstance };
|
|
6
6
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { TemplateRenderer } from "../template.mjs";
|
|
2
2
|
//#region src/runtime/component/types.d.ts
|
|
3
|
-
type DataRecord = Record<string, any>;
|
|
4
|
-
interface PropertyOption {
|
|
3
|
+
export type DataRecord = Record<string, any>;
|
|
4
|
+
export interface PropertyOption {
|
|
5
5
|
type?: StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
6
6
|
optionalTypes?: Array<StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor>;
|
|
7
7
|
value?: any;
|
|
8
8
|
observer?: (this: ComponentPublicInstance, newValue: any, oldValue: any) => void;
|
|
9
9
|
}
|
|
10
|
-
type PropertyDeclaration = PropertyOption | StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
11
|
-
interface LifeTimeHooks {
|
|
10
|
+
export type PropertyDeclaration = PropertyOption | StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor | null;
|
|
11
|
+
export interface LifeTimeHooks {
|
|
12
12
|
created?: (this: ComponentPublicInstance) => void;
|
|
13
13
|
attached?: (this: ComponentPublicInstance) => void;
|
|
14
14
|
ready?: (this: ComponentPublicInstance) => void;
|
|
15
15
|
detached?: (this: ComponentPublicInstance) => void;
|
|
16
16
|
}
|
|
17
|
-
interface PageLifeTimeHooks {
|
|
17
|
+
export interface PageLifeTimeHooks {
|
|
18
18
|
show?: (this: ComponentPublicInstance) => void;
|
|
19
19
|
hide?: (this: ComponentPublicInstance) => void;
|
|
20
20
|
resize?: (this: ComponentPublicInstance) => void;
|
|
21
21
|
}
|
|
22
|
-
type RelationType = 'parent' | 'child' | 'ancestor' | 'descendant';
|
|
23
|
-
interface RelationOption {
|
|
22
|
+
export type RelationType = 'parent' | 'child' | 'ancestor' | 'descendant';
|
|
23
|
+
export interface RelationOption {
|
|
24
24
|
type: RelationType;
|
|
25
25
|
linked?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
26
26
|
linkChanged?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
27
27
|
unlinked?: (this: ComponentPublicInstance, target: ComponentPublicInstance) => void;
|
|
28
28
|
}
|
|
29
|
-
interface ComponentBehaviorOptions {
|
|
29
|
+
export interface ComponentBehaviorOptions {
|
|
30
30
|
addGlobalClass?: boolean;
|
|
31
31
|
styleIsolation?: 'isolated' | 'apply-shared' | 'shared';
|
|
32
32
|
virtualHost?: boolean;
|
|
33
33
|
[key: string]: unknown;
|
|
34
34
|
}
|
|
35
|
-
interface ComponentOptions {
|
|
35
|
+
export interface ComponentOptions {
|
|
36
36
|
properties?: Record<string, PropertyDeclaration>;
|
|
37
37
|
data?: DataRecord | (() => DataRecord);
|
|
38
38
|
methods?: Record<string, (this: ComponentPublicInstance, event: any) => any>;
|
|
@@ -43,19 +43,19 @@ interface ComponentOptions {
|
|
|
43
43
|
behaviors?: ComponentOptions[];
|
|
44
44
|
options?: ComponentBehaviorOptions;
|
|
45
45
|
}
|
|
46
|
-
interface DefineComponentOptions {
|
|
46
|
+
export interface DefineComponentOptions {
|
|
47
47
|
id?: string;
|
|
48
48
|
template: TemplateRenderer;
|
|
49
49
|
style?: string;
|
|
50
50
|
component?: ComponentOptions;
|
|
51
51
|
observerInit?: boolean;
|
|
52
52
|
}
|
|
53
|
-
interface TriggerEventOptions {
|
|
53
|
+
export interface TriggerEventOptions {
|
|
54
54
|
bubbles?: boolean;
|
|
55
55
|
composed?: boolean;
|
|
56
56
|
capturePhase?: boolean;
|
|
57
57
|
}
|
|
58
|
-
interface ComponentPublicInstance extends HTMLElement {
|
|
58
|
+
export interface ComponentPublicInstance extends HTMLElement {
|
|
59
59
|
readonly data: DataRecord;
|
|
60
60
|
readonly properties: DataRecord;
|
|
61
61
|
setData: (patch: DataRecord, callback?: () => void) => void | Promise<void>;
|
|
@@ -70,9 +70,8 @@ interface ComponentPublicInstance extends HTMLElement {
|
|
|
70
70
|
selectAllComponents: (selector: string) => ComponentPublicInstance[];
|
|
71
71
|
getRelationNodes: (relationPath: string) => ComponentPublicInstance[];
|
|
72
72
|
}
|
|
73
|
-
type ComponentConstructor = CustomElementConstructor & {
|
|
73
|
+
export type ComponentConstructor = CustomElementConstructor & {
|
|
74
74
|
__weappUpdate?: (options: DefineComponentOptions) => void;
|
|
75
75
|
};
|
|
76
76
|
//#endregion
|
|
77
|
-
export { ComponentBehaviorOptions, ComponentConstructor, ComponentOptions, ComponentPublicInstance, DataRecord, DefineComponentOptions, LifeTimeHooks, PageLifeTimeHooks, PropertyDeclaration, PropertyOption, RelationOption, RelationType, TriggerEventOptions };
|
|
78
77
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AsyncDirective, ElementPart, PartInfo } from "lit/async-directive.js";
|
|
2
|
+
//#region src/runtime/eventBinding.d.ts
|
|
3
|
+
interface RuntimeEventFlags {
|
|
4
|
+
capture?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare class RuntimeEventBindingDirective extends AsyncDirective {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(partInfo: PartInfo);
|
|
9
|
+
render(_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags): symbol;
|
|
10
|
+
update(part: ElementPart, [eventName, listener, flags]: Parameters<this['render']>): symbol;
|
|
11
|
+
protected disconnected(): void;
|
|
12
|
+
protected reconnected(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const bindRuntimeEvent: (_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags | undefined) => import("lit/async-directive.js").DirectiveResult<typeof RuntimeEventBindingDirective>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=eventBinding.d.mts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { nothing } from "lit";
|
|
2
|
+
import { AsyncDirective, PartType, directive } from "lit/async-directive.js";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/eventBinding.ts
|
|
5
|
+
var RuntimeEventBindingDirective = class extends AsyncDirective {
|
|
6
|
+
#capture = false;
|
|
7
|
+
#element;
|
|
8
|
+
#eventName;
|
|
9
|
+
#listener;
|
|
10
|
+
#listening = false;
|
|
11
|
+
constructor(partInfo) {
|
|
12
|
+
super(partInfo);
|
|
13
|
+
if (partInfo.type !== PartType.ELEMENT) throw new TypeError("Runtime event bindings must be used in an element expression.");
|
|
14
|
+
}
|
|
15
|
+
render(_eventName, _listener, _flags) {
|
|
16
|
+
return nothing;
|
|
17
|
+
}
|
|
18
|
+
update(part, [eventName, listener, flags]) {
|
|
19
|
+
const capture = Boolean(flags?.capture);
|
|
20
|
+
if (part.element !== this.#element || eventName !== this.#eventName || listener !== this.#listener || capture !== this.#capture) {
|
|
21
|
+
this.#removeListener();
|
|
22
|
+
this.#element = part.element;
|
|
23
|
+
this.#eventName = eventName;
|
|
24
|
+
this.#listener = listener;
|
|
25
|
+
this.#capture = capture;
|
|
26
|
+
this.#addListener();
|
|
27
|
+
}
|
|
28
|
+
return nothing;
|
|
29
|
+
}
|
|
30
|
+
disconnected() {
|
|
31
|
+
this.#removeListener();
|
|
32
|
+
}
|
|
33
|
+
reconnected() {
|
|
34
|
+
this.#addListener();
|
|
35
|
+
}
|
|
36
|
+
#addListener() {
|
|
37
|
+
if (!this.isConnected || this.#listening || !this.#element || !this.#eventName || !this.#listener) return;
|
|
38
|
+
this.#element.addEventListener(this.#eventName, this.#listener, this.#capture);
|
|
39
|
+
this.#listening = true;
|
|
40
|
+
}
|
|
41
|
+
#removeListener() {
|
|
42
|
+
if (!this.#listening || !this.#element || !this.#eventName || !this.#listener) return;
|
|
43
|
+
this.#element.removeEventListener(this.#eventName, this.#listener, this.#capture);
|
|
44
|
+
this.#listening = false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const bindRuntimeEvent = directive(RuntimeEventBindingDirective);
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { bindRuntimeEvent };
|
|
51
|
+
//# sourceMappingURL=eventBinding.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventBinding.mjs","names":[],"sources":["../../src/runtime/eventBinding.ts"],"sourcesContent":["import type { ElementPart, PartInfo } from 'lit/async-directive.js'\nimport { nothing } from 'lit'\nimport { AsyncDirective, directive, PartType } from 'lit/async-directive.js'\n\ninterface RuntimeEventFlags {\n capture?: boolean\n}\n\nclass RuntimeEventBindingDirective extends AsyncDirective {\n #capture = false\n #element?: Element\n #eventName?: string\n #listener?: EventListener\n #listening = false\n\n constructor(partInfo: PartInfo) {\n super(partInfo)\n if (partInfo.type !== PartType.ELEMENT) {\n throw new TypeError('Runtime event bindings must be used in an element expression.')\n }\n }\n\n render(_eventName: string, _listener: EventListener, _flags?: RuntimeEventFlags) {\n return nothing\n }\n\n update(\n part: ElementPart,\n [eventName, listener, flags]: Parameters<this['render']>,\n ) {\n const capture = Boolean(flags?.capture)\n if (\n part.element !== this.#element\n || eventName !== this.#eventName\n || listener !== this.#listener\n || capture !== this.#capture\n ) {\n this.#removeListener()\n this.#element = part.element\n this.#eventName = eventName\n this.#listener = listener\n this.#capture = capture\n this.#addListener()\n }\n return nothing\n }\n\n protected disconnected() {\n this.#removeListener()\n }\n\n protected reconnected() {\n this.#addListener()\n }\n\n #addListener() {\n if (!this.isConnected || this.#listening || !this.#element || !this.#eventName || !this.#listener) {\n return\n }\n this.#element.addEventListener(this.#eventName, this.#listener, this.#capture)\n this.#listening = true\n }\n\n #removeListener() {\n if (!this.#listening || !this.#element || !this.#eventName || !this.#listener) {\n return\n }\n this.#element.removeEventListener(this.#eventName, this.#listener, this.#capture)\n this.#listening = false\n }\n}\n\nexport const bindRuntimeEvent = directive(RuntimeEventBindingDirective)\n"],"mappings":";;;;AAQA,IAAM,+BAAN,cAA2C,eAAe;CACxD,WAAW;CACX;CACA;CACA;CACA,aAAa;CAEb,YAAY,UAAoB;EAC9B,MAAM,QAAQ;EACd,IAAI,SAAS,SAAS,SAAS,SAC7B,MAAM,IAAI,UAAU,+DAA+D;CAEvF;CAEA,OAAO,YAAoB,WAA0B,QAA4B;EAC/E,OAAO;CACT;CAEA,OACE,MACA,CAAC,WAAW,UAAU,QACtB;EACA,MAAM,UAAU,QAAQ,OAAO,OAAO;EACtC,IACE,KAAK,YAAY,KAAK,YACnB,cAAc,KAAK,cACnB,aAAa,KAAK,aAClB,YAAY,KAAK,UACpB;GACA,KAAK,gBAAgB;GACrB,KAAK,WAAW,KAAK;GACrB,KAAK,aAAa;GAClB,KAAK,YAAY;GACjB,KAAK,WAAW;GAChB,KAAK,aAAa;EACpB;EACA,OAAO;CACT;CAEA,AAAU,eAAe;EACvB,KAAK,gBAAgB;CACvB;CAEA,AAAU,cAAc;EACtB,KAAK,aAAa;CACpB;CAEA,eAAe;EACb,IAAI,CAAC,KAAK,eAAe,KAAK,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,cAAc,CAAC,KAAK,WACtF;EAEF,KAAK,SAAS,iBAAiB,KAAK,YAAY,KAAK,WAAW,KAAK,QAAQ;EAC7E,KAAK,aAAa;CACpB;CAEA,kBAAkB;EAChB,IAAI,CAAC,KAAK,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,cAAc,CAAC,KAAK,WAClE;EAEF,KAAK,SAAS,oBAAoB,KAAK,YAAY,KAAK,WAAW,KAAK,QAAQ;EAChF,KAAK,aAAa;CACpB;AACF;AAEA,MAAa,mBAAmB,UAAU,4BAA4B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//#region src/runtime/execution.d.ts
|
|
2
|
-
type RuntimeExecutionMode = 'compat' | 'safe' | 'strict';
|
|
3
|
-
declare function getRuntimeExecutionMode(): RuntimeExecutionMode;
|
|
4
|
-
declare function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void;
|
|
2
|
+
export type RuntimeExecutionMode = 'compat' | 'safe' | 'strict';
|
|
3
|
+
export declare function getRuntimeExecutionMode(): RuntimeExecutionMode;
|
|
4
|
+
export declare function setRuntimeExecutionMode(mode?: RuntimeExecutionMode | string): void;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { RuntimeExecutionMode, getRuntimeExecutionMode, setRuntimeExecutionMode };
|
|
7
6
|
//# sourceMappingURL=execution.d.mts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage } from "./types.mjs";
|
|
2
2
|
//#region src/runtime/host/index.d.ts
|
|
3
|
-
declare function getWebRuntimeHost(): Readonly<WebRuntimeHost>;
|
|
4
|
-
declare function setWebRuntimeHost(host?: WebRuntimeHost): void;
|
|
5
|
-
declare function resetWebRuntimeHost(): void;
|
|
6
|
-
declare function getRuntimeFetch(): ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined;
|
|
7
|
-
declare function getRuntimeStorage(): WebRuntimeStorage | undefined;
|
|
8
|
-
declare function getRuntimeClipboard(): WebRuntimeClipboard | undefined;
|
|
9
|
-
declare function getRuntimeDialogs(): WebRuntimeDialogs;
|
|
10
|
-
declare function openRuntimeUrl(url?: string, target?: string, features?: string): unknown;
|
|
3
|
+
export declare function getWebRuntimeHost(): Readonly<WebRuntimeHost>;
|
|
4
|
+
export declare function setWebRuntimeHost(host?: WebRuntimeHost): void;
|
|
5
|
+
export declare function resetWebRuntimeHost(): void;
|
|
6
|
+
export declare function getRuntimeFetch(): ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined;
|
|
7
|
+
export declare function getRuntimeStorage(): WebRuntimeStorage | undefined;
|
|
8
|
+
export declare function getRuntimeClipboard(): WebRuntimeClipboard | undefined;
|
|
9
|
+
export declare function getRuntimeDialogs(): WebRuntimeDialogs;
|
|
10
|
+
export declare function openRuntimeUrl(url?: string, target?: string, features?: string): unknown;
|
|
11
11
|
//#endregion
|
|
12
|
-
export {
|
|
12
|
+
export type { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage };
|
|
13
13
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/runtime/host/types.d.ts
|
|
2
|
-
interface WebRuntimeStorage {
|
|
2
|
+
export interface WebRuntimeStorage {
|
|
3
3
|
readonly length: number;
|
|
4
4
|
clear: () => void;
|
|
5
5
|
getItem: (key: string) => string | null;
|
|
@@ -7,16 +7,16 @@ interface WebRuntimeStorage {
|
|
|
7
7
|
removeItem: (key: string) => void;
|
|
8
8
|
setItem: (key: string, value: string) => void;
|
|
9
9
|
}
|
|
10
|
-
interface WebRuntimeClipboard {
|
|
10
|
+
export interface WebRuntimeClipboard {
|
|
11
11
|
readText: () => string | Promise<string>;
|
|
12
12
|
writeText: (value: string) => void | Promise<void>;
|
|
13
13
|
}
|
|
14
|
-
interface WebRuntimeDialogs {
|
|
14
|
+
export interface WebRuntimeDialogs {
|
|
15
15
|
alert?: (message?: string) => void;
|
|
16
16
|
confirm?: (message?: string) => boolean;
|
|
17
17
|
prompt?: (message?: string, defaultValue?: string) => string | null;
|
|
18
18
|
}
|
|
19
|
-
interface WebRuntimeHost {
|
|
19
|
+
export interface WebRuntimeHost {
|
|
20
20
|
clipboard?: WebRuntimeClipboard;
|
|
21
21
|
dialogs?: WebRuntimeDialogs;
|
|
22
22
|
fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
@@ -24,5 +24,4 @@ interface WebRuntimeHost {
|
|
|
24
24
|
storage?: WebRuntimeStorage;
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
export { WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage };
|
|
28
27
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -3,7 +3,6 @@ type HostGlobalsTarget = Record<PropertyKey, any>;
|
|
|
3
3
|
/**
|
|
4
4
|
* 安装第三方库在模块求值阶段可能读取的小程序宿主全局。
|
|
5
5
|
*/
|
|
6
|
-
declare function installWebHostGlobals(target?: HostGlobalsTarget): void;
|
|
6
|
+
export declare function installWebHostGlobals(target?: HostGlobalsTarget): void;
|
|
7
7
|
//#endregion
|
|
8
|
-
export { installWebHostGlobals };
|
|
9
8
|
//# sourceMappingURL=hostGlobals.d.mts.map
|