@weapp-vite/web 1.3.18 → 1.3.19
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/compile.mjs.map +1 -1
- package/dist/compiler/wxml/interpolation.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/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/path.mjs.map +1 -1
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/scanConfig.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/component/behavior.mjs.map +1 -1
- package/dist/runtime/component/state.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/polyfill/auth.mjs.map +1 -1
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.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/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/picker.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/network/request.mjs.map +1 -1
- package/dist/runtime/polyfill/network/status.mjs.map +1 -1
- package/dist/runtime/polyfill/platformRuntime.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/runtimeOps.mjs.map +1 -1
- package/dist/runtime/polyfill/storage.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/videoContext.mjs.map +1 -1
- package/dist/runtime/renderContext.mjs.map +1 -1
- package/dist/shared/slugify.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/runtime/renderContext.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './component'\nimport type { TemplateScope } from './template'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from './execution'\nimport { emitRuntimeWarning } from './warning'\n\nexport interface RenderContext {\n instance: ComponentPublicInstance\n eval: (expression: string, scope: TemplateScope, wxs?: Record<string, any>) => any\n createScope: (parent: TemplateScope, locals?: Record<string, any>) => TemplateScope\n mergeScope: (parent: TemplateScope, data?: any) => TemplateScope\n normalizeList: (value: any) => any[]\n key: (rawKey: string, item: any, index: number, scope: TemplateScope, wxs?: Record<string, any>) => any\n renderTemplate: (templates: Record<string, any>, name: any, scope: TemplateScope, ctx: RenderContext) => any\n event: (eventName: string, handlerName: any, scope: TemplateScope, wxs?: Record<string, any>, flags?: { catch?: boolean, capture?: boolean }) => (event: Event) => void\n createWxsModule: (code: string, id: string, requireMap?: Record<string, any>) => Record<string, any>\n}\n\nconst expressionCache = new Map<string, (scope: TemplateScope) => any>()\nconst MUSTACHE_PREFIX_RE = /^\\{\\{\\s*/\nconst MUSTACHE_SUFFIX_RE = /\\s*\\}\\}$/\nconst SIMPLE_KEY_PATH_RE = /[.[()]/\n\nfunction createScope(initial?: TemplateScope): TemplateScope {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nfunction createChildScope(parent: TemplateScope, locals?: Record<string, any>): TemplateScope {\n return Object.assign(Object.create(parent), locals ?? {})\n}\n\nfunction evaluateExpression(expression: string, scope: TemplateScope): any {\n if (!expression) {\n return undefined\n }\n const trimmed = expression.trim()\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: TemplateScope) => 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-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-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nfunction 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\nfunction normalizeKey(rawKey: string, item: any, index: number, scope: TemplateScope): any {\n const key = rawKey?.trim()\n if (!key) {\n if (item != null && (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean')) {\n return item\n }\n return index\n }\n if (key === '*this') {\n return item\n }\n if (key.includes('{{') && key.includes('}}')) {\n const expr = key.replace(MUSTACHE_PREFIX_RE, '').replace(MUSTACHE_SUFFIX_RE, '')\n return evaluateExpression(expr, scope)\n }\n if (!SIMPLE_KEY_PATH_RE.test(key) && item && typeof item === 'object' && key in item) {\n return (item as Record<string, any>)[key]\n }\n return evaluateExpression(key, scope)\n}\n\nfunction createEventHandler(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n eventName: string,\n handlerRef: string | ((event: any) => any),\n flags?: { catch?: boolean },\n) {\n const handler = typeof handlerRef === 'function'\n ? handlerRef\n : methods[handlerRef] ?? (instance as Record<string, any>)[handlerRef]\n if (typeof handler !== 'function') {\n return () => {}\n }\n return (nativeEvent: Event) => {\n if (flags?.catch) {\n nativeEvent.stopPropagation()\n }\n const target = nativeEvent.target as HTMLElement | null\n const currentTarget = nativeEvent.currentTarget as HTMLElement | null\n const dataset = currentTarget?.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: target?.dataset ?? dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }\n}\n\nfunction createWxsModule(code: string, id: string, requireMap?: Record<string, any>) {\n const module = { exports: {} as Record<string, any> }\n const exports = module.exports\n const getRegExp = (pattern: string, flags?: string) => new RegExp(pattern, flags)\n const getDate = (value?: string | number | Date) => (value == null ? new Date() : new Date(value))\n const require = (request: string) => requireMap?.[request]\n try {\n // eslint-disable-next-line no-new-func -- run in isolated module scope\n const runner = new Function('module', 'exports', 'require', 'getRegExp', 'getDate', code)\n runner(module, exports, require, getRegExp, getDate)\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-wxs-runtime:${id}`,\n `[@weapp-vite/web] safe 模式下忽略 WXS 执行错误: ${id} ${reason}`,\n )\n return {}\n }\n throw new Error(`[@weapp-vite/web] WXS 执行失败: ${id} ${reason}`)\n }\n return module.exports\n}\n\nexport function createRenderContext(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n): RenderContext {\n const warnMissingTemplate = (name: string) => {\n emitRuntimeWarning(`[@weapp-vite/web] 未找到模板: ${name}`, {\n key: `template-missing:${name}`,\n context: 'runtime:template',\n })\n }\n\n return {\n instance,\n eval: (expression, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return evaluateExpression(expression, renderScope)\n },\n createScope: (parent, locals) => createChildScope(parent, locals),\n mergeScope: (parent, data) => {\n const baseScope = parent ?? createScope()\n if (!data || typeof data !== 'object') {\n return baseScope\n }\n return createChildScope(baseScope, data as Record<string, any>)\n },\n normalizeList,\n key: (rawKey, item, index, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return normalizeKey(rawKey, item, index, renderScope)\n },\n renderTemplate: (templates, name, scope, ctx) => {\n const resolvedName = typeof name === 'string' ? name : String(name)\n const template = templates?.[resolvedName]\n if (typeof template !== 'function') {\n warnMissingTemplate(resolvedName)\n return ''\n }\n return template(scope, ctx)\n },\n event: (eventName, handlerName, _scope, _wxs, flags) => {\n if (typeof handlerName === 'function') {\n return createEventHandler(instance, methods, eventName, handlerName, flags)\n }\n const resolvedHandler = String(handlerName ?? '')\n return createEventHandler(instance, methods, eventName, resolvedHandler, flags)\n },\n createWxsModule,\n }\n}\n\nexport { createChildScope, createScope, evaluateExpression }\n"],"mappings":";;;;AAiBA,MAAM,kCAAkB,IAAI,KAA4C;AACxE,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAE3B,SAAS,YAAY,SAAwC;AAC3D,QAAO,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,WAAW,EAAE,CAAC;;AAG1D,SAAS,iBAAiB,QAAuB,QAA6C;AAC5F,QAAO,OAAO,OAAO,OAAO,OAAO,OAAO,EAAE,UAAU,EAAE,CAAC;;AAG3D,SAAS,mBAAmB,YAAoB,OAA2B;AACzE,KAAI,CAAC,WACH;CAEF,MAAM,UAAU,WAAW,MAAM;AACjC,KAAI,CAAC,QACH;CAEF,IAAI,YAAY,gBAAgB,IAAI,QAAQ;AAC5C,KAAI,CAAC,WAAW;AACd,MAAI;AAEF,eAAY,IAAI,SAAS,SAAS,wBAAwB,QAAQ,MAAM;WAEnE,OAAO;GACZ,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAErE,OADa,yBAAyB,KACzB,QAAQ;AACnB,6BACE,yBAAyB,WACzB,wCAAwC,QAAQ,KAAK,SACtD;AACD,sBAAkB;SAGlB,OAAM,IAAI,YAAY,8BAA8B,QAAQ,KAAK,SAAS;;AAG9E,MAAI,UACF,iBAAgB,IAAI,SAAS,UAAU;;AAG3C,KAAI;AACF,SAAO,YAAY,MAAM;UAEpB,OAAO;EACZ,MAAM,OAAO,yBAAyB;AACtC,MAAI,SAAS,UAAU;GACrB,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACrE,SAAM,IAAI,MAAM,wCAAwC,QAAQ,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AS;GAC5B,MAAM,YAAY,UAAU,aAAa;AACzC,OAAI,CAAC,QAAQ,OAAO,SAAS,SAC3B,QAAO;AAET,UAAO,iBAAiB,WAAW,KAA4B;;EAEjE;EACA,MAAM,QAAQ,MAAM,OAAO,OAAO,QAAQ;GACxC,MAAM,YAAY,SAAS,aAAa;AAExC,UAAO,aAAa,QAAQ,MAAM,OADd,MAAM,iBAAiB,WAAW,IAAI,GAAG,UACR;;EAEvD,iBAAiB,WAAW,MAAM,OAAO,QAAQ;GAC/C,MAAM,eAAe,OAAO,SAAS,WAAW,OAAO,OAAO,KAAK;GACnE,MAAM,WAAW,YAAY;AAC7B,OAAI,OAAO,aAAa,YAAY;AAClC,wBAAoB,aAAa;AACjC,WAAO;;AAET,UAAO,SAAS,OAAO,IAAI;;EAE7B,QAAQ,WAAW,aAAa,QAAQ,MAAM,UAAU;AACtD,OAAI,OAAO,gBAAgB,WACzB,QAAO,mBAAmB,UAAU,SAAS,WAAW,aAAa,MAAM;AAG7E,UAAO,mBAAmB,UAAU,SAAS,WADrB,OAAO,eAAe,GAAG,EACwB,MAAM;;EAEjF;EACD"}
|
|
1
|
+
{"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/runtime/renderContext.ts"],"sourcesContent":["import type { ComponentPublicInstance } from './component'\nimport type { TemplateScope } from './template'\nimport { getRuntimeExecutionMode, warnRuntimeExecutionOnce } from './execution'\nimport { emitRuntimeWarning } from './warning'\n\nexport interface RenderContext {\n instance: ComponentPublicInstance\n eval: (expression: string, scope: TemplateScope, wxs?: Record<string, any>) => any\n createScope: (parent: TemplateScope, locals?: Record<string, any>) => TemplateScope\n mergeScope: (parent: TemplateScope, data?: any) => TemplateScope\n normalizeList: (value: any) => any[]\n key: (rawKey: string, item: any, index: number, scope: TemplateScope, wxs?: Record<string, any>) => any\n renderTemplate: (templates: Record<string, any>, name: any, scope: TemplateScope, ctx: RenderContext) => any\n event: (eventName: string, handlerName: any, scope: TemplateScope, wxs?: Record<string, any>, flags?: { catch?: boolean, capture?: boolean }) => (event: Event) => void\n createWxsModule: (code: string, id: string, requireMap?: Record<string, any>) => Record<string, any>\n}\n\nconst expressionCache = new Map<string, (scope: TemplateScope) => any>()\nconst MUSTACHE_PREFIX_RE = /^\\{\\{\\s*/\nconst MUSTACHE_SUFFIX_RE = /\\s*\\}\\}$/\nconst SIMPLE_KEY_PATH_RE = /[.[()]/\n\nfunction createScope(initial?: TemplateScope): TemplateScope {\n return Object.assign(Object.create(null), initial ?? {})\n}\n\nfunction createChildScope(parent: TemplateScope, locals?: Record<string, any>): TemplateScope {\n return Object.assign(Object.create(parent), locals ?? {})\n}\n\nfunction evaluateExpression(expression: string, scope: TemplateScope): any {\n if (!expression) {\n return undefined\n }\n const trimmed = expression.trim()\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: TemplateScope) => 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-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-expression-runtime:${trimmed}`,\n `[@weapp-vite/web] safe 模式下忽略表达式执行错误 \"${trimmed}\": ${reason}`,\n )\n }\n return undefined\n }\n}\n\nfunction 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\nfunction normalizeKey(rawKey: string, item: any, index: number, scope: TemplateScope): any {\n const key = rawKey?.trim()\n if (!key) {\n if (item != null && (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean')) {\n return item\n }\n return index\n }\n if (key === '*this') {\n return item\n }\n if (key.includes('{{') && key.includes('}}')) {\n const expr = key.replace(MUSTACHE_PREFIX_RE, '').replace(MUSTACHE_SUFFIX_RE, '')\n return evaluateExpression(expr, scope)\n }\n if (!SIMPLE_KEY_PATH_RE.test(key) && item && typeof item === 'object' && key in item) {\n return (item as Record<string, any>)[key]\n }\n return evaluateExpression(key, scope)\n}\n\nfunction createEventHandler(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n eventName: string,\n handlerRef: string | ((event: any) => any),\n flags?: { catch?: boolean },\n) {\n const handler = typeof handlerRef === 'function'\n ? handlerRef\n : methods[handlerRef] ?? (instance as Record<string, any>)[handlerRef]\n if (typeof handler !== 'function') {\n return () => {}\n }\n return (nativeEvent: Event) => {\n if (flags?.catch) {\n nativeEvent.stopPropagation()\n }\n const target = nativeEvent.target as HTMLElement | null\n const currentTarget = nativeEvent.currentTarget as HTMLElement | null\n const dataset = currentTarget?.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: target?.dataset ?? dataset,\n },\n currentTarget: {\n dataset,\n },\n originalEvent: nativeEvent,\n }\n handler.call(instance, syntheticEvent)\n }\n}\n\nfunction createWxsModule(code: string, id: string, requireMap?: Record<string, any>) {\n const module = { exports: {} as Record<string, any> }\n const exports = module.exports\n const getRegExp = (pattern: string, flags?: string) => new RegExp(pattern, flags)\n const getDate = (value?: string | number | Date) => (value == null ? new Date() : new Date(value))\n const require = (request: string) => requireMap?.[request]\n try {\n // eslint-disable-next-line no-new-func -- run in isolated module scope\n const runner = new Function('module', 'exports', 'require', 'getRegExp', 'getDate', code)\n runner(module, exports, require, getRegExp, getDate)\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-wxs-runtime:${id}`,\n `[@weapp-vite/web] safe 模式下忽略 WXS 执行错误: ${id} ${reason}`,\n )\n return {}\n }\n throw new Error(`[@weapp-vite/web] WXS 执行失败: ${id} ${reason}`)\n }\n return module.exports\n}\n\nexport function createRenderContext(\n instance: ComponentPublicInstance,\n methods: Record<string, (event: any) => any>,\n): RenderContext {\n const warnMissingTemplate = (name: string) => {\n emitRuntimeWarning(`[@weapp-vite/web] 未找到模板: ${name}`, {\n key: `template-missing:${name}`,\n context: 'runtime:template',\n })\n }\n\n return {\n instance,\n eval: (expression, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return evaluateExpression(expression, renderScope)\n },\n createScope: (parent, locals) => createChildScope(parent, locals),\n mergeScope: (parent, data) => {\n const baseScope = parent ?? createScope()\n if (!data || typeof data !== 'object') {\n return baseScope\n }\n return createChildScope(baseScope, data as Record<string, any>)\n },\n normalizeList,\n key: (rawKey, item, index, scope, wxs) => {\n const baseScope = scope ?? createScope()\n const renderScope = wxs ? createChildScope(baseScope, wxs) : baseScope\n return normalizeKey(rawKey, item, index, renderScope)\n },\n renderTemplate: (templates, name, scope, ctx) => {\n const resolvedName = typeof name === 'string' ? name : String(name)\n const template = templates?.[resolvedName]\n if (typeof template !== 'function') {\n warnMissingTemplate(resolvedName)\n return ''\n }\n return template(scope, ctx)\n },\n event: (eventName, handlerName, _scope, _wxs, flags) => {\n if (typeof handlerName === 'function') {\n return createEventHandler(instance, methods, eventName, handlerName, flags)\n }\n const resolvedHandler = String(handlerName ?? '')\n return createEventHandler(instance, methods, eventName, resolvedHandler, flags)\n },\n createWxsModule,\n }\n}\n\nexport { createChildScope, createScope, evaluateExpression }\n"],"mappings":";;;;AAiBA,MAAM,kCAAkB,IAAI,KAA4C;AACxE,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAE3B,SAAS,YAAY,SAAwC;AAC3D,QAAO,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,WAAW,EAAE,CAAC;;AAG1D,SAAS,iBAAiB,QAAuB,QAA6C;AAC5F,QAAO,OAAO,OAAO,OAAO,OAAO,OAAO,EAAE,UAAU,EAAE,CAAC;;AAG3D,SAAS,mBAAmB,YAAoB,OAA2B;AACzE,KAAI,CAAC,WACH;CAEF,MAAM,UAAU,WAAW,MAAM;AACjC,KAAI,CAAC,QACH;CAEF,IAAI,YAAY,gBAAgB,IAAI,QAAQ;AAC5C,KAAI,CAAC,WAAW;AACd,MAAI;AAEF,eAAY,IAAI,SAAS,SAAS,wBAAwB,QAAQ,MAAM;WAEnE,OAAO;GACZ,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAErE,OADa,yBACL,KAAK,QAAQ;AACnB,6BACE,yBAAyB,WACzB,wCAAwC,QAAQ,KAAK,SACtD;AACD,sBAAkB;SAGlB,OAAM,IAAI,YAAY,8BAA8B,QAAQ,KAAK,SAAS;;AAG9E,MAAI,UACF,iBAAgB,IAAI,SAAS,UAAU;;AAG3C,KAAI;AACF,SAAO,YAAY,MAAM;UAEpB,OAAO;EACZ,MAAM,OAAO,yBAAyB;AACtC,MAAI,SAAS,UAAU;GACrB,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACrE,SAAM,IAAI,MAAM,wCAAwC,Q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AAS;GAC5B,MAAM,YAAY,UAAU,aAAa;AACzC,OAAI,CAAC,QAAQ,OAAO,SAAS,SAC3B,QAAO;AAET,UAAO,iBAAiB,WAAW,KAA4B;;EAEjE;EACA,MAAM,QAAQ,MAAM,OAAO,OAAO,QAAQ;GACxC,MAAM,YAAY,SAAS,aAAa;AAExC,UAAO,aAAa,QAAQ,MAAM,OADd,MAAM,iBAAiB,WAAW,IAAI,GAAG,UACR;;EAEvD,iBAAiB,WAAW,MAAM,OAAO,QAAQ;GAC/C,MAAM,eAAe,OAAO,SAAS,WAAW,OAAO,OAAO,KAAK;GACnE,MAAM,WAAW,YAAY;AAC7B,OAAI,OAAO,aAAa,YAAY;AAClC,wBAAoB,aAAa;AACjC,WAAO;;AAET,UAAO,SAAS,OAAO,IAAI;;EAE7B,QAAQ,WAAW,aAAa,QAAQ,MAAM,UAAU;AACtD,OAAI,OAAO,gBAAgB,WACzB,QAAO,mBAAmB,UAAU,SAAS,WAAW,aAAa,MAAM;AAG7E,UAAO,mBAAmB,UAAU,SAAS,WADrB,OAAO,eAAe,GACyB,EAAE,MAAM;;EAEjF;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slugify.mjs","names":[],"sources":["../../src/shared/slugify.ts"],"sourcesContent":["export function slugify(id: string, prefix: string) {\n const normalized = id.replace(/[^a-z0-9]+/gi, '-').replace(/^-+|-+$/g, '').toLowerCase()\n return `${prefix}-${normalized || 'index'}`\n}\n"],"mappings":";AAAA,SAAgB,QAAQ,IAAY,QAAgB;AAElD,QAAO,GAAG,OAAO,GADE,GAAG,QAAQ,gBAAgB,IAAI,CAAC,QAAQ,YAAY,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"slugify.mjs","names":[],"sources":["../../src/shared/slugify.ts"],"sourcesContent":["export function slugify(id: string, prefix: string) {\n const normalized = id.replace(/[^a-z0-9]+/gi, '-').replace(/^-+|-+$/g, '').toLowerCase()\n return `${prefix}-${normalized || 'index'}`\n}\n"],"mappings":";AAAA,SAAgB,QAAQ,IAAY,QAAgB;AAElD,QAAO,GAAG,OAAO,GADE,GAAG,QAAQ,gBAAgB,IAAI,CAAC,QAAQ,YAAY,GAAG,CAAC,aAC7C,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.19",
|
|
5
5
|
"description": "Experimental web runtime for weapp-vite templates",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"lit": "^3.3.1",
|
|
57
57
|
"magic-string": "^0.30.21",
|
|
58
58
|
"pathe": "^2.0.3",
|
|
59
|
-
"@weapp-core/constants": "^0.1.
|
|
59
|
+
"@weapp-core/constants": "^0.1.2",
|
|
60
60
|
"@weapp-core/shared": "^3.0.4",
|
|
61
|
-
"rolldown-require": "2.0.
|
|
61
|
+
"rolldown-require": "2.0.15"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"dev": "tsdown -w --sourcemap",
|