1/* 2 * Copyright (c) 2022 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' /> 17interface CommonShapeOptionsParam { 18 width?: Length; 19 height?: Length; 20} 21class ArkCommonShapeComponent extends ArkComponent implements CommonShapeMethod<ShapeAttribute> { 22 constructor(nativePtr: KNode, classType?: ModifierType) { 23 super(nativePtr, classType); 24 } 25 viewPort(value: { 26 x?: Length | undefined; 27 y?: Length | undefined; 28 width?: Length | undefined; 29 height?: Length | undefined; 30 }): this { 31 throw new Error('Method not implemented.'); 32 } 33 stroke(value: ResourceColor): this { 34 modifierWithKey(this._modifiersWithKeys, StrokeModifier.identity, StrokeModifier, value); 35 return this; 36 } 37 fill(value: ResourceColor): this { 38 modifierWithKey(this._modifiersWithKeys, FillModifier.identity, FillModifier, value); 39 return this; 40 } 41 strokeDashOffset(value: Length): this { 42 modifierWithKey(this._modifiersWithKeys, StrokeDashOffsetModifier.identity, 43 StrokeDashOffsetModifier, value); 44 return this; 45 } 46 strokeLineCap(value: LineCapStyle): this { 47 modifierWithKey(this._modifiersWithKeys, StrokeLineCapModifier.identity, StrokeLineCapModifier, value); 48 return this; 49 } 50 strokeLineJoin(value: LineJoinStyle): this { 51 modifierWithKey(this._modifiersWithKeys, StrokeLineJoinModifier.identity, StrokeLineJoinModifier, value); 52 return this; 53 } 54 strokeMiterLimit(value: Length): this { 55 modifierWithKey(this._modifiersWithKeys, StrokeMiterLimitModifier.identity, 56 StrokeMiterLimitModifier, value); 57 return this; 58 } 59 strokeOpacity(value: number | string | Resource): this { 60 modifierWithKey(this._modifiersWithKeys, StrokeOpacityModifier.identity, StrokeOpacityModifier, value); 61 return this; 62 } 63 fillOpacity(value: number | string | Resource): this { 64 modifierWithKey(this._modifiersWithKeys, FillOpacityModifier.identity, FillOpacityModifier, value); 65 return this; 66 } 67 strokeWidth(value: Length): this { 68 modifierWithKey(this._modifiersWithKeys, StrokeWidthModifier.identity, StrokeWidthModifier, value); 69 return this; 70 } 71 antiAlias(value: boolean): this { 72 modifierWithKey(this._modifiersWithKeys, AntiAliasModifier.identity, AntiAliasModifier, value); 73 return this; 74 } 75 strokeDashArray(value: any[]): this { 76 modifierWithKey(this._modifiersWithKeys, StrokeDashArrayModifier.identity, StrokeDashArrayModifier, value); 77 return this; 78 } 79 mesh(value: any[], column: number, row: number): this { 80 throw new Error('Method not implemented.'); 81 } 82 height(value: Length): this { 83 modifierWithKey(this._modifiersWithKeys, CommonShapeHeightModifier.identity, CommonShapeHeightModifier, value); 84 return this; 85 } 86 width(value: Length): this { 87 modifierWithKey(this._modifiersWithKeys, CommonShapeWidthModifier.identity, CommonShapeWidthModifier, value); 88 return this; 89 } 90 foregroundColor(value: string | number | Resource | Color): this { 91 modifierWithKey( 92 this._modifiersWithKeys, CommonShapeForegroundColorModifier.identity, CommonShapeForegroundColorModifier, value); 93 return this; 94 } 95 resetCommonShapeOptions(): void { 96 modifierWithKey(this._modifiersWithKeys, CommonShapeWidthModifier.identity, 97 CommonShapeWidthModifier, undefined); 98 modifierWithKey(this._modifiersWithKeys, CommonShapeHeightModifier.identity, 99 CommonShapeHeightModifier, undefined); 100 } 101 initialize(value: Object[]): this { 102 if (isUndefined(value[0]) || isNull(value[0])) { 103 this.resetCommonShapeOptions(); 104 return this; 105 } 106 const value_casted = value[0] as CommonShapeOptionsParam; 107 if (!isUndefined(value_casted.width) && !isNull(value_casted.width)) { 108 modifierWithKey(this._modifiersWithKeys, CommonShapeWidthModifier.identity, 109 CommonShapeWidthModifier, value_casted.width); 110 } else { 111 modifierWithKey(this._modifiersWithKeys, CommonShapeWidthModifier.identity, 112 CommonShapeWidthModifier, undefined); 113 } 114 if (!isUndefined(value_casted.height) && !isNull(value_casted.height)) { 115 modifierWithKey(this._modifiersWithKeys, CommonShapeHeightModifier.identity, 116 CommonShapeHeightModifier, value_casted.height); 117 } else { 118 modifierWithKey(this._modifiersWithKeys, CommonShapeHeightModifier.identity, 119 CommonShapeHeightModifier, undefined); 120 } 121 return this; 122 } 123} 124 125class StrokeDashArrayModifier extends ModifierWithKey<object> { 126 constructor(value: object) { 127 super(value); 128 } 129 static identity: Symbol = Symbol('strokeDashArray'); 130 applyPeer(node: KNode, reset: boolean): void { 131 if (reset) { 132 getUINativeModule().commonShape.resetStrokeDashArray(node); 133 } else { 134 getUINativeModule().commonShape.setStrokeDashArray(node, this.value); 135 } 136 } 137 138 checkObjectDiff(): boolean { 139 return !isBaseOrResourceEqual(this.stageValue, this.value); 140 } 141} 142 143class StrokeModifier extends ModifierWithKey<ResourceColor> { 144 constructor(value: ResourceColor) { 145 super(value); 146 } 147 static identity: Symbol = Symbol('stroke'); 148 applyPeer(node: KNode, reset: boolean): void { 149 if (reset) { 150 getUINativeModule().commonShape.resetStroke(node); 151 } else { 152 getUINativeModule().commonShape.setStroke(node, this.value); 153 } 154 } 155 156 checkObjectDiff(): boolean { 157 return !isBaseOrResourceEqual(this.stageValue, this.value); 158 } 159} 160 161class FillModifier extends ModifierWithKey<ResourceColor> { 162 constructor(value: ResourceColor) { 163 super(value); 164 } 165 static identity: Symbol = Symbol('fill'); 166 applyPeer(node: KNode, reset: boolean): void { 167 if (reset) { 168 getUINativeModule().commonShape.resetFill(node); 169 } else { 170 getUINativeModule().commonShape.setFill(node, this.value); 171 } 172 } 173 174 checkObjectDiff(): boolean { 175 return !isBaseOrResourceEqual(this.stageValue, this.value); 176 } 177} 178 179class StrokeDashOffsetModifier extends ModifierWithKey<Length> { 180 constructor(value: Length) { 181 super(value); 182 } 183 static identity: Symbol = Symbol('strokeDashOffset'); 184 applyPeer(node: KNode, reset: boolean): void { 185 if (reset) { 186 getUINativeModule().commonShape.resetStrokeDashOffset(node); 187 } else { 188 getUINativeModule().commonShape.setStrokeDashOffset(node, this.value); 189 } 190 } 191 192 checkObjectDiff(): boolean { 193 return !isBaseOrResourceEqual(this.stageValue, this.value); 194 } 195} 196 197class StrokeLineCapModifier extends ModifierWithKey<number> { 198 constructor(value: number) { 199 super(value); 200 } 201 static identity: Symbol = Symbol('strokeLineCap'); 202 applyPeer(node: KNode, reset: boolean): void { 203 if (reset) { 204 getUINativeModule().commonShape.resetStrokeLineCap(node); 205 } else { 206 getUINativeModule().commonShape.setStrokeLineCap(node, this.value); 207 } 208 } 209} 210 211class StrokeLineJoinModifier extends ModifierWithKey<number> { 212 constructor(value: number) { 213 super(value); 214 } 215 static identity: Symbol = Symbol('strokeLineJoin'); 216 applyPeer(node: KNode, reset: boolean): void { 217 if (reset) { 218 getUINativeModule().commonShape.resetStrokeLineJoin(node); 219 } else { 220 getUINativeModule().commonShape.setStrokeLineJoin(node, this.value); 221 } 222 } 223} 224 225class StrokeMiterLimitModifier extends ModifierWithKey<Length> { 226 constructor(value: Length) { 227 super(value); 228 } 229 static identity: Symbol = Symbol('strokeMiterLimit'); 230 applyPeer(node: KNode, reset: boolean): void { 231 if (reset) { 232 getUINativeModule().commonShape.resetStrokeMiterLimit(node); 233 } else { 234 getUINativeModule().commonShape.setStrokeMiterLimit(node, this.value); 235 } 236 } 237} 238 239class FillOpacityModifier extends ModifierWithKey<number | string | Resource> { 240 constructor(value: number | string | Resource) { 241 super(value); 242 } 243 static identity: Symbol = Symbol('FillOpacity'); 244 applyPeer(node: KNode, reset: boolean): void { 245 if (reset) { 246 getUINativeModule().commonShape.resetFillOpacity(node); 247 } else { 248 getUINativeModule().commonShape.setFillOpacity(node, this.value); 249 } 250 } 251 checkObjectDiff(): boolean { 252 return !isBaseOrResourceEqual(this.stageValue, this.value); 253 } 254} 255 256class StrokeOpacityModifier extends ModifierWithKey<number | string | Resource> { 257 constructor(value: number | string | Resource) { 258 super(value); 259 } 260 static identity: Symbol = Symbol('StrokeOpacity'); 261 applyPeer(node: KNode, reset: boolean): void { 262 if (reset) { 263 getUINativeModule().commonShape.resetStrokeOpacity(node); 264 } else { 265 getUINativeModule().commonShape.setStrokeOpacity(node, this.value); 266 } 267 } 268 checkObjectDiff(): boolean { 269 return !isBaseOrResourceEqual(this.stageValue, this.value); 270 } 271} 272 273class StrokeWidthModifier extends ModifierWithKey<Length> { 274 constructor(value: Length) { 275 super(value); 276 } 277 static identity: Symbol = Symbol('strokeWidth'); 278 applyPeer(node: KNode, reset: boolean): void { 279 if (reset) { 280 getUINativeModule().commonShape.resetStrokeWidth(node); 281 } else { 282 getUINativeModule().commonShape.setStrokeWidth(node, this.value); 283 } 284 } 285} 286 287class AntiAliasModifier extends ModifierWithKey<boolean> { 288 constructor(value: boolean) { 289 super(value); 290 } 291 static identity: Symbol = Symbol('antiAlias'); 292 applyPeer(node: KNode, reset: boolean): void { 293 if (reset) { 294 getUINativeModule().commonShape.resetAntiAlias(node); 295 } else { 296 getUINativeModule().commonShape.setAntiAlias(node, this.value); 297 } 298 } 299} 300 301class CommonShapeHeightModifier extends ModifierWithKey<Length> { 302 constructor(value: Length) { 303 super(value); 304 } 305 static identity: Symbol = Symbol('commonShapeHeight'); 306 applyPeer(node: KNode, reset: boolean): void { 307 if (reset) { 308 getUINativeModule().commonShape.resetHeight(node); 309 } else { 310 getUINativeModule().commonShape.setHeight(node, this.value); 311 } 312 } 313 checkObjectDiff(): boolean { 314 return !isBaseOrResourceEqual(this.stageValue, this.value); 315 } 316} 317 318class CommonShapeWidthModifier extends ModifierWithKey<Length> { 319 constructor(value: Length) { 320 super(value); 321 } 322 static identity: Symbol = Symbol('commonShapeWidth'); 323 applyPeer(node: KNode, reset: boolean): void { 324 if (reset) { 325 getUINativeModule().commonShape.resetWidth(node); 326 } else { 327 getUINativeModule().commonShape.setWidth(node, this.value); 328 } 329 } 330 checkObjectDiff(): boolean { 331 return !isBaseOrResourceEqual(this.stageValue, this.value); 332 } 333} 334 335class CommonShapeForegroundColorModifier extends ModifierWithKey<string | number | Resource | Color> { 336 constructor(value: string | number | Resource | Color) { 337 super(value); 338 } 339 static identity: Symbol = Symbol('commonShapeForegroundColor'); 340 applyPeer(node: KNode, reset: boolean): void { 341 if (reset) { 342 getUINativeModule().commonShape.resetForegroundColor(node); 343 } else { 344 getUINativeModule().commonShape.setForegroundColor(node, this.value); 345 } 346 } 347 checkObjectDiff(): boolean { 348 return !isBaseOrResourceEqual(this.stageValue, this.value); 349 } 350}