this repo has no description

obsidian: community plugins and settings

+9060
+3
obsidian/community-plugins.json
··· 1 + [ 2 + "obsidian-style-settings" 3 + ]
+8
obsidian/plugins/obsidian-style-settings/data.json
··· 1 + { 2 + "sanctum@@no-uppercase": true, 3 + "sanctum@@heading-1": "1.4rem", 4 + "sanctum@@heading-2": "1.3rem", 5 + "sanctum@@heading-3": "1.2rem", 6 + "sanctum@@heading-4": "1.1rem", 7 + "sanctum@@heading-5": "1.0rem" 8 + }
+8825
obsidian/plugins/obsidian-style-settings/main.js
··· 1 + /* 2 + THIS IS A GENERATED/BUNDLED FILE BY ROLLUP 3 + if you want to view the source visit the plugins github repository 4 + */ 5 + 6 + 'use strict'; 7 + 8 + var obsidian = require('obsidian'); 9 + 10 + /*! ***************************************************************************** 11 + Copyright (c) Microsoft Corporation. 12 + 13 + Permission to use, copy, modify, and/or distribute this software for any 14 + purpose with or without fee is hereby granted. 15 + 16 + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 17 + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 18 + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 19 + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 20 + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 21 + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 22 + PERFORMANCE OF THIS SOFTWARE. 23 + ***************************************************************************** */ 24 + 25 + function __awaiter(thisArg, _arguments, P, generator) { 26 + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 27 + return new (P || (P = Promise))(function (resolve, reject) { 28 + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 29 + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 30 + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 31 + step((generator = generator.apply(thisArg, _arguments || [])).next()); 32 + }); 33 + } 34 + 35 + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 36 + 37 + function getDefaultExportFromCjs (x) { 38 + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; 39 + } 40 + 41 + function createCommonjsModule(fn, basedir, module) { 42 + return module = { 43 + path: basedir, 44 + exports: {}, 45 + require: function (path, base) { 46 + return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); 47 + } 48 + }, fn(module, module.exports), module.exports; 49 + } 50 + 51 + function commonjsRequire () { 52 + throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); 53 + } 54 + 55 + var chroma = createCommonjsModule(function (module, exports) { 56 + /** 57 + * chroma.js - JavaScript library for color conversions 58 + * 59 + * Copyright (c) 2011-2019, Gregor Aisch 60 + * All rights reserved. 61 + * 62 + * Redistribution and use in source and binary forms, with or without 63 + * modification, are permitted provided that the following conditions are met: 64 + * 65 + * 1. Redistributions of source code must retain the above copyright notice, this 66 + * list of conditions and the following disclaimer. 67 + * 68 + * 2. Redistributions in binary form must reproduce the above copyright notice, 69 + * this list of conditions and the following disclaimer in the documentation 70 + * and/or other materials provided with the distribution. 71 + * 72 + * 3. The name Gregor Aisch may not be used to endorse or promote products 73 + * derived from this software without specific prior written permission. 74 + * 75 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 76 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 77 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 78 + * DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 79 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 80 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 81 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 82 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 83 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 84 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 85 + * 86 + * ------------------------------------------------------- 87 + * 88 + * chroma.js includes colors from colorbrewer2.org, which are released under 89 + * the following license: 90 + * 91 + * Copyright (c) 2002 Cynthia Brewer, Mark Harrower, 92 + * and The Pennsylvania State University. 93 + * 94 + * Licensed under the Apache License, Version 2.0 (the "License"); 95 + * you may not use this file except in compliance with the License. 96 + * You may obtain a copy of the License at 97 + * http://www.apache.org/licenses/LICENSE-2.0 98 + * 99 + * Unless required by applicable law or agreed to in writing, 100 + * software distributed under the License is distributed on an 101 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 102 + * either express or implied. See the License for the specific 103 + * language governing permissions and limitations under the License. 104 + * 105 + * ------------------------------------------------------ 106 + * 107 + * Named colors are taken from X11 Color Names. 108 + * http://www.w3.org/TR/css3-color/#svg-color 109 + * 110 + * @preserve 111 + */ 112 + 113 + (function (global, factory) { 114 + module.exports = factory() ; 115 + }(commonjsGlobal, (function () { 116 + var limit = function (x, min, max) { 117 + if ( min === void 0 ) min=0; 118 + if ( max === void 0 ) max=1; 119 + 120 + return x < min ? min : x > max ? max : x; 121 + }; 122 + 123 + var clip_rgb = function (rgb) { 124 + rgb._clipped = false; 125 + rgb._unclipped = rgb.slice(0); 126 + for (var i=0; i<=3; i++) { 127 + if (i < 3) { 128 + if (rgb[i] < 0 || rgb[i] > 255) { rgb._clipped = true; } 129 + rgb[i] = limit(rgb[i], 0, 255); 130 + } else if (i === 3) { 131 + rgb[i] = limit(rgb[i], 0, 1); 132 + } 133 + } 134 + return rgb; 135 + }; 136 + 137 + // ported from jQuery's $.type 138 + var classToType = {}; 139 + for (var i = 0, list = ['Boolean', 'Number', 'String', 'Function', 'Array', 'Date', 'RegExp', 'Undefined', 'Null']; i < list.length; i += 1) { 140 + var name = list[i]; 141 + 142 + classToType[("[object " + name + "]")] = name.toLowerCase(); 143 + } 144 + var type = function(obj) { 145 + return classToType[Object.prototype.toString.call(obj)] || "object"; 146 + }; 147 + 148 + var unpack = function (args, keyOrder) { 149 + if ( keyOrder === void 0 ) keyOrder=null; 150 + 151 + // if called with more than 3 arguments, we return the arguments 152 + if (args.length >= 3) { return Array.prototype.slice.call(args); } 153 + // with less than 3 args we check if first arg is object 154 + // and use the keyOrder string to extract and sort properties 155 + if (type(args[0]) == 'object' && keyOrder) { 156 + return keyOrder.split('') 157 + .filter(function (k) { return args[0][k] !== undefined; }) 158 + .map(function (k) { return args[0][k]; }); 159 + } 160 + // otherwise we just return the first argument 161 + // (which we suppose is an array of args) 162 + return args[0]; 163 + }; 164 + 165 + var last = function (args) { 166 + if (args.length < 2) { return null; } 167 + var l = args.length-1; 168 + if (type(args[l]) == 'string') { return args[l].toLowerCase(); } 169 + return null; 170 + }; 171 + 172 + var PI = Math.PI; 173 + 174 + var utils = { 175 + clip_rgb: clip_rgb, 176 + limit: limit, 177 + type: type, 178 + unpack: unpack, 179 + last: last, 180 + PI: PI, 181 + TWOPI: PI*2, 182 + PITHIRD: PI/3, 183 + DEG2RAD: PI / 180, 184 + RAD2DEG: 180 / PI 185 + }; 186 + 187 + var input = { 188 + format: {}, 189 + autodetect: [] 190 + }; 191 + 192 + var last$1 = utils.last; 193 + var clip_rgb$1 = utils.clip_rgb; 194 + var type$1 = utils.type; 195 + 196 + 197 + var Color = function Color() { 198 + var args = [], len = arguments.length; 199 + while ( len-- ) args[ len ] = arguments[ len ]; 200 + 201 + var me = this; 202 + if (type$1(args[0]) === 'object' && 203 + args[0].constructor && 204 + args[0].constructor === this.constructor) { 205 + // the argument is already a Color instance 206 + return args[0]; 207 + } 208 + 209 + // last argument could be the mode 210 + var mode = last$1(args); 211 + var autodetect = false; 212 + 213 + if (!mode) { 214 + autodetect = true; 215 + if (!input.sorted) { 216 + input.autodetect = input.autodetect.sort(function (a,b) { return b.p - a.p; }); 217 + input.sorted = true; 218 + } 219 + // auto-detect format 220 + for (var i = 0, list = input.autodetect; i < list.length; i += 1) { 221 + var chk = list[i]; 222 + 223 + mode = chk.test.apply(chk, args); 224 + if (mode) { break; } 225 + } 226 + } 227 + 228 + if (input.format[mode]) { 229 + var rgb = input.format[mode].apply(null, autodetect ? args : args.slice(0,-1)); 230 + me._rgb = clip_rgb$1(rgb); 231 + } else { 232 + throw new Error('unknown format: '+args); 233 + } 234 + 235 + // add alpha channel 236 + if (me._rgb.length === 3) { me._rgb.push(1); } 237 + }; 238 + 239 + Color.prototype.toString = function toString () { 240 + if (type$1(this.hex) == 'function') { return this.hex(); } 241 + return ("[" + (this._rgb.join(',')) + "]"); 242 + }; 243 + 244 + var Color_1 = Color; 245 + 246 + var chroma = function () { 247 + var args = [], len = arguments.length; 248 + while ( len-- ) args[ len ] = arguments[ len ]; 249 + 250 + return new (Function.prototype.bind.apply( chroma.Color, [ null ].concat( args) )); 251 + }; 252 + 253 + chroma.Color = Color_1; 254 + chroma.version = '2.1.2'; 255 + 256 + var chroma_1 = chroma; 257 + 258 + var unpack$1 = utils.unpack; 259 + var max = Math.max; 260 + 261 + var rgb2cmyk = function () { 262 + var args = [], len = arguments.length; 263 + while ( len-- ) args[ len ] = arguments[ len ]; 264 + 265 + var ref = unpack$1(args, 'rgb'); 266 + var r = ref[0]; 267 + var g = ref[1]; 268 + var b = ref[2]; 269 + r = r / 255; 270 + g = g / 255; 271 + b = b / 255; 272 + var k = 1 - max(r,max(g,b)); 273 + var f = k < 1 ? 1 / (1-k) : 0; 274 + var c = (1-r-k) * f; 275 + var m = (1-g-k) * f; 276 + var y = (1-b-k) * f; 277 + return [c,m,y,k]; 278 + }; 279 + 280 + var rgb2cmyk_1 = rgb2cmyk; 281 + 282 + var unpack$2 = utils.unpack; 283 + 284 + var cmyk2rgb = function () { 285 + var args = [], len = arguments.length; 286 + while ( len-- ) args[ len ] = arguments[ len ]; 287 + 288 + args = unpack$2(args, 'cmyk'); 289 + var c = args[0]; 290 + var m = args[1]; 291 + var y = args[2]; 292 + var k = args[3]; 293 + var alpha = args.length > 4 ? args[4] : 1; 294 + if (k === 1) { return [0,0,0,alpha]; } 295 + return [ 296 + c >= 1 ? 0 : 255 * (1-c) * (1-k), // r 297 + m >= 1 ? 0 : 255 * (1-m) * (1-k), // g 298 + y >= 1 ? 0 : 255 * (1-y) * (1-k), // b 299 + alpha 300 + ]; 301 + }; 302 + 303 + var cmyk2rgb_1 = cmyk2rgb; 304 + 305 + var unpack$3 = utils.unpack; 306 + var type$2 = utils.type; 307 + 308 + 309 + 310 + Color_1.prototype.cmyk = function() { 311 + return rgb2cmyk_1(this._rgb); 312 + }; 313 + 314 + chroma_1.cmyk = function () { 315 + var args = [], len = arguments.length; 316 + while ( len-- ) args[ len ] = arguments[ len ]; 317 + 318 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['cmyk']) )); 319 + }; 320 + 321 + input.format.cmyk = cmyk2rgb_1; 322 + 323 + input.autodetect.push({ 324 + p: 2, 325 + test: function () { 326 + var args = [], len = arguments.length; 327 + while ( len-- ) args[ len ] = arguments[ len ]; 328 + 329 + args = unpack$3(args, 'cmyk'); 330 + if (type$2(args) === 'array' && args.length === 4) { 331 + return 'cmyk'; 332 + } 333 + } 334 + }); 335 + 336 + var unpack$4 = utils.unpack; 337 + var last$2 = utils.last; 338 + var rnd = function (a) { return Math.round(a*100)/100; }; 339 + 340 + /* 341 + * supported arguments: 342 + * - hsl2css(h,s,l) 343 + * - hsl2css(h,s,l,a) 344 + * - hsl2css([h,s,l], mode) 345 + * - hsl2css([h,s,l,a], mode) 346 + * - hsl2css({h,s,l,a}, mode) 347 + */ 348 + var hsl2css = function () { 349 + var args = [], len = arguments.length; 350 + while ( len-- ) args[ len ] = arguments[ len ]; 351 + 352 + var hsla = unpack$4(args, 'hsla'); 353 + var mode = last$2(args) || 'lsa'; 354 + hsla[0] = rnd(hsla[0] || 0); 355 + hsla[1] = rnd(hsla[1]*100) + '%'; 356 + hsla[2] = rnd(hsla[2]*100) + '%'; 357 + if (mode === 'hsla' || (hsla.length > 3 && hsla[3]<1)) { 358 + hsla[3] = hsla.length > 3 ? hsla[3] : 1; 359 + mode = 'hsla'; 360 + } else { 361 + hsla.length = 3; 362 + } 363 + return (mode + "(" + (hsla.join(',')) + ")"); 364 + }; 365 + 366 + var hsl2css_1 = hsl2css; 367 + 368 + var unpack$5 = utils.unpack; 369 + 370 + /* 371 + * supported arguments: 372 + * - rgb2hsl(r,g,b) 373 + * - rgb2hsl(r,g,b,a) 374 + * - rgb2hsl([r,g,b]) 375 + * - rgb2hsl([r,g,b,a]) 376 + * - rgb2hsl({r,g,b,a}) 377 + */ 378 + var rgb2hsl = function () { 379 + var args = [], len = arguments.length; 380 + while ( len-- ) args[ len ] = arguments[ len ]; 381 + 382 + args = unpack$5(args, 'rgba'); 383 + var r = args[0]; 384 + var g = args[1]; 385 + var b = args[2]; 386 + 387 + r /= 255; 388 + g /= 255; 389 + b /= 255; 390 + 391 + var min = Math.min(r, g, b); 392 + var max = Math.max(r, g, b); 393 + 394 + var l = (max + min) / 2; 395 + var s, h; 396 + 397 + if (max === min){ 398 + s = 0; 399 + h = Number.NaN; 400 + } else { 401 + s = l < 0.5 ? (max - min) / (max + min) : (max - min) / (2 - max - min); 402 + } 403 + 404 + if (r == max) { h = (g - b) / (max - min); } 405 + else if (g == max) { h = 2 + (b - r) / (max - min); } 406 + else if (b == max) { h = 4 + (r - g) / (max - min); } 407 + 408 + h *= 60; 409 + if (h < 0) { h += 360; } 410 + if (args.length>3 && args[3]!==undefined) { return [h,s,l,args[3]]; } 411 + return [h,s,l]; 412 + }; 413 + 414 + var rgb2hsl_1 = rgb2hsl; 415 + 416 + var unpack$6 = utils.unpack; 417 + var last$3 = utils.last; 418 + 419 + 420 + var round = Math.round; 421 + 422 + /* 423 + * supported arguments: 424 + * - rgb2css(r,g,b) 425 + * - rgb2css(r,g,b,a) 426 + * - rgb2css([r,g,b], mode) 427 + * - rgb2css([r,g,b,a], mode) 428 + * - rgb2css({r,g,b,a}, mode) 429 + */ 430 + var rgb2css = function () { 431 + var args = [], len = arguments.length; 432 + while ( len-- ) args[ len ] = arguments[ len ]; 433 + 434 + var rgba = unpack$6(args, 'rgba'); 435 + var mode = last$3(args) || 'rgb'; 436 + if (mode.substr(0,3) == 'hsl') { 437 + return hsl2css_1(rgb2hsl_1(rgba), mode); 438 + } 439 + rgba[0] = round(rgba[0]); 440 + rgba[1] = round(rgba[1]); 441 + rgba[2] = round(rgba[2]); 442 + if (mode === 'rgba' || (rgba.length > 3 && rgba[3]<1)) { 443 + rgba[3] = rgba.length > 3 ? rgba[3] : 1; 444 + mode = 'rgba'; 445 + } 446 + return (mode + "(" + (rgba.slice(0,mode==='rgb'?3:4).join(',')) + ")"); 447 + }; 448 + 449 + var rgb2css_1 = rgb2css; 450 + 451 + var unpack$7 = utils.unpack; 452 + var round$1 = Math.round; 453 + 454 + var hsl2rgb = function () { 455 + var assign; 456 + 457 + var args = [], len = arguments.length; 458 + while ( len-- ) args[ len ] = arguments[ len ]; 459 + args = unpack$7(args, 'hsl'); 460 + var h = args[0]; 461 + var s = args[1]; 462 + var l = args[2]; 463 + var r,g,b; 464 + if (s === 0) { 465 + r = g = b = l*255; 466 + } else { 467 + var t3 = [0,0,0]; 468 + var c = [0,0,0]; 469 + var t2 = l < 0.5 ? l * (1+s) : l+s-l*s; 470 + var t1 = 2 * l - t2; 471 + var h_ = h / 360; 472 + t3[0] = h_ + 1/3; 473 + t3[1] = h_; 474 + t3[2] = h_ - 1/3; 475 + for (var i=0; i<3; i++) { 476 + if (t3[i] < 0) { t3[i] += 1; } 477 + if (t3[i] > 1) { t3[i] -= 1; } 478 + if (6 * t3[i] < 1) 479 + { c[i] = t1 + (t2 - t1) * 6 * t3[i]; } 480 + else if (2 * t3[i] < 1) 481 + { c[i] = t2; } 482 + else if (3 * t3[i] < 2) 483 + { c[i] = t1 + (t2 - t1) * ((2 / 3) - t3[i]) * 6; } 484 + else 485 + { c[i] = t1; } 486 + } 487 + (assign = [round$1(c[0]*255),round$1(c[1]*255),round$1(c[2]*255)], r = assign[0], g = assign[1], b = assign[2]); 488 + } 489 + if (args.length > 3) { 490 + // keep alpha channel 491 + return [r,g,b,args[3]]; 492 + } 493 + return [r,g,b,1]; 494 + }; 495 + 496 + var hsl2rgb_1 = hsl2rgb; 497 + 498 + var RE_RGB = /^rgb\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*\)$/; 499 + var RE_RGBA = /^rgba\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*([01]|[01]?\.\d+)\)$/; 500 + var RE_RGB_PCT = /^rgb\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/; 501 + var RE_RGBA_PCT = /^rgba\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/; 502 + var RE_HSL = /^hsl\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/; 503 + var RE_HSLA = /^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/; 504 + 505 + var round$2 = Math.round; 506 + 507 + var css2rgb = function (css) { 508 + css = css.toLowerCase().trim(); 509 + var m; 510 + 511 + if (input.format.named) { 512 + try { 513 + return input.format.named(css); 514 + } catch (e) { 515 + // eslint-disable-next-line 516 + } 517 + } 518 + 519 + // rgb(250,20,0) 520 + if ((m = css.match(RE_RGB))) { 521 + var rgb = m.slice(1,4); 522 + for (var i=0; i<3; i++) { 523 + rgb[i] = +rgb[i]; 524 + } 525 + rgb[3] = 1; // default alpha 526 + return rgb; 527 + } 528 + 529 + // rgba(250,20,0,0.4) 530 + if ((m = css.match(RE_RGBA))) { 531 + var rgb$1 = m.slice(1,5); 532 + for (var i$1=0; i$1<4; i$1++) { 533 + rgb$1[i$1] = +rgb$1[i$1]; 534 + } 535 + return rgb$1; 536 + } 537 + 538 + // rgb(100%,0%,0%) 539 + if ((m = css.match(RE_RGB_PCT))) { 540 + var rgb$2 = m.slice(1,4); 541 + for (var i$2=0; i$2<3; i$2++) { 542 + rgb$2[i$2] = round$2(rgb$2[i$2] * 2.55); 543 + } 544 + rgb$2[3] = 1; // default alpha 545 + return rgb$2; 546 + } 547 + 548 + // rgba(100%,0%,0%,0.4) 549 + if ((m = css.match(RE_RGBA_PCT))) { 550 + var rgb$3 = m.slice(1,5); 551 + for (var i$3=0; i$3<3; i$3++) { 552 + rgb$3[i$3] = round$2(rgb$3[i$3] * 2.55); 553 + } 554 + rgb$3[3] = +rgb$3[3]; 555 + return rgb$3; 556 + } 557 + 558 + // hsl(0,100%,50%) 559 + if ((m = css.match(RE_HSL))) { 560 + var hsl = m.slice(1,4); 561 + hsl[1] *= 0.01; 562 + hsl[2] *= 0.01; 563 + var rgb$4 = hsl2rgb_1(hsl); 564 + rgb$4[3] = 1; 565 + return rgb$4; 566 + } 567 + 568 + // hsla(0,100%,50%,0.5) 569 + if ((m = css.match(RE_HSLA))) { 570 + var hsl$1 = m.slice(1,4); 571 + hsl$1[1] *= 0.01; 572 + hsl$1[2] *= 0.01; 573 + var rgb$5 = hsl2rgb_1(hsl$1); 574 + rgb$5[3] = +m[4]; // default alpha = 1 575 + return rgb$5; 576 + } 577 + }; 578 + 579 + css2rgb.test = function (s) { 580 + return RE_RGB.test(s) || 581 + RE_RGBA.test(s) || 582 + RE_RGB_PCT.test(s) || 583 + RE_RGBA_PCT.test(s) || 584 + RE_HSL.test(s) || 585 + RE_HSLA.test(s); 586 + }; 587 + 588 + var css2rgb_1 = css2rgb; 589 + 590 + var type$3 = utils.type; 591 + 592 + 593 + 594 + 595 + Color_1.prototype.css = function(mode) { 596 + return rgb2css_1(this._rgb, mode); 597 + }; 598 + 599 + chroma_1.css = function () { 600 + var args = [], len = arguments.length; 601 + while ( len-- ) args[ len ] = arguments[ len ]; 602 + 603 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['css']) )); 604 + }; 605 + 606 + input.format.css = css2rgb_1; 607 + 608 + input.autodetect.push({ 609 + p: 5, 610 + test: function (h) { 611 + var rest = [], len = arguments.length - 1; 612 + while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ]; 613 + 614 + if (!rest.length && type$3(h) === 'string' && css2rgb_1.test(h)) { 615 + return 'css'; 616 + } 617 + } 618 + }); 619 + 620 + var unpack$8 = utils.unpack; 621 + 622 + input.format.gl = function () { 623 + var args = [], len = arguments.length; 624 + while ( len-- ) args[ len ] = arguments[ len ]; 625 + 626 + var rgb = unpack$8(args, 'rgba'); 627 + rgb[0] *= 255; 628 + rgb[1] *= 255; 629 + rgb[2] *= 255; 630 + return rgb; 631 + }; 632 + 633 + chroma_1.gl = function () { 634 + var args = [], len = arguments.length; 635 + while ( len-- ) args[ len ] = arguments[ len ]; 636 + 637 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['gl']) )); 638 + }; 639 + 640 + Color_1.prototype.gl = function() { 641 + var rgb = this._rgb; 642 + return [rgb[0]/255, rgb[1]/255, rgb[2]/255, rgb[3]]; 643 + }; 644 + 645 + var unpack$9 = utils.unpack; 646 + 647 + var rgb2hcg = function () { 648 + var args = [], len = arguments.length; 649 + while ( len-- ) args[ len ] = arguments[ len ]; 650 + 651 + var ref = unpack$9(args, 'rgb'); 652 + var r = ref[0]; 653 + var g = ref[1]; 654 + var b = ref[2]; 655 + var min = Math.min(r, g, b); 656 + var max = Math.max(r, g, b); 657 + var delta = max - min; 658 + var c = delta * 100 / 255; 659 + var _g = min / (255 - delta) * 100; 660 + var h; 661 + if (delta === 0) { 662 + h = Number.NaN; 663 + } else { 664 + if (r === max) { h = (g - b) / delta; } 665 + if (g === max) { h = 2+(b - r) / delta; } 666 + if (b === max) { h = 4+(r - g) / delta; } 667 + h *= 60; 668 + if (h < 0) { h += 360; } 669 + } 670 + return [h, c, _g]; 671 + }; 672 + 673 + var rgb2hcg_1 = rgb2hcg; 674 + 675 + var unpack$a = utils.unpack; 676 + var floor = Math.floor; 677 + 678 + /* 679 + * this is basically just HSV with some minor tweaks 680 + * 681 + * hue.. [0..360] 682 + * chroma .. [0..1] 683 + * grayness .. [0..1] 684 + */ 685 + 686 + var hcg2rgb = function () { 687 + var assign, assign$1, assign$2, assign$3, assign$4, assign$5; 688 + 689 + var args = [], len = arguments.length; 690 + while ( len-- ) args[ len ] = arguments[ len ]; 691 + args = unpack$a(args, 'hcg'); 692 + var h = args[0]; 693 + var c = args[1]; 694 + var _g = args[2]; 695 + var r,g,b; 696 + _g = _g * 255; 697 + var _c = c * 255; 698 + if (c === 0) { 699 + r = g = b = _g; 700 + } else { 701 + if (h === 360) { h = 0; } 702 + if (h > 360) { h -= 360; } 703 + if (h < 0) { h += 360; } 704 + h /= 60; 705 + var i = floor(h); 706 + var f = h - i; 707 + var p = _g * (1 - c); 708 + var q = p + _c * (1 - f); 709 + var t = p + _c * f; 710 + var v = p + _c; 711 + switch (i) { 712 + case 0: (assign = [v, t, p], r = assign[0], g = assign[1], b = assign[2]); break 713 + case 1: (assign$1 = [q, v, p], r = assign$1[0], g = assign$1[1], b = assign$1[2]); break 714 + case 2: (assign$2 = [p, v, t], r = assign$2[0], g = assign$2[1], b = assign$2[2]); break 715 + case 3: (assign$3 = [p, q, v], r = assign$3[0], g = assign$3[1], b = assign$3[2]); break 716 + case 4: (assign$4 = [t, p, v], r = assign$4[0], g = assign$4[1], b = assign$4[2]); break 717 + case 5: (assign$5 = [v, p, q], r = assign$5[0], g = assign$5[1], b = assign$5[2]); break 718 + } 719 + } 720 + return [r, g, b, args.length > 3 ? args[3] : 1]; 721 + }; 722 + 723 + var hcg2rgb_1 = hcg2rgb; 724 + 725 + var unpack$b = utils.unpack; 726 + var type$4 = utils.type; 727 + 728 + 729 + 730 + 731 + 732 + 733 + Color_1.prototype.hcg = function() { 734 + return rgb2hcg_1(this._rgb); 735 + }; 736 + 737 + chroma_1.hcg = function () { 738 + var args = [], len = arguments.length; 739 + while ( len-- ) args[ len ] = arguments[ len ]; 740 + 741 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hcg']) )); 742 + }; 743 + 744 + input.format.hcg = hcg2rgb_1; 745 + 746 + input.autodetect.push({ 747 + p: 1, 748 + test: function () { 749 + var args = [], len = arguments.length; 750 + while ( len-- ) args[ len ] = arguments[ len ]; 751 + 752 + args = unpack$b(args, 'hcg'); 753 + if (type$4(args) === 'array' && args.length === 3) { 754 + return 'hcg'; 755 + } 756 + } 757 + }); 758 + 759 + var unpack$c = utils.unpack; 760 + var last$4 = utils.last; 761 + var round$3 = Math.round; 762 + 763 + var rgb2hex = function () { 764 + var args = [], len = arguments.length; 765 + while ( len-- ) args[ len ] = arguments[ len ]; 766 + 767 + var ref = unpack$c(args, 'rgba'); 768 + var r = ref[0]; 769 + var g = ref[1]; 770 + var b = ref[2]; 771 + var a = ref[3]; 772 + var mode = last$4(args) || 'auto'; 773 + if (a === undefined) { a = 1; } 774 + if (mode === 'auto') { 775 + mode = a < 1 ? 'rgba' : 'rgb'; 776 + } 777 + r = round$3(r); 778 + g = round$3(g); 779 + b = round$3(b); 780 + var u = r << 16 | g << 8 | b; 781 + var str = "000000" + u.toString(16); //#.toUpperCase(); 782 + str = str.substr(str.length - 6); 783 + var hxa = '0' + round$3(a * 255).toString(16); 784 + hxa = hxa.substr(hxa.length - 2); 785 + switch (mode.toLowerCase()) { 786 + case 'rgba': return ("#" + str + hxa); 787 + case 'argb': return ("#" + hxa + str); 788 + default: return ("#" + str); 789 + } 790 + }; 791 + 792 + var rgb2hex_1 = rgb2hex; 793 + 794 + var RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/; 795 + var RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/; 796 + 797 + var hex2rgb = function (hex) { 798 + if (hex.match(RE_HEX)) { 799 + // remove optional leading # 800 + if (hex.length === 4 || hex.length === 7) { 801 + hex = hex.substr(1); 802 + } 803 + // expand short-notation to full six-digit 804 + if (hex.length === 3) { 805 + hex = hex.split(''); 806 + hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; 807 + } 808 + var u = parseInt(hex, 16); 809 + var r = u >> 16; 810 + var g = u >> 8 & 0xFF; 811 + var b = u & 0xFF; 812 + return [r,g,b,1]; 813 + } 814 + 815 + // match rgba hex format, eg #FF000077 816 + if (hex.match(RE_HEXA)) { 817 + if (hex.length === 5 || hex.length === 9) { 818 + // remove optional leading # 819 + hex = hex.substr(1); 820 + } 821 + // expand short-notation to full eight-digit 822 + if (hex.length === 4) { 823 + hex = hex.split(''); 824 + hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]+hex[3]+hex[3]; 825 + } 826 + var u$1 = parseInt(hex, 16); 827 + var r$1 = u$1 >> 24 & 0xFF; 828 + var g$1 = u$1 >> 16 & 0xFF; 829 + var b$1 = u$1 >> 8 & 0xFF; 830 + var a = Math.round((u$1 & 0xFF) / 0xFF * 100) / 100; 831 + return [r$1,g$1,b$1,a]; 832 + } 833 + 834 + // we used to check for css colors here 835 + // if _input.css? and rgb = _input.css hex 836 + // return rgb 837 + 838 + throw new Error(("unknown hex color: " + hex)); 839 + }; 840 + 841 + var hex2rgb_1 = hex2rgb; 842 + 843 + var type$5 = utils.type; 844 + 845 + 846 + 847 + 848 + Color_1.prototype.hex = function(mode) { 849 + return rgb2hex_1(this._rgb, mode); 850 + }; 851 + 852 + chroma_1.hex = function () { 853 + var args = [], len = arguments.length; 854 + while ( len-- ) args[ len ] = arguments[ len ]; 855 + 856 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hex']) )); 857 + }; 858 + 859 + input.format.hex = hex2rgb_1; 860 + input.autodetect.push({ 861 + p: 4, 862 + test: function (h) { 863 + var rest = [], len = arguments.length - 1; 864 + while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ]; 865 + 866 + if (!rest.length && type$5(h) === 'string' && [3,4,5,6,7,8,9].indexOf(h.length) >= 0) { 867 + return 'hex'; 868 + } 869 + } 870 + }); 871 + 872 + var unpack$d = utils.unpack; 873 + var TWOPI = utils.TWOPI; 874 + var min = Math.min; 875 + var sqrt = Math.sqrt; 876 + var acos = Math.acos; 877 + 878 + var rgb2hsi = function () { 879 + var args = [], len = arguments.length; 880 + while ( len-- ) args[ len ] = arguments[ len ]; 881 + 882 + /* 883 + borrowed from here: 884 + http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/rgb2hsi.cpp 885 + */ 886 + var ref = unpack$d(args, 'rgb'); 887 + var r = ref[0]; 888 + var g = ref[1]; 889 + var b = ref[2]; 890 + r /= 255; 891 + g /= 255; 892 + b /= 255; 893 + var h; 894 + var min_ = min(r,g,b); 895 + var i = (r+g+b) / 3; 896 + var s = i > 0 ? 1 - min_/i : 0; 897 + if (s === 0) { 898 + h = NaN; 899 + } else { 900 + h = ((r-g)+(r-b)) / 2; 901 + h /= sqrt((r-g)*(r-g) + (r-b)*(g-b)); 902 + h = acos(h); 903 + if (b > g) { 904 + h = TWOPI - h; 905 + } 906 + h /= TWOPI; 907 + } 908 + return [h*360,s,i]; 909 + }; 910 + 911 + var rgb2hsi_1 = rgb2hsi; 912 + 913 + var unpack$e = utils.unpack; 914 + var limit$1 = utils.limit; 915 + var TWOPI$1 = utils.TWOPI; 916 + var PITHIRD = utils.PITHIRD; 917 + var cos = Math.cos; 918 + 919 + /* 920 + * hue [0..360] 921 + * saturation [0..1] 922 + * intensity [0..1] 923 + */ 924 + var hsi2rgb = function () { 925 + var args = [], len = arguments.length; 926 + while ( len-- ) args[ len ] = arguments[ len ]; 927 + 928 + /* 929 + borrowed from here: 930 + http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/hsi2rgb.cpp 931 + */ 932 + args = unpack$e(args, 'hsi'); 933 + var h = args[0]; 934 + var s = args[1]; 935 + var i = args[2]; 936 + var r,g,b; 937 + 938 + if (isNaN(h)) { h = 0; } 939 + if (isNaN(s)) { s = 0; } 940 + // normalize hue 941 + if (h > 360) { h -= 360; } 942 + if (h < 0) { h += 360; } 943 + h /= 360; 944 + if (h < 1/3) { 945 + b = (1-s)/3; 946 + r = (1+s*cos(TWOPI$1*h)/cos(PITHIRD-TWOPI$1*h))/3; 947 + g = 1 - (b+r); 948 + } else if (h < 2/3) { 949 + h -= 1/3; 950 + r = (1-s)/3; 951 + g = (1+s*cos(TWOPI$1*h)/cos(PITHIRD-TWOPI$1*h))/3; 952 + b = 1 - (r+g); 953 + } else { 954 + h -= 2/3; 955 + g = (1-s)/3; 956 + b = (1+s*cos(TWOPI$1*h)/cos(PITHIRD-TWOPI$1*h))/3; 957 + r = 1 - (g+b); 958 + } 959 + r = limit$1(i*r*3); 960 + g = limit$1(i*g*3); 961 + b = limit$1(i*b*3); 962 + return [r*255, g*255, b*255, args.length > 3 ? args[3] : 1]; 963 + }; 964 + 965 + var hsi2rgb_1 = hsi2rgb; 966 + 967 + var unpack$f = utils.unpack; 968 + var type$6 = utils.type; 969 + 970 + 971 + 972 + 973 + 974 + 975 + Color_1.prototype.hsi = function() { 976 + return rgb2hsi_1(this._rgb); 977 + }; 978 + 979 + chroma_1.hsi = function () { 980 + var args = [], len = arguments.length; 981 + while ( len-- ) args[ len ] = arguments[ len ]; 982 + 983 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hsi']) )); 984 + }; 985 + 986 + input.format.hsi = hsi2rgb_1; 987 + 988 + input.autodetect.push({ 989 + p: 2, 990 + test: function () { 991 + var args = [], len = arguments.length; 992 + while ( len-- ) args[ len ] = arguments[ len ]; 993 + 994 + args = unpack$f(args, 'hsi'); 995 + if (type$6(args) === 'array' && args.length === 3) { 996 + return 'hsi'; 997 + } 998 + } 999 + }); 1000 + 1001 + var unpack$g = utils.unpack; 1002 + var type$7 = utils.type; 1003 + 1004 + 1005 + 1006 + 1007 + 1008 + 1009 + Color_1.prototype.hsl = function() { 1010 + return rgb2hsl_1(this._rgb); 1011 + }; 1012 + 1013 + chroma_1.hsl = function () { 1014 + var args = [], len = arguments.length; 1015 + while ( len-- ) args[ len ] = arguments[ len ]; 1016 + 1017 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hsl']) )); 1018 + }; 1019 + 1020 + input.format.hsl = hsl2rgb_1; 1021 + 1022 + input.autodetect.push({ 1023 + p: 2, 1024 + test: function () { 1025 + var args = [], len = arguments.length; 1026 + while ( len-- ) args[ len ] = arguments[ len ]; 1027 + 1028 + args = unpack$g(args, 'hsl'); 1029 + if (type$7(args) === 'array' && args.length === 3) { 1030 + return 'hsl'; 1031 + } 1032 + } 1033 + }); 1034 + 1035 + var unpack$h = utils.unpack; 1036 + var min$1 = Math.min; 1037 + var max$1 = Math.max; 1038 + 1039 + /* 1040 + * supported arguments: 1041 + * - rgb2hsv(r,g,b) 1042 + * - rgb2hsv([r,g,b]) 1043 + * - rgb2hsv({r,g,b}) 1044 + */ 1045 + var rgb2hsl$1 = function () { 1046 + var args = [], len = arguments.length; 1047 + while ( len-- ) args[ len ] = arguments[ len ]; 1048 + 1049 + args = unpack$h(args, 'rgb'); 1050 + var r = args[0]; 1051 + var g = args[1]; 1052 + var b = args[2]; 1053 + var min_ = min$1(r, g, b); 1054 + var max_ = max$1(r, g, b); 1055 + var delta = max_ - min_; 1056 + var h,s,v; 1057 + v = max_ / 255.0; 1058 + if (max_ === 0) { 1059 + h = Number.NaN; 1060 + s = 0; 1061 + } else { 1062 + s = delta / max_; 1063 + if (r === max_) { h = (g - b) / delta; } 1064 + if (g === max_) { h = 2+(b - r) / delta; } 1065 + if (b === max_) { h = 4+(r - g) / delta; } 1066 + h *= 60; 1067 + if (h < 0) { h += 360; } 1068 + } 1069 + return [h, s, v] 1070 + }; 1071 + 1072 + var rgb2hsv = rgb2hsl$1; 1073 + 1074 + var unpack$i = utils.unpack; 1075 + var floor$1 = Math.floor; 1076 + 1077 + var hsv2rgb = function () { 1078 + var assign, assign$1, assign$2, assign$3, assign$4, assign$5; 1079 + 1080 + var args = [], len = arguments.length; 1081 + while ( len-- ) args[ len ] = arguments[ len ]; 1082 + args = unpack$i(args, 'hsv'); 1083 + var h = args[0]; 1084 + var s = args[1]; 1085 + var v = args[2]; 1086 + var r,g,b; 1087 + v *= 255; 1088 + if (s === 0) { 1089 + r = g = b = v; 1090 + } else { 1091 + if (h === 360) { h = 0; } 1092 + if (h > 360) { h -= 360; } 1093 + if (h < 0) { h += 360; } 1094 + h /= 60; 1095 + 1096 + var i = floor$1(h); 1097 + var f = h - i; 1098 + var p = v * (1 - s); 1099 + var q = v * (1 - s * f); 1100 + var t = v * (1 - s * (1 - f)); 1101 + 1102 + switch (i) { 1103 + case 0: (assign = [v, t, p], r = assign[0], g = assign[1], b = assign[2]); break 1104 + case 1: (assign$1 = [q, v, p], r = assign$1[0], g = assign$1[1], b = assign$1[2]); break 1105 + case 2: (assign$2 = [p, v, t], r = assign$2[0], g = assign$2[1], b = assign$2[2]); break 1106 + case 3: (assign$3 = [p, q, v], r = assign$3[0], g = assign$3[1], b = assign$3[2]); break 1107 + case 4: (assign$4 = [t, p, v], r = assign$4[0], g = assign$4[1], b = assign$4[2]); break 1108 + case 5: (assign$5 = [v, p, q], r = assign$5[0], g = assign$5[1], b = assign$5[2]); break 1109 + } 1110 + } 1111 + return [r,g,b,args.length > 3?args[3]:1]; 1112 + }; 1113 + 1114 + var hsv2rgb_1 = hsv2rgb; 1115 + 1116 + var unpack$j = utils.unpack; 1117 + var type$8 = utils.type; 1118 + 1119 + 1120 + 1121 + 1122 + 1123 + 1124 + Color_1.prototype.hsv = function() { 1125 + return rgb2hsv(this._rgb); 1126 + }; 1127 + 1128 + chroma_1.hsv = function () { 1129 + var args = [], len = arguments.length; 1130 + while ( len-- ) args[ len ] = arguments[ len ]; 1131 + 1132 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hsv']) )); 1133 + }; 1134 + 1135 + input.format.hsv = hsv2rgb_1; 1136 + 1137 + input.autodetect.push({ 1138 + p: 2, 1139 + test: function () { 1140 + var args = [], len = arguments.length; 1141 + while ( len-- ) args[ len ] = arguments[ len ]; 1142 + 1143 + args = unpack$j(args, 'hsv'); 1144 + if (type$8(args) === 'array' && args.length === 3) { 1145 + return 'hsv'; 1146 + } 1147 + } 1148 + }); 1149 + 1150 + var labConstants = { 1151 + // Corresponds roughly to RGB brighter/darker 1152 + Kn: 18, 1153 + 1154 + // D65 standard referent 1155 + Xn: 0.950470, 1156 + Yn: 1, 1157 + Zn: 1.088830, 1158 + 1159 + t0: 0.137931034, // 4 / 29 1160 + t1: 0.206896552, // 6 / 29 1161 + t2: 0.12841855, // 3 * t1 * t1 1162 + t3: 0.008856452, // t1 * t1 * t1 1163 + }; 1164 + 1165 + var unpack$k = utils.unpack; 1166 + var pow = Math.pow; 1167 + 1168 + var rgb2lab = function () { 1169 + var args = [], len = arguments.length; 1170 + while ( len-- ) args[ len ] = arguments[ len ]; 1171 + 1172 + var ref = unpack$k(args, 'rgb'); 1173 + var r = ref[0]; 1174 + var g = ref[1]; 1175 + var b = ref[2]; 1176 + var ref$1 = rgb2xyz(r,g,b); 1177 + var x = ref$1[0]; 1178 + var y = ref$1[1]; 1179 + var z = ref$1[2]; 1180 + var l = 116 * y - 16; 1181 + return [l < 0 ? 0 : l, 500 * (x - y), 200 * (y - z)]; 1182 + }; 1183 + 1184 + var rgb_xyz = function (r) { 1185 + if ((r /= 255) <= 0.04045) { return r / 12.92; } 1186 + return pow((r + 0.055) / 1.055, 2.4); 1187 + }; 1188 + 1189 + var xyz_lab = function (t) { 1190 + if (t > labConstants.t3) { return pow(t, 1 / 3); } 1191 + return t / labConstants.t2 + labConstants.t0; 1192 + }; 1193 + 1194 + var rgb2xyz = function (r,g,b) { 1195 + r = rgb_xyz(r); 1196 + g = rgb_xyz(g); 1197 + b = rgb_xyz(b); 1198 + var x = xyz_lab((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / labConstants.Xn); 1199 + var y = xyz_lab((0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / labConstants.Yn); 1200 + var z = xyz_lab((0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / labConstants.Zn); 1201 + return [x,y,z]; 1202 + }; 1203 + 1204 + var rgb2lab_1 = rgb2lab; 1205 + 1206 + var unpack$l = utils.unpack; 1207 + var pow$1 = Math.pow; 1208 + 1209 + /* 1210 + * L* [0..100] 1211 + * a [-100..100] 1212 + * b [-100..100] 1213 + */ 1214 + var lab2rgb = function () { 1215 + var args = [], len = arguments.length; 1216 + while ( len-- ) args[ len ] = arguments[ len ]; 1217 + 1218 + args = unpack$l(args, 'lab'); 1219 + var l = args[0]; 1220 + var a = args[1]; 1221 + var b = args[2]; 1222 + var x,y,z, r,g,b_; 1223 + 1224 + y = (l + 16) / 116; 1225 + x = isNaN(a) ? y : y + a / 500; 1226 + z = isNaN(b) ? y : y - b / 200; 1227 + 1228 + y = labConstants.Yn * lab_xyz(y); 1229 + x = labConstants.Xn * lab_xyz(x); 1230 + z = labConstants.Zn * lab_xyz(z); 1231 + 1232 + r = xyz_rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z); // D65 -> sRGB 1233 + g = xyz_rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z); 1234 + b_ = xyz_rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z); 1235 + 1236 + return [r,g,b_,args.length > 3 ? args[3] : 1]; 1237 + }; 1238 + 1239 + var xyz_rgb = function (r) { 1240 + return 255 * (r <= 0.00304 ? 12.92 * r : 1.055 * pow$1(r, 1 / 2.4) - 0.055) 1241 + }; 1242 + 1243 + var lab_xyz = function (t) { 1244 + return t > labConstants.t1 ? t * t * t : labConstants.t2 * (t - labConstants.t0) 1245 + }; 1246 + 1247 + var lab2rgb_1 = lab2rgb; 1248 + 1249 + var unpack$m = utils.unpack; 1250 + var type$9 = utils.type; 1251 + 1252 + 1253 + 1254 + 1255 + 1256 + 1257 + Color_1.prototype.lab = function() { 1258 + return rgb2lab_1(this._rgb); 1259 + }; 1260 + 1261 + chroma_1.lab = function () { 1262 + var args = [], len = arguments.length; 1263 + while ( len-- ) args[ len ] = arguments[ len ]; 1264 + 1265 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['lab']) )); 1266 + }; 1267 + 1268 + input.format.lab = lab2rgb_1; 1269 + 1270 + input.autodetect.push({ 1271 + p: 2, 1272 + test: function () { 1273 + var args = [], len = arguments.length; 1274 + while ( len-- ) args[ len ] = arguments[ len ]; 1275 + 1276 + args = unpack$m(args, 'lab'); 1277 + if (type$9(args) === 'array' && args.length === 3) { 1278 + return 'lab'; 1279 + } 1280 + } 1281 + }); 1282 + 1283 + var unpack$n = utils.unpack; 1284 + var RAD2DEG = utils.RAD2DEG; 1285 + var sqrt$1 = Math.sqrt; 1286 + var atan2 = Math.atan2; 1287 + var round$4 = Math.round; 1288 + 1289 + var lab2lch = function () { 1290 + var args = [], len = arguments.length; 1291 + while ( len-- ) args[ len ] = arguments[ len ]; 1292 + 1293 + var ref = unpack$n(args, 'lab'); 1294 + var l = ref[0]; 1295 + var a = ref[1]; 1296 + var b = ref[2]; 1297 + var c = sqrt$1(a * a + b * b); 1298 + var h = (atan2(b, a) * RAD2DEG + 360) % 360; 1299 + if (round$4(c*10000) === 0) { h = Number.NaN; } 1300 + return [l, c, h]; 1301 + }; 1302 + 1303 + var lab2lch_1 = lab2lch; 1304 + 1305 + var unpack$o = utils.unpack; 1306 + 1307 + 1308 + 1309 + var rgb2lch = function () { 1310 + var args = [], len = arguments.length; 1311 + while ( len-- ) args[ len ] = arguments[ len ]; 1312 + 1313 + var ref = unpack$o(args, 'rgb'); 1314 + var r = ref[0]; 1315 + var g = ref[1]; 1316 + var b = ref[2]; 1317 + var ref$1 = rgb2lab_1(r,g,b); 1318 + var l = ref$1[0]; 1319 + var a = ref$1[1]; 1320 + var b_ = ref$1[2]; 1321 + return lab2lch_1(l,a,b_); 1322 + }; 1323 + 1324 + var rgb2lch_1 = rgb2lch; 1325 + 1326 + var unpack$p = utils.unpack; 1327 + var DEG2RAD = utils.DEG2RAD; 1328 + var sin = Math.sin; 1329 + var cos$1 = Math.cos; 1330 + 1331 + var lch2lab = function () { 1332 + var args = [], len = arguments.length; 1333 + while ( len-- ) args[ len ] = arguments[ len ]; 1334 + 1335 + /* 1336 + Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel. 1337 + These formulas were invented by David Dalrymple to obtain maximum contrast without going 1338 + out of gamut if the parameters are in the range 0-1. 1339 + 1340 + A saturation multiplier was added by Gregor Aisch 1341 + */ 1342 + var ref = unpack$p(args, 'lch'); 1343 + var l = ref[0]; 1344 + var c = ref[1]; 1345 + var h = ref[2]; 1346 + if (isNaN(h)) { h = 0; } 1347 + h = h * DEG2RAD; 1348 + return [l, cos$1(h) * c, sin(h) * c] 1349 + }; 1350 + 1351 + var lch2lab_1 = lch2lab; 1352 + 1353 + var unpack$q = utils.unpack; 1354 + 1355 + 1356 + 1357 + var lch2rgb = function () { 1358 + var args = [], len = arguments.length; 1359 + while ( len-- ) args[ len ] = arguments[ len ]; 1360 + 1361 + args = unpack$q(args, 'lch'); 1362 + var l = args[0]; 1363 + var c = args[1]; 1364 + var h = args[2]; 1365 + var ref = lch2lab_1 (l,c,h); 1366 + var L = ref[0]; 1367 + var a = ref[1]; 1368 + var b_ = ref[2]; 1369 + var ref$1 = lab2rgb_1 (L,a,b_); 1370 + var r = ref$1[0]; 1371 + var g = ref$1[1]; 1372 + var b = ref$1[2]; 1373 + return [r, g, b, args.length > 3 ? args[3] : 1]; 1374 + }; 1375 + 1376 + var lch2rgb_1 = lch2rgb; 1377 + 1378 + var unpack$r = utils.unpack; 1379 + 1380 + 1381 + var hcl2rgb = function () { 1382 + var args = [], len = arguments.length; 1383 + while ( len-- ) args[ len ] = arguments[ len ]; 1384 + 1385 + var hcl = unpack$r(args, 'hcl').reverse(); 1386 + return lch2rgb_1.apply(void 0, hcl); 1387 + }; 1388 + 1389 + var hcl2rgb_1 = hcl2rgb; 1390 + 1391 + var unpack$s = utils.unpack; 1392 + var type$a = utils.type; 1393 + 1394 + 1395 + 1396 + 1397 + 1398 + 1399 + Color_1.prototype.lch = function() { return rgb2lch_1(this._rgb); }; 1400 + Color_1.prototype.hcl = function() { return rgb2lch_1(this._rgb).reverse(); }; 1401 + 1402 + chroma_1.lch = function () { 1403 + var args = [], len = arguments.length; 1404 + while ( len-- ) args[ len ] = arguments[ len ]; 1405 + 1406 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['lch']) )); 1407 + }; 1408 + chroma_1.hcl = function () { 1409 + var args = [], len = arguments.length; 1410 + while ( len-- ) args[ len ] = arguments[ len ]; 1411 + 1412 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['hcl']) )); 1413 + }; 1414 + 1415 + input.format.lch = lch2rgb_1; 1416 + input.format.hcl = hcl2rgb_1; 1417 + 1418 + ['lch','hcl'].forEach(function (m) { return input.autodetect.push({ 1419 + p: 2, 1420 + test: function () { 1421 + var args = [], len = arguments.length; 1422 + while ( len-- ) args[ len ] = arguments[ len ]; 1423 + 1424 + args = unpack$s(args, m); 1425 + if (type$a(args) === 'array' && args.length === 3) { 1426 + return m; 1427 + } 1428 + } 1429 + }); }); 1430 + 1431 + /** 1432 + X11 color names 1433 + 1434 + http://www.w3.org/TR/css3-color/#svg-color 1435 + */ 1436 + 1437 + var w3cx11 = { 1438 + aliceblue: '#f0f8ff', 1439 + antiquewhite: '#faebd7', 1440 + aqua: '#00ffff', 1441 + aquamarine: '#7fffd4', 1442 + azure: '#f0ffff', 1443 + beige: '#f5f5dc', 1444 + bisque: '#ffe4c4', 1445 + black: '#000000', 1446 + blanchedalmond: '#ffebcd', 1447 + blue: '#0000ff', 1448 + blueviolet: '#8a2be2', 1449 + brown: '#a52a2a', 1450 + burlywood: '#deb887', 1451 + cadetblue: '#5f9ea0', 1452 + chartreuse: '#7fff00', 1453 + chocolate: '#d2691e', 1454 + coral: '#ff7f50', 1455 + cornflower: '#6495ed', 1456 + cornflowerblue: '#6495ed', 1457 + cornsilk: '#fff8dc', 1458 + crimson: '#dc143c', 1459 + cyan: '#00ffff', 1460 + darkblue: '#00008b', 1461 + darkcyan: '#008b8b', 1462 + darkgoldenrod: '#b8860b', 1463 + darkgray: '#a9a9a9', 1464 + darkgreen: '#006400', 1465 + darkgrey: '#a9a9a9', 1466 + darkkhaki: '#bdb76b', 1467 + darkmagenta: '#8b008b', 1468 + darkolivegreen: '#556b2f', 1469 + darkorange: '#ff8c00', 1470 + darkorchid: '#9932cc', 1471 + darkred: '#8b0000', 1472 + darksalmon: '#e9967a', 1473 + darkseagreen: '#8fbc8f', 1474 + darkslateblue: '#483d8b', 1475 + darkslategray: '#2f4f4f', 1476 + darkslategrey: '#2f4f4f', 1477 + darkturquoise: '#00ced1', 1478 + darkviolet: '#9400d3', 1479 + deeppink: '#ff1493', 1480 + deepskyblue: '#00bfff', 1481 + dimgray: '#696969', 1482 + dimgrey: '#696969', 1483 + dodgerblue: '#1e90ff', 1484 + firebrick: '#b22222', 1485 + floralwhite: '#fffaf0', 1486 + forestgreen: '#228b22', 1487 + fuchsia: '#ff00ff', 1488 + gainsboro: '#dcdcdc', 1489 + ghostwhite: '#f8f8ff', 1490 + gold: '#ffd700', 1491 + goldenrod: '#daa520', 1492 + gray: '#808080', 1493 + green: '#008000', 1494 + greenyellow: '#adff2f', 1495 + grey: '#808080', 1496 + honeydew: '#f0fff0', 1497 + hotpink: '#ff69b4', 1498 + indianred: '#cd5c5c', 1499 + indigo: '#4b0082', 1500 + ivory: '#fffff0', 1501 + khaki: '#f0e68c', 1502 + laserlemon: '#ffff54', 1503 + lavender: '#e6e6fa', 1504 + lavenderblush: '#fff0f5', 1505 + lawngreen: '#7cfc00', 1506 + lemonchiffon: '#fffacd', 1507 + lightblue: '#add8e6', 1508 + lightcoral: '#f08080', 1509 + lightcyan: '#e0ffff', 1510 + lightgoldenrod: '#fafad2', 1511 + lightgoldenrodyellow: '#fafad2', 1512 + lightgray: '#d3d3d3', 1513 + lightgreen: '#90ee90', 1514 + lightgrey: '#d3d3d3', 1515 + lightpink: '#ffb6c1', 1516 + lightsalmon: '#ffa07a', 1517 + lightseagreen: '#20b2aa', 1518 + lightskyblue: '#87cefa', 1519 + lightslategray: '#778899', 1520 + lightslategrey: '#778899', 1521 + lightsteelblue: '#b0c4de', 1522 + lightyellow: '#ffffe0', 1523 + lime: '#00ff00', 1524 + limegreen: '#32cd32', 1525 + linen: '#faf0e6', 1526 + magenta: '#ff00ff', 1527 + maroon: '#800000', 1528 + maroon2: '#7f0000', 1529 + maroon3: '#b03060', 1530 + mediumaquamarine: '#66cdaa', 1531 + mediumblue: '#0000cd', 1532 + mediumorchid: '#ba55d3', 1533 + mediumpurple: '#9370db', 1534 + mediumseagreen: '#3cb371', 1535 + mediumslateblue: '#7b68ee', 1536 + mediumspringgreen: '#00fa9a', 1537 + mediumturquoise: '#48d1cc', 1538 + mediumvioletred: '#c71585', 1539 + midnightblue: '#191970', 1540 + mintcream: '#f5fffa', 1541 + mistyrose: '#ffe4e1', 1542 + moccasin: '#ffe4b5', 1543 + navajowhite: '#ffdead', 1544 + navy: '#000080', 1545 + oldlace: '#fdf5e6', 1546 + olive: '#808000', 1547 + olivedrab: '#6b8e23', 1548 + orange: '#ffa500', 1549 + orangered: '#ff4500', 1550 + orchid: '#da70d6', 1551 + palegoldenrod: '#eee8aa', 1552 + palegreen: '#98fb98', 1553 + paleturquoise: '#afeeee', 1554 + palevioletred: '#db7093', 1555 + papayawhip: '#ffefd5', 1556 + peachpuff: '#ffdab9', 1557 + peru: '#cd853f', 1558 + pink: '#ffc0cb', 1559 + plum: '#dda0dd', 1560 + powderblue: '#b0e0e6', 1561 + purple: '#800080', 1562 + purple2: '#7f007f', 1563 + purple3: '#a020f0', 1564 + rebeccapurple: '#663399', 1565 + red: '#ff0000', 1566 + rosybrown: '#bc8f8f', 1567 + royalblue: '#4169e1', 1568 + saddlebrown: '#8b4513', 1569 + salmon: '#fa8072', 1570 + sandybrown: '#f4a460', 1571 + seagreen: '#2e8b57', 1572 + seashell: '#fff5ee', 1573 + sienna: '#a0522d', 1574 + silver: '#c0c0c0', 1575 + skyblue: '#87ceeb', 1576 + slateblue: '#6a5acd', 1577 + slategray: '#708090', 1578 + slategrey: '#708090', 1579 + snow: '#fffafa', 1580 + springgreen: '#00ff7f', 1581 + steelblue: '#4682b4', 1582 + tan: '#d2b48c', 1583 + teal: '#008080', 1584 + thistle: '#d8bfd8', 1585 + tomato: '#ff6347', 1586 + turquoise: '#40e0d0', 1587 + violet: '#ee82ee', 1588 + wheat: '#f5deb3', 1589 + white: '#ffffff', 1590 + whitesmoke: '#f5f5f5', 1591 + yellow: '#ffff00', 1592 + yellowgreen: '#9acd32' 1593 + }; 1594 + 1595 + var w3cx11_1 = w3cx11; 1596 + 1597 + var type$b = utils.type; 1598 + 1599 + 1600 + 1601 + 1602 + 1603 + Color_1.prototype.name = function() { 1604 + var hex = rgb2hex_1(this._rgb, 'rgb'); 1605 + for (var i = 0, list = Object.keys(w3cx11_1); i < list.length; i += 1) { 1606 + var n = list[i]; 1607 + 1608 + if (w3cx11_1[n] === hex) { return n.toLowerCase(); } 1609 + } 1610 + return hex; 1611 + }; 1612 + 1613 + input.format.named = function (name) { 1614 + name = name.toLowerCase(); 1615 + if (w3cx11_1[name]) { return hex2rgb_1(w3cx11_1[name]); } 1616 + throw new Error('unknown color name: '+name); 1617 + }; 1618 + 1619 + input.autodetect.push({ 1620 + p: 5, 1621 + test: function (h) { 1622 + var rest = [], len = arguments.length - 1; 1623 + while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ]; 1624 + 1625 + if (!rest.length && type$b(h) === 'string' && w3cx11_1[h.toLowerCase()]) { 1626 + return 'named'; 1627 + } 1628 + } 1629 + }); 1630 + 1631 + var unpack$t = utils.unpack; 1632 + 1633 + var rgb2num = function () { 1634 + var args = [], len = arguments.length; 1635 + while ( len-- ) args[ len ] = arguments[ len ]; 1636 + 1637 + var ref = unpack$t(args, 'rgb'); 1638 + var r = ref[0]; 1639 + var g = ref[1]; 1640 + var b = ref[2]; 1641 + return (r << 16) + (g << 8) + b; 1642 + }; 1643 + 1644 + var rgb2num_1 = rgb2num; 1645 + 1646 + var type$c = utils.type; 1647 + 1648 + var num2rgb = function (num) { 1649 + if (type$c(num) == "number" && num >= 0 && num <= 0xFFFFFF) { 1650 + var r = num >> 16; 1651 + var g = (num >> 8) & 0xFF; 1652 + var b = num & 0xFF; 1653 + return [r,g,b,1]; 1654 + } 1655 + throw new Error("unknown num color: "+num); 1656 + }; 1657 + 1658 + var num2rgb_1 = num2rgb; 1659 + 1660 + var type$d = utils.type; 1661 + 1662 + 1663 + 1664 + Color_1.prototype.num = function() { 1665 + return rgb2num_1(this._rgb); 1666 + }; 1667 + 1668 + chroma_1.num = function () { 1669 + var args = [], len = arguments.length; 1670 + while ( len-- ) args[ len ] = arguments[ len ]; 1671 + 1672 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['num']) )); 1673 + }; 1674 + 1675 + input.format.num = num2rgb_1; 1676 + 1677 + input.autodetect.push({ 1678 + p: 5, 1679 + test: function () { 1680 + var args = [], len = arguments.length; 1681 + while ( len-- ) args[ len ] = arguments[ len ]; 1682 + 1683 + if (args.length === 1 && type$d(args[0]) === 'number' && args[0] >= 0 && args[0] <= 0xFFFFFF) { 1684 + return 'num'; 1685 + } 1686 + } 1687 + }); 1688 + 1689 + var unpack$u = utils.unpack; 1690 + var type$e = utils.type; 1691 + var round$5 = Math.round; 1692 + 1693 + Color_1.prototype.rgb = function(rnd) { 1694 + if ( rnd === void 0 ) rnd=true; 1695 + 1696 + if (rnd === false) { return this._rgb.slice(0,3); } 1697 + return this._rgb.slice(0,3).map(round$5); 1698 + }; 1699 + 1700 + Color_1.prototype.rgba = function(rnd) { 1701 + if ( rnd === void 0 ) rnd=true; 1702 + 1703 + return this._rgb.slice(0,4).map(function (v,i) { 1704 + return i<3 ? (rnd === false ? v : round$5(v)) : v; 1705 + }); 1706 + }; 1707 + 1708 + chroma_1.rgb = function () { 1709 + var args = [], len = arguments.length; 1710 + while ( len-- ) args[ len ] = arguments[ len ]; 1711 + 1712 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['rgb']) )); 1713 + }; 1714 + 1715 + input.format.rgb = function () { 1716 + var args = [], len = arguments.length; 1717 + while ( len-- ) args[ len ] = arguments[ len ]; 1718 + 1719 + var rgba = unpack$u(args, 'rgba'); 1720 + if (rgba[3] === undefined) { rgba[3] = 1; } 1721 + return rgba; 1722 + }; 1723 + 1724 + input.autodetect.push({ 1725 + p: 3, 1726 + test: function () { 1727 + var args = [], len = arguments.length; 1728 + while ( len-- ) args[ len ] = arguments[ len ]; 1729 + 1730 + args = unpack$u(args, 'rgba'); 1731 + if (type$e(args) === 'array' && (args.length === 3 || 1732 + args.length === 4 && type$e(args[3]) == 'number' && args[3] >= 0 && args[3] <= 1)) { 1733 + return 'rgb'; 1734 + } 1735 + } 1736 + }); 1737 + 1738 + /* 1739 + * Based on implementation by Neil Bartlett 1740 + * https://github.com/neilbartlett/color-temperature 1741 + */ 1742 + 1743 + var log = Math.log; 1744 + 1745 + var temperature2rgb = function (kelvin) { 1746 + var temp = kelvin / 100; 1747 + var r,g,b; 1748 + if (temp < 66) { 1749 + r = 255; 1750 + g = -155.25485562709179 - 0.44596950469579133 * (g = temp-2) + 104.49216199393888 * log(g); 1751 + b = temp < 20 ? 0 : -254.76935184120902 + 0.8274096064007395 * (b = temp-10) + 115.67994401066147 * log(b); 1752 + } else { 1753 + r = 351.97690566805693 + 0.114206453784165 * (r = temp-55) - 40.25366309332127 * log(r); 1754 + g = 325.4494125711974 + 0.07943456536662342 * (g = temp-50) - 28.0852963507957 * log(g); 1755 + b = 255; 1756 + } 1757 + return [r,g,b,1]; 1758 + }; 1759 + 1760 + var temperature2rgb_1 = temperature2rgb; 1761 + 1762 + /* 1763 + * Based on implementation by Neil Bartlett 1764 + * https://github.com/neilbartlett/color-temperature 1765 + **/ 1766 + 1767 + 1768 + var unpack$v = utils.unpack; 1769 + var round$6 = Math.round; 1770 + 1771 + var rgb2temperature = function () { 1772 + var args = [], len = arguments.length; 1773 + while ( len-- ) args[ len ] = arguments[ len ]; 1774 + 1775 + var rgb = unpack$v(args, 'rgb'); 1776 + var r = rgb[0], b = rgb[2]; 1777 + var minTemp = 1000; 1778 + var maxTemp = 40000; 1779 + var eps = 0.4; 1780 + var temp; 1781 + while (maxTemp - minTemp > eps) { 1782 + temp = (maxTemp + minTemp) * 0.5; 1783 + var rgb$1 = temperature2rgb_1(temp); 1784 + if ((rgb$1[2] / rgb$1[0]) >= (b / r)) { 1785 + maxTemp = temp; 1786 + } else { 1787 + minTemp = temp; 1788 + } 1789 + } 1790 + return round$6(temp); 1791 + }; 1792 + 1793 + var rgb2temperature_1 = rgb2temperature; 1794 + 1795 + Color_1.prototype.temp = 1796 + Color_1.prototype.kelvin = 1797 + Color_1.prototype.temperature = function() { 1798 + return rgb2temperature_1(this._rgb); 1799 + }; 1800 + 1801 + chroma_1.temp = 1802 + chroma_1.kelvin = 1803 + chroma_1.temperature = function () { 1804 + var args = [], len = arguments.length; 1805 + while ( len-- ) args[ len ] = arguments[ len ]; 1806 + 1807 + return new (Function.prototype.bind.apply( Color_1, [ null ].concat( args, ['temp']) )); 1808 + }; 1809 + 1810 + input.format.temp = 1811 + input.format.kelvin = 1812 + input.format.temperature = temperature2rgb_1; 1813 + 1814 + var type$f = utils.type; 1815 + 1816 + Color_1.prototype.alpha = function(a, mutate) { 1817 + if ( mutate === void 0 ) mutate=false; 1818 + 1819 + if (a !== undefined && type$f(a) === 'number') { 1820 + if (mutate) { 1821 + this._rgb[3] = a; 1822 + return this; 1823 + } 1824 + return new Color_1([this._rgb[0], this._rgb[1], this._rgb[2], a], 'rgb'); 1825 + } 1826 + return this._rgb[3]; 1827 + }; 1828 + 1829 + Color_1.prototype.clipped = function() { 1830 + return this._rgb._clipped || false; 1831 + }; 1832 + 1833 + Color_1.prototype.darken = function(amount) { 1834 + if ( amount === void 0 ) amount=1; 1835 + 1836 + var me = this; 1837 + var lab = me.lab(); 1838 + lab[0] -= labConstants.Kn * amount; 1839 + return new Color_1(lab, 'lab').alpha(me.alpha(), true); 1840 + }; 1841 + 1842 + Color_1.prototype.brighten = function(amount) { 1843 + if ( amount === void 0 ) amount=1; 1844 + 1845 + return this.darken(-amount); 1846 + }; 1847 + 1848 + Color_1.prototype.darker = Color_1.prototype.darken; 1849 + Color_1.prototype.brighter = Color_1.prototype.brighten; 1850 + 1851 + Color_1.prototype.get = function(mc) { 1852 + var ref = mc.split('.'); 1853 + var mode = ref[0]; 1854 + var channel = ref[1]; 1855 + var src = this[mode](); 1856 + if (channel) { 1857 + var i = mode.indexOf(channel); 1858 + if (i > -1) { return src[i]; } 1859 + throw new Error(("unknown channel " + channel + " in mode " + mode)); 1860 + } else { 1861 + return src; 1862 + } 1863 + }; 1864 + 1865 + var type$g = utils.type; 1866 + var pow$2 = Math.pow; 1867 + 1868 + var EPS = 1e-7; 1869 + var MAX_ITER = 20; 1870 + 1871 + Color_1.prototype.luminance = function(lum) { 1872 + if (lum !== undefined && type$g(lum) === 'number') { 1873 + if (lum === 0) { 1874 + // return pure black 1875 + return new Color_1([0,0,0,this._rgb[3]], 'rgb'); 1876 + } 1877 + if (lum === 1) { 1878 + // return pure white 1879 + return new Color_1([255,255,255,this._rgb[3]], 'rgb'); 1880 + } 1881 + // compute new color using... 1882 + var cur_lum = this.luminance(); 1883 + var mode = 'rgb'; 1884 + var max_iter = MAX_ITER; 1885 + 1886 + var test = function (low, high) { 1887 + var mid = low.interpolate(high, 0.5, mode); 1888 + var lm = mid.luminance(); 1889 + if (Math.abs(lum - lm) < EPS || !max_iter--) { 1890 + // close enough 1891 + return mid; 1892 + } 1893 + return lm > lum ? test(low, mid) : test(mid, high); 1894 + }; 1895 + 1896 + var rgb = (cur_lum > lum ? test(new Color_1([0,0,0]), this) : test(this, new Color_1([255,255,255]))).rgb(); 1897 + return new Color_1(rgb.concat( [this._rgb[3]])); 1898 + } 1899 + return rgb2luminance.apply(void 0, (this._rgb).slice(0,3)); 1900 + }; 1901 + 1902 + 1903 + var rgb2luminance = function (r,g,b) { 1904 + // relative luminance 1905 + // see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef 1906 + r = luminance_x(r); 1907 + g = luminance_x(g); 1908 + b = luminance_x(b); 1909 + return 0.2126 * r + 0.7152 * g + 0.0722 * b; 1910 + }; 1911 + 1912 + var luminance_x = function (x) { 1913 + x /= 255; 1914 + return x <= 0.03928 ? x/12.92 : pow$2((x+0.055)/1.055, 2.4); 1915 + }; 1916 + 1917 + var interpolator = {}; 1918 + 1919 + var type$h = utils.type; 1920 + 1921 + 1922 + var mix = function (col1, col2, f) { 1923 + if ( f === void 0 ) f=0.5; 1924 + var rest = [], len = arguments.length - 3; 1925 + while ( len-- > 0 ) rest[ len ] = arguments[ len + 3 ]; 1926 + 1927 + var mode = rest[0] || 'lrgb'; 1928 + if (!interpolator[mode] && !rest.length) { 1929 + // fall back to the first supported mode 1930 + mode = Object.keys(interpolator)[0]; 1931 + } 1932 + if (!interpolator[mode]) { 1933 + throw new Error(("interpolation mode " + mode + " is not defined")); 1934 + } 1935 + if (type$h(col1) !== 'object') { col1 = new Color_1(col1); } 1936 + if (type$h(col2) !== 'object') { col2 = new Color_1(col2); } 1937 + return interpolator[mode](col1, col2, f) 1938 + .alpha(col1.alpha() + f * (col2.alpha() - col1.alpha())); 1939 + }; 1940 + 1941 + Color_1.prototype.mix = 1942 + Color_1.prototype.interpolate = function(col2, f) { 1943 + if ( f === void 0 ) f=0.5; 1944 + var rest = [], len = arguments.length - 2; 1945 + while ( len-- > 0 ) rest[ len ] = arguments[ len + 2 ]; 1946 + 1947 + return mix.apply(void 0, [ this, col2, f ].concat( rest )); 1948 + }; 1949 + 1950 + Color_1.prototype.premultiply = function(mutate) { 1951 + if ( mutate === void 0 ) mutate=false; 1952 + 1953 + var rgb = this._rgb; 1954 + var a = rgb[3]; 1955 + if (mutate) { 1956 + this._rgb = [rgb[0]*a, rgb[1]*a, rgb[2]*a, a]; 1957 + return this; 1958 + } else { 1959 + return new Color_1([rgb[0]*a, rgb[1]*a, rgb[2]*a, a], 'rgb'); 1960 + } 1961 + }; 1962 + 1963 + Color_1.prototype.saturate = function(amount) { 1964 + if ( amount === void 0 ) amount=1; 1965 + 1966 + var me = this; 1967 + var lch = me.lch(); 1968 + lch[1] += labConstants.Kn * amount; 1969 + if (lch[1] < 0) { lch[1] = 0; } 1970 + return new Color_1(lch, 'lch').alpha(me.alpha(), true); 1971 + }; 1972 + 1973 + Color_1.prototype.desaturate = function(amount) { 1974 + if ( amount === void 0 ) amount=1; 1975 + 1976 + return this.saturate(-amount); 1977 + }; 1978 + 1979 + var type$i = utils.type; 1980 + 1981 + Color_1.prototype.set = function(mc, value, mutate) { 1982 + if ( mutate === void 0 ) mutate=false; 1983 + 1984 + var ref = mc.split('.'); 1985 + var mode = ref[0]; 1986 + var channel = ref[1]; 1987 + var src = this[mode](); 1988 + if (channel) { 1989 + var i = mode.indexOf(channel); 1990 + if (i > -1) { 1991 + if (type$i(value) == 'string') { 1992 + switch(value.charAt(0)) { 1993 + case '+': src[i] += +value; break; 1994 + case '-': src[i] += +value; break; 1995 + case '*': src[i] *= +(value.substr(1)); break; 1996 + case '/': src[i] /= +(value.substr(1)); break; 1997 + default: src[i] = +value; 1998 + } 1999 + } else if (type$i(value) === 'number') { 2000 + src[i] = value; 2001 + } else { 2002 + throw new Error("unsupported value for Color.set"); 2003 + } 2004 + var out = new Color_1(src, mode); 2005 + if (mutate) { 2006 + this._rgb = out._rgb; 2007 + return this; 2008 + } 2009 + return out; 2010 + } 2011 + throw new Error(("unknown channel " + channel + " in mode " + mode)); 2012 + } else { 2013 + return src; 2014 + } 2015 + }; 2016 + 2017 + var rgb$1 = function (col1, col2, f) { 2018 + var xyz0 = col1._rgb; 2019 + var xyz1 = col2._rgb; 2020 + return new Color_1( 2021 + xyz0[0] + f * (xyz1[0]-xyz0[0]), 2022 + xyz0[1] + f * (xyz1[1]-xyz0[1]), 2023 + xyz0[2] + f * (xyz1[2]-xyz0[2]), 2024 + 'rgb' 2025 + ) 2026 + }; 2027 + 2028 + // register interpolator 2029 + interpolator.rgb = rgb$1; 2030 + 2031 + var sqrt$2 = Math.sqrt; 2032 + var pow$3 = Math.pow; 2033 + 2034 + var lrgb = function (col1, col2, f) { 2035 + var ref = col1._rgb; 2036 + var x1 = ref[0]; 2037 + var y1 = ref[1]; 2038 + var z1 = ref[2]; 2039 + var ref$1 = col2._rgb; 2040 + var x2 = ref$1[0]; 2041 + var y2 = ref$1[1]; 2042 + var z2 = ref$1[2]; 2043 + return new Color_1( 2044 + sqrt$2(pow$3(x1,2) * (1-f) + pow$3(x2,2) * f), 2045 + sqrt$2(pow$3(y1,2) * (1-f) + pow$3(y2,2) * f), 2046 + sqrt$2(pow$3(z1,2) * (1-f) + pow$3(z2,2) * f), 2047 + 'rgb' 2048 + ) 2049 + }; 2050 + 2051 + // register interpolator 2052 + interpolator.lrgb = lrgb; 2053 + 2054 + var lab$1 = function (col1, col2, f) { 2055 + var xyz0 = col1.lab(); 2056 + var xyz1 = col2.lab(); 2057 + return new Color_1( 2058 + xyz0[0] + f * (xyz1[0]-xyz0[0]), 2059 + xyz0[1] + f * (xyz1[1]-xyz0[1]), 2060 + xyz0[2] + f * (xyz1[2]-xyz0[2]), 2061 + 'lab' 2062 + ) 2063 + }; 2064 + 2065 + // register interpolator 2066 + interpolator.lab = lab$1; 2067 + 2068 + var _hsx = function (col1, col2, f, m) { 2069 + var assign, assign$1; 2070 + 2071 + var xyz0, xyz1; 2072 + if (m === 'hsl') { 2073 + xyz0 = col1.hsl(); 2074 + xyz1 = col2.hsl(); 2075 + } else if (m === 'hsv') { 2076 + xyz0 = col1.hsv(); 2077 + xyz1 = col2.hsv(); 2078 + } else if (m === 'hcg') { 2079 + xyz0 = col1.hcg(); 2080 + xyz1 = col2.hcg(); 2081 + } else if (m === 'hsi') { 2082 + xyz0 = col1.hsi(); 2083 + xyz1 = col2.hsi(); 2084 + } else if (m === 'lch' || m === 'hcl') { 2085 + m = 'hcl'; 2086 + xyz0 = col1.hcl(); 2087 + xyz1 = col2.hcl(); 2088 + } 2089 + 2090 + var hue0, hue1, sat0, sat1, lbv0, lbv1; 2091 + if (m.substr(0, 1) === 'h') { 2092 + (assign = xyz0, hue0 = assign[0], sat0 = assign[1], lbv0 = assign[2]); 2093 + (assign$1 = xyz1, hue1 = assign$1[0], sat1 = assign$1[1], lbv1 = assign$1[2]); 2094 + } 2095 + 2096 + var sat, hue, lbv, dh; 2097 + 2098 + if (!isNaN(hue0) && !isNaN(hue1)) { 2099 + // both colors have hue 2100 + if (hue1 > hue0 && hue1 - hue0 > 180) { 2101 + dh = hue1-(hue0+360); 2102 + } else if (hue1 < hue0 && hue0 - hue1 > 180) { 2103 + dh = hue1+360-hue0; 2104 + } else { 2105 + dh = hue1 - hue0; 2106 + } 2107 + hue = hue0 + f * dh; 2108 + } else if (!isNaN(hue0)) { 2109 + hue = hue0; 2110 + if ((lbv1 == 1 || lbv1 == 0) && m != 'hsv') { sat = sat0; } 2111 + } else if (!isNaN(hue1)) { 2112 + hue = hue1; 2113 + if ((lbv0 == 1 || lbv0 == 0) && m != 'hsv') { sat = sat1; } 2114 + } else { 2115 + hue = Number.NaN; 2116 + } 2117 + 2118 + if (sat === undefined) { sat = sat0 + f * (sat1 - sat0); } 2119 + lbv = lbv0 + f * (lbv1-lbv0); 2120 + return new Color_1([hue, sat, lbv], m); 2121 + }; 2122 + 2123 + var lch$1 = function (col1, col2, f) { 2124 + return _hsx(col1, col2, f, 'lch'); 2125 + }; 2126 + 2127 + // register interpolator 2128 + interpolator.lch = lch$1; 2129 + interpolator.hcl = lch$1; 2130 + 2131 + var num$1 = function (col1, col2, f) { 2132 + var c1 = col1.num(); 2133 + var c2 = col2.num(); 2134 + return new Color_1(c1 + f * (c2-c1), 'num') 2135 + }; 2136 + 2137 + // register interpolator 2138 + interpolator.num = num$1; 2139 + 2140 + var hcg$1 = function (col1, col2, f) { 2141 + return _hsx(col1, col2, f, 'hcg'); 2142 + }; 2143 + 2144 + // register interpolator 2145 + interpolator.hcg = hcg$1; 2146 + 2147 + var hsi$1 = function (col1, col2, f) { 2148 + return _hsx(col1, col2, f, 'hsi'); 2149 + }; 2150 + 2151 + // register interpolator 2152 + interpolator.hsi = hsi$1; 2153 + 2154 + var hsl$1 = function (col1, col2, f) { 2155 + return _hsx(col1, col2, f, 'hsl'); 2156 + }; 2157 + 2158 + // register interpolator 2159 + interpolator.hsl = hsl$1; 2160 + 2161 + var hsv$1 = function (col1, col2, f) { 2162 + return _hsx(col1, col2, f, 'hsv'); 2163 + }; 2164 + 2165 + // register interpolator 2166 + interpolator.hsv = hsv$1; 2167 + 2168 + var clip_rgb$2 = utils.clip_rgb; 2169 + var pow$4 = Math.pow; 2170 + var sqrt$3 = Math.sqrt; 2171 + var PI$1 = Math.PI; 2172 + var cos$2 = Math.cos; 2173 + var sin$1 = Math.sin; 2174 + var atan2$1 = Math.atan2; 2175 + 2176 + var average = function (colors, mode, weights) { 2177 + if ( mode === void 0 ) mode='lrgb'; 2178 + if ( weights === void 0 ) weights=null; 2179 + 2180 + var l = colors.length; 2181 + if (!weights) { weights = Array.from(new Array(l)).map(function () { return 1; }); } 2182 + // normalize weights 2183 + var k = l / weights.reduce(function(a, b) { return a + b; }); 2184 + weights.forEach(function (w,i) { weights[i] *= k; }); 2185 + // convert colors to Color objects 2186 + colors = colors.map(function (c) { return new Color_1(c); }); 2187 + if (mode === 'lrgb') { 2188 + return _average_lrgb(colors, weights) 2189 + } 2190 + var first = colors.shift(); 2191 + var xyz = first.get(mode); 2192 + var cnt = []; 2193 + var dx = 0; 2194 + var dy = 0; 2195 + // initial color 2196 + for (var i=0; i<xyz.length; i++) { 2197 + xyz[i] = (xyz[i] || 0) * weights[0]; 2198 + cnt.push(isNaN(xyz[i]) ? 0 : weights[0]); 2199 + if (mode.charAt(i) === 'h' && !isNaN(xyz[i])) { 2200 + var A = xyz[i] / 180 * PI$1; 2201 + dx += cos$2(A) * weights[0]; 2202 + dy += sin$1(A) * weights[0]; 2203 + } 2204 + } 2205 + 2206 + var alpha = first.alpha() * weights[0]; 2207 + colors.forEach(function (c,ci) { 2208 + var xyz2 = c.get(mode); 2209 + alpha += c.alpha() * weights[ci+1]; 2210 + for (var i=0; i<xyz.length; i++) { 2211 + if (!isNaN(xyz2[i])) { 2212 + cnt[i] += weights[ci+1]; 2213 + if (mode.charAt(i) === 'h') { 2214 + var A = xyz2[i] / 180 * PI$1; 2215 + dx += cos$2(A) * weights[ci+1]; 2216 + dy += sin$1(A) * weights[ci+1]; 2217 + } else { 2218 + xyz[i] += xyz2[i] * weights[ci+1]; 2219 + } 2220 + } 2221 + } 2222 + }); 2223 + 2224 + for (var i$1=0; i$1<xyz.length; i$1++) { 2225 + if (mode.charAt(i$1) === 'h') { 2226 + var A$1 = atan2$1(dy / cnt[i$1], dx / cnt[i$1]) / PI$1 * 180; 2227 + while (A$1 < 0) { A$1 += 360; } 2228 + while (A$1 >= 360) { A$1 -= 360; } 2229 + xyz[i$1] = A$1; 2230 + } else { 2231 + xyz[i$1] = xyz[i$1]/cnt[i$1]; 2232 + } 2233 + } 2234 + alpha /= l; 2235 + return (new Color_1(xyz, mode)).alpha(alpha > 0.99999 ? 1 : alpha, true); 2236 + }; 2237 + 2238 + 2239 + var _average_lrgb = function (colors, weights) { 2240 + var l = colors.length; 2241 + var xyz = [0,0,0,0]; 2242 + for (var i=0; i < colors.length; i++) { 2243 + var col = colors[i]; 2244 + var f = weights[i] / l; 2245 + var rgb = col._rgb; 2246 + xyz[0] += pow$4(rgb[0],2) * f; 2247 + xyz[1] += pow$4(rgb[1],2) * f; 2248 + xyz[2] += pow$4(rgb[2],2) * f; 2249 + xyz[3] += rgb[3] * f; 2250 + } 2251 + xyz[0] = sqrt$3(xyz[0]); 2252 + xyz[1] = sqrt$3(xyz[1]); 2253 + xyz[2] = sqrt$3(xyz[2]); 2254 + if (xyz[3] > 0.9999999) { xyz[3] = 1; } 2255 + return new Color_1(clip_rgb$2(xyz)); 2256 + }; 2257 + 2258 + // minimal multi-purpose interface 2259 + 2260 + // @requires utils color analyze 2261 + 2262 + 2263 + var type$j = utils.type; 2264 + 2265 + var pow$5 = Math.pow; 2266 + 2267 + var scale = function(colors) { 2268 + 2269 + // constructor 2270 + var _mode = 'rgb'; 2271 + var _nacol = chroma_1('#ccc'); 2272 + var _spread = 0; 2273 + // const _fixed = false; 2274 + var _domain = [0, 1]; 2275 + var _pos = []; 2276 + var _padding = [0,0]; 2277 + var _classes = false; 2278 + var _colors = []; 2279 + var _out = false; 2280 + var _min = 0; 2281 + var _max = 1; 2282 + var _correctLightness = false; 2283 + var _colorCache = {}; 2284 + var _useCache = true; 2285 + var _gamma = 1; 2286 + 2287 + // private methods 2288 + 2289 + var setColors = function(colors) { 2290 + colors = colors || ['#fff', '#000']; 2291 + if (colors && type$j(colors) === 'string' && chroma_1.brewer && 2292 + chroma_1.brewer[colors.toLowerCase()]) { 2293 + colors = chroma_1.brewer[colors.toLowerCase()]; 2294 + } 2295 + if (type$j(colors) === 'array') { 2296 + // handle single color 2297 + if (colors.length === 1) { 2298 + colors = [colors[0], colors[0]]; 2299 + } 2300 + // make a copy of the colors 2301 + colors = colors.slice(0); 2302 + // convert to chroma classes 2303 + for (var c=0; c<colors.length; c++) { 2304 + colors[c] = chroma_1(colors[c]); 2305 + } 2306 + // auto-fill color position 2307 + _pos.length = 0; 2308 + for (var c$1=0; c$1<colors.length; c$1++) { 2309 + _pos.push(c$1/(colors.length-1)); 2310 + } 2311 + } 2312 + resetCache(); 2313 + return _colors = colors; 2314 + }; 2315 + 2316 + var getClass = function(value) { 2317 + if (_classes != null) { 2318 + var n = _classes.length-1; 2319 + var i = 0; 2320 + while (i < n && value >= _classes[i]) { 2321 + i++; 2322 + } 2323 + return i-1; 2324 + } 2325 + return 0; 2326 + }; 2327 + 2328 + var tMapLightness = function (t) { return t; }; 2329 + var tMapDomain = function (t) { return t; }; 2330 + 2331 + // const classifyValue = function(value) { 2332 + // let val = value; 2333 + // if (_classes.length > 2) { 2334 + // const n = _classes.length-1; 2335 + // const i = getClass(value); 2336 + // const minc = _classes[0] + ((_classes[1]-_classes[0]) * (0 + (_spread * 0.5))); // center of 1st class 2337 + // const maxc = _classes[n-1] + ((_classes[n]-_classes[n-1]) * (1 - (_spread * 0.5))); // center of last class 2338 + // val = _min + ((((_classes[i] + ((_classes[i+1] - _classes[i]) * 0.5)) - minc) / (maxc-minc)) * (_max - _min)); 2339 + // } 2340 + // return val; 2341 + // }; 2342 + 2343 + var getColor = function(val, bypassMap) { 2344 + var col, t; 2345 + if (bypassMap == null) { bypassMap = false; } 2346 + if (isNaN(val) || (val === null)) { return _nacol; } 2347 + if (!bypassMap) { 2348 + if (_classes && (_classes.length > 2)) { 2349 + // find the class 2350 + var c = getClass(val); 2351 + t = c / (_classes.length-2); 2352 + } else if (_max !== _min) { 2353 + // just interpolate between min/max 2354 + t = (val - _min) / (_max - _min); 2355 + } else { 2356 + t = 1; 2357 + } 2358 + } else { 2359 + t = val; 2360 + } 2361 + 2362 + // domain map 2363 + t = tMapDomain(t); 2364 + 2365 + if (!bypassMap) { 2366 + t = tMapLightness(t); // lightness correction 2367 + } 2368 + 2369 + if (_gamma !== 1) { t = pow$5(t, _gamma); } 2370 + 2371 + t = _padding[0] + (t * (1 - _padding[0] - _padding[1])); 2372 + 2373 + t = Math.min(1, Math.max(0, t)); 2374 + 2375 + var k = Math.floor(t * 10000); 2376 + 2377 + if (_useCache && _colorCache[k]) { 2378 + col = _colorCache[k]; 2379 + } else { 2380 + if (type$j(_colors) === 'array') { 2381 + //for i in [0.._pos.length-1] 2382 + for (var i=0; i<_pos.length; i++) { 2383 + var p = _pos[i]; 2384 + if (t <= p) { 2385 + col = _colors[i]; 2386 + break; 2387 + } 2388 + if ((t >= p) && (i === (_pos.length-1))) { 2389 + col = _colors[i]; 2390 + break; 2391 + } 2392 + if (t > p && t < _pos[i+1]) { 2393 + t = (t-p)/(_pos[i+1]-p); 2394 + col = chroma_1.interpolate(_colors[i], _colors[i+1], t, _mode); 2395 + break; 2396 + } 2397 + } 2398 + } else if (type$j(_colors) === 'function') { 2399 + col = _colors(t); 2400 + } 2401 + if (_useCache) { _colorCache[k] = col; } 2402 + } 2403 + return col; 2404 + }; 2405 + 2406 + var resetCache = function () { return _colorCache = {}; }; 2407 + 2408 + setColors(colors); 2409 + 2410 + // public interface 2411 + 2412 + var f = function(v) { 2413 + var c = chroma_1(getColor(v)); 2414 + if (_out && c[_out]) { return c[_out](); } else { return c; } 2415 + }; 2416 + 2417 + f.classes = function(classes) { 2418 + if (classes != null) { 2419 + if (type$j(classes) === 'array') { 2420 + _classes = classes; 2421 + _domain = [classes[0], classes[classes.length-1]]; 2422 + } else { 2423 + var d = chroma_1.analyze(_domain); 2424 + if (classes === 0) { 2425 + _classes = [d.min, d.max]; 2426 + } else { 2427 + _classes = chroma_1.limits(d, 'e', classes); 2428 + } 2429 + } 2430 + return f; 2431 + } 2432 + return _classes; 2433 + }; 2434 + 2435 + 2436 + f.domain = function(domain) { 2437 + if (!arguments.length) { 2438 + return _domain; 2439 + } 2440 + _min = domain[0]; 2441 + _max = domain[domain.length-1]; 2442 + _pos = []; 2443 + var k = _colors.length; 2444 + if ((domain.length === k) && (_min !== _max)) { 2445 + // update positions 2446 + for (var i = 0, list = Array.from(domain); i < list.length; i += 1) { 2447 + var d = list[i]; 2448 + 2449 + _pos.push((d-_min) / (_max-_min)); 2450 + } 2451 + } else { 2452 + for (var c=0; c<k; c++) { 2453 + _pos.push(c/(k-1)); 2454 + } 2455 + if (domain.length > 2) { 2456 + // set domain map 2457 + var tOut = domain.map(function (d,i) { return i/(domain.length-1); }); 2458 + var tBreaks = domain.map(function (d) { return (d - _min) / (_max - _min); }); 2459 + if (!tBreaks.every(function (val, i) { return tOut[i] === val; })) { 2460 + tMapDomain = function (t) { 2461 + if (t <= 0 || t >= 1) { return t; } 2462 + var i = 0; 2463 + while (t >= tBreaks[i+1]) { i++; } 2464 + var f = (t - tBreaks[i]) / (tBreaks[i+1] - tBreaks[i]); 2465 + var out = tOut[i] + f * (tOut[i+1] - tOut[i]); 2466 + return out; 2467 + }; 2468 + } 2469 + 2470 + } 2471 + } 2472 + _domain = [_min, _max]; 2473 + return f; 2474 + }; 2475 + 2476 + f.mode = function(_m) { 2477 + if (!arguments.length) { 2478 + return _mode; 2479 + } 2480 + _mode = _m; 2481 + resetCache(); 2482 + return f; 2483 + }; 2484 + 2485 + f.range = function(colors, _pos) { 2486 + setColors(colors); 2487 + return f; 2488 + }; 2489 + 2490 + f.out = function(_o) { 2491 + _out = _o; 2492 + return f; 2493 + }; 2494 + 2495 + f.spread = function(val) { 2496 + if (!arguments.length) { 2497 + return _spread; 2498 + } 2499 + _spread = val; 2500 + return f; 2501 + }; 2502 + 2503 + f.correctLightness = function(v) { 2504 + if (v == null) { v = true; } 2505 + _correctLightness = v; 2506 + resetCache(); 2507 + if (_correctLightness) { 2508 + tMapLightness = function(t) { 2509 + var L0 = getColor(0, true).lab()[0]; 2510 + var L1 = getColor(1, true).lab()[0]; 2511 + var pol = L0 > L1; 2512 + var L_actual = getColor(t, true).lab()[0]; 2513 + var L_ideal = L0 + ((L1 - L0) * t); 2514 + var L_diff = L_actual - L_ideal; 2515 + var t0 = 0; 2516 + var t1 = 1; 2517 + var max_iter = 20; 2518 + while ((Math.abs(L_diff) > 1e-2) && (max_iter-- > 0)) { 2519 + (function() { 2520 + if (pol) { L_diff *= -1; } 2521 + if (L_diff < 0) { 2522 + t0 = t; 2523 + t += (t1 - t) * 0.5; 2524 + } else { 2525 + t1 = t; 2526 + t += (t0 - t) * 0.5; 2527 + } 2528 + L_actual = getColor(t, true).lab()[0]; 2529 + return L_diff = L_actual - L_ideal; 2530 + })(); 2531 + } 2532 + return t; 2533 + }; 2534 + } else { 2535 + tMapLightness = function (t) { return t; }; 2536 + } 2537 + return f; 2538 + }; 2539 + 2540 + f.padding = function(p) { 2541 + if (p != null) { 2542 + if (type$j(p) === 'number') { 2543 + p = [p,p]; 2544 + } 2545 + _padding = p; 2546 + return f; 2547 + } else { 2548 + return _padding; 2549 + } 2550 + }; 2551 + 2552 + f.colors = function(numColors, out) { 2553 + // If no arguments are given, return the original colors that were provided 2554 + if (arguments.length < 2) { out = 'hex'; } 2555 + var result = []; 2556 + 2557 + if (arguments.length === 0) { 2558 + result = _colors.slice(0); 2559 + 2560 + } else if (numColors === 1) { 2561 + result = [f(0.5)]; 2562 + 2563 + } else if (numColors > 1) { 2564 + var dm = _domain[0]; 2565 + var dd = _domain[1] - dm; 2566 + result = __range__(0, numColors, false).map(function (i) { return f( dm + ((i/(numColors-1)) * dd) ); }); 2567 + 2568 + } else { // returns all colors based on the defined classes 2569 + colors = []; 2570 + var samples = []; 2571 + if (_classes && (_classes.length > 2)) { 2572 + for (var i = 1, end = _classes.length, asc = 1 <= end; asc ? i < end : i > end; asc ? i++ : i--) { 2573 + samples.push((_classes[i-1]+_classes[i])*0.5); 2574 + } 2575 + } else { 2576 + samples = _domain; 2577 + } 2578 + result = samples.map(function (v) { return f(v); }); 2579 + } 2580 + 2581 + if (chroma_1[out]) { 2582 + result = result.map(function (c) { return c[out](); }); 2583 + } 2584 + return result; 2585 + }; 2586 + 2587 + f.cache = function(c) { 2588 + if (c != null) { 2589 + _useCache = c; 2590 + return f; 2591 + } else { 2592 + return _useCache; 2593 + } 2594 + }; 2595 + 2596 + f.gamma = function(g) { 2597 + if (g != null) { 2598 + _gamma = g; 2599 + return f; 2600 + } else { 2601 + return _gamma; 2602 + } 2603 + }; 2604 + 2605 + f.nodata = function(d) { 2606 + if (d != null) { 2607 + _nacol = chroma_1(d); 2608 + return f; 2609 + } else { 2610 + return _nacol; 2611 + } 2612 + }; 2613 + 2614 + return f; 2615 + }; 2616 + 2617 + function __range__(left, right, inclusive) { 2618 + var range = []; 2619 + var ascending = left < right; 2620 + var end = !inclusive ? right : ascending ? right + 1 : right - 1; 2621 + for (var i = left; ascending ? i < end : i > end; ascending ? i++ : i--) { 2622 + range.push(i); 2623 + } 2624 + return range; 2625 + } 2626 + 2627 + // 2628 + // interpolates between a set of colors uzing a bezier spline 2629 + // 2630 + 2631 + // @requires utils lab 2632 + 2633 + 2634 + 2635 + 2636 + var bezier = function(colors) { 2637 + var assign, assign$1, assign$2; 2638 + 2639 + var I, lab0, lab1, lab2; 2640 + colors = colors.map(function (c) { return new Color_1(c); }); 2641 + if (colors.length === 2) { 2642 + // linear interpolation 2643 + (assign = colors.map(function (c) { return c.lab(); }), lab0 = assign[0], lab1 = assign[1]); 2644 + I = function(t) { 2645 + var lab = ([0, 1, 2].map(function (i) { return lab0[i] + (t * (lab1[i] - lab0[i])); })); 2646 + return new Color_1(lab, 'lab'); 2647 + }; 2648 + } else if (colors.length === 3) { 2649 + // quadratic bezier interpolation 2650 + (assign$1 = colors.map(function (c) { return c.lab(); }), lab0 = assign$1[0], lab1 = assign$1[1], lab2 = assign$1[2]); 2651 + I = function(t) { 2652 + var lab = ([0, 1, 2].map(function (i) { return ((1-t)*(1-t) * lab0[i]) + (2 * (1-t) * t * lab1[i]) + (t * t * lab2[i]); })); 2653 + return new Color_1(lab, 'lab'); 2654 + }; 2655 + } else if (colors.length === 4) { 2656 + // cubic bezier interpolation 2657 + var lab3; 2658 + (assign$2 = colors.map(function (c) { return c.lab(); }), lab0 = assign$2[0], lab1 = assign$2[1], lab2 = assign$2[2], lab3 = assign$2[3]); 2659 + I = function(t) { 2660 + var lab = ([0, 1, 2].map(function (i) { return ((1-t)*(1-t)*(1-t) * lab0[i]) + (3 * (1-t) * (1-t) * t * lab1[i]) + (3 * (1-t) * t * t * lab2[i]) + (t*t*t * lab3[i]); })); 2661 + return new Color_1(lab, 'lab'); 2662 + }; 2663 + } else if (colors.length === 5) { 2664 + var I0 = bezier(colors.slice(0, 3)); 2665 + var I1 = bezier(colors.slice(2, 5)); 2666 + I = function(t) { 2667 + if (t < 0.5) { 2668 + return I0(t*2); 2669 + } else { 2670 + return I1((t-0.5)*2); 2671 + } 2672 + }; 2673 + } 2674 + return I; 2675 + }; 2676 + 2677 + var bezier_1 = function (colors) { 2678 + var f = bezier(colors); 2679 + f.scale = function () { return scale(f); }; 2680 + return f; 2681 + }; 2682 + 2683 + /* 2684 + * interpolates between a set of colors uzing a bezier spline 2685 + * blend mode formulas taken from http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/ 2686 + */ 2687 + 2688 + 2689 + 2690 + 2691 + var blend = function (bottom, top, mode) { 2692 + if (!blend[mode]) { 2693 + throw new Error('unknown blend mode ' + mode); 2694 + } 2695 + return blend[mode](bottom, top); 2696 + }; 2697 + 2698 + var blend_f = function (f) { return function (bottom,top) { 2699 + var c0 = chroma_1(top).rgb(); 2700 + var c1 = chroma_1(bottom).rgb(); 2701 + return chroma_1.rgb(f(c0, c1)); 2702 + }; }; 2703 + 2704 + var each = function (f) { return function (c0, c1) { 2705 + var out = []; 2706 + out[0] = f(c0[0], c1[0]); 2707 + out[1] = f(c0[1], c1[1]); 2708 + out[2] = f(c0[2], c1[2]); 2709 + return out; 2710 + }; }; 2711 + 2712 + var normal = function (a) { return a; }; 2713 + var multiply = function (a,b) { return a * b / 255; }; 2714 + var darken$1 = function (a,b) { return a > b ? b : a; }; 2715 + var lighten = function (a,b) { return a > b ? a : b; }; 2716 + var screen = function (a,b) { return 255 * (1 - (1-a/255) * (1-b/255)); }; 2717 + var overlay = function (a,b) { return b < 128 ? 2 * a * b / 255 : 255 * (1 - 2 * (1 - a / 255 ) * ( 1 - b / 255 )); }; 2718 + var burn = function (a,b) { return 255 * (1 - (1 - b / 255) / (a/255)); }; 2719 + var dodge = function (a,b) { 2720 + if (a === 255) { return 255; } 2721 + a = 255 * (b / 255) / (1 - a / 255); 2722 + return a > 255 ? 255 : a 2723 + }; 2724 + 2725 + // # add = (a,b) -> 2726 + // # if (a + b > 255) then 255 else a + b 2727 + 2728 + blend.normal = blend_f(each(normal)); 2729 + blend.multiply = blend_f(each(multiply)); 2730 + blend.screen = blend_f(each(screen)); 2731 + blend.overlay = blend_f(each(overlay)); 2732 + blend.darken = blend_f(each(darken$1)); 2733 + blend.lighten = blend_f(each(lighten)); 2734 + blend.dodge = blend_f(each(dodge)); 2735 + blend.burn = blend_f(each(burn)); 2736 + // blend.add = blend_f(each(add)); 2737 + 2738 + var blend_1 = blend; 2739 + 2740 + // cubehelix interpolation 2741 + // based on D.A. Green "A colour scheme for the display of astronomical intensity images" 2742 + // http://astron-soc.in/bulletin/11June/289392011.pdf 2743 + 2744 + var type$k = utils.type; 2745 + var clip_rgb$3 = utils.clip_rgb; 2746 + var TWOPI$2 = utils.TWOPI; 2747 + var pow$6 = Math.pow; 2748 + var sin$2 = Math.sin; 2749 + var cos$3 = Math.cos; 2750 + 2751 + 2752 + var cubehelix = function(start, rotations, hue, gamma, lightness) { 2753 + if ( start === void 0 ) start=300; 2754 + if ( rotations === void 0 ) rotations=-1.5; 2755 + if ( hue === void 0 ) hue=1; 2756 + if ( gamma === void 0 ) gamma=1; 2757 + if ( lightness === void 0 ) lightness=[0,1]; 2758 + 2759 + var dh = 0, dl; 2760 + if (type$k(lightness) === 'array') { 2761 + dl = lightness[1] - lightness[0]; 2762 + } else { 2763 + dl = 0; 2764 + lightness = [lightness, lightness]; 2765 + } 2766 + 2767 + var f = function(fract) { 2768 + var a = TWOPI$2 * (((start+120)/360) + (rotations * fract)); 2769 + var l = pow$6(lightness[0] + (dl * fract), gamma); 2770 + var h = dh !== 0 ? hue[0] + (fract * dh) : hue; 2771 + var amp = (h * l * (1-l)) / 2; 2772 + var cos_a = cos$3(a); 2773 + var sin_a = sin$2(a); 2774 + var r = l + (amp * ((-0.14861 * cos_a) + (1.78277* sin_a))); 2775 + var g = l + (amp * ((-0.29227 * cos_a) - (0.90649* sin_a))); 2776 + var b = l + (amp * (+1.97294 * cos_a)); 2777 + return chroma_1(clip_rgb$3([r*255,g*255,b*255,1])); 2778 + }; 2779 + 2780 + f.start = function(s) { 2781 + if ((s == null)) { return start; } 2782 + start = s; 2783 + return f; 2784 + }; 2785 + 2786 + f.rotations = function(r) { 2787 + if ((r == null)) { return rotations; } 2788 + rotations = r; 2789 + return f; 2790 + }; 2791 + 2792 + f.gamma = function(g) { 2793 + if ((g == null)) { return gamma; } 2794 + gamma = g; 2795 + return f; 2796 + }; 2797 + 2798 + f.hue = function(h) { 2799 + if ((h == null)) { return hue; } 2800 + hue = h; 2801 + if (type$k(hue) === 'array') { 2802 + dh = hue[1] - hue[0]; 2803 + if (dh === 0) { hue = hue[1]; } 2804 + } else { 2805 + dh = 0; 2806 + } 2807 + return f; 2808 + }; 2809 + 2810 + f.lightness = function(h) { 2811 + if ((h == null)) { return lightness; } 2812 + if (type$k(h) === 'array') { 2813 + lightness = h; 2814 + dl = h[1] - h[0]; 2815 + } else { 2816 + lightness = [h,h]; 2817 + dl = 0; 2818 + } 2819 + return f; 2820 + }; 2821 + 2822 + f.scale = function () { return chroma_1.scale(f); }; 2823 + 2824 + f.hue(hue); 2825 + 2826 + return f; 2827 + }; 2828 + 2829 + var digits = '0123456789abcdef'; 2830 + 2831 + var floor$2 = Math.floor; 2832 + var random = Math.random; 2833 + 2834 + var random_1 = function () { 2835 + var code = '#'; 2836 + for (var i=0; i<6; i++) { 2837 + code += digits.charAt(floor$2(random() * 16)); 2838 + } 2839 + return new Color_1(code, 'hex'); 2840 + }; 2841 + 2842 + var log$1 = Math.log; 2843 + var pow$7 = Math.pow; 2844 + var floor$3 = Math.floor; 2845 + var abs = Math.abs; 2846 + 2847 + 2848 + var analyze = function (data, key) { 2849 + if ( key === void 0 ) key=null; 2850 + 2851 + var r = { 2852 + min: Number.MAX_VALUE, 2853 + max: Number.MAX_VALUE*-1, 2854 + sum: 0, 2855 + values: [], 2856 + count: 0 2857 + }; 2858 + if (type(data) === 'object') { 2859 + data = Object.values(data); 2860 + } 2861 + data.forEach(function (val) { 2862 + if (key && type(val) === 'object') { val = val[key]; } 2863 + if (val !== undefined && val !== null && !isNaN(val)) { 2864 + r.values.push(val); 2865 + r.sum += val; 2866 + if (val < r.min) { r.min = val; } 2867 + if (val > r.max) { r.max = val; } 2868 + r.count += 1; 2869 + } 2870 + }); 2871 + 2872 + r.domain = [r.min, r.max]; 2873 + 2874 + r.limits = function (mode, num) { return limits(r, mode, num); }; 2875 + 2876 + return r; 2877 + }; 2878 + 2879 + 2880 + var limits = function (data, mode, num) { 2881 + if ( mode === void 0 ) mode='equal'; 2882 + if ( num === void 0 ) num=7; 2883 + 2884 + if (type(data) == 'array') { 2885 + data = analyze(data); 2886 + } 2887 + var min = data.min; 2888 + var max = data.max; 2889 + var values = data.values.sort(function (a,b) { return a-b; }); 2890 + 2891 + if (num === 1) { return [min,max]; } 2892 + 2893 + var limits = []; 2894 + 2895 + if (mode.substr(0,1) === 'c') { // continuous 2896 + limits.push(min); 2897 + limits.push(max); 2898 + } 2899 + 2900 + if (mode.substr(0,1) === 'e') { // equal interval 2901 + limits.push(min); 2902 + for (var i=1; i<num; i++) { 2903 + limits.push(min+((i/num)*(max-min))); 2904 + } 2905 + limits.push(max); 2906 + } 2907 + 2908 + else if (mode.substr(0,1) === 'l') { // log scale 2909 + if (min <= 0) { 2910 + throw new Error('Logarithmic scales are only possible for values > 0'); 2911 + } 2912 + var min_log = Math.LOG10E * log$1(min); 2913 + var max_log = Math.LOG10E * log$1(max); 2914 + limits.push(min); 2915 + for (var i$1=1; i$1<num; i$1++) { 2916 + limits.push(pow$7(10, min_log + ((i$1/num) * (max_log - min_log)))); 2917 + } 2918 + limits.push(max); 2919 + } 2920 + 2921 + else if (mode.substr(0,1) === 'q') { // quantile scale 2922 + limits.push(min); 2923 + for (var i$2=1; i$2<num; i$2++) { 2924 + var p = ((values.length-1) * i$2)/num; 2925 + var pb = floor$3(p); 2926 + if (pb === p) { 2927 + limits.push(values[pb]); 2928 + } else { // p > pb 2929 + var pr = p - pb; 2930 + limits.push((values[pb]*(1-pr)) + (values[pb+1]*pr)); 2931 + } 2932 + } 2933 + limits.push(max); 2934 + 2935 + } 2936 + 2937 + else if (mode.substr(0,1) === 'k') { // k-means clustering 2938 + /* 2939 + implementation based on 2940 + http://code.google.com/p/figue/source/browse/trunk/figue.js#336 2941 + simplified for 1-d input values 2942 + */ 2943 + var cluster; 2944 + var n = values.length; 2945 + var assignments = new Array(n); 2946 + var clusterSizes = new Array(num); 2947 + var repeat = true; 2948 + var nb_iters = 0; 2949 + var centroids = null; 2950 + 2951 + // get seed values 2952 + centroids = []; 2953 + centroids.push(min); 2954 + for (var i$3=1; i$3<num; i$3++) { 2955 + centroids.push(min + ((i$3/num) * (max-min))); 2956 + } 2957 + centroids.push(max); 2958 + 2959 + while (repeat) { 2960 + // assignment step 2961 + for (var j=0; j<num; j++) { 2962 + clusterSizes[j] = 0; 2963 + } 2964 + for (var i$4=0; i$4<n; i$4++) { 2965 + var value = values[i$4]; 2966 + var mindist = Number.MAX_VALUE; 2967 + var best = (void 0); 2968 + for (var j$1=0; j$1<num; j$1++) { 2969 + var dist = abs(centroids[j$1]-value); 2970 + if (dist < mindist) { 2971 + mindist = dist; 2972 + best = j$1; 2973 + } 2974 + clusterSizes[best]++; 2975 + assignments[i$4] = best; 2976 + } 2977 + } 2978 + 2979 + // update centroids step 2980 + var newCentroids = new Array(num); 2981 + for (var j$2=0; j$2<num; j$2++) { 2982 + newCentroids[j$2] = null; 2983 + } 2984 + for (var i$5=0; i$5<n; i$5++) { 2985 + cluster = assignments[i$5]; 2986 + if (newCentroids[cluster] === null) { 2987 + newCentroids[cluster] = values[i$5]; 2988 + } else { 2989 + newCentroids[cluster] += values[i$5]; 2990 + } 2991 + } 2992 + for (var j$3=0; j$3<num; j$3++) { 2993 + newCentroids[j$3] *= 1/clusterSizes[j$3]; 2994 + } 2995 + 2996 + // check convergence 2997 + repeat = false; 2998 + for (var j$4=0; j$4<num; j$4++) { 2999 + if (newCentroids[j$4] !== centroids[j$4]) { 3000 + repeat = true; 3001 + break; 3002 + } 3003 + } 3004 + 3005 + centroids = newCentroids; 3006 + nb_iters++; 3007 + 3008 + if (nb_iters > 200) { 3009 + repeat = false; 3010 + } 3011 + } 3012 + 3013 + // finished k-means clustering 3014 + // the next part is borrowed from gabrielflor.it 3015 + var kClusters = {}; 3016 + for (var j$5=0; j$5<num; j$5++) { 3017 + kClusters[j$5] = []; 3018 + } 3019 + for (var i$6=0; i$6<n; i$6++) { 3020 + cluster = assignments[i$6]; 3021 + kClusters[cluster].push(values[i$6]); 3022 + } 3023 + var tmpKMeansBreaks = []; 3024 + for (var j$6=0; j$6<num; j$6++) { 3025 + tmpKMeansBreaks.push(kClusters[j$6][0]); 3026 + tmpKMeansBreaks.push(kClusters[j$6][kClusters[j$6].length-1]); 3027 + } 3028 + tmpKMeansBreaks = tmpKMeansBreaks.sort(function (a,b){ return a-b; }); 3029 + limits.push(tmpKMeansBreaks[0]); 3030 + for (var i$7=1; i$7 < tmpKMeansBreaks.length; i$7+= 2) { 3031 + var v = tmpKMeansBreaks[i$7]; 3032 + if (!isNaN(v) && (limits.indexOf(v) === -1)) { 3033 + limits.push(v); 3034 + } 3035 + } 3036 + } 3037 + return limits; 3038 + }; 3039 + 3040 + var analyze_1 = {analyze: analyze, limits: limits}; 3041 + 3042 + var contrast = function (a, b) { 3043 + // WCAG contrast ratio 3044 + // see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef 3045 + a = new Color_1(a); 3046 + b = new Color_1(b); 3047 + var l1 = a.luminance(); 3048 + var l2 = b.luminance(); 3049 + return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05); 3050 + }; 3051 + 3052 + var sqrt$4 = Math.sqrt; 3053 + var atan2$2 = Math.atan2; 3054 + var abs$1 = Math.abs; 3055 + var cos$4 = Math.cos; 3056 + var PI$2 = Math.PI; 3057 + 3058 + var deltaE = function(a, b, L, C) { 3059 + if ( L === void 0 ) L=1; 3060 + if ( C === void 0 ) C=1; 3061 + 3062 + // Delta E (CMC) 3063 + // see http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CMC.html 3064 + a = new Color_1(a); 3065 + b = new Color_1(b); 3066 + var ref = Array.from(a.lab()); 3067 + var L1 = ref[0]; 3068 + var a1 = ref[1]; 3069 + var b1 = ref[2]; 3070 + var ref$1 = Array.from(b.lab()); 3071 + var L2 = ref$1[0]; 3072 + var a2 = ref$1[1]; 3073 + var b2 = ref$1[2]; 3074 + var c1 = sqrt$4((a1 * a1) + (b1 * b1)); 3075 + var c2 = sqrt$4((a2 * a2) + (b2 * b2)); 3076 + var sl = L1 < 16.0 ? 0.511 : (0.040975 * L1) / (1.0 + (0.01765 * L1)); 3077 + var sc = ((0.0638 * c1) / (1.0 + (0.0131 * c1))) + 0.638; 3078 + var h1 = c1 < 0.000001 ? 0.0 : (atan2$2(b1, a1) * 180.0) / PI$2; 3079 + while (h1 < 0) { h1 += 360; } 3080 + while (h1 >= 360) { h1 -= 360; } 3081 + var t = (h1 >= 164.0) && (h1 <= 345.0) ? (0.56 + abs$1(0.2 * cos$4((PI$2 * (h1 + 168.0)) / 180.0))) : (0.36 + abs$1(0.4 * cos$4((PI$2 * (h1 + 35.0)) / 180.0))); 3082 + var c4 = c1 * c1 * c1 * c1; 3083 + var f = sqrt$4(c4 / (c4 + 1900.0)); 3084 + var sh = sc * (((f * t) + 1.0) - f); 3085 + var delL = L1 - L2; 3086 + var delC = c1 - c2; 3087 + var delA = a1 - a2; 3088 + var delB = b1 - b2; 3089 + var dH2 = ((delA * delA) + (delB * delB)) - (delC * delC); 3090 + var v1 = delL / (L * sl); 3091 + var v2 = delC / (C * sc); 3092 + var v3 = sh; 3093 + return sqrt$4((v1 * v1) + (v2 * v2) + (dH2 / (v3 * v3))); 3094 + }; 3095 + 3096 + // simple Euclidean distance 3097 + var distance = function(a, b, mode) { 3098 + if ( mode === void 0 ) mode='lab'; 3099 + 3100 + // Delta E (CIE 1976) 3101 + // see http://www.brucelindbloom.com/index.html?Equations.html 3102 + a = new Color_1(a); 3103 + b = new Color_1(b); 3104 + var l1 = a.get(mode); 3105 + var l2 = b.get(mode); 3106 + var sum_sq = 0; 3107 + for (var i in l1) { 3108 + var d = (l1[i] || 0) - (l2[i] || 0); 3109 + sum_sq += d*d; 3110 + } 3111 + return Math.sqrt(sum_sq); 3112 + }; 3113 + 3114 + var valid = function () { 3115 + var args = [], len = arguments.length; 3116 + while ( len-- ) args[ len ] = arguments[ len ]; 3117 + 3118 + try { 3119 + new (Function.prototype.bind.apply( Color_1, [ null ].concat( args) )); 3120 + return true; 3121 + } catch (e) { 3122 + return false; 3123 + } 3124 + }; 3125 + 3126 + // some pre-defined color scales: 3127 + 3128 + 3129 + 3130 + 3131 + var scales = { 3132 + cool: function cool() { return scale([chroma_1.hsl(180,1,.9), chroma_1.hsl(250,.7,.4)]) }, 3133 + hot: function hot() { return scale(['#000','#f00','#ff0','#fff']).mode('rgb') } 3134 + }; 3135 + 3136 + /** 3137 + ColorBrewer colors for chroma.js 3138 + 3139 + Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The 3140 + Pennsylvania State University. 3141 + 3142 + Licensed under the Apache License, Version 2.0 (the "License"); 3143 + you may not use this file except in compliance with the License. 3144 + You may obtain a copy of the License at 3145 + http://www.apache.org/licenses/LICENSE-2.0 3146 + 3147 + Unless required by applicable law or agreed to in writing, software distributed 3148 + under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 3149 + CONDITIONS OF ANY KIND, either express or implied. See the License for the 3150 + specific language governing permissions and limitations under the License. 3151 + */ 3152 + 3153 + var colorbrewer = { 3154 + // sequential 3155 + OrRd: ['#fff7ec', '#fee8c8', '#fdd49e', '#fdbb84', '#fc8d59', '#ef6548', '#d7301f', '#b30000', '#7f0000'], 3156 + PuBu: ['#fff7fb', '#ece7f2', '#d0d1e6', '#a6bddb', '#74a9cf', '#3690c0', '#0570b0', '#045a8d', '#023858'], 3157 + BuPu: ['#f7fcfd', '#e0ecf4', '#bfd3e6', '#9ebcda', '#8c96c6', '#8c6bb1', '#88419d', '#810f7c', '#4d004b'], 3158 + Oranges: ['#fff5eb', '#fee6ce', '#fdd0a2', '#fdae6b', '#fd8d3c', '#f16913', '#d94801', '#a63603', '#7f2704'], 3159 + BuGn: ['#f7fcfd', '#e5f5f9', '#ccece6', '#99d8c9', '#66c2a4', '#41ae76', '#238b45', '#006d2c', '#00441b'], 3160 + YlOrBr: ['#ffffe5', '#fff7bc', '#fee391', '#fec44f', '#fe9929', '#ec7014', '#cc4c02', '#993404', '#662506'], 3161 + YlGn: ['#ffffe5', '#f7fcb9', '#d9f0a3', '#addd8e', '#78c679', '#41ab5d', '#238443', '#006837', '#004529'], 3162 + Reds: ['#fff5f0', '#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#a50f15', '#67000d'], 3163 + RdPu: ['#fff7f3', '#fde0dd', '#fcc5c0', '#fa9fb5', '#f768a1', '#dd3497', '#ae017e', '#7a0177', '#49006a'], 3164 + Greens: ['#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'], 3165 + YlGnBu: ['#ffffd9', '#edf8b1', '#c7e9b4', '#7fcdbb', '#41b6c4', '#1d91c0', '#225ea8', '#253494', '#081d58'], 3166 + Purples: ['#fcfbfd', '#efedf5', '#dadaeb', '#bcbddc', '#9e9ac8', '#807dba', '#6a51a3', '#54278f', '#3f007d'], 3167 + GnBu: ['#f7fcf0', '#e0f3db', '#ccebc5', '#a8ddb5', '#7bccc4', '#4eb3d3', '#2b8cbe', '#0868ac', '#084081'], 3168 + Greys: ['#ffffff', '#f0f0f0', '#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525', '#000000'], 3169 + YlOrRd: ['#ffffcc', '#ffeda0', '#fed976', '#feb24c', '#fd8d3c', '#fc4e2a', '#e31a1c', '#bd0026', '#800026'], 3170 + PuRd: ['#f7f4f9', '#e7e1ef', '#d4b9da', '#c994c7', '#df65b0', '#e7298a', '#ce1256', '#980043', '#67001f'], 3171 + Blues: ['#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'], 3172 + PuBuGn: ['#fff7fb', '#ece2f0', '#d0d1e6', '#a6bddb', '#67a9cf', '#3690c0', '#02818a', '#016c59', '#014636'], 3173 + Viridis: ['#440154', '#482777', '#3f4a8a', '#31678e', '#26838f', '#1f9d8a', '#6cce5a', '#b6de2b', '#fee825'], 3174 + 3175 + // diverging 3176 + 3177 + Spectral: ['#9e0142', '#d53e4f', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#e6f598', '#abdda4', '#66c2a5', '#3288bd', '#5e4fa2'], 3178 + RdYlGn: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850', '#006837'], 3179 + RdBu: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'], 3180 + PiYG: ['#8e0152', '#c51b7d', '#de77ae', '#f1b6da', '#fde0ef', '#f7f7f7', '#e6f5d0', '#b8e186', '#7fbc41', '#4d9221', '#276419'], 3181 + PRGn: ['#40004b', '#762a83', '#9970ab', '#c2a5cf', '#e7d4e8', '#f7f7f7', '#d9f0d3', '#a6dba0', '#5aae61', '#1b7837', '#00441b'], 3182 + RdYlBu: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8', '#abd9e9', '#74add1', '#4575b4', '#313695'], 3183 + BrBG: ['#543005', '#8c510a', '#bf812d', '#dfc27d', '#f6e8c3', '#f5f5f5', '#c7eae5', '#80cdc1', '#35978f', '#01665e', '#003c30'], 3184 + RdGy: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#ffffff', '#e0e0e0', '#bababa', '#878787', '#4d4d4d', '#1a1a1a'], 3185 + PuOr: ['#7f3b08', '#b35806', '#e08214', '#fdb863', '#fee0b6', '#f7f7f7', '#d8daeb', '#b2abd2', '#8073ac', '#542788', '#2d004b'], 3186 + 3187 + // qualitative 3188 + 3189 + Set2: ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494', '#b3b3b3'], 3190 + Accent: ['#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f', '#bf5b17', '#666666'], 3191 + Set1: ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'], 3192 + Set3: ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f'], 3193 + Dark2: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'], 3194 + Paired: ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'], 3195 + Pastel2: ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'], 3196 + Pastel1: ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec', '#f2f2f2'], 3197 + }; 3198 + 3199 + // add lowercase aliases for case-insensitive matches 3200 + for (var i$1 = 0, list$1 = Object.keys(colorbrewer); i$1 < list$1.length; i$1 += 1) { 3201 + var key = list$1[i$1]; 3202 + 3203 + colorbrewer[key.toLowerCase()] = colorbrewer[key]; 3204 + } 3205 + 3206 + var colorbrewer_1 = colorbrewer; 3207 + 3208 + // feel free to comment out anything to rollup 3209 + // a smaller chroma.js built 3210 + 3211 + // io --> convert colors 3212 + 3213 + 3214 + 3215 + 3216 + 3217 + 3218 + 3219 + 3220 + 3221 + 3222 + 3223 + 3224 + 3225 + 3226 + 3227 + // operators --> modify existing Colors 3228 + 3229 + 3230 + 3231 + 3232 + 3233 + 3234 + 3235 + 3236 + 3237 + 3238 + // interpolators 3239 + 3240 + 3241 + 3242 + 3243 + 3244 + 3245 + 3246 + 3247 + 3248 + 3249 + // generators -- > create new colors 3250 + chroma_1.average = average; 3251 + chroma_1.bezier = bezier_1; 3252 + chroma_1.blend = blend_1; 3253 + chroma_1.cubehelix = cubehelix; 3254 + chroma_1.mix = chroma_1.interpolate = mix; 3255 + chroma_1.random = random_1; 3256 + chroma_1.scale = scale; 3257 + 3258 + // other utility methods 3259 + chroma_1.analyze = analyze_1.analyze; 3260 + chroma_1.contrast = contrast; 3261 + chroma_1.deltaE = deltaE; 3262 + chroma_1.distance = distance; 3263 + chroma_1.limits = analyze_1.limits; 3264 + chroma_1.valid = valid; 3265 + 3266 + // scale 3267 + chroma_1.scales = scales; 3268 + 3269 + // colors 3270 + chroma_1.colors = w3cx11_1; 3271 + chroma_1.brewer = colorbrewer_1; 3272 + 3273 + var chroma_js = chroma_1; 3274 + 3275 + return chroma_js; 3276 + 3277 + }))); 3278 + }); 3279 + 3280 + function generateColorVariables(key, format, colorStr, opacity, altFormats = []) { 3281 + const parsedColor = chroma(colorStr); 3282 + const alts = altFormats.reduce((a, alt) => { 3283 + a.push(...generateColorVariables(alt.id, alt.format, colorStr, opacity)); 3284 + return a; 3285 + }, []); 3286 + switch (format) { 3287 + case "hex": 3288 + return [{ key, value: colorStr }, ...alts]; 3289 + case "hsl": 3290 + return [ 3291 + { 3292 + key, 3293 + value: parsedColor.css("hsl"), 3294 + }, 3295 + ...alts, 3296 + ]; 3297 + case "hsl-values": { 3298 + const hsl = parsedColor.hsl(); 3299 + const alpha = opacity ? `,${parsedColor.alpha()}` : ""; 3300 + const h = isNaN(hsl[0]) ? 0 : hsl[0]; 3301 + return [ 3302 + { 3303 + key, 3304 + value: `${h},${hsl[1] * 100}%,${hsl[2] * 100}%${alpha}`, 3305 + }, 3306 + ...alts, 3307 + ]; 3308 + } 3309 + case "hsl-split": { 3310 + const hsl = parsedColor.hsl(); 3311 + const h = isNaN(hsl[0]) ? 0 : hsl[0]; 3312 + const out = [ 3313 + { 3314 + key: `${key}-h`, 3315 + value: h.toString(), 3316 + }, 3317 + { 3318 + key: `${key}-s`, 3319 + value: (hsl[1] * 100).toString() + "%", 3320 + }, 3321 + { 3322 + key: `${key}-l`, 3323 + value: (hsl[2] * 100).toString() + "%", 3324 + }, 3325 + ...alts, 3326 + ]; 3327 + if (opacity) 3328 + out.push({ 3329 + key: `${key}-a`, 3330 + value: parsedColor.alpha().toString(), 3331 + }); 3332 + return out; 3333 + } 3334 + case "rgb": 3335 + return [ 3336 + { 3337 + key, 3338 + value: parsedColor.css(), 3339 + }, 3340 + ...alts, 3341 + ]; 3342 + case "rgb-values": { 3343 + const rgb = parsedColor.rgb(); 3344 + const alpha = opacity ? `,${parsedColor.alpha()}` : ""; 3345 + return [ 3346 + { 3347 + key, 3348 + value: `${rgb[0]},${rgb[1]},${rgb[2]}${alpha}`, 3349 + }, 3350 + ...alts, 3351 + ]; 3352 + } 3353 + case "rgb-split": { 3354 + const rgb = parsedColor.rgb(); 3355 + const out = [ 3356 + { 3357 + key: `${key}-r`, 3358 + value: rgb[0].toString(), 3359 + }, 3360 + { 3361 + key: `${key}-g`, 3362 + value: rgb[1].toString(), 3363 + }, 3364 + { 3365 + key: `${key}-b`, 3366 + value: rgb[2].toString(), 3367 + }, 3368 + ...alts, 3369 + ]; 3370 + if (opacity) 3371 + out.push({ 3372 + key: `${key}-a`, 3373 + value: parsedColor.alpha().toString(), 3374 + }); 3375 + return out; 3376 + } 3377 + } 3378 + } 3379 + function getCSSVariables(settings, config) { 3380 + const vars = []; 3381 + const themedLight = []; 3382 + const themedDark = []; 3383 + for (const key in settings) { 3384 + const [sectionId, settingId, modifier] = key.split("@@"); 3385 + const section = config[sectionId]; 3386 + if (!section) 3387 + continue; 3388 + const setting = config[sectionId][settingId]; 3389 + if (!setting) 3390 + continue; 3391 + const value = settings[key]; 3392 + switch (setting.type) { 3393 + case "variable-number": 3394 + case "variable-number-slider": 3395 + const format = setting 3396 + .format; 3397 + const val = value !== undefined 3398 + ? value 3399 + : setting.default; 3400 + vars.push({ 3401 + key: setting.id, 3402 + value: `${val}${format || ""}`, 3403 + }); 3404 + continue; 3405 + case "variable-text": 3406 + case "variable-select": 3407 + const format_text = setting; 3408 + let text = value !== undefined 3409 + ? value.toString() 3410 + : format_text.default.toString(); 3411 + if (format_text.quotes) { 3412 + if (text !== `""`) { 3413 + text = `'${text}'`; 3414 + } 3415 + else { 3416 + text = ``; 3417 + } 3418 + } 3419 + vars.push({ 3420 + key: setting.id, 3421 + value: text 3422 + }); 3423 + continue; 3424 + case "variable-color": { 3425 + const colorSetting = setting; 3426 + const color = value !== undefined ? value.toString() : colorSetting.default; 3427 + vars.push(...generateColorVariables(setting.id, colorSetting.format, color, colorSetting.opacity, colorSetting["alt-format"])); 3428 + continue; 3429 + } 3430 + case "variable-themed-color": { 3431 + const colorSetting = setting; 3432 + const color = value !== undefined 3433 + ? value.toString() 3434 + : colorSetting[modifier === "light" ? "default-light" : "default-dark"]; 3435 + (modifier === "light" ? themedLight : themedDark).push(...generateColorVariables(setting.id, colorSetting.format, color, colorSetting.opacity, colorSetting["alt-format"])); 3436 + } 3437 + } 3438 + } 3439 + return [vars, themedLight, themedDark]; 3440 + } 3441 + class CSSSettingsManager { 3442 + constructor(plugin) { 3443 + this.config = {}; 3444 + this.plugin = plugin; 3445 + this.settings = {}; 3446 + this.styleTag = document.createElement("style"); 3447 + this.styleTag.id = "css-settings-manager"; 3448 + document.getElementsByTagName("head")[0].appendChild(this.styleTag); 3449 + } 3450 + cleanup() { 3451 + this.styleTag.remove(); 3452 + this.removeClasses(); 3453 + } 3454 + save() { 3455 + return __awaiter(this, void 0, void 0, function* () { 3456 + yield this.plugin.saveData(this.settings); 3457 + this.setCSSVariables(); 3458 + }); 3459 + } 3460 + load() { 3461 + return __awaiter(this, void 0, void 0, function* () { 3462 + this.settings = Object.assign({}, yield this.plugin.loadData()); 3463 + }); 3464 + } 3465 + initClasses() { 3466 + Object.keys(this.config).forEach((section) => { 3467 + const config = this.config[section]; 3468 + Object.keys(config).forEach((settingId) => { 3469 + const setting = config[settingId]; 3470 + if (setting.type === "class-toggle") { 3471 + const classToggle = setting; 3472 + let value = this.getSetting(section, settingId); 3473 + if (value === true || 3474 + (value === undefined && classToggle.default === true)) { 3475 + document.body.classList.add(setting.id); 3476 + } 3477 + } 3478 + else if (setting.type === "class-select") { 3479 + const multiToggle = setting; 3480 + let value = this.getSetting(section, settingId); 3481 + if (value === undefined && !!multiToggle.default) { 3482 + value = multiToggle.default; 3483 + } 3484 + else if (value === undefined) { 3485 + value = "none"; 3486 + } 3487 + if (value !== "none") { 3488 + document.body.classList.add(value); 3489 + } 3490 + } 3491 + }); 3492 + }); 3493 + } 3494 + removeClasses() { 3495 + Object.keys(this.config).forEach((section) => { 3496 + const config = this.config[section]; 3497 + Object.keys(config).forEach((settingId) => { 3498 + const setting = config[settingId]; 3499 + if (setting.type === "class-toggle") { 3500 + if (this.getSetting(section, settingId)) { 3501 + document.body.classList.remove(setting.id); 3502 + } 3503 + } 3504 + }); 3505 + }); 3506 + } 3507 + setCSSVariables() { 3508 + const [vars, themedLight, themedDark] = getCSSVariables(this.settings, this.config); 3509 + this.styleTag.innerText = ` 3510 + body.css-settings-manager { 3511 + ${vars.reduce((combined, current) => { 3512 + return combined + `--${current.key}: ${current.value}; `; 3513 + }, "")} 3514 + } 3515 + 3516 + body.theme-light.css-settings-manager { 3517 + ${themedLight.reduce((combined, current) => { 3518 + return combined + `--${current.key}: ${current.value}; `; 3519 + }, "")} 3520 + } 3521 + 3522 + body.theme-dark.css-settings-manager { 3523 + ${themedDark.reduce((combined, current) => { 3524 + return combined + `--${current.key}: ${current.value}; `; 3525 + }, "")} 3526 + } 3527 + ` 3528 + .trim() 3529 + .replace(/[\r\n\s]+/g, " "); 3530 + } 3531 + setConfig(settings) { 3532 + this.config = {}; 3533 + settings.forEach((s) => { 3534 + this.config[s.id] = {}; 3535 + s.settings.forEach((setting) => { 3536 + this.config[s.id][setting.id] = setting; 3537 + }); 3538 + }); 3539 + let pruned = false; 3540 + for (const key in this.settings) { 3541 + const [sectionId, settingId] = key.split("@@"); 3542 + if (this.config[sectionId] && !this.config[sectionId][settingId]) { 3543 + delete this.settings[key]; 3544 + pruned = true; 3545 + } 3546 + } 3547 + if (pruned) { 3548 + this.save(); 3549 + } 3550 + else { 3551 + this.setCSSVariables(); 3552 + } 3553 + } 3554 + getSetting(sectionId, settingId) { 3555 + return this.settings[`${sectionId}@@${settingId}`]; 3556 + } 3557 + getSettings(sectionId, ids) { 3558 + return ids.reduce((settings, id) => { 3559 + const fullId = `${sectionId}@@${id}`; 3560 + const alts = ["dark", "light"]; 3561 + if (this.settings[fullId]) { 3562 + settings[fullId] = this.settings[fullId]; 3563 + } 3564 + alts.forEach((alt) => { 3565 + const id = `${fullId}@@${alt}`; 3566 + if (this.settings[id]) { 3567 + settings[id] = this.settings[id]; 3568 + } 3569 + }); 3570 + return settings; 3571 + }, {}); 3572 + } 3573 + setSetting(sectionId, settingId, value) { 3574 + this.settings[`${sectionId}@@${settingId}`] = value; 3575 + this.save(); 3576 + } 3577 + setSettings(settings) { 3578 + Object.keys(settings).forEach((id) => { 3579 + this.settings[id] = settings[id]; 3580 + }); 3581 + return this.save(); 3582 + } 3583 + clearSetting(sectionId, settingId) { 3584 + delete this.settings[`${sectionId}@@${settingId}`]; 3585 + this.save(); 3586 + } 3587 + clearSection(sectionId) { 3588 + Object.keys(this.settings).forEach((key) => { 3589 + const [section] = key.split("@@"); 3590 + if (section === sectionId) { 3591 + delete this.settings[key]; 3592 + } 3593 + }); 3594 + this.save(); 3595 + } 3596 + export(section, config) { 3597 + new ExportModal(this.plugin.app, this.plugin, section, config).open(); 3598 + } 3599 + import() { 3600 + new ImportModal(this.plugin.app, this.plugin).open(); 3601 + } 3602 + } 3603 + class ExportModal extends obsidian.Modal { 3604 + constructor(app, plugin, section, config) { 3605 + super(app); 3606 + this.plugin = plugin; 3607 + this.config = config; 3608 + this.section = section; 3609 + } 3610 + onOpen() { 3611 + let { contentEl, modalEl } = this; 3612 + modalEl.addClass("modal-style-settings"); 3613 + new obsidian.Setting(contentEl) 3614 + .setName(`Export settings for: ${this.section}`) 3615 + .then((setting) => { 3616 + const output = JSON.stringify(this.config, null, 2); 3617 + // Build a copy to clipboard link 3618 + setting.controlEl.createEl("a", { 3619 + cls: "style-settings-copy", 3620 + text: "Copy to clipboard", 3621 + href: "#", 3622 + }, (copyButton) => { 3623 + new obsidian.TextAreaComponent(contentEl) 3624 + .setValue(output) 3625 + .then((textarea) => { 3626 + copyButton.addEventListener("click", (e) => { 3627 + e.preventDefault(); 3628 + // Select the textarea contents and copy them to the clipboard 3629 + textarea.inputEl.select(); 3630 + textarea.inputEl.setSelectionRange(0, 99999); 3631 + document.execCommand("copy"); 3632 + copyButton.addClass("success"); 3633 + setTimeout(() => { 3634 + // If the button is still in the dom, remove the success class 3635 + if (copyButton.parentNode) { 3636 + copyButton.removeClass("success"); 3637 + } 3638 + }, 2000); 3639 + }); 3640 + }); 3641 + }); 3642 + // Build a download link 3643 + setting.controlEl.createEl("a", { 3644 + cls: "style-settings-download", 3645 + text: "Download", 3646 + attr: { 3647 + download: "style-settings.json", 3648 + href: `data:application/json;charset=utf-8,${encodeURIComponent(output)}`, 3649 + }, 3650 + }); 3651 + }); 3652 + } 3653 + onClose() { 3654 + let { contentEl } = this; 3655 + contentEl.empty(); 3656 + } 3657 + } 3658 + class ImportModal extends obsidian.Modal { 3659 + constructor(app, plugin) { 3660 + super(app); 3661 + this.plugin = plugin; 3662 + } 3663 + onOpen() { 3664 + let { contentEl, modalEl } = this; 3665 + modalEl.addClass("modal-style-settings"); 3666 + new obsidian.Setting(contentEl) 3667 + .setName("Import style setting") 3668 + .setDesc("Import an entire or partial configuration. Warning: this may override existing settings"); 3669 + new obsidian.Setting(contentEl).then((setting) => { 3670 + // Build an error message container 3671 + const errorSpan = createSpan({ 3672 + cls: "style-settings-import-error", 3673 + text: "Error importing config", 3674 + }); 3675 + setting.nameEl.appendChild(errorSpan); 3676 + // Attempt to parse the imported data and close if successful 3677 + const importAndClose = (str) => __awaiter(this, void 0, void 0, function* () { 3678 + if (str) { 3679 + try { 3680 + const importedSettings = JSON.parse(str); 3681 + yield this.plugin.settingsManager.setSettings(importedSettings); 3682 + this.plugin.settingsTab.display(); 3683 + this.close(); 3684 + } 3685 + catch (e) { 3686 + errorSpan.addClass("active"); 3687 + errorSpan.setText(`Error importing style settings: ${e}`); 3688 + } 3689 + } 3690 + else { 3691 + errorSpan.addClass("active"); 3692 + errorSpan.setText(`Error importing style settings: config is empty`); 3693 + } 3694 + }); 3695 + // Build a file input 3696 + setting.controlEl.createEl("input", { 3697 + cls: "style-settings-import-input", 3698 + attr: { 3699 + id: "style-settings-import-input", 3700 + name: "style-settings-import-input", 3701 + type: "file", 3702 + accept: ".json", 3703 + }, 3704 + }, (importInput) => { 3705 + // Set up a FileReader so we can parse the file contents 3706 + importInput.addEventListener("change", (e) => { 3707 + const reader = new FileReader(); 3708 + reader.onload = (e) => __awaiter(this, void 0, void 0, function* () { 3709 + yield importAndClose(e.target.result.toString().trim()); 3710 + }); 3711 + reader.readAsText(e.target.files[0]); 3712 + }); 3713 + }); 3714 + // Build a label we will style as a link 3715 + setting.controlEl.createEl("label", { 3716 + cls: "style-settings-import-label", 3717 + text: "Import from file", 3718 + attr: { 3719 + for: "style-settings-import-input", 3720 + }, 3721 + }); 3722 + new obsidian.TextAreaComponent(contentEl) 3723 + .setPlaceholder("Paste config here...") 3724 + .then((ta) => { 3725 + new obsidian.ButtonComponent(contentEl) 3726 + .setButtonText("Save") 3727 + .onClick(() => __awaiter(this, void 0, void 0, function* () { 3728 + yield importAndClose(ta.getValue().trim()); 3729 + })); 3730 + }); 3731 + }); 3732 + } 3733 + onClose() { 3734 + let { contentEl } = this; 3735 + contentEl.empty(); 3736 + } 3737 + } 3738 + 3739 + var pickr_min = createCommonjsModule(function (module, exports) { 3740 + /*! Pickr 1.8.4 MIT | https://github.com/Simonwep/pickr */ 3741 + !function(t,e){module.exports=e();}(self,(function(){return (()=>{var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]});},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0});}},e={};t.d(e,{default:()=>x});var o={};function n(t,e,o,n){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(o)||(o=[o]);for(const s of e)for(const e of o)s[t](e,n,{capture:!1,...i});return Array.prototype.slice.call(arguments,1)}t.r(o),t.d(o,{adjustableInputNumbers:()=>p,createElementFromString:()=>r,createFromTemplate:()=>a,eventPath:()=>l,off:()=>s,on:()=>i,resolveElement:()=>c});const i=n.bind(null,"addEventListener"),s=n.bind(null,"removeEventListener");function r(t){const e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild}function a(t){const e=(t,e)=>{const o=t.getAttribute(e);return t.removeAttribute(e),o},o=function(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e(t,":obj"),s=e(t,":ref"),r=i?n[i]={}:n;s&&(n[s]=t);for(const n of Array.from(t.children)){const t=e(n,":arr"),i=o(n,t?{}:r);t&&(r[t]||(r[t]=[])).push(Object.keys(i).length?i:n);}return n};return o(r(t))}function l(t){let e=t.path||t.composedPath&&t.composedPath();if(e)return e;let o=t.target.parentElement;for(e=[t.target,o];o=o.parentElement;)e.push(o);return e.push(document,window),e}function c(t){return t instanceof Element?t:"string"==typeof t?t.split(/>>/g).reduce(((t,e,o,n)=>(t=t.querySelector(e),o<n.length-1?t.shadowRoot:t)),document):null}function p(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t=>t;function o(o){const n=[.001,.01,.1][Number(o.shiftKey||2*o.ctrlKey)]*(o.deltaY<0?1:-1);let i=0,s=t.selectionStart;t.value=t.value.replace(/[\d.]+/g,((t,o)=>o<=s&&o+t.length>=s?(s=o,e(Number(t),n,i)):(i++,t))),t.focus(),t.setSelectionRange(s,s),o.preventDefault(),t.dispatchEvent(new Event("input"));}i(t,"focus",(()=>i(window,"wheel",o,{passive:!1}))),i(t,"blur",(()=>s(window,"wheel",o)));}const{min:h,max:u,floor:d,round:v}=Math;function m(t,e,o){e/=100,o/=100;const n=d(t=t/360*6),i=t-n,s=o*(1-e),r=o*(1-i*e),a=o*(1-(1-i)*e),l=n%6;return [255*[o,r,s,s,a,o][l],255*[a,o,o,r,s,s][l],255*[s,s,a,o,o,r][l]]}function f(t,e,o){return m(t,e,o).map((t=>v(t).toString(16).padStart(2,"0")))}function g(t,e,o){const n=m(t,e,o),i=n[0]/255,s=n[1]/255,r=n[2]/255,a=h(1-i,1-s,1-r);return [100*(1===a?0:(1-i-a)/(1-a)),100*(1===a?0:(1-s-a)/(1-a)),100*(1===a?0:(1-r-a)/(1-a)),100*a]}function b(t,e,o){const n=(2-(e/=100))*(o/=100)/2;return 0!==n&&(e=1===n?0:n<.5?e*o/(2*n):e*o/(2-2*n)),[t,100*e,100*n]}function y(t,e,o){const n=h(t/=255,e/=255,o/=255),i=u(t,e,o),s=i-n;let r,a;if(0===s)r=a=0;else {a=s/i;const n=((i-t)/6+s/2)/s,l=((i-e)/6+s/2)/s,c=((i-o)/6+s/2)/s;t===i?r=c-l:e===i?r=1/3+n-c:o===i&&(r=2/3+l-n),r<0?r+=1:r>1&&(r-=1);}return [360*r,100*a,100*i]}function _(t,e,o,n){e/=100,o/=100;return [...y(255*(1-h(1,(t/=100)*(1-(n/=100))+n)),255*(1-h(1,e*(1-n)+n)),255*(1-h(1,o*(1-n)+n)))]}function w(t,e,o){e/=100;const n=2*(e*=(o/=100)<.5?o:1-o)/(o+e)*100,i=100*(o+e);return [t,isNaN(n)?0:n,i]}function A(t){return y(...t.match(/.{2}/g).map((t=>parseInt(t,16))))}function C(t){t=t.match(/^[a-zA-Z]+$/)?function(t){if("black"===t.toLowerCase())return "#000";const e=document.createElement("canvas").getContext("2d");return e.fillStyle=t,"#000"===e.fillStyle?null:e.fillStyle}(t):t;const e={cmyk:/^cmyk[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)/i,rgba:/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i,hsla:/^((hsla)|hsl)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i,hsva:/^((hsva)|hsv)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i,hexa:/^#?(([\dA-Fa-f]{3,4})|([\dA-Fa-f]{6})|([\dA-Fa-f]{8}))$/i},o=t=>t.map((t=>/^(|\d+)\.\d+|\d+$/.test(t)?Number(t):void 0));let n;t:for(const i in e){if(!(n=e[i].exec(t)))continue;const s=t=>!!n[2]==("number"==typeof t);switch(i){case"cmyk":{const[,t,e,s,r]=o(n);if(t>100||e>100||s>100||r>100)break t;return {values:_(t,e,s,r),type:i}}case"rgba":{const[,,,t,e,r,a]=o(n);if(t>255||e>255||r>255||a<0||a>1||!s(a))break t;return {values:[...y(t,e,r),a],a,type:i}}case"hexa":{let[,t]=n;4!==t.length&&3!==t.length||(t=t.split("").map((t=>t+t)).join(""));const e=t.substring(0,6);let o=t.substring(6);return o=o?parseInt(o,16)/255:void 0,{values:[...A(e),o],a:o,type:i}}case"hsla":{const[,,,t,e,r,a]=o(n);if(t>360||e>100||r>100||a<0||a>1||!s(a))break t;return {values:[...w(t,e,r),a],a,type:i}}case"hsva":{const[,,,t,e,r,a]=o(n);if(t>360||e>100||r>100||a<0||a>1||!s(a))break t;return {values:[t,e,r,a],a,type:i}}}}return {values:null,type:null}}function $(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;const i=(t,e)=>function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1;return e(~o?t.map((t=>Number(t.toFixed(o)))):t)},s={h:t,s:e,v:o,a:n,toHSVA(){const t=[s.h,s.s,s.v,s.a];return t.toString=i(t,(t=>`hsva(${t[0]}, ${t[1]}%, ${t[2]}%, ${s.a})`)),t},toHSLA(){const t=[...b(s.h,s.s,s.v),s.a];return t.toString=i(t,(t=>`hsla(${t[0]}, ${t[1]}%, ${t[2]}%, ${s.a})`)),t},toRGBA(){const t=[...m(s.h,s.s,s.v),s.a];return t.toString=i(t,(t=>`rgba(${t[0]}, ${t[1]}, ${t[2]}, ${s.a})`)),t},toCMYK(){const t=g(s.h,s.s,s.v);return t.toString=i(t,(t=>`cmyk(${t[0]}%, ${t[1]}%, ${t[2]}%, ${t[3]}%)`)),t},toHEXA(){const t=f(s.h,s.s,s.v),e=s.a>=1?"":Number((255*s.a).toFixed(0)).toString(16).toUpperCase().padStart(2,"0");return e&&t.push(e),t.toString=()=>`#${t.join("").toUpperCase()}`,t},clone:()=>$(s.h,s.s,s.v,s.a)};return s}const k=t=>Math.max(Math.min(t,1),0);function S(t){const e={options:Object.assign({lock:null,onchange:()=>0,onstop:()=>0},t),_keyboard(t){const{options:o}=e,{type:n,key:i}=t;if(document.activeElement===o.wrapper){const{lock:o}=e.options,s="ArrowUp"===i,r="ArrowRight"===i,a="ArrowDown"===i,l="ArrowLeft"===i;if("keydown"===n&&(s||r||a||l)){let n=0,i=0;"v"===o?n=s||r?1:-1:"h"===o?n=s||r?-1:1:(i=s?-1:a?1:0,n=l?-1:r?1:0),e.update(k(e.cache.x+.01*n),k(e.cache.y+.01*i)),t.preventDefault();}else i.startsWith("Arrow")&&(e.options.onstop(),t.preventDefault());}},_tapstart(t){i(document,["mouseup","touchend","touchcancel"],e._tapstop),i(document,["mousemove","touchmove"],e._tapmove),t.cancelable&&t.preventDefault(),e._tapmove(t);},_tapmove(t){const{options:o,cache:n}=e,{lock:i,element:s,wrapper:r}=o,a=r.getBoundingClientRect();let l=0,c=0;if(t){const e=t&&t.touches&&t.touches[0];l=t?(e||t).clientX:0,c=t?(e||t).clientY:0,l<a.left?l=a.left:l>a.left+a.width&&(l=a.left+a.width),c<a.top?c=a.top:c>a.top+a.height&&(c=a.top+a.height),l-=a.left,c-=a.top;}else n&&(l=n.x*a.width,c=n.y*a.height);"h"!==i&&(s.style.left=`calc(${l/a.width*100}% - ${s.offsetWidth/2}px)`),"v"!==i&&(s.style.top=`calc(${c/a.height*100}% - ${s.offsetHeight/2}px)`),e.cache={x:l/a.width,y:c/a.height};const p=k(l/a.width),h=k(c/a.height);switch(i){case"v":return o.onchange(p);case"h":return o.onchange(h);default:return o.onchange(p,h)}},_tapstop(){e.options.onstop(),s(document,["mouseup","touchend","touchcancel"],e._tapstop),s(document,["mousemove","touchmove"],e._tapmove);},trigger(){e._tapmove();},update(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;const{left:n,top:i,width:s,height:r}=e.options.wrapper.getBoundingClientRect();"h"===e.options.lock&&(o=t),e._tapmove({clientX:n+s*t,clientY:i+r*o});},destroy(){const{options:t,_tapstart:o,_keyboard:n}=e;s(document,["keydown","keyup"],n),s([t.wrapper,t.element],"mousedown",o),s([t.wrapper,t.element],"touchstart",o,{passive:!1});}},{options:o,_tapstart:n,_keyboard:r}=e;return i([o.wrapper,o.element],"mousedown",n),i([o.wrapper,o.element],"touchstart",n,{passive:!1}),i(document,["keydown","keyup"],r),e}function O(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t=Object.assign({onchange:()=>0,className:"",elements:[]},t);const e=i(t.elements,"click",(e=>{t.elements.forEach((o=>o.classList[e.target===o?"add":"remove"](t.className))),t.onchange(e),e.stopPropagation();}));return {destroy:()=>s(...e)}}const E={variantFlipOrder:{start:"sme",middle:"mse",end:"ems"},positionFlipOrder:{top:"tbrl",right:"rltb",bottom:"btrl",left:"lrbt"},position:"bottom",margin:8},L=(t,e,o)=>{const{container:n,margin:i,position:s,variantFlipOrder:r,positionFlipOrder:a}={container:document.documentElement.getBoundingClientRect(),...E,...o},{left:l,top:c}=e.style;e.style.left="0",e.style.top="0";const p=t.getBoundingClientRect(),h=e.getBoundingClientRect(),u={t:p.top-h.height-i,b:p.bottom+i,r:p.right+i,l:p.left-h.width-i},d={vs:p.left,vm:p.left+p.width/2+-h.width/2,ve:p.left+p.width-h.width,hs:p.top,hm:p.bottom-p.height/2-h.height/2,he:p.bottom-h.height},[v,m="middle"]=s.split("-"),f=a[v],g=r[m],{top:b,left:y,bottom:_,right:w}=n;for(const t of f){const o="t"===t||"b"===t,n=u[t],[i,s]=o?["top","left"]:["left","top"],[r,a]=o?[h.height,h.width]:[h.width,h.height],[l,c]=o?[_,w]:[w,_],[p,v]=o?[b,y]:[y,b];if(!(n<p||n+r>l))for(const r of g){const l=d[(o?"v":"h")+r];if(!(l<v||l+a>c))return e.style[s]=l-h[s]+"px",e.style[i]=n-h[i]+"px",t+r}}return e.style.left=l,e.style.top=c,null};function P(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}class x{constructor(t){P(this,"_initializingActive",!0),P(this,"_recalc",!0),P(this,"_nanopop",null),P(this,"_root",null),P(this,"_color",$()),P(this,"_lastColor",$()),P(this,"_swatchColors",[]),P(this,"_setupAnimationFrame",null),P(this,"_eventListener",{init:[],save:[],hide:[],show:[],clear:[],change:[],changestop:[],cancel:[],swatchselect:[]}),this.options=t=Object.assign({...x.DEFAULT_OPTIONS},t);const{swatches:e,components:o,theme:n,sliders:i,lockOpacity:s,padding:r}=t;["nano","monolith"].includes(n)&&!i&&(t.sliders="h"),o.interaction||(o.interaction={});const{preview:a,opacity:l,hue:c,palette:p}=o;o.opacity=!s&&l,o.palette=p||a||l||c,this._preBuild(),this._buildComponents(),this._bindEvents(),this._finalBuild(),e&&e.length&&e.forEach((t=>this.addSwatch(t)));const{button:h,app:u}=this._root;this._nanopop=((t,e,o)=>{const n="object"!=typeof t||t instanceof HTMLElement?{reference:t,popper:e,...o}:t;return {update(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n;const{reference:e,popper:o}=Object.assign(n,t);if(!o||!e)throw new Error("Popper- or reference-element missing.");return L(e,o,n)}}})(h,u,{margin:r}),h.setAttribute("role","button"),h.setAttribute("aria-label",this._t("btn:toggle"));const d=this;this._setupAnimationFrame=requestAnimationFrame((function e(){if(!u.offsetWidth)return d._setupAnimationFrame=requestAnimationFrame(e);d.setColor(t.default),d._rePositioningPicker(),t.defaultRepresentation&&(d._representation=t.defaultRepresentation,d.setColorRepresentation(d._representation)),t.showAlways&&d.show(),d._initializingActive=!1,d._emit("init");}));}_preBuild(){const{options:t}=this;for(const e of ["el","container"])t[e]=c(t[e]);this._root=(t=>{const{components:e,useAsButton:o,inline:n,appClass:i,theme:s,lockOpacity:r}=t.options,l=t=>t?"":'style="display:none" hidden',c=e=>t._t(e),p=a(`\n <div :ref="root" class="pickr">\n\n ${o?"":'<button type="button" :ref="button" class="pcr-button"></button>'}\n\n <div :ref="app" class="pcr-app ${i||""}" data-theme="${s}" ${n?'style="position: unset"':""} aria-label="${c("ui:dialog")}" role="window">\n <div class="pcr-selection" ${l(e.palette)}>\n <div :obj="preview" class="pcr-color-preview" ${l(e.preview)}>\n <button type="button" :ref="lastColor" class="pcr-last-color" aria-label="${c("btn:last-color")}"></button>\n <div :ref="currentColor" class="pcr-current-color"></div>\n </div>\n\n <div :obj="palette" class="pcr-color-palette">\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="palette" class="pcr-palette" tabindex="0" aria-label="${c("aria:palette")}" role="listbox"></div>\n </div>\n\n <div :obj="hue" class="pcr-color-chooser" ${l(e.hue)}>\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="slider" class="pcr-hue pcr-slider" tabindex="0" aria-label="${c("aria:hue")}" role="slider"></div>\n </div>\n\n <div :obj="opacity" class="pcr-color-opacity" ${l(e.opacity)}>\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="slider" class="pcr-opacity pcr-slider" tabindex="0" aria-label="${c("aria:opacity")}" role="slider"></div>\n </div>\n </div>\n\n <div class="pcr-swatches ${e.palette?"":"pcr-last"}" :ref="swatches"></div>\n\n <div :obj="interaction" class="pcr-interaction" ${l(Object.keys(e.interaction).length)}>\n <input :ref="result" class="pcr-result" type="text" spellcheck="false" ${l(e.interaction.input)} aria-label="${c("aria:input")}">\n\n <input :arr="options" class="pcr-type" data-type="HEXA" value="${r?"HEX":"HEXA"}" type="button" ${l(e.interaction.hex)}>\n <input :arr="options" class="pcr-type" data-type="RGBA" value="${r?"RGB":"RGBA"}" type="button" ${l(e.interaction.rgba)}>\n <input :arr="options" class="pcr-type" data-type="HSLA" value="${r?"HSL":"HSLA"}" type="button" ${l(e.interaction.hsla)}>\n <input :arr="options" class="pcr-type" data-type="HSVA" value="${r?"HSV":"HSVA"}" type="button" ${l(e.interaction.hsva)}>\n <input :arr="options" class="pcr-type" data-type="CMYK" value="CMYK" type="button" ${l(e.interaction.cmyk)}>\n\n <input :ref="save" class="pcr-save" value="${c("btn:save")}" type="button" ${l(e.interaction.save)} aria-label="${c("aria:btn:save")}">\n <input :ref="cancel" class="pcr-cancel" value="${c("btn:cancel")}" type="button" ${l(e.interaction.cancel)} aria-label="${c("aria:btn:cancel")}">\n <input :ref="clear" class="pcr-clear" value="${c("btn:clear")}" type="button" ${l(e.interaction.clear)} aria-label="${c("aria:btn:clear")}">\n </div>\n </div>\n </div>\n `),h=p.interaction;return h.options.find((t=>!t.hidden&&!t.classList.add("active"))),h.type=()=>h.options.find((t=>t.classList.contains("active"))),p})(this),t.useAsButton&&(this._root.button=t.el),t.container.appendChild(this._root.root);}_finalBuild(){const t=this.options,e=this._root;if(t.container.removeChild(e.root),t.inline){const o=t.el.parentElement;t.el.nextSibling?o.insertBefore(e.app,t.el.nextSibling):o.appendChild(e.app);}else t.container.appendChild(e.app);t.useAsButton?t.inline&&t.el.remove():t.el.parentNode.replaceChild(e.root,t.el),t.disabled&&this.disable(),t.comparison||(e.button.style.transition="none",t.useAsButton||(e.preview.lastColor.style.transition="none")),this.hide();}_buildComponents(){const t=this,e=this.options.components,o=(t.options.sliders||"v").repeat(2),[n,i]=o.match(/^[vh]+$/g)?o:[],s=()=>this._color||(this._color=this._lastColor.clone()),r={palette:S({element:t._root.palette.picker,wrapper:t._root.palette.palette,onstop:()=>t._emit("changestop","slider",t),onchange(o,n){if(!e.palette)return;const i=s(),{_root:r,options:a}=t,{lastColor:l,currentColor:c}=r.preview;t._recalc&&(i.s=100*o,i.v=100-100*n,i.v<0&&(i.v=0),t._updateOutput("slider"));const p=i.toRGBA().toString(0);this.element.style.background=p,this.wrapper.style.background=`\n linear-gradient(to top, rgba(0, 0, 0, ${i.a}), transparent),\n linear-gradient(to left, hsla(${i.h}, 100%, 50%, ${i.a}), rgba(255, 255, 255, ${i.a}))\n `,a.comparison?a.useAsButton||t._lastColor||l.style.setProperty("--pcr-color",p):(r.button.style.setProperty("--pcr-color",p),r.button.classList.remove("clear"));const h=i.toHEXA().toString();for(const{el:e,color:o}of t._swatchColors)e.classList[h===o.toHEXA().toString()?"add":"remove"]("pcr-active");c.style.setProperty("--pcr-color",p);}}),hue:S({lock:"v"===i?"h":"v",element:t._root.hue.picker,wrapper:t._root.hue.slider,onstop:()=>t._emit("changestop","slider",t),onchange(o){if(!e.hue||!e.palette)return;const n=s();t._recalc&&(n.h=360*o),this.element.style.backgroundColor=`hsl(${n.h}, 100%, 50%)`,r.palette.trigger();}}),opacity:S({lock:"v"===n?"h":"v",element:t._root.opacity.picker,wrapper:t._root.opacity.slider,onstop:()=>t._emit("changestop","slider",t),onchange(o){if(!e.opacity||!e.palette)return;const n=s();t._recalc&&(n.a=Math.round(100*o)/100),this.element.style.background=`rgba(0, 0, 0, ${n.a})`,r.palette.trigger();}}),selectable:O({elements:t._root.interaction.options,className:"active",onchange(e){t._representation=e.target.getAttribute("data-type").toUpperCase(),t._recalc&&t._updateOutput("swatch");}})};this._components=r;}_bindEvents(){const{_root:t,options:e}=this,o=[i(t.interaction.clear,"click",(()=>this._clearColor())),i([t.interaction.cancel,t.preview.lastColor],"click",(()=>{this.setHSVA(...(this._lastColor||this._color).toHSVA(),!0),this._emit("cancel");})),i(t.interaction.save,"click",(()=>{!this.applyColor()&&!e.showAlways&&this.hide();})),i(t.interaction.result,["keyup","input"],(t=>{this.setColor(t.target.value,!0)&&!this._initializingActive&&(this._emit("change",this._color,"input",this),this._emit("changestop","input",this)),t.stopImmediatePropagation();})),i(t.interaction.result,["focus","blur"],(t=>{this._recalc="blur"===t.type,this._recalc&&this._updateOutput(null);})),i([t.palette.palette,t.palette.picker,t.hue.slider,t.hue.picker,t.opacity.slider,t.opacity.picker],["mousedown","touchstart"],(()=>this._recalc=!0),{passive:!0})];if(!e.showAlways){const n=e.closeWithKey;o.push(i(t.button,"click",(()=>this.isOpen()?this.hide():this.show())),i(document,"keyup",(t=>this.isOpen()&&(t.key===n||t.code===n)&&this.hide())),i(document,["touchstart","mousedown"],(e=>{this.isOpen()&&!l(e).some((e=>e===t.app||e===t.button))&&this.hide();}),{capture:!0}));}if(e.adjustableNumbers){const e={rgba:[255,255,255,1],hsva:[360,100,100,1],hsla:[360,100,100,1],cmyk:[100,100,100,100]};p(t.interaction.result,((t,o,n)=>{const i=e[this.getColorRepresentation().toLowerCase()];if(i){const e=i[n],s=t+(e>=100?1e3*o:o);return s<=0?0:Number((s<e?s:e).toPrecision(3))}return t}));}if(e.autoReposition&&!e.inline){let t=null;const n=this;o.push(i(window,["scroll","resize"],(()=>{n.isOpen()&&(e.closeOnScroll&&n.hide(),null===t?(t=setTimeout((()=>t=null),100),requestAnimationFrame((function e(){n._rePositioningPicker(),null!==t&&requestAnimationFrame(e);}))):(clearTimeout(t),t=setTimeout((()=>t=null),100)));}),{capture:!0}));}this._eventBindings=o;}_rePositioningPicker(){const{options:t}=this;if(!t.inline){if(!this._nanopop.update({container:document.body.getBoundingClientRect(),position:t.position})){const t=this._root.app,e=t.getBoundingClientRect();t.style.top=(window.innerHeight-e.height)/2+"px",t.style.left=(window.innerWidth-e.width)/2+"px";}}}_updateOutput(t){const{_root:e,_color:o,options:n}=this;if(e.interaction.type()){const t=`to${e.interaction.type().getAttribute("data-type")}`;e.interaction.result.value="function"==typeof o[t]?o[t]().toString(n.outputPrecision):"";}!this._initializingActive&&this._recalc&&this._emit("change",o,t,this);}_clearColor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const{_root:e,options:o}=this;o.useAsButton||e.button.style.setProperty("--pcr-color","rgba(0, 0, 0, 0.15)"),e.button.classList.add("clear"),o.showAlways||this.hide(),this._lastColor=null,this._initializingActive||t||(this._emit("save",null),this._emit("clear"));}_parseLocalColor(t){const{values:e,type:o,a:n}=C(t),{lockOpacity:i}=this.options,s=void 0!==n&&1!==n;return e&&3===e.length&&(e[3]=void 0),{values:!e||i&&s?null:e,type:o}}_t(t){return this.options.i18n[t]||x.I18N_DEFAULTS[t]}_emit(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),n=1;n<e;n++)o[n-1]=arguments[n];this._eventListener[t].forEach((t=>t(...o,this)));}on(t,e){return this._eventListener[t].push(e),this}off(t,e){const o=this._eventListener[t]||[],n=o.indexOf(e);return ~n&&o.splice(n,1),this}addSwatch(t){const{values:e}=this._parseLocalColor(t);if(e){const{_swatchColors:t,_root:o}=this,n=$(...e),s=r(`<button type="button" style="--pcr-color: ${n.toRGBA().toString(0)}" aria-label="${this._t("btn:swatch")}"/>`);return o.swatches.appendChild(s),t.push({el:s,color:n}),this._eventBindings.push(i(s,"click",(()=>{this.setHSVA(...n.toHSVA(),!0),this._emit("swatchselect",n),this._emit("change",n,"swatch",this);}))),!0}return !1}removeSwatch(t){const e=this._swatchColors[t];if(e){const{el:o}=e;return this._root.swatches.removeChild(o),this._swatchColors.splice(t,1),!0}return !1}applyColor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const{preview:e,button:o}=this._root,n=this._color.toRGBA().toString(0);return e.lastColor.style.setProperty("--pcr-color",n),this.options.useAsButton||o.style.setProperty("--pcr-color",n),o.classList.remove("clear"),this._lastColor=this._color.clone(),this._initializingActive||t||this._emit("save",this._color),this}destroy(){cancelAnimationFrame(this._setupAnimationFrame),this._eventBindings.forEach((t=>s(...t))),Object.keys(this._components).forEach((t=>this._components[t].destroy()));}destroyAndRemove(){this.destroy();const{root:t,app:e}=this._root;t.parentElement&&t.parentElement.removeChild(t),e.parentElement.removeChild(e),Object.keys(this).forEach((t=>this[t]=null));}hide(){return !!this.isOpen()&&(this._root.app.classList.remove("visible"),this._emit("hide"),!0)}show(){return !this.options.disabled&&!this.isOpen()&&(this._root.app.classList.add("visible"),this._rePositioningPicker(),this._emit("show",this._color),this)}isOpen(){return this._root.app.classList.contains("visible")}setHSVA(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:360,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];const s=this._recalc;if(this._recalc=!1,t<0||t>360||e<0||e>100||o<0||o>100||n<0||n>1)return !1;this._color=$(t,e,o,n);const{hue:r,opacity:a,palette:l}=this._components;return r.update(t/360),a.update(n),l.update(e/100,1-o/100),i||this.applyColor(),s&&this._updateOutput(),this._recalc=s,!0}setColor(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(null===t)return this._clearColor(e),!0;const{values:o,type:n}=this._parseLocalColor(t);if(o){const t=n.toUpperCase(),{options:i}=this._root.interaction,s=i.find((e=>e.getAttribute("data-type")===t));if(s&&!s.hidden)for(const t of i)t.classList[t===s?"add":"remove"]("active");return !!this.setHSVA(...o,e)&&this.setColorRepresentation(t)}return !1}setColorRepresentation(t){return t=t.toUpperCase(),!!this._root.interaction.options.find((e=>e.getAttribute("data-type").startsWith(t)&&!e.click()))}getColorRepresentation(){return this._representation}getColor(){return this._color}getSelectedColor(){return this._lastColor}getRoot(){return this._root}disable(){return this.hide(),this.options.disabled=!0,this._root.button.classList.add("disabled"),this}enable(){return this.options.disabled=!1,this._root.button.classList.remove("disabled"),this}}return P(x,"utils",o),P(x,"version","1.8.4"),P(x,"I18N_DEFAULTS",{"ui:dialog":"color picker dialog","btn:toggle":"toggle color picker dialog","btn:swatch":"color swatch","btn:last-color":"use previous color","btn:save":"Save","btn:cancel":"Cancel","btn:clear":"Clear","aria:btn:save":"save and close","aria:btn:cancel":"cancel and close","aria:btn:clear":"clear and close","aria:input":"color input field","aria:palette":"color selection area","aria:hue":"hue selection slider","aria:opacity":"selection slider"}),P(x,"DEFAULT_OPTIONS",{appClass:null,theme:"classic",useAsButton:!1,padding:8,disabled:!1,comparison:!0,closeOnScroll:!1,outputPrecision:0,lockOpacity:!1,autoReposition:!0,container:"body",components:{interaction:{}},i18n:{},swatches:null,inline:!1,sliders:null,default:"#42445a",defaultRepresentation:null,position:"bottom-middle",adjustableNumbers:!0,showAlways:!1,closeWithKey:"Escape"}),P(x,"create",(t=>new x(t))),e=e.default})()})); 3742 + 3743 + }); 3744 + 3745 + var Pickr = /*@__PURE__*/getDefaultExportFromCjs(pickr_min); 3746 + 3747 + const ar = {}; 3748 + 3749 + const cz = {}; 3750 + 3751 + const da = {}; 3752 + 3753 + const de = { 3754 + "Default:": "Standard:", 3755 + "Error:": "Fehler:", 3756 + "missing default light value, or value is not in a valid color format": "Fehlender heller standard Wert oder Wert ist in keinem validen Farb-Format", 3757 + "missing default dark value, or value is not in a valid color format": "Fehlender dunkler standard Wert oder Wert ist in keinem validen Farb-Format", 3758 + "missing default value, or value is not in a valid color format": "Fehlender standard Wert oder Wert ist in keinem validen Farb-Format", 3759 + "missing default value": "Fehlender standard Wert", 3760 + }; 3761 + 3762 + const en = { 3763 + "Default:": "Default:", 3764 + "Error:": "Error:", 3765 + "missing default light value, or value is not in a valid color format": "missing default light value, or value is not in a valid color format", 3766 + "missing default dark value, or value is not in a valid color format": "missing default dark value, or value is not in a valid color format", 3767 + "missing default value, or value is not in a valid color format": "missing default value, or value is not in a valid color format", 3768 + "missing default value": "missing default value", 3769 + }; 3770 + 3771 + const es = {}; 3772 + 3773 + const fr = {}; 3774 + 3775 + const hi = {}; 3776 + 3777 + const id = {}; 3778 + 3779 + const it = {}; 3780 + 3781 + const ja = {}; 3782 + 3783 + const ko = {}; 3784 + 3785 + const nl = { 3786 + "Default:": "Standaard:", 3787 + "Error:": "Error:", 3788 + "missing default light value, or value is not in a valid color format": "Geen standaard waarde voor het lichte thema, of de waarde is niet in het goede formaat", 3789 + "missing default dark value, or value is not in a valid color format": "Geen standaard waarde voor het donkere thema, of de waarde is niet in het goede formaat", 3790 + "missing default value, or value is not in a valid color format": "Geen standaard waarde, of de waarde is niet in het goede formaat", 3791 + "missing default value": "Geen standaard waarde", 3792 + }; 3793 + 3794 + const no = {}; 3795 + 3796 + const pl = {}; 3797 + 3798 + const pt = {}; 3799 + 3800 + const ptBr = {}; 3801 + 3802 + const ro = {}; 3803 + 3804 + const ru = {}; 3805 + 3806 + const sq = {}; 3807 + 3808 + const tr = {}; 3809 + 3810 + const uk = {}; 3811 + 3812 + const zh = {}; 3813 + 3814 + const zhTw = {}; 3815 + 3816 + const lang = window.localStorage.getItem("language"); 3817 + const localeMap = { 3818 + ar, 3819 + cz, 3820 + da, 3821 + de, 3822 + en, 3823 + es, 3824 + fr, 3825 + hi, 3826 + id, 3827 + it, 3828 + ja, 3829 + ko, 3830 + nl, 3831 + no, 3832 + pl, 3833 + "pt-BR": ptBr, 3834 + pt, 3835 + ro, 3836 + ru, 3837 + sq, 3838 + tr, 3839 + uk, 3840 + "zh-TW": zhTw, 3841 + zh, 3842 + }; 3843 + const locale = localeMap[lang || "en"]; 3844 + function t(str) { 3845 + if (!locale) { 3846 + console.error("Error: Style Settings locale not found", lang); 3847 + } 3848 + return (locale && locale[str]) || en[str]; 3849 + } 3850 + 3851 + const resetTooltip = "Restore default"; 3852 + function sanitizeText(str) { 3853 + if (str === "") { 3854 + return `""`; 3855 + } 3856 + return str.replace(/[;<>]/g, ""); 3857 + } 3858 + function createDescription(description, def, defLabel) { 3859 + const fragment = createFragment(); 3860 + if (description) { 3861 + fragment.appendChild(document.createTextNode(description)); 3862 + } 3863 + if (def) { 3864 + const small = createEl("small"); 3865 + small.appendChild(createEl("strong", { text: `${t("Default:")} ` })); 3866 + small.appendChild(document.createTextNode(defLabel || def)); 3867 + const div = createEl("div"); 3868 + div.appendChild(small); 3869 + fragment.appendChild(div); 3870 + } 3871 + return fragment; 3872 + } 3873 + function getTitle(config) { 3874 + if (lang) { 3875 + return config[`title.${lang}`] || config.title; 3876 + } 3877 + return config.title; 3878 + } 3879 + function getDescription(config) { 3880 + if (lang) { 3881 + return (config[`description.${lang}`] || 3882 + config.description); 3883 + } 3884 + return config.description; 3885 + } 3886 + function createHeading(opts) { 3887 + new obsidian.Setting(opts.containerEl) 3888 + .setHeading() 3889 + .setClass("style-settings-heading") 3890 + .setName(getTitle(opts.config)) 3891 + .setDesc(getDescription(opts.config) ? getDescription(opts.config) : "") 3892 + .then((setting) => { 3893 + if (opts.config.collapsed) 3894 + setting.settingEl.addClass("is-collapsed"); 3895 + setting.settingEl.dataset.level = opts.config.level.toString(); 3896 + setting.settingEl.dataset.id = opts.config.id; 3897 + const iconContainer = createSpan({ 3898 + cls: "style-settings-collapse-indicator", 3899 + }); 3900 + obsidian.setIcon(iconContainer, "right-triangle"); 3901 + setting.nameEl.prepend(iconContainer); 3902 + setting.settingEl.addEventListener("click", (e) => { 3903 + setting.settingEl.toggleClass("is-collapsed", !setting.settingEl.hasClass("is-collapsed")); 3904 + }); 3905 + if (opts.config.resetFn) { 3906 + setting.addExtraButton((b) => { 3907 + b.setIcon("reset") 3908 + .setTooltip("Reset all settings to default") 3909 + .onClick(opts.config.resetFn); 3910 + }); 3911 + } 3912 + setting.addExtraButton((b) => { 3913 + b.setIcon("install") 3914 + .setTooltip("Export settings") 3915 + .then((b) => { 3916 + b.extraSettingsEl.onClickEvent((e) => { 3917 + e.stopPropagation(); 3918 + const title = opts.sectionName === getTitle(opts.config) 3919 + ? getTitle(opts.config) 3920 + : `${opts.sectionName} > ${getTitle(opts.config)}`; 3921 + opts.settingsManager.export(title, opts.settingsManager.getSettings(opts.sectionId, opts.children)); 3922 + }); 3923 + }); 3924 + }); 3925 + }); 3926 + } 3927 + function createClassToggle(opts) { 3928 + const { sectionId, config, containerEl, settingsManager } = opts; 3929 + let toggleComponent; 3930 + new obsidian.Setting(containerEl) 3931 + .setName(getTitle(config)) 3932 + .setDesc(getDescription(config) || "") 3933 + .addToggle((toggle) => { 3934 + const value = settingsManager.getSetting(sectionId, config.id); 3935 + toggle 3936 + .setValue(value !== undefined ? !!value : !!config.default) 3937 + .onChange((value) => { 3938 + settingsManager.setSetting(sectionId, config.id, value); 3939 + if (value) { 3940 + document.body.classList.add(config.id); 3941 + } 3942 + else { 3943 + document.body.classList.remove(config.id); 3944 + } 3945 + }); 3946 + toggleComponent = toggle; 3947 + }) 3948 + .addExtraButton((b) => { 3949 + b.setIcon("reset"); 3950 + b.onClick(() => { 3951 + const value = !!config.default; 3952 + toggleComponent.setValue(value); 3953 + if (value) { 3954 + document.body.classList.add(config.id); 3955 + } 3956 + else { 3957 + document.body.classList.remove(config.id); 3958 + } 3959 + settingsManager.clearSetting(sectionId, config.id); 3960 + }); 3961 + b.setTooltip(resetTooltip); 3962 + }) 3963 + .then((setting) => { 3964 + setting.settingEl.dataset.id = opts.config.id; 3965 + }); 3966 + } 3967 + function createClassMultiToggle(opts) { 3968 + const { sectionId, config, containerEl, settingsManager } = opts; 3969 + let dropdownComponent; 3970 + if (typeof config.default !== "string") { 3971 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value")}`); 3972 + } 3973 + let prevValue = settingsManager.getSetting(sectionId, config.id); 3974 + if (prevValue === undefined && !!config.default) { 3975 + prevValue = config.default; 3976 + } 3977 + else if (prevValue === undefined) { 3978 + prevValue = "none"; 3979 + } 3980 + const defaultOption = config.default 3981 + ? config.options.find((o) => { 3982 + if (typeof o === "string") { 3983 + return o === config.default; 3984 + } 3985 + return o.value === config.default; 3986 + }) 3987 + : undefined; 3988 + let defaultLabel = undefined; 3989 + if (defaultOption && typeof defaultOption === "string") { 3990 + defaultLabel = defaultOption; 3991 + } 3992 + else if (defaultOption && typeof defaultOption === "object") { 3993 + defaultLabel = defaultOption.label; 3994 + } 3995 + new obsidian.Setting(containerEl) 3996 + .setName(getTitle(config)) 3997 + .setDesc(createDescription(getDescription(config), config.default, defaultLabel)) 3998 + .addDropdown((dropdown) => { 3999 + if (config.allowEmpty) { 4000 + dropdown.addOption("none", ""); 4001 + } 4002 + config.options.forEach((o) => { 4003 + if (typeof o === "string") { 4004 + dropdown.addOption(o, o); 4005 + } 4006 + else { 4007 + dropdown.addOption(o.value, o.label); 4008 + } 4009 + }); 4010 + dropdown.setValue(prevValue).onChange((value) => { 4011 + settingsManager.setSetting(sectionId, config.id, value); 4012 + if (value !== "none") { 4013 + document.body.classList.add(value); 4014 + } 4015 + if (prevValue) { 4016 + document.body.classList.remove(prevValue); 4017 + } 4018 + prevValue = value; 4019 + }); 4020 + dropdownComponent = dropdown; 4021 + }) 4022 + .addExtraButton((b) => { 4023 + b.setIcon("reset"); 4024 + b.onClick(() => { 4025 + const value = config.default || "none"; 4026 + dropdownComponent.setValue(config.default || "none"); 4027 + if (value !== "none") { 4028 + document.body.classList.add(value); 4029 + } 4030 + if (prevValue) { 4031 + document.body.classList.remove(prevValue); 4032 + } 4033 + settingsManager.clearSetting(sectionId, config.id); 4034 + }); 4035 + b.setTooltip(resetTooltip); 4036 + }) 4037 + .then((setting) => { 4038 + setting.settingEl.dataset.id = opts.config.id; 4039 + }); 4040 + } 4041 + function createVariableText(opts) { 4042 + const { sectionId, config, containerEl, settingsManager } = opts; 4043 + let textComponent; 4044 + if (typeof config.default !== "string") { 4045 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value")}`); 4046 + } 4047 + new obsidian.Setting(containerEl) 4048 + .setName(getTitle(config)) 4049 + .setDesc(createDescription(getDescription(config), config.default)) 4050 + .addText((text) => { 4051 + let value = settingsManager.getSetting(sectionId, config.id); 4052 + const onChange = obsidian.debounce((value) => { 4053 + settingsManager.setSetting(sectionId, config.id, sanitizeText(value)); 4054 + }, 250, true); 4055 + if (config.quotes && value === `""`) { 4056 + value = ``; 4057 + } 4058 + text 4059 + .setValue(value ? value.toString() : config.default) 4060 + .onChange(onChange); 4061 + textComponent = text; 4062 + }) 4063 + .addExtraButton((b) => { 4064 + b.setIcon("reset"); 4065 + b.onClick(() => { 4066 + textComponent.setValue(config.default); 4067 + settingsManager.clearSetting(sectionId, config.id); 4068 + }); 4069 + b.setTooltip(resetTooltip); 4070 + }) 4071 + .then((setting) => { 4072 + setting.settingEl.dataset.id = opts.config.id; 4073 + }); 4074 + } 4075 + function createVariableNumber(opts) { 4076 + const { sectionId, config, containerEl, settingsManager } = opts; 4077 + let textComponent; 4078 + if (typeof config.default !== "number") { 4079 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value")}`); 4080 + } 4081 + new obsidian.Setting(containerEl) 4082 + .setName(getTitle(config)) 4083 + .setDesc(createDescription(getDescription(config), config.default.toString(10))) 4084 + .addText((text) => { 4085 + const value = settingsManager.getSetting(sectionId, config.id); 4086 + const onChange = obsidian.debounce((value) => { 4087 + const isFloat = /\./.test(value); 4088 + settingsManager.setSetting(sectionId, config.id, isFloat ? parseFloat(value) : parseInt(value, 10)); 4089 + }, 250, true); 4090 + text 4091 + .setValue(value !== undefined ? value.toString() : config.default.toString()) 4092 + .onChange(onChange); 4093 + textComponent = text; 4094 + }) 4095 + .addExtraButton((b) => { 4096 + b.setIcon("reset"); 4097 + b.onClick(() => { 4098 + textComponent.setValue(config.default.toString()); 4099 + settingsManager.clearSetting(sectionId, config.id); 4100 + }); 4101 + b.setTooltip(resetTooltip); 4102 + }) 4103 + .then((setting) => { 4104 + setting.settingEl.dataset.id = opts.config.id; 4105 + }); 4106 + } 4107 + function createVariableNumberSlider(opts) { 4108 + const { sectionId, config, containerEl, settingsManager } = opts; 4109 + let sliderComponent; 4110 + if (typeof config.default !== "number") { 4111 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value")}`); 4112 + } 4113 + new obsidian.Setting(containerEl) 4114 + .setName(getTitle(config)) 4115 + .setDesc(createDescription(getDescription(config), config.default.toString(10))) 4116 + .addSlider((slider) => { 4117 + const value = settingsManager.getSetting(sectionId, config.id); 4118 + const onChange = obsidian.debounce((value) => { 4119 + settingsManager.setSetting(sectionId, config.id, value); 4120 + }, 250, true); 4121 + slider 4122 + .setDynamicTooltip() 4123 + .setLimits(config.min, config.max, config.step) 4124 + .setValue(value !== undefined ? value : config.default) 4125 + .onChange(onChange); 4126 + sliderComponent = slider; 4127 + }) 4128 + .addExtraButton((b) => { 4129 + b.setIcon("reset"); 4130 + b.onClick(() => { 4131 + sliderComponent.setValue(config.default); 4132 + settingsManager.clearSetting(sectionId, config.id); 4133 + }); 4134 + b.setTooltip(resetTooltip); 4135 + }) 4136 + .then((setting) => { 4137 + setting.settingEl.dataset.id = opts.config.id; 4138 + }); 4139 + } 4140 + function createVariableSelect(opts) { 4141 + const { sectionId, config, containerEl, settingsManager } = opts; 4142 + let dropdownComponent; 4143 + if (typeof config.default !== "string") { 4144 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value")}`); 4145 + } 4146 + const defaultOption = config.default 4147 + ? config.options.find((o) => { 4148 + if (typeof o === "string") { 4149 + return o === config.default; 4150 + } 4151 + return o.value === config.default; 4152 + }) 4153 + : undefined; 4154 + let defaultLabel = undefined; 4155 + if (defaultOption && typeof defaultOption === "string") { 4156 + defaultLabel = defaultOption; 4157 + } 4158 + else if (defaultOption && typeof defaultOption === "object") { 4159 + defaultLabel = defaultOption.label; 4160 + } 4161 + new obsidian.Setting(containerEl) 4162 + .setName(getTitle(config)) 4163 + .setDesc(createDescription(getDescription(config), config.default, defaultLabel)) 4164 + .addDropdown((dropdown) => { 4165 + const value = settingsManager.getSetting(sectionId, config.id); 4166 + config.options.forEach((o) => { 4167 + if (typeof o === "string") { 4168 + dropdown.addOption(o, o); 4169 + } 4170 + else { 4171 + dropdown.addOption(o.value, o.label); 4172 + } 4173 + }); 4174 + dropdown 4175 + .setValue(value !== undefined ? value : config.default) 4176 + .onChange((value) => { 4177 + settingsManager.setSetting(sectionId, config.id, value); 4178 + }); 4179 + dropdownComponent = dropdown; 4180 + }) 4181 + .addExtraButton((b) => { 4182 + b.setIcon("reset"); 4183 + b.onClick(() => { 4184 + dropdownComponent.setValue(config.default); 4185 + settingsManager.clearSetting(sectionId, config.id); 4186 + }); 4187 + b.setTooltip(resetTooltip); 4188 + }) 4189 + .then((setting) => { 4190 + setting.settingEl.dataset.id = opts.config.id; 4191 + }); 4192 + } 4193 + function getPickrSettings(opts) { 4194 + const { el, isView, containerEl, swatches, opacity, defaultColor } = opts; 4195 + return { 4196 + el, 4197 + container: isView ? document.body : containerEl, 4198 + theme: "nano", 4199 + swatches, 4200 + lockOpacity: !opacity, 4201 + default: defaultColor, 4202 + position: "left-middle", 4203 + components: { 4204 + preview: true, 4205 + hue: true, 4206 + opacity: !!opacity, 4207 + interaction: { 4208 + hex: true, 4209 + rgba: true, 4210 + hsla: true, 4211 + input: true, 4212 + cancel: true, 4213 + save: true, 4214 + }, 4215 + }, 4216 + }; 4217 + } 4218 + function onPickrCancel(instance) { 4219 + instance.hide(); 4220 + } 4221 + function isValidDefaultColor(color) { 4222 + return /^(#|rgb|hsl)/.test(color); 4223 + } 4224 + function createVariableColor(opts) { 4225 + const { isView, sectionId, config, containerEl, settingsManager } = opts; 4226 + if (typeof config.default !== "string" || 4227 + !isValidDefaultColor(config.default)) { 4228 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default value, or value is not in a valid color format")}`); 4229 + } 4230 + const value = settingsManager.getSetting(sectionId, config.id); 4231 + const swatches = []; 4232 + let pickr; 4233 + if (config.default) { 4234 + swatches.push(config.default); 4235 + } 4236 + if (value !== undefined) { 4237 + swatches.push(value); 4238 + } 4239 + new obsidian.Setting(containerEl) 4240 + .setName(getTitle(config)) 4241 + .setDesc(createDescription(getDescription(config), config.default)) 4242 + .then((setting) => { 4243 + setting.settingEl.dataset.id = opts.config.id; 4244 + pickr = Pickr.create(getPickrSettings({ 4245 + isView, 4246 + el: setting.controlEl.createDiv({ cls: "picker" }), 4247 + containerEl, 4248 + swatches, 4249 + opacity: config.opacity, 4250 + defaultColor: value !== undefined ? value : config.default, 4251 + })) 4252 + .on("save", (color, instance) => { 4253 + if (!color) 4254 + return; 4255 + settingsManager.setSetting(sectionId, config.id, color.toHEXA().toString()); 4256 + instance.hide(); 4257 + instance.addSwatch(color.toHEXA().toString()); 4258 + }) 4259 + .on("show", () => { 4260 + const { result } = pickr.getRoot().interaction; 4261 + requestAnimationFrame(() => requestAnimationFrame(() => result.select())); 4262 + }) 4263 + .on("cancel", onPickrCancel); 4264 + }) 4265 + .addExtraButton((b) => { 4266 + b.setIcon("reset") 4267 + .onClick(() => { 4268 + pickr.setColor(config.default); 4269 + settingsManager.clearSetting(sectionId, config.id); 4270 + }) 4271 + .setTooltip(resetTooltip); 4272 + }); 4273 + return () => pickr.destroyAndRemove(); 4274 + } 4275 + function createVariableThemedColor(opts) { 4276 + const { sectionId, isView, config, containerEl, settingsManager } = opts; 4277 + if (typeof config["default-light"] !== "string" || 4278 + !isValidDefaultColor(config["default-light"])) { 4279 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default light value, or value is not in a valid color format")}`); 4280 + } 4281 + if (typeof config["default-dark"] !== "string" || 4282 + !isValidDefaultColor(config["default-dark"])) { 4283 + return console.error(`${t("Error:")} ${getTitle(config)} ${t("missing default dark value, or value is not in a valid color format")}`); 4284 + } 4285 + const idLight = `${config.id}@@light`; 4286 + const idDark = `${config.id}@@dark`; 4287 + const valueLight = settingsManager.getSetting(sectionId, idLight); 4288 + const valueDark = settingsManager.getSetting(sectionId, idDark); 4289 + const swatchesLight = []; 4290 + const swatchesDark = []; 4291 + let pickrLight; 4292 + let pickrDark; 4293 + if (config["default-light"]) { 4294 + swatchesLight.push(config["default-light"]); 4295 + } 4296 + if (valueLight !== undefined) { 4297 + swatchesLight.push(valueLight); 4298 + } 4299 + if (config["default-dark"]) { 4300 + swatchesDark.push(config["default-dark"]); 4301 + } 4302 + if (valueDark !== undefined) { 4303 + swatchesDark.push(valueDark); 4304 + } 4305 + const onSave = (id) => (color, instance) => { 4306 + if (!color) 4307 + return; 4308 + settingsManager.setSetting(sectionId, id, color.toHEXA().toString()); 4309 + instance.hide(); 4310 + instance.addSwatch(color.toHEXA().toString()); 4311 + }; 4312 + new obsidian.Setting(containerEl) 4313 + .setName(getTitle(config)) 4314 + .then((setting) => { 4315 + setting.settingEl.dataset.id = opts.config.id; 4316 + // Construct description 4317 + setting.descEl.createSpan({}, (span) => { 4318 + if (getDescription(config)) { 4319 + span.appendChild(document.createTextNode(getDescription(config))); 4320 + } 4321 + }); 4322 + setting.descEl.createDiv({}, (div) => { 4323 + div.createEl("small", {}, (sm) => { 4324 + sm.appendChild(createEl("strong", { text: "Default (light): " })); 4325 + sm.appendChild(document.createTextNode(config["default-light"])); 4326 + }); 4327 + div.createEl("br"); 4328 + div.createEl("small", {}, (sm) => { 4329 + sm.appendChild(createEl("strong", { text: "Default (dark): " })); 4330 + sm.appendChild(document.createTextNode(config["default-dark"])); 4331 + }); 4332 + }); 4333 + }) 4334 + .then((setting) => { 4335 + setting.controlEl.createDiv({ cls: "themed-color-wrapper" }, (wrapper) => { 4336 + // Create light color picker 4337 + wrapper.createDiv({ cls: "theme-light" }, (themeWrapper) => { 4338 + pickrLight = Pickr.create(getPickrSettings({ 4339 + isView, 4340 + el: themeWrapper.createDiv({ cls: "picker" }), 4341 + containerEl, 4342 + swatches: swatchesLight, 4343 + opacity: config.opacity, 4344 + defaultColor: valueLight !== undefined 4345 + ? valueLight 4346 + : config["default-light"], 4347 + })) 4348 + .on("show", () => { 4349 + const { result } = pickrLight.getRoot().interaction; 4350 + requestAnimationFrame(() => requestAnimationFrame(() => result.select())); 4351 + }) 4352 + .on("save", onSave(idLight)) 4353 + .on("cancel", onPickrCancel); 4354 + new obsidian.ButtonComponent(themeWrapper.createDiv({ cls: "pickr-reset" })) 4355 + .setIcon("reset") 4356 + .onClick(() => { 4357 + pickrLight.setColor(config["default-light"]); 4358 + settingsManager.clearSetting(sectionId, idLight); 4359 + }) 4360 + .setTooltip(resetTooltip); 4361 + }); 4362 + // Create dark color picker 4363 + wrapper.createDiv({ cls: "theme-dark" }, (themeWrapper) => { 4364 + pickrDark = Pickr.create(getPickrSettings({ 4365 + isView, 4366 + el: themeWrapper.createDiv({ cls: "picker" }), 4367 + containerEl, 4368 + swatches: swatchesDark, 4369 + opacity: config.opacity, 4370 + defaultColor: valueDark !== undefined 4371 + ? valueDark 4372 + : config["default-dark"], 4373 + })) 4374 + .on("show", () => { 4375 + const { result } = pickrDark.getRoot().interaction; 4376 + requestAnimationFrame(() => requestAnimationFrame(() => result.select())); 4377 + }) 4378 + .on("save", onSave(idDark)) 4379 + .on("cancel", onPickrCancel); 4380 + new obsidian.ButtonComponent(themeWrapper.createDiv({ cls: "pickr-reset" })) 4381 + .setIcon("reset") 4382 + .onClick(() => { 4383 + pickrDark.setColor(config["default-dark"]); 4384 + settingsManager.clearSetting(sectionId, idDark); 4385 + }) 4386 + .setTooltip(resetTooltip); 4387 + }); 4388 + }); 4389 + }); 4390 + return () => { 4391 + pickrLight.destroyAndRemove(); 4392 + pickrDark.destroyAndRemove(); 4393 + }; 4394 + } 4395 + function createSettings(opts) { 4396 + const { isView, containerEl, sectionId, settings, settingsManager, sectionName, } = opts; 4397 + const containerStack = [containerEl]; 4398 + const idStack = [sectionId]; 4399 + const cleanup = []; 4400 + const settingGroups = { 4401 + [sectionId]: [], 4402 + }; 4403 + let containerLevel = 0; 4404 + function getTargetContainer(stack) { 4405 + if (!stack.length) 4406 + return containerEl; 4407 + return stack[stack.length - 1]; 4408 + } 4409 + function pushId(id) { 4410 + idStack.forEach((containerId) => { 4411 + if (settingGroups[containerId]) { 4412 + settingGroups[containerId].push(id); 4413 + } 4414 + else { 4415 + settingGroups[containerId] = [id]; 4416 + } 4417 + }); 4418 + } 4419 + settings.forEach((setting) => { 4420 + switch (setting.type) { 4421 + case "heading": { 4422 + const config = setting; 4423 + settingGroups[config.id] = []; 4424 + let targetContainer = getTargetContainer(containerStack); 4425 + if (config.level > containerLevel) { 4426 + // Nest one level 4427 + createHeading({ 4428 + config, 4429 + containerEl: targetContainer, 4430 + children: settingGroups[config.id], 4431 + settingsManager, 4432 + sectionName, 4433 + sectionId, 4434 + }); 4435 + } 4436 + else if (config.level === containerLevel) { 4437 + // Same level 4438 + containerStack.pop(); 4439 + idStack.pop(); 4440 + targetContainer = getTargetContainer(containerStack); 4441 + createHeading({ 4442 + config, 4443 + containerEl: targetContainer, 4444 + children: settingGroups[config.id], 4445 + settingsManager, 4446 + sectionName, 4447 + sectionId, 4448 + }); 4449 + } 4450 + else { 4451 + // Step up to the appropriate level 4452 + while (containerStack.length > 1 && 4453 + parseInt(containerStack[containerStack.length - 1].dataset.level) >= 4454 + config.level) { 4455 + containerStack.pop(); 4456 + idStack.pop(); 4457 + } 4458 + targetContainer = getTargetContainer(containerStack); 4459 + createHeading({ 4460 + config, 4461 + containerEl: targetContainer, 4462 + children: settingGroups[config.id], 4463 + settingsManager, 4464 + sectionName, 4465 + sectionId, 4466 + }); 4467 + } 4468 + targetContainer.createDiv({ cls: "style-settings-container" }, (container) => { 4469 + container.dataset.level = config.level.toString(); 4470 + containerStack.push(container); 4471 + idStack.push(config.id); 4472 + }); 4473 + containerLevel = config.level; 4474 + break; 4475 + } 4476 + case "class-toggle": { 4477 + pushId(setting.id); 4478 + createClassToggle({ 4479 + sectionId, 4480 + config: setting, 4481 + containerEl: getTargetContainer(containerStack), 4482 + settingsManager, 4483 + }); 4484 + break; 4485 + } 4486 + case "class-select": { 4487 + pushId(setting.id); 4488 + createClassMultiToggle({ 4489 + sectionId, 4490 + config: setting, 4491 + containerEl: getTargetContainer(containerStack), 4492 + settingsManager, 4493 + }); 4494 + break; 4495 + } 4496 + case "variable-text": { 4497 + pushId(setting.id); 4498 + createVariableText({ 4499 + sectionId, 4500 + config: setting, 4501 + containerEl: getTargetContainer(containerStack), 4502 + settingsManager, 4503 + }); 4504 + break; 4505 + } 4506 + case "variable-number": { 4507 + pushId(setting.id); 4508 + createVariableNumber({ 4509 + sectionId, 4510 + config: setting, 4511 + containerEl: getTargetContainer(containerStack), 4512 + settingsManager, 4513 + }); 4514 + break; 4515 + } 4516 + case "variable-number-slider": { 4517 + pushId(setting.id); 4518 + createVariableNumberSlider({ 4519 + sectionId, 4520 + config: setting, 4521 + containerEl: getTargetContainer(containerStack), 4522 + settingsManager, 4523 + }); 4524 + break; 4525 + } 4526 + case "variable-select": { 4527 + pushId(setting.id); 4528 + createVariableSelect({ 4529 + sectionId, 4530 + config: setting, 4531 + containerEl: getTargetContainer(containerStack), 4532 + settingsManager, 4533 + }); 4534 + break; 4535 + } 4536 + case "variable-color": { 4537 + pushId(setting.id); 4538 + cleanup.push(createVariableColor({ 4539 + sectionId, 4540 + config: setting, 4541 + containerEl: getTargetContainer(containerStack), 4542 + settingsManager, 4543 + isView, 4544 + })); 4545 + break; 4546 + } 4547 + case "variable-themed-color": { 4548 + // TODO: multiple ids? 4549 + pushId(setting.id); 4550 + cleanup.push(createVariableThemedColor({ 4551 + sectionId, 4552 + config: setting, 4553 + containerEl: getTargetContainer(containerStack), 4554 + settingsManager, 4555 + isView, 4556 + })); 4557 + break; 4558 + } 4559 + } 4560 + }); 4561 + return cleanup; 4562 + } 4563 + 4564 + /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ 4565 + function isNothing(subject) { 4566 + return (typeof subject === 'undefined') || (subject === null); 4567 + } 4568 + 4569 + 4570 + function isObject(subject) { 4571 + return (typeof subject === 'object') && (subject !== null); 4572 + } 4573 + 4574 + 4575 + function toArray(sequence) { 4576 + if (Array.isArray(sequence)) return sequence; 4577 + else if (isNothing(sequence)) return []; 4578 + 4579 + return [ sequence ]; 4580 + } 4581 + 4582 + 4583 + function extend(target, source) { 4584 + var index, length, key, sourceKeys; 4585 + 4586 + if (source) { 4587 + sourceKeys = Object.keys(source); 4588 + 4589 + for (index = 0, length = sourceKeys.length; index < length; index += 1) { 4590 + key = sourceKeys[index]; 4591 + target[key] = source[key]; 4592 + } 4593 + } 4594 + 4595 + return target; 4596 + } 4597 + 4598 + 4599 + function repeat(string, count) { 4600 + var result = '', cycle; 4601 + 4602 + for (cycle = 0; cycle < count; cycle += 1) { 4603 + result += string; 4604 + } 4605 + 4606 + return result; 4607 + } 4608 + 4609 + 4610 + function isNegativeZero(number) { 4611 + return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number); 4612 + } 4613 + 4614 + 4615 + var isNothing_1 = isNothing; 4616 + var isObject_1 = isObject; 4617 + var toArray_1 = toArray; 4618 + var repeat_1 = repeat; 4619 + var isNegativeZero_1 = isNegativeZero; 4620 + var extend_1 = extend; 4621 + 4622 + var common = { 4623 + isNothing: isNothing_1, 4624 + isObject: isObject_1, 4625 + toArray: toArray_1, 4626 + repeat: repeat_1, 4627 + isNegativeZero: isNegativeZero_1, 4628 + extend: extend_1 4629 + }; 4630 + 4631 + // YAML error class. http://stackoverflow.com/questions/8458984 4632 + 4633 + 4634 + function formatError(exception, compact) { 4635 + var where = '', message = exception.reason || '(unknown reason)'; 4636 + 4637 + if (!exception.mark) return message; 4638 + 4639 + if (exception.mark.name) { 4640 + where += 'in "' + exception.mark.name + '" '; 4641 + } 4642 + 4643 + where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')'; 4644 + 4645 + if (!compact && exception.mark.snippet) { 4646 + where += '\n\n' + exception.mark.snippet; 4647 + } 4648 + 4649 + return message + ' ' + where; 4650 + } 4651 + 4652 + 4653 + function YAMLException$1(reason, mark) { 4654 + // Super constructor 4655 + Error.call(this); 4656 + 4657 + this.name = 'YAMLException'; 4658 + this.reason = reason; 4659 + this.mark = mark; 4660 + this.message = formatError(this, false); 4661 + 4662 + // Include stack trace in error object 4663 + if (Error.captureStackTrace) { 4664 + // Chrome and NodeJS 4665 + Error.captureStackTrace(this, this.constructor); 4666 + } else { 4667 + // FF, IE 10+ and Safari 6+. Fallback for others 4668 + this.stack = (new Error()).stack || ''; 4669 + } 4670 + } 4671 + 4672 + 4673 + // Inherit from Error 4674 + YAMLException$1.prototype = Object.create(Error.prototype); 4675 + YAMLException$1.prototype.constructor = YAMLException$1; 4676 + 4677 + 4678 + YAMLException$1.prototype.toString = function toString(compact) { 4679 + return this.name + ': ' + formatError(this, compact); 4680 + }; 4681 + 4682 + 4683 + var exception = YAMLException$1; 4684 + 4685 + // get snippet for a single line, respecting maxLength 4686 + function getLine(buffer, lineStart, lineEnd, position, maxLineLength) { 4687 + var head = ''; 4688 + var tail = ''; 4689 + var maxHalfLength = Math.floor(maxLineLength / 2) - 1; 4690 + 4691 + if (position - lineStart > maxHalfLength) { 4692 + head = ' ... '; 4693 + lineStart = position - maxHalfLength + head.length; 4694 + } 4695 + 4696 + if (lineEnd - position > maxHalfLength) { 4697 + tail = ' ...'; 4698 + lineEnd = position + maxHalfLength - tail.length; 4699 + } 4700 + 4701 + return { 4702 + str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail, 4703 + pos: position - lineStart + head.length // relative position 4704 + }; 4705 + } 4706 + 4707 + 4708 + function padStart(string, max) { 4709 + return common.repeat(' ', max - string.length) + string; 4710 + } 4711 + 4712 + 4713 + function makeSnippet(mark, options) { 4714 + options = Object.create(options || null); 4715 + 4716 + if (!mark.buffer) return null; 4717 + 4718 + if (!options.maxLength) options.maxLength = 79; 4719 + if (typeof options.indent !== 'number') options.indent = 1; 4720 + if (typeof options.linesBefore !== 'number') options.linesBefore = 3; 4721 + if (typeof options.linesAfter !== 'number') options.linesAfter = 2; 4722 + 4723 + var re = /\r?\n|\r|\0/g; 4724 + var lineStarts = [ 0 ]; 4725 + var lineEnds = []; 4726 + var match; 4727 + var foundLineNo = -1; 4728 + 4729 + while ((match = re.exec(mark.buffer))) { 4730 + lineEnds.push(match.index); 4731 + lineStarts.push(match.index + match[0].length); 4732 + 4733 + if (mark.position <= match.index && foundLineNo < 0) { 4734 + foundLineNo = lineStarts.length - 2; 4735 + } 4736 + } 4737 + 4738 + if (foundLineNo < 0) foundLineNo = lineStarts.length - 1; 4739 + 4740 + var result = '', i, line; 4741 + var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length; 4742 + var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3); 4743 + 4744 + for (i = 1; i <= options.linesBefore; i++) { 4745 + if (foundLineNo - i < 0) break; 4746 + line = getLine( 4747 + mark.buffer, 4748 + lineStarts[foundLineNo - i], 4749 + lineEnds[foundLineNo - i], 4750 + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), 4751 + maxLineLength 4752 + ); 4753 + result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + 4754 + ' | ' + line.str + '\n' + result; 4755 + } 4756 + 4757 + line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); 4758 + result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + 4759 + ' | ' + line.str + '\n'; 4760 + result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n'; 4761 + 4762 + for (i = 1; i <= options.linesAfter; i++) { 4763 + if (foundLineNo + i >= lineEnds.length) break; 4764 + line = getLine( 4765 + mark.buffer, 4766 + lineStarts[foundLineNo + i], 4767 + lineEnds[foundLineNo + i], 4768 + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), 4769 + maxLineLength 4770 + ); 4771 + result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + 4772 + ' | ' + line.str + '\n'; 4773 + } 4774 + 4775 + return result.replace(/\n$/, ''); 4776 + } 4777 + 4778 + 4779 + var snippet = makeSnippet; 4780 + 4781 + var TYPE_CONSTRUCTOR_OPTIONS = [ 4782 + 'kind', 4783 + 'multi', 4784 + 'resolve', 4785 + 'construct', 4786 + 'instanceOf', 4787 + 'predicate', 4788 + 'represent', 4789 + 'representName', 4790 + 'defaultStyle', 4791 + 'styleAliases' 4792 + ]; 4793 + 4794 + var YAML_NODE_KINDS = [ 4795 + 'scalar', 4796 + 'sequence', 4797 + 'mapping' 4798 + ]; 4799 + 4800 + function compileStyleAliases(map) { 4801 + var result = {}; 4802 + 4803 + if (map !== null) { 4804 + Object.keys(map).forEach(function (style) { 4805 + map[style].forEach(function (alias) { 4806 + result[String(alias)] = style; 4807 + }); 4808 + }); 4809 + } 4810 + 4811 + return result; 4812 + } 4813 + 4814 + function Type$1(tag, options) { 4815 + options = options || {}; 4816 + 4817 + Object.keys(options).forEach(function (name) { 4818 + if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) { 4819 + throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.'); 4820 + } 4821 + }); 4822 + 4823 + // TODO: Add tag format check. 4824 + this.options = options; // keep original options in case user wants to extend this type later 4825 + this.tag = tag; 4826 + this.kind = options['kind'] || null; 4827 + this.resolve = options['resolve'] || function () { return true; }; 4828 + this.construct = options['construct'] || function (data) { return data; }; 4829 + this.instanceOf = options['instanceOf'] || null; 4830 + this.predicate = options['predicate'] || null; 4831 + this.represent = options['represent'] || null; 4832 + this.representName = options['representName'] || null; 4833 + this.defaultStyle = options['defaultStyle'] || null; 4834 + this.multi = options['multi'] || false; 4835 + this.styleAliases = compileStyleAliases(options['styleAliases'] || null); 4836 + 4837 + if (YAML_NODE_KINDS.indexOf(this.kind) === -1) { 4838 + throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.'); 4839 + } 4840 + } 4841 + 4842 + var type = Type$1; 4843 + 4844 + /*eslint-disable max-len*/ 4845 + 4846 + 4847 + 4848 + 4849 + 4850 + function compileList(schema, name) { 4851 + var result = []; 4852 + 4853 + schema[name].forEach(function (currentType) { 4854 + var newIndex = result.length; 4855 + 4856 + result.forEach(function (previousType, previousIndex) { 4857 + if (previousType.tag === currentType.tag && 4858 + previousType.kind === currentType.kind && 4859 + previousType.multi === currentType.multi) { 4860 + 4861 + newIndex = previousIndex; 4862 + } 4863 + }); 4864 + 4865 + result[newIndex] = currentType; 4866 + }); 4867 + 4868 + return result; 4869 + } 4870 + 4871 + 4872 + function compileMap(/* lists... */) { 4873 + var result = { 4874 + scalar: {}, 4875 + sequence: {}, 4876 + mapping: {}, 4877 + fallback: {}, 4878 + multi: { 4879 + scalar: [], 4880 + sequence: [], 4881 + mapping: [], 4882 + fallback: [] 4883 + } 4884 + }, index, length; 4885 + 4886 + function collectType(type) { 4887 + if (type.multi) { 4888 + result.multi[type.kind].push(type); 4889 + result.multi['fallback'].push(type); 4890 + } else { 4891 + result[type.kind][type.tag] = result['fallback'][type.tag] = type; 4892 + } 4893 + } 4894 + 4895 + for (index = 0, length = arguments.length; index < length; index += 1) { 4896 + arguments[index].forEach(collectType); 4897 + } 4898 + return result; 4899 + } 4900 + 4901 + 4902 + function Schema$1(definition) { 4903 + return this.extend(definition); 4904 + } 4905 + 4906 + 4907 + Schema$1.prototype.extend = function extend(definition) { 4908 + var implicit = []; 4909 + var explicit = []; 4910 + 4911 + if (definition instanceof type) { 4912 + // Schema.extend(type) 4913 + explicit.push(definition); 4914 + 4915 + } else if (Array.isArray(definition)) { 4916 + // Schema.extend([ type1, type2, ... ]) 4917 + explicit = explicit.concat(definition); 4918 + 4919 + } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) { 4920 + // Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] }) 4921 + if (definition.implicit) implicit = implicit.concat(definition.implicit); 4922 + if (definition.explicit) explicit = explicit.concat(definition.explicit); 4923 + 4924 + } else { 4925 + throw new exception('Schema.extend argument should be a Type, [ Type ], ' + 4926 + 'or a schema definition ({ implicit: [...], explicit: [...] })'); 4927 + } 4928 + 4929 + implicit.forEach(function (type$1) { 4930 + if (!(type$1 instanceof type)) { 4931 + throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.'); 4932 + } 4933 + 4934 + if (type$1.loadKind && type$1.loadKind !== 'scalar') { 4935 + throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.'); 4936 + } 4937 + 4938 + if (type$1.multi) { 4939 + throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.'); 4940 + } 4941 + }); 4942 + 4943 + explicit.forEach(function (type$1) { 4944 + if (!(type$1 instanceof type)) { 4945 + throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.'); 4946 + } 4947 + }); 4948 + 4949 + var result = Object.create(Schema$1.prototype); 4950 + 4951 + result.implicit = (this.implicit || []).concat(implicit); 4952 + result.explicit = (this.explicit || []).concat(explicit); 4953 + 4954 + result.compiledImplicit = compileList(result, 'implicit'); 4955 + result.compiledExplicit = compileList(result, 'explicit'); 4956 + result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit); 4957 + 4958 + return result; 4959 + }; 4960 + 4961 + 4962 + var schema = Schema$1; 4963 + 4964 + var str = new type('tag:yaml.org,2002:str', { 4965 + kind: 'scalar', 4966 + construct: function (data) { return data !== null ? data : ''; } 4967 + }); 4968 + 4969 + var seq = new type('tag:yaml.org,2002:seq', { 4970 + kind: 'sequence', 4971 + construct: function (data) { return data !== null ? data : []; } 4972 + }); 4973 + 4974 + var map = new type('tag:yaml.org,2002:map', { 4975 + kind: 'mapping', 4976 + construct: function (data) { return data !== null ? data : {}; } 4977 + }); 4978 + 4979 + var failsafe = new schema({ 4980 + explicit: [ 4981 + str, 4982 + seq, 4983 + map 4984 + ] 4985 + }); 4986 + 4987 + function resolveYamlNull(data) { 4988 + if (data === null) return true; 4989 + 4990 + var max = data.length; 4991 + 4992 + return (max === 1 && data === '~') || 4993 + (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL')); 4994 + } 4995 + 4996 + function constructYamlNull() { 4997 + return null; 4998 + } 4999 + 5000 + function isNull(object) { 5001 + return object === null; 5002 + } 5003 + 5004 + var _null = new type('tag:yaml.org,2002:null', { 5005 + kind: 'scalar', 5006 + resolve: resolveYamlNull, 5007 + construct: constructYamlNull, 5008 + predicate: isNull, 5009 + represent: { 5010 + canonical: function () { return '~'; }, 5011 + lowercase: function () { return 'null'; }, 5012 + uppercase: function () { return 'NULL'; }, 5013 + camelcase: function () { return 'Null'; }, 5014 + empty: function () { return ''; } 5015 + }, 5016 + defaultStyle: 'lowercase' 5017 + }); 5018 + 5019 + function resolveYamlBoolean(data) { 5020 + if (data === null) return false; 5021 + 5022 + var max = data.length; 5023 + 5024 + return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) || 5025 + (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE')); 5026 + } 5027 + 5028 + function constructYamlBoolean(data) { 5029 + return data === 'true' || 5030 + data === 'True' || 5031 + data === 'TRUE'; 5032 + } 5033 + 5034 + function isBoolean(object) { 5035 + return Object.prototype.toString.call(object) === '[object Boolean]'; 5036 + } 5037 + 5038 + var bool = new type('tag:yaml.org,2002:bool', { 5039 + kind: 'scalar', 5040 + resolve: resolveYamlBoolean, 5041 + construct: constructYamlBoolean, 5042 + predicate: isBoolean, 5043 + represent: { 5044 + lowercase: function (object) { return object ? 'true' : 'false'; }, 5045 + uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; }, 5046 + camelcase: function (object) { return object ? 'True' : 'False'; } 5047 + }, 5048 + defaultStyle: 'lowercase' 5049 + }); 5050 + 5051 + function isHexCode(c) { 5052 + return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) || 5053 + ((0x41/* A */ <= c) && (c <= 0x46/* F */)) || 5054 + ((0x61/* a */ <= c) && (c <= 0x66/* f */)); 5055 + } 5056 + 5057 + function isOctCode(c) { 5058 + return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */)); 5059 + } 5060 + 5061 + function isDecCode(c) { 5062 + return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)); 5063 + } 5064 + 5065 + function resolveYamlInteger(data) { 5066 + if (data === null) return false; 5067 + 5068 + var max = data.length, 5069 + index = 0, 5070 + hasDigits = false, 5071 + ch; 5072 + 5073 + if (!max) return false; 5074 + 5075 + ch = data[index]; 5076 + 5077 + // sign 5078 + if (ch === '-' || ch === '+') { 5079 + ch = data[++index]; 5080 + } 5081 + 5082 + if (ch === '0') { 5083 + // 0 5084 + if (index + 1 === max) return true; 5085 + ch = data[++index]; 5086 + 5087 + // base 2, base 8, base 16 5088 + 5089 + if (ch === 'b') { 5090 + // base 2 5091 + index++; 5092 + 5093 + for (; index < max; index++) { 5094 + ch = data[index]; 5095 + if (ch === '_') continue; 5096 + if (ch !== '0' && ch !== '1') return false; 5097 + hasDigits = true; 5098 + } 5099 + return hasDigits && ch !== '_'; 5100 + } 5101 + 5102 + 5103 + if (ch === 'x') { 5104 + // base 16 5105 + index++; 5106 + 5107 + for (; index < max; index++) { 5108 + ch = data[index]; 5109 + if (ch === '_') continue; 5110 + if (!isHexCode(data.charCodeAt(index))) return false; 5111 + hasDigits = true; 5112 + } 5113 + return hasDigits && ch !== '_'; 5114 + } 5115 + 5116 + 5117 + if (ch === 'o') { 5118 + // base 8 5119 + index++; 5120 + 5121 + for (; index < max; index++) { 5122 + ch = data[index]; 5123 + if (ch === '_') continue; 5124 + if (!isOctCode(data.charCodeAt(index))) return false; 5125 + hasDigits = true; 5126 + } 5127 + return hasDigits && ch !== '_'; 5128 + } 5129 + } 5130 + 5131 + // base 10 (except 0) 5132 + 5133 + // value should not start with `_`; 5134 + if (ch === '_') return false; 5135 + 5136 + for (; index < max; index++) { 5137 + ch = data[index]; 5138 + if (ch === '_') continue; 5139 + if (!isDecCode(data.charCodeAt(index))) { 5140 + return false; 5141 + } 5142 + hasDigits = true; 5143 + } 5144 + 5145 + // Should have digits and should not end with `_` 5146 + if (!hasDigits || ch === '_') return false; 5147 + 5148 + return true; 5149 + } 5150 + 5151 + function constructYamlInteger(data) { 5152 + var value = data, sign = 1, ch; 5153 + 5154 + if (value.indexOf('_') !== -1) { 5155 + value = value.replace(/_/g, ''); 5156 + } 5157 + 5158 + ch = value[0]; 5159 + 5160 + if (ch === '-' || ch === '+') { 5161 + if (ch === '-') sign = -1; 5162 + value = value.slice(1); 5163 + ch = value[0]; 5164 + } 5165 + 5166 + if (value === '0') return 0; 5167 + 5168 + if (ch === '0') { 5169 + if (value[1] === 'b') return sign * parseInt(value.slice(2), 2); 5170 + if (value[1] === 'x') return sign * parseInt(value.slice(2), 16); 5171 + if (value[1] === 'o') return sign * parseInt(value.slice(2), 8); 5172 + } 5173 + 5174 + return sign * parseInt(value, 10); 5175 + } 5176 + 5177 + function isInteger(object) { 5178 + return (Object.prototype.toString.call(object)) === '[object Number]' && 5179 + (object % 1 === 0 && !common.isNegativeZero(object)); 5180 + } 5181 + 5182 + var int = new type('tag:yaml.org,2002:int', { 5183 + kind: 'scalar', 5184 + resolve: resolveYamlInteger, 5185 + construct: constructYamlInteger, 5186 + predicate: isInteger, 5187 + represent: { 5188 + binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); }, 5189 + octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); }, 5190 + decimal: function (obj) { return obj.toString(10); }, 5191 + /* eslint-disable max-len */ 5192 + hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); } 5193 + }, 5194 + defaultStyle: 'decimal', 5195 + styleAliases: { 5196 + binary: [ 2, 'bin' ], 5197 + octal: [ 8, 'oct' ], 5198 + decimal: [ 10, 'dec' ], 5199 + hexadecimal: [ 16, 'hex' ] 5200 + } 5201 + }); 5202 + 5203 + var YAML_FLOAT_PATTERN = new RegExp( 5204 + // 2.5e4, 2.5 and integers 5205 + '^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + 5206 + // .2e4, .2 5207 + // special case, seems not from spec 5208 + '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + 5209 + // .inf 5210 + '|[-+]?\\.(?:inf|Inf|INF)' + 5211 + // .nan 5212 + '|\\.(?:nan|NaN|NAN))$'); 5213 + 5214 + function resolveYamlFloat(data) { 5215 + if (data === null) return false; 5216 + 5217 + if (!YAML_FLOAT_PATTERN.test(data) || 5218 + // Quick hack to not allow integers end with `_` 5219 + // Probably should update regexp & check speed 5220 + data[data.length - 1] === '_') { 5221 + return false; 5222 + } 5223 + 5224 + return true; 5225 + } 5226 + 5227 + function constructYamlFloat(data) { 5228 + var value, sign; 5229 + 5230 + value = data.replace(/_/g, '').toLowerCase(); 5231 + sign = value[0] === '-' ? -1 : 1; 5232 + 5233 + if ('+-'.indexOf(value[0]) >= 0) { 5234 + value = value.slice(1); 5235 + } 5236 + 5237 + if (value === '.inf') { 5238 + return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; 5239 + 5240 + } else if (value === '.nan') { 5241 + return NaN; 5242 + } 5243 + return sign * parseFloat(value, 10); 5244 + } 5245 + 5246 + 5247 + var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/; 5248 + 5249 + function representYamlFloat(object, style) { 5250 + var res; 5251 + 5252 + if (isNaN(object)) { 5253 + switch (style) { 5254 + case 'lowercase': return '.nan'; 5255 + case 'uppercase': return '.NAN'; 5256 + case 'camelcase': return '.NaN'; 5257 + } 5258 + } else if (Number.POSITIVE_INFINITY === object) { 5259 + switch (style) { 5260 + case 'lowercase': return '.inf'; 5261 + case 'uppercase': return '.INF'; 5262 + case 'camelcase': return '.Inf'; 5263 + } 5264 + } else if (Number.NEGATIVE_INFINITY === object) { 5265 + switch (style) { 5266 + case 'lowercase': return '-.inf'; 5267 + case 'uppercase': return '-.INF'; 5268 + case 'camelcase': return '-.Inf'; 5269 + } 5270 + } else if (common.isNegativeZero(object)) { 5271 + return '-0.0'; 5272 + } 5273 + 5274 + res = object.toString(10); 5275 + 5276 + // JS stringifier can build scientific format without dots: 5e-100, 5277 + // while YAML requres dot: 5.e-100. Fix it with simple hack 5278 + 5279 + return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res; 5280 + } 5281 + 5282 + function isFloat(object) { 5283 + return (Object.prototype.toString.call(object) === '[object Number]') && 5284 + (object % 1 !== 0 || common.isNegativeZero(object)); 5285 + } 5286 + 5287 + var float = new type('tag:yaml.org,2002:float', { 5288 + kind: 'scalar', 5289 + resolve: resolveYamlFloat, 5290 + construct: constructYamlFloat, 5291 + predicate: isFloat, 5292 + represent: representYamlFloat, 5293 + defaultStyle: 'lowercase' 5294 + }); 5295 + 5296 + var json = failsafe.extend({ 5297 + implicit: [ 5298 + _null, 5299 + bool, 5300 + int, 5301 + float 5302 + ] 5303 + }); 5304 + 5305 + var core = json; 5306 + 5307 + var YAML_DATE_REGEXP = new RegExp( 5308 + '^([0-9][0-9][0-9][0-9])' + // [1] year 5309 + '-([0-9][0-9])' + // [2] month 5310 + '-([0-9][0-9])$'); // [3] day 5311 + 5312 + var YAML_TIMESTAMP_REGEXP = new RegExp( 5313 + '^([0-9][0-9][0-9][0-9])' + // [1] year 5314 + '-([0-9][0-9]?)' + // [2] month 5315 + '-([0-9][0-9]?)' + // [3] day 5316 + '(?:[Tt]|[ \\t]+)' + // ... 5317 + '([0-9][0-9]?)' + // [4] hour 5318 + ':([0-9][0-9])' + // [5] minute 5319 + ':([0-9][0-9])' + // [6] second 5320 + '(?:\\.([0-9]*))?' + // [7] fraction 5321 + '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour 5322 + '(?::([0-9][0-9]))?))?$'); // [11] tz_minute 5323 + 5324 + function resolveYamlTimestamp(data) { 5325 + if (data === null) return false; 5326 + if (YAML_DATE_REGEXP.exec(data) !== null) return true; 5327 + if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true; 5328 + return false; 5329 + } 5330 + 5331 + function constructYamlTimestamp(data) { 5332 + var match, year, month, day, hour, minute, second, fraction = 0, 5333 + delta = null, tz_hour, tz_minute, date; 5334 + 5335 + match = YAML_DATE_REGEXP.exec(data); 5336 + if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data); 5337 + 5338 + if (match === null) throw new Error('Date resolve error'); 5339 + 5340 + // match: [1] year [2] month [3] day 5341 + 5342 + year = +(match[1]); 5343 + month = +(match[2]) - 1; // JS month starts with 0 5344 + day = +(match[3]); 5345 + 5346 + if (!match[4]) { // no hour 5347 + return new Date(Date.UTC(year, month, day)); 5348 + } 5349 + 5350 + // match: [4] hour [5] minute [6] second [7] fraction 5351 + 5352 + hour = +(match[4]); 5353 + minute = +(match[5]); 5354 + second = +(match[6]); 5355 + 5356 + if (match[7]) { 5357 + fraction = match[7].slice(0, 3); 5358 + while (fraction.length < 3) { // milli-seconds 5359 + fraction += '0'; 5360 + } 5361 + fraction = +fraction; 5362 + } 5363 + 5364 + // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute 5365 + 5366 + if (match[9]) { 5367 + tz_hour = +(match[10]); 5368 + tz_minute = +(match[11] || 0); 5369 + delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds 5370 + if (match[9] === '-') delta = -delta; 5371 + } 5372 + 5373 + date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); 5374 + 5375 + if (delta) date.setTime(date.getTime() - delta); 5376 + 5377 + return date; 5378 + } 5379 + 5380 + function representYamlTimestamp(object /*, style*/) { 5381 + return object.toISOString(); 5382 + } 5383 + 5384 + var timestamp = new type('tag:yaml.org,2002:timestamp', { 5385 + kind: 'scalar', 5386 + resolve: resolveYamlTimestamp, 5387 + construct: constructYamlTimestamp, 5388 + instanceOf: Date, 5389 + represent: representYamlTimestamp 5390 + }); 5391 + 5392 + function resolveYamlMerge(data) { 5393 + return data === '<<' || data === null; 5394 + } 5395 + 5396 + var merge = new type('tag:yaml.org,2002:merge', { 5397 + kind: 'scalar', 5398 + resolve: resolveYamlMerge 5399 + }); 5400 + 5401 + /*eslint-disable no-bitwise*/ 5402 + 5403 + 5404 + 5405 + 5406 + 5407 + // [ 64, 65, 66 ] -> [ padding, CR, LF ] 5408 + var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r'; 5409 + 5410 + 5411 + function resolveYamlBinary(data) { 5412 + if (data === null) return false; 5413 + 5414 + var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP; 5415 + 5416 + // Convert one by one. 5417 + for (idx = 0; idx < max; idx++) { 5418 + code = map.indexOf(data.charAt(idx)); 5419 + 5420 + // Skip CR/LF 5421 + if (code > 64) continue; 5422 + 5423 + // Fail on illegal characters 5424 + if (code < 0) return false; 5425 + 5426 + bitlen += 6; 5427 + } 5428 + 5429 + // If there are any bits left, source was corrupted 5430 + return (bitlen % 8) === 0; 5431 + } 5432 + 5433 + function constructYamlBinary(data) { 5434 + var idx, tailbits, 5435 + input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan 5436 + max = input.length, 5437 + map = BASE64_MAP, 5438 + bits = 0, 5439 + result = []; 5440 + 5441 + // Collect by 6*4 bits (3 bytes) 5442 + 5443 + for (idx = 0; idx < max; idx++) { 5444 + if ((idx % 4 === 0) && idx) { 5445 + result.push((bits >> 16) & 0xFF); 5446 + result.push((bits >> 8) & 0xFF); 5447 + result.push(bits & 0xFF); 5448 + } 5449 + 5450 + bits = (bits << 6) | map.indexOf(input.charAt(idx)); 5451 + } 5452 + 5453 + // Dump tail 5454 + 5455 + tailbits = (max % 4) * 6; 5456 + 5457 + if (tailbits === 0) { 5458 + result.push((bits >> 16) & 0xFF); 5459 + result.push((bits >> 8) & 0xFF); 5460 + result.push(bits & 0xFF); 5461 + } else if (tailbits === 18) { 5462 + result.push((bits >> 10) & 0xFF); 5463 + result.push((bits >> 2) & 0xFF); 5464 + } else if (tailbits === 12) { 5465 + result.push((bits >> 4) & 0xFF); 5466 + } 5467 + 5468 + return new Uint8Array(result); 5469 + } 5470 + 5471 + function representYamlBinary(object /*, style*/) { 5472 + var result = '', bits = 0, idx, tail, 5473 + max = object.length, 5474 + map = BASE64_MAP; 5475 + 5476 + // Convert every three bytes to 4 ASCII characters. 5477 + 5478 + for (idx = 0; idx < max; idx++) { 5479 + if ((idx % 3 === 0) && idx) { 5480 + result += map[(bits >> 18) & 0x3F]; 5481 + result += map[(bits >> 12) & 0x3F]; 5482 + result += map[(bits >> 6) & 0x3F]; 5483 + result += map[bits & 0x3F]; 5484 + } 5485 + 5486 + bits = (bits << 8) + object[idx]; 5487 + } 5488 + 5489 + // Dump tail 5490 + 5491 + tail = max % 3; 5492 + 5493 + if (tail === 0) { 5494 + result += map[(bits >> 18) & 0x3F]; 5495 + result += map[(bits >> 12) & 0x3F]; 5496 + result += map[(bits >> 6) & 0x3F]; 5497 + result += map[bits & 0x3F]; 5498 + } else if (tail === 2) { 5499 + result += map[(bits >> 10) & 0x3F]; 5500 + result += map[(bits >> 4) & 0x3F]; 5501 + result += map[(bits << 2) & 0x3F]; 5502 + result += map[64]; 5503 + } else if (tail === 1) { 5504 + result += map[(bits >> 2) & 0x3F]; 5505 + result += map[(bits << 4) & 0x3F]; 5506 + result += map[64]; 5507 + result += map[64]; 5508 + } 5509 + 5510 + return result; 5511 + } 5512 + 5513 + function isBinary(obj) { 5514 + return Object.prototype.toString.call(obj) === '[object Uint8Array]'; 5515 + } 5516 + 5517 + var binary = new type('tag:yaml.org,2002:binary', { 5518 + kind: 'scalar', 5519 + resolve: resolveYamlBinary, 5520 + construct: constructYamlBinary, 5521 + predicate: isBinary, 5522 + represent: representYamlBinary 5523 + }); 5524 + 5525 + var _hasOwnProperty$3 = Object.prototype.hasOwnProperty; 5526 + var _toString$2 = Object.prototype.toString; 5527 + 5528 + function resolveYamlOmap(data) { 5529 + if (data === null) return true; 5530 + 5531 + var objectKeys = [], index, length, pair, pairKey, pairHasKey, 5532 + object = data; 5533 + 5534 + for (index = 0, length = object.length; index < length; index += 1) { 5535 + pair = object[index]; 5536 + pairHasKey = false; 5537 + 5538 + if (_toString$2.call(pair) !== '[object Object]') return false; 5539 + 5540 + for (pairKey in pair) { 5541 + if (_hasOwnProperty$3.call(pair, pairKey)) { 5542 + if (!pairHasKey) pairHasKey = true; 5543 + else return false; 5544 + } 5545 + } 5546 + 5547 + if (!pairHasKey) return false; 5548 + 5549 + if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey); 5550 + else return false; 5551 + } 5552 + 5553 + return true; 5554 + } 5555 + 5556 + function constructYamlOmap(data) { 5557 + return data !== null ? data : []; 5558 + } 5559 + 5560 + var omap = new type('tag:yaml.org,2002:omap', { 5561 + kind: 'sequence', 5562 + resolve: resolveYamlOmap, 5563 + construct: constructYamlOmap 5564 + }); 5565 + 5566 + var _toString$1 = Object.prototype.toString; 5567 + 5568 + function resolveYamlPairs(data) { 5569 + if (data === null) return true; 5570 + 5571 + var index, length, pair, keys, result, 5572 + object = data; 5573 + 5574 + result = new Array(object.length); 5575 + 5576 + for (index = 0, length = object.length; index < length; index += 1) { 5577 + pair = object[index]; 5578 + 5579 + if (_toString$1.call(pair) !== '[object Object]') return false; 5580 + 5581 + keys = Object.keys(pair); 5582 + 5583 + if (keys.length !== 1) return false; 5584 + 5585 + result[index] = [ keys[0], pair[keys[0]] ]; 5586 + } 5587 + 5588 + return true; 5589 + } 5590 + 5591 + function constructYamlPairs(data) { 5592 + if (data === null) return []; 5593 + 5594 + var index, length, pair, keys, result, 5595 + object = data; 5596 + 5597 + result = new Array(object.length); 5598 + 5599 + for (index = 0, length = object.length; index < length; index += 1) { 5600 + pair = object[index]; 5601 + 5602 + keys = Object.keys(pair); 5603 + 5604 + result[index] = [ keys[0], pair[keys[0]] ]; 5605 + } 5606 + 5607 + return result; 5608 + } 5609 + 5610 + var pairs = new type('tag:yaml.org,2002:pairs', { 5611 + kind: 'sequence', 5612 + resolve: resolveYamlPairs, 5613 + construct: constructYamlPairs 5614 + }); 5615 + 5616 + var _hasOwnProperty$2 = Object.prototype.hasOwnProperty; 5617 + 5618 + function resolveYamlSet(data) { 5619 + if (data === null) return true; 5620 + 5621 + var key, object = data; 5622 + 5623 + for (key in object) { 5624 + if (_hasOwnProperty$2.call(object, key)) { 5625 + if (object[key] !== null) return false; 5626 + } 5627 + } 5628 + 5629 + return true; 5630 + } 5631 + 5632 + function constructYamlSet(data) { 5633 + return data !== null ? data : {}; 5634 + } 5635 + 5636 + var set = new type('tag:yaml.org,2002:set', { 5637 + kind: 'mapping', 5638 + resolve: resolveYamlSet, 5639 + construct: constructYamlSet 5640 + }); 5641 + 5642 + var _default = core.extend({ 5643 + implicit: [ 5644 + timestamp, 5645 + merge 5646 + ], 5647 + explicit: [ 5648 + binary, 5649 + omap, 5650 + pairs, 5651 + set 5652 + ] 5653 + }); 5654 + 5655 + /*eslint-disable max-len,no-use-before-define*/ 5656 + 5657 + 5658 + 5659 + 5660 + 5661 + 5662 + 5663 + var _hasOwnProperty$1 = Object.prototype.hasOwnProperty; 5664 + 5665 + 5666 + var CONTEXT_FLOW_IN = 1; 5667 + var CONTEXT_FLOW_OUT = 2; 5668 + var CONTEXT_BLOCK_IN = 3; 5669 + var CONTEXT_BLOCK_OUT = 4; 5670 + 5671 + 5672 + var CHOMPING_CLIP = 1; 5673 + var CHOMPING_STRIP = 2; 5674 + var CHOMPING_KEEP = 3; 5675 + 5676 + 5677 + var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; 5678 + var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/; 5679 + var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/; 5680 + var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i; 5681 + var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i; 5682 + 5683 + 5684 + function _class(obj) { return Object.prototype.toString.call(obj); } 5685 + 5686 + function is_EOL(c) { 5687 + return (c === 0x0A/* LF */) || (c === 0x0D/* CR */); 5688 + } 5689 + 5690 + function is_WHITE_SPACE(c) { 5691 + return (c === 0x09/* Tab */) || (c === 0x20/* Space */); 5692 + } 5693 + 5694 + function is_WS_OR_EOL(c) { 5695 + return (c === 0x09/* Tab */) || 5696 + (c === 0x20/* Space */) || 5697 + (c === 0x0A/* LF */) || 5698 + (c === 0x0D/* CR */); 5699 + } 5700 + 5701 + function is_FLOW_INDICATOR(c) { 5702 + return c === 0x2C/* , */ || 5703 + c === 0x5B/* [ */ || 5704 + c === 0x5D/* ] */ || 5705 + c === 0x7B/* { */ || 5706 + c === 0x7D/* } */; 5707 + } 5708 + 5709 + function fromHexCode(c) { 5710 + var lc; 5711 + 5712 + if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) { 5713 + return c - 0x30; 5714 + } 5715 + 5716 + /*eslint-disable no-bitwise*/ 5717 + lc = c | 0x20; 5718 + 5719 + if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) { 5720 + return lc - 0x61 + 10; 5721 + } 5722 + 5723 + return -1; 5724 + } 5725 + 5726 + function escapedHexLen(c) { 5727 + if (c === 0x78/* x */) { return 2; } 5728 + if (c === 0x75/* u */) { return 4; } 5729 + if (c === 0x55/* U */) { return 8; } 5730 + return 0; 5731 + } 5732 + 5733 + function fromDecimalCode(c) { 5734 + if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) { 5735 + return c - 0x30; 5736 + } 5737 + 5738 + return -1; 5739 + } 5740 + 5741 + function simpleEscapeSequence(c) { 5742 + /* eslint-disable indent */ 5743 + return (c === 0x30/* 0 */) ? '\x00' : 5744 + (c === 0x61/* a */) ? '\x07' : 5745 + (c === 0x62/* b */) ? '\x08' : 5746 + (c === 0x74/* t */) ? '\x09' : 5747 + (c === 0x09/* Tab */) ? '\x09' : 5748 + (c === 0x6E/* n */) ? '\x0A' : 5749 + (c === 0x76/* v */) ? '\x0B' : 5750 + (c === 0x66/* f */) ? '\x0C' : 5751 + (c === 0x72/* r */) ? '\x0D' : 5752 + (c === 0x65/* e */) ? '\x1B' : 5753 + (c === 0x20/* Space */) ? ' ' : 5754 + (c === 0x22/* " */) ? '\x22' : 5755 + (c === 0x2F/* / */) ? '/' : 5756 + (c === 0x5C/* \ */) ? '\x5C' : 5757 + (c === 0x4E/* N */) ? '\x85' : 5758 + (c === 0x5F/* _ */) ? '\xA0' : 5759 + (c === 0x4C/* L */) ? '\u2028' : 5760 + (c === 0x50/* P */) ? '\u2029' : ''; 5761 + } 5762 + 5763 + function charFromCodepoint(c) { 5764 + if (c <= 0xFFFF) { 5765 + return String.fromCharCode(c); 5766 + } 5767 + // Encode UTF-16 surrogate pair 5768 + // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF 5769 + return String.fromCharCode( 5770 + ((c - 0x010000) >> 10) + 0xD800, 5771 + ((c - 0x010000) & 0x03FF) + 0xDC00 5772 + ); 5773 + } 5774 + 5775 + var simpleEscapeCheck = new Array(256); // integer, for fast access 5776 + var simpleEscapeMap = new Array(256); 5777 + for (var i = 0; i < 256; i++) { 5778 + simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0; 5779 + simpleEscapeMap[i] = simpleEscapeSequence(i); 5780 + } 5781 + 5782 + 5783 + function State$1(input, options) { 5784 + this.input = input; 5785 + 5786 + this.filename = options['filename'] || null; 5787 + this.schema = options['schema'] || _default; 5788 + this.onWarning = options['onWarning'] || null; 5789 + // (Hidden) Remove? makes the loader to expect YAML 1.1 documents 5790 + // if such documents have no explicit %YAML directive 5791 + this.legacy = options['legacy'] || false; 5792 + 5793 + this.json = options['json'] || false; 5794 + this.listener = options['listener'] || null; 5795 + 5796 + this.implicitTypes = this.schema.compiledImplicit; 5797 + this.typeMap = this.schema.compiledTypeMap; 5798 + 5799 + this.length = input.length; 5800 + this.position = 0; 5801 + this.line = 0; 5802 + this.lineStart = 0; 5803 + this.lineIndent = 0; 5804 + 5805 + // position of first leading tab in the current line, 5806 + // used to make sure there are no tabs in the indentation 5807 + this.firstTabInLine = -1; 5808 + 5809 + this.documents = []; 5810 + 5811 + /* 5812 + this.version; 5813 + this.checkLineBreaks; 5814 + this.tagMap; 5815 + this.anchorMap; 5816 + this.tag; 5817 + this.anchor; 5818 + this.kind; 5819 + this.result;*/ 5820 + 5821 + } 5822 + 5823 + 5824 + function generateError(state, message) { 5825 + var mark = { 5826 + name: state.filename, 5827 + buffer: state.input.slice(0, -1), // omit trailing \0 5828 + position: state.position, 5829 + line: state.line, 5830 + column: state.position - state.lineStart 5831 + }; 5832 + 5833 + mark.snippet = snippet(mark); 5834 + 5835 + return new exception(message, mark); 5836 + } 5837 + 5838 + function throwError(state, message) { 5839 + throw generateError(state, message); 5840 + } 5841 + 5842 + function throwWarning(state, message) { 5843 + if (state.onWarning) { 5844 + state.onWarning.call(null, generateError(state, message)); 5845 + } 5846 + } 5847 + 5848 + 5849 + var directiveHandlers = { 5850 + 5851 + YAML: function handleYamlDirective(state, name, args) { 5852 + 5853 + var match, major, minor; 5854 + 5855 + if (state.version !== null) { 5856 + throwError(state, 'duplication of %YAML directive'); 5857 + } 5858 + 5859 + if (args.length !== 1) { 5860 + throwError(state, 'YAML directive accepts exactly one argument'); 5861 + } 5862 + 5863 + match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]); 5864 + 5865 + if (match === null) { 5866 + throwError(state, 'ill-formed argument of the YAML directive'); 5867 + } 5868 + 5869 + major = parseInt(match[1], 10); 5870 + minor = parseInt(match[2], 10); 5871 + 5872 + if (major !== 1) { 5873 + throwError(state, 'unacceptable YAML version of the document'); 5874 + } 5875 + 5876 + state.version = args[0]; 5877 + state.checkLineBreaks = (minor < 2); 5878 + 5879 + if (minor !== 1 && minor !== 2) { 5880 + throwWarning(state, 'unsupported YAML version of the document'); 5881 + } 5882 + }, 5883 + 5884 + TAG: function handleTagDirective(state, name, args) { 5885 + 5886 + var handle, prefix; 5887 + 5888 + if (args.length !== 2) { 5889 + throwError(state, 'TAG directive accepts exactly two arguments'); 5890 + } 5891 + 5892 + handle = args[0]; 5893 + prefix = args[1]; 5894 + 5895 + if (!PATTERN_TAG_HANDLE.test(handle)) { 5896 + throwError(state, 'ill-formed tag handle (first argument) of the TAG directive'); 5897 + } 5898 + 5899 + if (_hasOwnProperty$1.call(state.tagMap, handle)) { 5900 + throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle'); 5901 + } 5902 + 5903 + if (!PATTERN_TAG_URI.test(prefix)) { 5904 + throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive'); 5905 + } 5906 + 5907 + try { 5908 + prefix = decodeURIComponent(prefix); 5909 + } catch (err) { 5910 + throwError(state, 'tag prefix is malformed: ' + prefix); 5911 + } 5912 + 5913 + state.tagMap[handle] = prefix; 5914 + } 5915 + }; 5916 + 5917 + 5918 + function captureSegment(state, start, end, checkJson) { 5919 + var _position, _length, _character, _result; 5920 + 5921 + if (start < end) { 5922 + _result = state.input.slice(start, end); 5923 + 5924 + if (checkJson) { 5925 + for (_position = 0, _length = _result.length; _position < _length; _position += 1) { 5926 + _character = _result.charCodeAt(_position); 5927 + if (!(_character === 0x09 || 5928 + (0x20 <= _character && _character <= 0x10FFFF))) { 5929 + throwError(state, 'expected valid JSON character'); 5930 + } 5931 + } 5932 + } else if (PATTERN_NON_PRINTABLE.test(_result)) { 5933 + throwError(state, 'the stream contains non-printable characters'); 5934 + } 5935 + 5936 + state.result += _result; 5937 + } 5938 + } 5939 + 5940 + function mergeMappings(state, destination, source, overridableKeys) { 5941 + var sourceKeys, key, index, quantity; 5942 + 5943 + if (!common.isObject(source)) { 5944 + throwError(state, 'cannot merge mappings; the provided source object is unacceptable'); 5945 + } 5946 + 5947 + sourceKeys = Object.keys(source); 5948 + 5949 + for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) { 5950 + key = sourceKeys[index]; 5951 + 5952 + if (!_hasOwnProperty$1.call(destination, key)) { 5953 + destination[key] = source[key]; 5954 + overridableKeys[key] = true; 5955 + } 5956 + } 5957 + } 5958 + 5959 + function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, 5960 + startLine, startLineStart, startPos) { 5961 + 5962 + var index, quantity; 5963 + 5964 + // The output is a plain object here, so keys can only be strings. 5965 + // We need to convert keyNode to a string, but doing so can hang the process 5966 + // (deeply nested arrays that explode exponentially using aliases). 5967 + if (Array.isArray(keyNode)) { 5968 + keyNode = Array.prototype.slice.call(keyNode); 5969 + 5970 + for (index = 0, quantity = keyNode.length; index < quantity; index += 1) { 5971 + if (Array.isArray(keyNode[index])) { 5972 + throwError(state, 'nested arrays are not supported inside keys'); 5973 + } 5974 + 5975 + if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') { 5976 + keyNode[index] = '[object Object]'; 5977 + } 5978 + } 5979 + } 5980 + 5981 + // Avoid code execution in load() via toString property 5982 + // (still use its own toString for arrays, timestamps, 5983 + // and whatever user schema extensions happen to have @@toStringTag) 5984 + if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') { 5985 + keyNode = '[object Object]'; 5986 + } 5987 + 5988 + 5989 + keyNode = String(keyNode); 5990 + 5991 + if (_result === null) { 5992 + _result = {}; 5993 + } 5994 + 5995 + if (keyTag === 'tag:yaml.org,2002:merge') { 5996 + if (Array.isArray(valueNode)) { 5997 + for (index = 0, quantity = valueNode.length; index < quantity; index += 1) { 5998 + mergeMappings(state, _result, valueNode[index], overridableKeys); 5999 + } 6000 + } else { 6001 + mergeMappings(state, _result, valueNode, overridableKeys); 6002 + } 6003 + } else { 6004 + if (!state.json && 6005 + !_hasOwnProperty$1.call(overridableKeys, keyNode) && 6006 + _hasOwnProperty$1.call(_result, keyNode)) { 6007 + state.line = startLine || state.line; 6008 + state.lineStart = startLineStart || state.lineStart; 6009 + state.position = startPos || state.position; 6010 + throwError(state, 'duplicated mapping key'); 6011 + } 6012 + 6013 + // used for this specific key only because Object.defineProperty is slow 6014 + if (keyNode === '__proto__') { 6015 + Object.defineProperty(_result, keyNode, { 6016 + configurable: true, 6017 + enumerable: true, 6018 + writable: true, 6019 + value: valueNode 6020 + }); 6021 + } else { 6022 + _result[keyNode] = valueNode; 6023 + } 6024 + delete overridableKeys[keyNode]; 6025 + } 6026 + 6027 + return _result; 6028 + } 6029 + 6030 + function readLineBreak(state) { 6031 + var ch; 6032 + 6033 + ch = state.input.charCodeAt(state.position); 6034 + 6035 + if (ch === 0x0A/* LF */) { 6036 + state.position++; 6037 + } else if (ch === 0x0D/* CR */) { 6038 + state.position++; 6039 + if (state.input.charCodeAt(state.position) === 0x0A/* LF */) { 6040 + state.position++; 6041 + } 6042 + } else { 6043 + throwError(state, 'a line break is expected'); 6044 + } 6045 + 6046 + state.line += 1; 6047 + state.lineStart = state.position; 6048 + state.firstTabInLine = -1; 6049 + } 6050 + 6051 + function skipSeparationSpace(state, allowComments, checkIndent) { 6052 + var lineBreaks = 0, 6053 + ch = state.input.charCodeAt(state.position); 6054 + 6055 + while (ch !== 0) { 6056 + while (is_WHITE_SPACE(ch)) { 6057 + if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) { 6058 + state.firstTabInLine = state.position; 6059 + } 6060 + ch = state.input.charCodeAt(++state.position); 6061 + } 6062 + 6063 + if (allowComments && ch === 0x23/* # */) { 6064 + do { 6065 + ch = state.input.charCodeAt(++state.position); 6066 + } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0); 6067 + } 6068 + 6069 + if (is_EOL(ch)) { 6070 + readLineBreak(state); 6071 + 6072 + ch = state.input.charCodeAt(state.position); 6073 + lineBreaks++; 6074 + state.lineIndent = 0; 6075 + 6076 + while (ch === 0x20/* Space */) { 6077 + state.lineIndent++; 6078 + ch = state.input.charCodeAt(++state.position); 6079 + } 6080 + } else { 6081 + break; 6082 + } 6083 + } 6084 + 6085 + if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) { 6086 + throwWarning(state, 'deficient indentation'); 6087 + } 6088 + 6089 + return lineBreaks; 6090 + } 6091 + 6092 + function testDocumentSeparator(state) { 6093 + var _position = state.position, 6094 + ch; 6095 + 6096 + ch = state.input.charCodeAt(_position); 6097 + 6098 + // Condition state.position === state.lineStart is tested 6099 + // in parent on each call, for efficiency. No needs to test here again. 6100 + if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) && 6101 + ch === state.input.charCodeAt(_position + 1) && 6102 + ch === state.input.charCodeAt(_position + 2)) { 6103 + 6104 + _position += 3; 6105 + 6106 + ch = state.input.charCodeAt(_position); 6107 + 6108 + if (ch === 0 || is_WS_OR_EOL(ch)) { 6109 + return true; 6110 + } 6111 + } 6112 + 6113 + return false; 6114 + } 6115 + 6116 + function writeFoldedLines(state, count) { 6117 + if (count === 1) { 6118 + state.result += ' '; 6119 + } else if (count > 1) { 6120 + state.result += common.repeat('\n', count - 1); 6121 + } 6122 + } 6123 + 6124 + 6125 + function readPlainScalar(state, nodeIndent, withinFlowCollection) { 6126 + var preceding, 6127 + following, 6128 + captureStart, 6129 + captureEnd, 6130 + hasPendingContent, 6131 + _line, 6132 + _lineStart, 6133 + _lineIndent, 6134 + _kind = state.kind, 6135 + _result = state.result, 6136 + ch; 6137 + 6138 + ch = state.input.charCodeAt(state.position); 6139 + 6140 + if (is_WS_OR_EOL(ch) || 6141 + is_FLOW_INDICATOR(ch) || 6142 + ch === 0x23/* # */ || 6143 + ch === 0x26/* & */ || 6144 + ch === 0x2A/* * */ || 6145 + ch === 0x21/* ! */ || 6146 + ch === 0x7C/* | */ || 6147 + ch === 0x3E/* > */ || 6148 + ch === 0x27/* ' */ || 6149 + ch === 0x22/* " */ || 6150 + ch === 0x25/* % */ || 6151 + ch === 0x40/* @ */ || 6152 + ch === 0x60/* ` */) { 6153 + return false; 6154 + } 6155 + 6156 + if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) { 6157 + following = state.input.charCodeAt(state.position + 1); 6158 + 6159 + if (is_WS_OR_EOL(following) || 6160 + withinFlowCollection && is_FLOW_INDICATOR(following)) { 6161 + return false; 6162 + } 6163 + } 6164 + 6165 + state.kind = 'scalar'; 6166 + state.result = ''; 6167 + captureStart = captureEnd = state.position; 6168 + hasPendingContent = false; 6169 + 6170 + while (ch !== 0) { 6171 + if (ch === 0x3A/* : */) { 6172 + following = state.input.charCodeAt(state.position + 1); 6173 + 6174 + if (is_WS_OR_EOL(following) || 6175 + withinFlowCollection && is_FLOW_INDICATOR(following)) { 6176 + break; 6177 + } 6178 + 6179 + } else if (ch === 0x23/* # */) { 6180 + preceding = state.input.charCodeAt(state.position - 1); 6181 + 6182 + if (is_WS_OR_EOL(preceding)) { 6183 + break; 6184 + } 6185 + 6186 + } else if ((state.position === state.lineStart && testDocumentSeparator(state)) || 6187 + withinFlowCollection && is_FLOW_INDICATOR(ch)) { 6188 + break; 6189 + 6190 + } else if (is_EOL(ch)) { 6191 + _line = state.line; 6192 + _lineStart = state.lineStart; 6193 + _lineIndent = state.lineIndent; 6194 + skipSeparationSpace(state, false, -1); 6195 + 6196 + if (state.lineIndent >= nodeIndent) { 6197 + hasPendingContent = true; 6198 + ch = state.input.charCodeAt(state.position); 6199 + continue; 6200 + } else { 6201 + state.position = captureEnd; 6202 + state.line = _line; 6203 + state.lineStart = _lineStart; 6204 + state.lineIndent = _lineIndent; 6205 + break; 6206 + } 6207 + } 6208 + 6209 + if (hasPendingContent) { 6210 + captureSegment(state, captureStart, captureEnd, false); 6211 + writeFoldedLines(state, state.line - _line); 6212 + captureStart = captureEnd = state.position; 6213 + hasPendingContent = false; 6214 + } 6215 + 6216 + if (!is_WHITE_SPACE(ch)) { 6217 + captureEnd = state.position + 1; 6218 + } 6219 + 6220 + ch = state.input.charCodeAt(++state.position); 6221 + } 6222 + 6223 + captureSegment(state, captureStart, captureEnd, false); 6224 + 6225 + if (state.result) { 6226 + return true; 6227 + } 6228 + 6229 + state.kind = _kind; 6230 + state.result = _result; 6231 + return false; 6232 + } 6233 + 6234 + function readSingleQuotedScalar(state, nodeIndent) { 6235 + var ch, 6236 + captureStart, captureEnd; 6237 + 6238 + ch = state.input.charCodeAt(state.position); 6239 + 6240 + if (ch !== 0x27/* ' */) { 6241 + return false; 6242 + } 6243 + 6244 + state.kind = 'scalar'; 6245 + state.result = ''; 6246 + state.position++; 6247 + captureStart = captureEnd = state.position; 6248 + 6249 + while ((ch = state.input.charCodeAt(state.position)) !== 0) { 6250 + if (ch === 0x27/* ' */) { 6251 + captureSegment(state, captureStart, state.position, true); 6252 + ch = state.input.charCodeAt(++state.position); 6253 + 6254 + if (ch === 0x27/* ' */) { 6255 + captureStart = state.position; 6256 + state.position++; 6257 + captureEnd = state.position; 6258 + } else { 6259 + return true; 6260 + } 6261 + 6262 + } else if (is_EOL(ch)) { 6263 + captureSegment(state, captureStart, captureEnd, true); 6264 + writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); 6265 + captureStart = captureEnd = state.position; 6266 + 6267 + } else if (state.position === state.lineStart && testDocumentSeparator(state)) { 6268 + throwError(state, 'unexpected end of the document within a single quoted scalar'); 6269 + 6270 + } else { 6271 + state.position++; 6272 + captureEnd = state.position; 6273 + } 6274 + } 6275 + 6276 + throwError(state, 'unexpected end of the stream within a single quoted scalar'); 6277 + } 6278 + 6279 + function readDoubleQuotedScalar(state, nodeIndent) { 6280 + var captureStart, 6281 + captureEnd, 6282 + hexLength, 6283 + hexResult, 6284 + tmp, 6285 + ch; 6286 + 6287 + ch = state.input.charCodeAt(state.position); 6288 + 6289 + if (ch !== 0x22/* " */) { 6290 + return false; 6291 + } 6292 + 6293 + state.kind = 'scalar'; 6294 + state.result = ''; 6295 + state.position++; 6296 + captureStart = captureEnd = state.position; 6297 + 6298 + while ((ch = state.input.charCodeAt(state.position)) !== 0) { 6299 + if (ch === 0x22/* " */) { 6300 + captureSegment(state, captureStart, state.position, true); 6301 + state.position++; 6302 + return true; 6303 + 6304 + } else if (ch === 0x5C/* \ */) { 6305 + captureSegment(state, captureStart, state.position, true); 6306 + ch = state.input.charCodeAt(++state.position); 6307 + 6308 + if (is_EOL(ch)) { 6309 + skipSeparationSpace(state, false, nodeIndent); 6310 + 6311 + // TODO: rework to inline fn with no type cast? 6312 + } else if (ch < 256 && simpleEscapeCheck[ch]) { 6313 + state.result += simpleEscapeMap[ch]; 6314 + state.position++; 6315 + 6316 + } else if ((tmp = escapedHexLen(ch)) > 0) { 6317 + hexLength = tmp; 6318 + hexResult = 0; 6319 + 6320 + for (; hexLength > 0; hexLength--) { 6321 + ch = state.input.charCodeAt(++state.position); 6322 + 6323 + if ((tmp = fromHexCode(ch)) >= 0) { 6324 + hexResult = (hexResult << 4) + tmp; 6325 + 6326 + } else { 6327 + throwError(state, 'expected hexadecimal character'); 6328 + } 6329 + } 6330 + 6331 + state.result += charFromCodepoint(hexResult); 6332 + 6333 + state.position++; 6334 + 6335 + } else { 6336 + throwError(state, 'unknown escape sequence'); 6337 + } 6338 + 6339 + captureStart = captureEnd = state.position; 6340 + 6341 + } else if (is_EOL(ch)) { 6342 + captureSegment(state, captureStart, captureEnd, true); 6343 + writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); 6344 + captureStart = captureEnd = state.position; 6345 + 6346 + } else if (state.position === state.lineStart && testDocumentSeparator(state)) { 6347 + throwError(state, 'unexpected end of the document within a double quoted scalar'); 6348 + 6349 + } else { 6350 + state.position++; 6351 + captureEnd = state.position; 6352 + } 6353 + } 6354 + 6355 + throwError(state, 'unexpected end of the stream within a double quoted scalar'); 6356 + } 6357 + 6358 + function readFlowCollection(state, nodeIndent) { 6359 + var readNext = true, 6360 + _line, 6361 + _lineStart, 6362 + _pos, 6363 + _tag = state.tag, 6364 + _result, 6365 + _anchor = state.anchor, 6366 + following, 6367 + terminator, 6368 + isPair, 6369 + isExplicitPair, 6370 + isMapping, 6371 + overridableKeys = Object.create(null), 6372 + keyNode, 6373 + keyTag, 6374 + valueNode, 6375 + ch; 6376 + 6377 + ch = state.input.charCodeAt(state.position); 6378 + 6379 + if (ch === 0x5B/* [ */) { 6380 + terminator = 0x5D;/* ] */ 6381 + isMapping = false; 6382 + _result = []; 6383 + } else if (ch === 0x7B/* { */) { 6384 + terminator = 0x7D;/* } */ 6385 + isMapping = true; 6386 + _result = {}; 6387 + } else { 6388 + return false; 6389 + } 6390 + 6391 + if (state.anchor !== null) { 6392 + state.anchorMap[state.anchor] = _result; 6393 + } 6394 + 6395 + ch = state.input.charCodeAt(++state.position); 6396 + 6397 + while (ch !== 0) { 6398 + skipSeparationSpace(state, true, nodeIndent); 6399 + 6400 + ch = state.input.charCodeAt(state.position); 6401 + 6402 + if (ch === terminator) { 6403 + state.position++; 6404 + state.tag = _tag; 6405 + state.anchor = _anchor; 6406 + state.kind = isMapping ? 'mapping' : 'sequence'; 6407 + state.result = _result; 6408 + return true; 6409 + } else if (!readNext) { 6410 + throwError(state, 'missed comma between flow collection entries'); 6411 + } else if (ch === 0x2C/* , */) { 6412 + // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4 6413 + throwError(state, "expected the node content, but found ','"); 6414 + } 6415 + 6416 + keyTag = keyNode = valueNode = null; 6417 + isPair = isExplicitPair = false; 6418 + 6419 + if (ch === 0x3F/* ? */) { 6420 + following = state.input.charCodeAt(state.position + 1); 6421 + 6422 + if (is_WS_OR_EOL(following)) { 6423 + isPair = isExplicitPair = true; 6424 + state.position++; 6425 + skipSeparationSpace(state, true, nodeIndent); 6426 + } 6427 + } 6428 + 6429 + _line = state.line; // Save the current line. 6430 + _lineStart = state.lineStart; 6431 + _pos = state.position; 6432 + composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); 6433 + keyTag = state.tag; 6434 + keyNode = state.result; 6435 + skipSeparationSpace(state, true, nodeIndent); 6436 + 6437 + ch = state.input.charCodeAt(state.position); 6438 + 6439 + if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) { 6440 + isPair = true; 6441 + ch = state.input.charCodeAt(++state.position); 6442 + skipSeparationSpace(state, true, nodeIndent); 6443 + composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); 6444 + valueNode = state.result; 6445 + } 6446 + 6447 + if (isMapping) { 6448 + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos); 6449 + } else if (isPair) { 6450 + _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)); 6451 + } else { 6452 + _result.push(keyNode); 6453 + } 6454 + 6455 + skipSeparationSpace(state, true, nodeIndent); 6456 + 6457 + ch = state.input.charCodeAt(state.position); 6458 + 6459 + if (ch === 0x2C/* , */) { 6460 + readNext = true; 6461 + ch = state.input.charCodeAt(++state.position); 6462 + } else { 6463 + readNext = false; 6464 + } 6465 + } 6466 + 6467 + throwError(state, 'unexpected end of the stream within a flow collection'); 6468 + } 6469 + 6470 + function readBlockScalar(state, nodeIndent) { 6471 + var captureStart, 6472 + folding, 6473 + chomping = CHOMPING_CLIP, 6474 + didReadContent = false, 6475 + detectedIndent = false, 6476 + textIndent = nodeIndent, 6477 + emptyLines = 0, 6478 + atMoreIndented = false, 6479 + tmp, 6480 + ch; 6481 + 6482 + ch = state.input.charCodeAt(state.position); 6483 + 6484 + if (ch === 0x7C/* | */) { 6485 + folding = false; 6486 + } else if (ch === 0x3E/* > */) { 6487 + folding = true; 6488 + } else { 6489 + return false; 6490 + } 6491 + 6492 + state.kind = 'scalar'; 6493 + state.result = ''; 6494 + 6495 + while (ch !== 0) { 6496 + ch = state.input.charCodeAt(++state.position); 6497 + 6498 + if (ch === 0x2B/* + */ || ch === 0x2D/* - */) { 6499 + if (CHOMPING_CLIP === chomping) { 6500 + chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP; 6501 + } else { 6502 + throwError(state, 'repeat of a chomping mode identifier'); 6503 + } 6504 + 6505 + } else if ((tmp = fromDecimalCode(ch)) >= 0) { 6506 + if (tmp === 0) { 6507 + throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one'); 6508 + } else if (!detectedIndent) { 6509 + textIndent = nodeIndent + tmp - 1; 6510 + detectedIndent = true; 6511 + } else { 6512 + throwError(state, 'repeat of an indentation width identifier'); 6513 + } 6514 + 6515 + } else { 6516 + break; 6517 + } 6518 + } 6519 + 6520 + if (is_WHITE_SPACE(ch)) { 6521 + do { ch = state.input.charCodeAt(++state.position); } 6522 + while (is_WHITE_SPACE(ch)); 6523 + 6524 + if (ch === 0x23/* # */) { 6525 + do { ch = state.input.charCodeAt(++state.position); } 6526 + while (!is_EOL(ch) && (ch !== 0)); 6527 + } 6528 + } 6529 + 6530 + while (ch !== 0) { 6531 + readLineBreak(state); 6532 + state.lineIndent = 0; 6533 + 6534 + ch = state.input.charCodeAt(state.position); 6535 + 6536 + while ((!detectedIndent || state.lineIndent < textIndent) && 6537 + (ch === 0x20/* Space */)) { 6538 + state.lineIndent++; 6539 + ch = state.input.charCodeAt(++state.position); 6540 + } 6541 + 6542 + if (!detectedIndent && state.lineIndent > textIndent) { 6543 + textIndent = state.lineIndent; 6544 + } 6545 + 6546 + if (is_EOL(ch)) { 6547 + emptyLines++; 6548 + continue; 6549 + } 6550 + 6551 + // End of the scalar. 6552 + if (state.lineIndent < textIndent) { 6553 + 6554 + // Perform the chomping. 6555 + if (chomping === CHOMPING_KEEP) { 6556 + state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); 6557 + } else if (chomping === CHOMPING_CLIP) { 6558 + if (didReadContent) { // i.e. only if the scalar is not empty. 6559 + state.result += '\n'; 6560 + } 6561 + } 6562 + 6563 + // Break this `while` cycle and go to the funciton's epilogue. 6564 + break; 6565 + } 6566 + 6567 + // Folded style: use fancy rules to handle line breaks. 6568 + if (folding) { 6569 + 6570 + // Lines starting with white space characters (more-indented lines) are not folded. 6571 + if (is_WHITE_SPACE(ch)) { 6572 + atMoreIndented = true; 6573 + // except for the first content line (cf. Example 8.1) 6574 + state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); 6575 + 6576 + // End of more-indented block. 6577 + } else if (atMoreIndented) { 6578 + atMoreIndented = false; 6579 + state.result += common.repeat('\n', emptyLines + 1); 6580 + 6581 + // Just one line break - perceive as the same line. 6582 + } else if (emptyLines === 0) { 6583 + if (didReadContent) { // i.e. only if we have already read some scalar content. 6584 + state.result += ' '; 6585 + } 6586 + 6587 + // Several line breaks - perceive as different lines. 6588 + } else { 6589 + state.result += common.repeat('\n', emptyLines); 6590 + } 6591 + 6592 + // Literal style: just add exact number of line breaks between content lines. 6593 + } else { 6594 + // Keep all line breaks except the header line break. 6595 + state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); 6596 + } 6597 + 6598 + didReadContent = true; 6599 + detectedIndent = true; 6600 + emptyLines = 0; 6601 + captureStart = state.position; 6602 + 6603 + while (!is_EOL(ch) && (ch !== 0)) { 6604 + ch = state.input.charCodeAt(++state.position); 6605 + } 6606 + 6607 + captureSegment(state, captureStart, state.position, false); 6608 + } 6609 + 6610 + return true; 6611 + } 6612 + 6613 + function readBlockSequence(state, nodeIndent) { 6614 + var _line, 6615 + _tag = state.tag, 6616 + _anchor = state.anchor, 6617 + _result = [], 6618 + following, 6619 + detected = false, 6620 + ch; 6621 + 6622 + // there is a leading tab before this token, so it can't be a block sequence/mapping; 6623 + // it can still be flow sequence/mapping or a scalar 6624 + if (state.firstTabInLine !== -1) return false; 6625 + 6626 + if (state.anchor !== null) { 6627 + state.anchorMap[state.anchor] = _result; 6628 + } 6629 + 6630 + ch = state.input.charCodeAt(state.position); 6631 + 6632 + while (ch !== 0) { 6633 + if (state.firstTabInLine !== -1) { 6634 + state.position = state.firstTabInLine; 6635 + throwError(state, 'tab characters must not be used in indentation'); 6636 + } 6637 + 6638 + if (ch !== 0x2D/* - */) { 6639 + break; 6640 + } 6641 + 6642 + following = state.input.charCodeAt(state.position + 1); 6643 + 6644 + if (!is_WS_OR_EOL(following)) { 6645 + break; 6646 + } 6647 + 6648 + detected = true; 6649 + state.position++; 6650 + 6651 + if (skipSeparationSpace(state, true, -1)) { 6652 + if (state.lineIndent <= nodeIndent) { 6653 + _result.push(null); 6654 + ch = state.input.charCodeAt(state.position); 6655 + continue; 6656 + } 6657 + } 6658 + 6659 + _line = state.line; 6660 + composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true); 6661 + _result.push(state.result); 6662 + skipSeparationSpace(state, true, -1); 6663 + 6664 + ch = state.input.charCodeAt(state.position); 6665 + 6666 + if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) { 6667 + throwError(state, 'bad indentation of a sequence entry'); 6668 + } else if (state.lineIndent < nodeIndent) { 6669 + break; 6670 + } 6671 + } 6672 + 6673 + if (detected) { 6674 + state.tag = _tag; 6675 + state.anchor = _anchor; 6676 + state.kind = 'sequence'; 6677 + state.result = _result; 6678 + return true; 6679 + } 6680 + return false; 6681 + } 6682 + 6683 + function readBlockMapping(state, nodeIndent, flowIndent) { 6684 + var following, 6685 + allowCompact, 6686 + _line, 6687 + _keyLine, 6688 + _keyLineStart, 6689 + _keyPos, 6690 + _tag = state.tag, 6691 + _anchor = state.anchor, 6692 + _result = {}, 6693 + overridableKeys = Object.create(null), 6694 + keyTag = null, 6695 + keyNode = null, 6696 + valueNode = null, 6697 + atExplicitKey = false, 6698 + detected = false, 6699 + ch; 6700 + 6701 + // there is a leading tab before this token, so it can't be a block sequence/mapping; 6702 + // it can still be flow sequence/mapping or a scalar 6703 + if (state.firstTabInLine !== -1) return false; 6704 + 6705 + if (state.anchor !== null) { 6706 + state.anchorMap[state.anchor] = _result; 6707 + } 6708 + 6709 + ch = state.input.charCodeAt(state.position); 6710 + 6711 + while (ch !== 0) { 6712 + if (!atExplicitKey && state.firstTabInLine !== -1) { 6713 + state.position = state.firstTabInLine; 6714 + throwError(state, 'tab characters must not be used in indentation'); 6715 + } 6716 + 6717 + following = state.input.charCodeAt(state.position + 1); 6718 + _line = state.line; // Save the current line. 6719 + 6720 + // 6721 + // Explicit notation case. There are two separate blocks: 6722 + // first for the key (denoted by "?") and second for the value (denoted by ":") 6723 + // 6724 + if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) { 6725 + 6726 + if (ch === 0x3F/* ? */) { 6727 + if (atExplicitKey) { 6728 + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 6729 + keyTag = keyNode = valueNode = null; 6730 + } 6731 + 6732 + detected = true; 6733 + atExplicitKey = true; 6734 + allowCompact = true; 6735 + 6736 + } else if (atExplicitKey) { 6737 + // i.e. 0x3A/* : */ === character after the explicit key. 6738 + atExplicitKey = false; 6739 + allowCompact = true; 6740 + 6741 + } else { 6742 + throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line'); 6743 + } 6744 + 6745 + state.position += 1; 6746 + ch = following; 6747 + 6748 + // 6749 + // Implicit notation case. Flow-style node as the key first, then ":", and the value. 6750 + // 6751 + } else { 6752 + _keyLine = state.line; 6753 + _keyLineStart = state.lineStart; 6754 + _keyPos = state.position; 6755 + 6756 + if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { 6757 + // Neither implicit nor explicit notation. 6758 + // Reading is done. Go to the epilogue. 6759 + break; 6760 + } 6761 + 6762 + if (state.line === _line) { 6763 + ch = state.input.charCodeAt(state.position); 6764 + 6765 + while (is_WHITE_SPACE(ch)) { 6766 + ch = state.input.charCodeAt(++state.position); 6767 + } 6768 + 6769 + if (ch === 0x3A/* : */) { 6770 + ch = state.input.charCodeAt(++state.position); 6771 + 6772 + if (!is_WS_OR_EOL(ch)) { 6773 + throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping'); 6774 + } 6775 + 6776 + if (atExplicitKey) { 6777 + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 6778 + keyTag = keyNode = valueNode = null; 6779 + } 6780 + 6781 + detected = true; 6782 + atExplicitKey = false; 6783 + allowCompact = false; 6784 + keyTag = state.tag; 6785 + keyNode = state.result; 6786 + 6787 + } else if (detected) { 6788 + throwError(state, 'can not read an implicit mapping pair; a colon is missed'); 6789 + 6790 + } else { 6791 + state.tag = _tag; 6792 + state.anchor = _anchor; 6793 + return true; // Keep the result of `composeNode`. 6794 + } 6795 + 6796 + } else if (detected) { 6797 + throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key'); 6798 + 6799 + } else { 6800 + state.tag = _tag; 6801 + state.anchor = _anchor; 6802 + return true; // Keep the result of `composeNode`. 6803 + } 6804 + } 6805 + 6806 + // 6807 + // Common reading code for both explicit and implicit notations. 6808 + // 6809 + if (state.line === _line || state.lineIndent > nodeIndent) { 6810 + if (atExplicitKey) { 6811 + _keyLine = state.line; 6812 + _keyLineStart = state.lineStart; 6813 + _keyPos = state.position; 6814 + } 6815 + 6816 + if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { 6817 + if (atExplicitKey) { 6818 + keyNode = state.result; 6819 + } else { 6820 + valueNode = state.result; 6821 + } 6822 + } 6823 + 6824 + if (!atExplicitKey) { 6825 + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos); 6826 + keyTag = keyNode = valueNode = null; 6827 + } 6828 + 6829 + skipSeparationSpace(state, true, -1); 6830 + ch = state.input.charCodeAt(state.position); 6831 + } 6832 + 6833 + if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) { 6834 + throwError(state, 'bad indentation of a mapping entry'); 6835 + } else if (state.lineIndent < nodeIndent) { 6836 + break; 6837 + } 6838 + } 6839 + 6840 + // 6841 + // Epilogue. 6842 + // 6843 + 6844 + // Special case: last mapping's node contains only the key in explicit notation. 6845 + if (atExplicitKey) { 6846 + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); 6847 + } 6848 + 6849 + // Expose the resulting mapping. 6850 + if (detected) { 6851 + state.tag = _tag; 6852 + state.anchor = _anchor; 6853 + state.kind = 'mapping'; 6854 + state.result = _result; 6855 + } 6856 + 6857 + return detected; 6858 + } 6859 + 6860 + function readTagProperty(state) { 6861 + var _position, 6862 + isVerbatim = false, 6863 + isNamed = false, 6864 + tagHandle, 6865 + tagName, 6866 + ch; 6867 + 6868 + ch = state.input.charCodeAt(state.position); 6869 + 6870 + if (ch !== 0x21/* ! */) return false; 6871 + 6872 + if (state.tag !== null) { 6873 + throwError(state, 'duplication of a tag property'); 6874 + } 6875 + 6876 + ch = state.input.charCodeAt(++state.position); 6877 + 6878 + if (ch === 0x3C/* < */) { 6879 + isVerbatim = true; 6880 + ch = state.input.charCodeAt(++state.position); 6881 + 6882 + } else if (ch === 0x21/* ! */) { 6883 + isNamed = true; 6884 + tagHandle = '!!'; 6885 + ch = state.input.charCodeAt(++state.position); 6886 + 6887 + } else { 6888 + tagHandle = '!'; 6889 + } 6890 + 6891 + _position = state.position; 6892 + 6893 + if (isVerbatim) { 6894 + do { ch = state.input.charCodeAt(++state.position); } 6895 + while (ch !== 0 && ch !== 0x3E/* > */); 6896 + 6897 + if (state.position < state.length) { 6898 + tagName = state.input.slice(_position, state.position); 6899 + ch = state.input.charCodeAt(++state.position); 6900 + } else { 6901 + throwError(state, 'unexpected end of the stream within a verbatim tag'); 6902 + } 6903 + } else { 6904 + while (ch !== 0 && !is_WS_OR_EOL(ch)) { 6905 + 6906 + if (ch === 0x21/* ! */) { 6907 + if (!isNamed) { 6908 + tagHandle = state.input.slice(_position - 1, state.position + 1); 6909 + 6910 + if (!PATTERN_TAG_HANDLE.test(tagHandle)) { 6911 + throwError(state, 'named tag handle cannot contain such characters'); 6912 + } 6913 + 6914 + isNamed = true; 6915 + _position = state.position + 1; 6916 + } else { 6917 + throwError(state, 'tag suffix cannot contain exclamation marks'); 6918 + } 6919 + } 6920 + 6921 + ch = state.input.charCodeAt(++state.position); 6922 + } 6923 + 6924 + tagName = state.input.slice(_position, state.position); 6925 + 6926 + if (PATTERN_FLOW_INDICATORS.test(tagName)) { 6927 + throwError(state, 'tag suffix cannot contain flow indicator characters'); 6928 + } 6929 + } 6930 + 6931 + if (tagName && !PATTERN_TAG_URI.test(tagName)) { 6932 + throwError(state, 'tag name cannot contain such characters: ' + tagName); 6933 + } 6934 + 6935 + try { 6936 + tagName = decodeURIComponent(tagName); 6937 + } catch (err) { 6938 + throwError(state, 'tag name is malformed: ' + tagName); 6939 + } 6940 + 6941 + if (isVerbatim) { 6942 + state.tag = tagName; 6943 + 6944 + } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) { 6945 + state.tag = state.tagMap[tagHandle] + tagName; 6946 + 6947 + } else if (tagHandle === '!') { 6948 + state.tag = '!' + tagName; 6949 + 6950 + } else if (tagHandle === '!!') { 6951 + state.tag = 'tag:yaml.org,2002:' + tagName; 6952 + 6953 + } else { 6954 + throwError(state, 'undeclared tag handle "' + tagHandle + '"'); 6955 + } 6956 + 6957 + return true; 6958 + } 6959 + 6960 + function readAnchorProperty(state) { 6961 + var _position, 6962 + ch; 6963 + 6964 + ch = state.input.charCodeAt(state.position); 6965 + 6966 + if (ch !== 0x26/* & */) return false; 6967 + 6968 + if (state.anchor !== null) { 6969 + throwError(state, 'duplication of an anchor property'); 6970 + } 6971 + 6972 + ch = state.input.charCodeAt(++state.position); 6973 + _position = state.position; 6974 + 6975 + while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) { 6976 + ch = state.input.charCodeAt(++state.position); 6977 + } 6978 + 6979 + if (state.position === _position) { 6980 + throwError(state, 'name of an anchor node must contain at least one character'); 6981 + } 6982 + 6983 + state.anchor = state.input.slice(_position, state.position); 6984 + return true; 6985 + } 6986 + 6987 + function readAlias(state) { 6988 + var _position, alias, 6989 + ch; 6990 + 6991 + ch = state.input.charCodeAt(state.position); 6992 + 6993 + if (ch !== 0x2A/* * */) return false; 6994 + 6995 + ch = state.input.charCodeAt(++state.position); 6996 + _position = state.position; 6997 + 6998 + while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) { 6999 + ch = state.input.charCodeAt(++state.position); 7000 + } 7001 + 7002 + if (state.position === _position) { 7003 + throwError(state, 'name of an alias node must contain at least one character'); 7004 + } 7005 + 7006 + alias = state.input.slice(_position, state.position); 7007 + 7008 + if (!_hasOwnProperty$1.call(state.anchorMap, alias)) { 7009 + throwError(state, 'unidentified alias "' + alias + '"'); 7010 + } 7011 + 7012 + state.result = state.anchorMap[alias]; 7013 + skipSeparationSpace(state, true, -1); 7014 + return true; 7015 + } 7016 + 7017 + function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) { 7018 + var allowBlockStyles, 7019 + allowBlockScalars, 7020 + allowBlockCollections, 7021 + indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent 7022 + atNewLine = false, 7023 + hasContent = false, 7024 + typeIndex, 7025 + typeQuantity, 7026 + typeList, 7027 + type, 7028 + flowIndent, 7029 + blockIndent; 7030 + 7031 + if (state.listener !== null) { 7032 + state.listener('open', state); 7033 + } 7034 + 7035 + state.tag = null; 7036 + state.anchor = null; 7037 + state.kind = null; 7038 + state.result = null; 7039 + 7040 + allowBlockStyles = allowBlockScalars = allowBlockCollections = 7041 + CONTEXT_BLOCK_OUT === nodeContext || 7042 + CONTEXT_BLOCK_IN === nodeContext; 7043 + 7044 + if (allowToSeek) { 7045 + if (skipSeparationSpace(state, true, -1)) { 7046 + atNewLine = true; 7047 + 7048 + if (state.lineIndent > parentIndent) { 7049 + indentStatus = 1; 7050 + } else if (state.lineIndent === parentIndent) { 7051 + indentStatus = 0; 7052 + } else if (state.lineIndent < parentIndent) { 7053 + indentStatus = -1; 7054 + } 7055 + } 7056 + } 7057 + 7058 + if (indentStatus === 1) { 7059 + while (readTagProperty(state) || readAnchorProperty(state)) { 7060 + if (skipSeparationSpace(state, true, -1)) { 7061 + atNewLine = true; 7062 + allowBlockCollections = allowBlockStyles; 7063 + 7064 + if (state.lineIndent > parentIndent) { 7065 + indentStatus = 1; 7066 + } else if (state.lineIndent === parentIndent) { 7067 + indentStatus = 0; 7068 + } else if (state.lineIndent < parentIndent) { 7069 + indentStatus = -1; 7070 + } 7071 + } else { 7072 + allowBlockCollections = false; 7073 + } 7074 + } 7075 + } 7076 + 7077 + if (allowBlockCollections) { 7078 + allowBlockCollections = atNewLine || allowCompact; 7079 + } 7080 + 7081 + if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) { 7082 + if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) { 7083 + flowIndent = parentIndent; 7084 + } else { 7085 + flowIndent = parentIndent + 1; 7086 + } 7087 + 7088 + blockIndent = state.position - state.lineStart; 7089 + 7090 + if (indentStatus === 1) { 7091 + if (allowBlockCollections && 7092 + (readBlockSequence(state, blockIndent) || 7093 + readBlockMapping(state, blockIndent, flowIndent)) || 7094 + readFlowCollection(state, flowIndent)) { 7095 + hasContent = true; 7096 + } else { 7097 + if ((allowBlockScalars && readBlockScalar(state, flowIndent)) || 7098 + readSingleQuotedScalar(state, flowIndent) || 7099 + readDoubleQuotedScalar(state, flowIndent)) { 7100 + hasContent = true; 7101 + 7102 + } else if (readAlias(state)) { 7103 + hasContent = true; 7104 + 7105 + if (state.tag !== null || state.anchor !== null) { 7106 + throwError(state, 'alias node should not have any properties'); 7107 + } 7108 + 7109 + } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) { 7110 + hasContent = true; 7111 + 7112 + if (state.tag === null) { 7113 + state.tag = '?'; 7114 + } 7115 + } 7116 + 7117 + if (state.anchor !== null) { 7118 + state.anchorMap[state.anchor] = state.result; 7119 + } 7120 + } 7121 + } else if (indentStatus === 0) { 7122 + // Special case: block sequences are allowed to have same indentation level as the parent. 7123 + // http://www.yaml.org/spec/1.2/spec.html#id2799784 7124 + hasContent = allowBlockCollections && readBlockSequence(state, blockIndent); 7125 + } 7126 + } 7127 + 7128 + if (state.tag === null) { 7129 + if (state.anchor !== null) { 7130 + state.anchorMap[state.anchor] = state.result; 7131 + } 7132 + 7133 + } else if (state.tag === '?') { 7134 + // Implicit resolving is not allowed for non-scalar types, and '?' 7135 + // non-specific tag is only automatically assigned to plain scalars. 7136 + // 7137 + // We only need to check kind conformity in case user explicitly assigns '?' 7138 + // tag, for example like this: "!<?> [0]" 7139 + // 7140 + if (state.result !== null && state.kind !== 'scalar') { 7141 + throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"'); 7142 + } 7143 + 7144 + for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { 7145 + type = state.implicitTypes[typeIndex]; 7146 + 7147 + if (type.resolve(state.result)) { // `state.result` updated in resolver if matched 7148 + state.result = type.construct(state.result); 7149 + state.tag = type.tag; 7150 + if (state.anchor !== null) { 7151 + state.anchorMap[state.anchor] = state.result; 7152 + } 7153 + break; 7154 + } 7155 + } 7156 + } else if (state.tag !== '!') { 7157 + if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) { 7158 + type = state.typeMap[state.kind || 'fallback'][state.tag]; 7159 + } else { 7160 + // looking for multi type 7161 + type = null; 7162 + typeList = state.typeMap.multi[state.kind || 'fallback']; 7163 + 7164 + for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) { 7165 + if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) { 7166 + type = typeList[typeIndex]; 7167 + break; 7168 + } 7169 + } 7170 + } 7171 + 7172 + if (!type) { 7173 + throwError(state, 'unknown tag !<' + state.tag + '>'); 7174 + } 7175 + 7176 + if (state.result !== null && type.kind !== state.kind) { 7177 + throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); 7178 + } 7179 + 7180 + if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched 7181 + throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag'); 7182 + } else { 7183 + state.result = type.construct(state.result, state.tag); 7184 + if (state.anchor !== null) { 7185 + state.anchorMap[state.anchor] = state.result; 7186 + } 7187 + } 7188 + } 7189 + 7190 + if (state.listener !== null) { 7191 + state.listener('close', state); 7192 + } 7193 + return state.tag !== null || state.anchor !== null || hasContent; 7194 + } 7195 + 7196 + function readDocument(state) { 7197 + var documentStart = state.position, 7198 + _position, 7199 + directiveName, 7200 + directiveArgs, 7201 + hasDirectives = false, 7202 + ch; 7203 + 7204 + state.version = null; 7205 + state.checkLineBreaks = state.legacy; 7206 + state.tagMap = Object.create(null); 7207 + state.anchorMap = Object.create(null); 7208 + 7209 + while ((ch = state.input.charCodeAt(state.position)) !== 0) { 7210 + skipSeparationSpace(state, true, -1); 7211 + 7212 + ch = state.input.charCodeAt(state.position); 7213 + 7214 + if (state.lineIndent > 0 || ch !== 0x25/* % */) { 7215 + break; 7216 + } 7217 + 7218 + hasDirectives = true; 7219 + ch = state.input.charCodeAt(++state.position); 7220 + _position = state.position; 7221 + 7222 + while (ch !== 0 && !is_WS_OR_EOL(ch)) { 7223 + ch = state.input.charCodeAt(++state.position); 7224 + } 7225 + 7226 + directiveName = state.input.slice(_position, state.position); 7227 + directiveArgs = []; 7228 + 7229 + if (directiveName.length < 1) { 7230 + throwError(state, 'directive name must not be less than one character in length'); 7231 + } 7232 + 7233 + while (ch !== 0) { 7234 + while (is_WHITE_SPACE(ch)) { 7235 + ch = state.input.charCodeAt(++state.position); 7236 + } 7237 + 7238 + if (ch === 0x23/* # */) { 7239 + do { ch = state.input.charCodeAt(++state.position); } 7240 + while (ch !== 0 && !is_EOL(ch)); 7241 + break; 7242 + } 7243 + 7244 + if (is_EOL(ch)) break; 7245 + 7246 + _position = state.position; 7247 + 7248 + while (ch !== 0 && !is_WS_OR_EOL(ch)) { 7249 + ch = state.input.charCodeAt(++state.position); 7250 + } 7251 + 7252 + directiveArgs.push(state.input.slice(_position, state.position)); 7253 + } 7254 + 7255 + if (ch !== 0) readLineBreak(state); 7256 + 7257 + if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) { 7258 + directiveHandlers[directiveName](state, directiveName, directiveArgs); 7259 + } else { 7260 + throwWarning(state, 'unknown document directive "' + directiveName + '"'); 7261 + } 7262 + } 7263 + 7264 + skipSeparationSpace(state, true, -1); 7265 + 7266 + if (state.lineIndent === 0 && 7267 + state.input.charCodeAt(state.position) === 0x2D/* - */ && 7268 + state.input.charCodeAt(state.position + 1) === 0x2D/* - */ && 7269 + state.input.charCodeAt(state.position + 2) === 0x2D/* - */) { 7270 + state.position += 3; 7271 + skipSeparationSpace(state, true, -1); 7272 + 7273 + } else if (hasDirectives) { 7274 + throwError(state, 'directives end mark is expected'); 7275 + } 7276 + 7277 + composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true); 7278 + skipSeparationSpace(state, true, -1); 7279 + 7280 + if (state.checkLineBreaks && 7281 + PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) { 7282 + throwWarning(state, 'non-ASCII line breaks are interpreted as content'); 7283 + } 7284 + 7285 + state.documents.push(state.result); 7286 + 7287 + if (state.position === state.lineStart && testDocumentSeparator(state)) { 7288 + 7289 + if (state.input.charCodeAt(state.position) === 0x2E/* . */) { 7290 + state.position += 3; 7291 + skipSeparationSpace(state, true, -1); 7292 + } 7293 + return; 7294 + } 7295 + 7296 + if (state.position < (state.length - 1)) { 7297 + throwError(state, 'end of the stream or a document separator is expected'); 7298 + } else { 7299 + return; 7300 + } 7301 + } 7302 + 7303 + 7304 + function loadDocuments(input, options) { 7305 + input = String(input); 7306 + options = options || {}; 7307 + 7308 + if (input.length !== 0) { 7309 + 7310 + // Add tailing `\n` if not exists 7311 + if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ && 7312 + input.charCodeAt(input.length - 1) !== 0x0D/* CR */) { 7313 + input += '\n'; 7314 + } 7315 + 7316 + // Strip BOM 7317 + if (input.charCodeAt(0) === 0xFEFF) { 7318 + input = input.slice(1); 7319 + } 7320 + } 7321 + 7322 + var state = new State$1(input, options); 7323 + 7324 + var nullpos = input.indexOf('\0'); 7325 + 7326 + if (nullpos !== -1) { 7327 + state.position = nullpos; 7328 + throwError(state, 'null byte is not allowed in input'); 7329 + } 7330 + 7331 + // Use 0 as string terminator. That significantly simplifies bounds check. 7332 + state.input += '\0'; 7333 + 7334 + while (state.input.charCodeAt(state.position) === 0x20/* Space */) { 7335 + state.lineIndent += 1; 7336 + state.position += 1; 7337 + } 7338 + 7339 + while (state.position < (state.length - 1)) { 7340 + readDocument(state); 7341 + } 7342 + 7343 + return state.documents; 7344 + } 7345 + 7346 + 7347 + function loadAll$1(input, iterator, options) { 7348 + if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') { 7349 + options = iterator; 7350 + iterator = null; 7351 + } 7352 + 7353 + var documents = loadDocuments(input, options); 7354 + 7355 + if (typeof iterator !== 'function') { 7356 + return documents; 7357 + } 7358 + 7359 + for (var index = 0, length = documents.length; index < length; index += 1) { 7360 + iterator(documents[index]); 7361 + } 7362 + } 7363 + 7364 + 7365 + function load$1(input, options) { 7366 + var documents = loadDocuments(input, options); 7367 + 7368 + if (documents.length === 0) { 7369 + /*eslint-disable no-undefined*/ 7370 + return undefined; 7371 + } else if (documents.length === 1) { 7372 + return documents[0]; 7373 + } 7374 + throw new exception('expected a single document in the stream, but found more'); 7375 + } 7376 + 7377 + 7378 + var loadAll_1 = loadAll$1; 7379 + var load_1 = load$1; 7380 + 7381 + var loader = { 7382 + loadAll: loadAll_1, 7383 + load: load_1 7384 + }; 7385 + 7386 + /*eslint-disable no-use-before-define*/ 7387 + 7388 + 7389 + 7390 + 7391 + 7392 + var _toString = Object.prototype.toString; 7393 + var _hasOwnProperty = Object.prototype.hasOwnProperty; 7394 + 7395 + var CHAR_BOM = 0xFEFF; 7396 + var CHAR_TAB = 0x09; /* Tab */ 7397 + var CHAR_LINE_FEED = 0x0A; /* LF */ 7398 + var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */ 7399 + var CHAR_SPACE = 0x20; /* Space */ 7400 + var CHAR_EXCLAMATION = 0x21; /* ! */ 7401 + var CHAR_DOUBLE_QUOTE = 0x22; /* " */ 7402 + var CHAR_SHARP = 0x23; /* # */ 7403 + var CHAR_PERCENT = 0x25; /* % */ 7404 + var CHAR_AMPERSAND = 0x26; /* & */ 7405 + var CHAR_SINGLE_QUOTE = 0x27; /* ' */ 7406 + var CHAR_ASTERISK = 0x2A; /* * */ 7407 + var CHAR_COMMA = 0x2C; /* , */ 7408 + var CHAR_MINUS = 0x2D; /* - */ 7409 + var CHAR_COLON = 0x3A; /* : */ 7410 + var CHAR_EQUALS = 0x3D; /* = */ 7411 + var CHAR_GREATER_THAN = 0x3E; /* > */ 7412 + var CHAR_QUESTION = 0x3F; /* ? */ 7413 + var CHAR_COMMERCIAL_AT = 0x40; /* @ */ 7414 + var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */ 7415 + var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */ 7416 + var CHAR_GRAVE_ACCENT = 0x60; /* ` */ 7417 + var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */ 7418 + var CHAR_VERTICAL_LINE = 0x7C; /* | */ 7419 + var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */ 7420 + 7421 + var ESCAPE_SEQUENCES = {}; 7422 + 7423 + ESCAPE_SEQUENCES[0x00] = '\\0'; 7424 + ESCAPE_SEQUENCES[0x07] = '\\a'; 7425 + ESCAPE_SEQUENCES[0x08] = '\\b'; 7426 + ESCAPE_SEQUENCES[0x09] = '\\t'; 7427 + ESCAPE_SEQUENCES[0x0A] = '\\n'; 7428 + ESCAPE_SEQUENCES[0x0B] = '\\v'; 7429 + ESCAPE_SEQUENCES[0x0C] = '\\f'; 7430 + ESCAPE_SEQUENCES[0x0D] = '\\r'; 7431 + ESCAPE_SEQUENCES[0x1B] = '\\e'; 7432 + ESCAPE_SEQUENCES[0x22] = '\\"'; 7433 + ESCAPE_SEQUENCES[0x5C] = '\\\\'; 7434 + ESCAPE_SEQUENCES[0x85] = '\\N'; 7435 + ESCAPE_SEQUENCES[0xA0] = '\\_'; 7436 + ESCAPE_SEQUENCES[0x2028] = '\\L'; 7437 + ESCAPE_SEQUENCES[0x2029] = '\\P'; 7438 + 7439 + var DEPRECATED_BOOLEANS_SYNTAX = [ 7440 + 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON', 7441 + 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF' 7442 + ]; 7443 + 7444 + var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/; 7445 + 7446 + function compileStyleMap(schema, map) { 7447 + var result, keys, index, length, tag, style, type; 7448 + 7449 + if (map === null) return {}; 7450 + 7451 + result = {}; 7452 + keys = Object.keys(map); 7453 + 7454 + for (index = 0, length = keys.length; index < length; index += 1) { 7455 + tag = keys[index]; 7456 + style = String(map[tag]); 7457 + 7458 + if (tag.slice(0, 2) === '!!') { 7459 + tag = 'tag:yaml.org,2002:' + tag.slice(2); 7460 + } 7461 + type = schema.compiledTypeMap['fallback'][tag]; 7462 + 7463 + if (type && _hasOwnProperty.call(type.styleAliases, style)) { 7464 + style = type.styleAliases[style]; 7465 + } 7466 + 7467 + result[tag] = style; 7468 + } 7469 + 7470 + return result; 7471 + } 7472 + 7473 + function encodeHex(character) { 7474 + var string, handle, length; 7475 + 7476 + string = character.toString(16).toUpperCase(); 7477 + 7478 + if (character <= 0xFF) { 7479 + handle = 'x'; 7480 + length = 2; 7481 + } else if (character <= 0xFFFF) { 7482 + handle = 'u'; 7483 + length = 4; 7484 + } else if (character <= 0xFFFFFFFF) { 7485 + handle = 'U'; 7486 + length = 8; 7487 + } else { 7488 + throw new exception('code point within a string may not be greater than 0xFFFFFFFF'); 7489 + } 7490 + 7491 + return '\\' + handle + common.repeat('0', length - string.length) + string; 7492 + } 7493 + 7494 + 7495 + var QUOTING_TYPE_SINGLE = 1, 7496 + QUOTING_TYPE_DOUBLE = 2; 7497 + 7498 + function State(options) { 7499 + this.schema = options['schema'] || _default; 7500 + this.indent = Math.max(1, (options['indent'] || 2)); 7501 + this.noArrayIndent = options['noArrayIndent'] || false; 7502 + this.skipInvalid = options['skipInvalid'] || false; 7503 + this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']); 7504 + this.styleMap = compileStyleMap(this.schema, options['styles'] || null); 7505 + this.sortKeys = options['sortKeys'] || false; 7506 + this.lineWidth = options['lineWidth'] || 80; 7507 + this.noRefs = options['noRefs'] || false; 7508 + this.noCompatMode = options['noCompatMode'] || false; 7509 + this.condenseFlow = options['condenseFlow'] || false; 7510 + this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE; 7511 + this.forceQuotes = options['forceQuotes'] || false; 7512 + this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null; 7513 + 7514 + this.implicitTypes = this.schema.compiledImplicit; 7515 + this.explicitTypes = this.schema.compiledExplicit; 7516 + 7517 + this.tag = null; 7518 + this.result = ''; 7519 + 7520 + this.duplicates = []; 7521 + this.usedDuplicates = null; 7522 + } 7523 + 7524 + // Indents every line in a string. Empty lines (\n only) are not indented. 7525 + function indentString(string, spaces) { 7526 + var ind = common.repeat(' ', spaces), 7527 + position = 0, 7528 + next = -1, 7529 + result = '', 7530 + line, 7531 + length = string.length; 7532 + 7533 + while (position < length) { 7534 + next = string.indexOf('\n', position); 7535 + if (next === -1) { 7536 + line = string.slice(position); 7537 + position = length; 7538 + } else { 7539 + line = string.slice(position, next + 1); 7540 + position = next + 1; 7541 + } 7542 + 7543 + if (line.length && line !== '\n') result += ind; 7544 + 7545 + result += line; 7546 + } 7547 + 7548 + return result; 7549 + } 7550 + 7551 + function generateNextLine(state, level) { 7552 + return '\n' + common.repeat(' ', state.indent * level); 7553 + } 7554 + 7555 + function testImplicitResolving(state, str) { 7556 + var index, length, type; 7557 + 7558 + for (index = 0, length = state.implicitTypes.length; index < length; index += 1) { 7559 + type = state.implicitTypes[index]; 7560 + 7561 + if (type.resolve(str)) { 7562 + return true; 7563 + } 7564 + } 7565 + 7566 + return false; 7567 + } 7568 + 7569 + // [33] s-white ::= s-space | s-tab 7570 + function isWhitespace(c) { 7571 + return c === CHAR_SPACE || c === CHAR_TAB; 7572 + } 7573 + 7574 + // Returns true if the character can be printed without escaping. 7575 + // From YAML 1.2: "any allowed characters known to be non-printable 7576 + // should also be escaped. [However,] This isn’t mandatory" 7577 + // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029. 7578 + function isPrintable(c) { 7579 + return (0x00020 <= c && c <= 0x00007E) 7580 + || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029) 7581 + || ((0x0E000 <= c && c <= 0x00FFFD) && c !== CHAR_BOM) 7582 + || (0x10000 <= c && c <= 0x10FFFF); 7583 + } 7584 + 7585 + // [34] ns-char ::= nb-char - s-white 7586 + // [27] nb-char ::= c-printable - b-char - c-byte-order-mark 7587 + // [26] b-char ::= b-line-feed | b-carriage-return 7588 + // Including s-white (for some reason, examples doesn't match specs in this aspect) 7589 + // ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark 7590 + function isNsCharOrWhitespace(c) { 7591 + return isPrintable(c) 7592 + && c !== CHAR_BOM 7593 + // - b-char 7594 + && c !== CHAR_CARRIAGE_RETURN 7595 + && c !== CHAR_LINE_FEED; 7596 + } 7597 + 7598 + // [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out 7599 + // c = flow-in ⇒ ns-plain-safe-in 7600 + // c = block-key ⇒ ns-plain-safe-out 7601 + // c = flow-key ⇒ ns-plain-safe-in 7602 + // [128] ns-plain-safe-out ::= ns-char 7603 + // [129] ns-plain-safe-in ::= ns-char - c-flow-indicator 7604 + // [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” ) 7605 + // | ( /* An ns-char preceding */ “#” ) 7606 + // | ( “:” /* Followed by an ns-plain-safe(c) */ ) 7607 + function isPlainSafe(c, prev, inblock) { 7608 + var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c); 7609 + var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c); 7610 + return ( 7611 + // ns-plain-safe 7612 + inblock ? // c = flow-in 7613 + cIsNsCharOrWhitespace 7614 + : cIsNsCharOrWhitespace 7615 + // - c-flow-indicator 7616 + && c !== CHAR_COMMA 7617 + && c !== CHAR_LEFT_SQUARE_BRACKET 7618 + && c !== CHAR_RIGHT_SQUARE_BRACKET 7619 + && c !== CHAR_LEFT_CURLY_BRACKET 7620 + && c !== CHAR_RIGHT_CURLY_BRACKET 7621 + ) 7622 + // ns-plain-char 7623 + && c !== CHAR_SHARP // false on '#' 7624 + && !(prev === CHAR_COLON && !cIsNsChar) // false on ': ' 7625 + || (isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP) // change to true on '[^ ]#' 7626 + || (prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]' 7627 + } 7628 + 7629 + // Simplified test for values allowed as the first character in plain style. 7630 + function isPlainSafeFirst(c) { 7631 + // Uses a subset of ns-char - c-indicator 7632 + // where ns-char = nb-char - s-white. 7633 + // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part 7634 + return isPrintable(c) && c !== CHAR_BOM 7635 + && !isWhitespace(c) // - s-white 7636 + // - (c-indicator ::= 7637 + // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}” 7638 + && c !== CHAR_MINUS 7639 + && c !== CHAR_QUESTION 7640 + && c !== CHAR_COLON 7641 + && c !== CHAR_COMMA 7642 + && c !== CHAR_LEFT_SQUARE_BRACKET 7643 + && c !== CHAR_RIGHT_SQUARE_BRACKET 7644 + && c !== CHAR_LEFT_CURLY_BRACKET 7645 + && c !== CHAR_RIGHT_CURLY_BRACKET 7646 + // | “#” | “&” | “*” | “!” | “|” | “=” | “>” | “'” | “"” 7647 + && c !== CHAR_SHARP 7648 + && c !== CHAR_AMPERSAND 7649 + && c !== CHAR_ASTERISK 7650 + && c !== CHAR_EXCLAMATION 7651 + && c !== CHAR_VERTICAL_LINE 7652 + && c !== CHAR_EQUALS 7653 + && c !== CHAR_GREATER_THAN 7654 + && c !== CHAR_SINGLE_QUOTE 7655 + && c !== CHAR_DOUBLE_QUOTE 7656 + // | “%” | “@” | “`”) 7657 + && c !== CHAR_PERCENT 7658 + && c !== CHAR_COMMERCIAL_AT 7659 + && c !== CHAR_GRAVE_ACCENT; 7660 + } 7661 + 7662 + // Simplified test for values allowed as the last character in plain style. 7663 + function isPlainSafeLast(c) { 7664 + // just not whitespace or colon, it will be checked to be plain character later 7665 + return !isWhitespace(c) && c !== CHAR_COLON; 7666 + } 7667 + 7668 + // Same as 'string'.codePointAt(pos), but works in older browsers. 7669 + function codePointAt(string, pos) { 7670 + var first = string.charCodeAt(pos), second; 7671 + if (first >= 0xD800 && first <= 0xDBFF && pos + 1 < string.length) { 7672 + second = string.charCodeAt(pos + 1); 7673 + if (second >= 0xDC00 && second <= 0xDFFF) { 7674 + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae 7675 + return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; 7676 + } 7677 + } 7678 + return first; 7679 + } 7680 + 7681 + // Determines whether block indentation indicator is required. 7682 + function needIndentIndicator(string) { 7683 + var leadingSpaceRe = /^\n* /; 7684 + return leadingSpaceRe.test(string); 7685 + } 7686 + 7687 + var STYLE_PLAIN = 1, 7688 + STYLE_SINGLE = 2, 7689 + STYLE_LITERAL = 3, 7690 + STYLE_FOLDED = 4, 7691 + STYLE_DOUBLE = 5; 7692 + 7693 + // Determines which scalar styles are possible and returns the preferred style. 7694 + // lineWidth = -1 => no limit. 7695 + // Pre-conditions: str.length > 0. 7696 + // Post-conditions: 7697 + // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string. 7698 + // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1). 7699 + // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1). 7700 + function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, 7701 + testAmbiguousType, quotingType, forceQuotes, inblock) { 7702 + 7703 + var i; 7704 + var char = 0; 7705 + var prevChar = null; 7706 + var hasLineBreak = false; 7707 + var hasFoldableLine = false; // only checked if shouldTrackWidth 7708 + var shouldTrackWidth = lineWidth !== -1; 7709 + var previousLineBreak = -1; // count the first line correctly 7710 + var plain = isPlainSafeFirst(codePointAt(string, 0)) 7711 + && isPlainSafeLast(codePointAt(string, string.length - 1)); 7712 + 7713 + if (singleLineOnly || forceQuotes) { 7714 + // Case: no block styles. 7715 + // Check for disallowed characters to rule out plain and single. 7716 + for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) { 7717 + char = codePointAt(string, i); 7718 + if (!isPrintable(char)) { 7719 + return STYLE_DOUBLE; 7720 + } 7721 + plain = plain && isPlainSafe(char, prevChar, inblock); 7722 + prevChar = char; 7723 + } 7724 + } else { 7725 + // Case: block styles permitted. 7726 + for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) { 7727 + char = codePointAt(string, i); 7728 + if (char === CHAR_LINE_FEED) { 7729 + hasLineBreak = true; 7730 + // Check if any line can be folded. 7731 + if (shouldTrackWidth) { 7732 + hasFoldableLine = hasFoldableLine || 7733 + // Foldable line = too long, and not more-indented. 7734 + (i - previousLineBreak - 1 > lineWidth && 7735 + string[previousLineBreak + 1] !== ' '); 7736 + previousLineBreak = i; 7737 + } 7738 + } else if (!isPrintable(char)) { 7739 + return STYLE_DOUBLE; 7740 + } 7741 + plain = plain && isPlainSafe(char, prevChar, inblock); 7742 + prevChar = char; 7743 + } 7744 + // in case the end is missing a \n 7745 + hasFoldableLine = hasFoldableLine || (shouldTrackWidth && 7746 + (i - previousLineBreak - 1 > lineWidth && 7747 + string[previousLineBreak + 1] !== ' ')); 7748 + } 7749 + // Although every style can represent \n without escaping, prefer block styles 7750 + // for multiline, since they're more readable and they don't add empty lines. 7751 + // Also prefer folding a super-long line. 7752 + if (!hasLineBreak && !hasFoldableLine) { 7753 + // Strings interpretable as another type have to be quoted; 7754 + // e.g. the string 'true' vs. the boolean true. 7755 + if (plain && !forceQuotes && !testAmbiguousType(string)) { 7756 + return STYLE_PLAIN; 7757 + } 7758 + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; 7759 + } 7760 + // Edge case: block indentation indicator can only have one digit. 7761 + if (indentPerLevel > 9 && needIndentIndicator(string)) { 7762 + return STYLE_DOUBLE; 7763 + } 7764 + // At this point we know block styles are valid. 7765 + // Prefer literal style unless we want to fold. 7766 + if (!forceQuotes) { 7767 + return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; 7768 + } 7769 + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; 7770 + } 7771 + 7772 + // Note: line breaking/folding is implemented for only the folded style. 7773 + // NB. We drop the last trailing newline (if any) of a returned block scalar 7774 + // since the dumper adds its own newline. This always works: 7775 + // • No ending newline => unaffected; already using strip "-" chomping. 7776 + // • Ending newline => removed then restored. 7777 + // Importantly, this keeps the "+" chomp indicator from gaining an extra line. 7778 + function writeScalar(state, string, level, iskey, inblock) { 7779 + state.dump = (function () { 7780 + if (string.length === 0) { 7781 + return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''"; 7782 + } 7783 + if (!state.noCompatMode) { 7784 + if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) { 7785 + return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'"); 7786 + } 7787 + } 7788 + 7789 + var indent = state.indent * Math.max(1, level); // no 0-indent scalars 7790 + // As indentation gets deeper, let the width decrease monotonically 7791 + // to the lower bound min(state.lineWidth, 40). 7792 + // Note that this implies 7793 + // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound. 7794 + // state.lineWidth > 40 + state.indent: width decreases until the lower bound. 7795 + // This behaves better than a constant minimum width which disallows narrower options, 7796 + // or an indent threshold which causes the width to suddenly increase. 7797 + var lineWidth = state.lineWidth === -1 7798 + ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); 7799 + 7800 + // Without knowing if keys are implicit/explicit, assume implicit for safety. 7801 + var singleLineOnly = iskey 7802 + // No block styles in flow mode. 7803 + || (state.flowLevel > -1 && level >= state.flowLevel); 7804 + function testAmbiguity(string) { 7805 + return testImplicitResolving(state, string); 7806 + } 7807 + 7808 + switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, 7809 + testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) { 7810 + 7811 + case STYLE_PLAIN: 7812 + return string; 7813 + case STYLE_SINGLE: 7814 + return "'" + string.replace(/'/g, "''") + "'"; 7815 + case STYLE_LITERAL: 7816 + return '|' + blockHeader(string, state.indent) 7817 + + dropEndingNewline(indentString(string, indent)); 7818 + case STYLE_FOLDED: 7819 + return '>' + blockHeader(string, state.indent) 7820 + + dropEndingNewline(indentString(foldString(string, lineWidth), indent)); 7821 + case STYLE_DOUBLE: 7822 + return '"' + escapeString(string) + '"'; 7823 + default: 7824 + throw new exception('impossible error: invalid scalar style'); 7825 + } 7826 + }()); 7827 + } 7828 + 7829 + // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9. 7830 + function blockHeader(string, indentPerLevel) { 7831 + var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ''; 7832 + 7833 + // note the special case: the string '\n' counts as a "trailing" empty line. 7834 + var clip = string[string.length - 1] === '\n'; 7835 + var keep = clip && (string[string.length - 2] === '\n' || string === '\n'); 7836 + var chomp = keep ? '+' : (clip ? '' : '-'); 7837 + 7838 + return indentIndicator + chomp + '\n'; 7839 + } 7840 + 7841 + // (See the note for writeScalar.) 7842 + function dropEndingNewline(string) { 7843 + return string[string.length - 1] === '\n' ? string.slice(0, -1) : string; 7844 + } 7845 + 7846 + // Note: a long line without a suitable break point will exceed the width limit. 7847 + // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0. 7848 + function foldString(string, width) { 7849 + // In folded style, $k$ consecutive newlines output as $k+1$ newlines— 7850 + // unless they're before or after a more-indented line, or at the very 7851 + // beginning or end, in which case $k$ maps to $k$. 7852 + // Therefore, parse each chunk as newline(s) followed by a content line. 7853 + var lineRe = /(\n+)([^\n]*)/g; 7854 + 7855 + // first line (possibly an empty line) 7856 + var result = (function () { 7857 + var nextLF = string.indexOf('\n'); 7858 + nextLF = nextLF !== -1 ? nextLF : string.length; 7859 + lineRe.lastIndex = nextLF; 7860 + return foldLine(string.slice(0, nextLF), width); 7861 + }()); 7862 + // If we haven't reached the first content line yet, don't add an extra \n. 7863 + var prevMoreIndented = string[0] === '\n' || string[0] === ' '; 7864 + var moreIndented; 7865 + 7866 + // rest of the lines 7867 + var match; 7868 + while ((match = lineRe.exec(string))) { 7869 + var prefix = match[1], line = match[2]; 7870 + moreIndented = (line[0] === ' '); 7871 + result += prefix 7872 + + (!prevMoreIndented && !moreIndented && line !== '' 7873 + ? '\n' : '') 7874 + + foldLine(line, width); 7875 + prevMoreIndented = moreIndented; 7876 + } 7877 + 7878 + return result; 7879 + } 7880 + 7881 + // Greedy line breaking. 7882 + // Picks the longest line under the limit each time, 7883 + // otherwise settles for the shortest line over the limit. 7884 + // NB. More-indented lines *cannot* be folded, as that would add an extra \n. 7885 + function foldLine(line, width) { 7886 + if (line === '' || line[0] === ' ') return line; 7887 + 7888 + // Since a more-indented line adds a \n, breaks can't be followed by a space. 7889 + var breakRe = / [^ ]/g; // note: the match index will always be <= length-2. 7890 + var match; 7891 + // start is an inclusive index. end, curr, and next are exclusive. 7892 + var start = 0, end, curr = 0, next = 0; 7893 + var result = ''; 7894 + 7895 + // Invariants: 0 <= start <= length-1. 7896 + // 0 <= curr <= next <= max(0, length-2). curr - start <= width. 7897 + // Inside the loop: 7898 + // A match implies length >= 2, so curr and next are <= length-2. 7899 + while ((match = breakRe.exec(line))) { 7900 + next = match.index; 7901 + // maintain invariant: curr - start <= width 7902 + if (next - start > width) { 7903 + end = (curr > start) ? curr : next; // derive end <= length-2 7904 + result += '\n' + line.slice(start, end); 7905 + // skip the space that was output as \n 7906 + start = end + 1; // derive start <= length-1 7907 + } 7908 + curr = next; 7909 + } 7910 + 7911 + // By the invariants, start <= length-1, so there is something left over. 7912 + // It is either the whole string or a part starting from non-whitespace. 7913 + result += '\n'; 7914 + // Insert a break if the remainder is too long and there is a break available. 7915 + if (line.length - start > width && curr > start) { 7916 + result += line.slice(start, curr) + '\n' + line.slice(curr + 1); 7917 + } else { 7918 + result += line.slice(start); 7919 + } 7920 + 7921 + return result.slice(1); // drop extra \n joiner 7922 + } 7923 + 7924 + // Escapes a double-quoted string. 7925 + function escapeString(string) { 7926 + var result = ''; 7927 + var char = 0; 7928 + var escapeSeq; 7929 + 7930 + for (var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) { 7931 + char = codePointAt(string, i); 7932 + escapeSeq = ESCAPE_SEQUENCES[char]; 7933 + 7934 + if (!escapeSeq && isPrintable(char)) { 7935 + result += string[i]; 7936 + if (char >= 0x10000) result += string[i + 1]; 7937 + } else { 7938 + result += escapeSeq || encodeHex(char); 7939 + } 7940 + } 7941 + 7942 + return result; 7943 + } 7944 + 7945 + function writeFlowSequence(state, level, object) { 7946 + var _result = '', 7947 + _tag = state.tag, 7948 + index, 7949 + length, 7950 + value; 7951 + 7952 + for (index = 0, length = object.length; index < length; index += 1) { 7953 + value = object[index]; 7954 + 7955 + if (state.replacer) { 7956 + value = state.replacer.call(object, String(index), value); 7957 + } 7958 + 7959 + // Write only valid elements, put null instead of invalid elements. 7960 + if (writeNode(state, level, value, false, false) || 7961 + (typeof value === 'undefined' && 7962 + writeNode(state, level, null, false, false))) { 7963 + 7964 + if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : ''); 7965 + _result += state.dump; 7966 + } 7967 + } 7968 + 7969 + state.tag = _tag; 7970 + state.dump = '[' + _result + ']'; 7971 + } 7972 + 7973 + function writeBlockSequence(state, level, object, compact) { 7974 + var _result = '', 7975 + _tag = state.tag, 7976 + index, 7977 + length, 7978 + value; 7979 + 7980 + for (index = 0, length = object.length; index < length; index += 1) { 7981 + value = object[index]; 7982 + 7983 + if (state.replacer) { 7984 + value = state.replacer.call(object, String(index), value); 7985 + } 7986 + 7987 + // Write only valid elements, put null instead of invalid elements. 7988 + if (writeNode(state, level + 1, value, true, true, false, true) || 7989 + (typeof value === 'undefined' && 7990 + writeNode(state, level + 1, null, true, true, false, true))) { 7991 + 7992 + if (!compact || _result !== '') { 7993 + _result += generateNextLine(state, level); 7994 + } 7995 + 7996 + if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 7997 + _result += '-'; 7998 + } else { 7999 + _result += '- '; 8000 + } 8001 + 8002 + _result += state.dump; 8003 + } 8004 + } 8005 + 8006 + state.tag = _tag; 8007 + state.dump = _result || '[]'; // Empty sequence if no valid values. 8008 + } 8009 + 8010 + function writeFlowMapping(state, level, object) { 8011 + var _result = '', 8012 + _tag = state.tag, 8013 + objectKeyList = Object.keys(object), 8014 + index, 8015 + length, 8016 + objectKey, 8017 + objectValue, 8018 + pairBuffer; 8019 + 8020 + for (index = 0, length = objectKeyList.length; index < length; index += 1) { 8021 + 8022 + pairBuffer = ''; 8023 + if (_result !== '') pairBuffer += ', '; 8024 + 8025 + if (state.condenseFlow) pairBuffer += '"'; 8026 + 8027 + objectKey = objectKeyList[index]; 8028 + objectValue = object[objectKey]; 8029 + 8030 + if (state.replacer) { 8031 + objectValue = state.replacer.call(object, objectKey, objectValue); 8032 + } 8033 + 8034 + if (!writeNode(state, level, objectKey, false, false)) { 8035 + continue; // Skip this pair because of invalid key; 8036 + } 8037 + 8038 + if (state.dump.length > 1024) pairBuffer += '? '; 8039 + 8040 + pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' '); 8041 + 8042 + if (!writeNode(state, level, objectValue, false, false)) { 8043 + continue; // Skip this pair because of invalid value. 8044 + } 8045 + 8046 + pairBuffer += state.dump; 8047 + 8048 + // Both key and value are valid. 8049 + _result += pairBuffer; 8050 + } 8051 + 8052 + state.tag = _tag; 8053 + state.dump = '{' + _result + '}'; 8054 + } 8055 + 8056 + function writeBlockMapping(state, level, object, compact) { 8057 + var _result = '', 8058 + _tag = state.tag, 8059 + objectKeyList = Object.keys(object), 8060 + index, 8061 + length, 8062 + objectKey, 8063 + objectValue, 8064 + explicitPair, 8065 + pairBuffer; 8066 + 8067 + // Allow sorting keys so that the output file is deterministic 8068 + if (state.sortKeys === true) { 8069 + // Default sorting 8070 + objectKeyList.sort(); 8071 + } else if (typeof state.sortKeys === 'function') { 8072 + // Custom sort function 8073 + objectKeyList.sort(state.sortKeys); 8074 + } else if (state.sortKeys) { 8075 + // Something is wrong 8076 + throw new exception('sortKeys must be a boolean or a function'); 8077 + } 8078 + 8079 + for (index = 0, length = objectKeyList.length; index < length; index += 1) { 8080 + pairBuffer = ''; 8081 + 8082 + if (!compact || _result !== '') { 8083 + pairBuffer += generateNextLine(state, level); 8084 + } 8085 + 8086 + objectKey = objectKeyList[index]; 8087 + objectValue = object[objectKey]; 8088 + 8089 + if (state.replacer) { 8090 + objectValue = state.replacer.call(object, objectKey, objectValue); 8091 + } 8092 + 8093 + if (!writeNode(state, level + 1, objectKey, true, true, true)) { 8094 + continue; // Skip this pair because of invalid key. 8095 + } 8096 + 8097 + explicitPair = (state.tag !== null && state.tag !== '?') || 8098 + (state.dump && state.dump.length > 1024); 8099 + 8100 + if (explicitPair) { 8101 + if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 8102 + pairBuffer += '?'; 8103 + } else { 8104 + pairBuffer += '? '; 8105 + } 8106 + } 8107 + 8108 + pairBuffer += state.dump; 8109 + 8110 + if (explicitPair) { 8111 + pairBuffer += generateNextLine(state, level); 8112 + } 8113 + 8114 + if (!writeNode(state, level + 1, objectValue, true, explicitPair)) { 8115 + continue; // Skip this pair because of invalid value. 8116 + } 8117 + 8118 + if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { 8119 + pairBuffer += ':'; 8120 + } else { 8121 + pairBuffer += ': '; 8122 + } 8123 + 8124 + pairBuffer += state.dump; 8125 + 8126 + // Both key and value are valid. 8127 + _result += pairBuffer; 8128 + } 8129 + 8130 + state.tag = _tag; 8131 + state.dump = _result || '{}'; // Empty mapping if no valid pairs. 8132 + } 8133 + 8134 + function detectType(state, object, explicit) { 8135 + var _result, typeList, index, length, type, style; 8136 + 8137 + typeList = explicit ? state.explicitTypes : state.implicitTypes; 8138 + 8139 + for (index = 0, length = typeList.length; index < length; index += 1) { 8140 + type = typeList[index]; 8141 + 8142 + if ((type.instanceOf || type.predicate) && 8143 + (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) && 8144 + (!type.predicate || type.predicate(object))) { 8145 + 8146 + if (explicit) { 8147 + if (type.multi && type.representName) { 8148 + state.tag = type.representName(object); 8149 + } else { 8150 + state.tag = type.tag; 8151 + } 8152 + } else { 8153 + state.tag = '?'; 8154 + } 8155 + 8156 + if (type.represent) { 8157 + style = state.styleMap[type.tag] || type.defaultStyle; 8158 + 8159 + if (_toString.call(type.represent) === '[object Function]') { 8160 + _result = type.represent(object, style); 8161 + } else if (_hasOwnProperty.call(type.represent, style)) { 8162 + _result = type.represent[style](object, style); 8163 + } else { 8164 + throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style'); 8165 + } 8166 + 8167 + state.dump = _result; 8168 + } 8169 + 8170 + return true; 8171 + } 8172 + } 8173 + 8174 + return false; 8175 + } 8176 + 8177 + // Serializes `object` and writes it to global `result`. 8178 + // Returns true on success, or false on invalid object. 8179 + // 8180 + function writeNode(state, level, object, block, compact, iskey, isblockseq) { 8181 + state.tag = null; 8182 + state.dump = object; 8183 + 8184 + if (!detectType(state, object, false)) { 8185 + detectType(state, object, true); 8186 + } 8187 + 8188 + var type = _toString.call(state.dump); 8189 + var inblock = block; 8190 + var tagStr; 8191 + 8192 + if (block) { 8193 + block = (state.flowLevel < 0 || state.flowLevel > level); 8194 + } 8195 + 8196 + var objectOrArray = type === '[object Object]' || type === '[object Array]', 8197 + duplicateIndex, 8198 + duplicate; 8199 + 8200 + if (objectOrArray) { 8201 + duplicateIndex = state.duplicates.indexOf(object); 8202 + duplicate = duplicateIndex !== -1; 8203 + } 8204 + 8205 + if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) { 8206 + compact = false; 8207 + } 8208 + 8209 + if (duplicate && state.usedDuplicates[duplicateIndex]) { 8210 + state.dump = '*ref_' + duplicateIndex; 8211 + } else { 8212 + if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) { 8213 + state.usedDuplicates[duplicateIndex] = true; 8214 + } 8215 + if (type === '[object Object]') { 8216 + if (block && (Object.keys(state.dump).length !== 0)) { 8217 + writeBlockMapping(state, level, state.dump, compact); 8218 + if (duplicate) { 8219 + state.dump = '&ref_' + duplicateIndex + state.dump; 8220 + } 8221 + } else { 8222 + writeFlowMapping(state, level, state.dump); 8223 + if (duplicate) { 8224 + state.dump = '&ref_' + duplicateIndex + ' ' + state.dump; 8225 + } 8226 + } 8227 + } else if (type === '[object Array]') { 8228 + if (block && (state.dump.length !== 0)) { 8229 + if (state.noArrayIndent && !isblockseq && level > 0) { 8230 + writeBlockSequence(state, level - 1, state.dump, compact); 8231 + } else { 8232 + writeBlockSequence(state, level, state.dump, compact); 8233 + } 8234 + if (duplicate) { 8235 + state.dump = '&ref_' + duplicateIndex + state.dump; 8236 + } 8237 + } else { 8238 + writeFlowSequence(state, level, state.dump); 8239 + if (duplicate) { 8240 + state.dump = '&ref_' + duplicateIndex + ' ' + state.dump; 8241 + } 8242 + } 8243 + } else if (type === '[object String]') { 8244 + if (state.tag !== '?') { 8245 + writeScalar(state, state.dump, level, iskey, inblock); 8246 + } 8247 + } else if (type === '[object Undefined]') { 8248 + return false; 8249 + } else { 8250 + if (state.skipInvalid) return false; 8251 + throw new exception('unacceptable kind of an object to dump ' + type); 8252 + } 8253 + 8254 + if (state.tag !== null && state.tag !== '?') { 8255 + // Need to encode all characters except those allowed by the spec: 8256 + // 8257 + // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */ 8258 + // [36] ns-hex-digit ::= ns-dec-digit 8259 + // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */ 8260 + // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */ 8261 + // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-” 8262 + // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#” 8263 + // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,” 8264 + // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]” 8265 + // 8266 + // Also need to encode '!' because it has special meaning (end of tag prefix). 8267 + // 8268 + tagStr = encodeURI( 8269 + state.tag[0] === '!' ? state.tag.slice(1) : state.tag 8270 + ).replace(/!/g, '%21'); 8271 + 8272 + if (state.tag[0] === '!') { 8273 + tagStr = '!' + tagStr; 8274 + } else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') { 8275 + tagStr = '!!' + tagStr.slice(18); 8276 + } else { 8277 + tagStr = '!<' + tagStr + '>'; 8278 + } 8279 + 8280 + state.dump = tagStr + ' ' + state.dump; 8281 + } 8282 + } 8283 + 8284 + return true; 8285 + } 8286 + 8287 + function getDuplicateReferences(object, state) { 8288 + var objects = [], 8289 + duplicatesIndexes = [], 8290 + index, 8291 + length; 8292 + 8293 + inspectNode(object, objects, duplicatesIndexes); 8294 + 8295 + for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) { 8296 + state.duplicates.push(objects[duplicatesIndexes[index]]); 8297 + } 8298 + state.usedDuplicates = new Array(length); 8299 + } 8300 + 8301 + function inspectNode(object, objects, duplicatesIndexes) { 8302 + var objectKeyList, 8303 + index, 8304 + length; 8305 + 8306 + if (object !== null && typeof object === 'object') { 8307 + index = objects.indexOf(object); 8308 + if (index !== -1) { 8309 + if (duplicatesIndexes.indexOf(index) === -1) { 8310 + duplicatesIndexes.push(index); 8311 + } 8312 + } else { 8313 + objects.push(object); 8314 + 8315 + if (Array.isArray(object)) { 8316 + for (index = 0, length = object.length; index < length; index += 1) { 8317 + inspectNode(object[index], objects, duplicatesIndexes); 8318 + } 8319 + } else { 8320 + objectKeyList = Object.keys(object); 8321 + 8322 + for (index = 0, length = objectKeyList.length; index < length; index += 1) { 8323 + inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes); 8324 + } 8325 + } 8326 + } 8327 + } 8328 + } 8329 + 8330 + function dump$1(input, options) { 8331 + options = options || {}; 8332 + 8333 + var state = new State(options); 8334 + 8335 + if (!state.noRefs) getDuplicateReferences(input, state); 8336 + 8337 + var value = input; 8338 + 8339 + if (state.replacer) { 8340 + value = state.replacer.call({ '': value }, '', value); 8341 + } 8342 + 8343 + if (writeNode(state, 0, value, true, true)) return state.dump + '\n'; 8344 + 8345 + return ''; 8346 + } 8347 + 8348 + var dump_1 = dump$1; 8349 + 8350 + var dumper = { 8351 + dump: dump_1 8352 + }; 8353 + 8354 + function renamed(from, to) { 8355 + return function () { 8356 + throw new Error('Function yaml.' + from + ' is removed in js-yaml 4. ' + 8357 + 'Use yaml.' + to + ' instead, which is now safe by default.'); 8358 + }; 8359 + } 8360 + 8361 + 8362 + var Type = type; 8363 + var Schema = schema; 8364 + var FAILSAFE_SCHEMA = failsafe; 8365 + var JSON_SCHEMA = json; 8366 + var CORE_SCHEMA = core; 8367 + var DEFAULT_SCHEMA = _default; 8368 + var load = loader.load; 8369 + var loadAll = loader.loadAll; 8370 + var dump = dumper.dump; 8371 + var YAMLException = exception; 8372 + 8373 + // Re-export all types in case user wants to create custom schema 8374 + var types = { 8375 + binary: binary, 8376 + float: float, 8377 + map: map, 8378 + null: _null, 8379 + pairs: pairs, 8380 + set: set, 8381 + timestamp: timestamp, 8382 + bool: bool, 8383 + int: int, 8384 + merge: merge, 8385 + omap: omap, 8386 + seq: seq, 8387 + str: str 8388 + }; 8389 + 8390 + // Removed functions from JS-YAML 3.0.x 8391 + var safeLoad = renamed('safeLoad', 'load'); 8392 + var safeLoadAll = renamed('safeLoadAll', 'loadAll'); 8393 + var safeDump = renamed('safeDump', 'dump'); 8394 + 8395 + var jsYaml = { 8396 + Type: Type, 8397 + Schema: Schema, 8398 + FAILSAFE_SCHEMA: FAILSAFE_SCHEMA, 8399 + JSON_SCHEMA: JSON_SCHEMA, 8400 + CORE_SCHEMA: CORE_SCHEMA, 8401 + DEFAULT_SCHEMA: DEFAULT_SCHEMA, 8402 + load: load, 8403 + loadAll: loadAll, 8404 + dump: dump, 8405 + YAMLException: YAMLException, 8406 + types: types, 8407 + safeLoad: safeLoad, 8408 + safeLoadAll: safeLoadAll, 8409 + safeDump: safeDump 8410 + }; 8411 + 8412 + // Detect either spaces or tabs but not both to properly handle tabs for indentation and spaces for alignment 8413 + const INDENT_REGEX = /^(?:( )+|\t+)/; 8414 + 8415 + const INDENT_TYPE_SPACE = 'space'; 8416 + const INDENT_TYPE_TAB = 'tab'; 8417 + 8418 + /** 8419 + Make a Map that counts how many indents/unindents have occurred for a given size and how many lines follow a given indentation. 8420 + 8421 + The key is a concatenation of the indentation type (s = space and t = tab) and the size of the indents/unindents. 8422 + 8423 + ``` 8424 + indents = { 8425 + t3: [1, 0], 8426 + t4: [1, 5], 8427 + s5: [1, 0], 8428 + s12: [1, 0], 8429 + } 8430 + ``` 8431 + */ 8432 + function makeIndentsMap(string, ignoreSingleSpaces) { 8433 + const indents = new Map(); 8434 + 8435 + // Remember the size of previous line's indentation 8436 + let previousSize = 0; 8437 + let previousIndentType; 8438 + 8439 + // Indents key (ident type + size of the indents/unindents) 8440 + let key; 8441 + 8442 + for (const line of string.split(/\n/g)) { 8443 + if (!line) { 8444 + // Ignore empty lines 8445 + continue; 8446 + } 8447 + 8448 + let indent; 8449 + let indentType; 8450 + let weight; 8451 + let entry; 8452 + const matches = line.match(INDENT_REGEX); 8453 + 8454 + if (matches === null) { 8455 + previousSize = 0; 8456 + previousIndentType = ''; 8457 + } else { 8458 + indent = matches[0].length; 8459 + indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB; 8460 + 8461 + // Ignore single space unless it's the only indent detected to prevent common false positives 8462 + if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) { 8463 + continue; 8464 + } 8465 + 8466 + if (indentType !== previousIndentType) { 8467 + previousSize = 0; 8468 + } 8469 + 8470 + previousIndentType = indentType; 8471 + 8472 + weight = 0; 8473 + 8474 + const indentDifference = indent - previousSize; 8475 + previousSize = indent; 8476 + 8477 + // Previous line have same indent? 8478 + if (indentDifference === 0) { 8479 + weight++; 8480 + // We use the key from previous loop 8481 + } else { 8482 + const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference; 8483 + key = encodeIndentsKey(indentType, absoluteIndentDifference); 8484 + } 8485 + 8486 + // Update the stats 8487 + entry = indents.get(key); 8488 + entry = entry === undefined ? [1, 0] : [++entry[0], entry[1] + weight]; 8489 + 8490 + indents.set(key, entry); 8491 + } 8492 + } 8493 + 8494 + return indents; 8495 + } 8496 + 8497 + // Encode the indent type and amount as a string (e.g. 's4') for use as a compound key in the indents Map. 8498 + function encodeIndentsKey(indentType, indentAmount) { 8499 + const typeCharacter = indentType === INDENT_TYPE_SPACE ? 's' : 't'; 8500 + return typeCharacter + String(indentAmount); 8501 + } 8502 + 8503 + // Extract the indent type and amount from a key of the indents Map. 8504 + function decodeIndentsKey(indentsKey) { 8505 + const keyHasTypeSpace = indentsKey[0] === 's'; 8506 + const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB; 8507 + 8508 + const amount = Number(indentsKey.slice(1)); 8509 + 8510 + return {type, amount}; 8511 + } 8512 + 8513 + // Return the key (e.g. 's4') from the indents Map that represents the most common indent, 8514 + // or return undefined if there are no indents. 8515 + function getMostUsedKey(indents) { 8516 + let result; 8517 + let maxUsed = 0; 8518 + let maxWeight = 0; 8519 + 8520 + for (const [key, [usedCount, weight]] of indents) { 8521 + if (usedCount > maxUsed || (usedCount === maxUsed && weight > maxWeight)) { 8522 + maxUsed = usedCount; 8523 + maxWeight = weight; 8524 + result = key; 8525 + } 8526 + } 8527 + 8528 + return result; 8529 + } 8530 + 8531 + function makeIndentString(type, amount) { 8532 + const indentCharacter = type === INDENT_TYPE_SPACE ? ' ' : '\t'; 8533 + return indentCharacter.repeat(amount); 8534 + } 8535 + 8536 + function detectIndent(string) { 8537 + if (typeof string !== 'string') { 8538 + throw new TypeError('Expected a string'); 8539 + } 8540 + 8541 + // Identify indents while skipping single space indents to avoid common edge cases (e.g. code comments) 8542 + // If no indents are identified, run again and include all indents for comprehensive detection 8543 + let indents = makeIndentsMap(string, true); 8544 + if (indents.size === 0) { 8545 + indents = makeIndentsMap(string, false); 8546 + } 8547 + 8548 + const keyOfMostUsedIndent = getMostUsedKey(indents); 8549 + 8550 + let type; 8551 + let amount = 0; 8552 + let indent = ''; 8553 + 8554 + if (keyOfMostUsedIndent !== undefined) { 8555 + ({type, amount} = decodeIndentsKey(keyOfMostUsedIndent)); 8556 + indent = makeIndentString(type, amount); 8557 + } 8558 + 8559 + return { 8560 + amount, 8561 + type, 8562 + indent, 8563 + }; 8564 + } 8565 + 8566 + const settingRegExp = /\/\*\s*@settings[\r\n]+?([\s\S]+?)\*\//g; 8567 + const nameRegExp = /^name:\s*(.+)$/m; 8568 + class CSSSettingsPlugin extends obsidian.Plugin { 8569 + constructor() { 8570 + super(...arguments); 8571 + this.settingsList = []; 8572 + this.errorList = []; 8573 + this.debounceTimer = 0; 8574 + } 8575 + onload() { 8576 + return __awaiter(this, void 0, void 0, function* () { 8577 + this.settingsManager = new CSSSettingsManager(this); 8578 + yield this.settingsManager.load(); 8579 + this.settingsTab = new CSSSettingsTab(this.app, this); 8580 + this.addSettingTab(this.settingsTab); 8581 + this.registerView(viewType, (leaf) => new SettingsView(this, leaf)); 8582 + this.addCommand({ 8583 + id: "show-style-settings-leaf", 8584 + name: "Show style settings view", 8585 + callback: () => { 8586 + this.activateView(); 8587 + }, 8588 + }); 8589 + this.registerEvent(this.app.workspace.on("css-change", () => { 8590 + this.parseCSS(); 8591 + })); 8592 + this.registerEvent(this.app.workspace.on("parse-style-settings", () => { 8593 + this.parseCSS(); 8594 + })); 8595 + document.body.classList.add("css-settings-manager"); 8596 + this.parseCSS(); 8597 + }); 8598 + } 8599 + parseCSS() { 8600 + clearTimeout(this.debounceTimer); 8601 + this.settingsList = []; 8602 + this.errorList = []; 8603 + this.debounceTimer = window.setTimeout(() => { 8604 + const styleSheets = document.styleSheets; 8605 + for (let i = 0, len = styleSheets.length; i < len; i++) { 8606 + const sheet = styleSheets.item(i); 8607 + const text = sheet.ownerNode.textContent.trim(); 8608 + let match = settingRegExp.exec(text); 8609 + if (match && match.length) { 8610 + do { 8611 + const nameMatch = text.match(nameRegExp); 8612 + const name = nameMatch 8613 + ? nameMatch[1] 8614 + : undefined; 8615 + try { 8616 + const str = match[1].trim(); 8617 + const indent = detectIndent(str); 8618 + const settings = jsYaml.load(str.replace(/\t/g, indent.type === "space" ? indent.indent : " "), { 8619 + filename: name, 8620 + }); 8621 + if (!settings.settings) 8622 + continue; 8623 + settings.settings = settings.settings.filter((setting) => setting); 8624 + if (typeof settings === "object" && 8625 + settings.name && 8626 + settings.id && 8627 + settings.settings && 8628 + settings.settings.length) { 8629 + this.settingsList.push(settings); 8630 + } 8631 + } 8632 + catch (e) { 8633 + this.errorList.push({ name, error: `${e}` }); 8634 + } 8635 + } while ((match = settingRegExp.exec(text)) !== null); 8636 + } 8637 + } 8638 + this.settingsTab.settingsMarkup.setSettings(this.settingsList, this.errorList); 8639 + this.app.workspace.getLeavesOfType(viewType).forEach((leaf) => { 8640 + leaf.view.settingsMarkup.setSettings(this.settingsList, this.errorList); 8641 + }); 8642 + this.settingsManager.initClasses(); 8643 + }, 100); 8644 + } 8645 + onunload() { 8646 + document.body.classList.remove("css-settings-manager"); 8647 + this.settingsManager.cleanup(); 8648 + this.settingsTab.settingsMarkup.cleanup(); 8649 + this.deactivateView(); 8650 + } 8651 + deactivateView() { 8652 + this.app.workspace.detachLeavesOfType(viewType); 8653 + } 8654 + activateView() { 8655 + return __awaiter(this, void 0, void 0, function* () { 8656 + this.deactivateView(); 8657 + const leaf = this.app.workspace.createLeafBySplit(this.app.workspace.activeLeaf, "vertical"); 8658 + yield leaf.setViewState({ 8659 + type: viewType, 8660 + }); 8661 + leaf.view.settingsMarkup.setSettings(this.settingsList, this.errorList); 8662 + }); 8663 + } 8664 + } 8665 + class SettingsMarkup { 8666 + constructor(app, plugin, containerEl, isView) { 8667 + this.cleanupFns = []; 8668 + this.settings = []; 8669 + this.errorList = []; 8670 + this.app = app; 8671 + this.plugin = plugin; 8672 + this.containerEl = containerEl; 8673 + this.isView = !!isView; 8674 + } 8675 + display() { 8676 + this.generate(this.settings); 8677 + } 8678 + cleanup() { 8679 + Array.from(this.cleanupFns).forEach((fn) => { 8680 + fn && fn(); 8681 + this.cleanupFns.remove(fn); 8682 + }); 8683 + } 8684 + setSettings(settings, errorList) { 8685 + this.settings = settings; 8686 + this.errorList = errorList; 8687 + this.plugin.settingsManager.setConfig(settings); 8688 + if (this.containerEl.parentNode) { 8689 + this.generate(settings); 8690 + } 8691 + } 8692 + displayErrors() { 8693 + let { containerEl, errorList } = this; 8694 + errorList.forEach((err) => { 8695 + containerEl.createDiv({ cls: "style-settings-error" }, (wrapper) => { 8696 + wrapper.createDiv({ 8697 + cls: "style-settings-error-name", 8698 + text: `Error: ${err.name}`, 8699 + }); 8700 + wrapper.createDiv({ 8701 + cls: "style-settings-error-desc", 8702 + text: err.error, 8703 + }); 8704 + }); 8705 + }); 8706 + } 8707 + displayEmpty() { 8708 + let { containerEl } = this; 8709 + containerEl.createDiv({ cls: "style-settings-empty" }, (wrapper) => { 8710 + wrapper.createDiv({ 8711 + cls: "style-settings-empty-name", 8712 + text: "No style settings found", 8713 + }); 8714 + wrapper.createDiv({ cls: "style-settings-empty-desc" }).appendChild(createFragment((frag) => { 8715 + frag.appendText("Style settings configured by theme and plugin authors will show up here. You can also create your own configuration by creating a CSS snippet in your vault. "); 8716 + frag.createEl("a", { 8717 + text: "Click here for details and examples.", 8718 + href: "https://github.com/mgmeyers/obsidian-style-settings#obsidian-style-settings-plugin", 8719 + }); 8720 + })); 8721 + }); 8722 + } 8723 + generate(settings) { 8724 + let { containerEl, plugin } = this; 8725 + containerEl.empty(); 8726 + this.cleanup(); 8727 + this.displayErrors(); 8728 + if (settings.length === 0) { 8729 + return this.displayEmpty(); 8730 + } 8731 + new obsidian.Setting(containerEl).then((setting) => { 8732 + // Build and import link to open the import modal 8733 + setting.controlEl.createEl("a", { 8734 + cls: "style-settings-import", 8735 + text: "Import", 8736 + href: "#", 8737 + }, (el) => { 8738 + el.addEventListener("click", (e) => { 8739 + e.preventDefault(); 8740 + this.plugin.settingsManager.import(); 8741 + }); 8742 + }); 8743 + // Build and export link to open the export modal 8744 + setting.controlEl.createEl("a", { 8745 + cls: "style-settings-export", 8746 + text: "Export", 8747 + href: "#", 8748 + }, (el) => { 8749 + el.addEventListener("click", (e) => { 8750 + e.preventDefault(); 8751 + this.plugin.settingsManager.export("All settings", this.plugin.settingsManager.settings); 8752 + }); 8753 + }); 8754 + }); 8755 + const cleanupFns = []; 8756 + settings.forEach((s) => { 8757 + const options = [ 8758 + { 8759 + id: s.id, 8760 + type: "heading", 8761 + title: s.name, 8762 + level: 0, 8763 + collapsed: true, 8764 + resetFn: () => { 8765 + plugin.settingsManager.clearSection(s.id); 8766 + this.generate(this.settings); 8767 + }, 8768 + }, 8769 + ...s.settings, 8770 + ]; 8771 + const cleanup = createSettings({ 8772 + containerEl, 8773 + isView: this.isView, 8774 + sectionId: s.id, 8775 + sectionName: s.name, 8776 + settings: options, 8777 + settingsManager: plugin.settingsManager, 8778 + }); 8779 + if (cleanup.length) 8780 + cleanupFns.push(...cleanup); 8781 + }); 8782 + this.cleanupFns = cleanupFns; 8783 + } 8784 + } 8785 + class CSSSettingsTab extends obsidian.PluginSettingTab { 8786 + constructor(app, plugin) { 8787 + super(app, plugin); 8788 + this.settingsMarkup = new SettingsMarkup(app, plugin, this.containerEl); 8789 + } 8790 + display() { 8791 + this.settingsMarkup.display(); 8792 + } 8793 + hide() { 8794 + this.settingsMarkup.cleanup(); 8795 + } 8796 + } 8797 + const viewType = "style-settings"; 8798 + class SettingsView extends obsidian.ItemView { 8799 + constructor(plugin, leaf) { 8800 + super(leaf); 8801 + this.plugin = plugin; 8802 + this.settingsMarkup = new SettingsMarkup(plugin.app, plugin, this.contentEl, true); 8803 + } 8804 + getViewType() { 8805 + return viewType; 8806 + } 8807 + getIcon() { 8808 + return "gear"; 8809 + } 8810 + getDisplayText() { 8811 + return "Style Settings"; 8812 + } 8813 + onOpen() { 8814 + return __awaiter(this, void 0, void 0, function* () { 8815 + return this.settingsMarkup.display(); 8816 + }); 8817 + } 8818 + onClose() { 8819 + return __awaiter(this, void 0, void 0, function* () { 8820 + return this.settingsMarkup.cleanup(); 8821 + }); 8822 + } 8823 + } 8824 + 8825 + module.exports = CSSSettingsPlugin;
+10
obsidian/plugins/obsidian-style-settings/manifest.json
··· 1 + { 2 + "id": "obsidian-style-settings", 3 + "name": "Style Settings", 4 + "version": "0.4.10", 5 + "minAppVersion": "0.11.5", 6 + "description": "Offers controls for adjusting theme, plugin, and snippet CSS variables.", 7 + "author": "mgmeyers", 8 + "authorUrl": "https://github.com/mgmeyers/obsidian-style-settings", 9 + "isDesktopOnly": false 10 + }
+214
obsidian/plugins/obsidian-style-settings/styles.css
··· 1 + .pcr-app .pcr-swatches > button { 2 + padding: 0; 3 + } 4 + 5 + .pickr .pcr-button { 6 + margin-right: 0; 7 + } 8 + 9 + .themed-color-wrapper > div { 10 + background: var(--background-primary); 11 + padding: 10px; 12 + display: flex; 13 + align-items: center; 14 + border-radius: 4px; 15 + } 16 + 17 + .themed-color-wrapper > div + div { 18 + margin-top: 6px; 19 + } 20 + 21 + .themed-color-wrapper button { 22 + display: block; 23 + } 24 + 25 + .themed-color-wrapper .pickr-reset > button { 26 + margin: 0 0 0 10px; 27 + padding: 9px; 28 + line-height: 1; 29 + } 30 + 31 + .themed-color-wrapper .pickr-reset > button > svg { 32 + display: block; 33 + } 34 + .style-settings-heading { 35 + cursor: pointer; 36 + margin-bottom: 18px; 37 + padding-bottom: 6px; 38 + border-bottom: 1px solid var(--background-modifier-border); 39 + } 40 + 41 + .style-settings-heading[data-level="0"] { 42 + margin-bottom: 26px; 43 + } 44 + 45 + .style-settings-container { 46 + padding-bottom: 16px; 47 + } 48 + 49 + .style-settings-heading[data-level="0"] + .style-settings-container { 50 + padding-left: 34px; 51 + } 52 + 53 + .style-settings-heading.is-collapsed { 54 + margin-bottom: 0; 55 + } 56 + 57 + .style-settings-heading.is-collapsed + .style-settings-container { 58 + display: none; 59 + } 60 + 61 + .style-settings-collapse-indicator { 62 + color: var(--text-faint); 63 + display: inline-block; 64 + margin-right: 8px; 65 + position: relative; 66 + top: -1px; 67 + } 68 + 69 + .style-settings-heading[data-level="0"] 70 + + .style-settings-container 71 + .style-settings-collapse-indicator { 72 + margin-left: -17px; 73 + } 74 + 75 + .style-settings-collapse-indicator > svg { 76 + height: 9px; 77 + width: 9px; 78 + } 79 + 80 + .style-settings-heading.is-collapsed .style-settings-collapse-indicator > svg { 81 + transform: rotate(-90deg); 82 + } 83 + 84 + .style-settings-error { 85 + font-size: 14px; 86 + border-radius: 6px; 87 + background: rgba(var(--background-modifier-error-rgb), 0.2); 88 + color: var(--text-error); 89 + padding: 10px; 90 + margin-bottom: 1rem; 91 + } 92 + 93 + .style-settings-error-name { 94 + font-weight: bold; 95 + margin-bottom: 5px; 96 + } 97 + 98 + .style-settings-error-desc { 99 + white-space: pre; 100 + } 101 + 102 + .style-settings-empty { 103 + font-size: 14px; 104 + background: var(--background-secondary); 105 + padding: 10px; 106 + } 107 + 108 + .style-settings-empty-name { 109 + font-weight: bold; 110 + margin-bottom: 5px; 111 + } 112 + 113 + .style-settings-import-input { 114 + width: 0.1px; 115 + height: 0.1px; 116 + opacity: 0; 117 + overflow: hidden; 118 + position: absolute; 119 + z-index: -1; 120 + } 121 + 122 + .style-settings-import-label { 123 + cursor: pointer; 124 + color: var(--text-accent); 125 + text-decoration: underline; 126 + } 127 + 128 + .style-settings-import-label:hover { 129 + color: var(--text-accent-hover); 130 + } 131 + 132 + .style-settings-export, 133 + .style-settings-import { 134 + display: inline-block; 135 + margin-right: 10px; 136 + } 137 + 138 + .style-settings-copy, 139 + .style-settings-download { 140 + position: relative; 141 + display: inline-block; 142 + margin-left: 10px; 143 + } 144 + 145 + .style-settings-copy:before { 146 + color: var(--interactive-success); 147 + content: "✓"; 148 + position: absolute; 149 + left: -18px; 150 + font-weight: bold; 151 + opacity: 0; 152 + transition: 150ms opacity ease-in-out; 153 + } 154 + 155 + .style-settings-copy.success:before { 156 + opacity: 1; 157 + } 158 + 159 + .modal-style-settings { 160 + height: 70vh; 161 + display: flex; 162 + flex-direction: column; 163 + } 164 + 165 + .modal-style-settings .modal-content { 166 + flex-grow: 1; 167 + margin: 0; 168 + display: flex; 169 + flex-direction: column; 170 + } 171 + 172 + .modal-style-settings textarea { 173 + display: block; 174 + width: 100%; 175 + height: 100%; 176 + font-family: var(--font-monospace) !important; 177 + font-size: 12px; 178 + white-space: pre; 179 + overflow-wrap: normal; 180 + overflow-x: scroll; 181 + margin-bottom: 5px; 182 + } 183 + 184 + .modal-style-settings .setting-item { 185 + align-items: flex-start; 186 + } 187 + 188 + .modal-style-settings button { 189 + margin: 10px 0 0; 190 + } 191 + 192 + .style-settings-import-error { 193 + display: none; 194 + color: var(--text-error); 195 + } 196 + 197 + .style-settings-import-error.active { 198 + display: block; 199 + } 200 + 201 + .view-content .style-settings-container .setting-item:not(.setting-item-heading) { 202 + flex-direction: column; 203 + align-items: flex-start; 204 + } 205 + 206 + .view-content .style-settings-container .setting-item:not(.setting-item-heading) .setting-item-control { 207 + padding-top: 0.5em; 208 + } 209 + 210 + .view-content .style-settings-container .setting-item:not(.setting-item-heading) .themed-color-wrapper { 211 + display: flex; 212 + }/*! Pickr 1.8.4 MIT | https://github.com/Simonwep/pickr */ 213 + .pickr{position:relative;overflow:visible;transform:translateY(0)}.pickr *{box-sizing:border-box;outline:none;border:none;-webkit-appearance:none}.pickr .pcr-button{position:relative;height:2em;width:2em;padding:0.5em;cursor:pointer;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Helvetica Neue",Arial,sans-serif;border-radius:.15em;background:url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" stroke="%2342445A" stroke-width="5px" stroke-linecap="round"><path d="M45,45L5,5"></path><path d="M45,5L5,45"></path></svg>') no-repeat center;background-size:0;transition:all 0.3s}.pickr .pcr-button::before{position:absolute;content:'';top:0;left:0;width:100%;height:100%;background:url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');background-size:.5em;border-radius:.15em;z-index:-1}.pickr .pcr-button::before{z-index:initial}.pickr .pcr-button::after{position:absolute;content:'';top:0;left:0;height:100%;width:100%;transition:background 0.3s;background:var(--pcr-color);border-radius:.15em}.pickr .pcr-button.clear{background-size:70%}.pickr .pcr-button.clear::before{opacity:0}.pickr .pcr-button.clear:focus{box-shadow:0 0 0 1px rgba(255,255,255,0.85),0 0 0 3px var(--pcr-color)}.pickr .pcr-button.disabled{cursor:not-allowed}.pickr *,.pcr-app *{box-sizing:border-box;outline:none;border:none;-webkit-appearance:none}.pickr input:focus,.pickr input.pcr-active,.pickr button:focus,.pickr button.pcr-active,.pcr-app input:focus,.pcr-app input.pcr-active,.pcr-app button:focus,.pcr-app button.pcr-active{box-shadow:0 0 0 1px rgba(255,255,255,0.85),0 0 0 3px var(--pcr-color)}.pickr .pcr-palette,.pickr .pcr-slider,.pcr-app .pcr-palette,.pcr-app .pcr-slider{transition:box-shadow 0.3s}.pickr .pcr-palette:focus,.pickr .pcr-slider:focus,.pcr-app .pcr-palette:focus,.pcr-app .pcr-slider:focus{box-shadow:0 0 0 1px rgba(255,255,255,0.85),0 0 0 3px rgba(0,0,0,0.25)}.pcr-app{position:fixed;display:flex;flex-direction:column;z-index:10000;border-radius:0.1em;background:#fff;opacity:0;visibility:hidden;transition:opacity 0.3s, visibility 0s 0.3s;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Helvetica Neue",Arial,sans-serif;box-shadow:0 0.15em 1.5em 0 rgba(0,0,0,0.1),0 0 1em 0 rgba(0,0,0,0.03);left:0;top:0}.pcr-app.visible{transition:opacity 0.3s;visibility:visible;opacity:1}.pcr-app .pcr-swatches{display:flex;flex-wrap:wrap;margin-top:0.75em}.pcr-app .pcr-swatches.pcr-last{margin:0}@supports (display: grid){.pcr-app .pcr-swatches{display:grid;align-items:center;grid-template-columns:repeat(auto-fit, 1.75em)}}.pcr-app .pcr-swatches>button{font-size:1em;position:relative;width:calc(1.75em - 5px);height:calc(1.75em - 5px);border-radius:0.15em;cursor:pointer;margin:2.5px;flex-shrink:0;justify-self:center;transition:all 0.15s;overflow:hidden;background:transparent;z-index:1}.pcr-app .pcr-swatches>button::before{position:absolute;content:'';top:0;left:0;width:100%;height:100%;background:url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');background-size:6px;border-radius:.15em;z-index:-1}.pcr-app .pcr-swatches>button::after{content:'';position:absolute;top:0;left:0;width:100%;height:100%;background:var(--pcr-color);border:1px solid rgba(0,0,0,0.05);border-radius:0.15em;box-sizing:border-box}.pcr-app .pcr-swatches>button:hover{filter:brightness(1.05)}.pcr-app .pcr-swatches>button:not(.pcr-active){box-shadow:none}.pcr-app .pcr-interaction{display:flex;flex-wrap:wrap;align-items:center;margin:0 -0.2em 0 -0.2em}.pcr-app .pcr-interaction>*{margin:0 0.2em}.pcr-app .pcr-interaction input{letter-spacing:0.07em;font-size:0.75em;text-align:center;cursor:pointer;color:#75797e;background:#f1f3f4;border-radius:.15em;transition:all 0.15s;padding:0.45em 0.5em;margin-top:0.75em}.pcr-app .pcr-interaction input:hover{filter:brightness(0.975)}.pcr-app .pcr-interaction input:focus{box-shadow:0 0 0 1px rgba(255,255,255,0.85),0 0 0 3px rgba(66,133,244,0.75)}.pcr-app .pcr-interaction .pcr-result{color:#75797e;text-align:left;flex:1 1 8em;min-width:8em;transition:all 0.2s;border-radius:.15em;background:#f1f3f4;cursor:text}.pcr-app .pcr-interaction .pcr-result::-moz-selection{background:#4285f4;color:#fff}.pcr-app .pcr-interaction .pcr-result::selection{background:#4285f4;color:#fff}.pcr-app .pcr-interaction .pcr-type.active{color:#fff;background:#4285f4}.pcr-app .pcr-interaction .pcr-save,.pcr-app .pcr-interaction .pcr-cancel,.pcr-app .pcr-interaction .pcr-clear{color:#fff;width:auto}.pcr-app .pcr-interaction .pcr-save,.pcr-app .pcr-interaction .pcr-cancel,.pcr-app .pcr-interaction .pcr-clear{color:#fff}.pcr-app .pcr-interaction .pcr-save:hover,.pcr-app .pcr-interaction .pcr-cancel:hover,.pcr-app .pcr-interaction .pcr-clear:hover{filter:brightness(0.925)}.pcr-app .pcr-interaction .pcr-save{background:#4285f4}.pcr-app .pcr-interaction .pcr-clear,.pcr-app .pcr-interaction .pcr-cancel{background:#f44250}.pcr-app .pcr-interaction .pcr-clear:focus,.pcr-app .pcr-interaction .pcr-cancel:focus{box-shadow:0 0 0 1px rgba(255,255,255,0.85),0 0 0 3px rgba(244,66,80,0.75)}.pcr-app .pcr-selection .pcr-picker{position:absolute;height:18px;width:18px;border:2px solid #fff;border-radius:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.pcr-app .pcr-selection .pcr-color-palette,.pcr-app .pcr-selection .pcr-color-chooser,.pcr-app .pcr-selection .pcr-color-opacity{position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:flex;flex-direction:column;cursor:grab;cursor:-webkit-grab}.pcr-app .pcr-selection .pcr-color-palette:active,.pcr-app .pcr-selection .pcr-color-chooser:active,.pcr-app .pcr-selection .pcr-color-opacity:active{cursor:grabbing;cursor:-webkit-grabbing}.pcr-app[data-theme='nano']{width:14.25em;max-width:95vw}.pcr-app[data-theme='nano'] .pcr-swatches{margin-top:.6em;padding:0 .6em}.pcr-app[data-theme='nano'] .pcr-interaction{padding:0 .6em .6em .6em}.pcr-app[data-theme='nano'] .pcr-selection{display:grid;grid-gap:.6em;grid-template-columns:1fr 4fr;grid-template-rows:5fr auto auto;align-items:center;height:10.5em;width:100%;align-self:flex-start}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-preview{grid-area:2 / 1 / 4 / 1;height:100%;width:100%;display:flex;flex-direction:row;justify-content:center;margin-left:.6em}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-preview .pcr-last-color{display:none}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-preview .pcr-current-color{position:relative;background:var(--pcr-color);width:2em;height:2em;border-radius:50em;overflow:hidden}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-preview .pcr-current-color::before{position:absolute;content:'';top:0;left:0;width:100%;height:100%;background:url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');background-size:.5em;border-radius:.15em;z-index:-1}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-palette{grid-area:1 / 1 / 2 / 3;width:100%;height:100%;z-index:1}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-palette .pcr-palette{border-radius:.15em;width:100%;height:100%}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-palette .pcr-palette::before{position:absolute;content:'';top:0;left:0;width:100%;height:100%;background:url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');background-size:.5em;border-radius:.15em;z-index:-1}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-chooser{grid-area:2 / 2 / 2 / 2}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-opacity{grid-area:3 / 2 / 3 / 2}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-chooser,.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-opacity{height:0.5em;margin:0 .6em}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-chooser .pcr-picker,.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-opacity .pcr-picker{top:50%;transform:translateY(-50%)}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-chooser .pcr-slider,.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-opacity .pcr-slider{flex-grow:1;border-radius:50em}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-chooser .pcr-slider{background:linear-gradient(to right, red, #ff0, lime, cyan, blue, #f0f, red)}.pcr-app[data-theme='nano'] .pcr-selection .pcr-color-opacity .pcr-slider{background:linear-gradient(to right, transparent, black),url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');background-size:100%, 0.25em} 214 +