1/* 2 * Copyright (c) 2023 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 = {})); 20class BaseNode extends __JSBaseNode__ { 21 constructor(uiContext, options) { 22 super(options); 23 let instanceId = -1; 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 instanceId = uiContext.instanceId_; 32 } 33 this.instanceId_ = instanceId; 34 } 35 getInstanceId() { 36 return this.instanceId_; 37 } 38} 39/* 40 * Copyright (c) 2023 Huawei Device Co., Ltd. 41 * Licensed under the Apache License, Version 2.0 (the "License"); 42 * you may not use this file except in compliance with the License. 43 * You may obtain a copy of the License at 44 * 45 * http://www.apache.org/licenses/LICENSE-2.0 46 * 47 * Unless required by applicable law or agreed to in writing, software 48 * distributed under the License is distributed on an "AS IS" BASIS, 49 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 50 * See the License for the specific language governing permissions and 51 * limitations under the License. 52 */ 53/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" /> 54/// <reference path="../../state_mgmt/src/lib/partial_update/pu_viewstack_processor.d.ts" /> 55class BuilderNode { 56 constructor(uiContext, options) { 57 let jsBuilderNode = new JSBuilderNode(uiContext, options); 58 this._JSBuilderNode = jsBuilderNode; 59 let id = Symbol("BuilderNode"); 60 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.set(id, jsBuilderNode); 61 BuilderNodeFinalizationRegisterProxy.register(this, { name: 'BuilderNode', idOfNode: id }); 62 } 63 update(params) { 64 this._JSBuilderNode.update(params); 65 } 66 build(builder, params) { 67 this._JSBuilderNode.build(builder, params); 68 this.nodePtr_ = this._JSBuilderNode.getNodePtr(); 69 } 70 getFrameNode() { 71 return this._JSBuilderNode.getFrameNode(); 72 } 73 postTouchEvent(touchEvent) { 74 return this._JSBuilderNode.postTouchEvent(touchEvent); 75 } 76 dispose() { 77 this._JSBuilderNode.dispose(); 78 } 79} 80class JSBuilderNode extends BaseNode { 81 constructor(uiContext, options) { 82 super(uiContext, options); 83 this.childrenWeakrefMap_ = new Map(); 84 this.uiContext_ = uiContext; 85 this.updateFuncByElmtId = new Map(); 86 } 87 getCardId() { 88 return -1; 89 } 90 addChild(child) { 91 if (this.childrenWeakrefMap_.has(child.id__())) { 92 return false; 93 } 94 this.childrenWeakrefMap_.set(child.id__(), new WeakRef(child)); 95 return true; 96 } 97 getChildById(id) { 98 const childWeakRef = this.childrenWeakrefMap_.get(id); 99 return childWeakRef ? childWeakRef.deref() : undefined; 100 } 101 updateStateVarsOfChildByElmtId(elmtId, params) { 102 if (elmtId < 0) { 103 return; 104 } 105 let child = this.getChildById(elmtId); 106 if (!child) { 107 return; 108 } 109 child.updateStateVars(params); 110 } 111 createOrGetNode(elmtId, builder) { 112 const entry = this.updateFuncByElmtId.get(elmtId); 113 if (entry === undefined) { 114 throw new Error(`fail to create node, elmtId is illegal`); 115 } 116 let updateFuncRecord = (typeof entry === 'object') ? entry : undefined; 117 if (updateFuncRecord === undefined) { 118 throw new Error(`fail to create node, the api level of app does not supported`); 119 } 120 let nodeInfo = updateFuncRecord.node; 121 if (nodeInfo === undefined) { 122 nodeInfo = builder(); 123 updateFuncRecord.node = nodeInfo; 124 } 125 return nodeInfo; 126 } 127 build(builder, params) { 128 __JSScopeUtil__.syncInstanceId(this.instanceId_); 129 this.params_ = params; 130 this.updateFuncByElmtId.clear(); 131 this.nodePtr_ = super.create(builder.builder, this.params_); 132 if (this.frameNode_ === undefined || this.frameNode_ === null) { 133 this.frameNode_ = new FrameNode(this.uiContext_, 'BuilderNode'); 134 } 135 this.frameNode_.setNodePtr(this.nodePtr_); 136 this.frameNode_.setBaseNode(this); 137 __JSScopeUtil__.restoreInstanceId(); 138 } 139 update(param) { 140 __JSScopeUtil__.syncInstanceId(this.instanceId_); 141 this.updateStart(); 142 this.purgeDeletedElmtIds(); 143 this.params_ = param; 144 Array.from(this.updateFuncByElmtId.keys()).sort((a, b) => { 145 return (a < b) ? -1 : (a > b) ? 1 : 0; 146 }).forEach(elmtId => this.UpdateElement(elmtId)); 147 this.updateEnd(); 148 __JSScopeUtil__.restoreInstanceId(); 149 } 150 UpdateElement(elmtId) { 151 // do not process an Element that has been marked to be deleted 152 const obj = this.updateFuncByElmtId.get(elmtId); 153 const updateFunc = (typeof obj === 'object') ? obj.updateFunc : null; 154 if (typeof updateFunc === 'function') { 155 updateFunc(elmtId, /* isFirstRender */ false); 156 this.finishUpdateFunc(); 157 } 158 } 159 purgeDeletedElmtIds() { 160 UINodeRegisterProxy.obtainDeletedElmtIds(); 161 UINodeRegisterProxy.unregisterElmtIdsFromViewPUs(); 162 } 163 purgeDeleteElmtId(rmElmtId) { 164 const result = this.updateFuncByElmtId.delete(rmElmtId); 165 if (result) { 166 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(rmElmtId); 167 } 168 return result; 169 } 170 getFrameNode() { 171 if (this.frameNode_ !== undefined && 172 this.frameNode_ !== null && 173 this.frameNode_.getNodePtr() !== null) { 174 return this.frameNode_; 175 } 176 return null; 177 } 178 observeComponentCreation(func) { 179 let elmId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 180 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmId, new WeakRef(this)); 181 try { 182 func(elmId, true); 183 } 184 catch (error) { 185 // avoid the incompatible change that move set function before updateFunc. 186 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmId); 187 throw error; 188 } 189 } 190 observeComponentCreation2(compilerAssignedUpdateFunc, classObject) { 191 const _componentName = classObject && 'name' in classObject ? Reflect.get(classObject, 'name') : 'unspecified UINode'; 192 const _popFunc = classObject && "pop" in classObject ? classObject.pop : () => { }; 193 const updateFunc = (elmtId, isFirstRender) => { 194 __JSScopeUtil__.syncInstanceId(this.instanceId_); 195 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 196 compilerAssignedUpdateFunc(elmtId, isFirstRender, this.params_); 197 if (!isFirstRender) { 198 _popFunc(); 199 } 200 ViewStackProcessor.StopGetAccessRecording(); 201 __JSScopeUtil__.restoreInstanceId(); 202 }; 203 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 204 // needs to move set before updateFunc. 205 // make sure the key and object value exist since it will add node in attributeModifier during updateFunc. 206 this.updateFuncByElmtId.set(elmtId, { 207 updateFunc: updateFunc, 208 componentName: _componentName, 209 }); 210 UINodeRegisterProxy.ElementIdToOwningViewPU_.set(elmtId, new WeakRef(this)); 211 try { 212 updateFunc(elmtId, /* is first render */ true); 213 } 214 catch (error) { 215 // avoid the incompatible change that move set function before updateFunc. 216 this.updateFuncByElmtId.delete(elmtId); 217 UINodeRegisterProxy.ElementIdToOwningViewPU_.delete(elmtId); 218 throw error; 219 } 220 } 221 /** 222 Partial updates for ForEach. 223 * @param elmtId ID of element. 224 * @param itemArray Array of items for use of itemGenFunc. 225 * @param itemGenFunc Item generation function to generate new elements. If index parameter is 226 * given set itemGenFuncUsesIndex to true. 227 * @param idGenFunc ID generation function to generate unique ID for each element. If index parameter is 228 * given set idGenFuncUsesIndex to true. 229 * @param itemGenFuncUsesIndex itemGenFunc optional index parameter is given or not. 230 * @param idGenFuncUsesIndex idGenFunc optional index parameter is given or not. 231 */ 232 forEachUpdateFunction(elmtId, itemArray, itemGenFunc, idGenFunc, itemGenFuncUsesIndex = false, idGenFuncUsesIndex = false) { 233 if (itemArray === null || itemArray === undefined) { 234 return; 235 } 236 if (itemGenFunc === null || itemGenFunc === undefined) { 237 return; 238 } 239 if (idGenFunc === undefined) { 240 idGenFuncUsesIndex = true; 241 // catch possible error caused by Stringify and re-throw an Error with a meaningful (!) error message 242 idGenFunc = (item, index) => { 243 try { 244 return `${index}__${JSON.stringify(item)}`; 245 } 246 catch (e) { 247 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!`); 248 } 249 }; 250 } 251 let diffIndexArray = []; // New indexes compared to old one. 252 let newIdArray = []; 253 let idDuplicates = []; 254 const arr = itemArray; // just to trigger a 'get' onto the array 255 // ID gen is with index. 256 if (idGenFuncUsesIndex) { 257 // Create array of new ids. 258 arr.forEach((item, indx) => { 259 newIdArray.push(idGenFunc(item, indx)); 260 }); 261 } 262 else { 263 // Create array of new ids. 264 arr.forEach((item, index) => { 265 newIdArray.push(`${itemGenFuncUsesIndex ? index + "_" : ""}` + idGenFunc(item)); 266 }); 267 } 268 // Set new array on C++ side. 269 // C++ returns array of indexes of newly added array items. 270 // these are indexes in new child list. 271 ForEach.setIdArray(elmtId, newIdArray, diffIndexArray, idDuplicates); 272 // Item gen is with index. 273 diffIndexArray.forEach((indx) => { 274 ForEach.createNewChildStart(newIdArray[indx], this); 275 if (itemGenFuncUsesIndex) { 276 itemGenFunc(arr[indx], indx); 277 } 278 else { 279 itemGenFunc(arr[indx]); 280 } 281 ForEach.createNewChildFinish(newIdArray[indx], this); 282 }); 283 } 284 ifElseBranchUpdateFunction(branchId, branchfunc) { 285 const oldBranchid = If.getBranchId(); 286 if (branchId === oldBranchid) { 287 return; 288 } 289 // branchId identifies uniquely the if .. <1> .. else if .<2>. else .<3>.branch 290 // ifElseNode stores the most recent branch, so we can compare 291 // removedChildElmtIds will be filled with the elmtIds of all children and their children will be deleted in response to if .. else change 292 let removedChildElmtIds = new Array(); 293 If.branchId(branchId, removedChildElmtIds); 294 this.purgeDeletedElmtIds(); 295 branchfunc(); 296 } 297 getNodePtr() { 298 return this.nodePtr_; 299 } 300 dispose() { 301 this.nodePtr_ = null; 302 super.dispose(); 303 if (this.frameNode_ !== undefined && this.frameNode_ !== null) { 304 this.frameNode_.setNodePtr(null); 305 } 306 } 307} 308/* 309 * Copyright (c) 2024 Huawei Device Co., Ltd. 310 * Licensed under the Apache License, Version 2.0 (the "License"); 311 * you may not use this file except in compliance with the License. 312 * You may obtain a copy of the License at 313 * 314 * http://www.apache.org/licenses/LICENSE-2.0 315 * 316 * Unless required by applicable law or agreed to in writing, software 317 * distributed under the License is distributed on an "AS IS" BASIS, 318 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 319 * See the License for the specific language governing permissions and 320 * limitations under the License. 321 */ 322class BuilderNodeFinalizationRegisterProxy { 323 constructor() { 324 this.finalizationRegistry_ = new FinalizationRegistry((heldValue) => { 325 if (heldValue.name === "BuilderNode") { 326 const builderNode = BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.get(heldValue.idOfNode); 327 BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_.delete(heldValue.idOfNode); 328 builderNode.dispose(); 329 } 330 }); 331 } 332 static register(target, heldValue) { 333 BuilderNodeFinalizationRegisterProxy.instance_.finalizationRegistry_.register(target, heldValue); 334 } 335} 336BuilderNodeFinalizationRegisterProxy.instance_ = new BuilderNodeFinalizationRegisterProxy(); 337BuilderNodeFinalizationRegisterProxy.ElementIdToOwningBuilderNode_ = new Map(); 338/* 339 * Copyright (c) 2023 Huawei Device Co., Ltd. 340 * Licensed under the Apache License, Version 2.0 (the "License"); 341 * you may not use this file except in compliance with the License. 342 * You may obtain a copy of the License at 343 * 344 * http://www.apache.org/licenses/LICENSE-2.0 345 * 346 * Unless required by applicable law or agreed to in writing, software 347 * distributed under the License is distributed on an "AS IS" BASIS, 348 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 349 * See the License for the specific language governing permissions and 350 * limitations under the License. 351 */ 352const arkUINativeModule = globalThis.getArkUINativeModule(); 353function GetUINativeModule() { 354 if (arkUINativeModule) { 355 return arkUINativeModule; 356 } 357 return arkUINativeModule; 358} 359class NodeController { 360 constructor() { 361 this.nodeContainerId_ = -1; 362 } 363 aboutToResize(size) { } 364 aboutToAppear() { } 365 aboutToDisappear() { } 366 onTouchEvent(event) { } 367 rebuild() { 368 if (this.nodeContainerId_ >= 0) { 369 GetUINativeModule().nodeContainer.rebuild(this.nodeContainerId_); 370 } 371 } 372} 373/* 374 * Copyright (c) 2023 Huawei Device Co., Ltd. 375 * Licensed under the Apache License, Version 2.0 (the "License"); 376 * you may not use this file except in compliance with the License. 377 * You may obtain a copy of the License at 378 * 379 * http://www.apache.org/licenses/LICENSE-2.0 380 * 381 * Unless required by applicable law or agreed to in writing, software 382 * distributed under the License is distributed on an "AS IS" BASIS, 383 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 384 * See the License for the specific language governing permissions and 385 * limitations under the License. 386 */ 387class FrameNode { 388 constructor(uiContext, type) { 389 this.renderNode_ = new RenderNode('FrameNode'); 390 if (type === 'BuilderNode') { 391 return; 392 } 393 this.baseNode_ = new BaseNode(uiContext); 394 this.nodePtr_ = this.baseNode_.createRenderNode(this); 395 this.renderNode_.setNodePtr(this.nodePtr_); 396 this.renderNode_.setBaseNode(this.baseNode_); 397 } 398 getRenderNode() { 399 if (this.renderNode_ !== undefined && 400 this.renderNode_ !== null && 401 this.renderNode_.getNodePtr() !== null) { 402 return this.renderNode_; 403 } 404 return null; 405 } 406 setNodePtr(nodePtr) { 407 this.nodePtr_ = nodePtr; 408 this.renderNode_.setNodePtr(nodePtr); 409 } 410 setBaseNode(baseNode) { 411 this.baseNode_ = baseNode; 412 this.renderNode_.setBaseNode(baseNode); 413 } 414 getNodePtr() { 415 return this.nodePtr_; 416 } 417 dispose() { 418 this.baseNode_.dispose(); 419 } 420} 421/* 422 * Copyright (c) 2023 Huawei Device Co., Ltd. 423 * Licensed under the Apache License, Version 2.0 (the "License"); 424 * you may not use this file except in compliance with the License. 425 * You may obtain a copy of the License at 426 * 427 * http://www.apache.org/licenses/LICENSE-2.0 428 * 429 * Unless required by applicable law or agreed to in writing, software 430 * distributed under the License is distributed on an "AS IS" BASIS, 431 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 432 * See the License for the specific language governing permissions and 433 * limitations under the License. 434 */ 435var BorderStyle; 436(function (BorderStyle) { 437 BorderStyle[BorderStyle["SOLID"] = 0] = "SOLID"; 438 BorderStyle[BorderStyle["DASHED"] = 1] = "DASHED"; 439 BorderStyle[BorderStyle["DOTTED"] = 2] = "DOTTED"; 440 BorderStyle[BorderStyle["NONE"] = 3] = "NONE"; 441})(BorderStyle || (BorderStyle = {})); 442class ShapeMask { 443 constructor() { 444 this.rect = null; 445 this.roundRect = null; 446 this.circle = null; 447 this.oval = null; 448 this.path = null; 449 this.fillColor = 0XFF000000; 450 this.strokeColor = 0XFF000000; 451 this.strokeWidth = 0; 452 } 453 setRectShape(rect) { 454 this.rect = rect; 455 this.roundRect = null; 456 this.circle = null; 457 this.oval = null; 458 this.path = null; 459 } 460 setRoundRectShape(roundRect) { 461 this.roundRect = roundRect; 462 this.rect = null; 463 this.circle = null; 464 this.oval = null; 465 this.path = null; 466 } 467 setCircleShape(circle) { 468 this.circle = circle; 469 this.rect = null; 470 this.roundRect = null; 471 this.oval = null; 472 this.path = null; 473 } 474 setOvalShape(oval) { 475 this.oval = oval; 476 this.rect = null; 477 this.circle = null; 478 this.roundRect = null; 479 this.path = null; 480 } 481 setCommandPath(path) { 482 this.path = path; 483 this.oval = null; 484 this.rect = null; 485 this.circle = null; 486 this.roundRect = null; 487 } 488} 489class RenderNode { 490 constructor(type) { 491 this.nodePtr = null; 492 this.childrenList = []; 493 this.parentRenderNode = null; 494 this.backgroundColorValue = 0; 495 this.clipToFrameValue = false; 496 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 497 this.opacityValue = 1.0; 498 this.pivotValue = { x: 0.5, y: 0.5 }; 499 this.rotationValue = { x: 0, y: 0, z: 0 }; 500 this.scaleValue = { x: 1.0, y: 1.0 }; 501 this.shadowColorValue = 0; 502 this.shadowOffsetValue = { x: 0, y: 0 }; 503 this.shadowAlphaValue = 0; 504 this.shadowElevationValue = 0; 505 this.shadowRadiusValue = 0; 506 this.transformValue = [1, 0, 0, 0, 507 0, 1, 0, 0, 508 0, 0, 1, 0, 509 0, 0, 0, 1]; 510 this.translationValue = { x: 0, y: 0 }; 511 if (type === 'FrameNode') { 512 return; 513 } 514 this.baseNode_ = new __JSBaseNode__(); 515 this.baseNode_.draw = this.draw; 516 this.nodePtr = this.baseNode_.createRenderNode(this); 517 } 518 set backgroundColor(color) { 519 this.backgroundColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 520 GetUINativeModule().renderNode.setBackgroundColor(this.nodePtr, this.backgroundColorValue); 521 } 522 set clipToFrame(useClip) { 523 this.clipToFrameValue = this.checkUndefinedOrNullWithDefaultValue(useClip, false); 524 GetUINativeModule().renderNode.setClipToFrame(this.nodePtr, this.clipToFrameValue); 525 } 526 set frame(frame) { 527 if (frame === undefined || frame === null) { 528 this.frameValue = { x: 0, y: 0, width: 0, height: 0 }; 529 } 530 else { 531 this.size = { width: frame.width, height: frame.height }; 532 this.position = { x: frame.x, y: frame.y }; 533 } 534 } 535 set opacity(value) { 536 this.opacityValue = this.checkUndefinedOrNullWithDefaultValue(value, 1.0); 537 GetUINativeModule().common.setOpacity(this.nodePtr, this.opacityValue); 538 } 539 set pivot(pivot) { 540 if (pivot === undefined || pivot === null) { 541 this.pivotValue = { x: 0.5, y: 0.5 }; 542 } 543 else { 544 this.pivotValue.x = this.checkUndefinedOrNullWithDefaultValue(pivot.x, 0.5); 545 this.pivotValue.y = this.checkUndefinedOrNullWithDefaultValue(pivot.y, 0.5); 546 } 547 GetUINativeModule().renderNode.setPivot(this.nodePtr, this.pivotValue.x, this.pivotValue.y); 548 } 549 set position(position) { 550 if (position === undefined || position === null) { 551 this.frameValue.x = 0; 552 this.frameValue.y = 0; 553 } 554 else { 555 this.frameValue.x = this.checkUndefinedOrNullWithDefaultValue(position.x, 0); 556 this.frameValue.y = this.checkUndefinedOrNullWithDefaultValue(position.y, 0); 557 } 558 GetUINativeModule().common.setPosition(this.nodePtr, this.frameValue.x, this.frameValue.y); 559 } 560 set rotation(rotation) { 561 if (rotation === undefined || rotation === null) { 562 this.rotationValue = { x: 0, y: 0, z: 0 }; 563 } 564 else { 565 this.rotationValue.x = this.checkUndefinedOrNullWithDefaultValue(rotation.x, 0); 566 this.rotationValue.y = this.checkUndefinedOrNullWithDefaultValue(rotation.y, 0); 567 this.rotationValue.z = this.checkUndefinedOrNullWithDefaultValue(rotation.z, 0); 568 } 569 GetUINativeModule().renderNode.setRotation(this.nodePtr, this.rotationValue.x, this.rotationValue.y, this.rotationValue.z); 570 } 571 set scale(scale) { 572 if (scale === undefined || scale === null) { 573 this.scaleValue = { x: 1.0, y: 1.0 }; 574 } 575 else { 576 this.scaleValue.x = this.checkUndefinedOrNullWithDefaultValue(scale.x, 1.0); 577 this.scaleValue.y = this.checkUndefinedOrNullWithDefaultValue(scale.y, 1.0); 578 } 579 GetUINativeModule().renderNode.setScale(this.nodePtr, this.scaleValue.x, this.scaleValue.y); 580 } 581 set shadowColor(color) { 582 this.shadowColorValue = this.checkUndefinedOrNullWithDefaultValue(color, 0); 583 GetUINativeModule().renderNode.setShadowColor(this.nodePtr, this.shadowColorValue); 584 } 585 set shadowOffset(offset) { 586 if (offset === undefined || offset === null) { 587 this.shadowOffsetValue = { x: 0, y: 0 }; 588 } 589 else { 590 this.shadowOffsetValue.x = this.checkUndefinedOrNullWithDefaultValue(offset.x, 0); 591 this.shadowOffsetValue.y = this.checkUndefinedOrNullWithDefaultValue(offset.y, 0); 592 } 593 GetUINativeModule().renderNode.setShadowOffset(this.nodePtr, this.shadowOffsetValue.x, this.shadowOffsetValue.y); 594 } 595 set shadowAlpha(alpha) { 596 this.shadowAlphaValue = this.checkUndefinedOrNullWithDefaultValue(alpha, 0); 597 GetUINativeModule().renderNode.setShadowAlpha(this.nodePtr, this.shadowAlphaValue); 598 } 599 set shadowElevation(elevation) { 600 this.shadowElevationValue = this.checkUndefinedOrNullWithDefaultValue(elevation, 0); 601 GetUINativeModule().renderNode.setShadowElevation(this.nodePtr, this.shadowElevationValue); 602 } 603 set shadowRadius(radius) { 604 this.shadowRadiusValue = this.checkUndefinedOrNullWithDefaultValue(radius, 0); 605 GetUINativeModule().renderNode.setShadowRadius(this.nodePtr, this.shadowRadiusValue); 606 } 607 set size(size) { 608 if (size === undefined || size === null) { 609 this.frameValue.width = 0; 610 this.frameValue.height = 0; 611 } 612 else { 613 this.frameValue.width = this.checkUndefinedOrNullWithDefaultValue(size.width, 0); 614 this.frameValue.height = this.checkUndefinedOrNullWithDefaultValue(size.height, 0); 615 } 616 GetUINativeModule().renderNode.setSize(this.nodePtr, this.frameValue.width, this.frameValue.height); 617 } 618 set transform(transform) { 619 if (transform === undefined || transform === null) { 620 this.transformValue = [1, 0, 0, 0, 621 0, 1, 0, 0, 622 0, 0, 1, 0, 623 0, 0, 0, 1]; 624 } 625 else { 626 let i = 0; 627 while (i < transform.length && i < 16) { 628 if (i % 5 === 0) { 629 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 1); 630 } 631 else { 632 this.transformValue[i] = this.checkUndefinedOrNullWithDefaultValue(transform[i], 0); 633 } 634 i = i + 1; 635 } 636 } 637 GetUINativeModule().common.setTransform(this.nodePtr, this.transformValue); 638 } 639 set translation(translation) { 640 if (translation === undefined || translation === null) { 641 this.translationValue = { x: 0, y: 0 }; 642 } 643 else { 644 this.translationValue.x = this.checkUndefinedOrNullWithDefaultValue(translation.x, 0); 645 this.translationValue.y = this.checkUndefinedOrNullWithDefaultValue(translation.y, 0); 646 } 647 GetUINativeModule().renderNode.setTranslate(this.nodePtr, this.translationValue.x, this.translationValue.y, 0); 648 } 649 get backgroundColor() { 650 return this.backgroundColorValue; 651 } 652 get clipToFrame() { 653 return this.clipToFrameValue; 654 } 655 get opacity() { 656 return this.opacityValue; 657 } 658 get frame() { 659 return this.frameValue; 660 } 661 get pivot() { 662 return this.pivotValue; 663 } 664 get position() { 665 return { x: this.frameValue.x, y: this.frameValue.y }; 666 } 667 get rotation() { 668 return this.rotationValue; 669 } 670 get scale() { 671 return this.scaleValue; 672 } 673 get shadowColor() { 674 return this.shadowColorValue; 675 } 676 get shadowOffset() { 677 return this.shadowOffsetValue; 678 } 679 get shadowAlpha() { 680 return this.shadowAlphaValue; 681 } 682 get shadowElevation() { 683 return this.shadowElevationValue; 684 } 685 get shadowRadius() { 686 return this.shadowRadiusValue; 687 } 688 get size() { 689 return { width: this.frameValue.width, height: this.frameValue.height }; 690 } 691 get transform() { 692 return this.transformValue; 693 } 694 get translation() { 695 return this.translationValue; 696 } 697 checkUndefinedOrNullWithDefaultValue(arg, defaultValue) { 698 if (arg === undefined || arg === null) { 699 return defaultValue; 700 } 701 else { 702 return arg; 703 } 704 } 705 appendChild(node) { 706 if (node === undefined || node === null) { 707 return; 708 } 709 if (this.childrenList.findIndex(element => element === node) !== -1) { 710 return; 711 } 712 this.childrenList.push(node); 713 node.parentRenderNode = this; 714 GetUINativeModule().renderNode.appendChild(this.nodePtr, node.nodePtr); 715 } 716 insertChildAfter(child, sibling) { 717 if (child === undefined || child === null) { 718 return; 719 } 720 let indexOfNode = this.childrenList.findIndex(element => element === child); 721 if (indexOfNode !== -1) { 722 return; 723 } 724 child.parentRenderNode = this; 725 let indexOfSibling = this.childrenList.findIndex(element => element === sibling); 726 if (indexOfSibling === -1) { 727 sibling === null; 728 } 729 if (sibling === undefined || sibling === null) { 730 this.childrenList.splice(0, 0, child); 731 GetUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, null); 732 } 733 else { 734 this.childrenList.splice(indexOfSibling + 1, 0, child); 735 GetUINativeModule().renderNode.insertChildAfter(this.nodePtr, child.nodePtr, sibling.nodePtr); 736 } 737 } 738 removeChild(node) { 739 if (node === undefined || node === null) { 740 return; 741 } 742 const index = this.childrenList.findIndex(element => element === node); 743 if (index === -1) { 744 return; 745 } 746 const child = this.childrenList[index]; 747 child.parentRenderNode = null; 748 this.childrenList.splice(index, 1); 749 GetUINativeModule().renderNode.removeChild(this.nodePtr, node.nodePtr); 750 } 751 clearChildren() { 752 this.childrenList = new Array(); 753 GetUINativeModule().renderNode.clearChildren(this.nodePtr); 754 } 755 getChild(index) { 756 if (this.childrenList.length > index && index >= 0) { 757 return this.childrenList[index]; 758 } 759 return null; 760 } 761 getFirstChild() { 762 if (this.childrenList.length > 0) { 763 return this.childrenList[0]; 764 } 765 return null; 766 } 767 getNextSibling() { 768 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 769 return null; 770 } 771 let siblingList = this.parentRenderNode.childrenList; 772 const index = siblingList.findIndex(element => element === this); 773 if (index === -1) { 774 return null; 775 } 776 return this.parentRenderNode.getChild(index + 1); 777 } 778 getPreviousSibling() { 779 if (this.parentRenderNode === undefined || this.parentRenderNode === null) { 780 return null; 781 } 782 let siblingList = this.parentRenderNode.childrenList; 783 const index = siblingList.findIndex(element => element === this); 784 if (index === -1) { 785 return null; 786 } 787 return this.parentRenderNode.getChild(index - 1); 788 } 789 setNodePtr(nodePtr) { 790 this.nodePtr = nodePtr; 791 } 792 setBaseNode(baseNode) { 793 this.baseNode_ = baseNode; 794 } 795 dispose() { 796 this.baseNode_.dispose(); 797 } 798 getNodePtr() { 799 return this.nodePtr; 800 } 801 draw(context) { 802 } 803 invalidate() { 804 GetUINativeModule().renderNode.invalidate(this.nodePtr); 805 } 806 set borderStyle(style) { 807 if (style === undefined || style === null) { 808 this.borderStyleValue = { left: BorderStyle.NONE, top: BorderStyle.NONE, right: BorderStyle.NONE, bottom: BorderStyle.NONE }; 809 } 810 else { 811 this.borderStyleValue = style; 812 } 813 GetUINativeModule().renderNode.setBorderStyle(this.nodePtr, this.borderStyleValue.left, this.borderStyleValue.top, this.borderStyleValue.right, this.borderStyleValue.bottom); 814 } 815 get borderStyle() { 816 return this.borderStyleValue; 817 } 818 set borderWidth(width) { 819 if (width === undefined || width === null) { 820 this.borderWidthValue = { left: 0, top: 0, right: 0, bottom: 0 }; 821 } 822 else { 823 this.borderWidthValue = width; 824 } 825 GetUINativeModule().renderNode.setBorderWidth(this.nodePtr, this.borderWidthValue.left, this.borderWidthValue.top, this.borderWidthValue.right, this.borderWidthValue.bottom); 826 } 827 get borderWidth() { 828 return this.borderWidthValue; 829 } 830 set borderColor(color) { 831 if (color === undefined || color === null) { 832 this.borderColorValue = { left: 0XFF000000, top: 0XFF000000, right: 0XFF000000, bottom: 0XFF000000 }; 833 } 834 else { 835 this.borderColorValue = color; 836 } 837 GetUINativeModule().renderNode.setBorderColor(this.nodePtr, this.borderColorValue.left, this.borderColorValue.top, this.borderColorValue.right, this.borderColorValue.bottom); 838 } 839 get borderColor() { 840 return this.borderColorValue; 841 } 842 set borderRadius(radius) { 843 if (radius === undefined || radius === null) { 844 this.borderRadiusValue = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0 }; 845 } 846 else { 847 this.borderRadiusValue = radius; 848 } 849 GetUINativeModule().renderNode.setBorderRadius(this.nodePtr, this.borderRadiusValue.topLeft, this.borderRadiusValue.topRight, this.borderRadiusValue.bottomLeft, this.borderRadiusValue.bottomRight); 850 } 851 get borderRadius() { 852 return this.borderRadiusValue; 853 } 854 set shapeMask(shapeMask) { 855 if (shapeMask === undefined || shapeMask === null) { 856 this.shapeMaskValue = new ShapeMask(); 857 } 858 else { 859 this.shapeMaskValue = shapeMask; 860 } 861 if (this.shapeMaskValue.rect !== null) { 862 const rectMask = this.shapeMaskValue.rect; 863 GetUINativeModule().renderNode.setRectMask(this.nodePtr, rectMask.left, rectMask.top, rectMask.right, rectMask.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 864 } 865 else if (this.shapeMaskValue.circle !== null) { 866 const circle = this.shapeMaskValue.circle; 867 GetUINativeModule().renderNode.setCircleMask(this.nodePtr, circle.centerX, circle.centerY, circle.radius, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 868 } 869 else if (this.shapeMaskValue.roundRect !== null) { 870 const reoundRect = this.shapeMask.roundRect; 871 const corners = reoundRect.corners; 872 const rect = reoundRect.rect; 873 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); 874 } 875 else if (this.shapeMaskValue.oval !== null) { 876 const oval = this.shapeMaskValue.oval; 877 GetUINativeModule().renderNode.setOvalMask(this.nodePtr, oval.left, oval.top, oval.right, oval.bottom, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 878 } 879 else if (this.shapeMaskValue.path !== null) { 880 const path = this.shapeMaskValue.path; 881 GetUINativeModule().renderNode.setPath(this.nodePtr, path.commands, this.shapeMaskValue.fillColor, this.shapeMaskValue.strokeColor, this.shapeMaskValue.strokeWidth); 882 } 883 } 884 get shapeMask() { 885 return this.shapeMaskValue; 886 } 887} 888function edgeColors(all) { 889 return { left: all, top: all, right: all, bottom: all }; 890} 891function edgeWidths(all) { 892 return { left: all, top: all, right: all, bottom: all }; 893} 894function borderStyles(all) { 895 return { left: all, top: all, right: all, bottom: all }; 896} 897function borderRadiuses(all) { 898 return { topLeft: all, topRight: all, bottomLeft: all, bottomRight: all }; 899} 900/* 901 * Copyright (c) 2023 Huawei Device Co., Ltd. 902 * Licensed under the Apache License, Version 2.0 (the "License"); 903 * you may not use this file except in compliance with the License. 904 * You may obtain a copy of the License at 905 * 906 * http://www.apache.org/licenses/LICENSE-2.0 907 * 908 * Unless required by applicable law or agreed to in writing, software 909 * distributed under the License is distributed on an "AS IS" BASIS, 910 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 911 * See the License for the specific language governing permissions and 912 * limitations under the License. 913 */ 914class XComponentNode extends FrameNode { 915 constructor(uiContext, options, id, type, libraryname) { 916 super(uiContext, 'XComponentNode'); 917 const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); 918 this.xcomponentNode_ = GetUINativeModule().xcomponentNode; 919 this.renderType_ = options.type; 920 const surfaceId = options.surfaceId; 921 const selfIdealWidth = options.selfIdealSize.width; 922 const selfIdealHeight = options.selfIdealSize.height; 923 this.nativeModule_ = this.xcomponentNode_.create(elmtId, id, type, this.renderType_, surfaceId, selfIdealWidth, selfIdealHeight, libraryname); 924 this.xcomponentNode_.registerOnCreateCallback(this.nativeModule_, this.onCreate); 925 this.xcomponentNode_.registerOnDestroyCallback(this.nativeModule_, this.onDestroy); 926 this.nodePtr_ = this.xcomponentNode_.getFrameNode(this.nativeModule_); 927 this.setNodePtr(this.nodePtr_); 928 } 929 onCreate(event) { } 930 onDestroy() { } 931 changeRenderType(type) { 932 if (this.renderType_ === type) { 933 return true; 934 } 935 if (this.xcomponentNode_.changeRenderType(this.nativeModule_, type)) { 936 this.renderType_ = type; 937 return true; 938 } 939 return false; 940 } 941} 942 943export default { NodeController, BuilderNode, BaseNode, RenderNode, FrameNode, NodeRenderType, XComponentNode, ShapeMask, edgeColors, edgeWidths, borderStyles, borderRadiuses }; 944