@weapp-vite/web 1.4.0 → 1.4.1
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/renderer.mjs +4 -1
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +2 -1
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/index.d.mts +1 -6
- package/dist/index.mjs +1 -177
- package/dist/plugin/index.mjs +10 -6
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/path.mjs +2 -1
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/scan.mjs +23 -16
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/vueSfc.mjs +3 -2
- package/dist/plugin/vueSfc.mjs.map +1 -1
- package/dist/runtime/component/relations.mjs +2 -1
- package/dist/runtime/component/relations.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.mjs +6 -3
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
- package/dist/runtime/polyfill/font.mjs +2 -1
- package/dist/runtime/polyfill/font.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +6 -3
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/locationApi.mjs +4 -2
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +2 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/picker.mjs +16 -8
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +3 -2
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +2 -1
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
- package/dist/runtime/polyfill/storageAsync.mjs +4 -2
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +1 -1
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs +2 -1
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/index.mjs.map +0 -1
package/dist/plugin/scan.mjs
CHANGED
|
@@ -79,7 +79,8 @@ async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportT
|
|
|
79
79
|
const getComponentTag = (script) => {
|
|
80
80
|
const cached = state.componentTagMap.get(script);
|
|
81
81
|
if (cached) return cached;
|
|
82
|
-
const
|
|
82
|
+
const id = getStableComponentId(script);
|
|
83
|
+
const tag = slugify(id, "wv-component");
|
|
83
84
|
state.componentTagMap.set(script, tag);
|
|
84
85
|
return tag;
|
|
85
86
|
};
|
|
@@ -158,7 +159,8 @@ async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportT
|
|
|
158
159
|
const template = await resolveTemplateFile(base);
|
|
159
160
|
if (template) state.templatePathSet.add(normalizePath(template));
|
|
160
161
|
const style = await resolveStyleFile(base);
|
|
161
|
-
const
|
|
162
|
+
const pageJsonBasePath = join(srcRoot, `${pageId}.json`);
|
|
163
|
+
const pageJsonPath = await resolveJsonPath(pageJsonBasePath);
|
|
162
164
|
const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : void 0;
|
|
163
165
|
const pageMeta = {
|
|
164
166
|
kind: "page",
|
|
@@ -249,20 +251,24 @@ async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportT
|
|
|
249
251
|
if (template) state.templatePathSet.add(normalizePath(template));
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
|
-
const
|
|
254
|
+
const appJsonBasePath = join(srcRoot, "app.json");
|
|
255
|
+
const appJsonPath = await resolveJsonPath(appJsonBasePath);
|
|
253
256
|
let appJson = appJsonPath ? await (resolveAppConfig ? resolveAppConfig(appJsonPath) : readJsonFile(appJsonPath)) : void 0;
|
|
254
|
-
if (appScript?.endsWith(".vue"))
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
257
|
+
if (appScript?.endsWith(".vue")) {
|
|
258
|
+
const appMeta = state.moduleMeta.get(normalizePath(appScript));
|
|
259
|
+
appJson = {
|
|
260
|
+
...(await compileScannedSfc({
|
|
261
|
+
filename: appScript,
|
|
262
|
+
meta: appMeta,
|
|
263
|
+
srcRoot,
|
|
264
|
+
state,
|
|
265
|
+
resolveId,
|
|
266
|
+
resolveAutoImportTag,
|
|
267
|
+
uniApp
|
|
268
|
+
})).config ?? {},
|
|
269
|
+
...appJson ?? {}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
266
272
|
if (appJson) {
|
|
267
273
|
appComponentTags = await collectComponentTagsFromConfig({
|
|
268
274
|
json: appJson,
|
|
@@ -276,7 +282,8 @@ async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportT
|
|
|
276
282
|
appComponentTags = tags;
|
|
277
283
|
}
|
|
278
284
|
});
|
|
279
|
-
|
|
285
|
+
const windowConfig = isRecord(appJson?.window) ? appJson.window : void 0;
|
|
286
|
+
appNavigationDefaults = pickNavigationConfig(windowConfig);
|
|
280
287
|
const configuredPages = Array.isArray(appJson.pages) ? appJson.pages.filter((page) => typeof page === "string") : [];
|
|
281
288
|
for (const page of configuredPages.length > 0 ? configuredPages : await discoverWebPageIds(srcRoot)) await collectPage(page);
|
|
282
289
|
const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
package/dist/plugin/scan.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.mjs","names":[],"sources":["../../src/plugin/scan.ts"],"sourcesContent":["import type { WebTabBarConfig } from '../shared/tabBar'\nimport type { ComponentEntry, LayoutEntry, ModuleMeta, PageEntry, ResolveWebAutoImportTag, ResolveWebModuleId, ScanState, WarnFn } from './types'\n\nimport { readdir } from 'node:fs/promises'\nimport process from 'node:process'\nimport { dirname, extname, join, posix, relative, resolve } from 'pathe'\nimport { slugify } from '../shared/slugify'\nimport { normalizeWebTabBarConfig } from '../shared/tabBar'\nimport { SCRIPT_EXTS } from './constants'\nimport { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from './files'\nimport { mergeNavigationConfig, pickNavigationConfig } from './navigation'\nimport { isInsideDir, normalizePath, toPosixId } from './path'\nimport { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from './scanConfig'\nimport { compileScannedSfc, discoverWebPageIds } from './scanSfc'\n\ninterface ScanProjectOptions {\n srcRoot: string\n warn?: WarnFn\n state: ScanState\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n resolveAppConfig?: (appConfigPath: string) => Promise<Record<string, unknown> | undefined>\n uniApp?: { include: string[] }\n}\n\nexport function getStableWebComponentId(script: string, srcRoot: string) {\n const normalized = script.replace(/\\\\/g, '/')\n const nodeModulesIndex = normalized.lastIndexOf('/node_modules/')\n const extension = extname(script)\n if (nodeModulesIndex >= 0) {\n const packageRelative = normalized.slice(nodeModulesIndex + '/node_modules/'.length)\n return `__external__/${packageRelative.slice(0, -extension.length)}`\n }\n return toPosixId(relative(srcRoot, script).slice(0, -extension.length))\n}\n\nfunction resolveComponentBase(raw: string, importerDir: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(importerDir, raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return undefined\n}\n\nexport async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportTag, resolveAppConfig, uniApp }: ScanProjectOptions) {\n state.moduleMeta.clear()\n state.pageNavigationMap.clear()\n state.templateComponentMap.clear()\n state.templatePathSet.clear()\n state.componentTagMap.clear()\n state.sfcResults.clear()\n\n let appNavigationDefaults = {}\n let appComponentTags: Record<string, string> = {}\n let appTabBar: WebTabBarConfig | undefined\n\n const pages = new Map<string, PageEntry>()\n const components = new Map<string, ComponentEntry>()\n const layouts = new Map<string, LayoutEntry>()\n\n async function walk(current: string, files: string[]) {\n const entries = await readdir(current, { withFileTypes: true })\n for (const entry of entries) {\n const pathname = join(current, entry.name)\n if (entry.isDirectory()) {\n await walk(pathname, files)\n }\n else {\n files.push(pathname)\n }\n }\n }\n\n const reportWarning = (message: string) => {\n if (warn) {\n warn(message)\n return\n }\n process.emitWarning(message)\n }\n\n const appScript = await resolveScriptFile(join(srcRoot, 'app'))\n if (appScript) {\n const appMeta: ModuleMeta = {\n kind: 'app',\n id: 'app',\n scriptPath: appScript,\n stylePath: await resolveStyleFile(appScript),\n sourceType: appScript.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n state.moduleMeta.set(normalizePath(appScript), appMeta)\n }\n\n const resolveComponentScript = async (raw: string, importerDir: string) => {\n const base = resolveComponentBase(raw, importerDir, srcRoot)\n if (base) {\n const resolved = await resolveScriptFile(base)\n return resolved ? normalizePath(resolved) : undefined\n }\n const importer = join(importerDir, '__weapp_web_using_components__.ts')\n const resolved = await resolveId?.(raw, importer)\n const script = resolved ? await resolveScriptFile(resolved) : undefined\n return script ? normalizePath(script) : undefined\n }\n\n const getStableComponentId = (script: string) => {\n return getStableWebComponentId(script, srcRoot)\n }\n\n const getComponentTag = (script: string) => {\n const cached = state.componentTagMap.get(script)\n if (cached) {\n return cached\n }\n const id = getStableComponentId(script)\n const tag = slugify(id, 'wv-component')\n state.componentTagMap.set(script, tag)\n return tag\n }\n\n const collectComponent = async (componentId: string, importerDir: string) => {\n const script = await resolveComponentScript(componentId, importerDir)\n if (!script) {\n return\n }\n\n const existing = components.get(script)\n if (existing) {\n existing.importId ??= resolveComponentBase(componentId, importerDir, srcRoot)\n ? undefined\n : componentId\n return\n }\n\n const componentIdPosix = getStableComponentId(script)\n const importId = resolveComponentBase(componentId, importerDir, srcRoot)\n ? (isInsideDir(script, srcRoot) ? undefined : componentIdPosix)\n : componentId\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const componentMeta: ModuleMeta = {\n kind: 'component',\n id: componentIdPosix,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: script.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n state.moduleMeta.set(normalizePath(script), componentMeta)\n\n components.set(script, { script, id: componentIdPosix, importId })\n\n const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), '')}.json`\n const sfcConfig = script.endsWith('.vue')\n ? (await compileScannedSfc({ filename: script, meta: componentMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n : undefined\n const componentTags = sfcConfig\n ? await collectComponentTagsFromConfig({\n json: sfcConfig,\n importerDir: dirname(script),\n jsonPath: script,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : await collectComponentTagsFromJson({\n jsonBasePath: componentJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir: nextImporterDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n componentMeta.componentTags = mergeComponentTags(appComponentTags, componentTags)\n\n if (!template) {\n return\n }\n\n const mergedTags = mergeComponentTags(appComponentTags, componentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n return\n }\n state.templateComponentMap.delete(normalizePath(template))\n }\n\n async function collectPage(pageId: string) {\n const base = join(srcRoot, pageId)\n const script = await resolveScriptFile(base)\n if (!script) {\n return\n }\n\n const template = await resolveTemplateFile(base)\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const style = await resolveStyleFile(base)\n const pageJsonBasePath = join(srcRoot, `${pageId}.json`)\n const pageJsonPath = await resolveJsonPath(pageJsonBasePath)\n const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : undefined\n const pageMeta: ModuleMeta = {\n kind: 'page',\n id: toPosixId(pageId),\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: script.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n\n const sfcConfig = script.endsWith('.vue')\n ? (await compileScannedSfc({ filename: script, meta: pageMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n : undefined\n const resolvedNavigationConfig = mergeNavigationConfig(\n appNavigationDefaults,\n sfcConfig ? pickNavigationConfig(sfcConfig) : pageJson ? pickNavigationConfig(pageJson) : {},\n )\n pageMeta.navigationBar = Object.keys(resolvedNavigationConfig).length > 0\n ? resolvedNavigationConfig\n : undefined\n state.moduleMeta.set(normalizePath(script), pageMeta)\n\n pages.set(script, {\n script,\n id: toPosixId(pageId),\n })\n\n const pageComponentTags = sfcConfig\n ? await collectComponentTagsFromConfig({\n json: sfcConfig,\n importerDir: dirname(script),\n jsonPath: script,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : pageJson && pageJsonPath\n ? await collectComponentTagsFromConfig({\n json: pageJson,\n importerDir: dirname(script),\n jsonPath: pageJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : {}\n\n if (template) {\n const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n }\n else {\n state.templateComponentMap.delete(normalizePath(template))\n }\n }\n pageMeta.componentTags = mergeComponentTags(appComponentTags, pageComponentTags)\n\n if (!template) {\n return\n }\n\n state.pageNavigationMap.set(normalizePath(template), resolvedNavigationConfig)\n }\n\n async function collectLayouts() {\n const layoutsRoot = join(srcRoot, 'layouts')\n const files: string[] = []\n try {\n await walk(layoutsRoot, files)\n }\n catch {\n return\n }\n for (const filename of files.sort()) {\n const script = SCRIPT_EXTS.includes(extname(filename)) ? filename : undefined\n if (!script) {\n continue\n }\n const relativePath = relative(layoutsRoot, script).replace(/\\\\/g, '/')\n const segments = relativePath.split('/')\n segments.pop()\n if (segments[segments.length - 1] === 'index') {\n segments.pop()\n }\n const name = segments.join('/')\n if (!name) {\n continue\n }\n const id = `layouts/${name}`\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n const tag = slugify(id, 'wv-component')\n state.moduleMeta.set(normalizePath(script), {\n kind: 'component',\n id,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: 'native',\n })\n layouts.set(script, { script, id, name, tag, template, style })\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n }\n }\n\n const appJsonBasePath = join(srcRoot, 'app.json')\n const appJsonPath = await resolveJsonPath(appJsonBasePath)\n let appJson = appJsonPath\n ? await (resolveAppConfig ? resolveAppConfig(appJsonPath) : readJsonFile(appJsonPath))\n : undefined\n if (appScript?.endsWith('.vue')) {\n const appMeta = state.moduleMeta.get(normalizePath(appScript))!\n const sfcConfig = (await compileScannedSfc({ filename: appScript, meta: appMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n appJson = {\n ...(sfcConfig ?? {}),\n ...(appJson ?? {}),\n }\n }\n if (appJson) {\n appComponentTags = await collectComponentTagsFromConfig({\n json: appJson,\n importerDir: srcRoot,\n jsonPath: appJsonPath ?? appScript!,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved: (tags) => {\n appComponentTags = tags\n },\n })\n\n const windowConfig = isRecord(appJson?.window) ? appJson.window : undefined\n appNavigationDefaults = pickNavigationConfig(windowConfig)\n\n const configuredPages = Array.isArray(appJson.pages)\n ? appJson.pages.filter((page): page is string => typeof page === 'string')\n : []\n for (const page of configuredPages.length > 0 ? configuredPages : await discoverWebPageIds(srcRoot)) {\n await collectPage(page)\n }\n\n const subPackages = Array.isArray(appJson.subPackages)\n ? appJson.subPackages\n : Array.isArray(appJson.subpackages)\n ? appJson.subpackages\n : []\n if (subPackages.length > 0) {\n for (const pkg of subPackages) {\n if (!pkg || typeof pkg !== 'object' || !Array.isArray(pkg.pages)) {\n continue\n }\n const root = typeof pkg.root === 'string' ? pkg.root : ''\n for (const page of pkg.pages) {\n if (typeof page !== 'string') {\n continue\n }\n await collectPage(posix.join(root, page))\n }\n }\n }\n\n appTabBar = normalizeWebTabBarConfig(appJson?.tabBar)\n }\n else {\n for (const page of await discoverWebPageIds(srcRoot)) {\n await collectPage(page)\n }\n }\n\n await collectLayouts()\n\n state.appNavigationDefaults = appNavigationDefaults\n state.appComponentTags = appComponentTags\n state.scanResult = {\n app: appScript,\n pages: Array.from(pages.values()),\n components: Array.from(components.values()),\n layouts: Array.from(layouts.values()),\n tabBar: appTabBar,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,wBAAwB,QAAgB,SAAiB;CACvE,MAAM,aAAa,OAAO,QAAQ,OAAO,GAAG;CAC5C,MAAM,mBAAmB,WAAW,YAAY,gBAAgB;CAChE,MAAM,YAAY,QAAQ,MAAM;CAChC,IAAI,oBAAoB,GAEtB,OAAO,gBADiB,WAAW,MAAM,mBAAmB,EACvB,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,MAAM;CAEnE,OAAO,UAAU,SAAS,SAAS,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,MAAM,CAAC;AACxE;AAEA,SAAS,qBAAqB,KAAa,aAAqB,SAAiB;CAC/E,IAAI,CAAC,KACH;CAEF,IAAI,IAAI,WAAW,GAAG,GACpB,OAAO,QAAQ,aAAa,GAAG;CAEjC,IAAI,IAAI,WAAW,GAAG,G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'../shared/tabBar'\nimport type { ComponentEntry, LayoutEntry, ModuleMeta, PageEntry, ResolveWebAutoImportTag, ResolveWebModuleId, ScanState, WarnFn } from './types'\n\nimport { readdir } from 'node:fs/promises'\nimport process from 'node:process'\nimport { dirname, extname, join, posix, relative, resolve } from 'pathe'\nimport { slugify } from '../shared/slugify'\nimport { normalizeWebTabBarConfig } from '../shared/tabBar'\nimport { SCRIPT_EXTS } from './constants'\nimport { isRecord, readJsonFile, resolveJsonPath, resolveScriptFile, resolveStyleFile, resolveTemplateFile } from './files'\nimport { mergeNavigationConfig, pickNavigationConfig } from './navigation'\nimport { isInsideDir, normalizePath, toPosixId } from './path'\nimport { collectComponentTagsFromConfig, collectComponentTagsFromJson, mergeComponentTags } from './scanConfig'\nimport { compileScannedSfc, discoverWebPageIds } from './scanSfc'\n\ninterface ScanProjectOptions {\n srcRoot: string\n warn?: WarnFn\n state: ScanState\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n resolveAppConfig?: (appConfigPath: string) => Promise<Record<string, unknown> | undefined>\n uniApp?: { include: string[] }\n}\n\nexport function getStableWebComponentId(script: string, srcRoot: string) {\n const normalized = script.replace(/\\\\/g, '/')\n const nodeModulesIndex = normalized.lastIndexOf('/node_modules/')\n const extension = extname(script)\n if (nodeModulesIndex >= 0) {\n const packageRelative = normalized.slice(nodeModulesIndex + '/node_modules/'.length)\n return `__external__/${packageRelative.slice(0, -extension.length)}`\n }\n return toPosixId(relative(srcRoot, script).slice(0, -extension.length))\n}\n\nfunction resolveComponentBase(raw: string, importerDir: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(importerDir, raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return undefined\n}\n\nexport async function scanProject({ srcRoot, warn, state, resolveId, resolveAutoImportTag, resolveAppConfig, uniApp }: ScanProjectOptions) {\n state.moduleMeta.clear()\n state.pageNavigationMap.clear()\n state.templateComponentMap.clear()\n state.templatePathSet.clear()\n state.componentTagMap.clear()\n state.sfcResults.clear()\n\n let appNavigationDefaults = {}\n let appComponentTags: Record<string, string> = {}\n let appTabBar: WebTabBarConfig | undefined\n\n const pages = new Map<string, PageEntry>()\n const components = new Map<string, ComponentEntry>()\n const layouts = new Map<string, LayoutEntry>()\n\n async function walk(current: string, files: string[]) {\n const entries = await readdir(current, { withFileTypes: true })\n for (const entry of entries) {\n const pathname = join(current, entry.name)\n if (entry.isDirectory()) {\n await walk(pathname, files)\n }\n else {\n files.push(pathname)\n }\n }\n }\n\n const reportWarning = (message: string) => {\n if (warn) {\n warn(message)\n return\n }\n process.emitWarning(message)\n }\n\n const appScript = await resolveScriptFile(join(srcRoot, 'app'))\n if (appScript) {\n const appMeta: ModuleMeta = {\n kind: 'app',\n id: 'app',\n scriptPath: appScript,\n stylePath: await resolveStyleFile(appScript),\n sourceType: appScript.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n state.moduleMeta.set(normalizePath(appScript), appMeta)\n }\n\n const resolveComponentScript = async (raw: string, importerDir: string) => {\n const base = resolveComponentBase(raw, importerDir, srcRoot)\n if (base) {\n const resolved = await resolveScriptFile(base)\n return resolved ? normalizePath(resolved) : undefined\n }\n const importer = join(importerDir, '__weapp_web_using_components__.ts')\n const resolved = await resolveId?.(raw, importer)\n const script = resolved ? await resolveScriptFile(resolved) : undefined\n return script ? normalizePath(script) : undefined\n }\n\n const getStableComponentId = (script: string) => {\n return getStableWebComponentId(script, srcRoot)\n }\n\n const getComponentTag = (script: string) => {\n const cached = state.componentTagMap.get(script)\n if (cached) {\n return cached\n }\n const id = getStableComponentId(script)\n const tag = slugify(id, 'wv-component')\n state.componentTagMap.set(script, tag)\n return tag\n }\n\n const collectComponent = async (componentId: string, importerDir: string) => {\n const script = await resolveComponentScript(componentId, importerDir)\n if (!script) {\n return\n }\n\n const existing = components.get(script)\n if (existing) {\n existing.importId ??= resolveComponentBase(componentId, importerDir, srcRoot)\n ? undefined\n : componentId\n return\n }\n\n const componentIdPosix = getStableComponentId(script)\n const importId = resolveComponentBase(componentId, importerDir, srcRoot)\n ? (isInsideDir(script, srcRoot) ? undefined : componentIdPosix)\n : componentId\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const componentMeta: ModuleMeta = {\n kind: 'component',\n id: componentIdPosix,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: script.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n state.moduleMeta.set(normalizePath(script), componentMeta)\n\n components.set(script, { script, id: componentIdPosix, importId })\n\n const componentJsonBasePath = `${script.replace(new RegExp(`${extname(script)}$`), '')}.json`\n const sfcConfig = script.endsWith('.vue')\n ? (await compileScannedSfc({ filename: script, meta: componentMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n : undefined\n const componentTags = sfcConfig\n ? await collectComponentTagsFromConfig({\n json: sfcConfig,\n importerDir: dirname(script),\n jsonPath: script,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : await collectComponentTagsFromJson({\n jsonBasePath: componentJsonBasePath,\n importerDir: dirname(script),\n warn: reportWarning,\n collectFromConfig: (json, nextImporterDir, jsonPath, nextWarn) => collectComponentTagsFromConfig({\n json,\n importerDir: nextImporterDir,\n jsonPath,\n warn: nextWarn,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n }),\n })\n componentMeta.componentTags = mergeComponentTags(appComponentTags, componentTags)\n\n if (!template) {\n return\n }\n\n const mergedTags = mergeComponentTags(appComponentTags, componentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n return\n }\n state.templateComponentMap.delete(normalizePath(template))\n }\n\n async function collectPage(pageId: string) {\n const base = join(srcRoot, pageId)\n const script = await resolveScriptFile(base)\n if (!script) {\n return\n }\n\n const template = await resolveTemplateFile(base)\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n\n const style = await resolveStyleFile(base)\n const pageJsonBasePath = join(srcRoot, `${pageId}.json`)\n const pageJsonPath = await resolveJsonPath(pageJsonBasePath)\n const pageJson = pageJsonPath ? await readJsonFile(pageJsonPath) : undefined\n const pageMeta: ModuleMeta = {\n kind: 'page',\n id: toPosixId(pageId),\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: script.endsWith('.vue') ? 'vue-sfc' : 'native',\n }\n\n const sfcConfig = script.endsWith('.vue')\n ? (await compileScannedSfc({ filename: script, meta: pageMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n : undefined\n const resolvedNavigationConfig = mergeNavigationConfig(\n appNavigationDefaults,\n sfcConfig ? pickNavigationConfig(sfcConfig) : pageJson ? pickNavigationConfig(pageJson) : {},\n )\n pageMeta.navigationBar = Object.keys(resolvedNavigationConfig).length > 0\n ? resolvedNavigationConfig\n : undefined\n state.moduleMeta.set(normalizePath(script), pageMeta)\n\n pages.set(script, {\n script,\n id: toPosixId(pageId),\n })\n\n const pageComponentTags = sfcConfig\n ? await collectComponentTagsFromConfig({\n json: sfcConfig,\n importerDir: dirname(script),\n jsonPath: script,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : pageJson && pageJsonPath\n ? await collectComponentTagsFromConfig({\n json: pageJson,\n importerDir: dirname(script),\n jsonPath: pageJsonPath,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n })\n : {}\n\n if (template) {\n const mergedTags = mergeComponentTags(appComponentTags, pageComponentTags)\n if (Object.keys(mergedTags).length > 0) {\n state.templateComponentMap.set(normalizePath(template), mergedTags)\n }\n else {\n state.templateComponentMap.delete(normalizePath(template))\n }\n }\n pageMeta.componentTags = mergeComponentTags(appComponentTags, pageComponentTags)\n\n if (!template) {\n return\n }\n\n state.pageNavigationMap.set(normalizePath(template), resolvedNavigationConfig)\n }\n\n async function collectLayouts() {\n const layoutsRoot = join(srcRoot, 'layouts')\n const files: string[] = []\n try {\n await walk(layoutsRoot, files)\n }\n catch {\n return\n }\n for (const filename of files.sort()) {\n const script = SCRIPT_EXTS.includes(extname(filename)) ? filename : undefined\n if (!script) {\n continue\n }\n const relativePath = relative(layoutsRoot, script).replace(/\\\\/g, '/')\n const segments = relativePath.split('/')\n segments.pop()\n if (segments[segments.length - 1] === 'index') {\n segments.pop()\n }\n const name = segments.join('/')\n if (!name) {\n continue\n }\n const id = `layouts/${name}`\n const template = await resolveTemplateFile(script)\n const style = await resolveStyleFile(script)\n const tag = slugify(id, 'wv-component')\n state.moduleMeta.set(normalizePath(script), {\n kind: 'component',\n id,\n scriptPath: script,\n templatePath: template,\n stylePath: style,\n sourceType: 'native',\n })\n layouts.set(script, { script, id, name, tag, template, style })\n if (template) {\n state.templatePathSet.add(normalizePath(template))\n }\n }\n }\n\n const appJsonBasePath = join(srcRoot, 'app.json')\n const appJsonPath = await resolveJsonPath(appJsonBasePath)\n let appJson = appJsonPath\n ? await (resolveAppConfig ? resolveAppConfig(appJsonPath) : readJsonFile(appJsonPath))\n : undefined\n if (appScript?.endsWith('.vue')) {\n const appMeta = state.moduleMeta.get(normalizePath(appScript))!\n const sfcConfig = (await compileScannedSfc({ filename: appScript, meta: appMeta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp })).config\n appJson = {\n ...(sfcConfig ?? {}),\n ...(appJson ?? {}),\n }\n }\n if (appJson) {\n appComponentTags = await collectComponentTagsFromConfig({\n json: appJson,\n importerDir: srcRoot,\n jsonPath: appJsonPath ?? appScript!,\n warn: reportWarning,\n resolveComponentScript,\n getComponentTag,\n collectComponent,\n onResolved: (tags) => {\n appComponentTags = tags\n },\n })\n\n const windowConfig = isRecord(appJson?.window) ? appJson.window : undefined\n appNavigationDefaults = pickNavigationConfig(windowConfig)\n\n const configuredPages = Array.isArray(appJson.pages)\n ? appJson.pages.filter((page): page is string => typeof page === 'string')\n : []\n for (const page of configuredPages.length > 0 ? configuredPages : await discoverWebPageIds(srcRoot)) {\n await collectPage(page)\n }\n\n const subPackages = Array.isArray(appJson.subPackages)\n ? appJson.subPackages\n : Array.isArray(appJson.subpackages)\n ? appJson.subpackages\n : []\n if (subPackages.length > 0) {\n for (const pkg of subPackages) {\n if (!pkg || typeof pkg !== 'object' || !Array.isArray(pkg.pages)) {\n continue\n }\n const root = typeof pkg.root === 'string' ? pkg.root : ''\n for (const page of pkg.pages) {\n if (typeof page !== 'string') {\n continue\n }\n await collectPage(posix.join(root, page))\n }\n }\n }\n\n appTabBar = normalizeWebTabBarConfig(appJson?.tabBar)\n }\n else {\n for (const page of await discoverWebPageIds(srcRoot)) {\n await collectPage(page)\n }\n }\n\n await collectLayouts()\n\n state.appNavigationDefaults = appNavigationDefaults\n state.appComponentTags = appComponentTags\n state.scanResult = {\n app: appScript,\n pages: Array.from(pages.values()),\n components: Array.from(components.values()),\n layouts: Array.from(layouts.values()),\n tabBar: appTabBar,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,wBAAwB,QAAgB,SAAiB;CACvE,MAAM,aAAa,OAAO,QAAQ,OAAO,GAAG;CAC5C,MAAM,mBAAmB,WAAW,YAAY,gBAAgB;CAChE,MAAM,YAAY,QAAQ,MAAM;CAChC,IAAI,oBAAoB,GAEtB,OAAO,gBADiB,WAAW,MAAM,mBAAmB,EACvB,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,MAAM;CAEnE,OAAO,UAAU,SAAS,SAAS,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,MAAM,CAAC;AACxE;AAEA,SAAS,qBAAqB,KAAa,aAAqB,SAAiB;CAC/E,IAAI,CAAC,KACH;CAEF,IAAI,IAAI,WAAW,GAAG,GACpB,OAAO,QAAQ,aAAa,GAAG;CAEjC,IAAI,IAAI,WAAW,GAAG,GACpB,OAAO,QAAQ,SAAS,IAAI,MAAM,CAAC,CAAC;AAGxC;AAEA,eAAsB,YAAY,EAAE,SAAS,MAAM,OAAO,WAAW,s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Root, resolveId) {
|
|
|
20
20
|
}
|
|
21
21
|
async function compileWebVueSfc(options) {
|
|
22
22
|
const { filename, meta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp } = options;
|
|
23
|
-
const
|
|
23
|
+
const source = uniApp && isUniAppCompatibilityFile(filename, srcRoot, uniApp.include) ? transformUniAppSource(options.source, {
|
|
24
24
|
filename,
|
|
25
25
|
target: "h5"
|
|
26
|
-
}).code : options.source
|
|
26
|
+
}).code : options.source;
|
|
27
|
+
const result = await compileVueFile(source, filename, {
|
|
27
28
|
isApp: meta.kind === "app",
|
|
28
29
|
isPage: meta.kind === "page",
|
|
29
30
|
sourceMap: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueSfc.mjs","names":[],"sources":["../../src/plugin/vueSfc.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { VueTransformResult } from 'wevu/compiler'\nimport type { ModuleMeta, ResolveWebAutoImportTag, ResolveWebModuleId, ScanState } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { fs } from '@weapp-core/shared/fs'\nimport { transform } from 'esbuild'\nimport MagicString from 'magic-string'\nimport path from 'pathe'\nimport { compileVueFile, isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { resolveScriptFile } from './files'\nimport { appendInlineQuery, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport } from './path'\n\nconst traverse = _babelTraverse\n\nasync function resolveSfcSrc(\n request: string,\n importer: string,\n srcRoot: string,\n resolveId?: ResolveWebModuleId,\n) {\n if (request.startsWith('@/')) {\n return path.resolve(srcRoot, request.slice(2))\n }\n if (request.startsWith('.')) {\n return path.resolve(path.dirname(importer), request)\n }\n if (request.startsWith('/')) {\n return path.resolve(srcRoot, request.slice(1))\n }\n return await resolveId?.(request, importer)\n}\n\nexport async function compileWebVueSfc(options: {\n source: string\n filename: string\n meta: ModuleMeta\n srcRoot: string\n state: ScanState\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n uniApp?: { include: string[] }\n}) {\n const { filename, meta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp } = options\n const source = uniApp && isUniAppCompatibilityFile(filename, srcRoot, uniApp.include)\n ? transformUniAppSource(options.source, { filename, target: 'h5' }).code\n : options.source\n const result = await compileVueFile(source, filename, {\n isApp: meta.kind === 'app',\n isPage: meta.kind === 'page',\n sourceMap: false,\n style: {\n preserveDeepSelectors: true,\n transformScoped: false,\n },\n json: { kind: meta.kind },\n autoUsingComponents: {\n enabled: true,\n resolveUsingComponentPath: async (request, importer) => {\n const base = request.startsWith('@/')\n ? path.resolve(srcRoot, request.slice(2))\n : request.startsWith('.')\n ? path.resolve(path.dirname(importer), request)\n : request.startsWith('/')\n ? path.resolve(srcRoot, request.slice(1))\n : undefined\n if (!base) {\n return undefined\n }\n const resolvedId = await resolveScriptFile(base)\n if (!resolvedId) {\n return undefined\n }\n return {\n from: request,\n resolvedId,\n sourceType: resolvedId.endsWith('.vue') ? 'wevu-sfc' : 'native',\n }\n },\n },\n autoImportTags: {\n enabled: Boolean(resolveAutoImportTag),\n resolveUsingComponent: async (tag, importer) => resolveAutoImportTag?.(tag, importer),\n },\n sfcSrc: {\n resolveId: async (request, importer) => {\n return resolveSfcSrc(request, importer!, srcRoot, resolveId)\n },\n },\n })\n state.sfcResults.set(filename, result)\n for (const dependency of result.meta?.sfcSrcDeps ?? []) {\n state.templatePathSet.add(dependency)\n }\n return result\n}\n\nexport async function ensureWebVueSfcResult(options: {\n filename: string\n meta: ModuleMeta\n srcRoot: string\n state: ScanState\n source?: string\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n uniApp?: { include: string[] }\n}) {\n const cached = options.state.sfcResults.get(options.filename)\n if (cached) {\n return cached\n }\n const source = options.source ?? await fs.readFile(options.filename, 'utf8')\n return await compileWebVueSfc({ ...options, source })\n}\n\nfunction getSfcRegisterName(kind: ModuleMeta['kind']) {\n return kind === 'app' ? 'registerWebWevuApp' : 'registerWebWevuComponent'\n}\n\nfunction getSfcFactoryName(kind: ModuleMeta['kind']) {\n return kind === 'app' ? 'createApp' : 'createWevuComponent'\n}\n\nfunction createRegisterMetaCode(meta: ModuleMeta, templateIdent?: string, styleIdent?: string) {\n const parts = [`id: ${JSON.stringify(meta.id)}`, `kind: ${JSON.stringify(meta.kind)}`]\n if (templateIdent) {\n parts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n parts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n parts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${parts.join(', ')} }`\n}\n\nexport async function transformWebVueSfcScript(options: {\n code: string\n filename: string\n meta: ModuleMeta\n runtimeModuleId: string\n styleLanguage: string\n enableHmr: boolean\n hmrAcceptCode?: string\n}) {\n const { code, filename, meta, runtimeModuleId, styleLanguage, enableHmr, hmrAcceptCode } = options\n const ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n ranges: true,\n })\n const s = new MagicString(code)\n const templateIdent = meta.kind === 'app' ? undefined : '__weapp_sfc_template__'\n const styleIdent = meta.kind === 'app' ? undefined : '__weapp_sfc_style__'\n const registerName = getSfcRegisterName(meta.kind)\n const factoryName = getSfcFactoryName(meta.kind)\n const registerMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent)\n let transformed = false\n\n traverse(ast, {\n CallExpression(nodePath: NodePath<CallExpression>) {\n const callee = nodePath.node.callee\n if (!t.isIdentifier(callee, { name: factoryName })) {\n return\n }\n s.overwrite(callee.start!, callee.end!, registerName)\n s.appendLeft(nodePath.node.end! - 1, `, ${registerMetaCode}`)\n transformed = true\n },\n })\n\n if (!transformed) {\n throw new Error(`[@weapp-vite/web] Vue SFC 未生成 ${factoryName} 注册调用: ${filename}`)\n }\n\n const imports = [`import { ${registerName} } from '${runtimeModuleId}'`]\n if (templateIdent) {\n imports.push(`import ${templateIdent} from '${toRelativeImport(filename, filename)}?weapp-web-sfc-template'`)\n }\n if (styleIdent) {\n const styleFilename = `${filename}.${styleLanguage}`\n imports.push(`import ${styleIdent} from '${appendInlineQuery(`${toRelativeImport(filename, styleFilename)}?weapp-web-sfc-style`)}'`)\n }\n s.prepend(`${imports.join('\\n')}\\n`)\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n const transpiled = await transform(s.toString(), {\n format: 'esm',\n legalComments: 'inline',\n loader: 'ts',\n sourcefile: filename,\n sourcemap: 'external',\n target: 'es2022',\n })\n return {\n code: transpiled.code,\n map: JSON.parse(transpiled.map),\n }\n}\n\nexport function generateWebVueSfcTemplate(\n result: VueTransformResult,\n meta: ModuleMeta,\n filename: string,\n srcRoot: string,\n) {\n const compiled = compileWxml({\n id: filename,\n source: result.template ?? '',\n navigationBar: meta.navigationBar ? { config: meta.navigationBar } : undefined,\n componentTags: meta.componentTags,\n resolveTemplatePath: (request, importer) => resolveTemplatePathSync(request, importer, srcRoot),\n resolveWxsPath: (request, importer) => resolveWxsPathSync(request, importer, srcRoot),\n })\n return compiled\n}\n\nexport function resolveWebVueSfcStyleLanguage(result: VueTransformResult, filename: string) {\n const languages = new Set(\n (result.meta?.styleBlocks ?? []).map(style => style.lang?.trim() || 'css'),\n )\n for (const language of languages) {\n if (!/^[a-z][a-z0-9-]*$/i.test(language)) {\n throw new Error(`[@weapp-vite/web] Vue SFC 样式语言无效: ${filename} -> ${language}`)\n }\n }\n const preprocessLanguages = [...languages].filter(language => language !== 'css')\n if (preprocessLanguages.length > 1) {\n throw new Error(`[@weapp-vite/web] Vue SFC 暂不支持混合样式语言: ${filename}`)\n }\n return preprocessLanguages[0] ?? 'css'\n}\n\nexport function generateWebVueSfcStyle(result: VueTransformResult) {\n return result.style ?? ''\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAA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CAChC;AACF;AAEA,SAAgB,0BACd,QACA,MACA,UACA,SACA;CASA,OARiB,YAAY;EAC3B,IAAI;EACJ,QAAQ,OAAO,YAAY;EAC3B,eAAe,KAAK,gBAAgB,EAAE,QAAQ,KAAK,cAAc,IAAI;EACrE,eAAe,KAAK;EACpB,sBAAsB,SAAS,aAAa,wBAAwB,SAAS,UAAU,OAAO;EAC9F,iBAAiB,SAAS,aAAa,mBAAmB,SAAS,UAAU,OAAO;CACtF,CACc;AAChB;AAEA,SAAgB,8BAA8B,QAA4B,UAAkB;CAC1F,MAAM,YAAY,IAAI,KACnB,OAAO,MAAM,eAAe,CAAC,EAAC,CAAE,KAAI,UAAS,MAAM,MAAM,KAAK,KAAK,KAAK,CAC3E;CACA,KAAK,MAAM,YAAY,WACrB,IAAI,CAAC,qBAAqB,KAAK,QAAQ,GACrC,MAAM,IAAI,MAAM,qCAAqC,SAAS,MAAM,UAAU;CAGlF,MAAM,sBAAsB,CAAC,GAAG,SAAS,CAAC,CAAC,QAAO,aAAY,aAAa,KAAK;CAChF,IAAI,oBAAoB,SAAS,GAC/B,MAAM,IAAI,MAAM,yCAAyC,UAAU;CAErE,OAAO,oBAAoB,MAAM;AACnC;AAEA,SAAgB,uBAAuB,QAA4B;CACjE,OAAO,OAAO,SAAS;AACzB"}
|
|
1
|
+
{"version":3,"file":"vueSfc.mjs","names":[],"sources":["../../src/plugin/vueSfc.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse'\nimport type { CallExpression } from '@babel/types'\nimport type { VueTransformResult } from 'wevu/compiler'\nimport type { ModuleMeta, ResolveWebAutoImportTag, ResolveWebModuleId, ScanState } from './types'\nimport { parse } from '@babel/parser'\nimport _babelTraverse from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { fs } from '@weapp-core/shared/fs'\nimport { transform } from 'esbuild'\nimport MagicString from 'magic-string'\nimport path from 'pathe'\nimport { compileVueFile, isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { resolveScriptFile } from './files'\nimport { appendInlineQuery, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport } from './path'\n\nconst traverse = _babelTraverse\n\nasync function resolveSfcSrc(\n request: string,\n importer: string,\n srcRoot: string,\n resolveId?: ResolveWebModuleId,\n) {\n if (request.startsWith('@/')) {\n return path.resolve(srcRoot, request.slice(2))\n }\n if (request.startsWith('.')) {\n return path.resolve(path.dirname(importer), request)\n }\n if (request.startsWith('/')) {\n return path.resolve(srcRoot, request.slice(1))\n }\n return await resolveId?.(request, importer)\n}\n\nexport async function compileWebVueSfc(options: {\n source: string\n filename: string\n meta: ModuleMeta\n srcRoot: string\n state: ScanState\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n uniApp?: { include: string[] }\n}) {\n const { filename, meta, srcRoot, state, resolveId, resolveAutoImportTag, uniApp } = options\n const source = uniApp && isUniAppCompatibilityFile(filename, srcRoot, uniApp.include)\n ? transformUniAppSource(options.source, { filename, target: 'h5' }).code\n : options.source\n const result = await compileVueFile(source, filename, {\n isApp: meta.kind === 'app',\n isPage: meta.kind === 'page',\n sourceMap: false,\n style: {\n preserveDeepSelectors: true,\n transformScoped: false,\n },\n json: { kind: meta.kind },\n autoUsingComponents: {\n enabled: true,\n resolveUsingComponentPath: async (request, importer) => {\n const base = request.startsWith('@/')\n ? path.resolve(srcRoot, request.slice(2))\n : request.startsWith('.')\n ? path.resolve(path.dirname(importer), request)\n : request.startsWith('/')\n ? path.resolve(srcRoot, request.slice(1))\n : undefined\n if (!base) {\n return undefined\n }\n const resolvedId = await resolveScriptFile(base)\n if (!resolvedId) {\n return undefined\n }\n return {\n from: request,\n resolvedId,\n sourceType: resolvedId.endsWith('.vue') ? 'wevu-sfc' : 'native',\n }\n },\n },\n autoImportTags: {\n enabled: Boolean(resolveAutoImportTag),\n resolveUsingComponent: async (tag, importer) => resolveAutoImportTag?.(tag, importer),\n },\n sfcSrc: {\n resolveId: async (request, importer) => {\n return resolveSfcSrc(request, importer!, srcRoot, resolveId)\n },\n },\n })\n state.sfcResults.set(filename, result)\n for (const dependency of result.meta?.sfcSrcDeps ?? []) {\n state.templatePathSet.add(dependency)\n }\n return result\n}\n\nexport async function ensureWebVueSfcResult(options: {\n filename: string\n meta: ModuleMeta\n srcRoot: string\n state: ScanState\n source?: string\n resolveId?: ResolveWebModuleId\n resolveAutoImportTag?: ResolveWebAutoImportTag\n uniApp?: { include: string[] }\n}) {\n const cached = options.state.sfcResults.get(options.filename)\n if (cached) {\n return cached\n }\n const source = options.source ?? await fs.readFile(options.filename, 'utf8')\n return await compileWebVueSfc({ ...options, source })\n}\n\nfunction getSfcRegisterName(kind: ModuleMeta['kind']) {\n return kind === 'app' ? 'registerWebWevuApp' : 'registerWebWevuComponent'\n}\n\nfunction getSfcFactoryName(kind: ModuleMeta['kind']) {\n return kind === 'app' ? 'createApp' : 'createWevuComponent'\n}\n\nfunction createRegisterMetaCode(meta: ModuleMeta, templateIdent?: string, styleIdent?: string) {\n const parts = [`id: ${JSON.stringify(meta.id)}`, `kind: ${JSON.stringify(meta.kind)}`]\n if (templateIdent) {\n parts.push(`template: ${templateIdent}`)\n }\n if (styleIdent) {\n parts.push(`style: ${styleIdent}`)\n }\n if (meta.navigationBar) {\n parts.push(`navigationBar: ${JSON.stringify(meta.navigationBar)}`)\n }\n return `{ ${parts.join(', ')} }`\n}\n\nexport async function transformWebVueSfcScript(options: {\n code: string\n filename: string\n meta: ModuleMeta\n runtimeModuleId: string\n styleLanguage: string\n enableHmr: boolean\n hmrAcceptCode?: string\n}) {\n const { code, filename, meta, runtimeModuleId, styleLanguage, enableHmr, hmrAcceptCode } = options\n const ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n ranges: true,\n })\n const s = new MagicString(code)\n const templateIdent = meta.kind === 'app' ? undefined : '__weapp_sfc_template__'\n const styleIdent = meta.kind === 'app' ? undefined : '__weapp_sfc_style__'\n const registerName = getSfcRegisterName(meta.kind)\n const factoryName = getSfcFactoryName(meta.kind)\n const registerMetaCode = createRegisterMetaCode(meta, templateIdent, styleIdent)\n let transformed = false\n\n traverse(ast, {\n CallExpression(nodePath: NodePath<CallExpression>) {\n const callee = nodePath.node.callee\n if (!t.isIdentifier(callee, { name: factoryName })) {\n return\n }\n s.overwrite(callee.start!, callee.end!, registerName)\n s.appendLeft(nodePath.node.end! - 1, `, ${registerMetaCode}`)\n transformed = true\n },\n })\n\n if (!transformed) {\n throw new Error(`[@weapp-vite/web] Vue SFC 未生成 ${factoryName} 注册调用: ${filename}`)\n }\n\n const imports = [`import { ${registerName} } from '${runtimeModuleId}'`]\n if (templateIdent) {\n imports.push(`import ${templateIdent} from '${toRelativeImport(filename, filename)}?weapp-web-sfc-template'`)\n }\n if (styleIdent) {\n const styleFilename = `${filename}.${styleLanguage}`\n imports.push(`import ${styleIdent} from '${appendInlineQuery(`${toRelativeImport(filename, styleFilename)}?weapp-web-sfc-style`)}'`)\n }\n s.prepend(`${imports.join('\\n')}\\n`)\n if (enableHmr && hmrAcceptCode) {\n s.append(`\\n${hmrAcceptCode}\\n`)\n }\n const transpiled = await transform(s.toString(), {\n format: 'esm',\n legalComments: 'inline',\n loader: 'ts',\n sourcefile: filename,\n sourcemap: 'external',\n target: 'es2022',\n })\n return {\n code: transpiled.code,\n map: JSON.parse(transpiled.map),\n }\n}\n\nexport function generateWebVueSfcTemplate(\n result: VueTransformResult,\n meta: ModuleMeta,\n filename: string,\n srcRoot: string,\n) {\n const compiled = compileWxml({\n id: filename,\n source: result.template ?? '',\n navigationBar: meta.navigationBar ? { config: meta.navigationBar } : undefined,\n componentTags: meta.componentTags,\n resolveTemplatePath: (request, importer) => resolveTemplatePathSync(request, importer, srcRoot),\n resolveWxsPath: (request, importer) => resolveWxsPathSync(request, importer, srcRoot),\n })\n return compiled\n}\n\nexport function resolveWebVueSfcStyleLanguage(result: VueTransformResult, filename: string) {\n const languages = new Set(\n (result.meta?.styleBlocks ?? []).map(style => style.lang?.trim() || 'css'),\n )\n for (const language of languages) {\n if (!/^[a-z][a-z0-9-]*$/i.test(language)) {\n throw new Error(`[@weapp-vite/web] Vue SFC 样式语言无效: ${filename} -> ${language}`)\n }\n }\n const preprocessLanguages = [...languages].filter(language => language !== 'css')\n if (preprocessLanguages.length > 1) {\n throw new Error(`[@weapp-vite/web] Vue SFC 暂不支持混合样式语言: ${filename}`)\n }\n return preprocessLanguages[0] ?? 'css'\n}\n\nexport function generateWebVueSfcStyle(result: VueTransformResult) {\n return result.style ?? ''\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,WAAW;AAEjB,eAAe,cACb,SACA,UACA,SACA,WACA;CACA,IAAI,QAAQ,WAAW,IAAI,GACzB,OAAO,KAAK,QAAQ,SAAS,QAAQ,MAAM,CAAC,CAAC;CAE/C,IAAI,QAAQ,WAAW,GAAG,GACxB,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ,GAAG,OAAO;CAErD,IAAI,QAAQ,WAAW,GAAG,GACxB,OAAO,KAAK,QAAQ,SAAS,QAAQ,MAAM,CAAC,CAAC;CAE/C,OAAO,MAAM,YAAY,SAAS,QAAQ;AAC5C;AAEA,eAAsB,iBAAiB,SASpC;CACD,MAAM,EAAE,UAAU,MAAM,SAAS,OAAO,WAAW,sBAAsB,WAAW;CACpF,MAAM,SAAS,UAAU,0BAA0B,UAAU,SAAS,OAAO,OAAO,IAChF,sBAAsB,QAAQ,QAAQ;EAAE;EAAU,QAAQ;CAAK,CAAC,CAAC,CAAC,OAClE,QAAQ;CACZ,MAAM,SAAS,MAAM,eAAe,QAAQ,UAAU;EACpD,OAAO,KAAK,SAAS;EACrB,QAAQ,KAAK,SAAS;EACtB,WAAW;EACX,OAAO;GACL,uBAAuB;GACvB,iBAAiB;EACnB;EACA,MAAM,EAAE,MAAM,KAAK,KAAK;EACxB,qBAAqB;GACnB,SAAS;GACT,2BAA2B,OAAO,SAAS,aAAa;IACtD,MAAM,OAAO,QAAQ,WAA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Parent(node) {
|
|
|
11
11
|
}
|
|
12
12
|
function resolveRelationTag(componentId, relationPath) {
|
|
13
13
|
if (!relationPath.startsWith(".")) return;
|
|
14
|
-
|
|
14
|
+
const targetId = posix.normalize(posix.join(posix.dirname(componentId), relationPath));
|
|
15
|
+
return slugify(targetId, "wv-component");
|
|
15
16
|
}
|
|
16
17
|
function resolveRelationNodes(instance, componentId, relationPath, type) {
|
|
17
18
|
if (!componentId) return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations.mjs","names":[],"sources":["../../../src/runtime/component/relations.ts"],"sourcesContent":["import type { ComponentPublicInstance, RelationType } from './types'\nimport { posix } from 'pathe'\nimport { slugify } from '../../shared/slugify'\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 resolveRelationTag(componentId: string, relationPath: string) {\n if (!relationPath.startsWith('.')) {\n return undefined\n }\n const targetId = posix.normalize(posix.join(posix.dirname(componentId), relationPath))\n return slugify(targetId, 'wv-component')\n}\n\nexport function resolveRelationNodes(\n instance: ComponentPublicInstance,\n componentId: string | undefined,\n relationPath: string,\n type: RelationType,\n): ComponentPublicInstance[] {\n if (!componentId) {\n return []\n }\n const tag = resolveRelationTag(componentId, relationPath)\n if (!tag) {\n return []\n }\n if (type === 'child' || type === 'descendant') {\n const matches = Array.from(instance.querySelectorAll(tag)) as ComponentPublicInstance[]\n return type === 'descendant'\n ? matches\n : matches.filter(node => resolveComposedParent(node) === instance)\n }\n\n let current = resolveComposedParent(instance)\n while (current) {\n if ((current as Element).tagName?.toLowerCase() === tag) {\n return [current as ComponentPublicInstance]\n }\n if (type === 'parent') {\n return []\n }\n current = resolveComposedParent(current)\n }\n return []\n}\n"],"mappings":";;;;AAIA,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,mBAAmB,aAAqB,cAAsB;CACrE,IAAI,CAAC,aAAa,WAAW,GAAG,GAC9B;
|
|
1
|
+
{"version":3,"file":"relations.mjs","names":[],"sources":["../../../src/runtime/component/relations.ts"],"sourcesContent":["import type { ComponentPublicInstance, RelationType } from './types'\nimport { posix } from 'pathe'\nimport { slugify } from '../../shared/slugify'\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 resolveRelationTag(componentId: string, relationPath: string) {\n if (!relationPath.startsWith('.')) {\n return undefined\n }\n const targetId = posix.normalize(posix.join(posix.dirname(componentId), relationPath))\n return slugify(targetId, 'wv-component')\n}\n\nexport function resolveRelationNodes(\n instance: ComponentPublicInstance,\n componentId: string | undefined,\n relationPath: string,\n type: RelationType,\n): ComponentPublicInstance[] {\n if (!componentId) {\n return []\n }\n const tag = resolveRelationTag(componentId, relationPath)\n if (!tag) {\n return []\n }\n if (type === 'child' || type === 'descendant') {\n const matches = Array.from(instance.querySelectorAll(tag)) as ComponentPublicInstance[]\n return type === 'descendant'\n ? matches\n : matches.filter(node => resolveComposedParent(node) === instance)\n }\n\n let current = resolveComposedParent(instance)\n while (current) {\n if ((current as Element).tagName?.toLowerCase() === tag) {\n return [current as ComponentPublicInstance]\n }\n if (type === 'parent') {\n return []\n }\n current = resolveComposedParent(current)\n }\n return []\n}\n"],"mappings":";;;;AAIA,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,mBAAmB,aAAqB,cAAsB;CACrE,IAAI,CAAC,aAAa,WAAW,GAAG,GAC9B;CAEF,MAAM,WAAW,MAAM,UAAU,MAAM,KAAK,MAAM,QAAQ,WAAW,GAAG,YAAY,CAAC;CACrF,OAAO,QAAQ,UAAU,cAAc;AACzC;AAEA,SAAgB,qBACd,UACA,aACA,cACA,MAC2B;CAC3B,IAAI,CAAC,aACH,OAAO,CAAC;CAEV,MAAM,MAAM,mBAAmB,aAAa,YAAY;CACxD,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,IAAI,SAAS,WAAW,SAAS,cAAc;EAC7C,MAAM,UAAU,MAAM,KAAK,SAAS,iBAAiB,GAAG,CAAC;EACzD,OAAO,SAAS,eACZ,UACA,QAAQ,QAAO,SAAQ,sBAAsB,IAAI,MAAM,QAAQ;CACrE;CAEA,IAAI,UAAU,sBAAsB,QAAQ;CAC5C,OAAO,SAAS;EACd,IAAK,QAAoB,SAAS,YAAY,MAAM,KAClD,OAAO,CAAC,OAAkC;EAE5C,IAAI,SAAS,UACX,OAAO,CAAC;EAEV,UAAU,sBAAsB,OAAO;CACzC;CACA,OAAO,CAAC;AACV"}
|
|
@@ -7,7 +7,8 @@ function vibrateShortBridge(options) {
|
|
|
7
7
|
vibrateDevice(options?.type);
|
|
8
8
|
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "vibrateShort:ok" }));
|
|
9
9
|
} catch (error) {
|
|
10
|
-
const
|
|
10
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11
|
+
const failure = callMiniProgramAsyncFailure(options, `vibrateShort:fail ${message}`);
|
|
11
12
|
return Promise.reject(failure);
|
|
12
13
|
}
|
|
13
14
|
}
|
|
@@ -16,12 +17,14 @@ function getBatteryInfoSyncBridge() {
|
|
|
16
17
|
}
|
|
17
18
|
async function getBatteryInfoBridge(options) {
|
|
18
19
|
try {
|
|
20
|
+
const batteryInfo = await readBatteryInfoSnapshot();
|
|
19
21
|
return callMiniProgramAsyncSuccess(options, {
|
|
20
22
|
errMsg: "getBatteryInfo:ok",
|
|
21
|
-
...
|
|
23
|
+
...batteryInfo
|
|
22
24
|
});
|
|
23
25
|
} catch (error) {
|
|
24
|
-
const
|
|
26
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
27
|
+
const failure = callMiniProgramAsyncFailure(options, `getBatteryInfo:fail ${message}`);
|
|
25
28
|
return Promise.reject(failure);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceApi.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n readBatteryInfoSnapshot,\n readBatteryInfoSyncSnapshot,\n vibrateDevice,\n} from './device'\n\nexport function vibrateShortBridge(options?: any) {\n try {\n vibrateDevice(options?.type)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'vibrateShort:ok' }))\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `vibrateShort:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport function getBatteryInfoSyncBridge() {\n return readBatteryInfoSyncSnapshot()\n}\n\nexport async function getBatteryInfoBridge(options?: any) {\n try {\n const batteryInfo = await readBatteryInfoSnapshot()\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getBatteryInfo:ok',\n ...batteryInfo,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getBatteryInfo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;AAUA,SAAgB,mBAAmB,SAAe;CAChD,IAAI;EACF,cAAc,SAAS,IAAI;EAC3B,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,kBAAkB,CAAC,CAAC;CAC5F,SACO,OAAO;
|
|
1
|
+
{"version":3,"file":"deviceApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceApi.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n readBatteryInfoSnapshot,\n readBatteryInfoSyncSnapshot,\n vibrateDevice,\n} from './device'\n\nexport function vibrateShortBridge(options?: any) {\n try {\n vibrateDevice(options?.type)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'vibrateShort:ok' }))\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `vibrateShort:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport function getBatteryInfoSyncBridge() {\n return readBatteryInfoSyncSnapshot()\n}\n\nexport async function getBatteryInfoBridge(options?: any) {\n try {\n const batteryInfo = await readBatteryInfoSnapshot()\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getBatteryInfo:ok',\n ...batteryInfo,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getBatteryInfo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;AAUA,SAAgB,mBAAmB,SAAe;CAChD,IAAI;EACF,cAAc,SAAS,IAAI;EAC3B,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,kBAAkB,CAAC,CAAC;CAC5F,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,4BAA4B,SAAS,qBAAqB,SAAS;EACnF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF;AAEA,SAAgB,2BAA2B;CACzC,OAAO,4BAA4B;AACrC;AAEA,eAAsB,qBAAqB,SAAe;CACxD,IAAI;EACF,MAAM,cAAc,MAAM,wBAAwB;EAClD,OAAO,4BAA4B,SAAS;GAC1C,QAAQ;GACR,GAAG;EACL,CAAC;CACH,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,4BAA4B,SAAS,uBAAuB,SAAS;EACrF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF"}
|
|
@@ -23,7 +23,8 @@ async function loadFontFace(options) {
|
|
|
23
23
|
});
|
|
24
24
|
return callMiniProgramAsyncSuccess(options, { errMsg: "loadFontFace:ok" });
|
|
25
25
|
} catch (error) {
|
|
26
|
-
|
|
26
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
27
|
+
return callMiniProgramAsyncFailure(options, `loadFontFace:fail ${message}`);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font.mjs","names":[],"sources":["../../../src/runtime/polyfill/font.ts"],"sourcesContent":["import type { LoadFontFaceOptions } from './types'\nimport { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from './async'\n\nfunction installFallbackFontFace(options: LoadFontFaceOptions) {\n if (typeof document === 'undefined') {\n throw new Error('document is unavailable')\n }\n const style = document.createElement('style')\n style.dataset.weappFontFamily = options.family\n style.textContent = `@font-face{font-family:${JSON.stringify(options.family)};src:${options.source};}`\n document.head.append(style)\n}\n\nexport async function loadFontFace(options: LoadFontFaceOptions) {\n const family = options?.family?.trim()\n const source = options?.source?.trim()\n if (!family || !source) {\n return callMiniProgramAsyncFailure(options, 'loadFontFace:fail invalid options')\n }\n\n try {\n if (\n typeof FontFace === 'function'\n && typeof document !== 'undefined'\n && document.fonts\n && typeof document.fonts.add === 'function'\n ) {\n const fontFace = new FontFace(family, source, options.descriptors)\n document.fonts.add(await fontFace.load())\n }\n else {\n installFallbackFontFace({ ...options, family, source })\n }\n return callMiniProgramAsyncSuccess(options, { errMsg: 'loadFontFace:ok' })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n return callMiniProgramAsyncFailure(options, `loadFontFace:fail ${message}`)\n }\n}\n"],"mappings":";;;AAGA,SAAS,wBAAwB,SAA8B;CAC7D,IAAI,OAAO,aAAa,aACtB,MAAM,IAAI,MAAM,yBAAyB;CAE3C,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,QAAQ,kBAAkB,QAAQ;CACxC,MAAM,cAAc,0BAA0B,KAAK,UAAU,QAAQ,MAAM,EAAE,OAAO,QAAQ,OAAO;CACnG,SAAS,KAAK,OAAO,KAAK;AAC5B;AAEA,eAAsB,aAAa,SAA8B;CAC/D,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,IAAI,CAAC,UAAU,CAAC,QACd,OAAO,4BAA4B,SAAS,mCAAmC;CAGjF,IAAI;EACF,IACE,OAAO,aAAa,cACjB,OAAO,aAAa,eACpB,SAAS,SACT,OAAO,SAAS,MAAM,QAAQ,YACjC;GACA,MAAM,WAAW,IAAI,SAAS,QAAQ,QAAQ,QAAQ,WAAW;GACjE,SAAS,MAAM,IAAI,MAAM,SAAS,KAAK,CAAC;EAC1C,OAEE,wBAAwB;GAAE,GAAG;GAAS;GAAQ;EAAO,CAAC;EAExD,OAAO,4BAA4B,SAAS,EAAE,QAAQ,kBAAkB,CAAC;CAC3E,SACO,OAAO;
|
|
1
|
+
{"version":3,"file":"font.mjs","names":[],"sources":["../../../src/runtime/polyfill/font.ts"],"sourcesContent":["import type { LoadFontFaceOptions } from './types'\nimport { callMiniProgramAsyncFailure, callMiniProgramAsyncSuccess } from './async'\n\nfunction installFallbackFontFace(options: LoadFontFaceOptions) {\n if (typeof document === 'undefined') {\n throw new Error('document is unavailable')\n }\n const style = document.createElement('style')\n style.dataset.weappFontFamily = options.family\n style.textContent = `@font-face{font-family:${JSON.stringify(options.family)};src:${options.source};}`\n document.head.append(style)\n}\n\nexport async function loadFontFace(options: LoadFontFaceOptions) {\n const family = options?.family?.trim()\n const source = options?.source?.trim()\n if (!family || !source) {\n return callMiniProgramAsyncFailure(options, 'loadFontFace:fail invalid options')\n }\n\n try {\n if (\n typeof FontFace === 'function'\n && typeof document !== 'undefined'\n && document.fonts\n && typeof document.fonts.add === 'function'\n ) {\n const fontFace = new FontFace(family, source, options.descriptors)\n document.fonts.add(await fontFace.load())\n }\n else {\n installFallbackFontFace({ ...options, family, source })\n }\n return callMiniProgramAsyncSuccess(options, { errMsg: 'loadFontFace:ok' })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n return callMiniProgramAsyncFailure(options, `loadFontFace:fail ${message}`)\n }\n}\n"],"mappings":";;;AAGA,SAAS,wBAAwB,SAA8B;CAC7D,IAAI,OAAO,aAAa,aACtB,MAAM,IAAI,MAAM,yBAAyB;CAE3C,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,QAAQ,kBAAkB,QAAQ;CACxC,MAAM,cAAc,0BAA0B,KAAK,UAAU,QAAQ,MAAM,EAAE,OAAO,QAAQ,OAAO;CACnG,SAAS,KAAK,OAAO,KAAK;AAC5B;AAEA,eAAsB,aAAa,SAA8B;CAC/D,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,MAAM,SAAS,SAAS,QAAQ,KAAK;CACrC,IAAI,CAAC,UAAU,CAAC,QACd,OAAO,4BAA4B,SAAS,mCAAmC;CAGjF,IAAI;EACF,IACE,OAAO,aAAa,cACjB,OAAO,aAAa,eACpB,SAAS,SACT,OAAO,SAAS,MAAM,QAAQ,YACjC;GACA,MAAM,WAAW,IAAI,SAAS,QAAQ,QAAQ,QAAQ,WAAW;GACjE,SAAS,MAAM,IAAI,MAAM,SAAS,KAAK,CAAC;EAC1C,OAEE,wBAAwB;GAAE,GAAG;GAAS;GAAQ;EAAO,CAAC;EAExD,OAAO,4BAA4B,SAAS,EAAE,QAAQ,kBAAkB,CAAC;CAC3E,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,OAAO,4BAA4B,SAAS,qBAAqB,SAAS;CAC5E;AACF"}
|
|
@@ -33,19 +33,22 @@ async function setClipboardDataBridge(options) {
|
|
|
33
33
|
try {
|
|
34
34
|
await writeClipboardData(data);
|
|
35
35
|
} catch (error) {
|
|
36
|
-
const
|
|
36
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37
|
+
const failure = callMiniProgramAsyncFailure(options, `setClipboardData:fail ${message}`);
|
|
37
38
|
return Promise.reject(failure);
|
|
38
39
|
}
|
|
39
40
|
return callMiniProgramAsyncSuccess(options, { errMsg: "setClipboardData:ok" });
|
|
40
41
|
}
|
|
41
42
|
async function getClipboardDataBridge(options) {
|
|
42
43
|
try {
|
|
44
|
+
const data = await readClipboardData();
|
|
43
45
|
return callMiniProgramAsyncSuccess(options, {
|
|
44
46
|
errMsg: "getClipboardData:ok",
|
|
45
|
-
data
|
|
47
|
+
data
|
|
46
48
|
});
|
|
47
49
|
} catch (error) {
|
|
48
|
-
const
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
const failure = callMiniProgramAsyncFailure(options, `getClipboardData:fail ${message}`);
|
|
49
52
|
return Promise.reject(failure);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/interactionApi.ts"],"sourcesContent":["import { openRuntimeUrl } from '../host'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n readClipboardData,\n resolveScanCodeResult,\n writeClipboardData,\n} from './interaction'\nimport { getGlobalDialogHandlers } from './ui'\n\nexport function openCustomerServiceChatBridge(options?: any) {\n const url = options?.url?.trim() ?? ''\n if (url) {\n try {\n openRuntimeUrl(url, '_blank', 'noopener,noreferrer')\n }\n catch {\n // ignore browser popup restrictions\n }\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openCustomerServiceChat:ok' }))\n}\n\nexport function scanCodeBridge(options?: any) {\n const { prompt } = getGlobalDialogHandlers()\n const resultText = resolveScanCodeResult(prompt)\n if (resultText == null) {\n const failure = callMiniProgramAsyncFailure(options, 'scanCode:fail cancel')\n return Promise.reject(failure)\n }\n const result = callMiniProgramAsyncSuccess(options, {\n errMsg: 'scanCode:ok',\n result: resultText,\n scanType: 'QR_CODE',\n charSet: 'utf-8',\n path: resultText,\n rawData: resultText,\n })\n return Promise.resolve(result)\n}\n\nexport async function setClipboardDataBridge(options?: any) {\n const data = String(options?.data ?? '')\n try {\n await writeClipboardData(data)\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `setClipboardData:fail ${message}`)\n return Promise.reject(failure)\n }\n return callMiniProgramAsyncSuccess(options, { errMsg: 'setClipboardData:ok' })\n}\n\nexport async function getClipboardDataBridge(options?: any) {\n try {\n const data = await readClipboardData()\n return callMiniProgramAsyncSuccess(options, { errMsg: 'getClipboardData:ok', data })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getClipboardData:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;;;AAYA,SAAgB,8BAA8B,SAAe;CAC3D,MAAM,MAAM,SAAS,KAAK,KAAK,KAAK;CACpC,IAAI,KACF,IAAI;EACF,eAAe,KAAK,UAAU,qBAAqB;CACrD,QACM,CAEN;CAEF,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,6BAA6B,CAAC,CAAC;AACvG;AAEA,SAAgB,eAAe,SAAe;CAC5C,MAAM,EAAE,WAAW,wBAAwB;CAC3C,MAAM,aAAa,sBAAsB,MAAM;CAC/C,IAAI,cAAc,MAAM;EACtB,MAAM,UAAU,4BAA4B,SAAS,sBAAsB;EAC3E,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,MAAM,SAAS,4BAA4B,SAAS;EAClD,QAAQ;EACR,QAAQ;EACR,UAAU;EACV,SAAS;EACT,MAAM;EACN,SAAS;CACX,CAAC;CACD,OAAO,QAAQ,QAAQ,MAAM;AAC/B;AAEA,eAAsB,uBAAuB,SAAe;CAC1D,MAAM,OAAO,OAAO,SAAS,QAAQ,EAAE;CACvC,IAAI;EACF,MAAM,mBAAmB,IAAI;CAC/B,SACO,OAAO;
|
|
1
|
+
{"version":3,"file":"interactionApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/interactionApi.ts"],"sourcesContent":["import { openRuntimeUrl } from '../host'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n readClipboardData,\n resolveScanCodeResult,\n writeClipboardData,\n} from './interaction'\nimport { getGlobalDialogHandlers } from './ui'\n\nexport function openCustomerServiceChatBridge(options?: any) {\n const url = options?.url?.trim() ?? ''\n if (url) {\n try {\n openRuntimeUrl(url, '_blank', 'noopener,noreferrer')\n }\n catch {\n // ignore browser popup restrictions\n }\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openCustomerServiceChat:ok' }))\n}\n\nexport function scanCodeBridge(options?: any) {\n const { prompt } = getGlobalDialogHandlers()\n const resultText = resolveScanCodeResult(prompt)\n if (resultText == null) {\n const failure = callMiniProgramAsyncFailure(options, 'scanCode:fail cancel')\n return Promise.reject(failure)\n }\n const result = callMiniProgramAsyncSuccess(options, {\n errMsg: 'scanCode:ok',\n result: resultText,\n scanType: 'QR_CODE',\n charSet: 'utf-8',\n path: resultText,\n rawData: resultText,\n })\n return Promise.resolve(result)\n}\n\nexport async function setClipboardDataBridge(options?: any) {\n const data = String(options?.data ?? '')\n try {\n await writeClipboardData(data)\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `setClipboardData:fail ${message}`)\n return Promise.reject(failure)\n }\n return callMiniProgramAsyncSuccess(options, { errMsg: 'setClipboardData:ok' })\n}\n\nexport async function getClipboardDataBridge(options?: any) {\n try {\n const data = await readClipboardData()\n return callMiniProgramAsyncSuccess(options, { errMsg: 'getClipboardData:ok', data })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getClipboardData:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;;;AAYA,SAAgB,8BAA8B,SAAe;CAC3D,MAAM,MAAM,SAAS,KAAK,KAAK,KAAK;CACpC,IAAI,KACF,IAAI;EACF,eAAe,KAAK,UAAU,qBAAqB;CACrD,QACM,CAEN;CAEF,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,6BAA6B,CAAC,CAAC;AACvG;AAEA,SAAgB,eAAe,SAAe;CAC5C,MAAM,EAAE,WAAW,wBAAwB;CAC3C,MAAM,aAAa,sBAAsB,MAAM;CAC/C,IAAI,cAAc,MAAM;EACtB,MAAM,UAAU,4BAA4B,SAAS,sBAAsB;EAC3E,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,MAAM,SAAS,4BAA4B,SAAS;EAClD,QAAQ;EACR,QAAQ;EACR,UAAU;EACV,SAAS;EACT,MAAM;EACN,SAAS;CACX,CAAC;CACD,OAAO,QAAQ,QAAQ,MAAM;AAC/B;AAEA,eAAsB,uBAAuB,SAAe;CAC1D,MAAM,OAAO,OAAO,SAAS,QAAQ,EAAE;CACvC,IAAI;EACF,MAAM,mBAAmB,IAAI;CAC/B,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,4BAA4B,SAAS,yBAAyB,SAAS;EACvF,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,OAAO,4BAA4B,SAAS,EAAE,QAAQ,sBAAsB,CAAC;AAC/E;AAEA,eAAsB,uBAAuB,SAAe;CAC1D,IAAI;EACF,MAAM,OAAO,MAAM,kBAAkB;EACrC,OAAO,4BAA4B,SAAS;GAAE,QAAQ;GAAuB;EAAK,CAAC;CACrF,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,4BAA4B,SAAS,yBAAyB,SAAS;EACvF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF"}
|
|
@@ -79,7 +79,8 @@ function openLocationBridge(options) {
|
|
|
79
79
|
return Promise.reject(failure);
|
|
80
80
|
}
|
|
81
81
|
const query = `${latitude},${longitude}`;
|
|
82
|
-
|
|
82
|
+
const target = `https://maps.google.com/?q=${encodeURIComponent(query)}`;
|
|
83
|
+
openTargetInNewWindow(target);
|
|
83
84
|
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "openLocation:ok" }));
|
|
84
85
|
}
|
|
85
86
|
function getLocationBridge(options) {
|
|
@@ -88,7 +89,8 @@ function getLocationBridge(options) {
|
|
|
88
89
|
errMsg: "getLocation:ok",
|
|
89
90
|
...location
|
|
90
91
|
})).catch((error) => {
|
|
91
|
-
const
|
|
92
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
93
|
+
const failure = callMiniProgramAsyncFailure(options, `getLocation:fail ${message}`);
|
|
92
94
|
return Promise.reject(failure);
|
|
93
95
|
});
|
|
94
96
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locationApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/locationApi.ts"],"sourcesContent":["import { openRuntimeUrl } from '../host'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n normalizeFuzzyCoordinate,\n normalizeGeoNumber,\n parseChooseAddressPromptInput,\n parseChooseLocationPromptInput,\n readCurrentLocation,\n readPresetChooseAddress,\n readPresetChooseLocation,\n readPresetFuzzyLocation,\n} from './location'\nimport { openTargetInNewWindow } from './mediaActions'\nimport { getGlobalDialogHandlers } from './ui'\n\nexport function makePhoneCallBridge(options?: any) {\n const phoneNumber = typeof options?.phoneNumber === 'string' ? options.phoneNumber.trim() : ''\n if (!phoneNumber) {\n const failure = callMiniProgramAsyncFailure(options, 'makePhoneCall:fail invalid phoneNumber')\n return Promise.reject(failure)\n }\n try {\n openRuntimeUrl(`tel:${encodeURIComponent(phoneNumber)}`, '_self')\n }\n catch {\n // ignore browser restrictions and keep API-level success semantics\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'makePhoneCall:ok' }))\n}\n\nexport function chooseAddressBridge(options?: any) {\n const preset = readPresetChooseAddress()\n if (preset) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseAddress:ok',\n ...preset,\n }))\n }\n const { prompt } = getGlobalDialogHandlers()\n if (typeof prompt === 'function') {\n const input = prompt('请输入地址(格式:省,市,区,详细地址,姓名,电话)', '')\n if (input == null) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail cancel')\n return Promise.reject(failure)\n }\n const parsed = parseChooseAddressPromptInput(input)\n if (!parsed) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail invalid input')\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseAddress:ok',\n ...parsed,\n }))\n }\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail address picker is unavailable')\n return Promise.reject(failure)\n}\n\nexport function chooseLocationBridge(options?: any) {\n const preset = readPresetChooseLocation()\n if (preset) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseLocation:ok',\n ...preset,\n }))\n }\n const { prompt } = getGlobalDialogHandlers()\n if (typeof prompt === 'function') {\n const input = prompt('请输入坐标(格式:latitude,longitude)', '')\n if (input == null) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail cancel')\n return Promise.reject(failure)\n }\n const parsed = parseChooseLocationPromptInput(input)\n if (!parsed) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail invalid latitude/longitude')\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseLocation:ok',\n name: '',\n address: '',\n latitude: parsed.latitude,\n longitude: parsed.longitude,\n }))\n }\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail location picker is unavailable')\n return Promise.reject(failure)\n}\n\nexport function openLocationBridge(options?: any) {\n const latitude = options?.latitude\n const longitude = options?.longitude\n if (typeof latitude !== 'number' || Number.isNaN(latitude) || typeof longitude !== 'number' || Number.isNaN(longitude)) {\n const failure = callMiniProgramAsyncFailure(options, 'openLocation:fail invalid latitude/longitude')\n return Promise.reject(failure)\n }\n const query = `${latitude},${longitude}`\n const target = `https://maps.google.com/?q=${encodeURIComponent(query)}`\n openTargetInNewWindow(target)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openLocation:ok' }))\n}\n\nexport function getLocationBridge(options?: any) {\n try {\n return readCurrentLocation(options)\n .then(location => callMiniProgramAsyncSuccess(options, {\n errMsg: 'getLocation:ok',\n ...location,\n }))\n .catch((error) => {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getLocation:fail ${message}`)\n return Promise.reject(failure)\n })\n }\n catch (error) {\n const message = (error as Error).message\n const failure = callMiniProgramAsyncFailure(options, `getLocation:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function getFuzzyLocationBridge(options?: any) {\n const preset = readPresetFuzzyLocation()\n if (preset) {\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getFuzzyLocation:ok',\n ...preset,\n })\n }\n try {\n const location = await getLocationBridge()\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getFuzzyLocation:ok',\n latitude: normalizeFuzzyCoordinate(location.latitude),\n longitude: normalizeFuzzyCoordinate(location.longitude),\n accuracy: Math.max(1000, normalizeGeoNumber(location.accuracy, 1000)),\n })\n }\n catch (error) {\n const message = (error as { errMsg: string }).errMsg\n const failure = callMiniProgramAsyncFailure(options, `getFuzzyLocation:fail ${message}`)\n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B;CAC3C,IAAI,OAAO,WAAW,YAAY;EAChC,MAAM,QAAQ,OAAO,gCAAgC,EAAE;EACvD,IAAI,SAAS,MAAM;GACjB,MAAM,UAAU,4BAA4B,SAAS,4BAA4B;GACjF,OAAO,QAAQ,OAAO,OAAO;EAC/B;EACA,MAAM,SAAS,+BAA+B,KAAK;EACnD,IAAI,CAAC,QAAQ;GACX,MAAM,UAAU,4BAA4B,SAAS,gDAAgD;GACrG,OAAO,QAAQ,OAAO,OAAO;EAC/B;EACA,OAAO,QAAQ,QAAQ,4BAA4B,SAAS;GAC1D,QAAQ;GACR,MAAM;GACN,SAAS;GACT,UAAU,OAAO;GACjB,WAAW,OAAO;EACpB,CAAC,CAAC;CACJ;CACA,MAAM,UAAU,4BAA4B,SAAS,oDAAoD;CACzG,OAAO,QAAQ,OAAO,OAAO;AAC/B;AAEA,SAAgB,mBAAmB,SAAe;CAChD,MAAM,WAAW,SAAS;CAC1B,MAAM,YAAY,SAAS;CAC3B,IAAI,OAAO,aAAa,YAAY,OAAO,MAAM,QAAQ,KAAK,OAAO,cAAc,YAAY,OAAO,MAAM,SAAS,GAAG;EACtH,MAAM,UAAU,4BAA4B,SAAS,8CAA8C;EACnG,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,MAAM,QAAQ,GAAG,SAAS,GAAG;
|
|
1
|
+
{"version":3,"file":"locationApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/locationApi.ts"],"sourcesContent":["import { openRuntimeUrl } from '../host'\nimport {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from './async'\nimport {\n normalizeFuzzyCoordinate,\n normalizeGeoNumber,\n parseChooseAddressPromptInput,\n parseChooseLocationPromptInput,\n readCurrentLocation,\n readPresetChooseAddress,\n readPresetChooseLocation,\n readPresetFuzzyLocation,\n} from './location'\nimport { openTargetInNewWindow } from './mediaActions'\nimport { getGlobalDialogHandlers } from './ui'\n\nexport function makePhoneCallBridge(options?: any) {\n const phoneNumber = typeof options?.phoneNumber === 'string' ? options.phoneNumber.trim() : ''\n if (!phoneNumber) {\n const failure = callMiniProgramAsyncFailure(options, 'makePhoneCall:fail invalid phoneNumber')\n return Promise.reject(failure)\n }\n try {\n openRuntimeUrl(`tel:${encodeURIComponent(phoneNumber)}`, '_self')\n }\n catch {\n // ignore browser restrictions and keep API-level success semantics\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'makePhoneCall:ok' }))\n}\n\nexport function chooseAddressBridge(options?: any) {\n const preset = readPresetChooseAddress()\n if (preset) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseAddress:ok',\n ...preset,\n }))\n }\n const { prompt } = getGlobalDialogHandlers()\n if (typeof prompt === 'function') {\n const input = prompt('请输入地址(格式:省,市,区,详细地址,姓名,电话)', '')\n if (input == null) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail cancel')\n return Promise.reject(failure)\n }\n const parsed = parseChooseAddressPromptInput(input)\n if (!parsed) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail invalid input')\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseAddress:ok',\n ...parsed,\n }))\n }\n const failure = callMiniProgramAsyncFailure(options, 'chooseAddress:fail address picker is unavailable')\n return Promise.reject(failure)\n}\n\nexport function chooseLocationBridge(options?: any) {\n const preset = readPresetChooseLocation()\n if (preset) {\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseLocation:ok',\n ...preset,\n }))\n }\n const { prompt } = getGlobalDialogHandlers()\n if (typeof prompt === 'function') {\n const input = prompt('请输入坐标(格式:latitude,longitude)', '')\n if (input == null) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail cancel')\n return Promise.reject(failure)\n }\n const parsed = parseChooseLocationPromptInput(input)\n if (!parsed) {\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail invalid latitude/longitude')\n return Promise.reject(failure)\n }\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseLocation:ok',\n name: '',\n address: '',\n latitude: parsed.latitude,\n longitude: parsed.longitude,\n }))\n }\n const failure = callMiniProgramAsyncFailure(options, 'chooseLocation:fail location picker is unavailable')\n return Promise.reject(failure)\n}\n\nexport function openLocationBridge(options?: any) {\n const latitude = options?.latitude\n const longitude = options?.longitude\n if (typeof latitude !== 'number' || Number.isNaN(latitude) || typeof longitude !== 'number' || Number.isNaN(longitude)) {\n const failure = callMiniProgramAsyncFailure(options, 'openLocation:fail invalid latitude/longitude')\n return Promise.reject(failure)\n }\n const query = `${latitude},${longitude}`\n const target = `https://maps.google.com/?q=${encodeURIComponent(query)}`\n openTargetInNewWindow(target)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openLocation:ok' }))\n}\n\nexport function getLocationBridge(options?: any) {\n try {\n return readCurrentLocation(options)\n .then(location => callMiniProgramAsyncSuccess(options, {\n errMsg: 'getLocation:ok',\n ...location,\n }))\n .catch((error) => {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `getLocation:fail ${message}`)\n return Promise.reject(failure)\n })\n }\n catch (error) {\n const message = (error as Error).message\n const failure = callMiniProgramAsyncFailure(options, `getLocation:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function getFuzzyLocationBridge(options?: any) {\n const preset = readPresetFuzzyLocation()\n if (preset) {\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getFuzzyLocation:ok',\n ...preset,\n })\n }\n try {\n const location = await getLocationBridge()\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'getFuzzyLocation:ok',\n latitude: normalizeFuzzyCoordinate(location.latitude),\n longitude: normalizeFuzzyCoordinate(location.longitude),\n accuracy: Math.max(1000, normalizeGeoNumber(location.accuracy, 1000)),\n })\n }\n catch (error) {\n const message = (error as { errMsg: string }).errMsg\n const failure = callMiniProgramAsyncFailure(options, `getFuz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,SAAS,oBAAoB,SAAS;GAClF,OAAO,QAAQ,OAAO,OAAO;EAC/B,CAAC;CACL,SACO,OAAO;EACZ,MAAM,UAAW,MAAgB;EACjC,MAAM,UAAU,4BAA4B,SAAS,oBAAoB,SAAS;EAClF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF;AAEA,eAAsB,uBAAuB,SAAe;CAC1D,MAAM,SAAS,wBAAwB;CACvC,IAAI,QACF,OAAO,4BAA4B,SAAS;EAC1C,QAAQ;EACR,GAAG;CACL,CAAC;CAEH,IAAI;EACF,MAAM,WAAW,MAAM,kBAAkB;EACzC,OAAO,4BAA4B,SAAS;GAC1C,QAAQ;GACR,UAAU,yBAAyB,SAAS,QAAQ;GACpD,WAAW,yBAAyB,SAAS,SAAS;GACtD,UAAU,KAAK,IAAI,KAAM,mBAAmB,SAAS,UAAU,GAAI,CAAC;EACtE,CAAC;CACH,SACO,OAAO;EACZ,MAAM,UAAW,MAA6B;EAC9C,MAAM,UAAU,4BAA4B,SAAS,yBAAyB,SAAS;EACvF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF"}
|
|
@@ -40,7 +40,8 @@ function saveFileToDiskBridge(options) {
|
|
|
40
40
|
const failure = callMiniProgramAsyncFailure(options, "saveFileToDisk:fail invalid filePath");
|
|
41
41
|
return Promise.reject(failure);
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
const fileName = typeof options?.fileName === "string" ? options.fileName.trim() : "";
|
|
44
|
+
triggerDownload(filePath, fileName);
|
|
44
45
|
return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: "saveFileToDisk:ok" }));
|
|
45
46
|
}
|
|
46
47
|
function openDocumentBridge(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.mjs","names":[],"sources":["../../../../src/runtime/polyfill/mediaApi/file.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from '../async'\nimport {\n normalizeFilePath,\n resolveOpenDocumentUrl,\n resolveSaveFilePath,\n saveMemoryFile,\n} from '../files'\nimport {\n openTargetInNewWindow,\n triggerDownload,\n} from '../mediaActions'\n\nexport function saveImageToPhotosAlbumBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveImageToPhotosAlbum:fail invalid filePath')\n return Promise.reject(failure)\n }\n triggerDownload(filePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveImageToPhotosAlbum:ok' }))\n}\n\nexport function saveVideoToPhotosAlbumBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveVideoToPhotosAlbum:fail invalid filePath')\n return Promise.reject(failure)\n }\n triggerDownload(filePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveVideoToPhotosAlbum:ok' }))\n}\n\nexport function saveFileBridge(options?: any) {\n const tempFilePath = typeof options?.tempFilePath === 'string' ? options.tempFilePath.trim() : ''\n if (!tempFilePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveFile:fail invalid tempFilePath')\n return Promise.reject(failure)\n }\n const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath)\n saveMemoryFile(tempFilePath, savedFilePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'saveFile:ok',\n savedFilePath,\n }))\n}\n\nexport function saveFileToDiskBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveFileToDisk:fail invalid filePath')\n return Promise.reject(failure)\n }\n const fileName = typeof options?.fileName === 'string' ? options.fileName.trim() : ''\n triggerDownload(filePath, fileName)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveFileToDisk:ok' }))\n}\n\nexport function openDocumentBridge(options?: any) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'openDocument:fail invalid filePath')\n return Promise.reject(failure)\n }\n const target = resolveOpenDocumentUrl(filePath)\n if (!target) {\n const failure = callMiniProgramAsyncFailure(options, 'openDocument:fail document url is unavailable')\n return Promise.reject(failure)\n }\n openTargetInNewWindow(target)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openDocument:ok' }))\n}\n"],"mappings":";;;;;AAeA,SAAgB,6BAA6B,SAAe;CAC1D,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,KAAK,IAAI;CACnF,IAAI,CAAC,UAAU;EACb,MAAM,UAAU,4BAA4B,SAAS,8CAA8C;EACnG,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,gBAAgB,QAAQ;CACxB,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,4BAA4B,CAAC,CAAC;AACtG;AAEA,SAAgB,6BAA6B,SAAe;CAC1D,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,KAAK,IAAI;CACnF,IAAI,CAAC,UAAU;EACb,MAAM,UAAU,4BAA4B,SAAS,8CAA8C;EACnG,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,gBAAgB,QAAQ;CACxB,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,4BAA4B,CAAC,CAAC;AACtG;AAEA,SAAgB,eAAe,SAAe;CAC5C,MAAM,eAAe,OAAO,SAAS,iBAAiB,WAAW,QAAQ,aAAa,KAAK,IAAI;CAC/F,IAAI,CAAC,cAAc;EACjB,MAAM,UAAU,4BAA4B,SAAS,oCAAoC;EACzF,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,MAAM,gBAAgB,oBAAoB,cAAc,SAAS,QAAQ;CACzE,eAAe,cAAc,aAAa;CAC1C,OAAO,QAAQ,QAAQ,4BAA4B,SAAS;EAC1D,QAAQ;EACR;CACF,CAAC,CAAC;AACJ;AAEA,SAAgB,qBAAqB,SAAe;CAClD,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,KAAK,IAAI;CACnF,IAAI,CAAC,UAAU;EACb,MAAM,UAAU,4BAA4B,SAAS,sCAAsC;EAC3F,OAAO,QAAQ,OAAO,OAAO;CAC/B;
|
|
1
|
+
{"version":3,"file":"file.mjs","names":[],"sources":["../../../../src/runtime/polyfill/mediaApi/file.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from '../async'\nimport {\n normalizeFilePath,\n resolveOpenDocumentUrl,\n resolveSaveFilePath,\n saveMemoryFile,\n} from '../files'\nimport {\n openTargetInNewWindow,\n triggerDownload,\n} from '../mediaActions'\n\nexport function saveImageToPhotosAlbumBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveImageToPhotosAlbum:fail invalid filePath')\n return Promise.reject(failure)\n }\n triggerDownload(filePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveImageToPhotosAlbum:ok' }))\n}\n\nexport function saveVideoToPhotosAlbumBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveVideoToPhotosAlbum:fail invalid filePath')\n return Promise.reject(failure)\n }\n triggerDownload(filePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveVideoToPhotosAlbum:ok' }))\n}\n\nexport function saveFileBridge(options?: any) {\n const tempFilePath = typeof options?.tempFilePath === 'string' ? options.tempFilePath.trim() : ''\n if (!tempFilePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveFile:fail invalid tempFilePath')\n return Promise.reject(failure)\n }\n const savedFilePath = resolveSaveFilePath(tempFilePath, options?.filePath)\n saveMemoryFile(tempFilePath, savedFilePath)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, {\n errMsg: 'saveFile:ok',\n savedFilePath,\n }))\n}\n\nexport function saveFileToDiskBridge(options?: any) {\n const filePath = typeof options?.filePath === 'string' ? options.filePath.trim() : ''\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'saveFileToDisk:fail invalid filePath')\n return Promise.reject(failure)\n }\n const fileName = typeof options?.fileName === 'string' ? options.fileName.trim() : ''\n triggerDownload(filePath, fileName)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'saveFileToDisk:ok' }))\n}\n\nexport function openDocumentBridge(options?: any) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n const failure = callMiniProgramAsyncFailure(options, 'openDocument:fail invalid filePath')\n return Promise.reject(failure)\n }\n const target = resolveOpenDocumentUrl(filePath)\n if (!target) {\n const failure = callMiniProgramAsyncFailure(options, 'openDocument:fail document url is unavailable')\n return Promise.reject(failure)\n }\n openTargetInNewWindow(target)\n return Promise.resolve(callMiniProgramAsyncSuccess(options, { errMsg: 'openDocument:ok' }))\n}\n"],"mappings":";;;;;AAeA,SAAgB,6BAA6B,SAAe;CAC1D,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,KAAK,IAAI;CACnF,IAAI,CAAC,UAAU;EACb,MAAM,UAAU,4BAA4B,SAAS,8CAA8C;EACnG,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,gBAAgB,QAAQ;CACxB,OAAO,QAAQ,QAAQ,4BAA4B,SAAS,EAAE,QAAQ,4BAA4B,CAAC,CAAC;AACtG;AAEA,SAAgB,6BAA6B,SAAe;CAC1D,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,KAAK,IAAI;CACnF,IAAI,CAAC,UAAU;EACb,MAAM,UAAU,4BAA4B,SAAS,8CAA8C;EACnG,OAAO,QAAQ,OAAO,OAAO;CAC/B;CACA,gBAAgB,QAAQ;CACxB,OAAO,QAAQ,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seImageBridge(options) {
|
|
|
8
8
|
const count = normalizeChooseImageCount(options?.count);
|
|
9
9
|
try {
|
|
10
10
|
const tempFiles = (await pickChooseImageFiles(count)).map((file) => normalizeChooseImageFile(file));
|
|
11
|
+
const tempFilePaths = tempFiles.map((item) => item.path);
|
|
11
12
|
return callMiniProgramAsyncSuccess(options, {
|
|
12
13
|
errMsg: "chooseImage:ok",
|
|
13
|
-
tempFilePaths
|
|
14
|
+
tempFilePaths,
|
|
14
15
|
tempFiles
|
|
15
16
|
});
|
|
16
17
|
} catch (error) {
|
|
17
|
-
const
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
const failure = callMiniProgramAsyncFailure(options, `chooseImage:fail ${message}`);
|
|
18
20
|
return Promise.reject(failure);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -30,7 +32,8 @@ async function chooseMediaBridge(options) {
|
|
|
30
32
|
tempFiles
|
|
31
33
|
});
|
|
32
34
|
} catch (error) {
|
|
33
|
-
const
|
|
35
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
36
|
+
const failure = callMiniProgramAsyncFailure(options, `chooseMedia:fail ${message}`);
|
|
34
37
|
return Promise.reject(failure);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -45,7 +48,8 @@ async function chooseVideoBridge(options) {
|
|
|
45
48
|
...normalized
|
|
46
49
|
});
|
|
47
50
|
} catch (error) {
|
|
48
|
-
const
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
const failure = callMiniProgramAsyncFailure(options, `chooseVideo:fail ${message}`);
|
|
49
53
|
return Promise.reject(failure);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -53,12 +57,14 @@ async function chooseMessageFileBridge(options) {
|
|
|
53
57
|
const count = normalizeChooseMessageFileCount(options?.count);
|
|
54
58
|
const type = normalizeChooseMessageFileType(options?.type);
|
|
55
59
|
try {
|
|
60
|
+
const tempFiles = (await pickChooseMessageFiles(count, type)).map((file) => normalizeChooseMessageFile(file));
|
|
56
61
|
return callMiniProgramAsyncSuccess(options, {
|
|
57
62
|
errMsg: "chooseMessageFile:ok",
|
|
58
|
-
tempFiles
|
|
63
|
+
tempFiles
|
|
59
64
|
});
|
|
60
65
|
} catch (error) {
|
|
61
|
-
const
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
const failure = callMiniProgramAsyncFailure(options, `chooseMessageFile:fail ${message}`);
|
|
62
68
|
return Promise.reject(failure);
|
|
63
69
|
}
|
|
64
70
|
}
|
|
@@ -67,12 +73,14 @@ async function chooseFileBridge(options) {
|
|
|
67
73
|
const type = normalizeChooseMessageFileType(options?.type);
|
|
68
74
|
const extensions = normalizeChooseFileExtensions(options?.extension);
|
|
69
75
|
try {
|
|
76
|
+
const tempFiles = (await pickChooseFileFiles(count, type, extensions)).map((file) => normalizeChooseMessageFile(file));
|
|
70
77
|
return callMiniProgramAsyncSuccess(options, {
|
|
71
78
|
errMsg: "chooseFile:ok",
|
|
72
|
-
tempFiles
|
|
79
|
+
tempFiles
|
|
73
80
|
});
|
|
74
81
|
} catch (error) {
|
|
75
|
-
const
|
|
82
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
+
const failure = callMiniProgramAsyncFailure(options, `chooseFile:fail ${message}`);
|
|
76
84
|
return Promise.reject(failure);
|
|
77
85
|
}
|
|
78
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picker.mjs","names":[],"sources":["../../../../src/runtime/polyfill/mediaApi/picker.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from '../async'\nimport {\n normalizeChooseFileExtensions,\n normalizeChooseMessageFile,\n normalizeChooseMessageFileCount,\n normalizeChooseMessageFileType,\n pickChooseFileFiles,\n pickChooseMessageFiles,\n} from '../filePicker'\nimport {\n normalizeChooseImageCount,\n normalizeChooseImageFile,\n normalizeChooseMediaCount,\n normalizeChooseMediaFile,\n normalizeChooseMediaTypes,\n pickChooseImageFiles,\n pickChooseMediaFiles,\n} from '../mediaPicker'\nimport {\n normalizeChooseVideoFile,\n pickChooseVideoFile,\n} from '../mediaProcess'\n\nexport async function chooseImageBridge(options?: any) {\n const count = normalizeChooseImageCount(options?.count)\n try {\n const files = await pickChooseImageFiles(count)\n const tempFiles = files.map(file => normalizeChooseImageFile(file))\n const tempFilePaths = tempFiles.map(item => item.path)\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseImage:ok',\n tempFilePaths,\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseImage:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseMediaBridge(options?: any) {\n const count = normalizeChooseMediaCount(options?.count)\n const types = normalizeChooseMediaTypes(options?.mediaType)\n try {\n const files = await pickChooseMediaFiles(count, types)\n const tempFiles = files.map(file => normalizeChooseMediaFile(file))\n const defaultType = types.has('video') && !types.has('image') ? 'video' : 'image'\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseMedia:ok',\n type: tempFiles[0]?.fileType ?? defaultType,\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseMedia:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseVideoBridge(options?: any) {\n try {\n const file = await pickChooseVideoFile()\n if (!file) {\n throw new TypeError('no file selected')\n }\n const normalized = normalizeChooseVideoFile(file)\n if (!normalized) {\n throw new TypeError('selected file is not a video')\n }\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseVideo:ok',\n ...normalized,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseVideo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseMessageFileBridge(options?: any) {\n const count = normalizeChooseMessageFileCount(options?.count)\n const type = normalizeChooseMessageFileType(options?.type)\n try {\n const files = await pickChooseMessageFiles(count, type)\n const tempFiles = files.map(file => normalizeChooseMessageFile(file))\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseMessageFile:ok',\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseMessageFile:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseFileBridge(options?: any) {\n const count = normalizeChooseMessageFileCount(options?.count)\n const type = normalizeChooseMessageFileType(options?.type)\n const extensions = normalizeChooseFileExtensions(options?.extension)\n try {\n const files = await pickChooseFileFiles(count, type, extensions)\n const tempFiles = files.map(file => normalizeChooseMessageFile(file))\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseFile:ok',\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseFile:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;;;AA0BA,eAAsB,kBAAkB,SAAe;CACrD,MAAM,QAAQ,0BAA0B,SAAS,KAAK;CACtD,IAAI;EAEF,MAAM,aAAY,MADE,qBAAqB,KAAK,EACvB,CAAC,KAAI,SAAQ,yBAAyB,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"picker.mjs","names":[],"sources":["../../../../src/runtime/polyfill/mediaApi/picker.ts"],"sourcesContent":["import {\n callMiniProgramAsyncFailure,\n callMiniProgramAsyncSuccess,\n} from '../async'\nimport {\n normalizeChooseFileExtensions,\n normalizeChooseMessageFile,\n normalizeChooseMessageFileCount,\n normalizeChooseMessageFileType,\n pickChooseFileFiles,\n pickChooseMessageFiles,\n} from '../filePicker'\nimport {\n normalizeChooseImageCount,\n normalizeChooseImageFile,\n normalizeChooseMediaCount,\n normalizeChooseMediaFile,\n normalizeChooseMediaTypes,\n pickChooseImageFiles,\n pickChooseMediaFiles,\n} from '../mediaPicker'\nimport {\n normalizeChooseVideoFile,\n pickChooseVideoFile,\n} from '../mediaProcess'\n\nexport async function chooseImageBridge(options?: any) {\n const count = normalizeChooseImageCount(options?.count)\n try {\n const files = await pickChooseImageFiles(count)\n const tempFiles = files.map(file => normalizeChooseImageFile(file))\n const tempFilePaths = tempFiles.map(item => item.path)\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseImage:ok',\n tempFilePaths,\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseImage:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseMediaBridge(options?: any) {\n const count = normalizeChooseMediaCount(options?.count)\n const types = normalizeChooseMediaTypes(options?.mediaType)\n try {\n const files = await pickChooseMediaFiles(count, types)\n const tempFiles = files.map(file => normalizeChooseMediaFile(file))\n const defaultType = types.has('video') && !types.has('image') ? 'video' : 'image'\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseMedia:ok',\n type: tempFiles[0]?.fileType ?? defaultType,\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseMedia:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseVideoBridge(options?: any) {\n try {\n const file = await pickChooseVideoFile()\n if (!file) {\n throw new TypeError('no file selected')\n }\n const normalized = normalizeChooseVideoFile(file)\n if (!normalized) {\n throw new TypeError('selected file is not a video')\n }\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseVideo:ok',\n ...normalized,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseVideo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseMessageFileBridge(options?: any) {\n const count = normalizeChooseMessageFileCount(options?.count)\n const type = normalizeChooseMessageFileType(options?.type)\n try {\n const files = await pickChooseMessageFiles(count, type)\n const tempFiles = files.map(file => normalizeChooseMessageFile(file))\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseMessageFile:ok',\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseMessageFile:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n\nexport async function chooseFileBridge(options?: any) {\n const count = normalizeChooseMessageFileCount(options?.count)\n const type = normalizeChooseMessageFileType(options?.type)\n const extensions = normalizeChooseFileExtensions(options?.extension)\n try {\n const files = await pickChooseFileFiles(count, type, extensions)\n const tempFiles = files.map(file => normalizeChooseMessageFile(file))\n return callMiniProgramAsyncSuccess(options, {\n errMsg: 'chooseFile:ok',\n tempFiles,\n })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callMiniProgramAsyncFailure(options, `chooseFile:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;;;AA0BA,eAAsB,kBAAkB,SAAe;CACrD,MAAM,QAAQ,0BAA0B,SAAS,KAAK;CACtD,IAAI;EAEF,MAAM,aAAY,MADE,qBAAqB,KAAK,EACvB,CAAC,KAAI,SAAQ,yBAAyB,IAAI,CAAC;EAClE,MAAM,gBAAgB,UAAU,KAAI,SAAQ,KAAK,IAAI;EACrD,OAAO,4BAA4B,SAAS;GAC1C,QAAQ;GACR;GACA;EACF,CAAC;CACH,SACO,OAAO;EACZ,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,4BAA4B,SAAS,oBAAoB,SAAS;EAClF,OAAO,QAAQ,OAAO,OAAO;CAC/B;AACF;AAEA,eAAsB,kBAAkB,SAAe;CACrD,MAAM,QAAQ,0BAA0B,SAAS,KAAK;CACtD,MAAM,QAAQ,0BAA0B,SAAS,SAAS;CAC1D,IAAI;EAEF,MAAM,aAAY,MADE,qBAAqB,OAAO,KAAK,EAC9B,CAAC,KAAI,SAAQ,yBAAyB,IAAI,CAAC;EAClE,MAA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