1/* 2 * Copyright (c) 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 */ 15 16/// <reference path='./import.ts' /> 17class SymbolSpanFontColorModifier extends ModifierWithKey<object> { 18 constructor(value: object) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('symbolSpanFontColor'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().symbolSpan.resetFontColor(node); 25 } else { 26 getUINativeModule().symbolSpan.setFontColor(node, this.value); 27 } 28 } 29 checkObjectDiff(): boolean { 30 if (isResource(this.stageValue) && isResource(this.value)) { 31 return !isResourceEqual(this.stageValue, this.value); 32 } else { 33 return true; 34 } 35 } 36} 37 38class SymbolSpanFontSizeModifier extends ModifierWithKey<number | string | Resource> { 39 constructor(value: number | string | Resource) { 40 super(value); 41 } 42 static identity: Symbol = Symbol('symbolSpanFontSize'); 43 applyPeer(node: KNode, reset: boolean): void { 44 if (reset) { 45 getUINativeModule().symbolSpan.resetFontSize(node); 46 } else { 47 getUINativeModule().symbolSpan.setFontSize(node, this.value); 48 } 49 } 50 51 checkObjectDiff(): boolean { 52 if (isResource(this.stageValue) && isResource(this.value)) { 53 return !isResourceEqual(this.stageValue, this.value); 54 } else { 55 return true; 56 } 57 } 58} 59 60class SymbolSpanFontWeightModifier extends ModifierWithKey<number | FontWeight | string> { 61 constructor(value: number | FontWeight | string) { 62 super(value); 63 } 64 static identity: Symbol = Symbol('symbolSpanFontWeight'); 65 applyPeer(node: KNode, reset: boolean): void { 66 if (reset) { 67 getUINativeModule().symbolSpan.resetFontWeight(node); 68 } else { 69 getUINativeModule().symbolSpan.setFontWeight(node, this.value); 70 } 71 } 72 checkObjectDiff(): boolean { 73 if (isResource(this.stageValue) && isResource(this.value)) { 74 return !isResourceEqual(this.stageValue, this.value); 75 } else { 76 return true; 77 } 78 } 79} 80 81class SymbolSpanEffectStrategyModifier extends ModifierWithKey<SymbolEffectStrategy> { 82 constructor(value: SymbolEffectStrategy) { 83 super(value); 84 } 85 static identity: Symbol = Symbol('symbolSpanEffectStrategy'); 86 applyPeer(node: KNode, reset: boolean): void { 87 if (reset) { 88 getUINativeModule().symbolSpan.resetEffectStrategy(node); 89 } else { 90 getUINativeModule().symbolSpan.setEffectStrategy(node, this.value); 91 } 92 } 93 94 checkObjectDiff(): boolean { 95 if (isResource(this.stageValue) && isResource(this.value)) { 96 return !isResourceEqual(this.stageValue, this.value); 97 } else { 98 return true; 99 } 100 } 101} 102 103class SymbolSpanRenderingStrategyModifier extends ModifierWithKey<SymbolRenderingStrategy> { 104 constructor(value: SymbolRenderingStrategy) { 105 super(value); 106 } 107 static identity: Symbol = Symbol('symbolSpanRenderingStrategy'); 108 applyPeer(node: KNode, reset: boolean): void { 109 if (reset) { 110 getUINativeModule().symbolSpan.resetRenderingStrategy(node); 111 } else { 112 getUINativeModule().symbolSpan.setRenderingStrategy(node, this.value); 113 } 114 } 115 checkObjectDiff(): boolean { 116 if (isResource(this.stageValue) && isResource(this.value)) { 117 return !isResourceEqual(this.stageValue, this.value); 118 } else { 119 return true; 120 } 121 } 122} 123 124class SymbolSpanIdModifier extends ModifierWithKey<Resource> { 125 constructor(value: Resource) { 126 super(value); 127 } 128 static identity: Symbol = Symbol('symbolSpanId'); 129 applyPeer(node: KNode, reset: boolean): void { 130 if (reset) { 131 getUINativeModule().symbolSpan.setId(node, ''); 132 } 133 else { 134 getUINativeModule().symbolSpan.setId(node, this.value); 135 } 136 } 137} 138 139class ArkSymbolSpanComponent extends ArkComponent implements SymbolSpanAttribute { 140 constructor(nativePtr: KNode, classType?: ModifierType) { 141 super(nativePtr, classType); 142 } 143 initialize(value: Object[]): SymbolSpanAttribute { 144 if (value[0] !== undefined) { 145 modifierWithKey(this._modifiersWithKeys, SymbolSpanIdModifier.identity, SymbolSpanIdModifier, value[0]); 146 } 147 return this; 148 } 149 fontSize(value: number | string | Resource): SymbolSpanAttribute { 150 modifierWithKey(this._modifiersWithKeys, SymbolSpanFontSizeModifier.identity, 151 SymbolSpanFontSizeModifier, value); 152 return this; 153 } 154 fontColor(value: object): SymbolSpanAttribute { 155 modifierWithKey(this._modifiersWithKeys, SymbolSpanFontColorModifier.identity, 156 SymbolSpanFontColorModifier, value); 157 return this; 158 } 159 fontWeight(value: number | FontWeight | string): SymbolSpanAttribute { 160 let fontWeightStr: string = '400'; 161 if (isNumber(value)) { 162 fontWeightStr = value.toString(); 163 } else if (isString(value)) { 164 fontWeightStr = String(value); 165 } 166 modifierWithKey(this._modifiersWithKeys, SymbolSpanFontWeightModifier.identity, 167 SymbolSpanFontWeightModifier, fontWeightStr); 168 return this; 169 } 170 effectStrategy(value: SymbolEffectStrategy): SymbolSpanAttribute { 171 modifierWithKey(this._modifiersWithKeys, SymbolSpanEffectStrategyModifier.identity, 172 SymbolSpanEffectStrategyModifier, value); 173 return this; 174 } 175 renderingStrategy(value: SymbolRenderingStrategy): SymbolSpanAttribute { 176 modifierWithKey(this._modifiersWithKeys, SymbolSpanRenderingStrategyModifier.identity, 177 SymbolSpanRenderingStrategyModifier, value); 178 return this; 179 } 180} 181 182// @ts-ignore 183globalThis.SymbolSpan.attributeModifier = function (modifier: ArkComponent): void { 184 attributeModifierFuncWithoutStateStyles.call(this, modifier, (nativePtr: KNode) => { 185 return new ArkSymbolSpanComponent(nativePtr); 186 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 187 return new modifierJS.SymbolSpanModifier(undefined, nativePtr, classType); 188 }); 189};