all files / diagram/load-utility/visio-import-export/ visio-theme.js

93.83% Statements 502/535
79.26% Branches 363/458
96.36% Functions 53/55
94.01% Lines 502/534
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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815                       4071×   4066×   2481× 187×   2294× 2294× 2294×   18206× 210×   17996× 17996×     17996× 16949× 16949×     16949×   1047× 1047×       1047× 1032×   15×     15×   2557×     2557× 12× 12×   2557×   1590×                   1590× 1590× 1590× 1590× 1590× 1590× 1590× 1590×   1590× 1590× 1397× 1279× 1279× 1279× 1279× 210× 210× 210× 210×       1069×     1069× 1069× 1069×           118×     1590× 1451× 1278× 1278× 1278× 1278× 1278× 1278× 1278×   1278× 1278× 1278× 1278× 1278×     1278× 1278× 1278× 1278×           173×         173× 33× 33× 33×     140×       1590× 1590× 1590× 1590× 1590×               1590×   4144× 4144× 4144× 778×   3366× 3366×   3366× 3366× 3366× 3366× 3366×   3366×   3366× 3366× 3366× 3366× 2712×     654× 654× 654×   3366×               3366× 2474×   892× 219×   673× 22×   651×   3366× 2490×   876× 255×   621× 15×   606×   1842×   30×   211×   1601×     4478× 4478×   1842× 1842×         564× 564× 564×     1354× 1354× 1354×   1279× 1279× 1279×     1278× 1278× 1278×     1590× 11×   1579× 1346×   233× 221× 221× 221× 221× 221× 221× 221×                 12× 12× 12× 12× 12× 12× 12× 12×                   564×   891× 891× 891× 891× 564× 564× 564× 564× 564× 564×   564× 564× 564×   564× 78× 78× 78×         891×     891× 891×           891×   6126×     6126× 2507×   3619× 907×   6126×   3366× 3366× 3366×       1357× 1357×   1590× 1590× 1590× 1590× 1590× 1590× 1590× 1590× 1590× 1386× 1386×       1386× 1354× 1354× 1354× 1354× 1354× 1354× 1354× 1354× 1354× 1354×       1354× 1354× 1354× 1354×       1590× 1590× 1590× 1590× 1590×     1590× 1590× 1590× 1590×                     1590×     210× 210× 210× 210×           210×   210× 210× 210× 210× 210× 210× 210× 210×   210×     210× 210× 210× 210× 210×       210×   210×     210× 630×   210× 630× 630× 210×   630×   210×   630× 630×     630× 630× 630× 630×     4411× 4411× 4411× 4411×   4411× 4411× 4411× 4411× 4411× 4411× 4411× 4411× 4411× 2353× 2353× 99× 99×     2254× 1308×     946×   2254×   675× 675×   492× 492×   1087× 1087×       4411×   2887×   4411×     4411× 4411× 4411× 4411× 4411×     4411×             4411× 4411× 4411× 2887× 2887× 2887× 2887×     2887×     4411×   4411× 4411× 4411× 4411× 4411× 2887× 2887×   1067× 1067×   236× 236×   792× 792×   792× 792×     4411× 4411×   4411×   13233× 13233×   4411× 4411× 4411× 4411× 2157×     2254×     2254× 2254× 6762× 818×   6762× 178×   6762× 891×   5871× 2254×   3617× 1363×   2254×   2254× 2254× 2254× 2254× 2254×   4411×   5774×                         210× 210× 210×   210×     210× 630× 630× 630×               3781× 3781× 3781× 3781× 3781× 3781× 158× 158×   3623× 1865× 1865×   3781× 3781× 3781×   1758× 1758× 1758×   158× 158×       158× 158×   4411× 4411× 4411× 4411× 4411× 158× 158×   4253× 4253× 4253×                         4411× 4253× 4253× 236×   4253× 1067×   4253× 792×   4253× 792×     4411×                
define(["require", "exports", "./visio-constants", "./visio-core", "./visio-nodes"], function (require, exports, visio_constants_1, visio_core_1, visio_nodes_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var themeConfig = {
        enableCache: true,
        defaultFill: 'white',
        defaultStroke: 'black',
        minStrokeWidth: 0.5,
        maxStrokeWidth: 100
    };
    var defaultFill = 'white';
    exports.defaultStroke = 'black';
    var themeIndex = [];
    var themeCache = new Map();
    var EMU_PER_INCH = 914400;
    var MIN_STROKE_WIDTH = 0.5;
    var MAX_STROKE_WIDTH = 100;
    var SATURATION_THRESHOLD = 0.001;
    var RGB_DIFF_THRESHOLD = 0.01;
    var ACHROMATIC_HUE = 0;
    var STANDARD_COLOR_OFFSET = 100;
    var PREMIUM_COLOR_OFFSET = 200;
    var MAX_MATRIX_INDEX = 6;
    var HUE_SCALE_FACTOR = 60000;
    var COLOR_MODIFIER_SCALE_FACTOR = 100000;
    exports.fontMapping = {
        'Arial Rounded MT Bold': 'Arial, sans-serif',
        'Eras Light ITC': 'Georgia, serif',
        'Franklin Gothic Demi': 'Verdana, sans-serif'
    };
    function normalizeOpacity(opacity) {
        if (!Number.isFinite(opacity)) {
            return 1;
        }
        return Math.max(0, Math.min(1, opacity));
    }
    function normalizeStrokeWidth(width) {
        if (!Number.isFinite(width) || width === undefined) {
            return 1;
        }
        var min = themeConfig.minStrokeWidth;
        var max = themeConfig.maxStrokeWidth;
        return Math.max(min, Math.min(max, width));
    }
    function isValidColor(color, isAnnotation) {
        if (typeof color !== 'string') {
            return false;
        }
        var s = color.trim();
        Iif (s === '' || s === 'undefined' || s === 'null') {
            return false;
        }
        if (s.charAt(0) === '#') {
            var len = s.length;
            Iif (len !== 4 && len !== 7 && len !== 9) {
                return false;
            }
            return /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(s);
        }
        var lower = s.toLowerCase();
        var validNamedColors = [
            'black', 'white', 'red', 'green', 'blue', 'yellow',
            'cyan', 'magenta', 'gray', 'grey', 'transparent'
        ];
        if (validNamedColors.indexOf(lower) !== -1) {
            return true;
        }
        Iif (isAnnotation) {
            return false;
        }
        return true;
    }
    exports.isValidColor = isValidColor;
    function getCachedThemeValue(key, getter) {
        Iif (!themeConfig.enableCache) {
            return getter();
        }
        if (!themeCache.has(key)) {
            var value = getter();
            themeCache.set(key, value);
        }
        return themeCache.get(key);
    }
    function getNodeStyle(node, context, isGroup) {
        Iif (!node || typeof node !== 'object') {
            return {
                fill: defaultFill,
                strokeColor: exports.defaultStroke,
                strokeWidth: 1,
                opacity: 1,
                strokeDashArray: '',
                gradient: undefined
            };
        }
        var fill = isGroup ? 'transparent' : node.style.fillColor;
        var strokeColor = isGroup ? 'transparent' : node.style.strokeColor;
        var strokeDashArray = isGroup ? '' : node.style.strokeDashArray;
        var strokeWidth = isGroup ? 0 : node.style.strokeWidth;
        var isGradientAccent = false;
        var gradient;
        var fillPattern = Number(node.style.fillPattern);
        if (fillPattern === 0) {
            fill = 'transparent';
        }
        var activeTheme = isActiveThemeApplied(node, context) || { isThemeApplied: false };
        if (!fill) {
            if (activeTheme.isThemeApplied) {
                var range = activeTheme.range;
                var themeElement = getType(activeTheme.currentTheme, range);
                Eif (themeElement && themeElement.name) {
                    if (themeElement.name === 'a:gradFill') {
                        var findGradient = convertVisioGradientToEJ2(themeElement);
                        Eif (findGradient) {
                            gradient = resolveGradientAccent(findGradient, activeTheme.theme, activeTheme.fillIdxColor);
                            isGradientAccent = true;
                        }
                    }
                    else {
                        var fillColorElement = (themeElement.name === 'a:pattFill')
                            ? themeElement.value['a:bgClr']
                            : themeElement;
                        var colorModifiers = extractColorWithModifiers(fillColorElement);
                        Eif (colorModifiers) {
                            fill = resolveAccentColor(colorModifiers, activeTheme.theme, activeTheme.fillIdxColor);
                        }
                    }
                }
            }
            else {
                fill = defaultFill;
            }
        }
        if (!strokeColor) {
            if (activeTheme.isThemeApplied) {
                var range = activeTheme.range;
                var strokeElement = getStrokeType(activeTheme.currentTheme, range);
                Eif (strokeElement && strokeElement.value) {
                    var strokeValue = strokeElement.value;
                    Eif (strokeValue && strokeValue['$'] && strokeValue['$'].w) {
                        var strokeInInches = emuToInches(strokeValue.$.w);
                        strokeWidth = (strokeWidth !== undefined) ? strokeWidth : strokeInInches;
                    }
                    Eif (strokeValue && strokeValue['a:prstDash'] && strokeValue['a:prstDash']['$']) {
                        var prstDash = strokeValue['a:prstDash'].$.val;
                        Eif (prstDash) {
                            var themeDashArray = mapPrstDashToStrokeDashArray(prstDash, strokeWidth || 0);
                            strokeDashArray = (strokeDashArray !== undefined) ? strokeDashArray : themeDashArray;
                        }
                    }
                    Eif (strokeValue && strokeValue['a:solidFill'] && !strokeColor) {
                        var solidFillData = extractColorWithModifiers(strokeValue['a:solidFill']);
                        Eif (solidFillData) {
                            strokeColor = resolveAccentColor(solidFillData, activeTheme.theme, activeTheme.fillIdxColor);
                        }
                    }
                }
            }
            else {
                var noExplicitStroke = !isGroup
                    && node.style
                    && node.style.strokeColor === undefined
                    && node.style.strokeWidth === undefined
                    && node.style.strokeDashArray === '0';
                if (noExplicitStroke) {
                    strokeColor = 'transparent';
                    strokeWidth = 0;
                    strokeDashArray = '';
                }
                else {
                    strokeColor = exports.defaultStroke;
                }
            }
        }
        fill = isValidColor(fill) ? fill : defaultFill;
        strokeColor = (strokeColor === 'transparent') ? 'transparent' : (isValidColor(strokeColor) ? strokeColor : exports.defaultStroke);
        var finalStrokeWidth = normalizeStrokeWidth(visio_core_1.inchToPoint(strokeWidth));
        var finalOpacity = normalizeOpacity((1 - node.style.opacity) || 1);
        var result = {
            fill: fill,
            strokeColor: strokeColor,
            strokeWidth: finalStrokeWidth,
            opacity: finalOpacity,
            strokeDashArray: visio_constants_1.LINE_PATTERN_MAP[String(strokeDashArray)] || '',
            gradient: isGradientAccent ? setGratient(gradient, undefined) : setGratient(node.style, isGroup)
        };
        return result;
    }
    exports.getNodeStyle = getNodeStyle;
    function isActiveThemeApplied(node, context) {
        var theme = context.data.themes;
        var currentTheme = context.data.currentTheme;
        if (!(theme.length && currentTheme) || node.ThemeIndex === 0) {
            return null;
        }
        var enumIndex = Number(currentTheme.schemeEnum);
        var isThemeApplied = context.data.pages && theme && currentTheme &&
            context.data.currentPage.theme === enumIndex;
        var fillMatrix = extractFillMatrix(node);
        var fillColor = extractFillColor(node);
        var valueForColor = (typeof fillColor === 'number') ? fillColor : (isThemeApplied ? 100 : undefined);
        Eif (valueForColor !== undefined) {
            themeIndex.push(fillColor);
        }
        var resolvedColorIndex = valueForColor !== undefined ? valueForColor : themeIndex.length > 0 ?
            themeIndex[themeIndex.length - 1] : undefined;
        var matrix = getMatrix(resolvedColorIndex);
        var fillIdxColor = getHexColorByIndex(matrix, currentTheme.hexColors);
        var range;
        if (fillMatrix !== undefined && fillMatrix < 7) {
            range = getMatrix(fillMatrix);
        }
        else {
            var index = fillMatrix ? getMatrix(fillMatrix) : 0;
            var variant = currentTheme.variant[parseInt(index.toString(), 10)];
            range = node.IsConnector ? 1 : Number(variant.$.fillIdx);
        }
        return {
            isThemeApplied: isThemeApplied,
            theme: theme,
            currentTheme: currentTheme,
            range: range,
            fillIdxColor: fillIdxColor
        };
    }
    exports.isActiveThemeApplied = isActiveThemeApplied;
    function extractFillColor(node) {
        if (typeof node.QuickFillColor === 'number') {
            return node.QuickFillColor;
        }
        if (typeof node.QuickStyleLineColor === 'number') {
            return node.QuickStyleLineColor;
        }
        if (typeof node.QuickStyleFontColor === 'number') {
            return node.QuickStyleFontColor;
        }
        return undefined;
    }
    function extractFillMatrix(node) {
        if (typeof node.QuickFillMatrix === 'number') {
            return node.QuickFillMatrix;
        }
        if (typeof node.QuickStyleLineMatrix === 'number') {
            return node.QuickStyleLineMatrix;
        }
        if (typeof node.QuickStyleFontMatrix === 'number') {
            return node.QuickStyleFontMatrix;
        }
        return undefined;
    }
    function mapPrstDashToStrokeDashArray(prstDash, strokeWidth) {
        switch (prstDash.toLowerCase()) {
            case 'sysdash':
                return StrokeDashArrayValue.Dash;
            case 'sysdot':
                return StrokeDashArrayValue.Dot;
            default:
                return StrokeDashArrayValue.Solid;
        }
    }
    function toZeroBasedIndex(range) {
        var r = Number.isFinite(range) ? Math.floor(range) : 1;
        return Math.max(0, r - 1);
    }
    exports.toZeroBasedIndex = toZeroBasedIndex;
    function emuToInches(emu) {
        Eif (!Number.isFinite(emu)) {
            return 0;
        }
        var emuValue = emu / EMU_PER_INCH;
        return emuValue;
    }
    function connectorType(VisioTheme, range) {
        var rangeIndex = toZeroBasedIndex(range);
        var accent = VisioTheme.connectorStroke['a:ln'][parseInt(rangeIndex.toString(), 10)];
        return accent;
    }
    function getConnectorFontType(VisioTheme, range) {
        var rangeIndex = toZeroBasedIndex(range);
        var accent = VisioTheme.connectorFont[parseInt(rangeIndex.toString(), 10)];
        return accent;
    }
    exports.getConnectorFontType = getConnectorFontType;
    function getFontType(VisioTheme, range) {
        var rangeIndex = toZeroBasedIndex(range);
        var accent = VisioTheme.fontStyles[parseInt(rangeIndex.toString(), 10)];
        return accent;
    }
    exports.getFontType = getFontType;
    function getType(VisioTheme, range) {
        var rangeIndex = toZeroBasedIndex(range);
        var cacheKey = "fill_" + range + "_" + rangeIndex;
        return getCachedThemeValue(cacheKey, function () {
            var accent = VisioTheme.fmtSchemeFill[parseInt(rangeIndex.toString(), 10)];
            return accent;
        });
    }
    function getStrokeType(VisioTheme, range) {
        var rangeIndex = toZeroBasedIndex(range);
        var cacheKey = "stroke_" + range + "_" + rangeIndex;
        return getCachedThemeValue(cacheKey, function () {
            var accent = VisioTheme.fmtSchemeStroke[parseInt(rangeIndex.toString(), 10)];
            return accent;
        });
    }
    function setGratient(style, isGroup) {
        if (!style || isGroup) {
            return undefined;
        }
        if (!style.isGradientEnabled) {
            return undefined;
        }
        if (style.gradientType === 'Linear') {
            var coords = style.gradientCoordinates;
            var x1 = typeof coords.x1 === 'number' ? coords.x1 : 0;
            var y1 = typeof coords.y1 === 'number' ? coords.y1 : 0;
            var x2 = typeof coords.x2 === 'number' ? coords.x2 : 1;
            var y2 = typeof coords.y2 === 'number' ? coords.y2 : 1;
            var stops = Array.isArray(style.gradientStops) ? style.gradientStops : [];
            return {
                type: 'Linear',
                x1: x1,
                y1: y1,
                x2: x2,
                y2: y2,
                stops: stops
            };
        }
        var rcoords = style.gradientCoordinates;
        var cx = typeof rcoords.cx === 'number' ? rcoords.cx : 0.5;
        var cy = typeof rcoords.cy === 'number' ? rcoords.cy : 0.5;
        var fx = typeof rcoords.fx === 'number' ? rcoords.fx : 0.5;
        var fy = typeof rcoords.fy === 'number' ? rcoords.fy : 0.5;
        var r = typeof rcoords.r === 'number' ? rcoords.r : 0.5;
        var rstops = Array.isArray(style.gradientStops) ? style.gradientStops : [];
        return {
            type: 'Radial',
            cx: cx,
            cy: cy,
            fx: fx,
            fy: fy,
            r: r,
            stops: rstops
        };
    }
    function isFiniteNumber(value) {
        return typeof value === 'number' && Number.isFinite(value);
    }
    function applyThemeStyles(connector, context) {
        var _a = connector.style, strokeColor = _a.strokeColor, strokeDashArray = _a.strokeDashArray, strokeWidth = _a.strokeWidth;
        var opacity = normalizeOpacity(connector.style.opacity);
        var activeTheme = isActiveThemeApplied(connector, context) || { isThemeApplied: false };
        if (activeTheme && activeTheme.isThemeApplied) {
            var range = isFiniteNumber(activeTheme.range) ? Math.floor(activeTheme.range) : 1;
            var LineElement = connectorType(activeTheme.currentTheme, range);
            Eif (LineElement && LineElement['$']) {
                Eif (LineElement['$'].w) {
                    var widthInInches = emuToInches(LineElement.$.w);
                    strokeWidth = strokeWidth !== undefined ? strokeWidth : widthInInches;
                }
                Eif (LineElement['a:prstDash'] && LineElement['a:prstDash']['$'] && LineElement['a:prstDash']['$'].val) {
                    var lineDashArray = mapPrstDashToStrokeDashArray(LineElement['a:prstDash'].$.val, strokeWidth || 0);
                    strokeDashArray = (strokeDashArray !== undefined) ? strokeDashArray : lineDashArray;
                }
                if (LineElement['a:solidFill'] && !strokeColor) {
                    var findFill = extractColorWithModifiers(LineElement['a:solidFill']);
                    Eif (findFill) {
                        strokeColor = resolveAccentColor(findFill, activeTheme.theme, activeTheme.fillIdxColor);
                    }
                }
            }
        }
        var finalStrokeColor = (strokeColor !== undefined && strokeColor !== null && strokeColor !== '' && isValidColor(strokeColor))
            ? strokeColor
            : exports.defaultStroke;
        var finalStrokeDashArray = (strokeDashArray !== undefined && strokeDashArray !== null) ? strokeDashArray : '';
        var result = {
            strokeColor: finalStrokeColor,
            strokeDashArray: finalStrokeDashArray,
            strokeWidth: normalizeStrokeWidth(visio_core_1.inchToPoint(strokeWidth)),
            opacity: opacity
        };
        return result;
    }
    exports.applyThemeStyles = applyThemeStyles;
    function getMatrix(matrix) {
        var index = typeof matrix === 'number'
            ? matrix
            : Number.parseInt(String(matrix || ''), 10);
        if (index >= PREMIUM_COLOR_OFFSET && index <= PREMIUM_COLOR_OFFSET + MAX_MATRIX_INDEX) {
            index -= PREMIUM_COLOR_OFFSET;
        }
        else if (index >= STANDARD_COLOR_OFFSET && index <= STANDARD_COLOR_OFFSET + MAX_MATRIX_INDEX) {
            index -= STANDARD_COLOR_OFFSET;
        }
        return index;
    }
    exports.getMatrix = getMatrix;
    function getHexColorByIndex(index, hexColors) {
        Eif (hexColors[parseInt(index.toString(), 10)]) {
            var color = hexColors[parseInt(index.toString(), 10)];
            return isValidColor(color) ? color : defaultFill;
        }
        return defaultFill;
    }
    exports.getHexColorByIndex = getHexColorByIndex;
    function normalizeRange(range) {
        var n = Number.isFinite(range) ? Math.floor(range) : 1;
        return n < 1 ? 1 : n;
    }
    exports.normalizeRange = normalizeRange;
    function setAnnotationStyle(node, context) {
        var incoming = node && node.annotation && node.annotation.style ? node.annotation.style : {};
        var incomingColor = typeof incoming.color === 'string' ? incoming.color : undefined;
        var resolvedColor = incomingColor ? incomingColor : '';
        var resolvedFontFamily = typeof incoming.fontFamily === 'string' ? incoming.fontFamily : undefined;
        var Bold;
        var activeTheme = isActiveThemeApplied(node, context) || { isThemeApplied: false };
        var themeApplied = false;
        var themeColorApplied = false;
        if (activeTheme && activeTheme.isThemeApplied) {
            var firstThemeEntry = activeTheme.theme[0];
            if (!resolvedFontFamily && firstThemeEntry && typeof firstThemeEntry.fontFamily === 'string') {
                var themeFont = firstThemeEntry.fontFamily;
                Iif (exports.fontMapping && exports.fontMapping["" + themeFont]) {
                    themeFont = exports.fontMapping["" + themeFont];
                }
                resolvedFontFamily = themeFont;
                themeApplied = true;
            }
            if (!incomingColor || incomingColor === 'Themed') {
                var range = normalizeRange(activeTheme.range);
                var fontEntry = getFontType(activeTheme.currentTheme, range);
                Eif (fontEntry && fontEntry['vt:color']) {
                    var colorNode = fontEntry['vt:color'];
                    var colorModifiers = extractColorWithModifiers(colorNode);
                    Eif (colorModifiers) {
                        var themeColor = resolveAccentColor(colorModifiers, activeTheme.theme, activeTheme.fillIdxColor);
                        Eif (typeof themeColor === 'string' && themeColor !== '' && isValidColor(themeColor)) {
                            resolvedColor = themeColor;
                            themeColorApplied = true;
                        }
                    }
                }
                Eif (fontEntry && fontEntry['$']) {
                    var styleRaw = fontEntry.$.style;
                    var style = typeof styleRaw === 'string' ? parseInt(styleRaw, 10) : Number(styleRaw);
                    Bold = (style & 1) !== 0;
                }
            }
        }
        var finalColor = (themeColorApplied ? resolvedColor : (incoming.color !== undefined && incoming.color !== null ? incoming.color : 'Black'));
        var finalFontFamily = themeApplied ? resolvedFontFamily : incoming.fontFamily;
        var finalFontSize = typeof incoming.fontSize === 'number' ? incoming.fontSize : 8 * 1.33;
        var finalOpacity = normalizeOpacity(incoming.opacity);
        var finalBold = (Bold === true)
            ? !(incoming.TEXT_STYLE_NONE === true)
            : (typeof incoming.bold === 'boolean' ? incoming.bold : false);
        var finalItalic = typeof incoming.italic === 'boolean' ? incoming.italic : false;
        var finalTextAlign = incoming.textAlign ? visio_nodes_1.getTextAlign(incoming.textAlign) : 'Center';
        var finalTextDecoration = visio_nodes_1.getTextDecoration(incoming.textDecoration);
        var result = {
            color: isValidColor(finalColor) ? finalColor : 'Black',
            fontFamily: finalFontFamily,
            fill: incoming.fill,
            fontSize: finalFontSize,
            opacity: finalOpacity,
            bold: finalBold,
            italic: finalItalic,
            textAlign: finalTextAlign,
            textDecoration: finalTextDecoration
        };
        return result;
    }
    exports.setAnnotationStyle = setAnnotationStyle;
    function hasOwn(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    }
    exports.hasOwn = hasOwn;
    function resolveGradientAccent(VisioGradient, theme, baseColor) {
        var _a = angleToLinearEndpoints(VisioGradient.angle), x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
        var stops = applyOfficeColorModifiers(VisioGradient, theme, baseColor);
        var gradientCoordinates = { x1: x1, y1: y1, x2: x2, y2: y2 };
        var style = {
            gradientStops: stops,
            isGradientEnabled: true,
            gradientCoordinates: gradientCoordinates,
            gradientType: 'Linear'
        };
        return style;
    }
    function angleToLinearEndpoints(thetaDeg) {
        var t = (thetaDeg % 360) * Math.PI / 180;
        var dx = Math.cos(t) * 100;
        var dy = Math.sin(t) * 100;
        var x1 = 0.5 - dx / 2;
        var y1 = 0.5 - dy / 2;
        var x2 = 0.5 + dx / 2;
        var y2 = 0.5 + dy / 2;
        return { x1: x1, y1: y1, x2: x2, y2: y2 };
    }
    function convertVisioGradientToEJ2(gradFillValue) {
        Iif (!gradFillValue || !gradFillValue.value) {
            return null;
        }
        var gradStopLst = gradFillValue.value['a:gsLst'];
        var linElement = gradFillValue.value['a:lin'];
        var stops = extractGradientStops(gradStopLst);
        var officeAngle = extractGradientAngle(linElement);
        var gradient = {
            stops: stops,
            angle: officeAngle
        };
        return gradient;
    }
    function applyOfficeColorModifiers(gradStopArray, theme, baseColor) {
        var stops = gradStopArray.stops && Array.isArray(gradStopArray.stops)
            ? gradStopArray.stops
            : [];
        var ensureHash = function (hex) {
            return hex ? (hex.startsWith('#') ? hex : "#" + hex) : '#000000';
        };
        var toPercent = function (pos) {
            var p = Number(pos);
            if (p <= 1) {
                p = p * 100;
            }
            return Math.max(0, Math.min(100, p));
        };
        return stops
            .map(function (s) {
            var colorType = s.colorType;
            var baseHex = colorType === 'srgb'
                ? ensureHash(s.color) : (s.color === 'phClr') ? ensureHash(baseColor)
                : resolveSchemeColor(s.color, theme[0].fontColor);
            var color = applyTransformsOOXML(baseHex, s.modifiers);
            var opacity = 1;
            var offset = toPercent(s.position);
            return { offset: offset, color: color, opacity: opacity };
        });
    }
    function hexToRgb(hex) {
        var s = hex.replace('#', '');
        var n = s.length === 3 ? s.split('').map(function (c) { return c + c; }).join('') : s;
        var num = parseInt(n, 16);
        return [(num >> 16) & 255, (num >> 8) & 255, num & 255];
    }
    function rgbToHsl(r, g, b) {
        r /= 255;
        g /= 255;
        b /= 255;
        var max = Math.max(r, g, b);
        var min = Math.min(r, g, b);
        var h = ACHROMATIC_HUE;
        var s = 0;
        var l = (max + min) / 2;
        if (max !== min) {
            var d = max - min;
            if (d < RGB_DIFF_THRESHOLD) {
                s = 0;
                h = ACHROMATIC_HUE;
            }
            else {
                if (l < 0.5) {
                    s = d / (max + min);
                }
                else {
                    s = d / (2 - max - min);
                }
                switch (max) {
                    case r:
                        h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
                        break;
                    case g:
                        h = ((b - r) / d + 2) / 6;
                        break;
                    case b:
                        h = ((r - g) / d + 4) / 6;
                        break;
                }
            }
        }
        return [h, s, l];
    }
    function normValByType(type, v) {
        return v > 1 ? clampToUnit(v / COLOR_MODIFIER_SCALE_FACTOR) : clampToUnit(v);
    }
    function normalizeTransforms(input) {
        Iif (input == null) {
            return [];
        }
        var arr = Array.isArray(input) ? input : [input];
        var out = [];
        for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
            var item = arr_1[_i];
            Iif (!item) {
                continue;
            }
            Iif (item.type && item.val != null) {
                var transform = item;
                if (visio_constants_1.VALID_TYPES.has(transform.type)) {
                    out.push({ type: transform.type, val: normValByType(transform.type, Number(transform.val)) });
                }
                continue;
            }
            var flat = item;
            var keys = Object.keys(flat);
            for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) {
                var key = keys_1[_a];
                var raw = (flat)["" + key];
                var v = Number(raw);
                Iif (!visio_constants_1.VALID_TYPES.has(key) || raw == null || !Number.isFinite(v)) {
                    continue;
                }
                out.push({ type: key, val: normValByType(key, v) });
            }
        }
        return out;
    }
    function applyTransformsOOXML(baseHex, transforms) {
        var _a = hexToRgb(baseHex), r0 = _a[0], g0 = _a[1], b0 = _a[2];
        var _b = rgbToHsl(r0, g0, b0), h = _b[0], s = _b[1], l = _b[2];
        h = h * 1;
        var mods = normalizeTransforms(transforms);
        for (var i = 0; i < mods.length; i++) {
            var t = mods[parseInt(i.toString(), 10)];
            switch (t.type) {
                case 'shade':
                    l = clampToUnit(l * t.val);
                    break;
                case 'tint':
                    l = clampToUnit(l + (1 - l) * t.val);
                    break;
                case 'lumMod':
                    l = clampToUnit(l * t.val);
                    break;
                case 'satMod':
                    s = clampToUnit(s * t.val);
                    break;
            }
        }
        var _c = hslToRgb(h, s, l), r = _c[0], g = _c[1], b = _c[2];
        return rgbToHex(r, g, b);
    }
    function rgbToHex(r, g, b) {
        return "#" + toHex2(r) + toHex2(g) + toHex2(b);
    }
    function toHex2(n) {
        var s = n.toString(16);
        return ('0' + s).slice(-2);
    }
    function hslToRgb(h, s, l) {
        var r;
        var g;
        var b;
        if (s === 0 || s < SATURATION_THRESHOLD) {
            r = g = b = l;
        }
        else {
            Iif (!Number.isFinite(h) || isNaN(h)) {
                h = ACHROMATIC_HUE;
            }
            h = ((h % 1) + 1) % 1;
            var hue2rgb = function (p, q, t) {
                if (t < 0) {
                    t += 1;
                }
                if (t > 1) {
                    t -= 1;
                }
                if (t < 1 / 6) {
                    return p + (q - p) * 6 * t;
                }
                if (t < 1 / 2) {
                    return q;
                }
                if (t < 2 / 3) {
                    return p + (q - p) * (2 / 3 - t) * 6;
                }
                return p;
            };
            var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
            var p = 2 * l - q;
            r = hue2rgb(p, q, h + 1 / 3);
            g = hue2rgb(p, q, h);
            b = hue2rgb(p, q, h - 1 / 3);
        }
        return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
    }
    function clampToUnit(x) {
        return Math.max(0, Math.min(1, x));
    }
    function resolveSchemeColor(name, palette) {
        if (!name || typeof name !== 'string') {
            return '#000000';
        }
        if (/^#?[0-9A-Fa-f]{6}$/.test(name)) {
            return name.startsWith('#') ? name.toUpperCase() : ('#' + name).toUpperCase();
        }
        if (palette && palette["" + name]) {
            return palette["" + name].toUpperCase();
        }
        return '#000000';
    }
    function extractGradientAngle(linElement) {
        var angValue = parseInt(linElement['$'].ang, 10);
        var degrees = angValue / HUE_SCALE_FACTOR;
        return ((degrees % 360) + 360) % 360;
    }
    function extractGradientStops(gsLst) {
        var gsArray = Array.isArray(gsLst['a:gs'])
            ? gsLst['a:gs']
            : [gsLst['a:gs']];
        return gsArray.map(function (gs) {
            var position = parseInt(gs['$'].pos, 10) / 1000;
            var colorInfo = extractColorWithModifiers(gs);
            return {
                position: position,
                color: (colorInfo && colorInfo.colorValue),
                colorType: (colorInfo && colorInfo.colorType),
                modifiers: (colorInfo && colorInfo.modifiers)
            };
        });
    }
    function resolveAccentColor(result, theme, baseColor) {
        var palette = theme[0].fontColor;
        var colorType = result.colorType, colorValue = result.colorValue, modifiers = result.modifiers;
        var colored = false;
        var hex;
        var valueLower = String(colorValue).toLowerCase();
        if (String(colorType).toLowerCase() === 'srgb' && isHexColor(colorValue)) {
            hex = ensureHashHex(colorValue);
            colored = true;
        }
        else if (valueLower === 'phclr') {
            hex = baseColor && isValidColor(baseColor) ? baseColor : defaultFill;
            colored = true;
        }
        hex = colored ? hex : resolveThemeColor(palette, valueLower);
        var color = applyTransformsOOXML(hex, modifiers);
        return isValidColor(color) ? color : defaultFill;
    }
    exports.resolveAccentColor = resolveAccentColor;
    function resolveThemeColor(theme, roleName) {
        var key = roleName.trim();
        var color = theme["" + key];
        return (color && isValidColor(color)) ? color : undefined;
    }
    function isHexColor(str) {
        var s = str.trim();
        return /^[0-9a-fA-F]{3}$/.test(s) ||
            /^[0-9a-fA-F]{6}$/.test(s) ||
            /^[0-9a-fA-F]{8}$/.test(s);
    }
    function ensureHashHex(str) {
        var s = str.trim();
        return s.startsWith('#') ? s.toUpperCase() : ('#' + s.toUpperCase());
    }
    function extractColorWithModifiers(solidFill) {
        var solidFillValue = (solidFill.value || solidFill);
        var colorType = '';
        var colorValue = '';
        var modifiers = {};
        if (solidFillValue['a:srgbClr']) {
            colorType = 'srgb';
            colorValue = solidFillValue['a:srgbClr']['$'].val;
        }
        else Eif (solidFillValue['a:schemeClr']) {
            colorType = 'scheme';
            colorValue = solidFillValue['a:schemeClr']['$'].val;
        }
        else if (solidFillValue['a:sysClr']) {
            colorType = 'system';
            colorValue = solidFillValue['a:sysClr']['$'].val;
        }
        else if (solidFillValue['a:prstClr']) {
            colorType = 'preset';
            colorValue = solidFillValue['a:prstClr']['$'].val;
        }
        else {
            return null;
        }
        if (solidFillValue['a:schemeClr']) {
            var schemeClr = solidFillValue['a:schemeClr'];
            if (schemeClr['a:tint']) {
                modifiers.tint = parseInt(schemeClr['a:tint']['$'].val, 10);
            }
            if (schemeClr['a:shade']) {
                modifiers.shade = parseInt(schemeClr['a:shade']['$'].val, 10);
            }
            if (schemeClr['a:lumMod']) {
                modifiers.lumMod = parseInt(schemeClr['a:lumMod']['$'].val, 10);
            }
            if (schemeClr['a:satMod']) {
                modifiers.satMod = parseInt(schemeClr['a:satMod']['$'].val, 10);
            }
        }
        return {
            colorType: colorType,
            colorValue: colorValue,
            modifiers: modifiers
        };
    }
    exports.extractColorWithModifiers = extractColorWithModifiers;
    var StrokeDashArrayValue;
    (function (StrokeDashArrayValue) {
        StrokeDashArrayValue["Solid"] = "";
        StrokeDashArrayValue["Dash"] = "2";
        StrokeDashArrayValue["Dot"] = "3";
        StrokeDashArrayValue["DashDot"] = "4";
        StrokeDashArrayValue["LargeDash"] = "7";
        StrokeDashArrayValue["LargeDashDot"] = "18";
        StrokeDashArrayValue["LargeDashDotDot"] = "19";
    })(StrokeDashArrayValue || (StrokeDashArrayValue = {}));
});