1/* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15var NodeRenderType; 16(function (NodeRenderType) { 17 NodeRenderType[NodeRenderType["RENDER_TYPE_DISPLAY"] = 0] = "RENDER_TYPE_DISPLAY"; 18 NodeRenderType[NodeRenderType["RENDER_TYPE_TEXTURE"] = 1] = "RENDER_TYPE_TEXTURE"; 19})(NodeRenderType || (NodeRenderType = {})); 20 21class BaseNode extends __JSBaseNode__ { 22 constructor(uiContext, options) { 23 super(options); 24 if (uiContext === undefined) { 25 throw Error('Node constructor error, param uiContext error'); 26 } 27 else { 28 if (!(typeof uiContext === 'object') || !('instanceId_' in uiContext)) { 29 throw Error('Node constructor error, param uiContext is invalid'); 30 } 31 } 32 this.instanceId_ = uiContext.instanceId_; 33 } 34 getInstanceId() { 35 return this.instanceId_; 36 } 37 updateInstance(uiContext) { 38 this.instanceId_ = uiContext.instanceId_; 39 } 40} 41/* 42 * Copyright (c) 2023 Huawei Device Co., Ltd. 43 * Licensed under the Apache License, Version 2.0 (the "License"); 44 * you may not use this file except in compliance with the License. 45 * You may obtain a copy of the License at 46 * 47 * http://www.apache.org/licenses/LICENSE-2.0 48 * 49 * Unless required by applicable law or agreed to in writing, software 50 * distributed under the License is distributed on an "AS IS" BASIS, 51 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 * See the License for the specific language governing permissions and 53 * limitations under the License. 54 */ 55/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" /> 56/// <reference path="../../state_mgmt/src/lib/puv2_common/puv2_viewstack_processor.d.ts" /> 57class BuilderNode { 58 constructor(uiContext, options) { 59 let jsBuilderNode = new JSBuilderNode(uiContext, options); 60 this._JSBuilderNode = jsBuilderNode; 61 let id = Symbol('BuilderRootFrameNode'); 62 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.set(id, jsBuilderNode); 63 BuilderNodeFinalizationRegisterProxy.register(this, { name: 'BuilderRootFrameNode', idOfNode: id }); 64 } 65 update(params) { 66 this._JSBuilderNode.update(params); 67 } 68 build(builder, params, options) { 69 this._JSBuilderNode.build(builder, params, options); 70 this.nodePtr_ = this._JSBuilderNode.getNodePtr(); 71 } 72 getNodePtr() { 73 return this._JSBuilderNode.getValidNodePtr(); 74 } 75 getFrameNode() { 76 return this._JSBuilderNode.getFrameNode(); 77 } 78 getFrameNodeWithoutCheck() { 79 return this._JSBuilderNode.getFrameNodeWithoutCheck(); 80 } 81 postTouchEvent(touchEvent) { 82 __JSScopeUtil__.syncInstanceId(this._JSBuilderNode.getInstanceId()); 83 let ret = this._JSBuilderNode.postTouchEvent(touchEvent); 84 __JSScopeUtil__.restoreInstanceId(); 85 return ret; 86 } 87 dispose() { 88 this._JSBuilderNode.dispose(); 89 } 90 reuse(param) { 91 this._JSBuilderNode.reuse(param); 92 } 93 recycle() { 94 this._JSBuilderNode.recycle(); 95 } 96 updateConfiguration() { 97 this._JSBuilderNode.updateConfiguration(); 98 } 99} 100class JSBuilderNode extends BaseNode { 101 constructor(uiContext, options) { 102 super(uiContext, options); 103 this.childrenWeakrefMap_ = new Map(); 104 this.uiContext_ = uiContext; 105 this.updateFuncByElmtId = new Map(); 106 this._supportNestingBuilder = false; 107 } 108 reuse(param) { 109 this.updateStart(); 110 this.childrenWeakrefMap_.forEach((weakRefChild) => { 111 const child = weakRefChild.deref(); 112 if (child) { 113 if (child instanceof ViewPU) { 114 child.aboutToReuseInternal(param); 115 } 116 else { 117 // FIXME fix for mixed V2 - V3 Hierarchies 118 throw new Error('aboutToReuseInternal: Recycle not implemented for ViewV2, yet'); 119 } 120 } // if child 121 }); 122 this.updateEnd(); 123 } 124 recycle() { 125 this.childrenWeakrefMap_.forEach((weakRefChild) => { 126 const child = weakRefChild.deref(); 127 if (child) { 128 if (child instanceof ViewPU) { 129 child.aboutToRecycleInternal(); 130 } 131 else { 132 // FIXME fix for mixed V2 - V3 Hierarchies 133 throw new Error('aboutToRecycleInternal: Recycle not yet implemented for ViewV2'); 134 } 135 } // if child 136 }); 137 } 138 getCardId() { 139 return -1; 140 } 141 addChild(child) { 142 if (this.childrenWeakrefMap_.has(child.id__())) { 143 return false; 144 } 145 this.childrenWeakrefMap_.set(child.id__(), new WeakRef(child)); 146 return true; 147 } 148 getChildById(id) { 149 const childWeakRef = this.childrenWeakrefMap_.get(id); 150 return childWeakRef ? childWeakRef.deref() : undefined; 151 } 152 updateStateVarsOfChildByElmtId(elmtId, params) { 153 if (elmtId < 0) { 154 return; 155 } 156 let child = this.getChildById(elmtId); 157 if (!child) { 158 return; 159 } 160 child.updateStateVars(params); 161 child.updateDirtyElements(); 162 } 163 createOrGetNode(elmtId, builder) { 164 const entry = this.updateFuncByElmtId.get(elmtId); 165 if (entry === undefined) { 166 throw new Error(`fail to create node, elmtId is illegal`); 167 } 168 let updateFuncRecord = (typeof entry === 'object') ? entry : undefined; 169 if (updateFuncRecord === undefined) { 170 throw new Error(`fail to create node, the api level of app does not supported`); 171 } 172 let nodeInfo = updateFuncRecord.node; 173 if (nodeInfo === undefined) { 174 nodeInfo = builder(); 175 updateFuncRecord.node = nodeInfo; 176 } 177 return nodeInfo; 178 } 179 isObject(param) { 180 const typeName = Object.prototype.toString.call(param); 181 const objectName = `[object Object]`; 182 if (typeName === objectName) { 183 return true; 184 } 185 else { 186 return false; 187 } 188 } 189 buildWithNestingBuilder(builder, supportLazyBuild) { 190 if (this._supportNestingBuilder && this.isObject(this.params_)) { 191 this._proxyObjectParam = new Proxy(this.params_, { 192 set(target, property, val) { 193 throw Error(`@Builder : Invalid attempt to set(write to) parameter '${property.toString()}' error!`); 194 }, 195 get: (target, property, receiver) => { return this.params_?.[property]; } 196 }); 197 this.nodePtr_ = super.create(builder.builder, this._proxyObjectParam, this.updateNodeFromNative, this.updateConfiguration, supportLazyBuild); 198 } 199 else { 200 this.nodePtr_ = super.create(builder.builder, this.params_, this.updateNodeFromNative, this.updateConfiguration, supportLazyBuild); 201 } 202 } 203 build(builder, params, options) { 204 __JSScopeUtil__.syncInstanceId(this.instanceId_); 205 this._supportNestingBuilder = options?.nestingBuilderSupported ? options.nestingBuilderSupported : false; 206 const supportLazyBuild = options?.lazyBuildSupported ? options.lazyBuildSupported : false; 207 this.params_ = params; 208 this.updateFuncByElmtId.clear(); 209 this.buildWithNestingBuilder(builder, supportLazyBuild); 210 this._nativeRef = getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_); 211 if (this.frameNode_ === undefined || this.frameNode_ === null) { 212 this.frameNode_ = new BuilderRootFrameNode(this.uiContext_); 213 } 214 this.frameNode_.setNodePtr(this._nativeRef, this.nodePtr_); 215 this.frameNode_.setRenderNode(this._nativeRef); 216 this.frameNode_.setBaseNode(this); 217 __JSScopeUtil__.restoreInstanceId(); 218 } 219 update(param) { 220 __JSScopeUtil__.syncInstanceId(this.instanceId_); 221 this.updateStart(); 222 this.purgeDeletedElmtIds(); 223 this.params_ = param; 224 Array.from(this.updateFuncByElmtId.keys()).sort((a, b) => { 225 return (a < b) ? -1 : (a > b) ? 1 : 0; 226 }).forEach(elmtId => this.UpdateElement(elmtId)); 227 this.updateEnd(); 228 __JSScopeUtil__.restoreInstanceId(); 229 } 230 updateConfiguration() { 231 __JSScopeUtil__.syncInstanceId(this.instanceId_); 232 this.updateStart(); 233 this.purgeDeletedElmtIds(); 234 Array.from(this.updateFuncByElmtId.keys()).sort((a, b) => { 235 return (a < b) ? -1 : (a > b) ? 1 : 0; 236 }).forEach(elmtId => this.UpdateElement(elmtId)); 237 for (const child of this.childrenWeakrefMap_.values()) { 238 const childView = child.deref(); 239 if (childView) { 240 childView.forceCompleteRerender(true); 241 } 242 } 243 this.updateEnd(); 244 __JSScopeUtil__.restoreInstanceId(); 245 } 246 UpdateElement(elmtId) { 247 // do not process an Element that has been marked to be deleted 248 const obj = this.updateFuncByElmtId.get(elmtId); 249 const updateFunc = (typeof obj === 'object') ? obj.updateFunc : null; 250 if (typeof updateFunc === 'function') { 251 updateFunc(elmtId, /* isFirstRender */ false); 252 this.finishUpdateFunc(); 253 } 254 } 255 purgeDeletedElmtIds() { 256 UINodeRegisterProxy.obtainDeletedElmtIds(); 257 UINodeRegisterProxy.unregisterElmtIdsFromIViews(); 258 } 259 purgeDeleteElmtId(rmElmtId) { 260 const result = this.updateFuncByElmtId.delete(rmElmtId); 261 if (result) { 262 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(rmElmtId); 263 } 264 return result; 265 } 266 getFrameNode() { 267 if (this.frameNode_ !== undefined && 268 this.frameNode_ !== null && 269 this.frameNode_.getNodePtr() !== null) { 270 return this.frameNode_; 271 } 272 return null; 273 } 274 getFrameNodeWithoutCheck() { 275 return this.frameNode_; 276 } 277 observeComponentCreation(func) { 278 let elmId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 279 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmId, new WeakRef(this)); 280 try { 281 func(elmId, true); 282 } 283 catch (error) { 284 // avoid the incompatible change that move set function before updateFunc. 285 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmId); 286 throw error; 287 } 288 } 289 observeComponentCreation2(compilerAssignedUpdateFunc, classObject) { 290 const _componentName = classObject && 'name' in classObject ? Reflect.get(classObject, 'name') : 'unspecified UINode'; 291 const _popFunc = classObject && 'pop' in classObject ? classObject.pop : () => { }; 292 const updateFunc = (elmtId, isFirstRender) => { 293 __JSScopeUtil__.syncInstanceId(this.instanceId_); 294 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 295 // if V2 @Observed/@Track used anywhere in the app (there is no more fine grained criteria), 296 // enable V2 object deep observation 297 // FIXME: A @Component should only use PU or V2 state, but ReactNative dynamic viewer uses both. 298 if (ConfigureStateMgmt.instance.needsV2Observe()) { 299 // FIXME: like in V2 setting bindId_ in ObserveV2 does not work with 'stacked' 300 // update + initial render calls, like in if and ForEach case, convert to stack as well 301 ObserveV2.getObserve().startRecordDependencies(this, elmtId, true); 302 } 303 if (this._supportNestingBuilder) { 304 compilerAssignedUpdateFunc(elmtId, isFirstRender); 305 } 306 else { 307 compilerAssignedUpdateFunc(elmtId, isFirstRender, this.params_); 308 } 309 if (!isFirstRender) { 310 _popFunc(); 311 } 312 if (ConfigureStateMgmt.instance.needsV2Observe()) { 313 ObserveV2.getObserve().stopRecordDependencies(); 314 } 315 ViewStackProcessor.StopGetAccessRecording(); 316 __JSScopeUtil__.restoreInstanceId(); 317 }; 318 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 319 // needs to move set before updateFunc. 320 // make sure the key and object value exist since it will add node in attributeModifier during updateFunc. 321 this.updateFuncByElmtId.set(elmtId, { 322 updateFunc: updateFunc, 323 componentName: _componentName, 324 }); 325 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmtId, new WeakRef(this)); 326 try { 327 updateFunc(elmtId, /* is first render */ true); 328 } 329 catch (error) { 330 // avoid the incompatible change that move set function before updateFunc. 331 this.updateFuncByElmtId.delete(elmtId); 332 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmtId); 333 throw error; 334 } 335 } 336 /** 337 Partial updates for ForEach. 338 * @param elmtId ID of element. 339 * @param itemArray Array of items for use of itemGenFunc. 340 * @param itemGenFunc Item generation function to generate new elements. If index parameter is 341 * given set itemGenFuncUsesIndex to true. 342 * @param idGenFunc ID generation function to generate unique ID for each element. If index parameter is 343 * given set idGenFuncUsesIndex to true. 344 * @param itemGenFuncUsesIndex itemGenFunc optional index parameter is given or not. 345 * @param idGenFuncUsesIndex idGenFunc optional index parameter is given or not. 346 */ 347 forEachUpdateFunction(elmtId, itemArray, itemGenFunc, idGenFunc, itemGenFuncUsesIndex = false, idGenFuncUsesIndex = false) { 348 if (itemArray === null || itemArray === undefined) { 349 return; 350 } 351 if (itemGenFunc === null || itemGenFunc === undefined) { 352 return; 353 } 354 if (idGenFunc === undefined) { 355 idGenFuncUsesIndex = true; 356 // catch possible error caused by Stringify and re-throw an Error with a meaningful (!) error message 357 idGenFunc = (item, index) => { 358 try { 359 return `${index}__${JSON.stringify(item)}`; 360 } 361 catch (e) { 362 throw new Error(` ForEach id ${elmtId}: use of default id generator function not possible on provided data structure. Need to specify id generator function (ForEach 3rd parameter). Application Error!`); 363 } 364 }; 365 } 366 let diffIndexArray = []; // New indexes compared to old one. 367 let newIdArray = []; 368 let idDuplicates = []; 369 const arr = itemArray; // just to trigger a 'get' onto the array 370 // ID gen is with index. 371 if (idGenFuncUsesIndex) { 372 // Create array of new ids. 373 arr.forEach((item, indx) => { 374 newIdArray.push(idGenFunc(item, indx)); 375 }); 376 } 377 else { 378 // Create array of new ids. 379 arr.forEach((item, index) => { 380 newIdArray.push(`${itemGenFuncUsesIndex ? index + '_' : ''}` + idGenFunc(item)); 381 }); 382 } 383 // removedChildElmtIds will be filled with the elmtIds of all children and their children will be deleted in response to foreach change 384 let removedChildElmtIds = []; 385 // Set new array on C++ side. 386 // C++ returns array of indexes of newly added array items. 387 // these are indexes in new child list. 388 ForEach.setIdArray(elmtId, newIdArray, diffIndexArray, idDuplicates, removedChildElmtIds); 389 // Item gen is with index. 390 diffIndexArray.forEach((indx) => { 391 ForEach.createNewChildStart(newIdArray[indx], this); 392 if (itemGenFuncUsesIndex) { 393 itemGenFunc(arr[indx], indx); 394 } 395 else { 396 itemGenFunc(arr[indx]); 397 } 398 ForEach.createNewChildFinish(newIdArray[indx], this); 399 }); 400 // un-registers the removed child elementIDs using proxy 401 UINodeRegisterProxy.unregisterRemovedElmtsFromViewPUs(removedChildElmtIds); 402 // purging these elmtIds from state mgmt will make sure no more update function on any deleted child will be executed 403 this.purgeDeletedElmtIds(); 404 } 405 ifElseBranchUpdateFunction(branchId, branchfunc) { 406 const oldBranchid = If.getBranchId(); 407 if (branchId === oldBranchid) { 408 return; 409 } 410 // branchId identifies uniquely the if .. <1> .. else if .<2>. else .<3>.branch 411 // ifElseNode stores the most recent branch, so we can compare 412 // removedChildElmtIds will be filled with the elmtIds of all children and their children will be deleted in response to if .. else change 413 let removedChildElmtIds = new Array(); 414 If.branchId(branchId, removedChildElmtIds); 415 //un-registers the removed child elementIDs using proxy 416 UINodeRegisterProxy.unregisterRemovedElmtsFromViewPUs(removedChildElmtIds); 417 this.purgeDeletedElmtIds(); 418 branchfunc(); 419 } 420 getNodePtr() { 421 return this.nodePtr_; 422 } 423 getValidNodePtr() { 424 return this._nativeRef?.getNativeHandle(); 425 } 426 dispose() { 427 this.frameNode_?.dispose(); 428 } 429 disposeNode() { 430 super.disposeNode(); 431 this.nodePtr_ = null; 432 this._nativeRef = null; 433 this.frameNode_?.resetNodePtr(); 434 } 435 updateInstance(uiContext) { 436 this.uiContext_ = uiContext; 437 this.instanceId_ = uiContext.instanceId_; 438 if (this.frameNode_ !== undefined && this.frameNode_ !== null) { 439 this.frameNode_.updateInstance(uiContext); 440 } 441 } 442 updateNodePtr(nodePtr) { 443 if (nodePtr != this.nodePtr_) { 444 this.dispose(); 445 this.nodePtr_ = nodePtr; 446 this._nativeRef = getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_); 447 this.frameNode_.setNodePtr(this._nativeRef, this.nodePtr_); 448 } 449 } 450 updateInstanceId(instanceId) { 451 this.instanceId_ = instanceId; 452 } 453 updateNodeFromNative(instanceId, nodePtr) { 454 this.updateNodePtr(nodePtr); 455 this.updateInstanceId(instanceId); 456 } 457 observeRecycleComponentCreation(name, recycleUpdateFunc) { 458 throw new Error('custom component in @Builder used by BuilderNode does not support @Reusable'); 459 } 460} 461/* 462 * Copyright (c) 2024 Huawei Device Co., Ltd. 463 * Licensed under the Apache License, Version 2.0 (the "License"); 464 * you may not use this file except in compliance with the License. 465 * You may obtain a copy of the License at 466 * 467 * http://www.apache.org/licenses/LICENSE-2.0 468 * 469 * Unless required by applicable law or agreed to in writing, software 470 * distributed under the License is distributed on an "AS IS" BASIS, 471 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 472 * See the License for the specific language governing permissions and 473 * limitations under the License. 474 */ 475class NodeAdapter { 476 constructor() { 477 this.nodeRefs_ = new Array(); 478 this.count_ = 0; 479 this.nativeRef_ = getUINativeModule().nodeAdapter.createAdapter(); 480 this.nativePtr_ = this.nativeRef_.getNativeHandle(); 481 getUINativeModule().nodeAdapter.setCallbacks(this.nativePtr_, this, this.onAttachToNodePtr, this.onDetachFromNodePtr, this.onGetChildId !== undefined ? this.onGetChildId : undefined, this.onCreateChild !== undefined ? this.onCreateNewNodePtr : undefined, this.onDisposeChild !== undefined ? this.onDisposeNodePtr : undefined, this.onUpdateChild !== undefined ? this.onUpdateNodePtr : undefined); 482 } 483 dispose() { 484 let hostNode = this.attachedNodeRef_.deref(); 485 if (hostNode !== undefined) { 486 NodeAdapter.detachNodeAdapter(hostNode); 487 } 488 this.nativeRef_.dispose(); 489 this.nativePtr_ = null; 490 } 491 set totalNodeCount(count) { 492 if (count < 0) { 493 return; 494 } 495 getUINativeModule().nodeAdapter.setTotalNodeCount(this.nativePtr_, count); 496 this.count_ = count; 497 } 498 get totalNodeCount() { 499 return this.count_; 500 } 501 reloadAllItems() { 502 getUINativeModule().nodeAdapter.notifyItemReloaded(this.nativePtr_); 503 } 504 reloadItem(start, count) { 505 if (start < 0 || count < 0) { 506 return; 507 } 508 getUINativeModule().nodeAdapter.notifyItemChanged(this.nativePtr_, start, count); 509 } 510 removeItem(start, count) { 511 if (start < 0 || count < 0) { 512 return; 513 } 514 getUINativeModule().nodeAdapter.notifyItemRemoved(this.nativePtr_, start, count); 515 } 516 insertItem(start, count) { 517 if (start < 0 || count < 0) { 518 return; 519 } 520 getUINativeModule().nodeAdapter.notifyItemInserted(this.nativePtr_, start, count); 521 } 522 moveItem(from, to) { 523 if (from < 0 || to < 0) { 524 return; 525 } 526 getUINativeModule().nodeAdapter.notifyItemMoved(this.nativePtr_, from, to); 527 } 528 getAllAvailableItems() { 529 let result = new Array(); 530 let nodes = getUINativeModule().nodeAdapter.getAllItems(this.nativePtr_); 531 if (nodes !== undefined) { 532 nodes.forEach(node => { 533 let nodeId = node.nodeId; 534 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 535 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 536 result.push(frameNode); 537 } 538 }); 539 } 540 return result; 541 } 542 onAttachToNodePtr(target) { 543 let nodeId = target.nodeId; 544 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 545 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 546 if (frameNode === undefined) { 547 return; 548 } 549 frameNode.setAdapterRef(this); 550 this.attachedNodeRef_ = new WeakRef(frameNode); 551 if (this.onAttachToNode !== undefined) { 552 this.onAttachToNode(frameNode); 553 } 554 } 555 } 556 onDetachFromNodePtr() { 557 if (this === undefined) { 558 return; 559 } 560 if (this.onDetachFromNode !== undefined) { 561 this.onDetachFromNode(); 562 } 563 let attachedNode = this.attachedNodeRef_.deref(); 564 if (attachedNode !== undefined) { 565 attachedNode.setAdapterRef(undefined); 566 } 567 this.nodeRefs_.splice(0, this.nodeRefs_.length); 568 } 569 onCreateNewNodePtr(index) { 570 if (this.onCreateChild !== undefined) { 571 let node = this.onCreateChild(index); 572 if (!this.nodeRefs_.includes(node)) { 573 this.nodeRefs_.push(node); 574 } 575 return node.getNodePtr(); 576 } 577 return null; 578 } 579 onDisposeNodePtr(id, node) { 580 let nodeId = node.nodeId; 581 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 582 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 583 if (this.onDisposeChild !== undefined && frameNode !== undefined) { 584 this.onDisposeChild(id, frameNode); 585 let index = this.nodeRefs_.indexOf(frameNode); 586 if (index > -1) { 587 this.nodeRefs_.splice(index, 1); 588 } 589 } 590 } 591 } 592 onUpdateNodePtr(id, node) { 593 let nodeId = node.nodeId; 594 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 595 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 596 if (this.onUpdateChild !== undefined && frameNode !== undefined) { 597 this.onUpdateChild(id, frameNode); 598 } 599 } 600 } 601 static attachNodeAdapter(adapter, node) { 602 if (node === null || node === undefined) { 603 return false; 604 } 605 if (!node.isModifiable()) { 606 return false; 607 } 608 const hasAttributeProperty = Object.prototype.hasOwnProperty.call(node, 'attribute_'); 609 if (hasAttributeProperty) { 610 let frameeNode = node; 611 if (frameeNode.attribute_.allowChildCount !== undefined) { 612 const allowCount = frameeNode.attribute_.allowChildCount(); 613 if (allowCount <= 1) { 614 return false; 615 } 616 } 617 } 618 return getUINativeModule().nodeAdapter.attachNodeAdapter(adapter.nativePtr_, node.getNodePtr()); 619 } 620 static detachNodeAdapter(node) { 621 if (node === null || node === undefined) { 622 return; 623 } 624 getUINativeModule().nodeAdapter.detachNodeAdapter(node.getNodePtr()); 625 } 626} 627/* 628 * Copyright (c) 2024 Huawei Device Co., Ltd. 629 * Licensed under the Apache License, Version 2.0 (the "License"); 630 * you may not use this file except in compliance with the License. 631 * You may obtain a copy of the License at 632 * 633 * http://www.apache.org/licenses/LICENSE-2.0 634 * 635 * Unless required by applicable law or agreed to in writing, software 636 * distributed under the License is distributed on an "AS IS" BASIS, 637 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 638 * See the License for the specific language governing permissions and 639 * limitations under the License. 640 */ 641class BuilderNodeFinalizationRegisterProxy { 642 constructor() { 643 this.finalizationRegistry_ = new FinalizationRegistry((heldValue) => { 644 if (heldValue.name === 'BuilderRootFrameNode') { 645 const builderNode = BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.get(heldValue.idOfNode); 646 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.delete(heldValue.idOfNode); 647 builderNode.dispose(); 648 } 649 }); 650 } 651 static register(target, heldValue) { 652 BuilderNodeFinalizationRegisterProxy.instance_.finalizationRegistry_.register(target, heldValue); 653 } 654} 655BuilderNodeFinalizationRegisterProxy.instance_ = new BuilderNodeFinalizationRegisterProxy(); 656BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_ = new Map(); 657class FrameNodeFinalizationRegisterProxy { 658 constructor() { 659 this.finalizationRegistry_ = new FinalizationRegistry((heldValue) => { 660 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(heldValue); 661 }); 662 } 663 static register(target, heldValue) { 664 FrameNodeFinalizationRegisterProxy.instance_.finalizationRegistry_.register(target, heldValue); 665 } 666} 667FrameNodeFinalizationRegisterProxy.instance_ = new FrameNodeFinalizationRegisterProxy(); 668FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_ = new Map(); 669FrameNodeFinalizationRegisterProxy.FrameNodeInMainTree_ = new Map(); 670class NodeControllerRegisterProxy { 671} 672NodeControllerRegisterProxy.instance_ = new NodeControllerRegisterProxy(); 673NodeControllerRegisterProxy.__NodeControllerMap__ = new Map(); 674globalThis.__AddToNodeControllerMap__ = function __AddToNodeControllerMap__(containerId, nodeController) { 675 NodeControllerRegisterProxy.__NodeControllerMap__.set(containerId, nodeController); 676}; 677globalThis.__RemoveFromNodeControllerMap__ = function __RemoveFromNodeControllerMap__(containerId) { 678 let nodeController = NodeControllerRegisterProxy.__NodeControllerMap__.get(containerId); 679 nodeController._nodeContainerId.__rootNodeOfNodeController__ = undefined; 680 NodeControllerRegisterProxy.__NodeControllerMap__.delete(containerId); 681}; 682/* 683 * Copyright (c) 2023 Huawei Device Co., Ltd. 684 * Licensed under the Apache License, Version 2.0 (the "License"); 685 * you may not use this file except in compliance with the License. 686 * You may obtain a copy of the License at 687 * 688 * http://www.apache.org/licenses/LICENSE-2.0 689 * 690 * Unless required by applicable law or agreed to in writing, software 691 * distributed under the License is distributed on an "AS IS" BASIS, 692 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 693 * See the License for the specific language governing permissions and 694 * limitations under the License. 695 */ 696class __InternalField__ { 697 constructor() { 698 this._value = -1; 699 } 700} 701class NodeController { 702 constructor() { 703 this._nodeContainerId = new __InternalField__(); 704 } 705 __makeNode__(UIContext) { 706 this._nodeContainerId.__rootNodeOfNodeController__ = this.makeNode(UIContext); 707 return this._nodeContainerId.__rootNodeOfNodeController__; 708 } 709 rebuild() { 710 if (this._nodeContainerId !== undefined && this._nodeContainerId !== null && this._nodeContainerId._value >= 0) { 711 getUINativeModule().nodeContainer.rebuild(this._nodeContainerId._value); 712 } 713 } 714} 715/* 716 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 717 * Licensed under the Apache License, Version 2.0 (the "License"); 718 * you may not use this file except in compliance with the License. 719 * You may obtain a copy of the License at 720 * 721 * http://www.apache.org/licenses/LICENSE-2.0 722 * 723 * Unless required by applicable law or agreed to in writing, software 724 * distributed under the License is distributed on an "AS IS" BASIS, 725 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 726 * See the License for the specific language governing permissions and 727 * limitations under the License. 728 */ 729class FrameNode { 730 constructor(uiContext, type, options) { 731 if (uiContext === undefined) { 732 throw Error('Node constructor error, param uiContext error'); 733 } 734 else { 735 if (!(typeof uiContext === "object") || !("instanceId_" in uiContext)) { 736 throw Error('Node constructor error, param uiContext is invalid'); 737 } 738 } 739 this.instanceId_ = uiContext.instanceId_; 740 this.uiContext_ = uiContext; 741 this._nodeId = -1; 742 this._childList = new Map(); 743 if (type === 'BuilderRootFrameNode') { 744 this.renderNode_ = new RenderNode(type); 745 this.renderNode_.setFrameNode(new WeakRef(this)); 746 return; 747 } 748 if (type === 'ProxyFrameNode') { 749 return; 750 } 751 let result; 752 __JSScopeUtil__.syncInstanceId(this.instanceId_); 753 if (type === undefined || type === "CustomFrameNode") { 754 this.renderNode_ = new RenderNode('CustomFrameNode'); 755 result = getUINativeModule().frameNode.createFrameNode(this); 756 } 757 else { 758 result = getUINativeModule().frameNode.createTypedFrameNode(this, type, options); 759 } 760 __JSScopeUtil__.restoreInstanceId(); 761 this._nativeRef = result?.nativeStrongRef; 762 this._nodeId = result?.nodeId; 763 this.nodePtr_ = this._nativeRef?.getNativeHandle(); 764 this.renderNode_?.setNodePtr(result?.nativeStrongRef); 765 this.renderNode_?.setFrameNode(new WeakRef(this)); 766 if (result === undefined || this._nodeId === -1) { 767 return; 768 } 769 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(this._nodeId, new WeakRef(this)); 770 FrameNodeFinalizationRegisterProxy.register(this, this._nodeId); 771 } 772 invalidate() { 773 if (this.nodePtr_ === undefined || this.nodePtr_ === null) { 774 return; 775 } 776 getUINativeModule().frameNode.invalidate(this.nodePtr_); 777 } 778 getType() { 779 return 'CustomFrameNode'; 780 } 781 setRenderNode(nativeRef) { 782 this.renderNode_?.setNodePtr(nativeRef); 783 } 784 getRenderNode() { 785 if (this.renderNode_ !== undefined && 786 this.renderNode_ !== null && 787 this.renderNode_.getNodePtr() !== null) { 788 return this.renderNode_; 789 } 790 return null; 791 } 792 setNodePtr(nativeRef, nodePtr) { 793 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 794 this._nativeRef = nativeRef; 795 this.nodePtr_ = nodePtr ? nodePtr : this._nativeRef?.getNativeHandle(); 796 this._nodeId = getUINativeModule().frameNode.getIdByNodePtr(this.nodePtr_); 797 if (this._nodeId === -1) { 798 return; 799 } 800 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(this._nodeId, new WeakRef(this)); 801 FrameNodeFinalizationRegisterProxy.register(this, this._nodeId); 802 } 803 resetNodePtr() { 804 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 805 this._nodeId = -1; 806 this._nativeRef = null; 807 this.nodePtr_ = null; 808 this.renderNode_?.resetNodePtr(); 809 } 810 setBaseNode(baseNode) { 811 this.baseNode_ = baseNode; 812 this.renderNode_?.setBaseNode(baseNode); 813 } 814 setAdapterRef(adapter) { 815 this.nodeAdapterRef_ = adapter; 816 } 817 getNodePtr() { 818 return this.nodePtr_; 819 } 820 dispose() { 821 this.renderNode_?.dispose(); 822 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 823 this._nodeId = -1; 824 this._nativeRef = null; 825 this.nodePtr_ = null; 826 } 827 static disposeTreeRecursively(node) { 828 if (node === null) { 829 return; 830 } 831 let child = node.getFirstChildWithoutExpand(); 832 FrameNode.disposeTreeRecursively(child); 833 let sibling = node.getNextSiblingWithoutExpand(); 834 FrameNode.disposeTreeRecursively(sibling); 835 node.dispose(); 836 } 837 disposeTree() { 838 let parent = this.getParent(); 839 if (parent?.getNodeType() === "NodeContainer") { 840 getUINativeModule().nodeContainer.clean(parent?.getNodePtr()); 841 } 842 else { 843 parent?.removeChild(this); 844 } 845 FrameNode.disposeTreeRecursively(this); 846 } 847 checkType() { 848 if (!this.isModifiable()) { 849 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 850 } 851 } 852 isModifiable() { 853 return this._nativeRef !== undefined && this._nativeRef !== null; 854 } 855 convertToFrameNode(nodePtr, nodeId = -1) { 856 if (nodeId === -1) { 857 nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 858 } 859 if (nodeId !== -1 && !getUINativeModule().frameNode.isModifiable(nodePtr)) { 860 let frameNode = new ProxyFrameNode(this.uiContext_); 861 let node = getUINativeModule().nativeUtils.createNativeWeakRef(nodePtr); 862 frameNode.setNodePtr(node); 863 frameNode._nodeId = nodeId; 864 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(frameNode._nodeId, new WeakRef(frameNode)); 865 FrameNodeFinalizationRegisterProxy.register(frameNode, frameNode._nodeId); 866 return frameNode; 867 } 868 return null; 869 } 870 checkValid(node) { 871 return true; 872 } 873 appendChild(node) { 874 if (node === undefined || node === null) { 875 return; 876 } 877 if (node.getType() === 'ProxyFrameNode' || !this.checkValid(node)) { 878 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 879 } 880 __JSScopeUtil__.syncInstanceId(this.instanceId_); 881 let flag = getUINativeModule().frameNode.appendChild(this.nodePtr_, node.nodePtr_); 882 __JSScopeUtil__.restoreInstanceId(); 883 if (!flag) { 884 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 885 } 886 this._childList.set(node._nodeId, node); 887 } 888 addComponentContent(content) { 889 if (content === undefined || content === null || content.getNodePtr() === null || content.getNodePtr() == undefined) { 890 return; 891 } 892 if (!this.checkValid() || !this.isModifiable()) { 893 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 894 } 895 __JSScopeUtil__.syncInstanceId(this.instanceId_); 896 let flag = getUINativeModule().frameNode.appendChild(this.nodePtr_, content.getNodeWithoutProxy()); 897 __JSScopeUtil__.restoreInstanceId(); 898 if (!flag) { 899 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 900 } 901 else { 902 content.setAttachedParent(new WeakRef(this)); 903 } 904 } 905 removeComponentContent(content) { 906 if (content === undefined || content === null || content.getNodePtr() === null || content.getNodePtr() === undefined) { 907 return; 908 } 909 __JSScopeUtil__.syncInstanceId(this.instanceId_); 910 getUINativeModule().frameNode.removeChild(this.nodePtr_, content.getNodePtr()); 911 content.setAttachedParent(undefined); 912 __JSScopeUtil__.restoreInstanceId(); 913 } 914 insertChildAfter(child, sibling) { 915 if (child === undefined || child === null) { 916 return; 917 } 918 if (child.getType() === 'ProxyFrameNode' || !this.checkValid(child)) { 919 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 920 } 921 let flag = true; 922 __JSScopeUtil__.syncInstanceId(this.instanceId_); 923 if (sibling === undefined || sibling === null) { 924 flag = getUINativeModule().frameNode.insertChildAfter(this.nodePtr_, child.nodePtr_, null); 925 } 926 else { 927 flag = getUINativeModule().frameNode.insertChildAfter(this.nodePtr_, child.nodePtr_, sibling.getNodePtr()); 928 } 929 __JSScopeUtil__.restoreInstanceId(); 930 if (!flag) { 931 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 932 } 933 this._childList.set(child._nodeId, child); 934 } 935 removeChild(node) { 936 if (node === undefined || node === null) { 937 return; 938 } 939 __JSScopeUtil__.syncInstanceId(this.instanceId_); 940 getUINativeModule().frameNode.removeChild(this.nodePtr_, node.nodePtr_); 941 __JSScopeUtil__.restoreInstanceId(); 942 this._childList.delete(node._nodeId); 943 } 944 clearChildren() { 945 __JSScopeUtil__.syncInstanceId(this.instanceId_); 946 getUINativeModule().frameNode.clearChildren(this.nodePtr_); 947 __JSScopeUtil__.restoreInstanceId(); 948 this._childList.clear(); 949 } 950 getChild(index, isExpanded) { 951 const result = getUINativeModule().frameNode.getChild(this.getNodePtr(), index, isExpanded); 952 const nodeId = result?.nodeId; 953 if (nodeId === undefined || nodeId === -1) { 954 return null; 955 } 956 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 957 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 958 return frameNode === undefined ? null : frameNode; 959 } 960 return this.convertToFrameNode(result.nodePtr, result.nodeId); 961 } 962 getFirstChild(isExpanded) { 963 const result = getUINativeModule().frameNode.getFirst(this.getNodePtr(), isExpanded); 964 const nodeId = result?.nodeId; 965 if (nodeId === undefined || nodeId === -1) { 966 return null; 967 } 968 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 969 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 970 return frameNode === undefined ? null : frameNode; 971 } 972 return this.convertToFrameNode(result.nodePtr, result.nodeId); 973 } 974 getFirstChildWithoutExpand() { 975 const result = getUINativeModule().frameNode.getFirst(this.getNodePtr(), false); 976 const nodeId = result?.nodeId; 977 if (nodeId === undefined || nodeId === -1) { 978 return null; 979 } 980 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 981 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 982 return frameNode === undefined ? null : frameNode; 983 } 984 return this.convertToFrameNode(result.nodePtr, result.nodeId); 985 } 986 getNextSibling(isExpanded) { 987 const result = getUINativeModule().frameNode.getNextSibling(this.getNodePtr(), isExpanded); 988 const nodeId = result?.nodeId; 989 if (nodeId === undefined || nodeId === -1) { 990 return null; 991 } 992 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 993 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 994 return frameNode === undefined ? null : frameNode; 995 } 996 return this.convertToFrameNode(result.nodePtr, result.nodeId); 997 } 998 getNextSiblingWithoutExpand() { 999 const result = getUINativeModule().frameNode.getNextSibling(this.getNodePtr(), false); 1000 const nodeId = result?.nodeId; 1001 if (nodeId === undefined || nodeId === -1) { 1002 return null; 1003 } 1004 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1005 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1006 return frameNode === undefined ? null : frameNode; 1007 } 1008 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1009 } 1010 getPreviousSibling(isExpanded) { 1011 const result = getUINativeModule().frameNode.getPreviousSibling(this.getNodePtr(), isExpanded); 1012 const nodeId = result?.nodeId; 1013 if (nodeId === undefined || nodeId === -1) { 1014 return null; 1015 } 1016 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1017 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1018 return frameNode === undefined ? null : frameNode; 1019 } 1020 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1021 } 1022 getParent() { 1023 const result = getUINativeModule().frameNode.getParent(this.getNodePtr()); 1024 const nodeId = result?.nodeId; 1025 if (nodeId === undefined || nodeId === -1) { 1026 return null; 1027 } 1028 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1029 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1030 return frameNode === undefined ? null : frameNode; 1031 } 1032 return this.convertToFrameNode(result.nodePtr, result.nodeId); 1033 } 1034 getChildrenCount(isExpanded) { 1035 return getUINativeModule().frameNode.getChildrenCount(this.nodePtr_, isExpanded); 1036 } 1037 getPositionToParent() { 1038 const position = getUINativeModule().frameNode.getPositionToParent(this.getNodePtr()); 1039 return { x: position[0], y: position[1] }; 1040 } 1041 getPositionToScreen() { 1042 const position = getUINativeModule().frameNode.getPositionToScreen(this.getNodePtr()); 1043 return { x: position[0], y: position[1] }; 1044 } 1045 getPositionToWindow() { 1046 const position = getUINativeModule().frameNode.getPositionToWindow(this.getNodePtr()); 1047 return { x: position[0], y: position[1] }; 1048 } 1049 getPositionToParentWithTransform() { 1050 const position = getUINativeModule().frameNode.getPositionToParentWithTransform(this.getNodePtr()); 1051 return { x: position[0], y: position[1] }; 1052 } 1053 getPositionToScreenWithTransform() { 1054 const position = getUINativeModule().frameNode.getPositionToScreenWithTransform(this.getNodePtr()); 1055 return { x: position[0], y: position[1] }; 1056 } 1057 getPositionToWindowWithTransform() { 1058 const position = getUINativeModule().frameNode.getPositionToWindowWithTransform(this.getNodePtr()); 1059 return { x: position[0], y: position[1] }; 1060 } 1061 getMeasuredSize() { 1062 const size = getUINativeModule().frameNode.getMeasuredSize(this.getNodePtr()); 1063 return { width: size[0], height: size[1] }; 1064 } 1065 getLayoutPosition() { 1066 const position = getUINativeModule().frameNode.getLayoutPosition(this.getNodePtr()); 1067 return { x: position[0], y: position[1] }; 1068 } 1069 getUserConfigBorderWidth() { 1070 const borderWidth = getUINativeModule().frameNode.getConfigBorderWidth(this.getNodePtr()); 1071 return { 1072 top: new LengthMetrics(borderWidth[0], borderWidth[1]), 1073 right: new LengthMetrics(borderWidth[2], borderWidth[3]), 1074 bottom: new LengthMetrics(borderWidth[4], borderWidth[5]), 1075 left: new LengthMetrics(borderWidth[6], borderWidth[7]) 1076 }; 1077 } 1078 getUserConfigPadding() { 1079 const borderWidth = getUINativeModule().frameNode.getConfigPadding(this.getNodePtr()); 1080 return { 1081 top: new LengthMetrics(borderWidth[0], borderWidth[1]), 1082 right: new LengthMetrics(borderWidth[2], borderWidth[3]), 1083 bottom: new LengthMetrics(borderWidth[4], borderWidth[5]), 1084 left: new LengthMetrics(borderWidth[6], borderWidth[7]) 1085 }; 1086 } 1087 getUserConfigMargin() { 1088 const margin = getUINativeModule().frameNode.getConfigMargin(this.getNodePtr()); 1089 return { 1090 top: new LengthMetrics(margin[0], margin[1]), 1091 right: new LengthMetrics(margin[2], margin[3]), 1092 bottom: new LengthMetrics(margin[4], margin[5]), 1093 left: new LengthMetrics(margin[6], margin[7]) 1094 }; 1095 } 1096 getUserConfigSize() { 1097 const size = getUINativeModule().frameNode.getConfigSize(this.getNodePtr()); 1098 return { 1099 width: new LengthMetrics(size[0], size[1]), 1100 height: new LengthMetrics(size[2], size[3]) 1101 }; 1102 } 1103 getId() { 1104 return getUINativeModule().frameNode.getId(this.getNodePtr()); 1105 } 1106 getUniqueId() { 1107 return getUINativeModule().frameNode.getIdByNodePtr(this.getNodePtr()); 1108 } 1109 getNodeType() { 1110 return getUINativeModule().frameNode.getNodeType(this.getNodePtr()); 1111 } 1112 getOpacity() { 1113 return getUINativeModule().frameNode.getOpacity(this.getNodePtr()); 1114 } 1115 isVisible() { 1116 return getUINativeModule().frameNode.isVisible(this.getNodePtr()); 1117 } 1118 isClipToFrame() { 1119 return getUINativeModule().frameNode.isClipToFrame(this.getNodePtr()); 1120 } 1121 isAttached() { 1122 return getUINativeModule().frameNode.isAttached(this.getNodePtr()); 1123 } 1124 getInspectorInfo() { 1125 const inspectorInfoStr = getUINativeModule().frameNode.getInspectorInfo(this.getNodePtr()); 1126 const inspectorInfo = JSON.parse(inspectorInfoStr); 1127 return inspectorInfo; 1128 } 1129 getCustomProperty(key) { 1130 if (key === undefined) { 1131 return undefined; 1132 } 1133 let value = __getCustomProperty__(this._nodeId, key); 1134 if (value === undefined) { 1135 const valueStr = getUINativeModule().frameNode.getCustomPropertyCapiByKey(this.getNodePtr(), key); 1136 value = valueStr === undefined ? undefined : valueStr; 1137 } 1138 return value; 1139 } 1140 setMeasuredSize(size) { 1141 getUINativeModule().frameNode.setMeasuredSize(this.getNodePtr(), Math.max(size.width, 0), Math.max(size.height, 0)); 1142 } 1143 setLayoutPosition(position) { 1144 getUINativeModule().frameNode.setLayoutPosition(this.getNodePtr(), position.x, position.y); 1145 } 1146 measure(constraint) { 1147 const minSize = constraint.minSize; 1148 const maxSize = constraint.maxSize; 1149 const percentReference = constraint.percentReference; 1150 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1151 getUINativeModule().frameNode.measureNode(this.getNodePtr(), minSize.width, minSize.height, maxSize.width, maxSize.height, percentReference.width, percentReference.height); 1152 __JSScopeUtil__.restoreInstanceId(); 1153 } 1154 layout(position) { 1155 getUINativeModule().frameNode.layoutNode(this.getNodePtr(), position.x, position.y); 1156 } 1157 setNeedsLayout() { 1158 getUINativeModule().frameNode.setNeedsLayout(this.getNodePtr()); 1159 } 1160 get commonAttribute() { 1161 if (this._commonAttribute === undefined) { 1162 this._commonAttribute = new ArkComponent(this.nodePtr_, ModifierType.FRAME_NODE); 1163 } 1164 this._commonAttribute.setNodePtr(this.nodePtr_); 1165 this._commonAttribute.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1166 return this._commonAttribute; 1167 } 1168 get commonEvent() { 1169 let node = this.getNodePtr(); 1170 if (this._commonEvent === undefined) { 1171 this._commonEvent = new UICommonEvent(node); 1172 } 1173 this._commonEvent.setNodePtr(node); 1174 this._commonEvent.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1175 return this._commonEvent; 1176 } 1177 get gestureEvent() { 1178 if (this._gestureEvent === undefined) { 1179 this._gestureEvent = new UIGestureEvent(); 1180 this._gestureEvent.setNodePtr(this.nodePtr_); 1181 let weakPtr = getUINativeModule().nativeUtils.createNativeWeakRef(this.nodePtr_); 1182 this._gestureEvent.setWeakNodePtr(weakPtr); 1183 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1184 this._gestureEvent.registerFrameNodeDeletedCallback(this.nodePtr_); 1185 __JSScopeUtil__.restoreInstanceId(); 1186 } 1187 return this._gestureEvent; 1188 } 1189 updateInstance(uiContext) { 1190 this.uiContext_ = uiContext; 1191 this.instanceId_ = uiContext.instanceId_; 1192 } 1193} 1194class ImmutableFrameNode extends FrameNode { 1195 isModifiable() { 1196 return false; 1197 } 1198 invalidate() { 1199 return; 1200 } 1201 appendChild(node) { 1202 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1203 } 1204 insertChildAfter(child, sibling) { 1205 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1206 } 1207 removeChild(node) { 1208 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1209 } 1210 clearChildren() { 1211 throw { message: 'The FrameNode is not modifiable.', code: 100021 }; 1212 } 1213 get commonAttribute() { 1214 if (this._commonAttribute === undefined) { 1215 this._commonAttribute = new ArkComponent(undefined, ModifierType.FRAME_NODE); 1216 } 1217 this._commonAttribute.setNodePtr(undefined); 1218 return this._commonAttribute; 1219 } 1220} 1221class BuilderRootFrameNode extends ImmutableFrameNode { 1222 constructor(uiContext, type = 'BuilderRootFrameNode') { 1223 super(uiContext, type); 1224 } 1225 getType() { 1226 return 'BuilderRootFrameNode'; 1227 } 1228} 1229class ProxyFrameNode extends ImmutableFrameNode { 1230 constructor(uiContext, type = 'ProxyFrameNode') { 1231 super(uiContext, type); 1232 } 1233 setNodePtr(nativeRef) { 1234 this._nativeRef = nativeRef; 1235 this.nodePtr_ = this._nativeRef.getNativeHandle(); 1236 } 1237 getType() { 1238 return 'ProxyFrameNode'; 1239 } 1240 getRenderNode() { 1241 return null; 1242 } 1243 getNodePtr() { 1244 if (this._nativeRef === undefined || this._nativeRef === null || this._nativeRef.invalid()) { 1245 return null; 1246 } 1247 return this.nodePtr_; 1248 } 1249 dispose() { 1250 this.renderNode_?.dispose(); 1251 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.delete(this._nodeId); 1252 this._nodeId = -1; 1253 this._nativeRef = undefined; 1254 this.nodePtr_ = undefined; 1255 } 1256} 1257class FrameNodeUtils { 1258 static searchNodeInRegisterProxy(nodePtr) { 1259 let nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 1260 if (nodeId === -1) { 1261 return null; 1262 } 1263 if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { 1264 let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId).deref(); 1265 return frameNode === undefined ? null : frameNode; 1266 } 1267 return null; 1268 } 1269 static createFrameNode(uiContext, nodePtr) { 1270 let nodeId = getUINativeModule().frameNode.getIdByNodePtr(nodePtr); 1271 if (nodeId !== -1 && !getUINativeModule().frameNode.isModifiable(nodePtr)) { 1272 let frameNode = new ProxyFrameNode(uiContext); 1273 let node = getUINativeModule().nativeUtils.createNativeWeakRef(nodePtr); 1274 frameNode.setNodePtr(node); 1275 frameNode._nodeId = nodeId; 1276 FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.set(nodeId, new WeakRef(frameNode)); 1277 FrameNodeFinalizationRegisterProxy.register(frameNode, nodeId); 1278 return frameNode; 1279 } 1280 return null; 1281 } 1282} 1283class TypedFrameNode extends FrameNode { 1284 constructor(uiContext, type, attrCreator, options) { 1285 super(uiContext, type, options); 1286 this.attrCreator_ = attrCreator; 1287 } 1288 initialize(...args) { 1289 return this.attribute.initialize(args); 1290 } 1291 get attribute() { 1292 if (this.attribute_ === undefined) { 1293 this.attribute_ = this.attrCreator_(this.nodePtr_, ModifierType.FRAME_NODE); 1294 } 1295 this.attribute_.setNodePtr(this.nodePtr_); 1296 this.attribute_.setInstanceId((this.uiContext_ === undefined || this.uiContext_ === null) ? -1 : this.uiContext_.instanceId_); 1297 return this.attribute_; 1298 } 1299 checkValid(node) { 1300 if (this.attribute_ === undefined) { 1301 this.attribute_ = this.attrCreator_(this.nodePtr_, ModifierType.FRAME_NODE); 1302 } 1303 if (this.attribute_.allowChildCount !== undefined) { 1304 const allowCount = this.attribute_.allowChildCount(); 1305 if (this.getChildrenCount() >= allowCount) { 1306 return false; 1307 } 1308 } 1309 if (this.attribute_.allowChildTypes !== undefined && node !== undefined) { 1310 const childType = node.getNodeType(); 1311 const allowTypes = this.attribute_.allowChildTypes(); 1312 let isValid = false; 1313 allowTypes.forEach((nodeType) => { 1314 if (nodeType === childType) { 1315 isValid = true; 1316 } 1317 }); 1318 return isValid; 1319 } 1320 return true; 1321 } 1322} 1323const __creatorMap__ = new Map([ 1324 ['Text', (context) => { 1325 return new TypedFrameNode(context, 'Text', (node, type) => { 1326 return new ArkTextComponent(node, type); 1327 }); 1328 }], 1329 ['Column', (context) => { 1330 return new TypedFrameNode(context, 'Column', (node, type) => { 1331 return new ArkColumnComponent(node, type); 1332 }); 1333 }], 1334 ['Row', (context) => { 1335 return new TypedFrameNode(context, 'Row', (node, type) => { 1336 return new ArkRowComponent(node, type); 1337 }); 1338 }], 1339 ['Stack', (context) => { 1340 return new TypedFrameNode(context, 'Stack', (node, type) => { 1341 return new ArkStackComponent(node, type); 1342 }); 1343 }], 1344 ['GridRow', (context) => { 1345 let node = new TypedFrameNode(context, 'GridRow', (node, type) => { 1346 return new ArkGridRowComponent(node, type); 1347 }); 1348 node.initialize(); 1349 return node; 1350 }], 1351 ['TextInput', (context) => { 1352 return new TypedFrameNode(context, 'TextInput', (node, type) => { 1353 return new ArkTextInputComponent(node, type); 1354 }); 1355 }], 1356 ['GridCol', (context) => { 1357 let node = new TypedFrameNode(context, 'GridCol', (node, type) => { 1358 return new ArkGridColComponent(node, type); 1359 }); 1360 node.initialize(); 1361 return node; 1362 }], 1363 ['Blank', (context) => { 1364 return new TypedFrameNode(context, 'Blank', (node, type) => { 1365 return new ArkBlankComponent(node, type); 1366 }); 1367 }], 1368 ['Image', (context) => { 1369 return new TypedFrameNode(context, 'Image', (node, type) => { 1370 return new ArkImageComponent(node, type); 1371 }); 1372 }], 1373 ['Flex', (context) => { 1374 return new TypedFrameNode(context, 'Flex', (node, type) => { 1375 return new ArkFlexComponent(node, type); 1376 }); 1377 }], 1378 ['Swiper', (context) => { 1379 return new TypedFrameNode(context, 'Swiper', (node, type) => { 1380 return new ArkSwiperComponent(node, type); 1381 }); 1382 }], 1383 ['Progress', (context) => { 1384 return new TypedFrameNode(context, 'Progress', (node, type) => { 1385 return new ArkProgressComponent(node, type); 1386 }); 1387 }], 1388 ['Scroll', (context) => { 1389 return new TypedFrameNode(context, 'Scroll', (node, type) => { 1390 return new ArkScrollComponent(node, type); 1391 }); 1392 }], 1393 ['RelativeContainer', (context) => { 1394 return new TypedFrameNode(context, 'RelativeContainer', (node, type) => { 1395 return new ArkRelativeContainerComponent(node, type); 1396 }); 1397 }], 1398 ['List', (context) => { 1399 return new TypedFrameNode(context, 'List', (node, type) => { 1400 return new ArkListComponent(node, type); 1401 }); 1402 }], 1403 ['ListItem', (context) => { 1404 return new TypedFrameNode(context, 'ListItem', (node, type) => { 1405 return new ArkListItemComponent(node, type); 1406 }); 1407 }], 1408 ['Divider', (context) => { 1409 return new TypedFrameNode(context, 'Divider', (node, type) => { 1410 return new ArkDividerComponent(node, type); 1411 }); 1412 }], 1413 ['LoadingProgress', (context) => { 1414 return new TypedFrameNode(context, 'LoadingProgress', (node, type) => { 1415 return new ArkLoadingProgressComponent(node, type); 1416 }); 1417 }], 1418 ['Search', (context) => { 1419 return new TypedFrameNode(context, 'Search', (node, type) => { 1420 return new ArkSearchComponent(node, type); 1421 }); 1422 }], 1423 ['Button', (context) => { 1424 return new TypedFrameNode(context, 'Button', (node, type) => { 1425 return new ArkButtonComponent(node, type); 1426 }); 1427 }], 1428 ['XComponent', (context, options) => { 1429 return new TypedFrameNode(context, 'XComponent', (node, type) => { 1430 return new ArkXComponentComponent(node, type); 1431 }, options); 1432 }], 1433 ['ListItemGroup', (context) => { 1434 return new TypedFrameNode(context, 'ListItemGroup', (node, type) => { 1435 return new ArkListItemGroupComponent(node, type); 1436 }); 1437 }], 1438 ['WaterFlow', (context) => { 1439 return new TypedFrameNode(context, 'WaterFlow', (node, type) => { 1440 return new ArkWaterFlowComponent(node, type); 1441 }); 1442 }], 1443 ['SymbolGlyph', (context)=> { 1444 return new TypedFrameNode(context, 'SymbolGlyph', (node, type) => { 1445 return new ArkSymbolGlyphComponent(node, type); 1446 }); 1447 }], 1448 ['FlowItem', (context) => { 1449 return new TypedFrameNode(context, 'FlowItem', (node, type) => { 1450 return new ArkFlowItemComponent(node, type); 1451 }); 1452 }], 1453 ['Marquee', (context) => { 1454 return new TypedFrameNode(context, 'Marquee', (node, type) => { 1455 return new ArkMarqueeComponent(node, type); 1456 }); 1457 }], 1458 ['TextArea', (context) => { 1459 return new TypedFrameNode(context, 'TextArea', (node, type) => { 1460 return new ArkTextAreaComponent(node, type); 1461 }); 1462 }], 1463 ['QRCode', (context) => { 1464 return new TypedFrameNode(context, 'QRCode', (node, type) => { 1465 return new ArkQRCodeComponent(node, type); 1466 }); 1467 }], 1468 ['Badge', (context) => { 1469 return new TypedFrameNode(context, 'Badge', (node, type) => { 1470 return new ArkBadgeComponent(node, type); 1471 }); 1472 }], 1473 ['Grid', (context) => { 1474 return new TypedFrameNode(context, 'Grid', (node, type) => { 1475 return new ArkGridComponent(node, type); 1476 }); 1477 }], 1478 ['GridItem', (context) => { 1479 return new TypedFrameNode(context, 'GridItem', (node, type) => { 1480 return new ArkGridItemComponent(node, type); 1481 }); 1482 }], 1483 ['TextClock', (context) => { 1484 return new TypedFrameNode(context, 'TextClock', (node, type) => { 1485 return new ArkTextClockComponent(node, type); 1486 }); 1487 }], 1488 ['TextTimer', (context) => { 1489 return new TypedFrameNode(context, 'TextTimer', (node, type) => { 1490 return new ArkTextTimerComponent(node, type); 1491 }); 1492 }], 1493]); 1494class typeNode { 1495 static createNode(context, type, options) { 1496 let creator = __creatorMap__.get(type); 1497 if (creator === undefined) { 1498 return undefined; 1499 } 1500 return creator(context, options); 1501 } 1502} 1503/* 1504 * Copyright (c) 2023 Huawei Device Co., Ltd. 1505 * Licensed under the Apache License, Version 2.0 (the "License"); 1506 * you may not use this file except in compliance with the License. 1507 * You may obtain a copy of the License at 1508 * 1509 * http://www.apache.org/licenses/LICENSE-2.0 1510 * 1511 * Unless required by applicable law or agreed to in writing, software 1512 * distributed under the License is distributed on an "AS IS" BASIS, 1513 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1514 * See the License for the specific language governing permissions and 1515 * limitations under the License. 1516 */ 1517var BorderStyle; 1518(function (BorderStyle) { 1519 BorderStyle[BorderStyle["SOLID"] = 0] = "SOLID"; 1520 BorderStyle[BorderStyle["DASHED"] = 1] = "DASHED"; 1521 BorderStyle[BorderStyle["DOTTED"] = 2] = "DOTTED"; 1522 BorderStyle[BorderStyle["NONE"] = 3] = "NONE"; 1523})(BorderStyle || (BorderStyle = {})); 1524var LengthUnit; 1525(function (LengthUnit) { 1526 LengthUnit[LengthUnit["PX"] = 0] = "PX"; 1527 LengthUnit[LengthUnit["VP"] = 1] = "VP"; 1528 LengthUnit[LengthUnit["FP"] = 2] = "FP"; 1529 LengthUnit[LengthUnit["PERCENT"] = 3] = "PERCENT"; 1530 LengthUnit[LengthUnit["LPX"] = 4] = "LPX"; 1531})(LengthUnit || (LengthUnit = {})); 1532var LengthMetricsUnit; 1533(function (LengthMetricsUnit) { 1534 LengthMetricsUnit[LengthMetricsUnit["DEFAULT"] = 0] = "DEFAULT"; 1535 LengthMetricsUnit[LengthMetricsUnit["PX"] = 1] = "PX"; 1536})(LengthMetricsUnit || (LengthMetricsUnit = {})); 1537class LengthMetrics { 1538 constructor(value, unit) { 1539 if (unit in LengthUnit) { 1540 this.unit = unit; 1541 this.value = value; 1542 } else { 1543 1544 this.unit = LengthUnit.VP; 1545 this.value = unit === undefined ? value : 0; 1546 } 1547 } 1548 static px(value) { 1549 return new LengthMetrics(value, LengthUnit.PX); 1550 } 1551 static vp(value) { 1552 return new LengthMetrics(value, LengthUnit.VP); 1553 } 1554 static fp(value) { 1555 return new LengthMetrics(value, LengthUnit.FP); 1556 } 1557 static percent(value) { 1558 return new LengthMetrics(value, LengthUnit.PERCENT); 1559 } 1560 static lpx(value) { 1561 return new LengthMetrics(value, LengthUnit.LPX); 1562 } 1563 static resource(res) { 1564 let length = getUINativeModule().nativeUtils.resoureToLengthMetrics(res); 1565 return new LengthMetrics(length[0], length[1]); 1566 } 1567} 1568const MAX_CHANNEL_VALUE = 0xFF; 1569const MAX_ALPHA_VALUE = 1; 1570const ERROR_CODE_RESOURCE_GET_FAILED = 180003; 1571const ERROR_CODE_COLOR_PARAMETER_INCORRECT = 401; 1572class ColorMetrics { 1573 constructor(red, green, blue, alpha = MAX_CHANNEL_VALUE) { 1574 this.red_ = ColorMetrics.clamp(red); 1575 this.green_ = ColorMetrics.clamp(green); 1576 this.blue_ = ColorMetrics.clamp(blue); 1577 this.alpha_ = ColorMetrics.clamp(alpha); 1578 } 1579 static clamp(value) { 1580 return Math.min(Math.max(value, 0), MAX_CHANNEL_VALUE); 1581 } 1582 toNumeric() { 1583 return (this.alpha_ << 24) + (this.red_ << 16) + (this.green_ << 8) + this.blue_; 1584 } 1585 static numeric(value) { 1586 const red = (value >> 16) & 0x000000FF; 1587 const green = (value >> 8) & 0x000000FF; 1588 const blue = value & 0x000000FF; 1589 const alpha = (value >> 24) & 0x000000FF; 1590 if (alpha === 0) { 1591 return new ColorMetrics(red, green, blue); 1592 } 1593 return new ColorMetrics(red, green, blue, alpha); 1594 } 1595 static rgba(red, green, blue, alpha = MAX_ALPHA_VALUE) { 1596 return new ColorMetrics(red, green, blue, alpha * MAX_CHANNEL_VALUE); 1597 } 1598 static rgbOrRGBA(format) { 1599 const rgbPattern = /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i; 1600 const rgbaPattern = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+(\.\d+)?)\s*\)$/i; 1601 const rgbMatch = rgbPattern.exec(format); 1602 const rgbaMatch = rgbaPattern.exec(format); 1603 if (rgbMatch) { 1604 const [, red, green, blue] = rgbMatch; 1605 return new ColorMetrics(Number.parseInt(red, 10), Number.parseInt(green, 10), Number.parseInt(blue, 10)); 1606 } 1607 else if (rgbaMatch) { 1608 const [, red, green, blue, alpha] = rgbaMatch; 1609 return new ColorMetrics(Number.parseInt(red, 10), Number.parseInt(green, 10), Number.parseInt(blue, 10), Number.parseFloat(alpha) * MAX_CHANNEL_VALUE); 1610 } 1611 else { 1612 const error = new Error('Parameter error. The format of the input color string is not RGB or RGBA.'); 1613 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1614 throw error; 1615 } 1616 } 1617 static resourceColor(color) { 1618 if (color === undefined || color === null) { 1619 const error = new Error('Parameter error. The type of the input color parameter is not ResourceColor.'); 1620 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1621 throw error; 1622 } 1623 let chanels = []; 1624 if (typeof color === 'object') { 1625 chanels = getUINativeModule().nativeUtils.parseResourceColor(color); 1626 if (chanels === undefined) { 1627 const error = new Error('Failed to obtain the color resource.'); 1628 error.code = ERROR_CODE_RESOURCE_GET_FAILED; 1629 throw error; 1630 } 1631 const red = chanels[0]; 1632 const green = chanels[1]; 1633 const blue = chanels[2]; 1634 const alpha = chanels[3]; 1635 return new ColorMetrics(red, green, blue, alpha); 1636 } 1637 else if (typeof color === 'number') { 1638 return ColorMetrics.numeric(color); 1639 } 1640 else if (typeof color === 'string') { 1641 if (ColorMetrics.isHexFormat(color)) { 1642 return ColorMetrics.hex(color); 1643 } 1644 else { 1645 return ColorMetrics.rgbOrRGBA(color); 1646 } 1647 } 1648 else { 1649 const error = new Error('Parameter error. The type of the input color parameter is not ResourceColor.'); 1650 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1651 throw error; 1652 } 1653 } 1654 static isHexFormat(format) { 1655 return /#(([0-9A-Fa-f]{3})|([0-9A-Fa-f]{6})|([0-9A-Fa-f]{4})|([0-9A-Fa-f]{8}))/.test(format); 1656 } 1657 static hex(hexFormat) { 1658 let r = 0; 1659 let g = 0; 1660 let b = 0; 1661 let a = 255; 1662 if (hexFormat.length === 4) { 1663 r = parseInt(hexFormat.slice(1, 2).repeat(2), 16); 1664 g = parseInt(hexFormat.slice(2, 3).repeat(2), 16); 1665 b = parseInt(hexFormat.slice(3).repeat(2), 16); 1666 } 1667 else if (hexFormat.length === 7) { 1668 r = parseInt(hexFormat.slice(1, 3), 16); 1669 g = parseInt(hexFormat.slice(3, 5), 16); 1670 b = parseInt(hexFormat.slice(5), 16); 1671 } 1672 else if (hexFormat.length === 5) { 1673 a = parseInt(hexFormat.slice(1, 2).repeat(2), 16); 1674 r = parseInt(hexFormat.slice(2, 3).repeat(2), 16); 1675 g = parseInt(hexFormat.slice(3, 4).repeat(2), 16); 1676 b = parseInt(hexFormat.slice(4).repeat(2), 16); 1677 } 1678 else if (hexFormat.length === 9) { 1679 a = parseInt(hexFormat.slice(1, 3), 16); 1680 r = parseInt(hexFormat.slice(3, 5), 16); 1681 g = parseInt(hexFormat.slice(5, 7), 16); 1682 b = parseInt(hexFormat.slice(7), 16); 1683 } 1684 return new ColorMetrics(r, g, b, a); 1685 } 1686 blendColor(overlayColor) { 1687 if (overlayColor === undefined || overlayColor === null) { 1688 const error = new Error('Parameter error. The type of the input parameter is not ColorMetrics.'); 1689 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1690 throw error; 1691 } 1692 const chanels = getUINativeModule().nativeUtils.blendColor(this.toNumeric(), overlayColor.toNumeric()); 1693 if (chanels === undefined) { 1694 const error = new Error('Parameter error. The type of the input parameter is not ColorMetrics.'); 1695 error.code = ERROR_CODE_COLOR_PARAMETER_INCORRECT; 1696 throw error; 1697 } 1698 const red = chanels[0]; 1699 const green = chanels[1]; 1700 const blue = chanels[2]; 1701 const alpha = chanels[3]; 1702 return new ColorMetrics(red, green, blue, alpha); 1703 } 1704 get color() { 1705 return `rgba(${this.red_}, ${this.green_}, ${this.blue_}, ${this.alpha_ / MAX_CHANNEL_VALUE})`; 1706 } 1707 get red() { 1708 return this.red_; 1709 } 1710 get green() { 1711 return this.green_; 1712 } 1713 get blue() { 1714 return this.blue_; 1715 } 1716 get alpha() { 1717 return this.alpha_; 1718 } 1719} 1720class BaseShape { 1721 constructor() { 1722 this.rect = null; 1723 this.roundRect = null; 1724 this.circle = null; 1725 this.oval = null; 1726 this.path = null; 1727 } 1728 setRectShape(rect) { 1729 this.rect = rect; 1730 this.roundRect = null; 1731 this.circle = null; 1732 this.oval = null; 1733 this.path = null; 1734 } 1735 setRoundRectShape(roundRect) { 1736 this.roundRect = roundRect; 1737 this.rect = null; 1738 this.circle = null; 1739 this.oval = null; 1740 this.path = null; 1741 } 1742 setCircleShape(circle) { 1743 this.circle = circle; 1744 this.rect = null; 1745 this.roundRect = null; 1746 this.oval = null; 1747 this.path = null; 1748 } 1749 setOvalShape(oval) { 1750 this.oval = oval; 1751 this.rect = null; 1752 this.circle = null; 1753 this.roundRect = null; 1754 this.path = null; 1755 } 1756 setCommandPath(path) { 1757 this.path = path; 1758 this.oval = null; 1759 this.rect = null; 1760 this.circle = null; 1761 this.roundRect = null; 1762 } 1763} 1764class ShapeClip extends BaseShape { 1765} 1766class ShapeMask extends BaseShape { 1767 constructor(...args) { 1768 super(...args); 1769 this.fillColor = 0XFF000000; 1770 this.strokeColor = 0XFF000000; 1771 this.strokeWidth = 0; 1772 } 1773} 1774class RenderNode { 1775 constructor(type) { 1776 this.nodePtr = null; 1777 this.childrenList = []; 1778 this.parentRenderNode = null; 1779 this.backgroundColorValue = 0; 1780 this.apiTargetVersion = getUINativeModule().common.getApiTargetVersion(); 1781 this.clipToFrameValue = true; 1782 if (this.apiTargetVersion && this.apiTargetVersion < 12) { 1783 this.clipToFrameValue = false; 1784 } 1785 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 1786 this.opacityValue = 1.0; 1787 this.pivotValue = { x: 0.5, y: 0.5 }; 1788 this.rotationValue = { x: 0, y: 0, z: 0 }; 1789 this.scaleValue = { x: 1.0, y: 1.0 }; 1790 this.shadowColorValue = 0; 1791 this.shadowOffsetValue = { x: 0, y: 0 }; 1792 this.labelValue = ''; 1793 this.shadowAlphaValue = 0; 1794 this.shadowElevationValue = 0; 1795 this.shadowRadiusValue = 0; 1796 this.transformValue = [1, 0, 0, 0, 1797 0, 1, 0, 0, 1798 0, 0, 1, 0, 1799 0, 0, 0, 1]; 1800 this.translationValue = { x: 0, y: 0 }; 1801 this.lengthMetricsUnitValue = LengthMetricsUnit.DEFAULT; 1802 this.markNodeGroupValue = false; 1803 if (type === 'BuilderRootFrameNode' || type === 'CustomFrameNode') { 1804 return; 1805 } 1806 this._nativeRef = getUINativeModule().renderNode.createRenderNode(this); 1807 this.nodePtr = this._nativeRef?.getNativeHandle(); 1808 if (this.apiTargetVersion && this.apiTargetVersion < 12) { 1809 this.clipToFrame = false; 1810 } else { 1811 this.clipToFrame = true; 1812 } 1813 } 1814 set backgroundColor(color) { 1815 this.backgroundColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 1816 getUINativeModule().renderNode.setBackgroundColor(this.nodePtr, this.backgroundColorValue); 1817 } 1818 set clipToFrame(useClip) { 1819 this.clipToFrameValue = this.checkUndefinedOrNullWithDefaultValue(useClip, true); 1820 getUINativeModule().renderNode.setClipToFrame(this.nodePtr, this.clipToFrameValue); 1821 } 1822 set frame(frame) { 1823 if (frame === undefined || frame === null) { 1824 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 1825 } 1826 else { 1827 this.size = { width: frame.width, height: frame.height }; 1828 this.position = { x: frame.x, y: frame.y }; 1829 } 1830 } 1831 set opacity(value) { 1832 this.opacityValue = this.checkUndefinedOrNullWithDefaultValue(value, 1.0); 1833 getUINativeModule().common.setOpacity(this.nodePtr, this.opacityValue); 1834 } 1835 set pivot(pivot) { 1836 if (pivot === undefined || pivot === null) { 1837 this.pivotValue = { x: 0.5, y: 0.5 }; 1838 } 1839 else { 1840 this.pivotValue.x = this.checkUndefinedOrNullWithDefaultValue(pivot.x, 0.5); 1841 this.pivotValue.y = this.checkUndefinedOrNullWithDefaultValue(pivot.y, 0.5); 1842 } 1843 getUINativeModule().renderNode.setPivot(this.nodePtr, this.pivotValue.x, this.pivotValue.y); 1844 } 1845 set position(position) { 1846 if (position === undefined || position === null) { 1847 this.frameValue.x = 0; 1848 this.frameValue.y = 0; 1849 } 1850 else { 1851 this.frameValue.x = this.checkUndefinedOrNullWithDefaultValue(position.x, 0); 1852 this.frameValue.y = this.checkUndefinedOrNullWithDefaultValue(position.y, 0); 1853 } 1854 getUINativeModule().renderNode.setPosition(this.nodePtr, this.frameValue.x, this.frameValue.y, this.lengthMetricsUnitValue); 1855 } 1856 set rotation(rotation) { 1857 if (rotation === undefined || rotation === null) { 1858 this.rotationValue = { x: 0, y: 0, z: 0 }; 1859 } 1860 else { 1861 this.rotationValue.x = this.checkUndefinedOrNullWithDefaultValue(rotation.x, 0); 1862 this.rotationValue.y = this.checkUndefinedOrNullWithDefaultValue(rotation.y, 0); 1863 this.rotationValue.z = this.checkUndefinedOrNullWithDefaultValue(rotation.z, 0); 1864 } 1865 getUINativeModule().renderNode.setRotation(this.nodePtr, this.rotationValue.x, this.rotationValue.y, this.rotationValue.z, this.lengthMetricsUnitValue); 1866 } 1867 set scale(scale) { 1868 if (scale === undefined || scale === null) { 1869 this.scaleValue = { x: 1.0, y: 1.0 }; 1870 } 1871 else { 1872 this.scaleValue.x = this.checkUndefinedOrNullWithDefaultValue(scale.x, 1.0); 1873 this.scaleValue.y = this.checkUndefinedOrNullWithDefaultValue(scale.y, 1.0); 1874 } 1875 getUINativeModule().renderNode.setScale(this.nodePtr, this.scaleValue.x, this.scaleValue.y); 1876 } 1877 set shadowColor(color) { 1878 this.shadowColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 1879 getUINativeModule().renderNode.setShadowColor(this.nodePtr, this.shadowColorValue); 1880 } 1881 set shadowOffset(offset) { 1882 if (offset === undefined || offset === null) { 1883 this.shadowOffsetValue = { x: 0, y: 0 }; 1884 } 1885 else { 1886 this.shadowOffsetValue.x = this.checkUndefinedOrNullWithDefaultValue(offset.x, 0); 1887 this.shadowOffsetValue.y = this.checkUndefinedOrNullWithDefaultValue(offset.y, 0); 1888 } 1889 getUINativeModule().renderNode.setShadowOffset(this.nodePtr, this.shadowOffsetValue.x, this.shadowOffsetValue.y, this.lengthMetricsUnitValue); 1890 } 1891 set label(label) { 1892 this.labelValue = this.checkUndefinedOrNullWithDefaultValue(label, ''); 1893 getUINativeModule().renderNode.setLabel(this.nodePtr, this.labelValue); 1894 } 1895 set shadowAlpha(alpha) { 1896 this.shadowAlphaValue = this.checkUndefinedOrNullWithDefaultValue(alpha, 0); 1897 getUINativeModule().renderNode.setShadowAlpha(this.nodePtr, this.shadowAlphaValue); 1898 } 1899 set shadowElevation(elevation) { 1900 this.shadowElevationValue = this.checkUndefinedOrNullWithDefaultValue(elevation, 0); 1901 getUINativeModule().renderNode.setShadowElevation(this.nodePtr, this.shadowElevationValue); 1902 } 1903 set shadowRadius(radius) { 1904 this.shadowRadiusValue = this.checkUndefinedOrNullWithDefaultValue(radius, 0); 1905 getUINativeModule().renderNode.setShadowRadius(this.nodePtr, this.shadowRadiusValue); 1906 } 1907 set size(size) { 1908 if (size === undefined || size === null) { 1909 this.frameValue.width = 0; 1910 this.frameValue.height = 0; 1911 } 1912 else { 1913 this.frameValue.width = this.checkUndefinedOrNullWithDefaultValue(size.width, 0); 1914 this.frameValue.height = this.checkUndefinedOrNullWithDefaultValue(size.height, 0); 1915 } 1916 getUINativeModule().renderNode.setSize(this.nodePtr, this.frameValue.width, this.frameValue.height, this.lengthMetricsUnitValue); 1917 } 1918 set transform(transform) { 1919 if (transform === undefined || transform === null) { 1920 this.transformValue = [1, 0, 0, 0, 1921 0, 1, 0, 0, 1922 0, 0, 1, 0, 1923 0, 0, 0, 1]; 1924 } 1925 else { 1926 let i = 0; 1927 while (i < transform.length && i < 16) { 1928 if (i % 5 === 0) { 1929 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 1); 1930 } 1931 else { 1932 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 0); 1933 } 1934 i = i + 1; 1935 } 1936 } 1937 getUINativeModule().common.setTransform(this.nodePtr, this.transformValue); 1938 } 1939 set translation(translation) { 1940 if (translation === undefined || translation === null) { 1941 this.translationValue = { x: 0, y: 0 }; 1942 } 1943 else { 1944 this.translationValue.x = this.checkUndefinedOrNullWithDefaultValue(translation.x, 0); 1945 this.translationValue.y = this.checkUndefinedOrNullWithDefaultValue(translation.y, 0); 1946 } 1947 getUINativeModule().renderNode.setTranslate(this.nodePtr, this.translationValue.x, this.translationValue.y, 0); 1948 } 1949 set lengthMetricsUnit(unit) { 1950 if (unit === undefined || unit == null) { 1951 this.lengthMetricsUnitValue = LengthMetricsUnit.DEFAULT; 1952 } 1953 else { 1954 this.lengthMetricsUnitValue = unit; 1955 } 1956 } 1957 set markNodeGroup(isNodeGroup) { 1958 if (isNodeGroup === undefined || isNodeGroup === null) { 1959 this.markNodeGroupValue = false; 1960 } 1961 else { 1962 this.markNodeGroupValue = isNodeGroup; 1963 } 1964 getUINativeModule().renderNode.setMarkNodeGroup(this.nodePtr, this.markNodeGroupValue); 1965 } 1966 get backgroundColor() { 1967 return this.backgroundColorValue; 1968 } 1969 get clipToFrame() { 1970 return this.clipToFrameValue; 1971 } 1972 get opacity() { 1973 return this.opacityValue; 1974 } 1975 get frame() { 1976 return this.frameValue; 1977 } 1978 get pivot() { 1979 return this.pivotValue; 1980 } 1981 get position() { 1982 return { x: this.frameValue.x, y: this.frameValue.y }; 1983 } 1984 get rotation() { 1985 return this.rotationValue; 1986 } 1987 get scale() { 1988 return this.scaleValue; 1989 } 1990 get shadowColor() { 1991 return this.shadowColorValue; 1992 } 1993 get shadowOffset() { 1994 return this.shadowOffsetValue; 1995 } 1996 get label() { 1997 return this.labelValue; 1998 } 1999 get shadowAlpha() { 2000 return this.shadowAlphaValue; 2001 } 2002 get shadowElevation() { 2003 return this.shadowElevationValue; 2004 } 2005 get shadowRadius() { 2006 return this.shadowRadiusValue; 2007 } 2008 get size() { 2009 return { width: this.frameValue.width, height: this.frameValue.height }; 2010 } 2011 get transform() { 2012 return this.transformValue; 2013 } 2014 get translation() { 2015 return this.translationValue; 2016 } 2017 get lengthMetricsUnit() { 2018 return this.lengthMetricsUnitValue; 2019 } 2020 get markNodeGroup() { 2021 return this.markNodeGroupValue; 2022 } 2023 checkUndefinedOrNullWithDefaultValue(arg, defaultValue) { 2024 if (arg === undefined || arg === null) { 2025 return defaultValue; 2026 } 2027 else { 2028 return arg; 2029 } 2030 } 2031 appendChild(node) { 2032 if (node === undefined || node === null) { 2033 return; 2034 } 2035 if (this.childrenList.findIndex(element => element === node) !== -1) { 2036 return; 2037 } 2038 this.childrenList.push(node); 2039 node.parentRenderNode = new WeakRef(this); 2040 getUINativeModule().renderNode.appendChild(this.nodePtr, node.nodePtr); 2041 } 2042 insertChildAfter(child, sibling) { 2043 if (child === undefined || child === null) { 2044 return; 2045 } 2046 let indexOfNode = this.childrenList.findIndex(element => element === child); 2047 if (indexOfNode !== -1) { 2048 return; 2049 } 2050 child.parentRenderNode = new WeakRef(this); 2051 let indexOfSibling = this.childrenList.findIndex(element => element === sibling); 2052 if (indexOfSibling === -1) { 2053 sibling === null; 2054 } 2055 if (sibling === undefined || sibling === null) { 2056 this.childrenList.splice(0, 0, child); 2057 getUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, null); 2058 } 2059 else { 2060 this.childrenList.splice(indexOfSibling + 1, 0, child); 2061 getUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, sibling.nodePtr); 2062 } 2063 } 2064 removeChild(node) { 2065 if (node === undefined || node === null) { 2066 return; 2067 } 2068 const index = this.childrenList.findIndex(element => element === node); 2069 if (index === -1) { 2070 return; 2071 } 2072 const child = this.childrenList[index]; 2073 child.parentRenderNode = null; 2074 this.childrenList.splice(index, 1); 2075 getUINativeModule().renderNode.removeChild(this.nodePtr, node.nodePtr); 2076 } 2077 clearChildren() { 2078 this.childrenList = new Array(); 2079 getUINativeModule().renderNode.clearChildren(this.nodePtr); 2080 } 2081 getChild(index) { 2082 if (this.childrenList.length > index && index >= 0) { 2083 return this.childrenList[index]; 2084 } 2085 return null; 2086 } 2087 getFirstChild() { 2088 if (this.childrenList.length > 0) { 2089 return this.childrenList[0]; 2090 } 2091 return null; 2092 } 2093 getNextSibling() { 2094 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 2095 return null; 2096 } 2097 let parent = this.parentRenderNode.deref(); 2098 if (parent === undefined || parent === null) { 2099 return null; 2100 } 2101 let siblingList = parent.childrenList; 2102 const index = siblingList.findIndex(element => element === this); 2103 if (index === -1) { 2104 return null; 2105 } 2106 return parent.getChild(index + 1); 2107 } 2108 getPreviousSibling() { 2109 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 2110 return null; 2111 } 2112 let parent = this.parentRenderNode.deref(); 2113 if (parent === undefined || parent === null) { 2114 return null; 2115 } 2116 let siblingList = parent.childrenList; 2117 const index = siblingList.findIndex(element => element === this); 2118 if (index === -1) { 2119 return null; 2120 } 2121 return parent.getChild(index - 1); 2122 } 2123 setFrameNode(frameNode) { 2124 this._frameNode = frameNode; 2125 } 2126 setNodePtr(nativeRef) { 2127 this._nativeRef = nativeRef; 2128 this.nodePtr = this._nativeRef?.getNativeHandle(); 2129 } 2130 setBaseNode(baseNode) { 2131 this.baseNode_ = baseNode; 2132 } 2133 resetNodePtr() { 2134 this.nodePtr = null; 2135 this._nativeRef = null; 2136 } 2137 dispose() { 2138 this._nativeRef?.dispose(); 2139 this.baseNode_?.disposeNode(); 2140 this._frameNode?.deref()?.resetNodePtr(); 2141 this._nativeRef = null; 2142 this.nodePtr = null; 2143 } 2144 getNodePtr() { 2145 return this.nodePtr; 2146 } 2147 invalidate() { 2148 getUINativeModule().renderNode.invalidate(this.nodePtr); 2149 } 2150 set borderStyle(style) { 2151 if (style === undefined || style === null) { 2152 this.borderStyleValue = { left: BorderStyle.NONE, top: BorderStyle.NONE, right: BorderStyle.NONE, bottom: BorderStyle.NONE }; 2153 } 2154 else { 2155 this.borderStyleValue = style; 2156 } 2157 getUINativeModule().renderNode.setBorderStyle(this.nodePtr, this.borderStyleValue.left, this.borderStyleValue.top, this.borderStyleValue.right, this.borderStyleValue.bottom); 2158 } 2159 get borderStyle() { 2160 return this.borderStyleValue; 2161 } 2162 set borderWidth(width) { 2163 if (width === undefined || width === null) { 2164 this.borderWidthValue = { left: 0, top: 0, right: 0, bottom: 0 }; 2165 } 2166 else { 2167 this.borderWidthValue = width; 2168 } 2169 getUINativeModule().renderNode.setBorderWidth(this.nodePtr, this.borderWidthValue.left, this.borderWidthValue.top, this.borderWidthValue.right, this.borderWidthValue.bottom, this.lengthMetricsUnitValue); 2170 } 2171 get borderWidth() { 2172 return this.borderWidthValue; 2173 } 2174 set borderColor(color) { 2175 if (color === undefined || color === null) { 2176 this.borderColorValue = { left: 0XFF000000, top: 0XFF000000, right: 0XFF000000, bottom: 0XFF000000 }; 2177 } 2178 else { 2179 this.borderColorValue = color; 2180 } 2181 getUINativeModule().renderNode.setBorderColor(this.nodePtr, this.borderColorValue.left, this.borderColorValue.top, this.borderColorValue.right, this.borderColorValue.bottom); 2182 } 2183 get borderColor() { 2184 return this.borderColorValue; 2185 } 2186 set borderRadius(radius) { 2187 if (radius === undefined || radius === null) { 2188 this.borderRadiusValue = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0 }; 2189 } 2190 else { 2191 this.borderRadiusValue = radius; 2192 } 2193 getUINativeModule().renderNode.setBorderRadius(this.nodePtr, this.borderRadiusValue.topLeft, this.borderRadiusValue.topRight, this.borderRadiusValue.bottomLeft, this.borderRadiusValue.bottomRight, this.lengthMetricsUnitValue); 2194 } 2195 get borderRadius() { 2196 return this.borderRadiusValue; 2197 } 2198 set shapeMask(shapeMask) { 2199 if (shapeMask === undefined || shapeMask === null) { 2200 this.shapeMaskValue = new ShapeMask(); 2201 } 2202 else { 2203 this.shapeMaskValue = shapeMask; 2204 } 2205 if (this.shapeMaskValue.rect !== null) { 2206 const rectMask = this.shapeMaskValue.rect; 2207 getUINativeModule().renderNode.setRectMask(this.nodePtr, rectMask.left, rectMask.top, rectMask.right, rectMask.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2208 } 2209 else if (this.shapeMaskValue.circle !== null) { 2210 const circle = this.shapeMaskValue.circle; 2211 getUINativeModule().renderNode.setCircleMask(this.nodePtr, circle.centerX, circle.centerY, circle.radius, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2212 } 2213 else if (this.shapeMaskValue.roundRect !== null) { 2214 const roundRect = this.shapeMask.roundRect; 2215 const corners = roundRect.corners; 2216 const rect = roundRect.rect; 2217 getUINativeModule().renderNode.setRoundRectMask(this.nodePtr, corners.topLeft.x, corners.topLeft.y, corners.topRight.x, corners.topRight.y, corners.bottomLeft.x, corners.bottomLeft.y, corners.bottomRight.x, corners.bottomRight.y, rect.left, rect.top, rect.right, rect.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2218 } 2219 else if (this.shapeMaskValue.oval !== null) { 2220 const oval = this.shapeMaskValue.oval; 2221 getUINativeModule().renderNode.setOvalMask(this.nodePtr, oval.left, oval.top, oval.right, oval.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2222 } 2223 else if (this.shapeMaskValue.path !== null) { 2224 const path = this.shapeMaskValue.path; 2225 getUINativeModule().renderNode.setPath(this.nodePtr, path.commands, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 2226 } 2227 } 2228 get shapeMask() { 2229 return this.shapeMaskValue; 2230 } 2231 set shapeClip(shapeClip) { 2232 if (shapeClip === undefined || shapeClip === null) { 2233 this.shapeClipValue = new ShapeClip(); 2234 } 2235 else { 2236 this.shapeClipValue = shapeClip; 2237 } 2238 if (this.shapeClipValue.rect !== null) { 2239 const rectClip = this.shapeClipValue.rect; 2240 getUINativeModule().renderNode.setRectClip(this.nodePtr, rectClip.left, rectClip.top, rectClip.right, rectClip.bottom); 2241 } 2242 else if (this.shapeClipValue.circle !== null) { 2243 const circle = this.shapeClipValue.circle; 2244 getUINativeModule().renderNode.setCircleClip(this.nodePtr, circle.centerX, circle.centerY, circle.radius); 2245 } 2246 else if (this.shapeClipValue.roundRect !== null) { 2247 const roundRect = this.shapeClipValue.roundRect; 2248 const corners = roundRect.corners; 2249 const rect = roundRect.rect; 2250 getUINativeModule().renderNode.setRoundRectClip(this.nodePtr, corners.topLeft.x, corners.topLeft.y, corners.topRight.x, corners.topRight.y, corners.bottomLeft.x, corners.bottomLeft.y, corners.bottomRight.x, corners.bottomRight.y, rect.left, rect.top, rect.right, rect.bottom); 2251 } 2252 else if (this.shapeClipValue.oval !== null) { 2253 const oval = this.shapeClipValue.oval; 2254 getUINativeModule().renderNode.setOvalClip(this.nodePtr, oval.left, oval.top, oval.right, oval.bottom); 2255 } 2256 else if (this.shapeClipValue.path !== null) { 2257 const path = this.shapeClipValue.path; 2258 getUINativeModule().renderNode.setPathClip(this.nodePtr, path.commands); 2259 } 2260 } 2261 get shapeClip() { 2262 this.shapeClipValue = this.shapeClipValue ? this.shapeClipValue : new ShapeClip(); 2263 return this.shapeClipValue; 2264 } 2265} 2266function edgeColors(all) { 2267 return { left: all, top: all, right: all, bottom: all }; 2268} 2269function edgeWidths(all) { 2270 return { left: all, top: all, right: all, bottom: all }; 2271} 2272function borderStyles(all) { 2273 return { left: all, top: all, right: all, bottom: all }; 2274} 2275function borderRadiuses(all) { 2276 return { topLeft: all, topRight: all, bottomLeft: all, bottomRight: all }; 2277} 2278/* 2279 * Copyright (c) 2023 Huawei Device Co., Ltd. 2280 * Licensed under the Apache License, Version 2.0 (the "License"); 2281 * you may not use this file except in compliance with the License. 2282 * You may obtain a copy of the License at 2283 * 2284 * http://www.apache.org/licenses/LICENSE-2.0 2285 * 2286 * Unless required by applicable law or agreed to in writing, software 2287 * distributed under the License is distributed on an "AS IS" BASIS, 2288 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2289 * See the License for the specific language governing permissions and 2290 * limitations under the License. 2291 */ 2292class XComponentNode extends FrameNode { 2293 constructor(uiContext, options, id, type, libraryname, controller) { 2294 super(uiContext, 'XComponentNode'); 2295 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 2296 this.xcomponentNode_ = getUINativeModule().xcomponentNode; 2297 this.renderType_ = options.type; 2298 const surfaceId = options.surfaceId; 2299 const selfIdealWidth = options.selfIdealSize.width; 2300 const selfIdealHeight = options.selfIdealSize.height; 2301 this.nativeModule_ = this.xcomponentNode_.create(elmtId, id, type, this.renderType_, surfaceId, selfIdealWidth, selfIdealHeight, libraryname, controller); 2302 this.xcomponentNode_.registerOnCreateCallback(this.nativeModule_, this.onCreate); 2303 this.xcomponentNode_.registerOnDestroyCallback(this.nativeModule_, this.onDestroy); 2304 this.nodePtr_ = this.xcomponentNode_.getFrameNode(this.nativeModule_); 2305 this.setNodePtr(getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_), this.nodePtr_); 2306 } 2307 onCreate(event) { } 2308 onDestroy() { } 2309 changeRenderType(type) { 2310 if (this.renderType_ === type) { 2311 return true; 2312 } 2313 if (this.xcomponentNode_.changeRenderType(this.nativeModule_, type)) { 2314 this.renderType_ = type; 2315 return true; 2316 } 2317 return false; 2318 } 2319} 2320/* 2321 * Copyright (c) 2024 Huawei Device Co., Ltd. 2322 * Licensed under the Apache License, Version 2.0 (the "License"); 2323 * you may not use this file except in compliance with the License. 2324 * You may obtain a copy of the License at 2325 * 2326 * http://www.apache.org/licenses/LICENSE-2.0 2327 * 2328 * Unless required by applicable law or agreed to in writing, software 2329 * distributed under the License is distributed on an "AS IS" BASIS, 2330 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2331 * See the License for the specific language governing permissions and 2332 * limitations under the License. 2333 */ 2334class Content { 2335 constructor() { } 2336 onAttachToWindow() { } 2337 onDetachFromWindow() { } 2338} 2339/* 2340 * Copyright (c) 2024 Huawei Device Co., Ltd. 2341 * Licensed under the Apache License, Version 2.0 (the "License"); 2342 * you may not use this file except in compliance with the License. 2343 * You may obtain a copy of the License at 2344 * 2345 * http://www.apache.org/licenses/LICENSE-2.0 2346 * 2347 * Unless required by applicable law or agreed to in writing, software 2348 * distributed under the License is distributed on an "AS IS" BASIS, 2349 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2350 * See the License for the specific language governing permissions and 2351 * limitations under the License. 2352 */ 2353/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" /> 2354 2355class ComponentContent extends Content { 2356 constructor(uiContext, builder, params, options) { 2357 super(); 2358 let builderNode = new BuilderNode(uiContext, {}); 2359 this.builderNode_ = builderNode; 2360 this.builderNode_.build(builder, params ?? undefined, options); 2361 } 2362 update(params) { 2363 this.builderNode_.update(params); 2364 } 2365 getFrameNode() { 2366 return this.builderNode_.getFrameNodeWithoutCheck(); 2367 } 2368 setAttachedParent(parent) { 2369 this.parentWeak_ = parent; 2370 } 2371 getNodePtr() { 2372 if (this.attachNodeRef_ !== undefined) { 2373 return this.attachNodeRef_.getNativeHandle(); 2374 } 2375 return this.builderNode_.getNodePtr(); 2376 } 2377 reuse(param) { 2378 this.builderNode_.reuse(param); 2379 } 2380 recycle() { 2381 this.builderNode_.recycle(); 2382 } 2383 dispose() { 2384 this.detachFromParent(); 2385 this.attachNodeRef_?.dispose(); 2386 this.builderNode_?.dispose(); 2387 } 2388 detachFromParent() { 2389 if (this.parentWeak_ === undefined) { 2390 return; 2391 } 2392 let parent = this.parentWeak_.deref(); 2393 if (parent !== undefined) { 2394 parent.removeComponentContent(this); 2395 } 2396 } 2397 getNodeWithoutProxy() { 2398 const node = this.getNodePtr(); 2399 const nodeType = getUINativeModule().frameNode.getNodeType(node); 2400 if (nodeType === "BuilderProxyNode") { 2401 const result = getUINativeModule().frameNode.getFirstUINode(node); 2402 this.attachNodeRef_ = getUINativeModule().nativeUtils.createNativeStrongRef(result); 2403 getUINativeModule().frameNode.removeChild(node, result); 2404 return result; 2405 } 2406 return node; 2407 } 2408 updateConfiguration() { 2409 this.builderNode_.updateConfiguration(); 2410 } 2411} 2412/* 2413 * Copyright (c) 2024 Huawei Device Co., Ltd. 2414 * Licensed under the Apache License, Version 2.0 (the "License"); 2415 * you may not use this file except in compliance with the License. 2416 * You may obtain a copy of the License at 2417 * 2418 * http://www.apache.org/licenses/LICENSE-2.0 2419 * 2420 * Unless required by applicable law or agreed to in writing, software 2421 * distributed under the License is distributed on an "AS IS" BASIS, 2422 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 2423 * See the License for the specific language governing permissions and 2424 * limitations under the License. 2425 */ 2426class NodeContent extends Content { 2427 constructor() { 2428 super(); 2429 this.nativeRef_ = getUINativeModule().frameNode.createNodeContent(); 2430 this.nativePtr_ = this.nativeRef_.getNativeHandle(); 2431 this.nodeArray_ = new Array(); 2432 } 2433 addFrameNode(node) { 2434 if (this.nodeArray_.includes(node)) { 2435 return; 2436 } 2437 if (getUINativeModule().frameNode.addFrameNodeToNodeContent(node.getNodePtr(), this.nativePtr_)) { 2438 this.nodeArray_.push(node); 2439 } 2440 } 2441 removeFrameNode(node) { 2442 if (!this.nodeArray_.includes(node)) { 2443 return; 2444 } 2445 if (getUINativeModule().frameNode.removeFrameNodeFromNodeContent(node.getNodePtr(), this.nativePtr_)) { 2446 let index = this.nodeArray_.indexOf(node); 2447 if (index > -1) { 2448 this.nodeArray_.splice(index, 1); 2449 } 2450 } 2451 } 2452} 2453 2454export default { 2455 NodeController, BuilderNode, BaseNode, RenderNode, FrameNode, FrameNodeUtils, 2456 NodeRenderType, XComponentNode, LengthMetrics, ColorMetrics, LengthUnit, LengthMetricsUnit, ShapeMask, ShapeClip, 2457 edgeColors, edgeWidths, borderStyles, borderRadiuses, Content, ComponentContent, NodeContent, typeNode, NodeAdapter 2458}; 2459