@mpcore/simulator 0.3.1 → 0.3.3
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/index.d.mts +36 -3
- package/dist/index.mjs +508 -178
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ interface HeadlessBehaviorDefinition extends Record<string, any> {
|
|
|
7
7
|
}
|
|
8
8
|
interface HeadlessHostLoadContext {
|
|
9
9
|
kind: 'app' | 'page' | 'component';
|
|
10
|
+
componentDefinitions?: HeadlessComponentDefinition[];
|
|
10
11
|
route?: string;
|
|
11
12
|
}
|
|
12
13
|
interface HeadlessHostRegistries {
|
|
@@ -15,9 +16,10 @@ interface HeadlessHostRegistries {
|
|
|
15
16
|
currentLoadContext: HeadlessHostLoadContext | null;
|
|
16
17
|
pages: Map<string, HeadlessPageDefinition>;
|
|
17
18
|
}
|
|
19
|
+
declare function normalizeComponentPageDefinition(definition: HeadlessComponentDefinition): HeadlessPageDefinition;
|
|
18
20
|
declare function createHostRegistries(): HeadlessHostRegistries;
|
|
19
21
|
declare function registerAppDefinition(registries: HeadlessHostRegistries, definition: HeadlessAppDefinition): HeadlessAppDefinition;
|
|
20
|
-
declare function registerPageDefinition(registries: HeadlessHostRegistries, definition: HeadlessPageDefinition): HeadlessPageDefinition;
|
|
22
|
+
declare function registerPageDefinition(registries: HeadlessHostRegistries, definition: HeadlessPageDefinition, explicitRoute?: string): HeadlessPageDefinition;
|
|
21
23
|
declare function registerComponentDefinition(registries: HeadlessHostRegistries, definition: HeadlessComponentDefinition): HeadlessPageDefinition;
|
|
22
24
|
declare function registerExportedComponentDefinition(registries: HeadlessHostRegistries, id: string, moduleExports: Record<string, any>, registeredDefinition?: HeadlessComponentDefinition): HeadlessComponentDefinition | null;
|
|
23
25
|
//#endregion
|
|
@@ -1071,6 +1073,10 @@ interface RuntimeDiagnosticEntry {
|
|
|
1071
1073
|
level: RuntimeDiagnosticLevel;
|
|
1072
1074
|
timestamp: number;
|
|
1073
1075
|
}
|
|
1076
|
+
interface RuntimeConsoleEntry {
|
|
1077
|
+
args: unknown[];
|
|
1078
|
+
level: 'debug' | 'error' | 'info' | 'log' | 'warn';
|
|
1079
|
+
}
|
|
1074
1080
|
declare class RuntimeDiagnostics {
|
|
1075
1081
|
private readonly entries;
|
|
1076
1082
|
clear(): void;
|
|
@@ -1080,7 +1086,7 @@ declare class RuntimeDiagnostics {
|
|
|
1080
1086
|
timestamp: number;
|
|
1081
1087
|
}[];
|
|
1082
1088
|
record(level: RuntimeDiagnosticLevel, args: unknown[]): void;
|
|
1083
|
-
createConsole(baseConsole?: Console): Console;
|
|
1089
|
+
createConsole(baseConsole?: Console, onConsole?: (entry: RuntimeConsoleEntry) => void): Console;
|
|
1084
1090
|
}
|
|
1085
1091
|
//#endregion
|
|
1086
1092
|
//#region src/kernel/platform.d.ts
|
|
@@ -1268,6 +1274,18 @@ declare function createComponentInstance(options: CreateComponentInstanceOptions
|
|
|
1268
1274
|
declare function runComponentLifecycle(instance: HeadlessComponentInstance, lifecycleName: 'attached' | 'created' | 'detached' | 'ready'): void;
|
|
1269
1275
|
declare function runComponentPageLifetime(instance: HeadlessComponentInstance, lifetimeName: 'hide' | 'resize' | 'show', payload?: unknown): void;
|
|
1270
1276
|
//#endregion
|
|
1277
|
+
//#region src/view/templateRuntime.d.ts
|
|
1278
|
+
interface TemplateNodeLike {
|
|
1279
|
+
attribs?: Record<string, string>;
|
|
1280
|
+
children?: TemplateNodeLike[];
|
|
1281
|
+
name?: string;
|
|
1282
|
+
type?: string;
|
|
1283
|
+
}
|
|
1284
|
+
interface TemplateRenderState<T extends TemplateNodeLike> {
|
|
1285
|
+
definitions: Map<string, T>;
|
|
1286
|
+
stack: string[];
|
|
1287
|
+
}
|
|
1288
|
+
//#endregion
|
|
1271
1289
|
//#region src/browser/render/types.d.ts
|
|
1272
1290
|
interface DomNodeLike$5 {
|
|
1273
1291
|
attribs?: Record<string, string>;
|
|
@@ -1301,6 +1319,7 @@ interface BrowserSlotContent {
|
|
|
1301
1319
|
ownerFilePath: string;
|
|
1302
1320
|
ownerJsonPath: string;
|
|
1303
1321
|
scope: BrowserRenderScope;
|
|
1322
|
+
templateRenderState: TemplateRenderState<DomNodeLike$5>;
|
|
1304
1323
|
}
|
|
1305
1324
|
interface BrowserRenderedPageTree {
|
|
1306
1325
|
root: DomNodeLike$5;
|
|
@@ -1386,6 +1405,7 @@ interface RuntimeSlotContent {
|
|
|
1386
1405
|
ownerFilePath: string;
|
|
1387
1406
|
ownerJsonPath: string;
|
|
1388
1407
|
scope: RuntimeRenderScope;
|
|
1408
|
+
templateRenderState: TemplateRenderState<DomNodeLike$4>;
|
|
1389
1409
|
}
|
|
1390
1410
|
interface RuntimeRenderedPageTree {
|
|
1391
1411
|
root: DomNodeLike$4;
|
|
@@ -1804,6 +1824,7 @@ declare class HeadlessSession {
|
|
|
1804
1824
|
private appDefinition;
|
|
1805
1825
|
private appInstance;
|
|
1806
1826
|
private readonly moduleLoader;
|
|
1827
|
+
private readonly eventListeners;
|
|
1807
1828
|
private readonly registries;
|
|
1808
1829
|
private currentPageInstance;
|
|
1809
1830
|
private readonly pages;
|
|
@@ -1828,9 +1849,13 @@ declare class HeadlessSession {
|
|
|
1828
1849
|
assertActive(): void;
|
|
1829
1850
|
close(): void;
|
|
1830
1851
|
getDiagnostics(): RuntimeDiagnosticEntry[];
|
|
1852
|
+
on(eventName: string, handler: (...args: any[]) => void): void;
|
|
1853
|
+
removeListener(eventName: string, handler: (...args: any[]) => void): void;
|
|
1854
|
+
private emit;
|
|
1831
1855
|
get isClosed(): boolean;
|
|
1832
1856
|
getApp(): HeadlessAppInstance | null;
|
|
1833
1857
|
getCurrentPages(): HeadlessPageInstance[];
|
|
1858
|
+
getWx(): HeadlessWx;
|
|
1834
1859
|
callWxMethod(methodName: string, ...args: any[]): any;
|
|
1835
1860
|
getCurrentPageNavigationBarTitle(): string | null;
|
|
1836
1861
|
getCurrentPageNavigationBar(): {
|
|
@@ -2108,6 +2133,7 @@ declare class HeadlessSession {
|
|
|
2108
2133
|
errMsg: string;
|
|
2109
2134
|
};
|
|
2110
2135
|
bootstrap(launchOptions?: HeadlessWxLaunchOptions): HeadlessAppInstance;
|
|
2136
|
+
private syncRuntimeAppState;
|
|
2111
2137
|
reLaunch(url: string): HeadlessPageInstance;
|
|
2112
2138
|
navigateTo(url: string): HeadlessPageInstance;
|
|
2113
2139
|
redirectTo(url: string): HeadlessPageInstance;
|
|
@@ -2831,11 +2857,17 @@ declare class HeadlessTestingScopeHandle {
|
|
|
2831
2857
|
interface HeadlessTestingProtocolOptions {
|
|
2832
2858
|
timeout?: number;
|
|
2833
2859
|
}
|
|
2860
|
+
type HeadlessTestingEvaluator<T = unknown> = ((...args: any[]) => T | PromiseLike<T>) | string;
|
|
2834
2861
|
declare class HeadlessTestingSessionHandle {
|
|
2835
2862
|
private readonly project;
|
|
2836
2863
|
private readonly session;
|
|
2837
2864
|
constructor(project: HeadlessProjectDescriptor, session: HeadlessSession);
|
|
2838
2865
|
close(): Promise<void>;
|
|
2866
|
+
on(eventName: string, handler: (...args: any[]) => void): this;
|
|
2867
|
+
removeListener(eventName: string, handler: (...args: any[]) => void): this;
|
|
2868
|
+
off(eventName: string, handler: (...args: any[]) => void): this;
|
|
2869
|
+
evaluate<T = unknown>(evaluator: HeadlessTestingEvaluator<T>, ...args: any[]): Promise<T>;
|
|
2870
|
+
evaluateWithOptions<T = unknown>(evaluator: HeadlessTestingEvaluator<T>, options?: HeadlessTestingProtocolOptions, ...args: any[]): Promise<T>;
|
|
2839
2871
|
currentPage(): Promise<HeadlessTestingPageHandle | null>;
|
|
2840
2872
|
getCurrentPages(): Promise<HeadlessTestingPageHandle[]>;
|
|
2841
2873
|
callWxMethod<T = unknown>(methodName: string, ...args: any[]): Promise<T>;
|
|
@@ -2875,6 +2907,7 @@ declare class HeadlessTestingSessionHandle {
|
|
|
2875
2907
|
triggerResize(options: Record<string, any>): Promise<void>;
|
|
2876
2908
|
triggerRouteDone(options?: Record<string, any>): Promise<void>;
|
|
2877
2909
|
private requireCurrentPage;
|
|
2910
|
+
private evaluateInRuntime;
|
|
2878
2911
|
}
|
|
2879
2912
|
//#endregion
|
|
2880
2913
|
//#region src/testing/launch.d.ts
|
|
@@ -2883,4 +2916,4 @@ interface HeadlessTestingLaunchOptions {
|
|
|
2883
2916
|
}
|
|
2884
2917
|
declare function launch(options: HeadlessTestingLaunchOptions): Promise<HeadlessTestingSessionHandle>;
|
|
2885
2918
|
//#endregion
|
|
2886
|
-
export { ArtifactSource, BrowserDirectoryFileLike, BrowserHeadlessSession, BrowserHeadlessSessionOptions, BrowserModuleLoader, type BrowserRenderedPageTree, type BrowserRendererContext, BrowserVirtualFiles, CreateArtifactProjectOptions, CreateBrowserProjectOptions, type CreateComponentInstanceOptions, CreateProjectDescriptorOptions, HeadlessAppDefinition, HeadlessAppInstance, HeadlessBehaviorDefinition, HeadlessComponentDefinition, type HeadlessComponentInstance, HeadlessHostLoadContext, HeadlessHostRegistries, HeadlessPageDefinition, HeadlessPageInstance, HeadlessProjectConfigFile, HeadlessProjectDescriptor, HeadlessRouteRecord, HeadlessSelectorQueryResolverOptions, HeadlessSession, HeadlessSessionOptions, HeadlessTestingDataMatcher, HeadlessTestingLaunchOptions, HeadlessTestingLogicalNode, HeadlessTestingNodeHandle, HeadlessTestingPageCallMethodOptions, HeadlessTestingPageHandle, HeadlessTestingPageQueryOptions, HeadlessTestingPageSnapshot, HeadlessTestingPageWaitAccess, HeadlessTestingRenderedNodeSnapshot, HeadlessTestingRenderedOptions, HeadlessTestingRenderedPageAccess, HeadlessTestingRenderedSelectorNodesSnapshot, HeadlessTestingScopeHandle, HeadlessTestingSessionHandle, HeadlessTestingWaitForSelectorOptions, HeadlessTestingWaitOptions, HeadlessUniEventBus, HeadlessUniEventHandler, HeadlessWx, HeadlessWxAccessFileOption, HeadlessWxActionSheetLogEntry, HeadlessWxActionSheetMockDefinition, HeadlessWxAnimation, HeadlessWxAnimationAction, HeadlessWxAnimationExportResult, HeadlessWxAnimationStepOption, HeadlessWxAppBaseInfoResult, HeadlessWxAppendFileOption, HeadlessWxCallbackOption, HeadlessWxCanvasContext, HeadlessWxCanvasDrawCall, HeadlessWxCanvasSnapshot, HeadlessWxCanvasToTempFilePathOption, HeadlessWxCanvasToTempFilePathSuccessResult, HeadlessWxChooseImageOption, HeadlessWxChooseImageResult, HeadlessWxChooseImageTempFile, HeadlessWxChooseMediaOption, HeadlessWxChooseMediaResult, HeadlessWxChooseMediaTempFile, HeadlessWxChooseMessageFileOption, HeadlessWxChooseMessageFileResult, HeadlessWxChooseMessageFileTempFile, HeadlessWxChooseVideoOption, HeadlessWxChooseVideoResult, HeadlessWxClearStorageOption, HeadlessWxClipboardSnapshot, HeadlessWxCompressImageOption, HeadlessWxCompressImageResult, HeadlessWxCopyFileOption, HeadlessWxCreateIntersectionObserverOption, HeadlessWxDeviceInfoResult, HeadlessWxDownloadFileLogEntry, HeadlessWxDownloadFileMockDefinition, HeadlessWxDownloadFileOption, HeadlessWxDownloadFileSuccessResult, HeadlessWxDriver, HeadlessWxDriverCapabilities, HeadlessWxFileSystemManager, HeadlessWxFileSystemResult, HeadlessWxGetAppBaseInfoOption, HeadlessWxGetClipboardDataOption, HeadlessWxGetClipboardDataResult, HeadlessWxGetFileInfoOption, HeadlessWxGetFileInfoResult, HeadlessWxGetImageInfoOption, HeadlessWxGetImageInfoResult, HeadlessWxGetLocationOption, HeadlessWxGetLocationResult, HeadlessWxGetNetworkTypeOption, HeadlessWxGetNetworkTypeResult, HeadlessWxGetSavedFileInfoOption, HeadlessWxGetSavedFileInfoSuccessResult, HeadlessWxGetSavedFileListOption, HeadlessWxGetSavedFileListSuccessResult, HeadlessWxGetStorageInfoOption, HeadlessWxGetStorageOption, HeadlessWxGetStorageResult, HeadlessWxGetSystemInfoOption, HeadlessWxGetVideoInfoOption, HeadlessWxGetVideoInfoResult, HeadlessWxGetWindowInfoOption, HeadlessWxHideLoadingOption, HeadlessWxHideNavigationBarLoadingOption, HeadlessWxIntersectionObserver, HeadlessWxIntersectionObserverMargins, HeadlessWxIntersectionObserverObserveAllResult, HeadlessWxLaunchOptions, HeadlessWxLoadFontFaceOption, HeadlessWxLoadFontFaceResult, HeadlessWxLoadingSnapshot, HeadlessWxMediaQueryObserver, HeadlessWxMediaQueryObserverObserveCallbackResult, HeadlessWxMenuButtonBoundingClientRectResult, HeadlessWxMkdirOption, HeadlessWxModalLogEntry, HeadlessWxModalMockDefinition, HeadlessWxNavigateBackOption, HeadlessWxNavigateOption, HeadlessWxNetworkSnapshot, HeadlessWxNetworkStatusChangeCallback, HeadlessWxNetworkStatusChangeResult, HeadlessWxNetworkType, HeadlessWxObserveDescriptor, HeadlessWxOpenDocumentOption, HeadlessWxOpenDocumentResult, HeadlessWxOpenDocumentSnapshot, HeadlessWxPageScrollToOption, HeadlessWxPreviewImageOption, HeadlessWxPreviewImageResult, HeadlessWxPreviewImageSnapshot, HeadlessWxReadDirOption, HeadlessWxReadDirSuccessResult, HeadlessWxReadFileOption, HeadlessWxReadFileSuccessResult, HeadlessWxRemoveSavedFileOption, HeadlessWxRemoveStorageOption, HeadlessWxRenameOption, HeadlessWxRequestLogEntry, HeadlessWxRequestMockDefinition, HeadlessWxRequestOption, HeadlessWxRequestSuccessResult, HeadlessWxRequestTask, HeadlessWxRmdirOption, HeadlessWxSafeArea, HeadlessWxSafeAreaInsets, HeadlessWxSaveFileOption, HeadlessWxSaveFileSuccessResult, HeadlessWxSaveImageToPhotosAlbumOption, HeadlessWxSaveImageToPhotosAlbumResult, HeadlessWxSaveVideoToPhotosAlbumOption, HeadlessWxSaveVideoToPhotosAlbumResult, HeadlessWxSavedFileInfo, HeadlessWxSelectorQuery, HeadlessWxSelectorQueryBoundingClientRectResult, HeadlessWxSelectorQueryFieldsOption, HeadlessWxSelectorQueryNode, HeadlessWxSelectorQueryRequest, HeadlessWxSelectorQueryScrollOffsetResult, HeadlessWxSetBackgroundColorOption, HeadlessWxSetBackgroundTextStyleOption, HeadlessWxSetClipboardDataOption, HeadlessWxSetClipboardDataResult, HeadlessWxSetNavigationBarColorOption, HeadlessWxSetNavigationBarTitleOption, HeadlessWxSetStorageOption, HeadlessWxSetTabBarBadgeOption, HeadlessWxShareMenuOption, HeadlessWxShareMenuSnapshot, HeadlessWxShowActionSheetOption, HeadlessWxShowActionSheetResult, HeadlessWxShowLoadingOption, HeadlessWxShowModalOption, HeadlessWxShowModalResult, HeadlessWxShowNavigationBarLoadingOption, HeadlessWxShowToastOption, HeadlessWxStartPullDownRefreshOption, HeadlessWxStatOption, HeadlessWxStatSuccessResult, HeadlessWxStateOptions, HeadlessWxStats, HeadlessWxStorageInfoResult, HeadlessWxStorageResult, HeadlessWxSystemInfoResult, HeadlessWxTabBarItemOption, HeadlessWxTabBarOption, HeadlessWxToastSnapshot, HeadlessWxUnlinkOption, HeadlessWxUploadFileLogEntry, HeadlessWxUploadFileMockDefinition, HeadlessWxUploadFileOption, HeadlessWxUploadFileSuccessResult, HeadlessWxVideoContext, HeadlessWxWindowInfoResult, HeadlessWxWriteFileOption, MiniProgramEventBinding, PlatformAdapter, RenderedPageTree, RuntimeDiagnosticEntry, RuntimeDiagnosticLevel, RuntimeDiagnostics, RuntimeKernel, type RuntimeRenderedPageTree, type RuntimeRendererContext, RuntimeScheduler, cloneValue, coerceComponentPropertyValue, collectMiniProgramEventBindings, createAppInstance, createArtifactProject, createBrowserHeadlessSession, createBrowserModuleLoader, createBrowserProject, createBrowserVirtualFiles, createBrowserVirtualFilesFromDirectory, createComponentInstance, createFileSystemArtifactSource, createHeadlessSession, createHeadlessUniEventBus, createHeadlessWx, createHeadlessWxState, createHostRegistries, createLogicalNode, createMemoryArtifactSource, createOverlayArtifactSource, createPageInstance, createProjectDescriptor, executeSelectorQueryRequests, hasBrowserVirtualFile, hasComponentPropertyValueChanged, launch, loadProject, normalizeBrowserFilePath, normalizeComponentPropertyValue, querySelectorAll, readBrowserVirtualFile, readRenderedNodes, readRenderedSelectorNodes, registerAppDefinition, registerComponentDefinition, registerExportedComponentDefinition, registerPageDefinition, renderBrowserPageTree, renderPageTree, renderRuntimePageTree, resolveMiniProgramEventBinding, resolveRoutesFromAppConfig, resolveSelectorQueryScopeRoot, resolveSelectorScrollTop, runComponentLifecycle, runComponentObservers, runComponentPageLifetime, waitForPageComponent, waitForPageComponents, waitForPageData, waitForPageSelector, waitForPageText, waitForPageTextGone, waitForRenderedPage, wechat };
|
|
2919
|
+
export { ArtifactSource, BrowserDirectoryFileLike, BrowserHeadlessSession, BrowserHeadlessSessionOptions, BrowserModuleLoader, type BrowserRenderedPageTree, type BrowserRendererContext, BrowserVirtualFiles, CreateArtifactProjectOptions, CreateBrowserProjectOptions, type CreateComponentInstanceOptions, CreateProjectDescriptorOptions, HeadlessAppDefinition, HeadlessAppInstance, HeadlessBehaviorDefinition, HeadlessComponentDefinition, type HeadlessComponentInstance, HeadlessHostLoadContext, HeadlessHostRegistries, HeadlessPageDefinition, HeadlessPageInstance, HeadlessProjectConfigFile, HeadlessProjectDescriptor, HeadlessRouteRecord, HeadlessSelectorQueryResolverOptions, HeadlessSession, HeadlessSessionOptions, HeadlessTestingDataMatcher, HeadlessTestingLaunchOptions, HeadlessTestingLogicalNode, HeadlessTestingNodeHandle, HeadlessTestingPageCallMethodOptions, HeadlessTestingPageHandle, HeadlessTestingPageQueryOptions, HeadlessTestingPageSnapshot, HeadlessTestingPageWaitAccess, HeadlessTestingRenderedNodeSnapshot, HeadlessTestingRenderedOptions, HeadlessTestingRenderedPageAccess, HeadlessTestingRenderedSelectorNodesSnapshot, HeadlessTestingScopeHandle, HeadlessTestingSessionHandle, HeadlessTestingWaitForSelectorOptions, HeadlessTestingWaitOptions, HeadlessUniEventBus, HeadlessUniEventHandler, HeadlessWx, HeadlessWxAccessFileOption, HeadlessWxActionSheetLogEntry, HeadlessWxActionSheetMockDefinition, HeadlessWxAnimation, HeadlessWxAnimationAction, HeadlessWxAnimationExportResult, HeadlessWxAnimationStepOption, HeadlessWxAppBaseInfoResult, HeadlessWxAppendFileOption, HeadlessWxCallbackOption, HeadlessWxCanvasContext, HeadlessWxCanvasDrawCall, HeadlessWxCanvasSnapshot, HeadlessWxCanvasToTempFilePathOption, HeadlessWxCanvasToTempFilePathSuccessResult, HeadlessWxChooseImageOption, HeadlessWxChooseImageResult, HeadlessWxChooseImageTempFile, HeadlessWxChooseMediaOption, HeadlessWxChooseMediaResult, HeadlessWxChooseMediaTempFile, HeadlessWxChooseMessageFileOption, HeadlessWxChooseMessageFileResult, HeadlessWxChooseMessageFileTempFile, HeadlessWxChooseVideoOption, HeadlessWxChooseVideoResult, HeadlessWxClearStorageOption, HeadlessWxClipboardSnapshot, HeadlessWxCompressImageOption, HeadlessWxCompressImageResult, HeadlessWxCopyFileOption, HeadlessWxCreateIntersectionObserverOption, HeadlessWxDeviceInfoResult, HeadlessWxDownloadFileLogEntry, HeadlessWxDownloadFileMockDefinition, HeadlessWxDownloadFileOption, HeadlessWxDownloadFileSuccessResult, HeadlessWxDriver, HeadlessWxDriverCapabilities, HeadlessWxFileSystemManager, HeadlessWxFileSystemResult, HeadlessWxGetAppBaseInfoOption, HeadlessWxGetClipboardDataOption, HeadlessWxGetClipboardDataResult, HeadlessWxGetFileInfoOption, HeadlessWxGetFileInfoResult, HeadlessWxGetImageInfoOption, HeadlessWxGetImageInfoResult, HeadlessWxGetLocationOption, HeadlessWxGetLocationResult, HeadlessWxGetNetworkTypeOption, HeadlessWxGetNetworkTypeResult, HeadlessWxGetSavedFileInfoOption, HeadlessWxGetSavedFileInfoSuccessResult, HeadlessWxGetSavedFileListOption, HeadlessWxGetSavedFileListSuccessResult, HeadlessWxGetStorageInfoOption, HeadlessWxGetStorageOption, HeadlessWxGetStorageResult, HeadlessWxGetSystemInfoOption, HeadlessWxGetVideoInfoOption, HeadlessWxGetVideoInfoResult, HeadlessWxGetWindowInfoOption, HeadlessWxHideLoadingOption, HeadlessWxHideNavigationBarLoadingOption, HeadlessWxIntersectionObserver, HeadlessWxIntersectionObserverMargins, HeadlessWxIntersectionObserverObserveAllResult, HeadlessWxLaunchOptions, HeadlessWxLoadFontFaceOption, HeadlessWxLoadFontFaceResult, HeadlessWxLoadingSnapshot, HeadlessWxMediaQueryObserver, HeadlessWxMediaQueryObserverObserveCallbackResult, HeadlessWxMenuButtonBoundingClientRectResult, HeadlessWxMkdirOption, HeadlessWxModalLogEntry, HeadlessWxModalMockDefinition, HeadlessWxNavigateBackOption, HeadlessWxNavigateOption, HeadlessWxNetworkSnapshot, HeadlessWxNetworkStatusChangeCallback, HeadlessWxNetworkStatusChangeResult, HeadlessWxNetworkType, HeadlessWxObserveDescriptor, HeadlessWxOpenDocumentOption, HeadlessWxOpenDocumentResult, HeadlessWxOpenDocumentSnapshot, HeadlessWxPageScrollToOption, HeadlessWxPreviewImageOption, HeadlessWxPreviewImageResult, HeadlessWxPreviewImageSnapshot, HeadlessWxReadDirOption, HeadlessWxReadDirSuccessResult, HeadlessWxReadFileOption, HeadlessWxReadFileSuccessResult, HeadlessWxRemoveSavedFileOption, HeadlessWxRemoveStorageOption, HeadlessWxRenameOption, HeadlessWxRequestLogEntry, HeadlessWxRequestMockDefinition, HeadlessWxRequestOption, HeadlessWxRequestSuccessResult, HeadlessWxRequestTask, HeadlessWxRmdirOption, HeadlessWxSafeArea, HeadlessWxSafeAreaInsets, HeadlessWxSaveFileOption, HeadlessWxSaveFileSuccessResult, HeadlessWxSaveImageToPhotosAlbumOption, HeadlessWxSaveImageToPhotosAlbumResult, HeadlessWxSaveVideoToPhotosAlbumOption, HeadlessWxSaveVideoToPhotosAlbumResult, HeadlessWxSavedFileInfo, HeadlessWxSelectorQuery, HeadlessWxSelectorQueryBoundingClientRectResult, HeadlessWxSelectorQueryFieldsOption, HeadlessWxSelectorQueryNode, HeadlessWxSelectorQueryRequest, HeadlessWxSelectorQueryScrollOffsetResult, HeadlessWxSetBackgroundColorOption, HeadlessWxSetBackgroundTextStyleOption, HeadlessWxSetClipboardDataOption, HeadlessWxSetClipboardDataResult, HeadlessWxSetNavigationBarColorOption, HeadlessWxSetNavigationBarTitleOption, HeadlessWxSetStorageOption, HeadlessWxSetTabBarBadgeOption, HeadlessWxShareMenuOption, HeadlessWxShareMenuSnapshot, HeadlessWxShowActionSheetOption, HeadlessWxShowActionSheetResult, HeadlessWxShowLoadingOption, HeadlessWxShowModalOption, HeadlessWxShowModalResult, HeadlessWxShowNavigationBarLoadingOption, HeadlessWxShowToastOption, HeadlessWxStartPullDownRefreshOption, HeadlessWxStatOption, HeadlessWxStatSuccessResult, HeadlessWxStateOptions, HeadlessWxStats, HeadlessWxStorageInfoResult, HeadlessWxStorageResult, HeadlessWxSystemInfoResult, HeadlessWxTabBarItemOption, HeadlessWxTabBarOption, HeadlessWxToastSnapshot, HeadlessWxUnlinkOption, HeadlessWxUploadFileLogEntry, HeadlessWxUploadFileMockDefinition, HeadlessWxUploadFileOption, HeadlessWxUploadFileSuccessResult, HeadlessWxVideoContext, HeadlessWxWindowInfoResult, HeadlessWxWriteFileOption, MiniProgramEventBinding, PlatformAdapter, RenderedPageTree, RuntimeConsoleEntry, RuntimeDiagnosticEntry, RuntimeDiagnosticLevel, RuntimeDiagnostics, RuntimeKernel, type RuntimeRenderedPageTree, type RuntimeRendererContext, RuntimeScheduler, cloneValue, coerceComponentPropertyValue, collectMiniProgramEventBindings, createAppInstance, createArtifactProject, createBrowserHeadlessSession, createBrowserModuleLoader, createBrowserProject, createBrowserVirtualFiles, createBrowserVirtualFilesFromDirectory, createComponentInstance, createFileSystemArtifactSource, createHeadlessSession, createHeadlessUniEventBus, createHeadlessWx, createHeadlessWxState, createHostRegistries, createLogicalNode, createMemoryArtifactSource, createOverlayArtifactSource, createPageInstance, createProjectDescriptor, executeSelectorQueryRequests, hasBrowserVirtualFile, hasComponentPropertyValueChanged, launch, loadProject, normalizeBrowserFilePath, normalizeComponentPageDefinition, normalizeComponentPropertyValue, querySelectorAll, readBrowserVirtualFile, readRenderedNodes, readRenderedSelectorNodes, registerAppDefinition, registerComponentDefinition, registerExportedComponentDefinition, registerPageDefinition, renderBrowserPageTree, renderPageTree, renderRuntimePageTree, resolveMiniProgramEventBinding, resolveRoutesFromAppConfig, resolveSelectorQueryScopeRoot, resolveSelectorScrollTop, runComponentLifecycle, runComponentObservers, runComponentPageLifetime, waitForPageComponent, waitForPageComponents, waitForPageData, waitForPageSelector, waitForPageText, waitForPageTextGone, waitForRenderedPage, wechat };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dirname, join, normalize, posix } from "pathe";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { parseExpression } from "@babel/parser";
|
|
4
5
|
import { WEVU_NATIVE_INSTANCE_KEY } from "@weapp-core/constants";
|
|
5
6
|
import { parseDocument } from "htmlparser2";
|
|
6
|
-
import { parseExpression } from "@babel/parser";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import vm from "node:vm";
|
|
9
9
|
//#region src/host/globals.ts
|
|
@@ -65,15 +65,21 @@ function registerAppDefinition(registries, definition) {
|
|
|
65
65
|
registries.appDefinition = definition;
|
|
66
66
|
return definition;
|
|
67
67
|
}
|
|
68
|
-
function registerPageDefinition(registries, definition) {
|
|
69
|
-
const route = registries.currentLoadContext?.route;
|
|
68
|
+
function registerPageDefinition(registries, definition, explicitRoute) {
|
|
69
|
+
const route = explicitRoute ?? registries.currentLoadContext?.route;
|
|
70
70
|
if (!route) throw new Error("Cannot register Page() without an active page load context in headless runtime.");
|
|
71
71
|
if (registries.pages.has(route)) throw createDuplicateRegistrationError("page", route);
|
|
72
72
|
registries.pages.set(route, definition);
|
|
73
73
|
return definition;
|
|
74
74
|
}
|
|
75
75
|
function registerComponentDefinition(registries, definition) {
|
|
76
|
-
if (registries.currentLoadContext?.kind === "page")
|
|
76
|
+
if (registries.currentLoadContext?.kind === "page") {
|
|
77
|
+
if (registries.currentLoadContext.componentDefinitions) {
|
|
78
|
+
registries.currentLoadContext.componentDefinitions.push(definition);
|
|
79
|
+
return definition;
|
|
80
|
+
}
|
|
81
|
+
return registerPageDefinition(registries, normalizeComponentPageDefinition(definition));
|
|
82
|
+
}
|
|
77
83
|
const id = registries.currentLoadContext?.route ?? `anonymous:${registries.components.size}`;
|
|
78
84
|
if (registries.components.has(id)) throw createDuplicateRegistrationError("component", id);
|
|
79
85
|
registries.components.set(id, definition);
|
|
@@ -692,7 +698,11 @@ function createBrowserModuleLoader(files, registries, getCurrentPages, getApp, w
|
|
|
692
698
|
const contextEntries = Object.entries(executionContext);
|
|
693
699
|
new Function(...contextEntries.map(([key]) => key), "exports", "module", "require", "__filename", "__dirname", source)(...contextEntries.map(([, value]) => value), module.exports, module, localRequire, resolvedPath, dirname(resolvedPath));
|
|
694
700
|
const registeredDefinitions = [...registries.components.values()].filter((definition) => !registeredDefinitionsBefore.has(definition));
|
|
695
|
-
module.componentDefinitions = [.../* @__PURE__ */ new Set([
|
|
701
|
+
module.componentDefinitions = [.../* @__PURE__ */ new Set([
|
|
702
|
+
...requiredComponentDefinitions,
|
|
703
|
+
...loadContext?.componentDefinitions ?? [],
|
|
704
|
+
...registeredDefinitions
|
|
705
|
+
])];
|
|
696
706
|
return module;
|
|
697
707
|
} finally {
|
|
698
708
|
registries.currentLoadContext = previousLoadContext;
|
|
@@ -708,11 +718,13 @@ function createBrowserModuleLoader(files, registries, getCurrentPages, getApp, w
|
|
|
708
718
|
return registries.appDefinition;
|
|
709
719
|
},
|
|
710
720
|
executePageModule(filePath, route) {
|
|
711
|
-
executeModule(filePath, {
|
|
721
|
+
const fallbackDefinition = executeModule(filePath, {
|
|
712
722
|
kind: "page",
|
|
713
|
-
route
|
|
714
|
-
|
|
715
|
-
|
|
723
|
+
route,
|
|
724
|
+
componentDefinitions: []
|
|
725
|
+
}).componentDefinitions.at(-1);
|
|
726
|
+
const definition = registries.pages.get(route) ?? (fallbackDefinition ? normalizeComponentPageDefinition(fallbackDefinition) : void 0);
|
|
727
|
+
if (!registries.pages.has(route) && definition) registerPageDefinition(registries, definition, route);
|
|
716
728
|
if (!definition) throw new Error(`Page() was not registered for route "${route}" while executing ${normalize(filePath)}.`);
|
|
717
729
|
return definition;
|
|
718
730
|
},
|
|
@@ -781,15 +793,24 @@ var RuntimeDiagnostics = class {
|
|
|
781
793
|
timestamp: Date.now()
|
|
782
794
|
});
|
|
783
795
|
}
|
|
784
|
-
createConsole(baseConsole = console) {
|
|
796
|
+
createConsole(baseConsole = console, onConsole) {
|
|
785
797
|
const runtimeConsole = Object.create(baseConsole);
|
|
798
|
+
const wrap = (level, method) => (...args) => {
|
|
799
|
+
if (level === "error" || level === "warn") this.record(level, args);
|
|
800
|
+
onConsole?.({
|
|
801
|
+
args: [...args],
|
|
802
|
+
level
|
|
803
|
+
});
|
|
804
|
+
method(...args);
|
|
805
|
+
};
|
|
806
|
+
runtimeConsole.debug = wrap("debug", baseConsole.debug.bind(baseConsole));
|
|
807
|
+
runtimeConsole.info = wrap("info", baseConsole.info.bind(baseConsole));
|
|
808
|
+
runtimeConsole.log = wrap("log", baseConsole.log.bind(baseConsole));
|
|
786
809
|
runtimeConsole.error = (...args) => {
|
|
787
|
-
|
|
788
|
-
baseConsole.error(...args);
|
|
810
|
+
wrap("error", baseConsole.error.bind(baseConsole))(...args);
|
|
789
811
|
};
|
|
790
812
|
runtimeConsole.warn = (...args) => {
|
|
791
|
-
|
|
792
|
-
baseConsole.warn(...args);
|
|
813
|
+
wrap("warn", baseConsole.warn.bind(baseConsole))(...args);
|
|
793
814
|
};
|
|
794
815
|
return runtimeConsole;
|
|
795
816
|
}
|
|
@@ -1241,11 +1262,15 @@ function resolveInitialProperties(definition, properties) {
|
|
|
1241
1262
|
//#region src/runtime/componentInstance/index.ts
|
|
1242
1263
|
function createComponentInstance(options) {
|
|
1243
1264
|
const definition = normalizeComponentDefinition(options.definition);
|
|
1265
|
+
const properties = resolveInitialProperties(definition, options.properties ?? {});
|
|
1244
1266
|
const instance = {
|
|
1245
1267
|
__definition__: definition,
|
|
1246
|
-
data:
|
|
1268
|
+
data: {
|
|
1269
|
+
...resolveInitialData$2(definition),
|
|
1270
|
+
...properties
|
|
1271
|
+
},
|
|
1247
1272
|
__propertySnapshots__: {},
|
|
1248
|
-
properties
|
|
1273
|
+
properties,
|
|
1249
1274
|
setData(patch, callback) {
|
|
1250
1275
|
const changedKeys = Object.keys(patch);
|
|
1251
1276
|
for (const [key, value] of Object.entries(patch)) assignByPath$1(instance.data, key, value);
|
|
@@ -1280,119 +1305,6 @@ function runComponentPageLifetime(instance, lifetimeName, payload) {
|
|
|
1280
1305
|
handler.call(instance, payload);
|
|
1281
1306
|
}
|
|
1282
1307
|
//#endregion
|
|
1283
|
-
//#region src/view/eventBinding.ts
|
|
1284
|
-
const LEGACY_EVENT_NAME_RE = /^\w+$/;
|
|
1285
|
-
const EVENT_BINDING_PREFIXES = [
|
|
1286
|
-
{
|
|
1287
|
-
prefix: "bind:",
|
|
1288
|
-
priority: 0,
|
|
1289
|
-
stopAfter: false
|
|
1290
|
-
},
|
|
1291
|
-
{
|
|
1292
|
-
prefix: "catch:",
|
|
1293
|
-
priority: 0,
|
|
1294
|
-
stopAfter: true
|
|
1295
|
-
},
|
|
1296
|
-
{
|
|
1297
|
-
prefix: "bind",
|
|
1298
|
-
priority: 1,
|
|
1299
|
-
stopAfter: false
|
|
1300
|
-
},
|
|
1301
|
-
{
|
|
1302
|
-
prefix: "catch",
|
|
1303
|
-
priority: 1,
|
|
1304
|
-
stopAfter: true
|
|
1305
|
-
}
|
|
1306
|
-
];
|
|
1307
|
-
function parseEventBinding(attributeName, method) {
|
|
1308
|
-
const definition = EVENT_BINDING_PREFIXES.find((item) => attributeName.startsWith(item.prefix));
|
|
1309
|
-
if (!definition) return null;
|
|
1310
|
-
const eventName = attributeName.slice(definition.prefix.length);
|
|
1311
|
-
if (!eventName || !definition.prefix.endsWith(":") && !LEGACY_EVENT_NAME_RE.test(eventName)) return null;
|
|
1312
|
-
return {
|
|
1313
|
-
eventName,
|
|
1314
|
-
method,
|
|
1315
|
-
priority: definition.priority,
|
|
1316
|
-
stopAfter: definition.stopAfter
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
function collectMiniProgramEventBindings(attributes = {}) {
|
|
1320
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
1321
|
-
const priorities = /* @__PURE__ */ new Map();
|
|
1322
|
-
for (const [attributeName, method] of Object.entries(attributes)) {
|
|
1323
|
-
const candidate = parseEventBinding(attributeName, method);
|
|
1324
|
-
if (!candidate || candidate.priority < (priorities.get(candidate.eventName) ?? -1)) continue;
|
|
1325
|
-
bindings.set(candidate.eventName, {
|
|
1326
|
-
method: candidate.method,
|
|
1327
|
-
stopAfter: candidate.stopAfter
|
|
1328
|
-
});
|
|
1329
|
-
priorities.set(candidate.eventName, candidate.priority);
|
|
1330
|
-
}
|
|
1331
|
-
return bindings;
|
|
1332
|
-
}
|
|
1333
|
-
function resolveMiniProgramEventBinding(attributes, eventName) {
|
|
1334
|
-
return collectMiniProgramEventBindings(attributes).get(eventName) ?? null;
|
|
1335
|
-
}
|
|
1336
|
-
//#endregion
|
|
1337
|
-
//#region src/view/selectorQueryScope.ts
|
|
1338
|
-
const MPCORE_COMPONENT_SCOPE_ID = "__mpcoreComponentScopeId";
|
|
1339
|
-
function isScopeCandidate(value) {
|
|
1340
|
-
return typeof value === "object" && value !== null || typeof value === "function";
|
|
1341
|
-
}
|
|
1342
|
-
function resolveScopeCandidates(scope) {
|
|
1343
|
-
const candidates = [];
|
|
1344
|
-
const visited = /* @__PURE__ */ new Set();
|
|
1345
|
-
const queue = [scope];
|
|
1346
|
-
while (queue.length > 0) {
|
|
1347
|
-
const candidate = queue.shift();
|
|
1348
|
-
if (!isScopeCandidate(candidate) || visited.has(candidate)) continue;
|
|
1349
|
-
visited.add(candidate);
|
|
1350
|
-
candidates.push(candidate);
|
|
1351
|
-
queue.push(candidate.$, candidate.$el, candidate.$state, candidate[WEVU_NATIVE_INSTANCE_KEY]);
|
|
1352
|
-
}
|
|
1353
|
-
return candidates;
|
|
1354
|
-
}
|
|
1355
|
-
function resolveSelectorQueryNativeScope(scope, page, components) {
|
|
1356
|
-
if (!scope) return;
|
|
1357
|
-
const nativeScopes = [page, ...components];
|
|
1358
|
-
const nativeScopeSet = new Set(nativeScopes);
|
|
1359
|
-
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1360
|
-
if (nativeScopeSet.has(candidate)) return candidate;
|
|
1361
|
-
const scopeId = candidate[MPCORE_COMPONENT_SCOPE_ID];
|
|
1362
|
-
if (typeof scopeId !== "string" || !scopeId) continue;
|
|
1363
|
-
const currentScope = nativeScopes.find((nativeScope) => nativeScope[MPCORE_COMPONENT_SCOPE_ID] === scopeId);
|
|
1364
|
-
if (currentScope) return currentScope;
|
|
1365
|
-
}
|
|
1366
|
-
return null;
|
|
1367
|
-
}
|
|
1368
|
-
function setSelectorQueryScopeId(scope, scopeId) {
|
|
1369
|
-
Object.defineProperty(scope, MPCORE_COMPONENT_SCOPE_ID, {
|
|
1370
|
-
configurable: true,
|
|
1371
|
-
enumerable: false,
|
|
1372
|
-
value: scopeId,
|
|
1373
|
-
writable: false
|
|
1374
|
-
});
|
|
1375
|
-
}
|
|
1376
|
-
function resolveSelectorQueryScopeId(scope) {
|
|
1377
|
-
if (!scope) return null;
|
|
1378
|
-
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1379
|
-
const scopeId = candidate[MPCORE_COMPONENT_SCOPE_ID];
|
|
1380
|
-
if (typeof scopeId === "string" && scopeId) return scopeId;
|
|
1381
|
-
}
|
|
1382
|
-
return null;
|
|
1383
|
-
}
|
|
1384
|
-
function resolveSelectorQueryScopeSnapshot(scope, snapshots) {
|
|
1385
|
-
if (!scope) return null;
|
|
1386
|
-
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1387
|
-
const snapshot = snapshots.get(candidate);
|
|
1388
|
-
if (snapshot) return {
|
|
1389
|
-
nativeScope: candidate,
|
|
1390
|
-
snapshot
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
return null;
|
|
1394
|
-
}
|
|
1395
|
-
//#endregion
|
|
1396
1308
|
//#region src/view/templateExpression.ts
|
|
1397
1309
|
const expressionCache = /* @__PURE__ */ new Map();
|
|
1398
1310
|
const BLOCKED_MEMBER_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -1400,7 +1312,7 @@ const BLOCKED_MEMBER_KEYS = /* @__PURE__ */ new Set([
|
|
|
1400
1312
|
"constructor",
|
|
1401
1313
|
"prototype"
|
|
1402
1314
|
]);
|
|
1403
|
-
const NUMERIC_DOT_PATH_RE = /\.(\d+)(?=[.[\s]|$)/g;
|
|
1315
|
+
const NUMERIC_DOT_PATH_RE = /\.(\d+)(?=[.[\s,}\]]|$)/g;
|
|
1404
1316
|
function isMustacheOnly$2(value) {
|
|
1405
1317
|
const trimmed = value.trim();
|
|
1406
1318
|
return trimmed.startsWith("{{") && trimmed.endsWith("}}") && !trimmed.includes("{{", 2);
|
|
@@ -1532,6 +1444,160 @@ function resolveTemplateExpression(source, expression) {
|
|
|
1532
1444
|
return evaluateExpressionNode(parseTemplateExpression(normalized), source);
|
|
1533
1445
|
}
|
|
1534
1446
|
//#endregion
|
|
1447
|
+
//#region src/view/templateRuntime.ts
|
|
1448
|
+
function isTagNode$2(node) {
|
|
1449
|
+
return node.type === "tag" && typeof node.name === "string";
|
|
1450
|
+
}
|
|
1451
|
+
function readMustacheExpression(value) {
|
|
1452
|
+
const trimmed = value.trim();
|
|
1453
|
+
return trimmed.startsWith("{{") && trimmed.endsWith("}}") ? trimmed.slice(2, -2).trim() : trimmed;
|
|
1454
|
+
}
|
|
1455
|
+
function createTemplateRenderState(root) {
|
|
1456
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
1457
|
+
const visit = (node) => {
|
|
1458
|
+
if (isTagNode$2(node) && node.name === "template") {
|
|
1459
|
+
const name = node.attribs?.name?.trim();
|
|
1460
|
+
if (name) definitions.set(name, node);
|
|
1461
|
+
}
|
|
1462
|
+
for (const child of node.children ?? []) visit(child);
|
|
1463
|
+
};
|
|
1464
|
+
visit(root);
|
|
1465
|
+
return {
|
|
1466
|
+
definitions,
|
|
1467
|
+
stack: []
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function isTemplateDefinition(node) {
|
|
1471
|
+
return node.name === "template" && Boolean(node.attribs?.name?.trim());
|
|
1472
|
+
}
|
|
1473
|
+
function resolveTemplateCall(node, source) {
|
|
1474
|
+
if (node.name !== "template" || isTemplateDefinition(node)) return;
|
|
1475
|
+
const isValue = node.attribs?.is?.trim();
|
|
1476
|
+
if (!isValue) return;
|
|
1477
|
+
const name = isValue.includes("{{") ? resolveTemplateExpression(source, readMustacheExpression(isValue)) : isValue;
|
|
1478
|
+
return typeof name === "string" && name ? name : void 0;
|
|
1479
|
+
}
|
|
1480
|
+
function resolveTemplateData(node, source) {
|
|
1481
|
+
const dataValue = node.attribs?.data?.trim();
|
|
1482
|
+
if (!dataValue) return {};
|
|
1483
|
+
const expression = readMustacheExpression(dataValue);
|
|
1484
|
+
const resolved = resolveTemplateExpression(source, expression) ?? resolveTemplateExpression(source, `{${expression}}`);
|
|
1485
|
+
return resolved && typeof resolved === "object" ? resolved : {};
|
|
1486
|
+
}
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region src/view/eventBinding.ts
|
|
1489
|
+
const LEGACY_EVENT_NAME_RE = /^\w+$/;
|
|
1490
|
+
const EVENT_BINDING_PREFIXES = [
|
|
1491
|
+
{
|
|
1492
|
+
prefix: "bind:",
|
|
1493
|
+
priority: 0,
|
|
1494
|
+
stopAfter: false
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
prefix: "catch:",
|
|
1498
|
+
priority: 0,
|
|
1499
|
+
stopAfter: true
|
|
1500
|
+
},
|
|
1501
|
+
{
|
|
1502
|
+
prefix: "bind",
|
|
1503
|
+
priority: 1,
|
|
1504
|
+
stopAfter: false
|
|
1505
|
+
},
|
|
1506
|
+
{
|
|
1507
|
+
prefix: "catch",
|
|
1508
|
+
priority: 1,
|
|
1509
|
+
stopAfter: true
|
|
1510
|
+
}
|
|
1511
|
+
];
|
|
1512
|
+
function parseEventBinding(attributeName, method) {
|
|
1513
|
+
const definition = EVENT_BINDING_PREFIXES.find((item) => attributeName.startsWith(item.prefix));
|
|
1514
|
+
if (!definition) return null;
|
|
1515
|
+
const eventName = attributeName.slice(definition.prefix.length);
|
|
1516
|
+
if (!eventName || !definition.prefix.endsWith(":") && !LEGACY_EVENT_NAME_RE.test(eventName)) return null;
|
|
1517
|
+
return {
|
|
1518
|
+
eventName,
|
|
1519
|
+
method,
|
|
1520
|
+
priority: definition.priority,
|
|
1521
|
+
stopAfter: definition.stopAfter
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
function collectMiniProgramEventBindings(attributes = {}) {
|
|
1525
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
1526
|
+
const priorities = /* @__PURE__ */ new Map();
|
|
1527
|
+
for (const [attributeName, method] of Object.entries(attributes)) {
|
|
1528
|
+
const candidate = parseEventBinding(attributeName, method);
|
|
1529
|
+
if (!candidate || candidate.priority < (priorities.get(candidate.eventName) ?? -1)) continue;
|
|
1530
|
+
bindings.set(candidate.eventName, {
|
|
1531
|
+
method: candidate.method,
|
|
1532
|
+
stopAfter: candidate.stopAfter
|
|
1533
|
+
});
|
|
1534
|
+
priorities.set(candidate.eventName, candidate.priority);
|
|
1535
|
+
}
|
|
1536
|
+
return bindings;
|
|
1537
|
+
}
|
|
1538
|
+
function resolveMiniProgramEventBinding(attributes, eventName) {
|
|
1539
|
+
return collectMiniProgramEventBindings(attributes).get(eventName) ?? null;
|
|
1540
|
+
}
|
|
1541
|
+
//#endregion
|
|
1542
|
+
//#region src/view/selectorQueryScope.ts
|
|
1543
|
+
const MPCORE_COMPONENT_SCOPE_ID = "__mpcoreComponentScopeId";
|
|
1544
|
+
function isScopeCandidate(value) {
|
|
1545
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
1546
|
+
}
|
|
1547
|
+
function resolveScopeCandidates(scope) {
|
|
1548
|
+
const candidates = [];
|
|
1549
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1550
|
+
const queue = [scope];
|
|
1551
|
+
while (queue.length > 0) {
|
|
1552
|
+
const candidate = queue.shift();
|
|
1553
|
+
if (!isScopeCandidate(candidate) || visited.has(candidate)) continue;
|
|
1554
|
+
visited.add(candidate);
|
|
1555
|
+
candidates.push(candidate);
|
|
1556
|
+
queue.push(candidate.$, candidate.$el, candidate.$state, candidate[WEVU_NATIVE_INSTANCE_KEY]);
|
|
1557
|
+
}
|
|
1558
|
+
return candidates;
|
|
1559
|
+
}
|
|
1560
|
+
function resolveSelectorQueryNativeScope(scope, page, components) {
|
|
1561
|
+
if (!scope) return;
|
|
1562
|
+
const nativeScopes = [page, ...components];
|
|
1563
|
+
const nativeScopeSet = new Set(nativeScopes);
|
|
1564
|
+
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1565
|
+
if (nativeScopeSet.has(candidate)) return candidate;
|
|
1566
|
+
const scopeId = candidate[MPCORE_COMPONENT_SCOPE_ID];
|
|
1567
|
+
if (typeof scopeId !== "string" || !scopeId) continue;
|
|
1568
|
+
const currentScope = nativeScopes.find((nativeScope) => nativeScope[MPCORE_COMPONENT_SCOPE_ID] === scopeId);
|
|
1569
|
+
if (currentScope) return currentScope;
|
|
1570
|
+
}
|
|
1571
|
+
return null;
|
|
1572
|
+
}
|
|
1573
|
+
function setSelectorQueryScopeId(scope, scopeId) {
|
|
1574
|
+
Object.defineProperty(scope, MPCORE_COMPONENT_SCOPE_ID, {
|
|
1575
|
+
configurable: true,
|
|
1576
|
+
enumerable: false,
|
|
1577
|
+
value: scopeId,
|
|
1578
|
+
writable: false
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
function resolveSelectorQueryScopeId(scope) {
|
|
1582
|
+
if (!scope) return null;
|
|
1583
|
+
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1584
|
+
const scopeId = candidate[MPCORE_COMPONENT_SCOPE_ID];
|
|
1585
|
+
if (typeof scopeId === "string" && scopeId) return scopeId;
|
|
1586
|
+
}
|
|
1587
|
+
return null;
|
|
1588
|
+
}
|
|
1589
|
+
function resolveSelectorQueryScopeSnapshot(scope, snapshots) {
|
|
1590
|
+
if (!scope) return null;
|
|
1591
|
+
for (const candidate of resolveScopeCandidates(scope)) {
|
|
1592
|
+
const snapshot = snapshots.get(candidate);
|
|
1593
|
+
if (snapshot) return {
|
|
1594
|
+
nativeScope: candidate,
|
|
1595
|
+
snapshot
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
return null;
|
|
1599
|
+
}
|
|
1600
|
+
//#endregion
|
|
1535
1601
|
//#region src/browser/render/shared.ts
|
|
1536
1602
|
const TEMPLATE_INTERPOLATION_RE$2 = /\{\{([^{}]+)\}\}/g;
|
|
1537
1603
|
const DATASET_NAME_RE$4 = /-([a-z])/g;
|
|
@@ -1783,6 +1849,7 @@ function syncComponentProperties$1(instance, definition, nextProperties, binding
|
|
|
1783
1849
|
if (hasComponentPropertyValueChanged(instance.properties[key], previousSnapshot, nextValue, bindingAffected)) {
|
|
1784
1850
|
previousProperties[key] = instance.properties[key];
|
|
1785
1851
|
instance.properties[key] = nextValue;
|
|
1852
|
+
instance.data[key] = nextValue;
|
|
1786
1853
|
changedRootKeys.push(key);
|
|
1787
1854
|
}
|
|
1788
1855
|
instance.__propertySnapshots ??= {};
|
|
@@ -1829,9 +1896,10 @@ function resolveComponentProperties$1(clonedNode, scope, definition) {
|
|
|
1829
1896
|
};
|
|
1830
1897
|
}
|
|
1831
1898
|
function createBrowserComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId) {
|
|
1899
|
+
const componentProperties = Object.keys(componentEntry.definition.methods ?? {}).some((key) => key.startsWith("__weapp_vite_")) || Object.hasOwn(componentEntry.definition.properties ?? {}, "__wvSlotOwnerId") ? Object.fromEntries(Object.keys(componentEntry.definition.properties ?? {}).filter((key) => Object.hasOwn(nextProperties, key)).map((key) => [key, nextProperties[key]])) : nextProperties;
|
|
1832
1900
|
const componentInstance = createComponentInstance({
|
|
1833
1901
|
definition: componentEntry.definition,
|
|
1834
|
-
properties:
|
|
1902
|
+
properties: componentProperties,
|
|
1835
1903
|
requestRender: (callback) => context.session.requestRender(callback),
|
|
1836
1904
|
triggerEvent: buildComponentTrigger$1(componentScopeId, context, clonedNode)
|
|
1837
1905
|
});
|
|
@@ -1844,7 +1912,7 @@ function createBrowserComponentInstance(componentScopeId, context, clonedNode, c
|
|
|
1844
1912
|
componentInstance.selectOwnerComponent = () => ownerScopeId ? context.componentCache.get(ownerScopeId) ?? null : null;
|
|
1845
1913
|
context.componentCache.set(componentScopeId, componentInstance);
|
|
1846
1914
|
runComponentLifecycle(componentInstance, "created");
|
|
1847
|
-
runComponentObservers(componentInstance.__definition__ ?? componentEntry.definition, componentInstance, Object.keys(
|
|
1915
|
+
runComponentObservers(componentInstance.__definition__ ?? componentEntry.definition, componentInstance, Object.keys(componentProperties), {});
|
|
1848
1916
|
componentInstance.__propertySnapshots = Object.fromEntries(Object.entries(componentInstance.properties).map(([key, propertyValue]) => [key, cloneValue(propertyValue)]));
|
|
1849
1917
|
runComponentLifecycle(componentInstance, "attached");
|
|
1850
1918
|
runComponentPageLifetime(componentInstance, "show");
|
|
@@ -1852,7 +1920,9 @@ function createBrowserComponentInstance(componentScopeId, context, clonedNode, c
|
|
|
1852
1920
|
}
|
|
1853
1921
|
function renderBrowserComponentTemplate(context, componentEntry, renderNodeTree, componentScope, componentScopeId, seenComponentScopes) {
|
|
1854
1922
|
const componentDocument = parseTemplateDocument$1(readTemplateSource$1(context.files, componentEntry.templatePath));
|
|
1855
|
-
|
|
1923
|
+
const componentRoot = (componentDocument.children ?? [])[0] ?? componentDocument;
|
|
1924
|
+
const templateRenderState = createTemplateRenderState(componentRoot);
|
|
1925
|
+
return renderNodeTree(componentRoot, componentScope, context, `${componentEntry.filePath.replace(JS_FILE_RE$1, "")}.json`, componentEntry.filePath, componentScopeId, seenComponentScopes, templateRenderState);
|
|
1856
1926
|
}
|
|
1857
1927
|
//#endregion
|
|
1858
1928
|
//#region src/browser/render/index.ts
|
|
@@ -1873,17 +1943,18 @@ function expandNodeByFor$1(node, scope) {
|
|
|
1873
1943
|
instanceSuffix: `:for-${index}`
|
|
1874
1944
|
}));
|
|
1875
1945
|
}
|
|
1876
|
-
function renderNodeVariants$1(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
1877
|
-
return expandNodeByFor$1(node, scope).map(({ node: expandedNode, scope: expandedScope, instanceSuffix }) => renderNodeTree$1(expandedNode, expandedScope, context, ownerJsonPath, ownerFilePath, `${instancePath}${instanceSuffix}`, seenComponentScopes));
|
|
1946
|
+
function renderNodeVariants$1(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
1947
|
+
return expandNodeByFor$1(node, scope).map(({ node: expandedNode, scope: expandedScope, instanceSuffix }) => renderNodeTree$1(expandedNode, expandedScope, context, ownerJsonPath, ownerFilePath, `${instancePath}${instanceSuffix}`, seenComponentScopes, templateRenderState));
|
|
1878
1948
|
}
|
|
1879
|
-
function renderChildren$1(children, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
1949
|
+
function renderChildren$1(children, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
1880
1950
|
const renderedChildren = [];
|
|
1881
1951
|
for (let index = 0; index < children.length; index += 1) {
|
|
1882
1952
|
const child = children[index];
|
|
1883
1953
|
if (!isTagNode$1(child)) {
|
|
1884
|
-
renderedChildren.push(...renderNodeVariants$1(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes));
|
|
1954
|
+
renderedChildren.push(...renderNodeVariants$1(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes, templateRenderState));
|
|
1885
1955
|
continue;
|
|
1886
1956
|
}
|
|
1957
|
+
if (isTemplateDefinition(child)) continue;
|
|
1887
1958
|
const hasConditional = child.attribs?.["wx:if"] != null;
|
|
1888
1959
|
const isElseBranch = child.attribs?.["wx:elif"] != null || child.attribs?.["wx:else"] != null;
|
|
1889
1960
|
if (hasConditional) {
|
|
@@ -1898,7 +1969,7 @@ function renderChildren$1(children, scope, context, ownerJsonPath, ownerFilePath
|
|
|
1898
1969
|
if (!isTagNode$1(branch)) break;
|
|
1899
1970
|
if (cursor !== index && !WX_ELSE_ATTRS$1.has(Object.keys(branch.attribs ?? {}).find((key) => key.startsWith("wx:")) ?? "")) break;
|
|
1900
1971
|
if (branch.attribs?.["wx:else"] != null ? !branchMatched : !branchMatched && evaluateConditionalBranch$1(branch, scope)) {
|
|
1901
|
-
renderedChildren.push(...renderNodeVariants$1(branch, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${cursor}`, seenComponentScopes));
|
|
1972
|
+
renderedChildren.push(...renderNodeVariants$1(branch, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${cursor}`, seenComponentScopes, templateRenderState));
|
|
1902
1973
|
branchMatched = true;
|
|
1903
1974
|
}
|
|
1904
1975
|
let nextBranchIndex = cursor + 1;
|
|
@@ -1911,11 +1982,11 @@ function renderChildren$1(children, scope, context, ownerJsonPath, ownerFilePath
|
|
|
1911
1982
|
continue;
|
|
1912
1983
|
}
|
|
1913
1984
|
if (isElseBranch) continue;
|
|
1914
|
-
renderedChildren.push(...renderNodeVariants$1(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes));
|
|
1985
|
+
renderedChildren.push(...renderNodeVariants$1(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes, templateRenderState));
|
|
1915
1986
|
}
|
|
1916
1987
|
return renderedChildren;
|
|
1917
1988
|
}
|
|
1918
|
-
function collectComponentSlots$1(componentNode, scope, ownerJsonPath, ownerFilePath, instancePath) {
|
|
1989
|
+
function collectComponentSlots$1(componentNode, scope, ownerJsonPath, ownerFilePath, instancePath, templateRenderState) {
|
|
1919
1990
|
const slots = /* @__PURE__ */ new Map();
|
|
1920
1991
|
(componentNode.children ?? []).forEach((node, index) => {
|
|
1921
1992
|
const slotName = isTagNode$1(node) && typeof node.attribs?.slot === "string" && node.attribs.slot.trim() ? node.attribs.slot.trim() : "default";
|
|
@@ -1925,7 +1996,8 @@ function collectComponentSlots$1(componentNode, scope, ownerJsonPath, ownerFileP
|
|
|
1925
1996
|
node,
|
|
1926
1997
|
ownerFilePath,
|
|
1927
1998
|
ownerJsonPath,
|
|
1928
|
-
scope
|
|
1999
|
+
scope,
|
|
2000
|
+
templateRenderState
|
|
1929
2001
|
});
|
|
1930
2002
|
slots.set(slotName, entries);
|
|
1931
2003
|
});
|
|
@@ -1942,16 +2014,43 @@ function collectComponentSlots$1(componentNode, scope, ownerJsonPath, ownerFileP
|
|
|
1942
2014
|
}
|
|
1943
2015
|
return slots;
|
|
1944
2016
|
}
|
|
1945
|
-
function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
2017
|
+
function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
1946
2018
|
const clonedNode = cloneNode$1(node);
|
|
1947
2019
|
if (!isTagNode$1(clonedNode)) {
|
|
1948
2020
|
applyNodeBindings$1(clonedNode, scope);
|
|
1949
2021
|
return clonedNode;
|
|
1950
2022
|
}
|
|
2023
|
+
if (isTemplateDefinition(clonedNode)) return {
|
|
2024
|
+
type: "tag",
|
|
2025
|
+
name: "block",
|
|
2026
|
+
attribs: {},
|
|
2027
|
+
children: []
|
|
2028
|
+
};
|
|
2029
|
+
const templateName = resolveTemplateCall(clonedNode, scope.data);
|
|
2030
|
+
if (templateName) {
|
|
2031
|
+
const definition = templateRenderState.definitions.get(templateName);
|
|
2032
|
+
const templateScope = {
|
|
2033
|
+
...scope,
|
|
2034
|
+
data: resolveTemplateData(clonedNode, scope.data)
|
|
2035
|
+
};
|
|
2036
|
+
const children = definition && !templateRenderState.stack.includes(templateName) ? renderChildren$1(definition.children ?? [], templateScope, context, ownerJsonPath, ownerFilePath, `${instancePath}/template-${templateName}`, seenComponentScopes, {
|
|
2037
|
+
definitions: templateRenderState.definitions,
|
|
2038
|
+
stack: [...templateRenderState.stack, templateName]
|
|
2039
|
+
}) : [];
|
|
2040
|
+
return {
|
|
2041
|
+
type: "tag",
|
|
2042
|
+
name: "block",
|
|
2043
|
+
attribs: {
|
|
2044
|
+
"data-sim-node": instancePath,
|
|
2045
|
+
"data-sim-scope": scope.getScopeId()
|
|
2046
|
+
},
|
|
2047
|
+
children
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
1951
2050
|
if (clonedNode.name === "slot") {
|
|
1952
2051
|
const slotName = clonedNode.attribs?.name?.trim() || "default";
|
|
1953
2052
|
const projected = scope.slots?.get(slotName) ?? [];
|
|
1954
|
-
const children = projected.length ? projected.flatMap((entry) => renderNodeVariants$1(entry.node, entry.scope, context, entry.ownerJsonPath, entry.ownerFilePath, entry.instancePath, seenComponentScopes)) : renderChildren$1(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/slot-fallback-${slotName}`, seenComponentScopes);
|
|
2053
|
+
const children = projected.length ? projected.flatMap((entry) => renderNodeVariants$1(entry.node, entry.scope, context, entry.ownerJsonPath, entry.ownerFilePath, entry.instancePath, seenComponentScopes, entry.templateRenderState)) : renderChildren$1(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/slot-fallback-${slotName}`, seenComponentScopes, templateRenderState);
|
|
1955
2054
|
return {
|
|
1956
2055
|
type: "tag",
|
|
1957
2056
|
name: "block",
|
|
@@ -1969,7 +2068,7 @@ function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, in
|
|
|
1969
2068
|
else syncComponentProperties$1(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, nextProperties, bindingExpressions, context.changedPageKeys);
|
|
1970
2069
|
seenComponentScopes.add(componentScopeId);
|
|
1971
2070
|
const genericComponents = resolveComponentGenerics$1(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
1972
|
-
const slots = collectComponentSlots$1(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId);
|
|
2071
|
+
const slots = collectComponentSlots$1(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
1973
2072
|
const componentScope = createComponentScope$1(clonedNode, scope, componentScopeId, componentInstance, genericComponents, slots);
|
|
1974
2073
|
context.componentScopes.set(componentScopeId, componentScope);
|
|
1975
2074
|
const renderedComponentRoot = renderBrowserComponentTemplate(context, componentEntry, renderNodeTree$1, componentScope, componentScopeId, seenComponentScopes);
|
|
@@ -1984,7 +2083,7 @@ function renderNodeTree$1(node, scope, context, ownerJsonPath, ownerFilePath, in
|
|
|
1984
2083
|
return renderedComponentRoot;
|
|
1985
2084
|
}
|
|
1986
2085
|
applyNodeBindings$1(clonedNode, scope);
|
|
1987
|
-
clonedNode.children = renderChildren$1(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/${clonedNode.name}`, seenComponentScopes);
|
|
2086
|
+
clonedNode.children = renderChildren$1(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/${clonedNode.name}`, seenComponentScopes, templateRenderState);
|
|
1988
2087
|
return clonedNode;
|
|
1989
2088
|
}
|
|
1990
2089
|
function renderBrowserPageTree(context, page) {
|
|
@@ -2004,7 +2103,9 @@ function renderBrowserPageTree(context, page) {
|
|
|
2004
2103
|
context.componentScopes.clear();
|
|
2005
2104
|
context.componentScopes.set(pageScopeId, pageScope);
|
|
2006
2105
|
const seenComponentScopes = /* @__PURE__ */ new Set();
|
|
2007
|
-
const
|
|
2106
|
+
const root = (document.children ?? [])[0] ?? document;
|
|
2107
|
+
const templateRenderState = createTemplateRenderState(root);
|
|
2108
|
+
const renderedRoot = renderNodeTree$1(root, pageScope, context, `${route}.json`, `${route}.js`, pageScopeId, seenComponentScopes, templateRenderState);
|
|
2008
2109
|
for (const [scopeId, instance] of [...context.componentCache.entries()]) if (!seenComponentScopes.has(scopeId)) {
|
|
2009
2110
|
runComponentLifecycle(instance, "detached");
|
|
2010
2111
|
context.componentCache.delete(scopeId);
|
|
@@ -4164,12 +4265,15 @@ function parseNumericLikeValue$1(value) {
|
|
|
4164
4265
|
const match = value.match(NUMERIC_LIKE_VALUE_RE$1);
|
|
4165
4266
|
return match ? Number(match[0]) : 0;
|
|
4166
4267
|
}
|
|
4167
|
-
function resolveRect$1(node) {
|
|
4268
|
+
function resolveRect$1(node, windowInfo) {
|
|
4168
4269
|
const style = parseStyleDeclarations$1(node.attribs?.style);
|
|
4169
4270
|
const left = parseNumericLikeValue$1(node.attribs?.["data-sim-left"] ?? style.left);
|
|
4170
4271
|
const top = parseNumericLikeValue$1(node.attribs?.["data-sim-top"] ?? style.top);
|
|
4171
|
-
const
|
|
4172
|
-
const
|
|
4272
|
+
const rawWidth = node.attribs?.["data-sim-width"] ?? style.width;
|
|
4273
|
+
const rawHeight = node.attribs?.["data-sim-height"] ?? style.height;
|
|
4274
|
+
const isTopLevelView = node.name === "view" && node.parent?.name === "page" && windowInfo?.windowWidth != null;
|
|
4275
|
+
const width = rawWidth != null ? parseNumericLikeValue$1(rawWidth) : isTopLevelView && windowInfo ? windowInfo.windowWidth : 0;
|
|
4276
|
+
const height = rawHeight != null ? parseNumericLikeValue$1(rawHeight) : isTopLevelView && windowInfo ? windowInfo.windowHeight : 0;
|
|
4173
4277
|
return {
|
|
4174
4278
|
bottom: top + height,
|
|
4175
4279
|
height,
|
|
@@ -4216,7 +4320,7 @@ function resolveFieldsResult(node, fields, options) {
|
|
|
4216
4320
|
if (fields.dataset) result.dataset = collectDataset$2(node);
|
|
4217
4321
|
if (fields.mark) result.mark = collectMark(node);
|
|
4218
4322
|
if (fields.rect || fields.size) {
|
|
4219
|
-
const rect = resolveRect$1(node);
|
|
4323
|
+
const rect = resolveRect$1(node, options.root.name === "page" ? options.windowInfo : void 0);
|
|
4220
4324
|
if (fields.rect) Object.assign(result, rect);
|
|
4221
4325
|
if (fields.size) {
|
|
4222
4326
|
result.width = rect.width;
|
|
@@ -6443,6 +6547,7 @@ function syncComponentProperties(instance, definition, nextProperties, bindingEx
|
|
|
6443
6547
|
if (hasComponentPropertyValueChanged(instance.properties[key], previousSnapshot, nextValue, bindingAffected)) {
|
|
6444
6548
|
previousProperties[key] = instance.properties[key];
|
|
6445
6549
|
instance.properties[key] = nextValue;
|
|
6550
|
+
instance.data[key] = nextValue;
|
|
6446
6551
|
changedRootKeys.push(key);
|
|
6447
6552
|
}
|
|
6448
6553
|
instance.__propertySnapshots ??= {};
|
|
@@ -6489,9 +6594,10 @@ function resolveComponentProperties(clonedNode, scope, definition) {
|
|
|
6489
6594
|
};
|
|
6490
6595
|
}
|
|
6491
6596
|
function createRuntimeComponentInstance(componentScopeId, context, clonedNode, componentEntry, nextProperties, ownerScopeId) {
|
|
6597
|
+
const componentProperties = Object.keys(componentEntry.definition.methods ?? {}).some((key) => key.startsWith("__weapp_vite_")) || Object.hasOwn(componentEntry.definition.properties ?? {}, "__wvSlotOwnerId") ? Object.fromEntries(Object.keys(componentEntry.definition.properties ?? {}).filter((key) => Object.hasOwn(nextProperties, key)).map((key) => [key, nextProperties[key]])) : nextProperties;
|
|
6492
6598
|
const componentInstance = createComponentInstance({
|
|
6493
6599
|
definition: componentEntry.definition,
|
|
6494
|
-
properties:
|
|
6600
|
+
properties: componentProperties,
|
|
6495
6601
|
requestRender: (callback) => context.session.requestRender(callback),
|
|
6496
6602
|
triggerEvent: buildComponentTrigger(componentScopeId, context, clonedNode)
|
|
6497
6603
|
});
|
|
@@ -6504,14 +6610,16 @@ function createRuntimeComponentInstance(componentScopeId, context, clonedNode, c
|
|
|
6504
6610
|
componentInstance.selectOwnerComponent = () => ownerScopeId ? context.componentCache.get(ownerScopeId) ?? null : null;
|
|
6505
6611
|
context.componentCache.set(componentScopeId, componentInstance);
|
|
6506
6612
|
runComponentLifecycle(componentInstance, "created");
|
|
6507
|
-
runComponentObservers(componentInstance.__definition__ ?? componentEntry.definition, componentInstance, Object.keys(
|
|
6613
|
+
runComponentObservers(componentInstance.__definition__ ?? componentEntry.definition, componentInstance, Object.keys(componentProperties), {});
|
|
6508
6614
|
componentInstance.__propertySnapshots = Object.fromEntries(Object.entries(componentInstance.properties).map(([key, propertyValue]) => [key, cloneValue(propertyValue)]));
|
|
6509
6615
|
runComponentLifecycle(componentInstance, "attached");
|
|
6510
6616
|
return componentInstance;
|
|
6511
6617
|
}
|
|
6512
6618
|
function renderRuntimeComponentTemplate(context, componentEntry, renderNodeTree, componentScope, componentScopeId, seenComponentScopes) {
|
|
6513
6619
|
const componentDocument = parseTemplateDocument(readTemplateSource(context.artifactSource, componentEntry.absoluteTemplatePath));
|
|
6514
|
-
|
|
6620
|
+
const componentRoot = (componentDocument.children ?? [])[0] ?? componentDocument;
|
|
6621
|
+
const templateRenderState = createTemplateRenderState(componentRoot);
|
|
6622
|
+
return renderNodeTree(componentRoot, componentScope, context, path.resolve(context.project.miniprogramRootPath, `${componentEntry.filePath.replace(JS_FILE_RE, "")}.json`), componentEntry.filePath, componentScopeId, seenComponentScopes, templateRenderState);
|
|
6515
6623
|
}
|
|
6516
6624
|
//#endregion
|
|
6517
6625
|
//#region src/runtime/render/index.ts
|
|
@@ -6532,17 +6640,18 @@ function expandNodeByFor(node, scope) {
|
|
|
6532
6640
|
instanceSuffix: `:for-${index}`
|
|
6533
6641
|
}));
|
|
6534
6642
|
}
|
|
6535
|
-
function renderNodeVariants(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
6536
|
-
return expandNodeByFor(node, scope).map(({ node: expandedNode, scope: expandedScope, instanceSuffix }) => renderNodeTree(expandedNode, expandedScope, context, ownerJsonPath, ownerFilePath, `${instancePath}${instanceSuffix}`, seenComponentScopes));
|
|
6643
|
+
function renderNodeVariants(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
6644
|
+
return expandNodeByFor(node, scope).map(({ node: expandedNode, scope: expandedScope, instanceSuffix }) => renderNodeTree(expandedNode, expandedScope, context, ownerJsonPath, ownerFilePath, `${instancePath}${instanceSuffix}`, seenComponentScopes, templateRenderState));
|
|
6537
6645
|
}
|
|
6538
|
-
function renderChildren(children, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
6646
|
+
function renderChildren(children, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
6539
6647
|
const renderedChildren = [];
|
|
6540
6648
|
for (let index = 0; index < children.length; index += 1) {
|
|
6541
6649
|
const child = children[index];
|
|
6542
6650
|
if (!isTagNode(child)) {
|
|
6543
|
-
renderedChildren.push(...renderNodeVariants(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes));
|
|
6651
|
+
renderedChildren.push(...renderNodeVariants(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes, templateRenderState));
|
|
6544
6652
|
continue;
|
|
6545
6653
|
}
|
|
6654
|
+
if (isTemplateDefinition(child)) continue;
|
|
6546
6655
|
const hasConditional = child.attribs?.["wx:if"] != null;
|
|
6547
6656
|
const isElseBranch = child.attribs?.["wx:elif"] != null || child.attribs?.["wx:else"] != null;
|
|
6548
6657
|
if (hasConditional) {
|
|
@@ -6557,7 +6666,7 @@ function renderChildren(children, scope, context, ownerJsonPath, ownerFilePath,
|
|
|
6557
6666
|
if (!isTagNode(branch)) break;
|
|
6558
6667
|
if (cursor !== index && !WX_ELSE_ATTRS.has(Object.keys(branch.attribs ?? {}).find((key) => key.startsWith("wx:")) ?? "")) break;
|
|
6559
6668
|
if (branch.attribs?.["wx:else"] != null ? !branchMatched : !branchMatched && evaluateConditionalBranch(branch, scope)) {
|
|
6560
|
-
renderedChildren.push(...renderNodeVariants(branch, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${cursor}`, seenComponentScopes));
|
|
6669
|
+
renderedChildren.push(...renderNodeVariants(branch, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${cursor}`, seenComponentScopes, templateRenderState));
|
|
6561
6670
|
branchMatched = true;
|
|
6562
6671
|
}
|
|
6563
6672
|
let nextBranchIndex = cursor + 1;
|
|
@@ -6570,11 +6679,11 @@ function renderChildren(children, scope, context, ownerJsonPath, ownerFilePath,
|
|
|
6570
6679
|
continue;
|
|
6571
6680
|
}
|
|
6572
6681
|
if (isElseBranch) continue;
|
|
6573
|
-
renderedChildren.push(...renderNodeVariants(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes));
|
|
6682
|
+
renderedChildren.push(...renderNodeVariants(child, scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/node-${index}`, seenComponentScopes, templateRenderState));
|
|
6574
6683
|
}
|
|
6575
6684
|
return renderedChildren;
|
|
6576
6685
|
}
|
|
6577
|
-
function collectComponentSlots(componentNode, scope, ownerJsonPath, ownerFilePath, instancePath) {
|
|
6686
|
+
function collectComponentSlots(componentNode, scope, ownerJsonPath, ownerFilePath, instancePath, templateRenderState) {
|
|
6578
6687
|
const slots = /* @__PURE__ */ new Map();
|
|
6579
6688
|
(componentNode.children ?? []).forEach((node, index) => {
|
|
6580
6689
|
const slotName = isTagNode(node) && typeof node.attribs?.slot === "string" && node.attribs.slot.trim() ? node.attribs.slot.trim() : "default";
|
|
@@ -6584,7 +6693,8 @@ function collectComponentSlots(componentNode, scope, ownerJsonPath, ownerFilePat
|
|
|
6584
6693
|
node,
|
|
6585
6694
|
ownerFilePath,
|
|
6586
6695
|
ownerJsonPath,
|
|
6587
|
-
scope
|
|
6696
|
+
scope,
|
|
6697
|
+
templateRenderState
|
|
6588
6698
|
});
|
|
6589
6699
|
slots.set(slotName, entries);
|
|
6590
6700
|
});
|
|
@@ -6601,16 +6711,43 @@ function collectComponentSlots(componentNode, scope, ownerJsonPath, ownerFilePat
|
|
|
6601
6711
|
}
|
|
6602
6712
|
return slots;
|
|
6603
6713
|
}
|
|
6604
|
-
function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes) {
|
|
6714
|
+
function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, instancePath, seenComponentScopes, templateRenderState) {
|
|
6605
6715
|
const clonedNode = cloneNode(node);
|
|
6606
6716
|
if (!isTagNode(clonedNode)) {
|
|
6607
6717
|
applyNodeBindings(clonedNode, scope);
|
|
6608
6718
|
return clonedNode;
|
|
6609
6719
|
}
|
|
6720
|
+
if (isTemplateDefinition(clonedNode)) return {
|
|
6721
|
+
type: "tag",
|
|
6722
|
+
name: "block",
|
|
6723
|
+
attribs: {},
|
|
6724
|
+
children: []
|
|
6725
|
+
};
|
|
6726
|
+
const templateName = resolveTemplateCall(clonedNode, scope.data);
|
|
6727
|
+
if (templateName) {
|
|
6728
|
+
const definition = templateRenderState.definitions.get(templateName);
|
|
6729
|
+
const templateScope = {
|
|
6730
|
+
...scope,
|
|
6731
|
+
data: resolveTemplateData(clonedNode, scope.data)
|
|
6732
|
+
};
|
|
6733
|
+
const children = definition && !templateRenderState.stack.includes(templateName) ? renderChildren(definition.children ?? [], templateScope, context, ownerJsonPath, ownerFilePath, `${instancePath}/template-${templateName}`, seenComponentScopes, {
|
|
6734
|
+
definitions: templateRenderState.definitions,
|
|
6735
|
+
stack: [...templateRenderState.stack, templateName]
|
|
6736
|
+
}) : [];
|
|
6737
|
+
return {
|
|
6738
|
+
type: "tag",
|
|
6739
|
+
name: "block",
|
|
6740
|
+
attribs: {
|
|
6741
|
+
"data-sim-node": instancePath,
|
|
6742
|
+
"data-sim-scope": scope.getScopeId()
|
|
6743
|
+
},
|
|
6744
|
+
children
|
|
6745
|
+
};
|
|
6746
|
+
}
|
|
6610
6747
|
if (clonedNode.name === "slot") {
|
|
6611
6748
|
const slotName = clonedNode.attribs?.name?.trim() || "default";
|
|
6612
6749
|
const projected = scope.slots?.get(slotName) ?? [];
|
|
6613
|
-
const children = projected.length ? projected.flatMap((entry) => renderNodeVariants(entry.node, entry.scope, context, entry.ownerJsonPath, entry.ownerFilePath, entry.instancePath, seenComponentScopes)) : renderChildren(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/slot-fallback-${slotName}`, seenComponentScopes);
|
|
6750
|
+
const children = projected.length ? projected.flatMap((entry) => renderNodeVariants(entry.node, entry.scope, context, entry.ownerJsonPath, entry.ownerFilePath, entry.instancePath, seenComponentScopes, entry.templateRenderState)) : renderChildren(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/slot-fallback-${slotName}`, seenComponentScopes, templateRenderState);
|
|
6614
6751
|
return {
|
|
6615
6752
|
type: "tag",
|
|
6616
6753
|
name: "block",
|
|
@@ -6631,7 +6768,7 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
6631
6768
|
else syncComponentProperties(componentInstance, componentInstance.__definition__ ?? componentEntry.definition, nextProperties, bindingExpressions, context.changedPageKeys);
|
|
6632
6769
|
seenComponentScopes.add(componentScopeId);
|
|
6633
6770
|
const genericComponents = resolveComponentGenerics(context, clonedNode, ownerJsonPath, ownerFilePath, componentEntry.filePath);
|
|
6634
|
-
const slots = collectComponentSlots(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId);
|
|
6771
|
+
const slots = collectComponentSlots(clonedNode, scope, ownerJsonPath, ownerFilePath, componentScopeId, templateRenderState);
|
|
6635
6772
|
const componentScope = createComponentScope(clonedNode, scope, componentScopeId, componentInstance, genericComponents, slots);
|
|
6636
6773
|
context.componentScopes.set(componentScopeId, componentScope);
|
|
6637
6774
|
const renderedComponentRoot = renderRuntimeComponentTemplate(context, componentEntry, renderNodeTree, componentScope, componentScopeId, seenComponentScopes);
|
|
@@ -6649,7 +6786,7 @@ function renderNodeTree(node, scope, context, ownerJsonPath, ownerFilePath, inst
|
|
|
6649
6786
|
}
|
|
6650
6787
|
applyNodeBindings(clonedNode, scope);
|
|
6651
6788
|
clonedNode.attribs["data-sim-node"] = instancePath;
|
|
6652
|
-
clonedNode.children = renderChildren(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/${clonedNode.name}`, seenComponentScopes);
|
|
6789
|
+
clonedNode.children = renderChildren(clonedNode.children ?? [], scope, context, ownerJsonPath, ownerFilePath, `${instancePath}/${clonedNode.name}`, seenComponentScopes, templateRenderState);
|
|
6653
6790
|
return clonedNode;
|
|
6654
6791
|
}
|
|
6655
6792
|
function renderRuntimePageTree(context, page) {
|
|
@@ -6669,7 +6806,9 @@ function renderRuntimePageTree(context, page) {
|
|
|
6669
6806
|
context.componentScopes.clear();
|
|
6670
6807
|
context.componentScopes.set(pageScopeId, pageScope);
|
|
6671
6808
|
const seenComponentScopes = /* @__PURE__ */ new Set();
|
|
6672
|
-
const
|
|
6809
|
+
const root = (document.children ?? [])[0] ?? document;
|
|
6810
|
+
const templateRenderState = createTemplateRenderState(root);
|
|
6811
|
+
const renderedRoot = renderNodeTree(root, pageScope, context, path.resolve(context.project.miniprogramRootPath, `${route}.json`), `${route}.js`, pageScopeId, seenComponentScopes, templateRenderState);
|
|
6673
6812
|
for (const [scopeId, instance] of [...context.componentCache.entries()]) if (!seenComponentScopes.has(scopeId)) {
|
|
6674
6813
|
runComponentLifecycle(instance, "detached");
|
|
6675
6814
|
context.componentCache.delete(scopeId);
|
|
@@ -6682,6 +6821,102 @@ function renderRuntimePageTree(context, page) {
|
|
|
6682
6821
|
}
|
|
6683
6822
|
//#endregion
|
|
6684
6823
|
//#region src/runtime/moduleLoader.ts
|
|
6824
|
+
const ESM_IMPORT_LINE_RE = /^[ \t]*import[^\n]*$/gm;
|
|
6825
|
+
const ESM_EXPORT_LIST_RE = /^[ \t]*export[ \t]*\{([^}\n]+)\}[ \t]*;?$/gm;
|
|
6826
|
+
const ESM_EXPORT_DECLARATION_RE = /\bexport\s+(const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
6827
|
+
const ESM_EXPORT_DEFAULT_DECLARATION_RE = /\bexport\s+default\s+(function|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
6828
|
+
function isImportWhitespace(value) {
|
|
6829
|
+
return value === " " || value === " ";
|
|
6830
|
+
}
|
|
6831
|
+
function parseEsmImportLine(line) {
|
|
6832
|
+
let statement = line.trim().slice(6).trim();
|
|
6833
|
+
if (statement.endsWith(";")) statement = statement.slice(0, -1).trimEnd();
|
|
6834
|
+
if (statement.startsWith("\"") || statement.startsWith("'")) {
|
|
6835
|
+
const quote = statement[0];
|
|
6836
|
+
if (statement.endsWith(quote) && statement.length > 1) return {
|
|
6837
|
+
request: statement.slice(1, -1),
|
|
6838
|
+
sideEffect: true
|
|
6839
|
+
};
|
|
6840
|
+
return;
|
|
6841
|
+
}
|
|
6842
|
+
let fromIndex = statement.indexOf("from");
|
|
6843
|
+
while (fromIndex >= 0) {
|
|
6844
|
+
if (isImportWhitespace(statement[fromIndex - 1]) && isImportWhitespace(statement[fromIndex + 4])) break;
|
|
6845
|
+
fromIndex = statement.indexOf("from", fromIndex + 4);
|
|
6846
|
+
}
|
|
6847
|
+
if (fromIndex < 0) return;
|
|
6848
|
+
const specifier = statement.slice(0, fromIndex).trim();
|
|
6849
|
+
const requestLiteral = statement.slice(fromIndex + 4).trim();
|
|
6850
|
+
const quote = requestLiteral[0];
|
|
6851
|
+
if (!specifier || quote !== "\"" && quote !== "'" || requestLiteral.length < 2 || !requestLiteral.endsWith(quote)) return;
|
|
6852
|
+
return {
|
|
6853
|
+
request: requestLiteral.slice(1, -1),
|
|
6854
|
+
sideEffect: false,
|
|
6855
|
+
specifier
|
|
6856
|
+
};
|
|
6857
|
+
}
|
|
6858
|
+
function createEsmImportBindings(specifier, request, index) {
|
|
6859
|
+
const namespaceName = `__headlessEsmImport${index}`;
|
|
6860
|
+
const statements = [`const ${namespaceName} = require(${JSON.stringify(request)});`];
|
|
6861
|
+
const normalizedSpecifier = specifier.trim();
|
|
6862
|
+
if (normalizedSpecifier.startsWith("{") && normalizedSpecifier.endsWith("}")) {
|
|
6863
|
+
const entries = normalizedSpecifier.slice(1, -1).split(",");
|
|
6864
|
+
for (const entry of entries) {
|
|
6865
|
+
const [importedName, localName] = entry.trim().split(/\s+as\s+/);
|
|
6866
|
+
if (!importedName) continue;
|
|
6867
|
+
const bindingName = localName || importedName;
|
|
6868
|
+
statements.push(`const ${bindingName} = ${namespaceName}[${JSON.stringify(importedName)}];`);
|
|
6869
|
+
}
|
|
6870
|
+
return statements.join("\n");
|
|
6871
|
+
}
|
|
6872
|
+
if (normalizedSpecifier.startsWith("* as ")) {
|
|
6873
|
+
const bindingName = normalizedSpecifier.slice(5).trim();
|
|
6874
|
+
statements.push(`const ${bindingName} = ${namespaceName};`);
|
|
6875
|
+
return statements.join("\n");
|
|
6876
|
+
}
|
|
6877
|
+
const [defaultName, namedPart] = normalizedSpecifier.split(/\s*,\s*/, 2);
|
|
6878
|
+
if (defaultName) statements.push(`const ${defaultName.trim()} = ${namespaceName}.default ?? ${namespaceName};`);
|
|
6879
|
+
if (namedPart?.startsWith("{") && namedPart.endsWith("}")) statements.push(createEsmImportBindings(namedPart, request, index).split("\n").slice(1).join("\n"));
|
|
6880
|
+
return statements.join("\n");
|
|
6881
|
+
}
|
|
6882
|
+
function transformEsmToCommonJs(source) {
|
|
6883
|
+
if (!/^\s*(?:import|export)\b/m.test(source)) return source;
|
|
6884
|
+
let importIndex = 0;
|
|
6885
|
+
const exportedNames = [];
|
|
6886
|
+
let transformed = source.replace(ESM_IMPORT_LINE_RE, (line) => {
|
|
6887
|
+
const parsed = parseEsmImportLine(line);
|
|
6888
|
+
if (!parsed) return line;
|
|
6889
|
+
if (parsed.sideEffect) return `require(${JSON.stringify(parsed.request)});`;
|
|
6890
|
+
return createEsmImportBindings(parsed.specifier, parsed.request, importIndex++);
|
|
6891
|
+
});
|
|
6892
|
+
transformed = transformed.replace(ESM_EXPORT_LIST_RE, (_match, entries) => {
|
|
6893
|
+
for (const entry of entries.split(",")) {
|
|
6894
|
+
const [local, exported] = entry.trim().split(/\s+as\s+/);
|
|
6895
|
+
if (local) exportedNames.push({
|
|
6896
|
+
exported: exported || local,
|
|
6897
|
+
local
|
|
6898
|
+
});
|
|
6899
|
+
}
|
|
6900
|
+
return "";
|
|
6901
|
+
});
|
|
6902
|
+
transformed = transformed.replace(ESM_EXPORT_DEFAULT_DECLARATION_RE, (_match, kind, local) => {
|
|
6903
|
+
exportedNames.push({
|
|
6904
|
+
exported: "default",
|
|
6905
|
+
local
|
|
6906
|
+
});
|
|
6907
|
+
return `${kind} ${local}`;
|
|
6908
|
+
});
|
|
6909
|
+
transformed = transformed.replace(ESM_EXPORT_DECLARATION_RE, (_match, kind, local) => {
|
|
6910
|
+
exportedNames.push({
|
|
6911
|
+
exported: local,
|
|
6912
|
+
local
|
|
6913
|
+
});
|
|
6914
|
+
return `${kind} ${local}`;
|
|
6915
|
+
});
|
|
6916
|
+
transformed = transformed.replace(/\bexport\s+default\s+/g, "module.exports.default = ");
|
|
6917
|
+
if (exportedNames.length > 0) transformed += `\n${exportedNames.map(({ exported, local }) => `module.exports[${JSON.stringify(exported)}] = ${local};`).join("\n")}`;
|
|
6918
|
+
return transformed;
|
|
6919
|
+
}
|
|
6685
6920
|
function createRequireNotFoundError(request, importer) {
|
|
6686
6921
|
return /* @__PURE__ */ new Error(`Cannot resolve require("${request}") from ${normalize(importer)} in headless runtime.`);
|
|
6687
6922
|
}
|
|
@@ -6697,7 +6932,7 @@ function resolveRequiredModulePath(artifactSource, importer, request) {
|
|
|
6697
6932
|
for (const candidate of candidates) if (artifactSource.has(candidate)) return candidate;
|
|
6698
6933
|
throw createRequireNotFoundError(request, importer);
|
|
6699
6934
|
}
|
|
6700
|
-
function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, kernel, globals) {
|
|
6935
|
+
function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, kernel, globals, onConsole) {
|
|
6701
6936
|
const wx = createHeadlessWx(wxDriver);
|
|
6702
6937
|
return {
|
|
6703
6938
|
App(definition) {
|
|
@@ -6715,7 +6950,7 @@ function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, k
|
|
|
6715
6950
|
Page(definition) {
|
|
6716
6951
|
return registerPageDefinition(registries, definition);
|
|
6717
6952
|
},
|
|
6718
|
-
console: kernel.diagnostics.createConsole(),
|
|
6953
|
+
console: kernel.diagnostics.createConsole(console, onConsole),
|
|
6719
6954
|
clearInterval: (handle) => kernel.scheduler.clearInterval(handle),
|
|
6720
6955
|
clearTimeout: (handle) => kernel.scheduler.clearTimeout(handle),
|
|
6721
6956
|
getApp,
|
|
@@ -6725,13 +6960,17 @@ function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, k
|
|
|
6725
6960
|
require: void 0,
|
|
6726
6961
|
setInterval: kernel.scheduler.setInterval.bind(kernel.scheduler),
|
|
6727
6962
|
setTimeout: kernel.scheduler.setTimeout.bind(kernel.scheduler),
|
|
6963
|
+
TextDecoder: globalThis.TextDecoder,
|
|
6964
|
+
TextEncoder: globalThis.TextEncoder,
|
|
6965
|
+
URL: globalThis.URL,
|
|
6966
|
+
URLSearchParams: globalThis.URLSearchParams,
|
|
6728
6967
|
wx,
|
|
6729
6968
|
...globals
|
|
6730
6969
|
};
|
|
6731
6970
|
}
|
|
6732
6971
|
function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, options) {
|
|
6733
6972
|
const moduleCache = /* @__PURE__ */ new Map();
|
|
6734
|
-
const executionContext = createExecutionContext(registries, getCurrentPages, getApp, wxDriver, options.kernel, options.globals ?? {});
|
|
6973
|
+
const executionContext = createExecutionContext(registries, getCurrentPages, getApp, wxDriver, options.kernel, options.globals ?? {}, options.onConsole);
|
|
6735
6974
|
executionContext.globalThis = executionContext;
|
|
6736
6975
|
function executeModule(filePath, loadContext) {
|
|
6737
6976
|
const resolvedPath = path.resolve(filePath);
|
|
@@ -6761,9 +7000,13 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, optio
|
|
|
6761
7000
|
});
|
|
6762
7001
|
localRequire.async = (request) => Promise.resolve().then(() => localRequire(request));
|
|
6763
7002
|
try {
|
|
6764
|
-
new vm.Script(`(function (exports, module, require, __filename, __dirname) { ${source}\n})`, { filename: resolvedPath }).runInNewContext(executionContext)(module.exports, module, localRequire, resolvedPath, path.dirname(resolvedPath));
|
|
7003
|
+
new vm.Script(`(function (exports, module, require, __filename, __dirname) { ${transformEsmToCommonJs(source)}\n})`, { filename: resolvedPath }).runInNewContext(executionContext)(module.exports, module, localRequire, resolvedPath, path.dirname(resolvedPath));
|
|
6765
7004
|
const registeredDefinitions = [...registries.components.values()].filter((definition) => !registeredDefinitionsBefore.has(definition));
|
|
6766
|
-
module.componentDefinitions = [.../* @__PURE__ */ new Set([
|
|
7005
|
+
module.componentDefinitions = [.../* @__PURE__ */ new Set([
|
|
7006
|
+
...requiredComponentDefinitions,
|
|
7007
|
+
...loadContext?.componentDefinitions ?? [],
|
|
7008
|
+
...registeredDefinitions
|
|
7009
|
+
])];
|
|
6767
7010
|
return module;
|
|
6768
7011
|
} finally {
|
|
6769
7012
|
registries.currentLoadContext = previousLoadContext;
|
|
@@ -6779,11 +7022,13 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, optio
|
|
|
6779
7022
|
return registries.appDefinition;
|
|
6780
7023
|
},
|
|
6781
7024
|
executePageModule(filePath, route) {
|
|
6782
|
-
executeModule(filePath, {
|
|
7025
|
+
const fallbackDefinition = executeModule(filePath, {
|
|
6783
7026
|
kind: "page",
|
|
6784
|
-
route
|
|
6785
|
-
|
|
6786
|
-
|
|
7027
|
+
route,
|
|
7028
|
+
componentDefinitions: []
|
|
7029
|
+
}).componentDefinitions.at(-1);
|
|
7030
|
+
const definition = registries.pages.get(route) ?? (fallbackDefinition ? normalizeComponentPageDefinition(fallbackDefinition) : void 0);
|
|
7031
|
+
if (!registries.pages.has(route) && definition) registerPageDefinition(registries, definition, route);
|
|
6787
7032
|
if (!definition) throw new Error(`Page() was not registered for route "${route}" while executing ${normalize(filePath)}.`);
|
|
6788
7033
|
return definition;
|
|
6789
7034
|
},
|
|
@@ -6880,6 +7125,7 @@ var HeadlessSession = class {
|
|
|
6880
7125
|
appDefinition = null;
|
|
6881
7126
|
appInstance = null;
|
|
6882
7127
|
moduleLoader;
|
|
7128
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
6883
7129
|
registries;
|
|
6884
7130
|
currentPageInstance = null;
|
|
6885
7131
|
pages = [];
|
|
@@ -7021,7 +7267,8 @@ var HeadlessSession = class {
|
|
|
7021
7267
|
}, {
|
|
7022
7268
|
artifactSource: this.project.artifactSource,
|
|
7023
7269
|
globals: options.globals,
|
|
7024
|
-
kernel: this.kernel
|
|
7270
|
+
kernel: this.kernel,
|
|
7271
|
+
onConsole: (entry) => this.emit("console", entry)
|
|
7025
7272
|
});
|
|
7026
7273
|
}
|
|
7027
7274
|
assertActive() {
|
|
@@ -7035,11 +7282,26 @@ var HeadlessSession = class {
|
|
|
7035
7282
|
this.renderRequestPending = false;
|
|
7036
7283
|
this.wxState.close();
|
|
7037
7284
|
this.moduleLoader.close();
|
|
7285
|
+
this.eventListeners.clear();
|
|
7038
7286
|
this.kernel.close();
|
|
7039
7287
|
}
|
|
7040
7288
|
getDiagnostics() {
|
|
7041
7289
|
return this.kernel.diagnostics.getEntries();
|
|
7042
7290
|
}
|
|
7291
|
+
on(eventName, handler) {
|
|
7292
|
+
if (!eventName || typeof handler !== "function") return;
|
|
7293
|
+
const listeners = this.eventListeners.get(eventName) ?? /* @__PURE__ */ new Set();
|
|
7294
|
+
listeners.add(handler);
|
|
7295
|
+
this.eventListeners.set(eventName, listeners);
|
|
7296
|
+
}
|
|
7297
|
+
removeListener(eventName, handler) {
|
|
7298
|
+
const listeners = this.eventListeners.get(eventName);
|
|
7299
|
+
listeners?.delete(handler);
|
|
7300
|
+
if (listeners?.size === 0) this.eventListeners.delete(eventName);
|
|
7301
|
+
}
|
|
7302
|
+
emit(eventName, ...args) {
|
|
7303
|
+
for (const handler of [...this.eventListeners.get(eventName) ?? []]) handler(...args);
|
|
7304
|
+
}
|
|
7043
7305
|
get isClosed() {
|
|
7044
7306
|
return this.kernel.isClosed;
|
|
7045
7307
|
}
|
|
@@ -7051,6 +7313,10 @@ var HeadlessSession = class {
|
|
|
7051
7313
|
this.assertActive();
|
|
7052
7314
|
return this.pages.slice();
|
|
7053
7315
|
}
|
|
7316
|
+
getWx() {
|
|
7317
|
+
this.assertActive();
|
|
7318
|
+
return this.moduleLoader.wx;
|
|
7319
|
+
}
|
|
7054
7320
|
callWxMethod(methodName, ...args) {
|
|
7055
7321
|
this.assertActive();
|
|
7056
7322
|
const method = this.moduleLoader.wx[methodName];
|
|
@@ -7446,9 +7712,19 @@ var HeadlessSession = class {
|
|
|
7446
7712
|
this.appDefinition = this.moduleLoader.executeAppModule(appModulePath);
|
|
7447
7713
|
this.appInstance = createAppInstance(this.appDefinition);
|
|
7448
7714
|
this.appInstance.onLaunch?.(launchOptions);
|
|
7715
|
+
this.syncRuntimeAppState();
|
|
7449
7716
|
this.appInstance.onShow?.(launchOptions);
|
|
7450
7717
|
return this.appInstance;
|
|
7451
7718
|
}
|
|
7719
|
+
syncRuntimeAppState() {
|
|
7720
|
+
const runtimeApp = this.appInstance?.__wevuRuntimeApp;
|
|
7721
|
+
if (!runtimeApp || typeof runtimeApp !== "object" || !this.appInstance) return;
|
|
7722
|
+
if (runtimeApp.globalData && typeof runtimeApp.globalData === "object") this.appInstance.globalData = {
|
|
7723
|
+
...this.appInstance.globalData,
|
|
7724
|
+
...runtimeApp.globalData
|
|
7725
|
+
};
|
|
7726
|
+
if (Object.hasOwn(runtimeApp, "routes")) this.appInstance.routes = runtimeApp.routes;
|
|
7727
|
+
}
|
|
7452
7728
|
reLaunch(url) {
|
|
7453
7729
|
const target = this.resolveNavigationTarget(url);
|
|
7454
7730
|
this.bootstrap(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
@@ -8096,7 +8372,10 @@ var HeadlessTestingPageHandle = class {
|
|
|
8096
8372
|
return await runWithTimeout(async () => {
|
|
8097
8373
|
this.session?.renderCurrentPage();
|
|
8098
8374
|
const method = this.page[normalizedMethodName];
|
|
8099
|
-
if (typeof method !== "function")
|
|
8375
|
+
if (typeof method !== "function") {
|
|
8376
|
+
if (options.routeOnly) return;
|
|
8377
|
+
throw new TypeError(`Method "${normalizedMethodName}" does not exist on headless page ${this.page.route}.`);
|
|
8378
|
+
}
|
|
8100
8379
|
return cloneProtocolValue(await method.apply(this.page, args));
|
|
8101
8380
|
}, options.timeout, `Timed out calling page method "${normalizedMethodName}" in headless testing runtime.`);
|
|
8102
8381
|
}
|
|
@@ -8271,6 +8550,24 @@ var HeadlessTestingSessionHandle = class {
|
|
|
8271
8550
|
async close() {
|
|
8272
8551
|
this.session.close();
|
|
8273
8552
|
}
|
|
8553
|
+
on(eventName, handler) {
|
|
8554
|
+
this.session.on(eventName, handler);
|
|
8555
|
+
return this;
|
|
8556
|
+
}
|
|
8557
|
+
removeListener(eventName, handler) {
|
|
8558
|
+
this.session.removeListener(eventName, handler);
|
|
8559
|
+
return this;
|
|
8560
|
+
}
|
|
8561
|
+
off(eventName, handler) {
|
|
8562
|
+
return this.removeListener(eventName, handler);
|
|
8563
|
+
}
|
|
8564
|
+
async evaluate(evaluator, ...args) {
|
|
8565
|
+
return await this.evaluateWithOptions(evaluator, {}, ...args);
|
|
8566
|
+
}
|
|
8567
|
+
async evaluateWithOptions(evaluator, options = {}, ...args) {
|
|
8568
|
+
this.session.assertActive();
|
|
8569
|
+
return await runWithTimeout(() => this.evaluateInRuntime(evaluator, args), options.timeout, "Timed out evaluating code in headless testing runtime.");
|
|
8570
|
+
}
|
|
8274
8571
|
async currentPage() {
|
|
8275
8572
|
this.session.assertActive();
|
|
8276
8573
|
const current = this.session.getCurrentPages().at(-1);
|
|
@@ -8367,13 +8664,46 @@ var HeadlessTestingSessionHandle = class {
|
|
|
8367
8664
|
if (!page) throw new Error(`Failed to ${methodName} route "${route}" through the headless wx runtime.`);
|
|
8368
8665
|
return page;
|
|
8369
8666
|
}
|
|
8667
|
+
async evaluateInRuntime(evaluator, args) {
|
|
8668
|
+
const runtimeGlobals = {
|
|
8669
|
+
getApp: () => this.session.getApp(),
|
|
8670
|
+
getCurrentPages: () => this.session.getCurrentPages(),
|
|
8671
|
+
wx: this.session.getWx()
|
|
8672
|
+
};
|
|
8673
|
+
const host = globalThis;
|
|
8674
|
+
const previous = /* @__PURE__ */ new Map();
|
|
8675
|
+
for (const [name, value] of Object.entries(runtimeGlobals)) {
|
|
8676
|
+
previous.set(name, Object.getOwnPropertyDescriptor(host, name));
|
|
8677
|
+
Object.defineProperty(host, name, {
|
|
8678
|
+
configurable: true,
|
|
8679
|
+
enumerable: false,
|
|
8680
|
+
value,
|
|
8681
|
+
writable: true
|
|
8682
|
+
});
|
|
8683
|
+
}
|
|
8684
|
+
try {
|
|
8685
|
+
const fn = typeof evaluator === "string" ? new vm.Script(`(${evaluator})`).runInThisContext() : evaluator;
|
|
8686
|
+
if (typeof fn !== "function") throw new TypeError("Headless evaluator must be a function or function source string.");
|
|
8687
|
+
return await fn(...args);
|
|
8688
|
+
} finally {
|
|
8689
|
+
for (const [name, descriptor] of previous) if (descriptor) Object.defineProperty(host, name, descriptor);
|
|
8690
|
+
else delete host[name];
|
|
8691
|
+
}
|
|
8692
|
+
}
|
|
8370
8693
|
};
|
|
8371
8694
|
//#endregion
|
|
8372
8695
|
//#region src/testing/launch.ts
|
|
8696
|
+
function resolveInitialRoute(session) {
|
|
8697
|
+
const entryPagePath = typeof session.project.appConfig.entryPagePath === "string" ? session.project.appConfig.entryPagePath.trim().replace(/^\/+/, "") : "";
|
|
8698
|
+
if (entryPagePath && session.project.routes.some((route) => route.route === entryPagePath)) return entryPagePath;
|
|
8699
|
+
return session.project.routes[0]?.route ?? null;
|
|
8700
|
+
}
|
|
8373
8701
|
async function launch(options) {
|
|
8374
8702
|
const session = createHeadlessSession({ projectPath: options.projectPath });
|
|
8375
8703
|
session.bootstrap();
|
|
8704
|
+
const initialRoute = resolveInitialRoute(session);
|
|
8705
|
+
if (initialRoute) session.reLaunch(`/${initialRoute}`);
|
|
8376
8706
|
return new HeadlessTestingSessionHandle(session.project, session);
|
|
8377
8707
|
}
|
|
8378
8708
|
//#endregion
|
|
8379
|
-
export { BrowserHeadlessSession, HeadlessSession, HeadlessTestingNodeHandle, HeadlessTestingPageHandle, HeadlessTestingScopeHandle, HeadlessTestingSessionHandle, RuntimeDiagnostics, RuntimeKernel, RuntimeScheduler, cloneValue, coerceComponentPropertyValue, collectMiniProgramEventBindings, createAppInstance, createArtifactProject, createBrowserHeadlessSession, createBrowserModuleLoader, createBrowserProject, createBrowserVirtualFiles, createBrowserVirtualFilesFromDirectory, createComponentInstance, createFileSystemArtifactSource, createHeadlessSession, createHeadlessUniEventBus, createHeadlessWx, createHeadlessWxState, createHostRegistries, createLogicalNode, createMemoryArtifactSource, createOverlayArtifactSource, createPageInstance, createProjectDescriptor, executeSelectorQueryRequests, hasBrowserVirtualFile, hasComponentPropertyValueChanged, launch, loadProject, normalizeBrowserFilePath, normalizeComponentPropertyValue, querySelectorAll, readBrowserVirtualFile, readRenderedNodes, readRenderedSelectorNodes, registerAppDefinition, registerComponentDefinition, registerExportedComponentDefinition, registerPageDefinition, renderBrowserPageTree, renderPageTree, renderRuntimePageTree, resolveMiniProgramEventBinding, resolveRoutesFromAppConfig, resolveSelectorQueryScopeRoot, resolveSelectorScrollTop, runComponentLifecycle, runComponentObservers, runComponentPageLifetime, waitForPageComponent, waitForPageComponents, waitForPageData, waitForPageSelector, waitForPageText, waitForPageTextGone, waitForRenderedPage, wechat };
|
|
8709
|
+
export { BrowserHeadlessSession, HeadlessSession, HeadlessTestingNodeHandle, HeadlessTestingPageHandle, HeadlessTestingScopeHandle, HeadlessTestingSessionHandle, RuntimeDiagnostics, RuntimeKernel, RuntimeScheduler, cloneValue, coerceComponentPropertyValue, collectMiniProgramEventBindings, createAppInstance, createArtifactProject, createBrowserHeadlessSession, createBrowserModuleLoader, createBrowserProject, createBrowserVirtualFiles, createBrowserVirtualFilesFromDirectory, createComponentInstance, createFileSystemArtifactSource, createHeadlessSession, createHeadlessUniEventBus, createHeadlessWx, createHeadlessWxState, createHostRegistries, createLogicalNode, createMemoryArtifactSource, createOverlayArtifactSource, createPageInstance, createProjectDescriptor, executeSelectorQueryRequests, hasBrowserVirtualFile, hasComponentPropertyValueChanged, launch, loadProject, normalizeBrowserFilePath, normalizeComponentPageDefinition, normalizeComponentPropertyValue, querySelectorAll, readBrowserVirtualFile, readRenderedNodes, readRenderedSelectorNodes, registerAppDefinition, registerComponentDefinition, registerExportedComponentDefinition, registerPageDefinition, renderBrowserPageTree, renderPageTree, renderRuntimePageTree, resolveMiniProgramEventBinding, resolveRoutesFromAppConfig, resolveSelectorQueryScopeRoot, resolveSelectorScrollTop, runComponentLifecycle, runComponentObservers, runComponentPageLifetime, waitForPageComponent, waitForPageComponents, waitForPageData, waitForPageSelector, waitForPageText, waitForPageTextGone, waitForRenderedPage, wechat };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/simulator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@babel/parser": "^8.0.4",
|
|
42
42
|
"htmlparser2": "^12.0.0",
|
|
43
43
|
"pathe": "^2.0.3",
|
|
44
|
-
"@weapp-core/constants": "0.1.
|
|
44
|
+
"@weapp-core/constants": "0.1.17"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public",
|