all files / document-editor/implementation/format/ border.js

88.24% Statements 285/323
86.26% Branches 182/211
97.14% Functions 34/35
88.24% Lines 285/323
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 5771×   1× 1× 1× 24045229× 24045229× 24045229×   1×   420367×     4943×         1×   1435542×     24678×         1×   561814×     24663×         1×   365781×     19772×         1×   367330×     19771×         1×   261944×     18411×         1×   129507×           1× 3412778× 3412778× 716976× 716976× 716976× 716976× 716976×       2695802×   1× 112238× 13×   112238× 24678×     87560× 87560×   2×   87558×     1× 24678× 24678× 24678× 24678× 24678× 24678× 24678× 24678×   1× 148068× 148068× 24678×     1× 2695815× 2695815×   402186× 402186×   1052741× 1052741×   343137× 343137×   344153× 344153×   343456× 343456×   210142× 210142×   2695815×   1× 103652×     25347×                             134× 134× 134× 566×   134×                 77995×   22×   22×     89×   43×   1× 134× 134×   6× 6×   6× 6×   5× 5×   4× 4×   5× 5×   4× 4×   22× 22×   6× 6×   6× 6×   4× 4×   22× 22×     44× 44×   134×     134× 566× 402×     164×     134×   1× 35018× 35018× 35018×                                               33870× 33870×     3× 3×   35018×   1× 35018× 35018×   33584× 33584×   1× 1×   1× 1×   1× 1×   2× 2×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   45× 45×   1× 1×   45× 45×   1× 1×   1× 1×   45× 45×   1× 1×   133× 133×   1× 1×   35018×   1×                                                                                                                                 1× 34830× 34830×   33433× 33433×   1× 1×   1× 1×   1× 1×   2× 2×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   1× 1×   2× 2×   2× 2×   2× 2×   46× 46×   1× 1×   45× 45×   1× 1×   1× 1×   46× 46×   1× 1×   134× 134×   1× 1×   34830×   1× 1586601×   1× 13667308× 918564× 918564×   12748744×   1× 1346× 1346× 1346× 1346× 1346× 1346× 1346×   1× 236885× 14746×   236885×   1× 173429× 173429×   1× 141552× 141552×     140887×   141552×   1× 99122× 8927× 1083×   8927× 8926×   8927× 8926×   8927× 5447×   8927× 5447×   8927× 5432×       1× 41×   1× 1× 1×   1×    
define(["require", "exports", "../../base/dictionary", "../../base/unique-format", "../../base/unique-formats", "@syncfusion/ej2-base"], function (require, exports, dictionary_1, unique_format_1, unique_formats_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WBorder = (function () {
        function WBorder(node) {
            this.uniqueBorderFormat = undefined;
            this.ownerBase = undefined;
            this.ownerBase = node;
        }
        Object.defineProperty(WBorder.prototype, "color", {
            get: function () {
                return this.getPropertyValue('color');
            },
            set: function (value) {
                this.setPropertyValue('color', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "lineStyle", {
            get: function () {
                return this.getPropertyValue('lineStyle');
            },
            set: function (value) {
                this.setPropertyValue('lineStyle', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "lineWidth", {
            get: function () {
                return this.getPropertyValue('lineWidth');
            },
            set: function (value) {
                this.setPropertyValue('lineWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "shadow", {
            get: function () {
                return this.getPropertyValue('shadow');
            },
            set: function (value) {
                this.setPropertyValue('shadow', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "space", {
            get: function () {
                return this.getPropertyValue('space');
            },
            set: function (value) {
                this.setPropertyValue('space', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "hasNoneStyle", {
            get: function () {
                return this.getPropertyValue('hasNoneStyle');
            },
            set: function (value) {
                this.setPropertyValue('hasNoneStyle', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WBorder.prototype, "isBorderDefined", {
            get: function () {
                return (this.lineStyle !== 'None' ||
                    (this.hasNoneStyle && this.hasValue('hasNoneStyle')));
            },
            enumerable: true,
            configurable: true
        });
        WBorder.prototype.getPropertyValue = function (property) {
            var hasValue = this.hasValue(property);
            if (hasValue) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WBorder.uniqueFormatType, property);
                Eif (!ej2_base_1.isNullOrUndefined(this.uniqueBorderFormat)) {
                    var propValue = this.uniqueBorderFormat.propertiesHash.get(propertyType);
                    Eif (!ej2_base_1.isNullOrUndefined(propValue)) {
                        return propValue;
                    }
                }
            }
            return WBorder.getPropertyDefaultValue(property);
        };
        WBorder.prototype.setPropertyValue = function (property, value) {
            if (ej2_base_1.isNullOrUndefined(value) || value === '') {
                value = WBorder.getPropertyDefaultValue(property);
            }
            if (ej2_base_1.isNullOrUndefined(this.uniqueBorderFormat)) {
                this.initializeUniqueBorder(property, value);
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueBorderFormat.uniqueFormatType, property);
                if (this.uniqueBorderFormat.propertiesHash.containsKey(propertyType) &&
                    this.uniqueBorderFormat.propertiesHash.get(propertyType) === value) {
                    return;
                }
                this.uniqueBorderFormat = WBorder.uniqueBorderFormats.updateUniqueFormat(this.uniqueBorderFormat, property, value);
            }
        };
        WBorder.prototype.initializeUniqueBorder = function (property, propValue) {
            var uniqueBorderFormatTemp = new dictionary_1.Dictionary();
            this.addUniqueBorderFormat('color', property, propValue, uniqueBorderFormatTemp);
            this.addUniqueBorderFormat('lineStyle', property, propValue, uniqueBorderFormatTemp);
            this.addUniqueBorderFormat('lineWidth', property, propValue, uniqueBorderFormatTemp);
            this.addUniqueBorderFormat('shadow', property, propValue, uniqueBorderFormatTemp);
            this.addUniqueBorderFormat('space', property, propValue, uniqueBorderFormatTemp);
            this.addUniqueBorderFormat('hasNoneStyle', property, propValue, uniqueBorderFormatTemp);
            this.uniqueBorderFormat = WBorder.uniqueBorderFormats.addUniqueFormat(uniqueBorderFormatTemp, WBorder.uniqueFormatType);
        };
        WBorder.prototype.addUniqueBorderFormat = function (property, modifiedProperty, propValue, uniqueBorderFormatTemp) {
            var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WBorder.uniqueFormatType, property);
            if (property === modifiedProperty) {
                uniqueBorderFormatTemp.add(propertyType, propValue);
            }
        };
        WBorder.getPropertyDefaultValue = function (property) {
            var value = undefined;
            switch (property) {
                case 'color':
                    value = '#000000';
                    break;
                case 'lineStyle':
                    value = 'None';
                    break;
                case 'lineWidth':
                    value = 0;
                    break;
                case 'shadow':
                    value = false;
                    break;
                case 'space':
                    value = 0;
                    break;
                case 'hasNoneStyle':
                    value = false;
                    break;
            }
            return value;
        };
        WBorder.prototype.getLineWidth = function () {
            switch (this.lineStyle) {
                case 'None':
                case 'Cleared':
                    return 0;
                case 'Triple':
                case 'Double':
                case 'ThinThickSmallGap':
                case 'ThickThinSmallGap':
                case 'ThinThickThinSmallGap':
                case 'ThinThickMediumGap':
                case 'ThickThinMediumGap':
                case 'ThinThickThinMediumGap':
                case 'ThinThickLargeGap':
                case 'ThickThinLargeGap':
                case 'ThinThickThinLargeGap':
                case 'Emboss3D':
                case 'Engrave3D':
                    {
                        var lineArray = this.getBorderLineWidthArray(this.lineStyle, this.lineWidth);
                        var width = 0;
                        for (var i = 0; i < lineArray.length; i++) {
                            width += lineArray[i];
                        }
                        return width;
                    }
                case 'Single':
                case 'DashLargeGap':
                case 'DashSmallGap':
                case 'Dot':
                case 'DashDot':
                case 'DashDotDot':
                case 'Thick':
                    return (this.lineWidth >= 0.5 ? this.lineWidth : 0.5);
                case 'SingleWavy':
                    return (this.lineWidth === 1.5 ? 3 : 2.5);
                case 'DoubleWavy':
                    return (6.75);
                case 'DashDotStroked':
                case 'Outset':
                    return (this.lineWidth >= 0.5 ? this.lineWidth : 0.5);
            }
            return (this.lineWidth >= 0.5 ? this.lineWidth : 0.5);
        };
        WBorder.prototype.getBorderLineWidthArray = function (lineStyle, lineWidth) {
            var borderLineArray = [lineWidth];
            switch (lineStyle) {
                case 'Double':
                    borderLineArray = [1, 1, 1];
                    break;
                case 'ThinThickSmallGap':
                    borderLineArray = [1, -0.75, -0.75];
                    break;
                case 'ThickThinSmallGap':
                    borderLineArray = [-0.75, -0.75, 1];
                    break;
                case 'ThinThickMediumGap':
                    borderLineArray = [1, 0.5, 0.5];
                    break;
                case 'ThickThinMediumGap':
                    borderLineArray = [0.5, 0.5, 1];
                    break;
                case 'ThinThickLargeGap':
                    borderLineArray = [-1.5, 1, -0.75];
                    break;
                case 'ThickThinLargeGap':
                    borderLineArray = [-0.75, 1, -1.5];
                    break;
                case 'Triple':
                    borderLineArray = [1, 1, 1, 1, 1];
                    break;
                case 'ThinThickThinSmallGap':
                    borderLineArray = [-0.75, -0.75, 1, -0.75, -0.75];
                    break;
                case 'ThinThickThinMediumGap':
                    borderLineArray = [0.5, 0.5, 1, 0.5, 0.5];
                    break;
                case 'ThinThickThinLargeGap':
                    borderLineArray = [-0.75, 1, -1.5, 1, -0.75];
                    break;
                case 'Emboss3D':
                case 'Engrave3D':
                    borderLineArray = [0.25, 0, 1, 0, 0.25];
                    break;
            }
            Iif (borderLineArray.length === 1) {
                return [lineWidth];
            }
            for (var i = 0; i < borderLineArray.length; i++) {
                if (borderLineArray[parseInt(i.toString(), 10)] >= 0) {
                    borderLineArray[parseInt(i.toString(), 10)] = borderLineArray[parseInt(i.toString(), 10)] * lineWidth;
                }
                else {
                    borderLineArray[parseInt(i.toString(), 10)] = Math.abs(borderLineArray[parseInt(i.toString(), 10)]);
                }
            }
            return borderLineArray;
        };
        WBorder.prototype.getBorderWeight = function () {
            var weight = 0;
            var borderNumber = this.getBorderNumber();
            switch (this.lineStyle) {
                case 'Single':
                case 'DashSmallGap':
                case 'DashDot':
                case 'DashDotDot':
                case 'Double':
                case 'Triple':
                case 'ThinThickSmallGap':
                case 'ThickThinSmallGap':
                case 'ThinThickThinSmallGap':
                case 'ThinThickMediumGap':
                case 'ThickThinMediumGap':
                case 'ThinThickThinMediumGap':
                case 'ThinThickLargeGap':
                case 'ThickThinLargeGap':
                case 'ThinThickThinLargeGap':
                case 'SingleWavy':
                case 'DoubleWavy':
                case 'DashDotStroked':
                case 'Emboss3D':
                case 'Engrave3D':
                case 'Outset':
                case 'Inset':
                case 'Thick':
                    weight = this.lineWidth * borderNumber;
                    break;
                case 'Dot':
                case 'DashLargeGap':
                    weight = 1;
                    break;
            }
            return weight;
        };
        WBorder.prototype.getBorderNumber = function () {
            var borderNumber = 0;
            switch (this.lineStyle) {
                case 'Single':
                    borderNumber = 1;
                    break;
                case 'Thick':
                    borderNumber = 2;
                    break;
                case 'Double':
                    borderNumber = 3;
                    break;
                case 'Dot':
                    borderNumber = 4;
                    break;
                case 'DashLargeGap':
                    borderNumber = 5;
                    break;
                case 'DashDot':
                    borderNumber = 6;
                    break;
                case 'DashDotDot':
                    borderNumber = 7;
                    break;
                case 'Triple':
                    borderNumber = 8;
                    break;
                case 'ThinThickSmallGap':
                    borderNumber = 9;
                    break;
                case 'ThickThinSmallGap':
                    borderNumber = 10;
                    break;
                case 'ThinThickThinSmallGap':
                    borderNumber = 11;
                    break;
                case 'ThinThickMediumGap':
                    borderNumber = 12;
                    break;
                case 'ThickThinMediumGap':
                    borderNumber = 13;
                    break;
                case 'ThinThickThinMediumGap':
                    borderNumber = 14;
                    break;
                case 'ThinThickLargeGap':
                    borderNumber = 15;
                    break;
                case 'ThickThinLargeGap':
                    borderNumber = 16;
                    break;
                case 'ThinThickThinLargeGap':
                    borderNumber = 17;
                    break;
                case 'SingleWavy':
                    borderNumber = 18;
                    break;
                case 'DoubleWavy':
                    borderNumber = 19;
                    break;
                case 'DashSmallGap':
                    borderNumber = 20;
                    break;
                case 'DashDotStroked':
                    borderNumber = 21;
                    break;
                case 'Emboss3D':
                    borderNumber = 22;
                    break;
                case 'Engrave3D':
                    borderNumber = 23;
                    break;
                case 'Outset':
                    borderNumber = 24;
                    break;
                case 'Inset':
                    borderNumber = 25;
                    break;
            }
            return borderNumber;
        };
        WBorder.prototype.getNumberOfLines = function () {
            var value = 0;
            switch (this.lineStyle) {
                case 'Single':
                case 'Dot':
                case 'DashSmallGap':
                case 'DashLargeGap':
                case 'DashDot':
                case 'DashDotDot':
                    value = 1;
                    break;
                case 'Double':
                    value = 3;
                    break;
                case 'Triple':
                    value = 5;
                    break;
                case 'ThinThickSmallGap':
                    value = 3;
                    break;
                case 'ThickThinSmallGap':
                    value = 3;
                    break;
                case 'ThinThickThinSmallGap':
                    value = 5;
                    break;
                case 'ThinThickMediumGap':
                    value = 3;
                    break;
                case 'ThickThinMediumGap':
                    value = 3;
                    break;
                case 'ThinThickThinMediumGap':
                    value = 5;
                    break;
                case 'ThinThickLargeGap':
                    value = 3;
                    break;
                case 'ThickThinLargeGap':
                    value = 3;
                    break;
                case 'ThinThickThinLargeGap':
                    value = 5;
                    break;
                case 'SingleWavy':
                    value = 1;
                    break;
                case 'DoubleWavy':
                    value = 2;
                    break;
                case 'DashDotStroked':
                    value = 1;
                    break;
                case 'Emboss3D':
                case 'Engrave3D':
                    value = 3;
                    break;
                case 'Outset':
                case 'Inset':
                case 'Thick':
                    value = 1;
                    break;
            }
            return value;
        };
        WBorder.prototype.getPrecedence = function () {
            var value = 0;
            switch (this.lineStyle) {
                case 'Single':
                    value = 1;
                    break;
                case 'Thick':
                    value = 2;
                    break;
                case 'Double':
                    value = 3;
                    break;
                case 'Dot':
                    value = 4;
                    break;
                case 'DashLargeGap':
                    value = 5;
                    break;
                case 'DashDot':
                    value = 6;
                    break;
                case 'DashDotDot':
                    value = 7;
                    break;
                case 'Triple':
                    value = 8;
                    break;
                case 'ThinThickSmallGap':
                    value = 9;
                    break;
                case 'ThickThinSmallGap':
                    value = 10;
                    break;
                case 'ThinThickThinSmallGap':
                    value = 11;
                    break;
                case 'ThinThickMediumGap':
                    value = 12;
                    break;
                case 'ThickThinMediumGap':
                    value = 13;
                    break;
                case 'ThinThickThinMediumGap':
                    value = 14;
                    break;
                case 'ThinThickLargeGap':
                    value = 15;
                    break;
                case 'ThickThinLargeGap':
                    value = 16;
                    break;
                case 'ThinThickThinLargeGap':
                    value = 17;
                    break;
                case 'SingleWavy':
                    value = 18;
                    break;
                case 'DoubleWavy':
                    value = 19;
                    break;
                case 'DashSmallGap':
                    value = 20;
                    break;
                case 'DashDotStroked':
                    value = 21;
                    break;
                case 'Emboss3D':
                    value = 22;
                    break;
                case 'Engrave3D':
                    value = 23;
                    break;
                case 'Outset':
                    value = 24;
                    break;
                case 'Inset':
                    value = 25;
                    break;
            }
            return value;
        };
        WBorder.prototype.hasValues = function () {
            return this.hasValue('color') || this.hasValue('lineStyle') || this.hasValue('lineWidth') || this.hasValue('shadow') || this.hasValue('space') || this.hasValue('hasNoneStyle');
        };
        WBorder.prototype.hasValue = function (property) {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueBorderFormat)) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueBorderFormat.uniqueFormatType, property);
                return this.uniqueBorderFormat.propertiesHash.containsKey(propertyType);
            }
            return false;
        };
        WBorder.prototype.cloneFormat = function () {
            var border = new WBorder(undefined);
            border.color = this.color;
            border.lineStyle = this.lineStyle;
            border.lineWidth = this.lineWidth;
            border.shadow = this.shadow;
            border.space = this.space;
            return border;
        };
        WBorder.prototype.clearFormat = function () {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueBorderFormat)) {
                WBorder.uniqueBorderFormats.remove(this.uniqueBorderFormat);
            }
            this.uniqueBorderFormat = undefined;
        };
        WBorder.prototype.destroy = function () {
            this.clearFormat();
            this.ownerBase = undefined;
        };
        WBorder.prototype.isEqualFormat = function (border) {
            var value = false;
            if (this.color === border.color && this.lineStyle === border.lineStyle
                && this.lineWidth === border.lineWidth && this.shadow === border.shadow
                && this.space === border.space) {
                value = true;
            }
            return value;
        };
        WBorder.prototype.copyFormat = function (border) {
            if (!ej2_base_1.isNullOrUndefined(border) && !ej2_base_1.isNullOrUndefined(border.uniqueBorderFormat)) {
                if (border.hasValue('color')) {
                    this.color = border.color;
                }
                if (border.hasValue('lineStyle')) {
                    this.lineStyle = border.lineStyle;
                }
                if (border.hasValue('lineWidth')) {
                    this.lineWidth = border.lineWidth;
                }
                if (border.hasValue('shadow')) {
                    this.shadow = border.shadow;
                }
                if (border.hasValue('space')) {
                    this.space = border.space;
                }
                if (border.hasValue('hasNoneStyle')) {
                    this.hasNoneStyle = border.hasNoneStyle;
                }
            }
        };
        WBorder.clear = function () {
            this.uniqueBorderFormats.clear();
        };
        WBorder.uniqueBorderFormats = new unique_formats_1.WUniqueFormats();
        WBorder.uniqueFormatType = 1;
        return WBorder;
    }());
    exports.WBorder = WBorder;
});