ui.create.buttons使用DocumentFragment避免多次重渲染,一系列涉及position的函数支持传入DocumentFragment元素

This commit is contained in:
shijian 2023-12-17 22:16:36 +08:00
parent 310ad8506b
commit 7cade08dd9
1 changed files with 17 additions and 25 deletions

View File

@ -25438,7 +25438,7 @@ new Promise(resolve=>{
else if(typeof arguments[i]=='boolean'){ else if(typeof arguments[i]=='boolean'){
next.animate=arguments[i]; next.animate=arguments[i];
} }
else if(get.objtype(arguments[i])=='div'){ else if(['div','fragment'].includes(get.objtype(arguments[i]))){
next.position=arguments[i]; next.position=arguments[i];
} }
else if(arguments[i]=='notBySelf'){ else if(arguments[i]=='notBySelf'){
@ -25466,7 +25466,7 @@ new Promise(resolve=>{
else if(typeof arguments[i]=='boolean'){ else if(typeof arguments[i]=='boolean'){
next.animate=arguments[i]; next.animate=arguments[i];
} }
else if(get.objtype(arguments[i])=='div'){ else if(['div','fragment'].includes(get.objtype(arguments[i]))){
next.position=arguments[i]; next.position=arguments[i];
} }
else if(arguments[i]=='notBySelf'){ else if(arguments[i]=='notBySelf'){
@ -25832,7 +25832,7 @@ new Promise(resolve=>{
else if(get.itemtype(arguments[i])=='card'){ else if(get.itemtype(arguments[i])=='card'){
next.cards=[arguments[i]]; next.cards=[arguments[i]];
} }
else if(get.objtype(arguments[i])=='div'){ else if(['div','fragment'].includes(get.objtype(arguments[i]))){
next.position=arguments[i]; next.position=arguments[i];
} }
else if(arguments[i]=='toStorage'){ else if(arguments[i]=='toStorage'){
@ -26427,7 +26427,7 @@ new Promise(resolve=>{
else if(typeof arguments[i]=='boolean'){ else if(typeof arguments[i]=='boolean'){
next.clearArena=arguments[i]; next.clearArena=arguments[i];
} }
else if(get.objtype(arguments[i])=='div'){ else if(['div','fragment'].includes(get.objtype(arguments[i]))){
next.position=arguments[i]; next.position=arguments[i];
} }
} }
@ -31074,7 +31074,7 @@ new Promise(resolve=>{
var position; var position;
for(var i=0;i<arguments.length;i++){ for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='string') node.classList.add(arguments[i]); if(typeof arguments[i]=='string') node.classList.add(arguments[i]);
else if(get.objtype(arguments[i])=='div') position=arguments[i]; else if(['div','fragment'].includes(get.objtype(arguments[i]))) position=arguments[i];
else if(typeof arguments[i]=='boolean') clone=arguments[i]; else if(typeof arguments[i]=='boolean') clone=arguments[i];
} }
node.moveTo=lib.element.Card.prototype.moveTo; node.moveTo=lib.element.Card.prototype.moveTo;
@ -31231,7 +31231,7 @@ new Promise(resolve=>{
/** /**
* @param {{}} item * @param {{}} item
* @param {keyof typeof ui.create.buttonPresets | (item: {}, type: Function, position?: HTMLDivElement, noClick?: true, button?: HTMLDivElement) => HTMLDivElement} type * @param {keyof typeof ui.create.buttonPresets | (item: {}, type: Function, position?: HTMLDivElement, noClick?: true, button?: HTMLDivElement) => HTMLDivElement} type
* @param {HTMLDivElement} [position] * @param {HTMLDivElement|DocumentFragment} [position]
* @param {true} [noClick] * @param {true} [noClick]
* @param {HTMLDivElement} [button] * @param {HTMLDivElement} [button]
*/ */
@ -32241,6 +32241,7 @@ new Promise(resolve=>{
let noTouchScroll=false; let noTouchScroll=false;
let forceButton=false; let forceButton=false;
let noForceButton=false; let noForceButton=false;
/** @type {this} */
const dialog=ui.create.div('.dialog'); const dialog=ui.create.div('.dialog');
Object.setPrototypeOf(dialog,lib.element.Dialog.prototype); Object.setPrototypeOf(dialog,lib.element.Dialog.prototype);
dialog.contentContainer=ui.create.div('.content-container',dialog); dialog.contentContainer=ui.create.div('.content-container',dialog);
@ -32287,7 +32288,7 @@ new Promise(resolve=>{
item=ui.create.caption(item,this.content); item=ui.create.caption(item,this.content);
} }
} }
else if(get.objtype(item)=='div'){ else if(['div','fragment'].includes(get.objtype(item))){
this.content.appendChild(item); this.content.appendChild(item);
} }
else if(get.itemtype(item)=='cards'){ else if(get.itemtype(item)=='cards'){
@ -40296,7 +40297,7 @@ new Promise(resolve=>{
else{ else{
node.style.transform=`rotate(${(-deg)}deg) scaleY(0)`; node.style.transform=`rotate(${(-deg)}deg) scaleY(0)`;
node.style.height=`${get.xyDistance(from,to)}px`; node.style.height=`${get.xyDistance(from,to)}px`;
if(get.objtype(arguments[1])=='div') arguments[1].appendChild(node); if(['div','fragment'].includes(get.objtype(arguments[1]))) arguments[1].appendChild(node);
else if(game.chess) ui.chess.appendChild(node); else if(game.chess) ui.chess.appendChild(node);
else ui.arena.appendChild(node); else ui.arena.appendChild(node);
ui.refresh(node); ui.refresh(node);
@ -44692,11 +44693,7 @@ new Promise(resolve=>{
str=arguments[i]; str=arguments[i];
} }
} }
else if(get.objtype(arguments[i])=='div'|| else if(['div','table','tr','td','body','fragment'].includes(get.objtype(arguments[i]))) position=arguments[i];
get.objtype(arguments[i])=='table'||
get.objtype(arguments[i])=='tr'||
get.objtype(arguments[i])=='td'||
get.objtype(arguments[i])=='body') position=arguments[i];
else if(typeof arguments[i]=='number') position2=arguments[i]; else if(typeof arguments[i]=='number') position2=arguments[i];
else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i]; else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i];
else if(typeof arguments[i]=='object') style=arguments[i]; else if(typeof arguments[i]=='object') style=arguments[i];
@ -44766,11 +44763,7 @@ new Promise(resolve=>{
tagName=arguments[i]; tagName=arguments[i];
} }
} }
else if(get.objtype(arguments[i])=='div'|| else if(['div','table','tr','td','body','fragment'].includes(get.objtype(arguments[i]))) position=arguments[i];
get.objtype(arguments[i])=='table'||
get.objtype(arguments[i])=='tr'||
get.objtype(arguments[i])=='td'||
get.objtype(arguments[i])=='body') position=arguments[i];
else if(typeof arguments[i]=='number') position2=arguments[i]; else if(typeof arguments[i]=='number') position2=arguments[i];
else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i]; else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i];
else if(typeof arguments[i]=='object') style=arguments[i]; else if(typeof arguments[i]=='object') style=arguments[i];
@ -52060,11 +52053,7 @@ new Promise(resolve=>{
} }
else row=arguments[i]; else row=arguments[i];
} }
else if(get.objtype(arguments[i])=='div'|| else if(['div','table','tr','td','body','fragment'].includes(get.objtype(arguments[i]))) position=arguments[i];
get.objtype(arguments[i])=='table'||
get.objtype(arguments[i])=='tr'||
get.objtype(arguments[i])=='td'||
get.objtype(arguments[i])=='body') position=arguments[i];
else if(typeof arguments[i]=='boolean') fixed=arguments[i]; else if(typeof arguments[i]=='boolean') fixed=arguments[i];
else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i]; else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i];
else if(typeof arguments[i]=='object') style=arguments[i]; else if(typeof arguments[i]=='object') style=arguments[i];
@ -54096,14 +54085,16 @@ new Promise(resolve=>{
}); });
} }
} }
var fragment=document.createDocumentFragment();
for(var i=0;i<list.length;i++){ for(var i=0;i<list.length;i++){
if(pre){ if(pre){
buttons.push(ui.create.prebutton(list[i],type.slice(3),position,noclick)); buttons.push(ui.create.prebutton(list[i],type.slice(3),fragment,noclick));
} }
else{ else{
buttons.push(ui.create.button(list[i],type,position,noclick)); buttons.push(ui.create.button(list[i],type,fragment,noclick));
} }
} }
if(position) position.appendChild(fragment);
return buttons; return buttons;
}, },
textbuttons:function(list,dialog,noclick){ textbuttons:function(list,dialog,noclick){
@ -60846,6 +60837,7 @@ new Promise(resolve=>{
if(Object.prototype.toString.call(obj) === '[object HTMLTableRowElement]') return 'tr'; if(Object.prototype.toString.call(obj) === '[object HTMLTableRowElement]') return 'tr';
if(Object.prototype.toString.call(obj) === '[object HTMLTableCellElement]') return 'td'; if(Object.prototype.toString.call(obj) === '[object HTMLTableCellElement]') return 'td';
if(Object.prototype.toString.call(obj) === '[object HTMLBodyElement]') return 'td'; if(Object.prototype.toString.call(obj) === '[object HTMLBodyElement]') return 'td';
if(Object.prototype.toString.call(obj) === '[object DocumentFragment]') return 'fragment';
}, },
type:(obj,method,player)=>{ type:(obj,method,player)=>{
if(typeof obj=='string') obj={name:obj}; if(typeof obj=='string') obj={name:obj};