@weapp-vite/web 1.3.14 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/compiler/wxml/attributes.mjs +93 -0
- package/dist/compiler/wxml/attributes.mjs.map +1 -0
- package/dist/compiler/wxml/compile.mjs +158 -0
- package/dist/compiler/wxml/compile.mjs.map +1 -0
- package/dist/compiler/wxml/dependency.mjs +31 -0
- package/dist/compiler/wxml/dependency.mjs.map +1 -0
- package/dist/compiler/wxml/interpolation.mjs +142 -0
- package/dist/compiler/wxml/interpolation.mjs.map +1 -0
- package/dist/compiler/wxml/navigation.mjs +85 -0
- package/dist/compiler/wxml/navigation.mjs.map +1 -0
- package/dist/compiler/wxml/parser.mjs +41 -0
- package/dist/compiler/wxml/parser.mjs.map +1 -0
- package/dist/compiler/wxml/renderer.mjs +114 -0
- package/dist/compiler/wxml/renderer.mjs.map +1 -0
- package/dist/compiler/wxml/specialNodes.mjs +84 -0
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -0
- package/dist/compiler/wxs.mjs +83 -0
- package/dist/compiler/wxs.mjs.map +1 -0
- package/dist/css/wxss.d.mts +25 -0
- package/dist/css/wxss.mjs +17 -0
- package/dist/css/wxss.mjs.map +1 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +18 -3
- package/dist/plugin/constants.mjs +43 -0
- package/dist/plugin/constants.mjs.map +1 -0
- package/dist/plugin/entry.mjs +29 -0
- package/dist/plugin/entry.mjs.map +1 -0
- package/dist/plugin/files.mjs +58 -0
- package/dist/plugin/files.mjs.map +1 -0
- package/dist/plugin/index.d.mts +33 -0
- package/dist/plugin/index.mjs +188 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/plugin/navigation.mjs +20 -0
- package/dist/plugin/navigation.mjs.map +1 -0
- package/dist/plugin/path.mjs +85 -0
- package/dist/plugin/path.mjs.map +1 -0
- package/dist/plugin/register.mjs +83 -0
- package/dist/plugin/register.mjs.map +1 -0
- package/dist/plugin/scan.mjs +195 -0
- package/dist/plugin/scan.mjs.map +1 -0
- package/dist/plugin/scanConfig.mjs +45 -0
- package/dist/plugin/scanConfig.mjs.map +1 -0
- package/dist/plugin/state.mjs +22 -0
- package/dist/plugin/state.mjs.map +1 -0
- package/dist/plugin/types.d.mts +46 -0
- package/dist/plugin.d.mts +3 -2
- package/dist/plugin.mjs +3 -2
- package/dist/runtime/button/helpers.mjs +92 -0
- package/dist/runtime/button/helpers.mjs.map +1 -0
- package/dist/runtime/button/index.d.mts +9 -0
- package/dist/runtime/button/index.mjs +198 -0
- package/dist/runtime/button/index.mjs.map +1 -0
- package/dist/runtime/button/style.mjs +168 -0
- package/dist/runtime/button/style.mjs.map +1 -0
- package/dist/runtime/component/behavior.mjs +98 -0
- package/dist/runtime/component/behavior.mjs.map +1 -0
- package/dist/runtime/component/constants.mjs +8 -0
- package/dist/runtime/component/constants.mjs.map +1 -0
- package/dist/runtime/component/dom.mjs +26 -0
- package/dist/runtime/component/dom.mjs.map +1 -0
- package/dist/runtime/component/element.mjs +208 -0
- package/dist/runtime/component/element.mjs.map +1 -0
- package/dist/runtime/component/events.mjs +48 -0
- package/dist/runtime/component/events.mjs.map +1 -0
- package/dist/runtime/component/index.d.mts +7 -0
- package/dist/runtime/component/index.mjs +44 -0
- package/dist/runtime/component/index.mjs.map +1 -0
- package/dist/runtime/component/state.mjs +63 -0
- package/dist/runtime/component/state.mjs.map +1 -0
- package/dist/runtime/component/types.d.mts +49 -0
- package/dist/runtime/component/utils.mjs +39 -0
- package/dist/runtime/component/utils.mjs.map +1 -0
- package/dist/runtime/execution.d.mts +7 -0
- package/dist/runtime/execution.mjs +37 -0
- package/dist/runtime/execution.mjs.map +1 -0
- package/dist/runtime/index.d.mts +16 -2
- package/dist/runtime/index.mjs +16 -2
- package/dist/runtime/legacyTemplate/dom.mjs +131 -0
- package/dist/runtime/legacyTemplate/dom.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/expression.mjs +113 -0
- package/dist/runtime/legacyTemplate/expression.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/index.d.mts +9 -0
- package/dist/runtime/legacyTemplate/index.mjs +131 -0
- package/dist/runtime/legacyTemplate/index.mjs.map +1 -0
- package/dist/runtime/legacyTemplate/types.d.mts +6 -0
- package/dist/runtime/navigationBar/index.d.mts +10 -0
- package/dist/runtime/navigationBar/index.mjs +162 -0
- package/dist/runtime/navigationBar/index.mjs.map +1 -0
- package/dist/runtime/navigationBar/style.mjs +108 -0
- package/dist/runtime/navigationBar/style.mjs.map +1 -0
- package/dist/runtime/polyfill/ad.mjs +150 -0
- package/dist/runtime/polyfill/ad.mjs.map +1 -0
- package/dist/runtime/polyfill/appState.mjs +31 -0
- package/dist/runtime/polyfill/appState.mjs.map +1 -0
- package/dist/runtime/polyfill/async.mjs +31 -0
- package/dist/runtime/polyfill/async.mjs.map +1 -0
- package/dist/runtime/polyfill/auth.mjs +120 -0
- package/dist/runtime/polyfill/auth.mjs.map +1 -0
- package/dist/runtime/polyfill/authApi.mjs +101 -0
- package/dist/runtime/polyfill/authApi.mjs.map +1 -0
- package/dist/runtime/polyfill/background.mjs +31 -0
- package/dist/runtime/polyfill/background.mjs.map +1 -0
- package/dist/runtime/polyfill/canvasContext.mjs +115 -0
- package/dist/runtime/polyfill/canvasContext.mjs.map +1 -0
- package/dist/runtime/polyfill/capability.mjs +17 -0
- package/dist/runtime/polyfill/capability.mjs.map +1 -0
- package/dist/runtime/polyfill/cloud.mjs +39 -0
- package/dist/runtime/polyfill/cloud.mjs.map +1 -0
- package/dist/runtime/polyfill/device.mjs +44 -0
- package/dist/runtime/polyfill/device.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceApi.mjs +31 -0
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +102 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +144 -0
- package/dist/runtime/polyfill/deviceAuthSystemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/filePicker.mjs +158 -0
- package/dist/runtime/polyfill/filePicker.mjs.map +1 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs +45 -0
- package/dist/runtime/polyfill/fileSystemManager.mjs.map +1 -0
- package/dist/runtime/polyfill/files.mjs +118 -0
- package/dist/runtime/polyfill/files.mjs.map +1 -0
- package/dist/runtime/polyfill/index.d.mts +40 -0
- package/dist/runtime/polyfill/index.mjs +99 -0
- package/dist/runtime/polyfill/index.mjs.map +1 -0
- package/dist/runtime/polyfill/interaction.mjs +38 -0
- package/dist/runtime/polyfill/interaction.mjs.map +1 -0
- package/dist/runtime/polyfill/interactionApi.mjs +54 -0
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -0
- package/dist/runtime/polyfill/location.mjs +106 -0
- package/dist/runtime/polyfill/location.mjs.map +1 -0
- package/dist/runtime/polyfill/locationApi.mjs +120 -0
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaActions.mjs +52 -0
- package/dist/runtime/polyfill/mediaActions.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs +63 -0
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs +59 -0
- package/dist/runtime/polyfill/mediaApi/info.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs +82 -0
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs +39 -0
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs +46 -0
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaInfo.mjs +136 -0
- package/dist/runtime/polyfill/mediaInfo.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaPicker.mjs +213 -0
- package/dist/runtime/polyfill/mediaPicker.mjs.map +1 -0
- package/dist/runtime/polyfill/mediaProcess.mjs +65 -0
- package/dist/runtime/polyfill/mediaProcess.mjs.map +1 -0
- package/dist/runtime/polyfill/menuApi.mjs +70 -0
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs +65 -0
- package/dist/runtime/polyfill/navigationBarRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/network/request.mjs +162 -0
- package/dist/runtime/polyfill/network/request.mjs.map +1 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs +49 -0
- package/dist/runtime/polyfill/network/requestBridge.mjs.map +1 -0
- package/dist/runtime/polyfill/network/status.mjs +55 -0
- package/dist/runtime/polyfill/network/status.mjs.map +1 -0
- package/dist/runtime/polyfill/platformApi.mjs +33 -0
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -0
- package/dist/runtime/polyfill/platformRuntime.mjs +120 -0
- package/dist/runtime/polyfill/platformRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs +36 -0
- package/dist/runtime/polyfill/routeRuntime/dom.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +83 -0
- package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/options.d.mts +33 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs +76 -0
- package/dist/runtime/polyfill/routeRuntime/options.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs +35 -0
- package/dist/runtime/polyfill/routeRuntime/url.mjs.map +1 -0
- package/dist/runtime/polyfill/routeRuntime.d.mts +43 -0
- package/dist/runtime/polyfill/routeRuntime.mjs +202 -0
- package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +26 -0
- package/dist/runtime/polyfill/runtimeCapabilityApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeDataApi.d.mts +79 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs +134 -0
- package/dist/runtime/polyfill/runtimeDataApi.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs +40 -0
- package/dist/runtime/polyfill/runtimeInfra.mjs.map +1 -0
- package/dist/runtime/polyfill/runtimeOps.mjs +62 -0
- package/dist/runtime/polyfill/runtimeOps.mjs.map +1 -0
- package/dist/runtime/polyfill/selectorQuery.mjs +204 -0
- package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -0
- package/dist/runtime/polyfill/storage.mjs +103 -0
- package/dist/runtime/polyfill/storage.mjs.map +1 -0
- package/dist/runtime/polyfill/storageAsync.mjs +62 -0
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -0
- package/dist/runtime/polyfill/subscribe.mjs +30 -0
- package/dist/runtime/polyfill/subscribe.mjs.map +1 -0
- package/dist/runtime/polyfill/system.mjs +111 -0
- package/dist/runtime/polyfill/system.mjs.map +1 -0
- package/dist/runtime/polyfill/systemApi.mjs +65 -0
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -0
- package/dist/runtime/polyfill/types/base.d.mts +12 -0
- package/dist/runtime/polyfill/types/common.d.mts +126 -0
- package/dist/runtime/polyfill/types/locationRuntime.d.mts +151 -0
- package/dist/runtime/polyfill/types/mediaAuth.d.mts +152 -0
- package/dist/runtime/polyfill/types/platformRuntime.d.mts +141 -0
- package/dist/runtime/polyfill/types/systemAuth.d.mts +122 -0
- package/dist/runtime/polyfill/ui.mjs +135 -0
- package/dist/runtime/polyfill/ui.mjs.map +1 -0
- package/dist/runtime/polyfill/uiFeedback.mjs +35 -0
- package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -0
- package/dist/runtime/polyfill/uiMediaApi.d.mts +172 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs +162 -0
- package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -0
- package/dist/runtime/polyfill/videoContext.mjs +56 -0
- package/dist/runtime/polyfill/videoContext.mjs.map +1 -0
- package/dist/runtime/polyfill/vkSession.mjs +58 -0
- package/dist/runtime/polyfill/vkSession.mjs.map +1 -0
- package/dist/runtime/polyfill/windowResize.mjs +39 -0
- package/dist/runtime/polyfill/windowResize.mjs.map +1 -0
- package/dist/runtime/polyfill/worker.mjs +77 -0
- package/dist/runtime/polyfill/worker.mjs.map +1 -0
- package/dist/runtime/polyfill.d.mts +5 -0
- package/dist/runtime/renderContext.d.mts +21 -0
- package/dist/runtime/renderContext.mjs +147 -0
- package/dist/runtime/renderContext.mjs.map +1 -0
- package/dist/runtime/rpx.d.mts +9 -0
- package/dist/runtime/rpx.mjs +27 -0
- package/dist/runtime/rpx.mjs.map +1 -0
- package/dist/runtime/style.d.mts +6 -0
- package/dist/runtime/style.mjs +37 -0
- package/dist/runtime/style.mjs.map +1 -0
- package/dist/runtime/template.d.mts +10 -0
- package/dist/runtime/warning.d.mts +10 -0
- package/dist/runtime/warning.mjs +43 -0
- package/dist/runtime/warning.mjs.map +1 -0
- package/dist/{slugify-B4l45KNs.mjs → shared/slugify.mjs} +3 -1
- package/dist/shared/slugify.mjs.map +1 -0
- package/dist/shared/wxml.mjs +64 -0
- package/dist/shared/wxml.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/index-w9xxIH-l.d.mts +0 -1229
- package/dist/plugin-BARxSPO8.mjs +0 -1567
- package/dist/plugin-DP2iPVmw.d.mts +0 -96
- package/dist/runtime-D6j2_x_N.mjs +0 -6251
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { callWxAsyncFailure, callWxAsyncSuccess } from "./async.mjs";
|
|
2
|
+
import { readBatteryInfoSnapshot, readBatteryInfoSyncSnapshot, vibrateDevice } from "./device.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/polyfill/deviceApi.ts
|
|
5
|
+
function vibrateShortBridge(options) {
|
|
6
|
+
try {
|
|
7
|
+
vibrateDevice(options?.type);
|
|
8
|
+
return Promise.resolve(callWxAsyncSuccess(options, { errMsg: "vibrateShort:ok" }));
|
|
9
|
+
} catch (error) {
|
|
10
|
+
const failure = callWxAsyncFailure(options, `vibrateShort:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
11
|
+
return Promise.reject(failure);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getBatteryInfoSyncBridge() {
|
|
15
|
+
return readBatteryInfoSyncSnapshot();
|
|
16
|
+
}
|
|
17
|
+
async function getBatteryInfoBridge(options) {
|
|
18
|
+
try {
|
|
19
|
+
return callWxAsyncSuccess(options, {
|
|
20
|
+
errMsg: "getBatteryInfo:ok",
|
|
21
|
+
...await readBatteryInfoSnapshot()
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
const failure = callWxAsyncFailure(options, `getBatteryInfo:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
25
|
+
return Promise.reject(failure);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { getBatteryInfoBridge, getBatteryInfoSyncBridge, vibrateShortBridge };
|
|
31
|
+
//# sourceMappingURL=deviceApi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceApi.ts"],"sourcesContent":["import {\n callWxAsyncFailure,\n callWxAsyncSuccess,\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(callWxAsyncSuccess(options, { errMsg: 'vibrateShort:ok' }))\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n const failure = callWxAsyncFailure(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 callWxAsyncSuccess(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 = callWxAsyncFailure(options, `getBatteryInfo:fail ${message}`)\n return Promise.reject(failure)\n }\n}\n"],"mappings":";;;;AAUA,SAAgB,mBAAmB,SAAe;AAChD,KAAI;AACF,gBAAc,SAAS,KAAK;AAC5B,SAAO,QAAQ,QAAQ,mBAAmB,SAAS,EAAE,QAAQ,mBAAmB,CAAC,CAAC;UAE7E,OAAO;EAEZ,MAAM,UAAU,mBAAmB,SAAS,qBAD5B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACK;AAC3E,SAAO,QAAQ,OAAO,QAAQ;;;AAIlC,SAAgB,2BAA2B;AACzC,QAAO,6BAA6B;;AAGtC,eAAsB,qBAAqB,SAAe;AACxD,KAAI;AAEF,SAAO,mBAAmB,SAAS;GACjC,QAAQ;GACR,GAHkB,MAAM,yBAAyB;GAIlD,CAAC;UAEG,OAAO;EAEZ,MAAM,UAAU,mBAAmB,SAAS,uBAD5B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACO;AAC7E,SAAO,QAAQ,OAAO,QAAQ"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { WxAsyncOptions } from "./types/base.mjs";
|
|
2
|
+
import { GetFuzzyLocationOptions, GetLocationOptions, GetNetworkTypeOptions, NetworkStatusChangeCallback, WindowResizeCallback } from "./types/locationRuntime.mjs";
|
|
3
|
+
import { AuthorizeOptions, GetSettingOptions, OpenSettingOptions } from "./types/mediaAuth.mjs";
|
|
4
|
+
import { BatteryInfo, GetBatteryInfoSuccessResult, VibrateShortOptions } from "./types/platformRuntime.mjs";
|
|
5
|
+
import { AccountInfoSync, AppAuthorizeSetting, AppBaseInfo, CheckSessionOptions, DeviceInfo, GetSystemInfoOptions, GetUserInfoOptions, GetUserProfileOptions, LoginOptions, MenuButtonBoundingClientRect, OpenAppAuthorizeSettingOptions, SystemInfo, SystemSetting, WindowInfo } from "./types/systemAuth.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/runtime/polyfill/deviceAuthSystemApi.d.ts
|
|
8
|
+
declare function vibrateShort(options?: VibrateShortOptions): Promise<{
|
|
9
|
+
errMsg: string;
|
|
10
|
+
}>;
|
|
11
|
+
declare function getBatteryInfoSync(): BatteryInfo;
|
|
12
|
+
declare function getBatteryInfo(options?: WxAsyncOptions<GetBatteryInfoSuccessResult>): Promise<{
|
|
13
|
+
level: number;
|
|
14
|
+
isCharging: boolean;
|
|
15
|
+
errMsg: string;
|
|
16
|
+
}>;
|
|
17
|
+
declare function getLocation(options?: GetLocationOptions): Promise<{
|
|
18
|
+
latitude: number;
|
|
19
|
+
longitude: number;
|
|
20
|
+
speed: number;
|
|
21
|
+
accuracy: number;
|
|
22
|
+
altitude: number;
|
|
23
|
+
verticalAccuracy: number;
|
|
24
|
+
horizontalAccuracy: number;
|
|
25
|
+
errMsg: string;
|
|
26
|
+
}>;
|
|
27
|
+
declare function getFuzzyLocation(options?: GetFuzzyLocationOptions): Promise<{
|
|
28
|
+
latitude: number;
|
|
29
|
+
longitude: number;
|
|
30
|
+
accuracy: number;
|
|
31
|
+
errMsg: string;
|
|
32
|
+
}>;
|
|
33
|
+
declare function getSetting(options?: GetSettingOptions): Promise<{
|
|
34
|
+
errMsg: string;
|
|
35
|
+
authSetting: Record<string, boolean>;
|
|
36
|
+
}>;
|
|
37
|
+
declare function authorize(options?: AuthorizeOptions): Promise<{
|
|
38
|
+
errMsg: string;
|
|
39
|
+
}>;
|
|
40
|
+
declare function openSetting(options?: OpenSettingOptions): Promise<{
|
|
41
|
+
errMsg: string;
|
|
42
|
+
authSetting: Record<string, boolean>;
|
|
43
|
+
}>;
|
|
44
|
+
declare function getAppAuthorizeSetting(): AppAuthorizeSetting;
|
|
45
|
+
declare function openAppAuthorizeSetting(options?: OpenAppAuthorizeSettingOptions): Promise<{
|
|
46
|
+
errMsg: string;
|
|
47
|
+
}>;
|
|
48
|
+
declare function getNetworkType(options?: GetNetworkTypeOptions): Promise<any>;
|
|
49
|
+
declare function onNetworkStatusChange(callback: NetworkStatusChangeCallback): void;
|
|
50
|
+
declare function offNetworkStatusChange(callback?: NetworkStatusChangeCallback): void;
|
|
51
|
+
declare function getWindowInfo(): WindowInfo;
|
|
52
|
+
declare function onWindowResize(callback: WindowResizeCallback): void;
|
|
53
|
+
declare function offWindowResize(callback?: WindowResizeCallback): void;
|
|
54
|
+
declare function getSystemInfoSync(): SystemInfo;
|
|
55
|
+
declare function getSystemInfo(options?: GetSystemInfoOptions): Promise<any>;
|
|
56
|
+
declare function getDeviceInfo(): DeviceInfo;
|
|
57
|
+
declare function getSystemSetting(): SystemSetting;
|
|
58
|
+
declare function login(options?: LoginOptions): Promise<{
|
|
59
|
+
errMsg: string;
|
|
60
|
+
code: string;
|
|
61
|
+
}>;
|
|
62
|
+
declare function checkSession(options?: CheckSessionOptions): Promise<{
|
|
63
|
+
errMsg: string;
|
|
64
|
+
}>;
|
|
65
|
+
declare function getUserInfo(options?: GetUserInfoOptions): Promise<{
|
|
66
|
+
errMsg: "getUserInfo:ok" | "getUserProfile:ok";
|
|
67
|
+
userInfo: {
|
|
68
|
+
nickName: string;
|
|
69
|
+
avatarUrl: string;
|
|
70
|
+
gender: 0 | 1 | 2;
|
|
71
|
+
country: string;
|
|
72
|
+
province: string;
|
|
73
|
+
city: string;
|
|
74
|
+
language: "en" | "zh_CN" | "zh_TW";
|
|
75
|
+
};
|
|
76
|
+
rawData: string;
|
|
77
|
+
signature: string;
|
|
78
|
+
encryptedData: string;
|
|
79
|
+
iv: string;
|
|
80
|
+
}>;
|
|
81
|
+
declare function getUserProfile(options?: GetUserProfileOptions): Promise<{
|
|
82
|
+
errMsg: "getUserInfo:ok" | "getUserProfile:ok";
|
|
83
|
+
userInfo: {
|
|
84
|
+
nickName: string;
|
|
85
|
+
avatarUrl: string;
|
|
86
|
+
gender: 0 | 1 | 2;
|
|
87
|
+
country: string;
|
|
88
|
+
province: string;
|
|
89
|
+
city: string;
|
|
90
|
+
language: "en" | "zh_CN" | "zh_TW";
|
|
91
|
+
};
|
|
92
|
+
rawData: string;
|
|
93
|
+
signature: string;
|
|
94
|
+
encryptedData: string;
|
|
95
|
+
iv: string;
|
|
96
|
+
}>;
|
|
97
|
+
declare function getAccountInfoSync(): AccountInfoSync;
|
|
98
|
+
declare function getAppBaseInfo(): AppBaseInfo;
|
|
99
|
+
declare function getMenuButtonBoundingClientRect(): MenuButtonBoundingClientRect;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { authorize, checkSession, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort };
|
|
102
|
+
//# sourceMappingURL=deviceAuthSystemApi.d.mts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { authorizeBridge, checkSessionBridge, getAppAuthorizeSettingBridge, getSettingBridge, getSystemSettingBridge, getUserInfoBridge, getUserProfileBridge, loginBridge, openAppAuthorizeSettingBridge, openSettingBridge } from "./authApi.mjs";
|
|
3
|
+
import { getBatteryInfoBridge, getBatteryInfoSyncBridge, vibrateShortBridge } from "./deviceApi.mjs";
|
|
4
|
+
import { getFuzzyLocationBridge, getLocationBridge } from "./locationApi.mjs";
|
|
5
|
+
import { getNetworkTypeBridge } from "./menuApi.mjs";
|
|
6
|
+
import { offNetworkStatusChangeBridge, offWindowResizeBridge, onNetworkStatusChangeBridge, onWindowResizeBridge } from "./runtimeCapabilityApi.mjs";
|
|
7
|
+
import { resolveDeviceOrientation } from "./system.mjs";
|
|
8
|
+
import { getAccountInfoSyncBridge, getAppBaseInfoBridge, getDeviceInfoBridge, getMenuButtonBoundingClientRectBridge, getSystemInfoBridge, getSystemInfoSyncBridge, getWindowInfoBridge } from "./systemApi.mjs";
|
|
9
|
+
|
|
10
|
+
//#region src/runtime/polyfill/deviceAuthSystemApi.ts
|
|
11
|
+
var deviceAuthSystemApi_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
authorize: () => authorize,
|
|
13
|
+
checkSession: () => checkSession,
|
|
14
|
+
getAccountInfoSync: () => getAccountInfoSync,
|
|
15
|
+
getAppAuthorizeSetting: () => getAppAuthorizeSetting,
|
|
16
|
+
getAppBaseInfo: () => getAppBaseInfo,
|
|
17
|
+
getBatteryInfo: () => getBatteryInfo,
|
|
18
|
+
getBatteryInfoSync: () => getBatteryInfoSync,
|
|
19
|
+
getDeviceInfo: () => getDeviceInfo,
|
|
20
|
+
getFuzzyLocation: () => getFuzzyLocation,
|
|
21
|
+
getLocation: () => getLocation,
|
|
22
|
+
getMenuButtonBoundingClientRect: () => getMenuButtonBoundingClientRect,
|
|
23
|
+
getNetworkType: () => getNetworkType,
|
|
24
|
+
getSetting: () => getSetting,
|
|
25
|
+
getSystemInfo: () => getSystemInfo,
|
|
26
|
+
getSystemInfoSync: () => getSystemInfoSync,
|
|
27
|
+
getSystemSetting: () => getSystemSetting,
|
|
28
|
+
getUserInfo: () => getUserInfo,
|
|
29
|
+
getUserProfile: () => getUserProfile,
|
|
30
|
+
getWindowInfo: () => getWindowInfo,
|
|
31
|
+
login: () => login,
|
|
32
|
+
offNetworkStatusChange: () => offNetworkStatusChange,
|
|
33
|
+
offWindowResize: () => offWindowResize,
|
|
34
|
+
onNetworkStatusChange: () => onNetworkStatusChange,
|
|
35
|
+
onWindowResize: () => onWindowResize,
|
|
36
|
+
openAppAuthorizeSetting: () => openAppAuthorizeSetting,
|
|
37
|
+
openSetting: () => openSetting,
|
|
38
|
+
vibrateShort: () => vibrateShort
|
|
39
|
+
});
|
|
40
|
+
const WEB_SUPPORTED_AUTH_SCOPES = new Set([
|
|
41
|
+
"scope.userInfo",
|
|
42
|
+
"scope.userLocation",
|
|
43
|
+
"scope.userLocationBackground",
|
|
44
|
+
"scope.address",
|
|
45
|
+
"scope.invoiceTitle",
|
|
46
|
+
"scope.invoice",
|
|
47
|
+
"scope.werun",
|
|
48
|
+
"scope.record",
|
|
49
|
+
"scope.writePhotosAlbum",
|
|
50
|
+
"scope.camera"
|
|
51
|
+
]);
|
|
52
|
+
const APP_AUTHORIZE_SCOPE_MAP = {
|
|
53
|
+
albumAuthorized: "scope.writePhotosAlbum",
|
|
54
|
+
cameraAuthorized: "scope.camera",
|
|
55
|
+
locationAuthorized: "scope.userLocation",
|
|
56
|
+
microphoneAuthorized: "scope.record"
|
|
57
|
+
};
|
|
58
|
+
const webAuthorizeState = /* @__PURE__ */ new Map();
|
|
59
|
+
for (const scope of WEB_SUPPORTED_AUTH_SCOPES) webAuthorizeState.set(scope, "not determined");
|
|
60
|
+
function vibrateShort(options) {
|
|
61
|
+
return vibrateShortBridge(options);
|
|
62
|
+
}
|
|
63
|
+
function getBatteryInfoSync() {
|
|
64
|
+
return getBatteryInfoSyncBridge();
|
|
65
|
+
}
|
|
66
|
+
async function getBatteryInfo(options) {
|
|
67
|
+
return getBatteryInfoBridge(options);
|
|
68
|
+
}
|
|
69
|
+
function getLocation(options) {
|
|
70
|
+
return getLocationBridge(options);
|
|
71
|
+
}
|
|
72
|
+
async function getFuzzyLocation(options) {
|
|
73
|
+
return getFuzzyLocationBridge(options);
|
|
74
|
+
}
|
|
75
|
+
function getSetting(options) {
|
|
76
|
+
return getSettingBridge(options, webAuthorizeState);
|
|
77
|
+
}
|
|
78
|
+
function authorize(options) {
|
|
79
|
+
return authorizeBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES);
|
|
80
|
+
}
|
|
81
|
+
function openSetting(options) {
|
|
82
|
+
return openSettingBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES);
|
|
83
|
+
}
|
|
84
|
+
function getAppAuthorizeSetting() {
|
|
85
|
+
return getAppAuthorizeSettingBridge(webAuthorizeState);
|
|
86
|
+
}
|
|
87
|
+
function openAppAuthorizeSetting(options) {
|
|
88
|
+
return openAppAuthorizeSettingBridge(options, webAuthorizeState, APP_AUTHORIZE_SCOPE_MAP, getAppAuthorizeSetting);
|
|
89
|
+
}
|
|
90
|
+
function getNetworkType(options) {
|
|
91
|
+
return getNetworkTypeBridge(options);
|
|
92
|
+
}
|
|
93
|
+
function onNetworkStatusChange(callback) {
|
|
94
|
+
return onNetworkStatusChangeBridge(callback);
|
|
95
|
+
}
|
|
96
|
+
function offNetworkStatusChange(callback) {
|
|
97
|
+
return offNetworkStatusChangeBridge(callback);
|
|
98
|
+
}
|
|
99
|
+
function getWindowInfo() {
|
|
100
|
+
return getWindowInfoBridge();
|
|
101
|
+
}
|
|
102
|
+
function onWindowResize(callback) {
|
|
103
|
+
return onWindowResizeBridge(callback, getWindowInfo);
|
|
104
|
+
}
|
|
105
|
+
function offWindowResize(callback) {
|
|
106
|
+
return offWindowResizeBridge(callback);
|
|
107
|
+
}
|
|
108
|
+
function getSystemInfoSync() {
|
|
109
|
+
return getSystemInfoSyncBridge();
|
|
110
|
+
}
|
|
111
|
+
function getSystemInfo(options) {
|
|
112
|
+
return getSystemInfoBridge(options);
|
|
113
|
+
}
|
|
114
|
+
function getDeviceInfo() {
|
|
115
|
+
return getDeviceInfoBridge();
|
|
116
|
+
}
|
|
117
|
+
function getSystemSetting() {
|
|
118
|
+
return getSystemSettingBridge(webAuthorizeState, resolveDeviceOrientation);
|
|
119
|
+
}
|
|
120
|
+
function login(options) {
|
|
121
|
+
return loginBridge(options);
|
|
122
|
+
}
|
|
123
|
+
function checkSession(options) {
|
|
124
|
+
return checkSessionBridge(options);
|
|
125
|
+
}
|
|
126
|
+
function getUserInfo(options) {
|
|
127
|
+
return getUserInfoBridge(options, webAuthorizeState);
|
|
128
|
+
}
|
|
129
|
+
function getUserProfile(options) {
|
|
130
|
+
return getUserProfileBridge(options, webAuthorizeState);
|
|
131
|
+
}
|
|
132
|
+
function getAccountInfoSync() {
|
|
133
|
+
return getAccountInfoSyncBridge();
|
|
134
|
+
}
|
|
135
|
+
function getAppBaseInfo() {
|
|
136
|
+
return getAppBaseInfoBridge();
|
|
137
|
+
}
|
|
138
|
+
function getMenuButtonBoundingClientRect() {
|
|
139
|
+
return getMenuButtonBoundingClientRectBridge();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
export { authorize, checkSession, deviceAuthSystemApi_exports, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getDeviceInfo, getFuzzyLocation, getLocation, getMenuButtonBoundingClientRect, getNetworkType, getSetting, getSystemInfo, getSystemInfoSync, getSystemSetting, getUserInfo, getUserProfile, getWindowInfo, login, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openSetting, vibrateShort };
|
|
144
|
+
//# sourceMappingURL=deviceAuthSystemApi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceAuthSystemApi.mjs","names":[],"sources":["../../../src/runtime/polyfill/deviceAuthSystemApi.ts"],"sourcesContent":["import type {\n AccountInfoSync,\n AppAuthorizeSetting,\n AppAuthorizeStatus,\n AppBaseInfo,\n AuthorizeOptions,\n BatteryInfo,\n CheckSessionOptions,\n DeviceInfo,\n GetBatteryInfoSuccessResult,\n GetFuzzyLocationOptions,\n GetLocationOptions,\n GetNetworkTypeOptions,\n GetSettingOptions,\n GetSystemInfoOptions,\n GetUserInfoOptions,\n GetUserProfileOptions,\n LoginOptions,\n MenuButtonBoundingClientRect,\n NetworkStatusChangeCallback,\n OpenAppAuthorizeSettingOptions,\n OpenSettingOptions,\n SystemInfo,\n SystemSetting,\n VibrateShortOptions,\n WindowInfo,\n WindowResizeCallback,\n WxAsyncOptions,\n} from './types'\nimport {\n authorizeBridge,\n checkSessionBridge,\n getAppAuthorizeSettingBridge,\n getSettingBridge,\n getSystemSettingBridge,\n getUserInfoBridge,\n getUserProfileBridge,\n loginBridge,\n openAppAuthorizeSettingBridge,\n openSettingBridge,\n} from './authApi'\nimport {\n getBatteryInfoBridge,\n getBatteryInfoSyncBridge,\n vibrateShortBridge,\n} from './deviceApi'\nimport {\n getFuzzyLocationBridge,\n getLocationBridge,\n} from './locationApi'\nimport { getNetworkTypeBridge } from './menuApi'\nimport {\n offNetworkStatusChangeBridge,\n offWindowResizeBridge,\n onNetworkStatusChangeBridge,\n onWindowResizeBridge,\n} from './runtimeCapabilityApi'\nimport { resolveDeviceOrientation } from './system'\nimport {\n getAccountInfoSyncBridge,\n getAppBaseInfoBridge,\n getDeviceInfoBridge,\n getMenuButtonBoundingClientRectBridge,\n getSystemInfoBridge,\n getSystemInfoSyncBridge,\n getWindowInfoBridge,\n} from './systemApi'\n\nconst WEB_SUPPORTED_AUTH_SCOPES = new Set([\n 'scope.userInfo',\n 'scope.userLocation',\n 'scope.userLocationBackground',\n 'scope.address',\n 'scope.invoiceTitle',\n 'scope.invoice',\n 'scope.werun',\n 'scope.record',\n 'scope.writePhotosAlbum',\n 'scope.camera',\n])\nconst APP_AUTHORIZE_SCOPE_MAP: Partial<Record<keyof AppAuthorizeSetting, string>> = {\n albumAuthorized: 'scope.writePhotosAlbum',\n cameraAuthorized: 'scope.camera',\n locationAuthorized: 'scope.userLocation',\n microphoneAuthorized: 'scope.record',\n}\nconst webAuthorizeState = new Map<string, AppAuthorizeStatus>()\nfor (const scope of WEB_SUPPORTED_AUTH_SCOPES) {\n webAuthorizeState.set(scope, 'not determined')\n}\n\nexport function vibrateShort(options?: VibrateShortOptions) {\n return vibrateShortBridge(options)\n}\n\nexport function getBatteryInfoSync(): BatteryInfo {\n return getBatteryInfoSyncBridge()\n}\n\nexport async function getBatteryInfo(options?: WxAsyncOptions<GetBatteryInfoSuccessResult>) {\n return getBatteryInfoBridge(options)\n}\n\nexport function getLocation(options?: GetLocationOptions) {\n return getLocationBridge(options)\n}\n\nexport async function getFuzzyLocation(options?: GetFuzzyLocationOptions) {\n return getFuzzyLocationBridge(options)\n}\n\nexport function getSetting(options?: GetSettingOptions) {\n return getSettingBridge(options, webAuthorizeState)\n}\n\nexport function authorize(options?: AuthorizeOptions) {\n return authorizeBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES)\n}\n\nexport function openSetting(options?: OpenSettingOptions) {\n return openSettingBridge(options, webAuthorizeState, WEB_SUPPORTED_AUTH_SCOPES)\n}\n\nexport function getAppAuthorizeSetting(): AppAuthorizeSetting {\n return getAppAuthorizeSettingBridge(webAuthorizeState) as AppAuthorizeSetting\n}\n\nexport function openAppAuthorizeSetting(options?: OpenAppAuthorizeSettingOptions) {\n return openAppAuthorizeSettingBridge(\n options,\n webAuthorizeState,\n APP_AUTHORIZE_SCOPE_MAP as Record<string, string>,\n getAppAuthorizeSetting,\n )\n}\n\nexport function getNetworkType(options?: GetNetworkTypeOptions) {\n return getNetworkTypeBridge(options)\n}\n\nexport function onNetworkStatusChange(callback: NetworkStatusChangeCallback) {\n return onNetworkStatusChangeBridge(callback)\n}\n\nexport function offNetworkStatusChange(callback?: NetworkStatusChangeCallback) {\n return offNetworkStatusChangeBridge(callback)\n}\n\nexport function getWindowInfo(): WindowInfo {\n return getWindowInfoBridge()\n}\n\nexport function onWindowResize(callback: WindowResizeCallback) {\n return onWindowResizeBridge(callback, getWindowInfo)\n}\n\nexport function offWindowResize(callback?: WindowResizeCallback) {\n return offWindowResizeBridge(callback)\n}\n\nexport function getSystemInfoSync(): SystemInfo {\n return getSystemInfoSyncBridge()\n}\n\nexport function getSystemInfo(options?: GetSystemInfoOptions) {\n return getSystemInfoBridge(options)\n}\n\nexport function getDeviceInfo(): DeviceInfo {\n return getDeviceInfoBridge() as DeviceInfo\n}\n\nexport function getSystemSetting(): SystemSetting {\n return getSystemSettingBridge(webAuthorizeState, resolveDeviceOrientation)\n}\n\nexport function login(options?: LoginOptions) {\n return loginBridge(options)\n}\n\nexport function checkSession(options?: CheckSessionOptions) {\n return checkSessionBridge(options)\n}\n\nexport function getUserInfo(options?: GetUserInfoOptions) {\n return getUserInfoBridge(options, webAuthorizeState)\n}\n\nexport function getUserProfile(options?: GetUserProfileOptions) {\n return getUserProfileBridge(options, webAuthorizeState)\n}\n\nexport function getAccountInfoSync(): AccountInfoSync {\n return getAccountInfoSyncBridge() as AccountInfoSync\n}\n\nexport function getAppBaseInfo(): AppBaseInfo {\n return getAppBaseInfoBridge() as AppBaseInfo\n}\n\nexport function getMenuButtonBoundingClientRect(): MenuButtonBoundingClientRect {\n return getMenuButtonBoundingClientRectBridge() as MenuButtonBoundingClientRect\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AACF,MAAM,0BAA8E;CAClF,iBAAiB;CACjB,kBAAkB;CAClB,oBAAoB;CACpB,sBAAsB;CACvB;AACD,MAAM,oCAAoB,IAAI,KAAiC;AAC/D,KAAK,MAAM,SAAS,0BAClB,mBAAkB,IAAI,OAAO,iBAAiB;AAGhD,SAAgB,aAAa,SAA+B;AAC1D,QAAO,mBAAmB,QAAQ;;AAGpC,SAAgB,qBAAkC;AAChD,QAAO,0BAA0B;;AAGnC,eAAsB,eAAe,SAAuD;AAC1F,QAAO,qBAAqB,QAAQ;;AAGtC,SAAgB,YAAY,SAA8B;AACxD,QAAO,kBAAkB,QAAQ;;AAGnC,eAAsB,iBAAiB,SAAmC;AACxE,QAAO,uBAAuB,QAAQ;;AAGxC,SAAgB,WAAW,SAA6B;AACtD,QAAO,iBAAiB,SAAS,kBAAkB;;AAGrD,SAAgB,UAAU,SAA4B;AACpD,QAAO,gBA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2
|
+
|
|
3
|
+
//#region src/runtime/polyfill/filePicker.ts
|
|
4
|
+
function normalizeChooseMessageFileCount(count) {
|
|
5
|
+
if (typeof count !== "number" || Number.isNaN(count)) return 1;
|
|
6
|
+
return Math.max(1, Math.floor(count));
|
|
7
|
+
}
|
|
8
|
+
function normalizeChooseMessageFileType(type) {
|
|
9
|
+
if (type === "video" || type === "image" || type === "file" || type === "all") return type;
|
|
10
|
+
return "all";
|
|
11
|
+
}
|
|
12
|
+
function buildChooseMessageAccept(type) {
|
|
13
|
+
if (type === "video") return "video/*";
|
|
14
|
+
if (type === "image") return "image/*";
|
|
15
|
+
if (type === "file") return "*/*";
|
|
16
|
+
return "*/*";
|
|
17
|
+
}
|
|
18
|
+
function normalizeChooseMessageFile(file) {
|
|
19
|
+
return {
|
|
20
|
+
path: createTempFilePath(file),
|
|
21
|
+
size: typeof file.size === "number" ? file.size : 0,
|
|
22
|
+
type: typeof file.type === "string" ? file.type : "",
|
|
23
|
+
name: typeof file.name === "string" ? file.name : "",
|
|
24
|
+
time: typeof file.lastModified === "number" ? file.lastModified : Date.now()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async function pickMessageFilesByOpenPicker(count, type) {
|
|
28
|
+
const picker = globalThis.showOpenFilePicker;
|
|
29
|
+
if (typeof picker !== "function") return null;
|
|
30
|
+
const accept = buildChooseMessageAccept(type);
|
|
31
|
+
const handles = await picker({
|
|
32
|
+
multiple: count > 1,
|
|
33
|
+
types: [{
|
|
34
|
+
description: "Message Files",
|
|
35
|
+
accept: { [accept]: [] }
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
const files = [];
|
|
39
|
+
for (const handle of handles ?? []) {
|
|
40
|
+
const file = await handle?.getFile?.();
|
|
41
|
+
if (file) files.push(file);
|
|
42
|
+
if (files.length >= count) break;
|
|
43
|
+
}
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
async function pickMessageFilesByInput(count, type) {
|
|
47
|
+
if (typeof document === "undefined" || typeof document.createElement !== "function") return null;
|
|
48
|
+
const input = document.createElement("input");
|
|
49
|
+
input.setAttribute("type", "file");
|
|
50
|
+
input.setAttribute("accept", buildChooseMessageAccept(type));
|
|
51
|
+
if (count > 1) input.setAttribute("multiple", "true");
|
|
52
|
+
input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
|
|
53
|
+
if (document.body) document.body.append(input);
|
|
54
|
+
try {
|
|
55
|
+
return await new Promise((resolve, reject) => {
|
|
56
|
+
const onChange = () => {
|
|
57
|
+
const selected = input.files ? Array.from(input.files) : [];
|
|
58
|
+
if (selected.length) {
|
|
59
|
+
resolve(selected.slice(0, count));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
reject(/* @__PURE__ */ new Error("no file selected"));
|
|
63
|
+
};
|
|
64
|
+
input.addEventListener("change", onChange, { once: true });
|
|
65
|
+
if (typeof input.click === "function") {
|
|
66
|
+
input.click();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
reject(/* @__PURE__ */ new Error("file input click is unavailable"));
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
if (input.parentNode) input.parentNode.removeChild(input);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function pickChooseMessageFiles(count, type) {
|
|
76
|
+
const viaPicker = await pickMessageFilesByOpenPicker(count, type);
|
|
77
|
+
if (Array.isArray(viaPicker)) return viaPicker;
|
|
78
|
+
const viaInput = await pickMessageFilesByInput(count, type);
|
|
79
|
+
if (Array.isArray(viaInput)) return viaInput;
|
|
80
|
+
throw new TypeError("Message file picker is unavailable in current environment.");
|
|
81
|
+
}
|
|
82
|
+
function normalizeChooseFileExtensions(extension) {
|
|
83
|
+
const set = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const item of extension ?? []) {
|
|
85
|
+
if (typeof item !== "string") continue;
|
|
86
|
+
const normalized = item.trim().toLowerCase();
|
|
87
|
+
if (!normalized) continue;
|
|
88
|
+
set.add(normalized.startsWith(".") ? normalized : `.${normalized}`);
|
|
89
|
+
}
|
|
90
|
+
return Array.from(set);
|
|
91
|
+
}
|
|
92
|
+
function buildChooseFilePickerAccept(type, extensions) {
|
|
93
|
+
if (extensions.length) return { "*/*": extensions };
|
|
94
|
+
return { [buildChooseMessageAccept(type)]: [] };
|
|
95
|
+
}
|
|
96
|
+
function buildChooseFileInputAccept(type, extensions) {
|
|
97
|
+
if (extensions.length) return extensions.join(",");
|
|
98
|
+
return buildChooseMessageAccept(type);
|
|
99
|
+
}
|
|
100
|
+
async function pickChooseFileByOpenPicker(count, type, extensions) {
|
|
101
|
+
const picker = globalThis.showOpenFilePicker;
|
|
102
|
+
if (typeof picker !== "function") return null;
|
|
103
|
+
const handles = await picker({
|
|
104
|
+
multiple: count > 1,
|
|
105
|
+
types: [{
|
|
106
|
+
description: "Files",
|
|
107
|
+
accept: buildChooseFilePickerAccept(type, extensions)
|
|
108
|
+
}]
|
|
109
|
+
});
|
|
110
|
+
const files = [];
|
|
111
|
+
for (const handle of handles ?? []) {
|
|
112
|
+
const file = await handle?.getFile?.();
|
|
113
|
+
if (file) files.push(file);
|
|
114
|
+
if (files.length >= count) break;
|
|
115
|
+
}
|
|
116
|
+
return files;
|
|
117
|
+
}
|
|
118
|
+
async function pickChooseFileByInput(count, type, extensions) {
|
|
119
|
+
if (typeof document === "undefined" || typeof document.createElement !== "function") return null;
|
|
120
|
+
const input = document.createElement("input");
|
|
121
|
+
if (!input || typeof input !== "object") return null;
|
|
122
|
+
input.setAttribute("type", "file");
|
|
123
|
+
input.setAttribute("accept", buildChooseFileInputAccept(type, extensions));
|
|
124
|
+
if (count > 1) input.setAttribute("multiple", "true");
|
|
125
|
+
input.setAttribute("style", "position: fixed; left: -9999px; top: -9999px; opacity: 0;");
|
|
126
|
+
if (document.body) document.body.append(input);
|
|
127
|
+
try {
|
|
128
|
+
return await new Promise((resolve, reject) => {
|
|
129
|
+
const onChange = () => {
|
|
130
|
+
const selected = input.files ? Array.from(input.files) : [];
|
|
131
|
+
if (selected.length) {
|
|
132
|
+
resolve(selected.slice(0, count));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
reject(/* @__PURE__ */ new Error("no file selected"));
|
|
136
|
+
};
|
|
137
|
+
input.addEventListener("change", onChange, { once: true });
|
|
138
|
+
if (typeof input.click === "function") {
|
|
139
|
+
input.click();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
reject(/* @__PURE__ */ new Error("file input click is unavailable"));
|
|
143
|
+
});
|
|
144
|
+
} finally {
|
|
145
|
+
if (input.parentNode) input.parentNode.removeChild(input);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function pickChooseFileFiles(count, type, extensions) {
|
|
149
|
+
const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions);
|
|
150
|
+
if (Array.isArray(viaPicker)) return viaPicker;
|
|
151
|
+
const viaInput = await pickChooseFileByInput(count, type, extensions);
|
|
152
|
+
if (Array.isArray(viaInput)) return viaInput;
|
|
153
|
+
throw new TypeError("File picker is unavailable in current environment.");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
export { normalizeChooseFileExtensions, normalizeChooseMessageFile, normalizeChooseMessageFileCount, normalizeChooseMessageFileType, pickChooseFileFiles, pickChooseMessageFiles };
|
|
158
|
+
//# sourceMappingURL=filePicker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filePicker.mjs","names":[],"sources":["../../../src/runtime/polyfill/filePicker.ts"],"sourcesContent":["import { createTempFilePath } from './mediaPicker'\n\ntype ChooseMessageFileType = 'all' | 'video' | 'image' | 'file'\n\nexport function normalizeChooseMessageFileCount(count: number | undefined) {\n if (typeof count !== 'number' || Number.isNaN(count)) {\n return 1\n }\n return Math.max(1, Math.floor(count))\n}\n\nexport function normalizeChooseMessageFileType(type: unknown): ChooseMessageFileType {\n if (type === 'video' || type === 'image' || type === 'file' || type === 'all') {\n return type\n }\n return 'all'\n}\n\nfunction buildChooseMessageAccept(type: ChooseMessageFileType) {\n if (type === 'video') {\n return 'video/*'\n }\n if (type === 'image') {\n return 'image/*'\n }\n if (type === 'file') {\n return '*/*'\n }\n return '*/*'\n}\n\nexport function normalizeChooseMessageFile(file: {\n size?: number\n type?: string\n name?: string\n lastModified?: number\n}) {\n return {\n path: createTempFilePath(file),\n size: typeof file.size === 'number' ? file.size : 0,\n type: typeof file.type === 'string' ? file.type : '',\n name: typeof file.name === 'string' ? file.name : '',\n time: typeof file.lastModified === 'number' ? file.lastModified : Date.now(),\n }\n}\n\nasync function pickMessageFilesByOpenPicker(count: number, type: ChooseMessageFileType) {\n const picker = (globalThis as {\n showOpenFilePicker?: (options: {\n multiple?: boolean\n types?: Array<{\n description?: string\n accept?: Record<string, string[]>\n }>\n }) => Promise<Array<{ getFile?: () => Promise<any> }>>\n }).showOpenFilePicker\n if (typeof picker !== 'function') {\n return null\n }\n const accept = buildChooseMessageAccept(type)\n const handles = await picker({\n multiple: count > 1,\n types: [{\n description: 'Message Files',\n accept: {\n [accept]: [],\n },\n }],\n })\n const files: any[] = []\n for (const handle of handles ?? []) {\n const file = await handle?.getFile?.()\n if (file) {\n files.push(file)\n }\n if (files.length >= count) {\n break\n }\n }\n return files\n}\n\nasync function pickMessageFilesByInput(count: number, type: ChooseMessageFileType) {\n if (typeof document === 'undefined' || typeof document.createElement !== 'function') {\n return null\n }\n const input = document.createElement('input') as HTMLInputElement\n input.setAttribute('type', 'file')\n input.setAttribute('accept', buildChooseMessageAccept(type))\n if (count > 1) {\n input.setAttribute('multiple', 'true')\n }\n input.setAttribute('style', 'position: fixed; left: -9999px; top: -9999px; opacity: 0;')\n if (document.body) {\n document.body.append(input)\n }\n try {\n const files = await new Promise<any[]>((resolve, reject) => {\n const onChange = () => {\n const selected = input.files ? Array.from(input.files) : []\n if (selected.length) {\n resolve(selected.slice(0, count))\n return\n }\n reject(new Error('no file selected'))\n }\n input.addEventListener('change', onChange, { once: true })\n if (typeof input.click === 'function') {\n input.click()\n return\n }\n reject(new Error('file input click is unavailable'))\n })\n return files\n }\n finally {\n if (input.parentNode) {\n input.parentNode.removeChild(input)\n }\n }\n}\n\nexport async function pickChooseMessageFiles(count: number, type: ChooseMessageFileType) {\n const viaPicker = await pickMessageFilesByOpenPicker(count, type)\n if (Array.isArray(viaPicker)) {\n return viaPicker\n }\n const viaInput = await pickMessageFilesByInput(count, type)\n if (Array.isArray(viaInput)) {\n return viaInput\n }\n throw new TypeError('Message file picker is unavailable in current environment.')\n}\n\nexport function normalizeChooseFileExtensions(extension: readonly string[] | undefined) {\n const set = new Set<string>()\n for (const item of extension ?? []) {\n if (typeof item !== 'string') {\n continue\n }\n const normalized = item.trim().toLowerCase()\n if (!normalized) {\n continue\n }\n set.add(normalized.startsWith('.') ? normalized : `.${normalized}`)\n }\n return Array.from(set)\n}\n\nfunction buildChooseFilePickerAccept(type: ChooseMessageFileType, extensions: string[]) {\n if (extensions.length) {\n return {\n '*/*': extensions,\n }\n }\n return {\n [buildChooseMessageAccept(type)]: [],\n }\n}\n\nfunction buildChooseFileInputAccept(type: ChooseMessageFileType, extensions: string[]) {\n if (extensions.length) {\n return extensions.join(',')\n }\n return buildChooseMessageAccept(type)\n}\n\nasync function pickChooseFileByOpenPicker(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n const picker = (globalThis as {\n showOpenFilePicker?: (options: {\n multiple?: boolean\n types?: Array<{\n description?: string\n accept?: Record<string, string[]>\n }>\n }) => Promise<Array<{ getFile?: () => Promise<any> }>>\n }).showOpenFilePicker\n if (typeof picker !== 'function') {\n return null\n }\n const handles = await picker({\n multiple: count > 1,\n types: [{\n description: 'Files',\n accept: buildChooseFilePickerAccept(type, extensions),\n }],\n })\n const files: any[] = []\n for (const handle of handles ?? []) {\n const file = await handle?.getFile?.()\n if (file) {\n files.push(file)\n }\n if (files.length >= count) {\n break\n }\n }\n return files\n}\n\nasync function pickChooseFileByInput(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n if (typeof document === 'undefined' || typeof document.createElement !== 'function') {\n return null\n }\n const input = document.createElement('input') as HTMLInputElement\n if (!input || typeof input !== 'object') {\n return null\n }\n input.setAttribute('type', 'file')\n input.setAttribute('accept', buildChooseFileInputAccept(type, extensions))\n if (count > 1) {\n input.setAttribute('multiple', 'true')\n }\n input.setAttribute('style', 'position: fixed; left: -9999px; top: -9999px; opacity: 0;')\n if (document.body) {\n document.body.append(input)\n }\n try {\n const files = await new Promise<any[]>((resolve, reject) => {\n const onChange = () => {\n const selected = input.files ? Array.from(input.files) : []\n if (selected.length) {\n resolve(selected.slice(0, count))\n return\n }\n reject(new Error('no file selected'))\n }\n input.addEventListener('change', onChange, { once: true })\n if (typeof input.click === 'function') {\n input.click()\n return\n }\n reject(new Error('file input click is unavailable'))\n })\n return files\n }\n finally {\n if (input.parentNode) {\n input.parentNode.removeChild(input)\n }\n }\n}\n\nexport async function pickChooseFileFiles(\n count: number,\n type: ChooseMessageFileType,\n extensions: string[],\n) {\n const viaPicker = await pickChooseFileByOpenPicker(count, type, extensions)\n if (Array.isArray(viaPicker)) {\n return viaPicker\n }\n const viaInput = await pickChooseFileByInput(count, type, extensions)\n if (Array.isArray(viaInput)) {\n return viaInput\n }\n throw new TypeError('File picker is unavailable in current environment.')\n}\n"],"mappings":";;;AAIA,SAAgB,gCAAgC,OAA2B;AACzE,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAClD,QAAO;AAET,QAAO,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,CAAC;;AAGvC,SAAgB,+BAA+B,MAAsC;AACnF,KAAI,SAAS,WAAW,SAAS,WAAW,SAAS,UAAU,SAAS,MACtE,QAAO;AAET,QAAO;;AAGT,SAAS,yBAAyB,MAA6B;AAC7D,KAAI,SAAS,QACX,QAAO;AAET,KAAI,SAAS,QACX,QAAO;AAET,KAAI,SAAS,OACX,QAAO;AAET,QAAO;;AAGT,SAAgB,2BAA2B,M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,QAAQ,UAAU,CAC1B,QAAO;CAET,MAAM,WAAW,MAAM,sBAAsB,OAAO,MAAM,WAAW;AACrE,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO;AAET,OAAM,IAAI,UAAU,qDAAqD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { normalizeFilePath, readFileSyncInternal, writeFileSyncInternal } from "./files.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/polyfill/fileSystemManager.ts
|
|
4
|
+
function createFileSystemManagerBridge(callWxAsyncSuccess, callWxAsyncFailure) {
|
|
5
|
+
return {
|
|
6
|
+
writeFile(options) {
|
|
7
|
+
const filePath = normalizeFilePath(options?.filePath);
|
|
8
|
+
if (!filePath) {
|
|
9
|
+
callWxAsyncFailure(options, "writeFile:fail invalid filePath");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
writeFileSyncInternal(filePath, options?.data ?? "");
|
|
14
|
+
callWxAsyncSuccess(options, { errMsg: "writeFile:ok" });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
callWxAsyncFailure(options, `writeFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
readFile(options) {
|
|
20
|
+
const filePath = normalizeFilePath(options?.filePath);
|
|
21
|
+
if (!filePath) {
|
|
22
|
+
callWxAsyncFailure(options, "readFile:fail invalid filePath");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
callWxAsyncSuccess(options, {
|
|
27
|
+
errMsg: "readFile:ok",
|
|
28
|
+
data: readFileSyncInternal(filePath, options?.encoding)
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
callWxAsyncFailure(options, `readFile:fail ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
writeFileSync(filePath, data, _encoding) {
|
|
35
|
+
writeFileSyncInternal(filePath, data);
|
|
36
|
+
},
|
|
37
|
+
readFileSync(filePath, encoding) {
|
|
38
|
+
return readFileSyncInternal(filePath, encoding);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { createFileSystemManagerBridge };
|
|
45
|
+
//# sourceMappingURL=fileSystemManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystemManager.mjs","names":[],"sources":["../../../src/runtime/polyfill/fileSystemManager.ts"],"sourcesContent":["import {\n normalizeFilePath,\n readFileSyncInternal,\n writeFileSyncInternal,\n} from './files'\n\ntype AsyncSuccess = (options: unknown, result: { errMsg: string, [key: string]: unknown }) => unknown\ntype AsyncFailure = (options: unknown, errMsg: string) => unknown\n\ninterface FileWriteOptionsLike {\n filePath?: string\n data?: unknown\n}\n\ninterface FileReadOptionsLike {\n filePath?: string\n encoding?: string\n}\n\nexport function createFileSystemManagerBridge(\n callWxAsyncSuccess: AsyncSuccess,\n callWxAsyncFailure: AsyncFailure,\n) {\n return {\n writeFile(options?: FileWriteOptionsLike) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n callWxAsyncFailure(options, 'writeFile:fail invalid filePath')\n return\n }\n try {\n writeFileSyncInternal(filePath, (options?.data ?? '') as string | ArrayBuffer | ArrayBufferView)\n callWxAsyncSuccess(options, { errMsg: 'writeFile:ok' })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n callWxAsyncFailure(options, `writeFile:fail ${message}`)\n }\n },\n readFile(options?: FileReadOptionsLike) {\n const filePath = normalizeFilePath(options?.filePath)\n if (!filePath) {\n callWxAsyncFailure(options, 'readFile:fail invalid filePath')\n return\n }\n try {\n const data = readFileSyncInternal(filePath, options?.encoding)\n callWxAsyncSuccess(options, { errMsg: 'readFile:ok', data })\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n callWxAsyncFailure(options, `readFile:fail ${message}`)\n }\n },\n writeFileSync(filePath: string, data: string | ArrayBuffer | ArrayBufferView, _encoding?: string) {\n writeFileSyncInternal(filePath, data)\n },\n readFileSync(filePath: string, encoding?: string) {\n return readFileSyncInternal(filePath, encoding)\n },\n }\n}\n"],"mappings":";;;AAmBA,SAAgB,8BACd,oBACA,oBACA;AACA,QAAO;EACL,UAAU,SAAgC;GACxC,MAAM,WAAW,kBAAkB,SAAS,SAAS;AACrD,OAAI,CAAC,UAAU;AACb,uBAAmB,SAAS,kCAAkC;AAC9D;;AAEF,OAAI;AACF,0BAAsB,UAAW,SAAS,QAAQ,GAA8C;AAChG,uBAAmB,SAAS,EAAE,QAAQ,gBAAgB,CAAC;YAElD,OAAO;AAEZ,uBAAmB,SAAS,kBADZ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACd;;;EAG5D,SAAS,SAA+B;GACtC,MAAM,WAAW,kBAAkB,SAAS,SAAS;AACrD,OAAI,CAAC,UAAU;AACb,uBAAmB,SAAS,iCAAiC;AAC7D;;AAEF,OAAI;AAEF,uBAAmB,SAAS;KAAE,QAAQ;KAAe,MADxC,qBAAqB,UAAU,SAAS,SAAS;KACH,CAAC;YAEvD,OAAO;AAEZ,uBAAmB,SAAS,iBADZ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACf;;;EAG3D,cAAc,UAAkB,MAA8C,WAAoB;AAChG,yBAAsB,UAAU,KAAK;;EAEvC,aAAa,UAAkB,UAAmB;AAChD,UAAO,qBAAqB,UAAU,SAAS;;EAElD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/runtime/polyfill/files.ts
|
|
2
|
+
const WEB_USER_DATA_PATH = "/__weapp_vite_web_user_data__";
|
|
3
|
+
const memoryFileStorage = /* @__PURE__ */ new Map();
|
|
4
|
+
function normalizeFilePath(filePath) {
|
|
5
|
+
if (typeof filePath !== "string") return "";
|
|
6
|
+
return filePath.trim();
|
|
7
|
+
}
|
|
8
|
+
function normalizeFileEncoding(encoding) {
|
|
9
|
+
if (typeof encoding !== "string") return "";
|
|
10
|
+
return encoding.trim().toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
function cloneArrayBuffer(buffer) {
|
|
13
|
+
return buffer.slice(0);
|
|
14
|
+
}
|
|
15
|
+
function toArrayBuffer(data) {
|
|
16
|
+
if (data instanceof ArrayBuffer) return cloneArrayBuffer(data);
|
|
17
|
+
const view = data;
|
|
18
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer;
|
|
19
|
+
}
|
|
20
|
+
function decodeArrayBufferToText(buffer, encoding) {
|
|
21
|
+
if (typeof TextDecoder === "function") try {
|
|
22
|
+
return new TextDecoder(encoding || "utf-8").decode(new Uint8Array(buffer));
|
|
23
|
+
} catch {
|
|
24
|
+
return new TextDecoder().decode(new Uint8Array(buffer));
|
|
25
|
+
}
|
|
26
|
+
return Array.from(new Uint8Array(buffer)).map((byte) => String.fromCharCode(byte)).join("");
|
|
27
|
+
}
|
|
28
|
+
function writeFileSyncInternal(filePath, data) {
|
|
29
|
+
const normalizedPath = normalizeFilePath(filePath);
|
|
30
|
+
if (!normalizedPath) throw new TypeError("writeFileSync:fail invalid filePath");
|
|
31
|
+
if (typeof data === "string") {
|
|
32
|
+
memoryFileStorage.set(normalizedPath, {
|
|
33
|
+
kind: "text",
|
|
34
|
+
text: data
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
memoryFileStorage.set(normalizedPath, {
|
|
39
|
+
kind: "binary",
|
|
40
|
+
bytes: toArrayBuffer(data)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function readFileSyncInternal(filePath, encoding) {
|
|
44
|
+
const normalizedPath = normalizeFilePath(filePath);
|
|
45
|
+
if (!normalizedPath) throw new TypeError("readFileSync:fail invalid filePath");
|
|
46
|
+
const record = memoryFileStorage.get(normalizedPath);
|
|
47
|
+
if (!record) throw new TypeError(`readFileSync:fail no such file ${normalizedPath}`);
|
|
48
|
+
const normalizedEncoding = normalizeFileEncoding(encoding);
|
|
49
|
+
if (record.kind === "text") return record.text ?? "";
|
|
50
|
+
const bytes = record.bytes ? cloneArrayBuffer(record.bytes) : /* @__PURE__ */ new ArrayBuffer(0);
|
|
51
|
+
if (normalizedEncoding) return decodeArrayBufferToText(bytes, normalizedEncoding);
|
|
52
|
+
return bytes;
|
|
53
|
+
}
|
|
54
|
+
function resolveUploadFileName(filePath) {
|
|
55
|
+
const segments = (filePath.split(/[?#]/)[0] ?? "").split("/");
|
|
56
|
+
return segments[segments.length - 1] || "file";
|
|
57
|
+
}
|
|
58
|
+
async function resolveUploadFileBlob(filePath, runtimeFetch) {
|
|
59
|
+
const record = memoryFileStorage.get(filePath);
|
|
60
|
+
if (record) {
|
|
61
|
+
if (record.kind === "text") return new Blob([record.text ?? ""], { type: "text/plain;charset=utf-8" });
|
|
62
|
+
return new Blob([record.bytes ?? /* @__PURE__ */ new ArrayBuffer(0)]);
|
|
63
|
+
}
|
|
64
|
+
if (/^(?:https?:|blob:|data:)/i.test(filePath) && runtimeFetch) try {
|
|
65
|
+
return await (await runtimeFetch(filePath, { method: "GET" })).blob();
|
|
66
|
+
} catch {}
|
|
67
|
+
return new Blob([filePath], { type: "text/plain;charset=utf-8" });
|
|
68
|
+
}
|
|
69
|
+
function cloneMemoryFileRecord(record) {
|
|
70
|
+
if (record.kind === "text") return {
|
|
71
|
+
kind: "text",
|
|
72
|
+
text: record.text ?? ""
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
kind: "binary",
|
|
76
|
+
bytes: record.bytes ? cloneArrayBuffer(record.bytes) : /* @__PURE__ */ new ArrayBuffer(0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function resolveSaveFilePath(tempFilePath, customPath) {
|
|
80
|
+
const targetPath = typeof customPath === "string" ? customPath.trim() : "";
|
|
81
|
+
if (targetPath) return targetPath;
|
|
82
|
+
return `${WEB_USER_DATA_PATH}/${resolveUploadFileName(tempFilePath)}`;
|
|
83
|
+
}
|
|
84
|
+
function saveMemoryFile(tempFilePath, savedFilePath) {
|
|
85
|
+
const sourceRecord = memoryFileStorage.get(tempFilePath);
|
|
86
|
+
if (sourceRecord) {
|
|
87
|
+
memoryFileStorage.set(savedFilePath, cloneMemoryFileRecord(sourceRecord));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
memoryFileStorage.set(savedFilePath, {
|
|
91
|
+
kind: "text",
|
|
92
|
+
text: tempFilePath
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function resolveOpenDocumentUrl(filePath) {
|
|
96
|
+
const record = memoryFileStorage.get(filePath);
|
|
97
|
+
const runtimeUrl = globalThis.URL;
|
|
98
|
+
if (record) {
|
|
99
|
+
if (record.kind === "text") {
|
|
100
|
+
const text = record.text ?? "";
|
|
101
|
+
if (typeof Blob === "function" && runtimeUrl?.createObjectURL) return runtimeUrl.createObjectURL(new Blob([text], { type: "text/plain;charset=utf-8" }));
|
|
102
|
+
return `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`;
|
|
103
|
+
}
|
|
104
|
+
const bytes = record.bytes ?? /* @__PURE__ */ new ArrayBuffer(0);
|
|
105
|
+
if (typeof Blob === "function" && runtimeUrl?.createObjectURL) return runtimeUrl.createObjectURL(new Blob([bytes]));
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
if (/^(?:https?:|blob:|data:)/i.test(filePath)) return filePath;
|
|
109
|
+
try {
|
|
110
|
+
const runtimeLocation = typeof location !== "undefined" ? location : void 0;
|
|
111
|
+
if (runtimeLocation?.href) return new URL(filePath, runtimeLocation.href).toString();
|
|
112
|
+
} catch {}
|
|
113
|
+
return filePath;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { WEB_USER_DATA_PATH, normalizeFilePath, readFileSyncInternal, resolveOpenDocumentUrl, resolveSaveFilePath, resolveUploadFileBlob, resolveUploadFileName, saveMemoryFile, writeFileSyncInternal };
|
|
118
|
+
//# sourceMappingURL=files.mjs.map
|