@gongxh/bit-ui 0.0.7 → 0.0.9
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/bit-ui.cjs +80 -44
- package/dist/bit-ui.min.cjs +1 -1
- package/dist/bit-ui.min.mjs +1 -1
- package/dist/bit-ui.mjs +80 -44
- package/package.json +39 -39
- package/LICENSE +0 -21
package/dist/bit-ui.cjs
CHANGED
|
@@ -486,7 +486,9 @@ class ResLoader {
|
|
|
486
486
|
*/
|
|
487
487
|
static decWaitRef() {
|
|
488
488
|
var _a;
|
|
489
|
-
|
|
489
|
+
// 修复:防止waitRef变为负数
|
|
490
|
+
this.waitRef = Math.max(0, this.waitRef - 1);
|
|
491
|
+
if (this.waitRef === 0) {
|
|
490
492
|
(_a = this._hideWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
491
493
|
}
|
|
492
494
|
}
|
|
@@ -536,6 +538,19 @@ class ResLoader {
|
|
|
536
538
|
*/
|
|
537
539
|
static loadUIPackages(packages, windowName) {
|
|
538
540
|
return __awaiter(this, void 0, void 0, function* () {
|
|
541
|
+
// 修复:防止并发加载相同的包
|
|
542
|
+
// 检查是否有包正在加载,如果有则等待其完成
|
|
543
|
+
const waitPromises = [];
|
|
544
|
+
for (const pkg of packages) {
|
|
545
|
+
const loadingPromise = this.loadingPromises.get(pkg);
|
|
546
|
+
if (loadingPromise) {
|
|
547
|
+
waitPromises.push(loadingPromise);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// 等待所有正在加载的包完成
|
|
551
|
+
if (waitPromises.length > 0) {
|
|
552
|
+
yield Promise.all(waitPromises);
|
|
553
|
+
}
|
|
539
554
|
// 先找出来所有需要加载的包名
|
|
540
555
|
let list = packages.filter(pkg => this.getRef(pkg) <= 0);
|
|
541
556
|
if (list.length <= 0) {
|
|
@@ -545,23 +560,42 @@ class ResLoader {
|
|
|
545
560
|
}
|
|
546
561
|
// 一定有需要加载的资源
|
|
547
562
|
this.addWaitRef();
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
563
|
+
// 记录成功加载的包,用于失败时回滚
|
|
564
|
+
const loadedPackages = [];
|
|
565
|
+
// 创建加载Promise并记录
|
|
566
|
+
const loadPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
567
|
+
try {
|
|
568
|
+
// 获取包对应的bundle名
|
|
569
|
+
let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
|
|
570
|
+
// 加载bundle
|
|
571
|
+
yield this.loadBundles(bundleNames, windowName);
|
|
572
|
+
// 顺序加载每个UI包,每加载成功一个就记录
|
|
573
|
+
for (const pkg of list) {
|
|
574
|
+
yield this.loadSingleUIPackage(pkg, windowName);
|
|
575
|
+
loadedPackages.push(pkg);
|
|
576
|
+
}
|
|
577
|
+
// 所有包加载成功后,减少等待窗引用计数
|
|
578
|
+
this.decWaitRef();
|
|
579
|
+
// 增加包资源的引用计数
|
|
580
|
+
packages.forEach(pkg => this.addRef(pkg));
|
|
581
|
+
}
|
|
582
|
+
catch (err) {
|
|
583
|
+
// 减少等待窗的引用计数
|
|
584
|
+
this.decWaitRef();
|
|
585
|
+
// 回滚:卸载已经加载成功的包
|
|
586
|
+
loadedPackages.forEach(pkg => {
|
|
587
|
+
fairyguiCc.UIPackage.removePackage(pkg);
|
|
588
|
+
});
|
|
589
|
+
throw err;
|
|
590
|
+
}
|
|
591
|
+
finally {
|
|
592
|
+
// 清理加载状态
|
|
593
|
+
list.forEach(pkg => this.loadingPromises.delete(pkg));
|
|
594
|
+
}
|
|
595
|
+
}))();
|
|
596
|
+
// 记录正在加载的包
|
|
597
|
+
list.forEach(pkg => this.loadingPromises.set(pkg, loadPromise));
|
|
598
|
+
yield loadPromise;
|
|
565
599
|
});
|
|
566
600
|
}
|
|
567
601
|
/**
|
|
@@ -595,20 +629,6 @@ class ResLoader {
|
|
|
595
629
|
}
|
|
596
630
|
});
|
|
597
631
|
}
|
|
598
|
-
/**
|
|
599
|
-
* 顺序加载多个 UI 包
|
|
600
|
-
* @param packages 包名列表
|
|
601
|
-
* @param windowName 窗口名(用于失败回调)
|
|
602
|
-
* @internal
|
|
603
|
-
*/
|
|
604
|
-
static loadUIPackagesSequentially(packages, windowName) {
|
|
605
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
// 顺序加载每个UI包
|
|
607
|
-
for (const pkg of packages) {
|
|
608
|
-
yield this.loadSingleUIPackage(pkg, windowName);
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
632
|
/**
|
|
613
633
|
* 加载单个 UI 包
|
|
614
634
|
* @param pkg 包名
|
|
@@ -668,6 +688,8 @@ class ResLoader {
|
|
|
668
688
|
ResLoader.waitRef = 0;
|
|
669
689
|
/** 包的引用计数 包名 -> 引用计数 */
|
|
670
690
|
ResLoader.pkgRefs = new Map();
|
|
691
|
+
/** 包的加载状态 包名 -> 加载中的Promise,用于防止并发加载 */
|
|
692
|
+
ResLoader.loadingPromises = new Map();
|
|
671
693
|
/**
|
|
672
694
|
* 自动释放UI资源
|
|
673
695
|
* @internal
|
|
@@ -926,7 +948,7 @@ class WindowManager {
|
|
|
926
948
|
for (let j = group.windowNames.length - 1; j >= 0; j--) {
|
|
927
949
|
const name = group.windowNames[j];
|
|
928
950
|
const win = WindowManager.getWindow(name);
|
|
929
|
-
if (win.bgAlpha > 0) {
|
|
951
|
+
if (win && win.bgAlpha > 0) {
|
|
930
952
|
topWindow = win;
|
|
931
953
|
break;
|
|
932
954
|
}
|
|
@@ -936,7 +958,7 @@ class WindowManager {
|
|
|
936
958
|
}
|
|
937
959
|
}
|
|
938
960
|
// 如果找到了需要遮罩的窗口
|
|
939
|
-
if (topWindow) {
|
|
961
|
+
if (topWindow && topWindow.parent) {
|
|
940
962
|
// 获取窗口组的根节点
|
|
941
963
|
const parent = topWindow.parent;
|
|
942
964
|
// 将遮罩设置到目标窗口的下方
|
|
@@ -1019,9 +1041,12 @@ class HeaderManager {
|
|
|
1019
1041
|
this._headerWindowsMap.set(headerName, new Set());
|
|
1020
1042
|
}
|
|
1021
1043
|
// 增加引用计数
|
|
1022
|
-
this._refCounts.set(headerName, this._refCounts.get(headerName) + 1);
|
|
1044
|
+
this._refCounts.set(headerName, (this._refCounts.get(headerName) || 0) + 1);
|
|
1023
1045
|
// 记录窗口和header的关系
|
|
1024
|
-
this._headerWindowsMap.get(headerName)
|
|
1046
|
+
const windowsSet = this._headerWindowsMap.get(headerName);
|
|
1047
|
+
if (windowsSet) {
|
|
1048
|
+
windowsSet.add(windowName);
|
|
1049
|
+
}
|
|
1025
1050
|
}
|
|
1026
1051
|
/**
|
|
1027
1052
|
* 显示指定窗口的header
|
|
@@ -1073,9 +1098,12 @@ class HeaderManager {
|
|
|
1073
1098
|
}
|
|
1074
1099
|
const headerName = this.getHeaderName(windowName);
|
|
1075
1100
|
// 减少引用计数
|
|
1076
|
-
const refCount = this._refCounts.get(headerName) - 1;
|
|
1101
|
+
const refCount = (this._refCounts.get(headerName) || 1) - 1;
|
|
1077
1102
|
// 移除映射关系
|
|
1078
|
-
this._headerWindowsMap.get(headerName)
|
|
1103
|
+
const windowsSet = this._headerWindowsMap.get(headerName);
|
|
1104
|
+
if (windowsSet) {
|
|
1105
|
+
windowsSet.delete(windowName);
|
|
1106
|
+
}
|
|
1079
1107
|
// 清除窗口的header信息
|
|
1080
1108
|
this._headerInfos.delete(windowName);
|
|
1081
1109
|
const header = this.getHeader(headerName);
|
|
@@ -1521,7 +1549,8 @@ class WindowGroup {
|
|
|
1521
1549
|
// 最后一个是新显示上来的窗口
|
|
1522
1550
|
if (window.type === exports.WindowType.CloseOne) {
|
|
1523
1551
|
// 关闭上一个窗口(倒数第二个,因为最后一个是当前窗口)
|
|
1524
|
-
|
|
1552
|
+
// 修复:明确检查边界,避免数组越界
|
|
1553
|
+
if (this.size < 2) {
|
|
1525
1554
|
return;
|
|
1526
1555
|
}
|
|
1527
1556
|
const name = this._windowNames[this.size - 2];
|
|
@@ -1538,17 +1567,24 @@ class WindowGroup {
|
|
|
1538
1567
|
}
|
|
1539
1568
|
else if (window.type === exports.WindowType.CloseAll) {
|
|
1540
1569
|
// 关闭所有窗口 从后向前依次删除
|
|
1570
|
+
// 修复:添加异常保护,避免清理异常导致数据不一致
|
|
1541
1571
|
for (let i = this.size - 2; i >= 0; i--) {
|
|
1542
1572
|
const name = this._windowNames[i];
|
|
1543
1573
|
const win = WindowManager.getWindow(name);
|
|
1544
1574
|
if (!win) {
|
|
1545
1575
|
console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
|
|
1546
|
-
|
|
1576
|
+
continue; // 继续处理其他窗口,而不是直接返回
|
|
1577
|
+
}
|
|
1578
|
+
try {
|
|
1579
|
+
// 释放header
|
|
1580
|
+
HeaderManager.releaseHeader(name);
|
|
1581
|
+
win._close();
|
|
1582
|
+
WindowManager.removeWindow(name);
|
|
1583
|
+
}
|
|
1584
|
+
catch (err) {
|
|
1585
|
+
console.error(`关闭窗口【${name}】时发生异常:`, err);
|
|
1586
|
+
// 即使出错也继续处理其他窗口
|
|
1547
1587
|
}
|
|
1548
|
-
// 释放header
|
|
1549
|
-
HeaderManager.releaseHeader(name);
|
|
1550
|
-
win._close();
|
|
1551
|
-
WindowManager.removeWindow(name);
|
|
1552
1588
|
}
|
|
1553
1589
|
// 清理数组,只保留最后一个(当前窗口)
|
|
1554
1590
|
this._windowNames.splice(0, this.size - 1);
|
package/dist/bit-ui.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t,s,i=require("fairygui-cc"),o=require("@gongxh/bit-core"),n=require("cc");function a(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function r(e,t,s,i){return new(s||(s=Promise))(function(o,n){function a(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,r)}d((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed",function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(s||(s={}));class d{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const d=o.transitions;this.serializationTransitionsNode(e,d)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}d._config={};class h{static add(e,t,s,n,a){if(this.has(n))console.warn(`窗口【${n}】已注册,跳过,请检查是否重复注册`);else if(o.debug(`窗口注册 窗口名:${n} 包名:${s} 组名:${t}`),this._windowInfos.set(n,{ctor:e,group:t,pkgName:s,name:n}),i.UIObjectFactory.setExtension(`ui://${s}/${n}`,e),this.addWindowPkg(n,s),a.length>0)for(const e of a)this.addWindowPkg(n,e)}static addHeader(e,t,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`header注册 header名:${s} 包名:${t}`),this._headerInfos.set(s,{ctor:e,pkgName:t}),i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(e,t,s){e.prototype.onConstruct=function(){d.serializeProps(this,t,s),this.onInit&&this.onInit()};const o=e.prototype.dispose;e.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}h._windowInfos=new Map,h._headerInfos=new Map,h._customComponents=new Set,h._customPackageBundle=new Map,h._customPackagePath=new Map,h._windowPkgs=new Map,h._manualPackages=new Set,h._dirty=!0;class c{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=h.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=h.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){return r(this,void 0,void 0,function*(){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)e.forEach(e=>this.addRef(e));else{this.addWaitRef();try{let i=s.map(e=>h.getBundleName(e));yield this.loadBundles(i,t),yield this.loadUIPackagesSequentially(s,t),this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),e}}})}static loadBundles(e,t){return r(this,void 0,void 0,function*(){let s=e.filter(e=>"resources"!==e&&!n.assetManager.getBundle(e));if(!(s.length<=0))for(const e of s)yield new Promise((s,i)=>{n.assetManager.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),i(new Error(`bundle【${e}】加载失败`))):s()})})})}static loadUIPackagesSequentially(e,t){return r(this,void 0,void 0,function*(){for(const s of e)yield this.loadSingleUIPackage(s,t)})}static loadSingleUIPackage(e,t){return new Promise((s,o)=>{let a=h.getBundleName(e),r="resources"===a?n.resources:n.assetManager.getBundle(a);i.UIPackage.loadPackage(r,h.getPackagePath(e),i=>{i?(t&&this._onLoadFail&&this._onLoadFail(t,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const t of e)0===this.subRef(t)&&this.autoRelease&&i.UIPackage.removePackage(t)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const t of e)this.getRef(t)<=0&&(i.UIPackage.removePackage(t),this.pkgRefs.delete(t))}}c.waitRef=0,c.pkgRefs=new Map,c.autoRelease=!0,c._showWaitWindow=null,c._hideWaitWindow=null,c._onLoadFail=null;class l{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this._alphaGraph.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),p.onScreenResize()}static addManualPackage(e){h.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&h.addBundleName(e,t),"ui"!==s&&h.addPackagePath(e,s)}static setUIConfig(e){d.setConfig(e)}static setPackageCallbacks(e){c.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[s.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const s=h.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[s.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=h.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=l.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){c.releaseUnusedRes()}}l._bgAlpha=.75,l._bgColor=new n.Color(0,0,0,0),l._alphaGraph=null,l._groups=new Map,l._groupNames=[],l._windows=new Map;class p{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const t=h.getHeader(e.name),s=i.UIPackage.createObject(t.pkgName,e.name);return s.name=e.name,d.serializeProps(s,t.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!0;const s=h.get(e),i=h.get(t),o=l.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=l.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=l.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=l.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=l.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=l.getWindow(t),o=h.get(t),n=l.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=l.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}p._headers=new Map,p._refCounts=new Map,p._headerWindowsMap=new Map,p._headerInfos=new Map,p._cacheHeaderTopWindow=new Map;class u{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return r(this,void 0,void 0,function*(){let s=l.getTopWindow();if(l.hasWindow(e.name)){const i=l.getWindow(e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&(s._toBottom(),i._toTop()),i}try{yield c.loadWindowRes(e.name);const i=this.createWindow(e.pkgName,e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&s._toBottom(),i}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),p.showHeader(e.name),l.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,t){let s=i.UIPackage.createObject(e,t);return s.name=t,d.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(t),l.addWindow(t,s),p.requestHeader(t,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=l.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),p.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=l.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===exports.WindowType.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=l.getWindow(t);s&&s.isShowing()&&(s._hide(),p.hideHeader(t))}break}if(e.type===exports.WindowType.HideOne){let e=this._windowNames[t-1],s=l.getWindow(e);s&&s.isShowing()&&(s._hide(),p.hideHeader(e))}else{let e=this._windowNames[t-1],s=l.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),p.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===exports.WindowType.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close(),l.removeWindow(e)}else if(e.type===exports.WindowType.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=l.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);p.releaseHeader(t),s._close(),l.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),l.removeWindow(e),c.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?l.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=l.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);p.releaseHeader(s),i._close(),l.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function w(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}exports._uidecorator=void 0,function(e){const t=new Map,i=new Map,o=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return o},e.uiclass=function(e,i,o,n){return function(a){const r=a;a[s.originalName]=o,t.set(r,{ctor:a,props:a[s.prop]||null,callbacks:a[s.callback]||null,controls:a[s.control]||null,transitions:a[s.transition]||null,res:{group:e,pkg:i,name:o}});let d=[];return Array.isArray(n)?d=n:"string"==typeof n&&(d=[n]),h.add(a,e,i,o,d),a}},e.uicom=function(e,t){return function(o){const n=o;return o[s.originalName]=t,i.set(n,{ctor:o,props:o[s.prop]||null,callbacks:o[s.callback]||null,controls:o[s.control]||null,transitions:o[s.transition]||null,res:{pkg:e,name:t}}),h.addComponent(o,e,t),o}},e.uiheader=function(e,t){return function(i){const n=i;return i[s.originalName]=t,o.set(n,{ctor:i,props:i[s.prop]||null,callbacks:i[s.callback]||null,controls:i[s.control]||null,transitions:i[s.transition]||null,res:{pkg:e,name:t}}),h.addHeader(i,e,t),i}},e.uiprop=function(e,t){w(e.constructor,s.prop)[t]=1},e.uicontrol=function(e,t){w(e.constructor,s.control)[t]=1},e.uitransition=function(e,t){w(e.constructor,s.transition)[t]=1},e.uiclick=function(e,t,i){w(e.constructor,s.callback)[t]=i.value}}(exports._uidecorator||(exports._uidecorator={}));const g=globalThis||window||global;g.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},g.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},g.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class _ extends i.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class f{static create(e,t){const i=e[s.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const o=new f;return o.name=i,o.userdata=t,o}static createByName(e,t){const s=new f;return s.name=e,s.userdata=t,s}}class m extends i.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i.GComponent;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=l.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this._swallowNode.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){p.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){l.closeWindowByName(this.name)}}const{ccclass:W,property:H,menu:N}=n._decorator;let S=class extends n.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;o.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),i.GRoot.inst.addChild(t),l.addWindowGroup(new u(e,t,this.ignoreQuery,this.swallowTouch))}};a([H({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],S.prototype,"ignoreQuery",void 0),a([H({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],S.prototype,"swallowTouch",void 0),S=a([W("CocosWindowContainer"),N("bit/UIContainer")],S);const{ccclass:k,menu:y,property:P}=n._decorator;exports.UIModule=class extends o.Module{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&d.setConfig(this.ui_config.json),c.setAutoRelease(this.autoReleaseUIRes),l.bgAlpha=this.bgAlpha,i.GRoot.create(),o.debug("初始化 WindowContainers");const e=new i.GGraph;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),e.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.GRoot.inst.addChild(e),l.setAlphaGraph(e);for(const e of this.getComponentsInChildren(S))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){l.onScreenResize()}},a([P({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],exports.UIModule.prototype,"ui_config",void 0),a([P({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],exports.UIModule.prototype,"bgAlpha",void 0),a([P({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],exports.UIModule.prototype,"autoReleaseUIRes",void 0),exports.UIModule=a([k("UIModule"),y("bit/UIModule")],exports.UIModule),exports.Header=_,exports.HeaderInfo=f,exports.Window=class extends m{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}},exports.WindowGroup=u,exports.WindowManager=l;
|
|
1
|
+
"use strict";var e,t,s,i=require("fairygui-cc"),o=require("@gongxh/bit-core"),n=require("cc");function a(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function r(e,t,s,i){return new(s||(s=Promise))(function(o,n){function a(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,r)}d((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed",function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(s||(s={}));class d{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const d=o.transitions;this.serializationTransitionsNode(e,d)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}d._config={};class h{static add(e,t,s,n,a){if(this.has(n))console.warn(`窗口【${n}】已注册,跳过,请检查是否重复注册`);else if(o.debug(`窗口注册 窗口名:${n} 包名:${s} 组名:${t}`),this._windowInfos.set(n,{ctor:e,group:t,pkgName:s,name:n}),i.UIObjectFactory.setExtension(`ui://${s}/${n}`,e),this.addWindowPkg(n,s),a.length>0)for(const e of a)this.addWindowPkg(n,e)}static addHeader(e,t,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`header注册 header名:${s} 包名:${t}`),this._headerInfos.set(s,{ctor:e,pkgName:t}),i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(e,t,s){e.prototype.onConstruct=function(){d.serializeProps(this,t,s),this.onInit&&this.onInit()};const o=e.prototype.dispose;e.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}h._windowInfos=new Map,h._headerInfos=new Map,h._customComponents=new Set,h._customPackageBundle=new Map,h._customPackagePath=new Map,h._windowPkgs=new Map,h._manualPackages=new Set,h._dirty=!0;class c{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;this.waitRef=Math.max(0,this.waitRef-1),0===this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=h.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=h.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){return r(this,void 0,void 0,function*(){const s=[];for(const t of e){const e=this.loadingPromises.get(t);e&&s.push(e)}s.length>0&&(yield Promise.all(s));let o=e.filter(e=>this.getRef(e)<=0);if(o.length<=0)return void e.forEach(e=>this.addRef(e));this.addWaitRef();const n=[],a=(()=>r(this,void 0,void 0,function*(){try{let s=o.map(e=>h.getBundleName(e));yield this.loadBundles(s,t);for(const e of o)yield this.loadSingleUIPackage(e,t),n.push(e);this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),n.forEach(e=>{i.UIPackage.removePackage(e)}),e}finally{o.forEach(e=>this.loadingPromises.delete(e))}}))();o.forEach(e=>this.loadingPromises.set(e,a)),yield a})}static loadBundles(e,t){return r(this,void 0,void 0,function*(){let s=e.filter(e=>"resources"!==e&&!n.assetManager.getBundle(e));if(!(s.length<=0))for(const e of s)yield new Promise((s,i)=>{n.assetManager.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),i(new Error(`bundle【${e}】加载失败`))):s()})})})}static loadSingleUIPackage(e,t){return new Promise((s,o)=>{let a=h.getBundleName(e),r="resources"===a?n.resources:n.assetManager.getBundle(a);i.UIPackage.loadPackage(r,h.getPackagePath(e),i=>{i?(t&&this._onLoadFail&&this._onLoadFail(t,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const t of e)0===this.subRef(t)&&this.autoRelease&&i.UIPackage.removePackage(t)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const t of e)this.getRef(t)<=0&&(i.UIPackage.removePackage(t),this.pkgRefs.delete(t))}}c.waitRef=0,c.pkgRefs=new Map,c.loadingPromises=new Map,c.autoRelease=!0,c._showWaitWindow=null,c._hideWaitWindow=null,c._onLoadFail=null;class l{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this._alphaGraph.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),p.onScreenResize()}static addManualPackage(e){h.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&h.addBundleName(e,t),"ui"!==s&&h.addPackagePath(e,s)}static setUIConfig(e){d.setConfig(e)}static setPackageCallbacks(e){c.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[s.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const s=h.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[s.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=h.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=l.getWindow(i);if(o&&o.bgAlpha>0){e=o;break}}if(e)break}}if(e&&e.parent){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){c.releaseUnusedRes()}}l._bgAlpha=.75,l._bgColor=new n.Color(0,0,0,0),l._alphaGraph=null,l._groups=new Map,l._groupNames=[],l._windows=new Map;class p{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,(this._refCounts.get(s)||0)+1);const i=this._headerWindowsMap.get(s);i&&i.add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=(this._refCounts.get(t)||1)-1,i=this._headerWindowsMap.get(t);i&&i.delete(e),this._headerInfos.delete(e);const o=this.getHeader(t);if(0===s)o._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const i=this.findTopWindowForHeader(t,e);i?(this._cacheHeaderTopWindow.set(t,i),this.adjustHeaderPosition(t,i),o._show(this.getHeaderUserData(i))):(this._cacheHeaderTopWindow.delete(t),o.isShowing()&&o._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const t=h.getHeader(e.name),s=i.UIPackage.createObject(t.pkgName,e.name);return s.name=e.name,d.serializeProps(s,t.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!0;const s=h.get(e),i=h.get(t),o=l.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=l.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=l.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=l.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=l.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=l.getWindow(t),o=h.get(t),n=l.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=l.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}p._headers=new Map,p._refCounts=new Map,p._headerWindowsMap=new Map,p._headerInfos=new Map,p._cacheHeaderTopWindow=new Map;class u{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return r(this,void 0,void 0,function*(){let s=l.getTopWindow();if(l.hasWindow(e.name)){const i=l.getWindow(e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&(s._toBottom(),i._toTop()),i}try{yield c.loadWindowRes(e.name);const i=this.createWindow(e.pkgName,e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&s._toBottom(),i}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),p.showHeader(e.name),l.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,t){let s=i.UIPackage.createObject(e,t);return s.name=t,d.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(t),l.addWindow(t,s),p.requestHeader(t,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=l.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),p.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=l.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===exports.WindowType.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=l.getWindow(t);s&&s.isShowing()&&(s._hide(),p.hideHeader(t))}break}if(e.type===exports.WindowType.HideOne){let e=this._windowNames[t-1],s=l.getWindow(e);s&&s.isShowing()&&(s._hide(),p.hideHeader(e))}else{let e=this._windowNames[t-1],s=l.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),p.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===exports.WindowType.CloseOne){if(this.size<2)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close(),l.removeWindow(e)}else if(e.type===exports.WindowType.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=l.getWindow(t);if(s)try{p.releaseHeader(t),s._close(),l.removeWindow(t)}catch(e){console.error(`关闭窗口【${t}】时发生异常:`,e)}else console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=l.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);p.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),l.removeWindow(e),c.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?l.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=l.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);p.releaseHeader(s),i._close(),l.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function w(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}exports._uidecorator=void 0,function(e){const t=new Map,i=new Map,o=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return o},e.uiclass=function(e,i,o,n){return function(a){const r=a;a[s.originalName]=o,t.set(r,{ctor:a,props:a[s.prop]||null,callbacks:a[s.callback]||null,controls:a[s.control]||null,transitions:a[s.transition]||null,res:{group:e,pkg:i,name:o}});let d=[];return Array.isArray(n)?d=n:"string"==typeof n&&(d=[n]),h.add(a,e,i,o,d),a}},e.uicom=function(e,t){return function(o){const n=o;return o[s.originalName]=t,i.set(n,{ctor:o,props:o[s.prop]||null,callbacks:o[s.callback]||null,controls:o[s.control]||null,transitions:o[s.transition]||null,res:{pkg:e,name:t}}),h.addComponent(o,e,t),o}},e.uiheader=function(e,t){return function(i){const n=i;return i[s.originalName]=t,o.set(n,{ctor:i,props:i[s.prop]||null,callbacks:i[s.callback]||null,controls:i[s.control]||null,transitions:i[s.transition]||null,res:{pkg:e,name:t}}),h.addHeader(i,e,t),i}},e.uiprop=function(e,t){w(e.constructor,s.prop)[t]=1},e.uicontrol=function(e,t){w(e.constructor,s.control)[t]=1},e.uitransition=function(e,t){w(e.constructor,s.transition)[t]=1},e.uiclick=function(e,t,i){w(e.constructor,s.callback)[t]=i.value}}(exports._uidecorator||(exports._uidecorator={}));const g=globalThis||window||global;g.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},g.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},g.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class _ extends i.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class f{static create(e,t){const i=e[s.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const o=new f;return o.name=i,o.userdata=t,o}static createByName(e,t){const s=new f;return s.name=e,s.userdata=t,s}}class m extends i.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i.GComponent;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=l.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this._swallowNode.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){p.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){l.closeWindowByName(this.name)}}const{ccclass:W,property:H,menu:N}=n._decorator;let k=class extends n.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;o.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),i.GRoot.inst.addChild(t),l.addWindowGroup(new u(e,t,this.ignoreQuery,this.swallowTouch))}};a([H({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],k.prototype,"ignoreQuery",void 0),a([H({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],k.prototype,"swallowTouch",void 0),k=a([W("CocosWindowContainer"),N("bit/UIContainer")],k);const{ccclass:S,menu:P,property:y}=n._decorator;exports.UIModule=class extends o.Module{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&d.setConfig(this.ui_config.json),c.setAutoRelease(this.autoReleaseUIRes),l.bgAlpha=this.bgAlpha,i.GRoot.create(),o.debug("初始化 WindowContainers");const e=new i.GGraph;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),e.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.GRoot.inst.addChild(e),l.setAlphaGraph(e);for(const e of this.getComponentsInChildren(k))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){l.onScreenResize()}},a([y({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],exports.UIModule.prototype,"ui_config",void 0),a([y({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],exports.UIModule.prototype,"bgAlpha",void 0),a([y({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],exports.UIModule.prototype,"autoReleaseUIRes",void 0),exports.UIModule=a([S("UIModule"),P("bit/UIModule")],exports.UIModule),exports.Header=_,exports.HeaderInfo=f,exports.Window=class extends m{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}},exports.WindowGroup=u,exports.WindowManager=l;
|
package/dist/bit-ui.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UIObjectFactory as e,UIPackage as t,GComponent as i,GRoot as s,GGraph as o}from"fairygui-cc";import{debug as n,Screen as a,Module as r,Adapter as h}from"@gongxh/bit-core";import{resources as d,assetManager as l,Color as c,_decorator as u,Component as w,JsonAsset as p}from"cc";function g(e,t,i,s){var o,n=arguments.length,a=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,s);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,i,a):o(t,i))||a);return n>3&&a&&Object.defineProperty(t,i,a),a}function _(e,t,i,s){return new(i||(i=Promise))(function(o,n){function a(e){try{h(s.next(e))}catch(e){n(e)}}function r(e){try{h(s.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,r)}h((s=s.apply(e,t||[])).next())})}var f,m,W,H;"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(f||(f={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(m||(m={})),function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(W||(W={}));class N{static setConfig(e){this._config=e}static serializeProps(e,t,i){if(!this._config)return;const s=this._config[t];if(!s)return;const o=s[i=i||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})属性(${i})赋值,请检查节点配置是否正确`);break}e[i]=n==e?null:n}}static serializationCallbacksNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})的(${i})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[i],e)}}static serializationControlsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置控制器,请检查配置是否正确`);break}e[i]=n,s+=2}}static serializationTransitionsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置动画,请检查配置是否正确`);break}e[i]=n,s+=2}}}N._config={};class k{static add(t,i,s,o,a){if(this.has(o))console.warn(`窗口【${o}】已注册,跳过,请检查是否重复注册`);else if(n(`窗口注册 窗口名:${o} 包名:${s} 组名:${i}`),this._windowInfos.set(o,{ctor:t,group:i,pkgName:s,name:o}),e.setExtension(`ui://${s}/${o}`,t),this.addWindowPkg(o,s),a.length>0)for(const e of a)this.addWindowPkg(o,e)}static addHeader(t,i,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(n(`header注册 header名:${s} 包名:${i}`),this._headerInfos.set(s,{ctor:t,pkgName:i}),e.setExtension(`ui://${i}/${s}`,t))}static addComponent(e,t,i){const s=`${t}/${i}`;this._customComponents.has(s)?console.debug(`自定义组件【${i}】已注册,跳过,请检查是否重复注册`):(n(`自定义组件注册 组件名:${i} 包名:${t}`),this._customComponents.add(s),this.registerComponent(e,t,i))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(t,i,s){t.prototype.onConstruct=function(){N.serializeProps(this,i,s),this.onInit&&this.onInit()};const o=t.prototype.dispose;t.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},e.setExtension(`ui://${i}/${s}`,t)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const i=e[t];this._manualPackages.has(i)&&e.splice(t,1)}}}}k._windowInfos=new Map,k._headerInfos=new Map,k._customComponents=new Set,k._customPackageBundle=new Map,k._customPackagePath=new Map,k._windowPkgs=new Map,k._manualPackages=new Set,k._dirty=!0;class P{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=k.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=k.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){return _(this,void 0,void 0,function*(){let i=e.filter(e=>this.getRef(e)<=0);if(i.length<=0)e.forEach(e=>this.addRef(e));else{this.addWaitRef();try{let s=i.map(e=>k.getBundleName(e));yield this.loadBundles(s,t),yield this.loadUIPackagesSequentially(i,t),this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),e}}})}static loadBundles(e,t){return _(this,void 0,void 0,function*(){let i=e.filter(e=>"resources"!==e&&!l.getBundle(e));if(!(i.length<=0))for(const e of i)yield new Promise((i,s)=>{l.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),s(new Error(`bundle【${e}】加载失败`))):i()})})})}static loadUIPackagesSequentially(e,t){return _(this,void 0,void 0,function*(){for(const i of e)yield this.loadSingleUIPackage(i,t)})}static loadSingleUIPackage(e,i){return new Promise((s,o)=>{let n=k.getBundleName(e),a="resources"===n?d:l.getBundle(n);t.loadPackage(a,k.getPackagePath(e),t=>{t?(i&&this._onLoadFail&&this._onLoadFail(i,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const i of e)0===this.subRef(i)&&this.autoRelease&&t.removePackage(i)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const i of e)this.getRef(i)<=0&&(t.removePackage(i),this.pkgRefs.delete(i))}}P.waitRef=0,P.pkgRefs=new Map,P.autoRelease=!0,P._showWaitWindow=null,P._hideWaitWindow=null,P._onLoadFail=null;class C{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this._alphaGraph.setSize(a.ScreenWidth,a.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),v.onScreenResize()}static addManualPackage(e){k.addManualPackage(e)}static setPackageInfo(e,t="resources",i="ui"){"resources"!==t&&k.addBundleName(e,t),"ui"!==i&&k.addPackagePath(e,i)}static setUIConfig(e){N.setConfig(e)}static setPackageCallbacks(e){P.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[W.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const i=k.get(e);return this.getWindowGroup(i.group).showWindow(i,t)}static closeWindow(e){const t=e[W.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=k.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let i=this.getTopWindow();i&&!i.isTop()&&i._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let i=t.length-1;i>=0;i--){const s=this.getWindowGroup(t[i]);if((!s.isIgnore||e)&&0!==s.size)return s.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const i=this._groups.get(this._groupNames[t]);if(0!==i.size){for(let t=i.windowNames.length-1;t>=0;t--){const s=i.windowNames[t],o=C.getWindow(s);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,i=t.getChildIndex(e);let s=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),s=t.numChildren-1):s=t.getChildIndex(this._alphaGraph);let o=s>=i?i:i-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){P.releaseUnusedRes()}}C._bgAlpha=.75,C._bgColor=new c(0,0,0,0),C._alphaGraph=null,C._groups=new Map,C._groupNames=[],C._windows=new Map;class v{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const i=t.name;if(!this._headers.has(i)){const e=this.createHeader(t);this._headers.set(i,e),this._refCounts.set(i,0),this._headerWindowsMap.set(i,new Set)}this._refCounts.set(i,this._refCounts.get(i)+1),this._headerWindowsMap.get(i).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&i._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);i._show(this.getHeaderUserData(e))}else i.isShowing()&&i._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),i=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const s=this.getHeader(t);if(0===i)s._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,i);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),s._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),s.isShowing()&&s._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const i=this.getHeaderName(e),s=null==t?void 0:t.name;if(i!==s)i&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(s)===e){this.getHeader(s)._show(t.userdata)}}}static createHeader(e){const i=k.getHeader(e.name),s=t.createObject(i.pkgName,e.name);return s.name=e.name,N.serializeProps(s,i.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,i){const s=this._cacheHeaderTopWindow.get(e);if(i){if(!s||this.isWindowAbove(t,s))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(s===t){const i=this.findTopWindowForHeader(e,t);if(i)this._cacheHeaderTopWindow.set(e,i),this.adjustHeaderPosition(e,i);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!0;const i=k.get(e),s=k.get(t),o=C.getGroupNames(),n=o.indexOf(i.group),a=o.indexOf(s.group);if(n!==a)return n>a;const r=C.getWindowGroup(i.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const i=this._headerWindowsMap.get(e);if(!i||0===i.size)return null;const s=C.getGroupNames();for(let e=s.length-1;e>=0;e--){const o=C.getWindowGroup(s[e]);for(let e=o.windowNames.length-1;e>=0;e--){const s=o.windowNames[e];if(s===t)continue;if(!i.has(s))continue;const n=C.getWindow(s);if(n&&n.isShowing())return s}}return null}static adjustHeaderPosition(e,t){const i=this._headers.get(e),s=C.getWindow(t),o=k.get(t),n=C.getWindowGroup(o.group),a=n.root;i.parent!==a&&(i.removeFromParent(),a.addChild(i));let r=a.getChildIndex(s);for(let e=n.windowNames.length-1;e>=0;e--){const t=C.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(i,r+1)}}v._headers=new Map,v._refCounts=new Map,v._headerWindowsMap=new Map,v._headerInfos=new Map,v._cacheHeaderTopWindow=new Map;class b{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,i,s){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=i,this._swallowTouch=s,this._windowNames=[]}showWindow(e,t){return _(this,void 0,void 0,function*(){let i=C.getTopWindow();if(C.hasWindow(e.name)){const s=C.getWindow(e.name);return this.showAdjustment(s,t),i&&i.name!==s.name&&(i._toBottom(),s._toTop()),s}try{yield P.loadWindowRes(e.name);const s=this.createWindow(e.pkgName,e.name);return this.showAdjustment(s,t),i&&i.name!==s.name&&i._toBottom(),s}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),v.showHeader(e.name),C.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,i){let s=t.createObject(e,i);return s.name=i,N.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(i),C.addWindow(i,s),v.requestHeader(i,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=C.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),v.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=C.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===f.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const i=C.getWindow(t);i&&i.isShowing()&&(i._hide(),v.hideHeader(t))}break}if(e.type===f.HideOne){let e=this._windowNames[t-1],i=C.getWindow(e);i&&i.isShowing()&&(i._hide(),v.hideHeader(e))}else{let e=this._windowNames[t-1],i=C.getWindow(e);i&&!i.isShowing()&&(i._showFromHide(),v.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===f.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=C.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);v.releaseHeader(e),t._close(),C.removeWindow(e)}else if(e.type===f.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],i=C.getWindow(t);if(!i)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);v.releaseHeader(t),i._close(),C.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=C.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);v.releaseHeader(e),t._close();let i=this._windowNames.lastIndexOf(e);i<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(i,1),C.removeWindow(e),P.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?C.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let i=this._windowNames[t];if(e.some(e=>e.name===i))continue;const s=C.getWindow(i);if(!s)return void console.error(`[BUG] 窗口【${i}】不存在,数据结构已损坏`);v.releaseHeader(i),s._close(),C.removeWindow(i),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function S(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}!function(e){const t=new Map,i=new Map,s=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return s},e.uiclass=function(e,i,s,o){return function(n){const a=n;n[W.originalName]=s,t.set(a,{ctor:n,props:n[W.prop]||null,callbacks:n[W.callback]||null,controls:n[W.control]||null,transitions:n[W.transition]||null,res:{group:e,pkg:i,name:s}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),k.add(n,e,i,s,r),n}},e.uicom=function(e,t){return function(s){const o=s;return s[W.originalName]=t,i.set(o,{ctor:s,props:s[W.prop]||null,callbacks:s[W.callback]||null,controls:s[W.control]||null,transitions:s[W.transition]||null,res:{pkg:e,name:t}}),k.addComponent(s,e,t),s}},e.uiheader=function(e,t){return function(i){const o=i;return i[W.originalName]=t,s.set(o,{ctor:i,props:i[W.prop]||null,callbacks:i[W.callback]||null,controls:i[W.control]||null,transitions:i[W.transition]||null,res:{pkg:e,name:t}}),k.addHeader(i,e,t),i}},e.uiprop=function(e,t){S(e.constructor,W.prop)[t]=1},e.uicontrol=function(e,t){S(e.constructor,W.control)[t]=1},e.uitransition=function(e,t){S(e.constructor,W.transition)[t]=1},e.uiclick=function(e,t,i){S(e.constructor,W.callback)[t]=i.value}}(H||(H={}));const y=globalThis||window||global;y.getKunpoRegisterWindowMaps=function(){return H.getWindowMaps()},y.getKunpoRegisterComponentMaps=function(){return H.getComponentMaps()},y.getKunpoRegisterHeaderMaps=function(){return H.getHeaderMaps()};class I extends i{constructor(){super(...arguments),this.adapterType=m.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class T{static create(e,t){const i=e[W.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const s=new T;return s.name=i,s.userdata=t,s}static createByName(e,t){const i=new T;return i.name=e,i.userdata=t,i}}class R extends i{constructor(){super(...arguments),this.type=f.Normal,this.adapterType=m.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=C.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this._swallowNode.setSize(a.ScreenWidth,a.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){v.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){C.closeWindowByName(this.name)}}class $ extends R{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}}const{ccclass:A,property:z,menu:G}=u;let U=class extends w{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;n(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(a.ScreenWidth,a.ScreenHeight,!0),s.inst.addChild(t),C.addWindowGroup(new b(e,t,this.ignoreQuery,this.swallowTouch))}};g([z({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],U.prototype,"ignoreQuery",void 0),g([z({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],U.prototype,"swallowTouch",void 0),U=g([A("CocosWindowContainer"),G("bit/UIContainer")],U);const{ccclass:M,menu:B,property:x}=u;let F=class extends r{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&N.setConfig(this.ui_config.json),P.setAutoRelease(this.autoReleaseUIRes),C.bgAlpha=this.bgAlpha,s.create(),n("初始化 WindowContainers");const e=new o;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),e.setSize(a.ScreenWidth,a.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,s.inst.addChild(e),C.setAlphaGraph(e);for(const e of this.getComponentsInChildren(U))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){C.onScreenResize()}};g([x({type:p,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],F.prototype,"ui_config",void 0),g([x({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],F.prototype,"bgAlpha",void 0),g([x({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],F.prototype,"autoReleaseUIRes",void 0),F=g([M("UIModule"),B("bit/UIModule")],F);export{m as AdapterType,I as Header,T as HeaderInfo,F as UIModule,$ as Window,b as WindowGroup,C as WindowManager,f as WindowType,H as _uidecorator};
|
|
1
|
+
import{UIObjectFactory as e,UIPackage as t,GComponent as s,GRoot as i,GGraph as o}from"fairygui-cc";import{debug as n,Screen as a,Module as r,Adapter as h}from"@gongxh/bit-core";import{resources as d,assetManager as l,Color as c,_decorator as u,Component as w,JsonAsset as p}from"cc";function g(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function _(e,t,s,i){return new(s||(s=Promise))(function(o,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function r(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,r)}h((i=i.apply(e,t||[])).next())})}var f,m,W,H;"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(f||(f={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(m||(m={})),function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(W||(W={}));class N{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}N._config={};class k{static add(t,s,i,o,a){if(this.has(o))console.warn(`窗口【${o}】已注册,跳过,请检查是否重复注册`);else if(n(`窗口注册 窗口名:${o} 包名:${i} 组名:${s}`),this._windowInfos.set(o,{ctor:t,group:s,pkgName:i,name:o}),e.setExtension(`ui://${i}/${o}`,t),this.addWindowPkg(o,i),a.length>0)for(const e of a)this.addWindowPkg(o,e)}static addHeader(t,s,i){this.hasHeader(i)?console.warn(`header【${i}】已注册,跳过,请检查是否重复注册`):(n(`header注册 header名:${i} 包名:${s}`),this._headerInfos.set(i,{ctor:t,pkgName:s}),e.setExtension(`ui://${s}/${i}`,t))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(n(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(t,s,i){t.prototype.onConstruct=function(){N.serializeProps(this,s,i),this.onInit&&this.onInit()};const o=t.prototype.dispose;t.prototype.dispose=function(){this.onClose&&this.onClose(),o.call(this)},e.setExtension(`ui://${s}/${i}`,t)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}k._windowInfos=new Map,k._headerInfos=new Map,k._customComponents=new Set,k._customPackageBundle=new Map,k._customPackagePath=new Map,k._windowPkgs=new Map,k._manualPackages=new Set,k._dirty=!0;class P{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;this.waitRef=Math.max(0,this.waitRef-1),0===this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=k.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=k.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,s){return _(this,void 0,void 0,function*(){const i=[];for(const t of e){const e=this.loadingPromises.get(t);e&&i.push(e)}i.length>0&&(yield Promise.all(i));let o=e.filter(e=>this.getRef(e)<=0);if(o.length<=0)return void e.forEach(e=>this.addRef(e));this.addWaitRef();const n=[],a=(()=>_(this,void 0,void 0,function*(){try{let t=o.map(e=>k.getBundleName(e));yield this.loadBundles(t,s);for(const e of o)yield this.loadSingleUIPackage(e,s),n.push(e);this.decWaitRef(),e.forEach(e=>this.addRef(e))}catch(e){throw this.decWaitRef(),n.forEach(e=>{t.removePackage(e)}),e}finally{o.forEach(e=>this.loadingPromises.delete(e))}}))();o.forEach(e=>this.loadingPromises.set(e,a)),yield a})}static loadBundles(e,t){return _(this,void 0,void 0,function*(){let s=e.filter(e=>"resources"!==e&&!l.getBundle(e));if(!(s.length<=0))for(const e of s)yield new Promise((s,i)=>{l.loadBundle(e,(o,n)=>{o?(this._onLoadFail&&this._onLoadFail(t,1,e),i(new Error(`bundle【${e}】加载失败`))):s()})})})}static loadSingleUIPackage(e,s){return new Promise((i,o)=>{let n=k.getBundleName(e),a="resources"===n?d:l.getBundle(n);t.loadPackage(a,k.getPackagePath(e),t=>{t?(s&&this._onLoadFail&&this._onLoadFail(s,2,e),o(new Error(`UI包【${e}】加载失败`))):i()})})}static unloadUIPackages(e){for(const s of e)0===this.subRef(s)&&this.autoRelease&&t.removePackage(s)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const s of e)this.getRef(s)<=0&&(t.removePackage(s),this.pkgRefs.delete(s))}}P.waitRef=0,P.pkgRefs=new Map,P.loadingPromises=new Map,P.autoRelease=!0,P._showWaitWindow=null,P._hideWaitWindow=null,P._onLoadFail=null;class v{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this._alphaGraph.setSize(a.ScreenWidth,a.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),C.onScreenResize()}static addManualPackage(e){k.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&k.addBundleName(e,t),"ui"!==s&&k.addPackagePath(e,s)}static setUIConfig(e){N.setConfig(e)}static setPackageCallbacks(e){P.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const s=e[W.originalName];if(!s)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(s,t)}static showWindowByName(e,t){const s=k.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[W.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=k.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=v.getWindow(i);if(o&&o.bgAlpha>0){e=o;break}}if(e)break}}if(e&&e.parent){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){P.releaseUnusedRes()}}v._bgAlpha=.75,v._bgColor=new c(0,0,0,0),v._alphaGraph=null,v._groups=new Map,v._groupNames=[],v._windows=new Map;class C{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,(this._refCounts.get(s)||0)+1);const i=this._headerWindowsMap.get(s);i&&i.add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=(this._refCounts.get(t)||1)-1,i=this._headerWindowsMap.get(t);i&&i.delete(e),this._headerInfos.delete(e);const o=this.getHeader(t);if(0===s)o._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const i=this.findTopWindowForHeader(t,e);i?(this._cacheHeaderTopWindow.set(t,i),this.adjustHeaderPosition(t,i),o._show(this.getHeaderUserData(i))):(this._cacheHeaderTopWindow.delete(t),o.isShowing()&&o._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const s=k.getHeader(e.name),i=t.createObject(s.pkgName,e.name);return i.name=e.name,N.serializeProps(i,s.pkgName),i._init(),i._adapted(),i}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!0;const s=k.get(e),i=k.get(t),o=v.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=v.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=v.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=v.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=v.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=v.getWindow(t),o=k.get(t),n=v.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=v.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}C._headers=new Map,C._refCounts=new Map,C._headerWindowsMap=new Map,C._headerInfos=new Map,C._cacheHeaderTopWindow=new Map;class b{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return _(this,void 0,void 0,function*(){let s=v.getTopWindow();if(v.hasWindow(e.name)){const i=v.getWindow(e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&(s._toBottom(),i._toTop()),i}try{yield P.loadWindowRes(e.name);const i=this.createWindow(e.pkgName,e.name);return this.showAdjustment(i,t),s&&s.name!==i.name&&s._toBottom(),i}catch(t){throw new Error(`窗口【${e.name}】打开失败: ${t.message}`)}})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),C.showHeader(e.name),v.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,s){let i=t.createObject(e,s);return i.name=s,N.serializeProps(i,e),i._init(this._swallowTouch),i._adapted(),this._root.addChild(i),0===this.size&&(this._root.visible=!0),this._windowNames.push(s),v.addWindow(s,i),C.requestHeader(s,i.getHeaderInfo()),i}processWindowHideStatus(e){let t=v.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),C.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=v.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===f.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=v.getWindow(t);s&&s.isShowing()&&(s._hide(),C.hideHeader(t))}break}if(e.type===f.HideOne){let e=this._windowNames[t-1],s=v.getWindow(e);s&&s.isShowing()&&(s._hide(),C.hideHeader(e))}else{let e=this._windowNames[t-1],s=v.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),C.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===f.CloseOne){if(this.size<2)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=v.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);C.releaseHeader(e),t._close(),v.removeWindow(e)}else if(e.type===f.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=v.getWindow(t);if(s)try{C.releaseHeader(t),s._close(),v.removeWindow(t)}catch(e){console.error(`关闭窗口【${t}】时发生异常:`,e)}else console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=v.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);C.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),v.removeWindow(e),P.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?v.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=v.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);C.releaseHeader(s),i._close(),v.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function y(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}!function(e){const t=new Map,s=new Map,i=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return s},e.getHeaderMaps=function(){return i},e.uiclass=function(e,s,i,o){return function(n){const a=n;n[W.originalName]=i,t.set(a,{ctor:n,props:n[W.prop]||null,callbacks:n[W.callback]||null,controls:n[W.control]||null,transitions:n[W.transition]||null,res:{group:e,pkg:s,name:i}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),k.add(n,e,s,i,r),n}},e.uicom=function(e,t){return function(i){const o=i;return i[W.originalName]=t,s.set(o,{ctor:i,props:i[W.prop]||null,callbacks:i[W.callback]||null,controls:i[W.control]||null,transitions:i[W.transition]||null,res:{pkg:e,name:t}}),k.addComponent(i,e,t),i}},e.uiheader=function(e,t){return function(s){const o=s;return s[W.originalName]=t,i.set(o,{ctor:s,props:s[W.prop]||null,callbacks:s[W.callback]||null,controls:s[W.control]||null,transitions:s[W.transition]||null,res:{pkg:e,name:t}}),k.addHeader(s,e,t),s}},e.uiprop=function(e,t){y(e.constructor,W.prop)[t]=1},e.uicontrol=function(e,t){y(e.constructor,W.control)[t]=1},e.uitransition=function(e,t){y(e.constructor,W.transition)[t]=1},e.uiclick=function(e,t,s){y(e.constructor,W.callback)[t]=s.value}}(H||(H={}));const S=globalThis||window||global;S.getKunpoRegisterWindowMaps=function(){return H.getWindowMaps()},S.getKunpoRegisterComponentMaps=function(){return H.getComponentMaps()},S.getKunpoRegisterHeaderMaps=function(){return H.getHeaderMaps()};class I extends s{constructor(){super(...arguments),this.adapterType=m.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class T{static create(e,t){const s=e[W.originalName];if(!s)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const i=new T;return i.name=s,i.userdata=t,i}static createByName(e,t){const s=new T;return s.name=e,s.userdata=t,s}}class R extends s{constructor(){super(...arguments),this.type=f.Normal,this.adapterType=m.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new s;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=v.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case m.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case m.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this._swallowNode.setSize(a.ScreenWidth,a.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){C.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){v.closeWindowByName(this.name)}}class $ extends R{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}}const{ccclass:A,property:z,menu:G}=u;let M=class extends w{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;n(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new s;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(a.ScreenWidth,a.ScreenHeight,!0),i.inst.addChild(t),v.addWindowGroup(new b(e,t,this.ignoreQuery,this.swallowTouch))}};g([z({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],M.prototype,"ignoreQuery",void 0),g([z({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],M.prototype,"swallowTouch",void 0),M=g([A("CocosWindowContainer"),G("bit/UIContainer")],M);const{ccclass:U,menu:B,property:x}=u;let F=class extends r{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&N.setConfig(this.ui_config.json),P.setAutoRelease(this.autoReleaseUIRes),v.bgAlpha=this.bgAlpha,i.create(),n("初始化 WindowContainers");const e=new o;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),e.setSize(a.ScreenWidth,a.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.inst.addChild(e),v.setAlphaGraph(e);for(const e of this.getComponentsInChildren(M))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){v.onScreenResize()}};g([x({type:p,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],F.prototype,"ui_config",void 0),g([x({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],F.prototype,"bgAlpha",void 0),g([x({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],F.prototype,"autoReleaseUIRes",void 0),F=g([U("UIModule"),B("bit/UIModule")],F);export{m as AdapterType,I as Header,T as HeaderInfo,F as UIModule,$ as Window,b as WindowGroup,v as WindowManager,f as WindowType,H as _uidecorator};
|
package/dist/bit-ui.mjs
CHANGED
|
@@ -484,7 +484,9 @@ class ResLoader {
|
|
|
484
484
|
*/
|
|
485
485
|
static decWaitRef() {
|
|
486
486
|
var _a;
|
|
487
|
-
|
|
487
|
+
// 修复:防止waitRef变为负数
|
|
488
|
+
this.waitRef = Math.max(0, this.waitRef - 1);
|
|
489
|
+
if (this.waitRef === 0) {
|
|
488
490
|
(_a = this._hideWaitWindow) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
489
491
|
}
|
|
490
492
|
}
|
|
@@ -534,6 +536,19 @@ class ResLoader {
|
|
|
534
536
|
*/
|
|
535
537
|
static loadUIPackages(packages, windowName) {
|
|
536
538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
539
|
+
// 修复:防止并发加载相同的包
|
|
540
|
+
// 检查是否有包正在加载,如果有则等待其完成
|
|
541
|
+
const waitPromises = [];
|
|
542
|
+
for (const pkg of packages) {
|
|
543
|
+
const loadingPromise = this.loadingPromises.get(pkg);
|
|
544
|
+
if (loadingPromise) {
|
|
545
|
+
waitPromises.push(loadingPromise);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// 等待所有正在加载的包完成
|
|
549
|
+
if (waitPromises.length > 0) {
|
|
550
|
+
yield Promise.all(waitPromises);
|
|
551
|
+
}
|
|
537
552
|
// 先找出来所有需要加载的包名
|
|
538
553
|
let list = packages.filter(pkg => this.getRef(pkg) <= 0);
|
|
539
554
|
if (list.length <= 0) {
|
|
@@ -543,23 +558,42 @@ class ResLoader {
|
|
|
543
558
|
}
|
|
544
559
|
// 一定有需要加载的资源
|
|
545
560
|
this.addWaitRef();
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
561
|
+
// 记录成功加载的包,用于失败时回滚
|
|
562
|
+
const loadedPackages = [];
|
|
563
|
+
// 创建加载Promise并记录
|
|
564
|
+
const loadPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
565
|
+
try {
|
|
566
|
+
// 获取包对应的bundle名
|
|
567
|
+
let bundleNames = list.map(pkg => InfoPool.getBundleName(pkg));
|
|
568
|
+
// 加载bundle
|
|
569
|
+
yield this.loadBundles(bundleNames, windowName);
|
|
570
|
+
// 顺序加载每个UI包,每加载成功一个就记录
|
|
571
|
+
for (const pkg of list) {
|
|
572
|
+
yield this.loadSingleUIPackage(pkg, windowName);
|
|
573
|
+
loadedPackages.push(pkg);
|
|
574
|
+
}
|
|
575
|
+
// 所有包加载成功后,减少等待窗引用计数
|
|
576
|
+
this.decWaitRef();
|
|
577
|
+
// 增加包资源的引用计数
|
|
578
|
+
packages.forEach(pkg => this.addRef(pkg));
|
|
579
|
+
}
|
|
580
|
+
catch (err) {
|
|
581
|
+
// 减少等待窗的引用计数
|
|
582
|
+
this.decWaitRef();
|
|
583
|
+
// 回滚:卸载已经加载成功的包
|
|
584
|
+
loadedPackages.forEach(pkg => {
|
|
585
|
+
UIPackage.removePackage(pkg);
|
|
586
|
+
});
|
|
587
|
+
throw err;
|
|
588
|
+
}
|
|
589
|
+
finally {
|
|
590
|
+
// 清理加载状态
|
|
591
|
+
list.forEach(pkg => this.loadingPromises.delete(pkg));
|
|
592
|
+
}
|
|
593
|
+
}))();
|
|
594
|
+
// 记录正在加载的包
|
|
595
|
+
list.forEach(pkg => this.loadingPromises.set(pkg, loadPromise));
|
|
596
|
+
yield loadPromise;
|
|
563
597
|
});
|
|
564
598
|
}
|
|
565
599
|
/**
|
|
@@ -593,20 +627,6 @@ class ResLoader {
|
|
|
593
627
|
}
|
|
594
628
|
});
|
|
595
629
|
}
|
|
596
|
-
/**
|
|
597
|
-
* 顺序加载多个 UI 包
|
|
598
|
-
* @param packages 包名列表
|
|
599
|
-
* @param windowName 窗口名(用于失败回调)
|
|
600
|
-
* @internal
|
|
601
|
-
*/
|
|
602
|
-
static loadUIPackagesSequentially(packages, windowName) {
|
|
603
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
-
// 顺序加载每个UI包
|
|
605
|
-
for (const pkg of packages) {
|
|
606
|
-
yield this.loadSingleUIPackage(pkg, windowName);
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
630
|
/**
|
|
611
631
|
* 加载单个 UI 包
|
|
612
632
|
* @param pkg 包名
|
|
@@ -666,6 +686,8 @@ class ResLoader {
|
|
|
666
686
|
ResLoader.waitRef = 0;
|
|
667
687
|
/** 包的引用计数 包名 -> 引用计数 */
|
|
668
688
|
ResLoader.pkgRefs = new Map();
|
|
689
|
+
/** 包的加载状态 包名 -> 加载中的Promise,用于防止并发加载 */
|
|
690
|
+
ResLoader.loadingPromises = new Map();
|
|
669
691
|
/**
|
|
670
692
|
* 自动释放UI资源
|
|
671
693
|
* @internal
|
|
@@ -924,7 +946,7 @@ class WindowManager {
|
|
|
924
946
|
for (let j = group.windowNames.length - 1; j >= 0; j--) {
|
|
925
947
|
const name = group.windowNames[j];
|
|
926
948
|
const win = WindowManager.getWindow(name);
|
|
927
|
-
if (win.bgAlpha > 0) {
|
|
949
|
+
if (win && win.bgAlpha > 0) {
|
|
928
950
|
topWindow = win;
|
|
929
951
|
break;
|
|
930
952
|
}
|
|
@@ -934,7 +956,7 @@ class WindowManager {
|
|
|
934
956
|
}
|
|
935
957
|
}
|
|
936
958
|
// 如果找到了需要遮罩的窗口
|
|
937
|
-
if (topWindow) {
|
|
959
|
+
if (topWindow && topWindow.parent) {
|
|
938
960
|
// 获取窗口组的根节点
|
|
939
961
|
const parent = topWindow.parent;
|
|
940
962
|
// 将遮罩设置到目标窗口的下方
|
|
@@ -1017,9 +1039,12 @@ class HeaderManager {
|
|
|
1017
1039
|
this._headerWindowsMap.set(headerName, new Set());
|
|
1018
1040
|
}
|
|
1019
1041
|
// 增加引用计数
|
|
1020
|
-
this._refCounts.set(headerName, this._refCounts.get(headerName) + 1);
|
|
1042
|
+
this._refCounts.set(headerName, (this._refCounts.get(headerName) || 0) + 1);
|
|
1021
1043
|
// 记录窗口和header的关系
|
|
1022
|
-
this._headerWindowsMap.get(headerName)
|
|
1044
|
+
const windowsSet = this._headerWindowsMap.get(headerName);
|
|
1045
|
+
if (windowsSet) {
|
|
1046
|
+
windowsSet.add(windowName);
|
|
1047
|
+
}
|
|
1023
1048
|
}
|
|
1024
1049
|
/**
|
|
1025
1050
|
* 显示指定窗口的header
|
|
@@ -1071,9 +1096,12 @@ class HeaderManager {
|
|
|
1071
1096
|
}
|
|
1072
1097
|
const headerName = this.getHeaderName(windowName);
|
|
1073
1098
|
// 减少引用计数
|
|
1074
|
-
const refCount = this._refCounts.get(headerName) - 1;
|
|
1099
|
+
const refCount = (this._refCounts.get(headerName) || 1) - 1;
|
|
1075
1100
|
// 移除映射关系
|
|
1076
|
-
this._headerWindowsMap.get(headerName)
|
|
1101
|
+
const windowsSet = this._headerWindowsMap.get(headerName);
|
|
1102
|
+
if (windowsSet) {
|
|
1103
|
+
windowsSet.delete(windowName);
|
|
1104
|
+
}
|
|
1077
1105
|
// 清除窗口的header信息
|
|
1078
1106
|
this._headerInfos.delete(windowName);
|
|
1079
1107
|
const header = this.getHeader(headerName);
|
|
@@ -1519,7 +1547,8 @@ class WindowGroup {
|
|
|
1519
1547
|
// 最后一个是新显示上来的窗口
|
|
1520
1548
|
if (window.type === WindowType.CloseOne) {
|
|
1521
1549
|
// 关闭上一个窗口(倒数第二个,因为最后一个是当前窗口)
|
|
1522
|
-
|
|
1550
|
+
// 修复:明确检查边界,避免数组越界
|
|
1551
|
+
if (this.size < 2) {
|
|
1523
1552
|
return;
|
|
1524
1553
|
}
|
|
1525
1554
|
const name = this._windowNames[this.size - 2];
|
|
@@ -1536,17 +1565,24 @@ class WindowGroup {
|
|
|
1536
1565
|
}
|
|
1537
1566
|
else if (window.type === WindowType.CloseAll) {
|
|
1538
1567
|
// 关闭所有窗口 从后向前依次删除
|
|
1568
|
+
// 修复:添加异常保护,避免清理异常导致数据不一致
|
|
1539
1569
|
for (let i = this.size - 2; i >= 0; i--) {
|
|
1540
1570
|
const name = this._windowNames[i];
|
|
1541
1571
|
const win = WindowManager.getWindow(name);
|
|
1542
1572
|
if (!win) {
|
|
1543
1573
|
console.error(`[BUG] 窗口【${name}】不存在,数据结构已损坏`);
|
|
1544
|
-
|
|
1574
|
+
continue; // 继续处理其他窗口,而不是直接返回
|
|
1575
|
+
}
|
|
1576
|
+
try {
|
|
1577
|
+
// 释放header
|
|
1578
|
+
HeaderManager.releaseHeader(name);
|
|
1579
|
+
win._close();
|
|
1580
|
+
WindowManager.removeWindow(name);
|
|
1581
|
+
}
|
|
1582
|
+
catch (err) {
|
|
1583
|
+
console.error(`关闭窗口【${name}】时发生异常:`, err);
|
|
1584
|
+
// 即使出错也继续处理其他窗口
|
|
1545
1585
|
}
|
|
1546
|
-
// 释放header
|
|
1547
|
-
HeaderManager.releaseHeader(name);
|
|
1548
|
-
win._close();
|
|
1549
|
-
WindowManager.removeWindow(name);
|
|
1550
1586
|
}
|
|
1551
1587
|
// 清理数组,只保留最后一个(当前窗口)
|
|
1552
1588
|
this._windowNames.splice(0, this.size - 1);
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
"name": "@gongxh/bit-ui",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "基于creator3.0+的bit-ui库",
|
|
5
|
+
"main": "./dist/bit-ui.cjs",
|
|
6
|
+
"module": "./dist/bit-ui.mjs",
|
|
7
|
+
"types": "./dist/bit-ui.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/bit-ui.cjs",
|
|
11
|
+
"import": "./dist/bit-ui.mjs",
|
|
12
|
+
"types": "./dist/bit-ui.d.ts",
|
|
13
|
+
"default": "./dist/bit-ui.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./min": {
|
|
16
|
+
"require": "./dist/bit-ui.min.cjs",
|
|
17
|
+
"import": "./dist/bit-ui.min.mjs"
|
|
18
|
+
}
|
|
14
19
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"build": "pnpm clean && rollup -c rollup.config.mjs"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"author": "bit老宫",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/gongxh0901/bit-framework.git",
|
|
32
|
+
"directory": "bit-ui"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@gongxh/bit-core": "workspace:*",
|
|
40
|
+
"fairygui-cc": "^1.2.2"
|
|
18
41
|
}
|
|
19
|
-
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
-
"author": "bit老宫",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"repository": {
|
|
26
|
-
"type": "git",
|
|
27
|
-
"url": "https://github.com/gongxh0901/bit-framework.git",
|
|
28
|
-
"directory": "bit-ui"
|
|
29
|
-
},
|
|
30
|
-
"publishConfig": {
|
|
31
|
-
"registry": "https://registry.npmjs.org/",
|
|
32
|
-
"access": "public"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"fairygui-cc": "^1.2.2",
|
|
36
|
-
"@gongxh/bit-core": "0.0.7"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"clean": "rm -rf dist",
|
|
40
|
-
"build": "pnpm clean && rollup -c rollup.config.mjs"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
42
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 bit老宫
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|