@das-fed/mframe 0.0.27 → 0.0.28

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.
Files changed (5) hide show
  1. package/es5.js +5704 -5093
  2. package/index.css +1 -1
  3. package/index.d.ts +277 -0
  4. package/index.js +4772 -4283
  5. package/package.json +1 -1
package/index.css CHANGED
@@ -1 +1 @@
1
- @charset "UTF-8";.main-loader-container{display:flex;align-items:center;justify-content:center}.main-loader-container .loader{border:4px solid #f3f3f3;border-top:4px solid #3498db;border-radius:50%;width:24px;height:24px;margin-right:10px;animation:mainLoaderAnimation 2s linear infinite}@keyframes mainLoaderAnimation{0%{transform:rotate(0)}to{transform:rotate(360deg)}}
1
+ .main-loader-container{display:flex;align-items:center;justify-content:center;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);z-index:1000}.main-loader-container .loader{border:4px solid #f3f3f3;border-top:4px solid #3498db;border-radius:50%;width:24px;height:24px;margin-right:10px;animation:mainLoaderAnimation 2s linear infinite}@keyframes mainLoaderAnimation{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.main-error-container{display:flex;flex-direction:column;align-items:center;justify-content:center;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);z-index:1000;padding:30px;background-color:#fff;border-radius:8px;box-shadow:0 2px 12px #00000026;min-width:320px;text-align:center}.main-error-container .error-icon{font-size:48px;color:#f56c6c;margin-bottom:16px}.main-error-container .error-message{color:#606266;font-size:14px;line-height:1.6;margin-bottom:20px;max-width:400px}.main-error-container .retry-button{padding:8px 24px;background-color:#409eff;color:#fff;border:none;border-radius:4px;font-size:14px;cursor:pointer;transition:background-color .3s}.main-error-container .retry-button:hover{background-color:#66b1ff}.main-error-container .retry-button:active{background-color:#3a8ee6}
package/index.d.ts CHANGED
@@ -346,6 +346,9 @@ declare type ContainerInitOptions = {
346
346
 
347
347
  /** 作为子应用时,是否自动清除html、body、挂载点的背景颜色。默认清除,防止子应用的背景颜色覆盖主应用,但是会自动继到可用的布局容器中 */
348
348
  autoClearBackground?: Boolean
349
+
350
+ /** 预加载配置 */
351
+ preload?: PreloadConfig
349
352
  }
350
353
 
351
354
  /** 容器初始化方法的结果 */
@@ -423,6 +426,19 @@ declare type MainAppChannelType = {
423
426
  /** 主应用的初始化配置 */
424
427
  declare type MainAppContainerInitOptions = Omit<ContainerInitOptions, 'type' | 'autoClearBackground'>
425
428
 
429
+ export declare interface MemoryMetric {
430
+ /** 应用名称 */
431
+ appName: string;
432
+ /** 内存使用(字节) */
433
+ usedJSHeapSize?: number;
434
+ /** 总内存(字节) */
435
+ totalJSHeapSize?: number;
436
+ /** 内存限制(字节) */
437
+ jsHeapSizeLimit?: number;
438
+ /** 记录时间 */
439
+ timestamp: number;
440
+ }
441
+
426
442
  declare type MenuItem = {
427
443
  label: string
428
444
  value: string
@@ -475,11 +491,122 @@ declare type ParentListener = 'getMicroFrameRect' | 'reportRouter' | 'microAppSt
475
491
 
476
492
  declare type ParentListener_2 = 'getMicroFrameRect' | 'reportRouter' | 'microAppStickStatus' | 'customEventFromMicro';
477
493
 
494
+ /**
495
+ * 性能监控工具
496
+ */
497
+ export declare interface PerformanceMetric {
498
+ /** 应用名称 */
499
+ appName: string;
500
+ /** 加载开始时间 */
501
+ startTime: number;
502
+ /** 加载结束时间 */
503
+ endTime?: number;
504
+ /** 加载耗时(毫秒) */
505
+ loadTime?: number;
506
+ /** 状态:loading, loaded, error */
507
+ status: 'loading' | 'loaded' | 'error';
508
+ /** 错误信息 */
509
+ error?: string;
510
+ }
511
+
512
+ declare class PerformanceMonitor {
513
+ private loadMetrics;
514
+ private memoryMetrics;
515
+ private routerMetrics;
516
+ private routerStartTime;
517
+ private routerFrom;
518
+ /**
519
+ * 记录应用开始加载
520
+ */
521
+ startLoad(appName: string): void;
522
+ /**
523
+ * 记录应用加载完成
524
+ */
525
+ endLoad(appName: string, success?: boolean, error?: string): void;
526
+ /**
527
+ * 记录内存使用
528
+ */
529
+ recordMemory(appName: string): void;
530
+ /**
531
+ * 记录路由开始切换
532
+ */
533
+ startRouterChange(from: string): void;
534
+ /**
535
+ * 记录路由切换完成
536
+ */
537
+ endRouterChange(to: string): void;
538
+ /**
539
+ * 获取性能报告
540
+ */
541
+ getReport(): PerformanceReport;
542
+ /**
543
+ * 打印性能报告
544
+ */
545
+ printReport(): PerformanceReport;
546
+ /**
547
+ * 清除所有指标
548
+ */
549
+ clear(): void;
550
+ /**
551
+ * 启用自动内存监控
552
+ */
553
+ enableAutoMemoryMonitor(interval?: number): () => void;
554
+ }
555
+
556
+ export declare interface PerformanceReport {
557
+ /** 加载指标 */
558
+ loadMetrics: PerformanceMetric[];
559
+ /** 内存指标 */
560
+ memoryMetrics: MemoryMetric[];
561
+ /** 路由指标 */
562
+ routerMetrics: RouterMetric[];
563
+ /** 平均加载时间(毫秒) */
564
+ averageLoadTime: number;
565
+ /** 最慢的应用 */
566
+ slowestApp?: string;
567
+ /** 最快的应用 */
568
+ fastestApp?: string;
569
+ /** 当前总内存使用(MB) */
570
+ totalMemoryUsage?: number;
571
+ }
572
+
478
573
  export declare const pollVariable: <T>(getDataFn: () => any, opt?: {
479
574
  interval: number;
480
575
  times: number;
481
576
  }) => Promise<T>;
482
577
 
578
+ /** 预加载配置 */
579
+ declare type PreloadConfig = {
580
+ /** 是否启用预加载,默认 false */
581
+ enabled?: boolean
582
+
583
+ /** 预加载策略:idle-浏览器空闲时,immediate-立即,visible-页面可见时 */
584
+ strategy?: 'idle' | 'immediate' | 'visible'
585
+
586
+ /** 延迟预加载的时间(毫秒),仅当 strategy 为 immediate 时有效 */
587
+ delay?: number
588
+
589
+ /** 指定要预加载的应用名称列表,为空则预加载所有子应用 */
590
+ apps?: string[]
591
+ }
592
+
593
+ declare interface PreloadedIframe {
594
+ id: string;
595
+ iframe: HTMLIFrameElement;
596
+ origin: string;
597
+ status: 'loading' | 'ready' | 'error';
598
+ loadTime?: number;
599
+ }
600
+
601
+ declare interface PreloadOptions {
602
+ /** 预加载的应用列表 */
603
+ apps?: MicroAppItem[];
604
+ /** 预加载策略 */
605
+ strategy?: 'idle' | 'immediate' | 'visible';
606
+ /** 自定义预加载时机(毫秒) */
607
+ delay?: number;
608
+ }
609
+
483
610
  export declare const reportRouter: (data?: any) => Promise<void>;
484
611
 
485
612
  declare type RouterConfig = {
@@ -495,12 +622,125 @@ declare type RouterConfig = {
495
622
 
496
623
  declare type RouterEventListenerTypes = 'replaceState' | 'pushState';
497
624
 
625
+ export declare interface RouterMetric {
626
+ /** 从哪个路由 */
627
+ from: string;
628
+ /** 到哪个路由 */
629
+ to: string;
630
+ /** 耗时(毫秒) */
631
+ duration: number;
632
+ /** 时间戳 */
633
+ timestamp: number;
634
+ }
635
+
636
+ export declare class RouterSyncManager {
637
+ private syncLock;
638
+ private lastSync;
639
+ private debounceTimer;
640
+ private options;
641
+ private syncHistory;
642
+ private maxHistorySize;
643
+ constructor(options?: RouterSyncOptions);
644
+ /**
645
+ * 检查是否应该同步(防止死循环)
646
+ */
647
+ shouldSync(path: string, source: SyncSource): boolean;
648
+ /**
649
+ * 开始同步(加锁)
650
+ */
651
+ startSync(path: string, source: SyncSource): boolean;
652
+ /**
653
+ * 结束同步(解锁)
654
+ */
655
+ endSync(source: SyncSource, delay?: number): void;
656
+ /**
657
+ * 防抖执行
658
+ */
659
+ debounce(fn: () => void): void;
660
+ /**
661
+ * 取消防抖
662
+ */
663
+ cancelDebounce(): void;
664
+ /**
665
+ * 检查是否有锁
666
+ */
667
+ hasLock(source?: SyncSource): boolean;
668
+ /**
669
+ * 加锁
670
+ */
671
+ private lock;
672
+ /**
673
+ * 解锁
674
+ */
675
+ private unlock;
676
+ /**
677
+ * 强制解锁所有
678
+ */
679
+ unlockAll(): void;
680
+ /**
681
+ * 获取同步历史
682
+ */
683
+ getHistory(): SyncRecord[];
684
+ /**
685
+ * 清除历史
686
+ */
687
+ clearHistory(): void;
688
+ /**
689
+ * 获取统计信息
690
+ */
691
+ getStats(): {
692
+ total: number;
693
+ bySource: {
694
+ main: number;
695
+ micro: number;
696
+ popstate: number;
697
+ };
698
+ lastSync: SyncRecord | null;
699
+ hasLock: boolean;
700
+ };
701
+ /**
702
+ * 打印统计信息
703
+ */
704
+ printStats(): void;
705
+ /**
706
+ * 调试日志
707
+ */
708
+ private log;
709
+ /**
710
+ * 重置管理器
711
+ */
712
+ reset(): void;
713
+ }
714
+
715
+ /**
716
+ * 路由同步管理器
717
+ * 解决路由同步死循环和防抖问题
718
+ */
719
+ export declare interface RouterSyncOptions {
720
+ /** 防抖延迟(毫秒),默认 50ms */
721
+ debounceDelay?: number;
722
+ /** 是否启用调试日志 */
723
+ debug?: boolean;
724
+ }
725
+
726
+ export declare interface SyncRecord {
727
+ path: string;
728
+ source: SyncSource;
729
+ timestamp: number;
730
+ }
731
+
498
732
  export declare const syncRouter: (cb: (params: {
499
733
  appInfo: any;
500
734
  parentRouter: any;
501
735
  replacePath: string;
502
736
  }) => any) => void;
503
737
 
738
+ export declare enum SyncSource {
739
+ MAIN = "main",// 主应用触发
740
+ MICRO = "micro",// 子应用触发
741
+ POPSTATE = "popstate"
742
+ }
743
+
504
744
  declare type TabItem = {
505
745
  label: string
506
746
  value: string
@@ -527,6 +767,38 @@ export declare const useIframeManager: () => {
527
767
  destroyIframe: (id: string) => void;
528
768
  };
529
769
 
770
+ /**
771
+ * iframe 预加载管理器
772
+ */
773
+ export declare const useIframePreload: () => {
774
+ preload: (id: string, origin: string) => Promise<PreloadedIframe>;
775
+ preloadBatch: (apps: MicroAppItem[]) => Promise<PreloadedIframe[]>;
776
+ getPreloaded: (id: string) => PreloadedIframe | null;
777
+ moveToContainer: (id: string, targetContainer: Element) => HTMLIFrameElement | null;
778
+ clearPreload: (id: string) => void;
779
+ clearAll: () => void;
780
+ preloadOnIdle: (apps: MicroAppItem[]) => void;
781
+ preloadImmediate: (apps: MicroAppItem[]) => Promise<PreloadedIframe[]>;
782
+ preloadWithStrategy: (options: PreloadOptions) => void;
783
+ getStats: () => {
784
+ total: number;
785
+ ready: number;
786
+ loading: number;
787
+ error: number;
788
+ averageLoadTime: number;
789
+ details: Array<{
790
+ id: string;
791
+ status: string;
792
+ loadTime?: number;
793
+ }>;
794
+ };
795
+ };
796
+
797
+ /**
798
+ * 获取性能监控实例
799
+ */
800
+ export declare const usePerformanceMonitor: () => PerformanceMonitor;
801
+
530
802
  export declare const useRouter: () => {
531
803
  replaceState: (path: string) => void;
532
804
  addRule: (key: string, rule: string | string[]) => void;
@@ -538,4 +810,9 @@ export declare const useRouterEventListener: () => {
538
810
  removeRouterEventListener: (type?: RouterEventListenerTypes | RouterEventListenerTypes[]) => void;
539
811
  };
540
812
 
813
+ /**
814
+ * 获取路由同步管理器实例
815
+ */
816
+ export declare const useRouterSyncManager: (options?: RouterSyncOptions) => RouterSyncManager;
817
+
541
818
  export { }